diff --git a/ctor/lib/main.js b/ctor/lib/main.js index b2e702dd..d7ae030d 100644 --- a/ctor/lib/main.js +++ b/ctor/lib/main.js @@ -34,6 +34,7 @@ var isBufferLengthCompatible = require( './../../base/assert/is-buffer-length-co var numel = require( './../../base/numel' ); var parent = require( './../../base/ctor' ); // eslint-disable-line stdlib/no-redeclare var inherit = require( '@stdlib/utils/inherit' ); +var format = require( '@stdlib/string/format' ); var defaults = require( './defaults.json' ); var iget = require( './iget.js' ); var iset = require( './iset.js' ); @@ -111,16 +112,16 @@ function ndarray( dtype, buffer, shape, strides, offset, order, options ) { return new ndarray( dtype, buffer, shape, strides, offset, order, options ); // eslint-disable-line max-len } if ( !isDataType( dtype ) ) { - throw new TypeError( 'invalid argument. `dtype` argument must be a supported ndarray data type. Value: `' + dtype + '`.' ); + throw new TypeError( format( 'invalid argument. `dtype` argument must be a supported ndarray data type. Value: `%s`.', dtype ) ); } if ( !isCollection( buffer ) ) { - throw new TypeError( 'invalid argument. `buffer` argument must be an array-like object, typed-array-like, or a Buffer. Value: `' + buffer + '`.' ); + throw new TypeError( format( 'invalid argument. `buffer` argument must be an array-like object, typed-array-like, or a Buffer. Value: `%s`.', buffer ) ); } else if ( buffer.get && buffer.set && ( !isFunction( buffer.get ) || !isFunction( buffer.set ) ) ) { // eslint-disable-line max-len - throw new TypeError( 'invalid argument. `buffer` argument `get` and `set` properties must be functions. Value: `' + buffer + '`.' ); + throw new TypeError( format( 'invalid argument. `buffer` argument `get` and `set` properties must be functions. Value: `%s`.', buffer ) ); } if ( !isNonNegativeIntegerArray( shape ) ) { if ( !isCollection( shape) || shape.length > 0 ) { - throw new TypeError( 'invalid argument. `shape` argument must be an array-like object containing nonnegative integers. Value: `' + shape + '`.' ); + throw new TypeError( format( 'invalid argument. `shape` argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) ); } } ndims = shape.length; @@ -128,7 +129,7 @@ function ndarray( dtype, buffer, shape, strides, offset, order, options ) { throw new RangeError( 'invalid argument. Number of dimensions must not exceed ' + MAX_DIMS + ' due to stack limits. Value: `' + ndims + '`.' ); } if ( !isIntegerArray( strides ) ) { - throw new TypeError( 'invalid argument. `strides` argument must be an array-like object containing integers. Value: `' + strides + '`.' ); + throw new TypeError( format( 'invalid argument. `strides` argument must be an array-like object containing integers. Value: `%s`.', strides ) ); } if ( ndims > 0 ) { if ( strides.length !== ndims ) { @@ -140,10 +141,10 @@ function ndarray( dtype, buffer, shape, strides, offset, order, options ) { throw new RangeError( 'invalid argument. `strides` argument must contain a single element equal to `0`. Value: `' + strides[ 0 ] + '`.' ); } if ( !isNonNegativeInteger( offset ) ) { - throw new TypeError( 'invalid argument. `offset` argument must be a nonnegative integer. Value: `' + offset + '`.' ); + throw new TypeError( format( 'invalid argument. `offset` argument must be a nonnegative integer. Value: `%s`.', offset ) ); } if ( !isOrder( order ) ) { - throw new TypeError( 'invalid argument. `order` argument must be a supported order. Value: `' + order + '`.' ); + throw new TypeError( format( 'invalid argument. `order` argument must be a supported order. Value: `%s`.', order ) ); } if ( ndims > 0 && !isBufferLengthCompatible( buffer.length, shape, strides, offset ) && numel( shape ) > 0 ) { // eslint-disable-line max-len throw new Error( 'invalid arguments. The input buffer is incompatible with the specified meta data. Ensure that the offset is valid with regard to the strides array and that the buffer has enough elements to satisfy the desired array shape.' ); diff --git a/ctor/lib/validate.js b/ctor/lib/validate.js index 30774d8d..635b9c1a 100644 --- a/ctor/lib/validate.js +++ b/ctor/lib/validate.js @@ -81,7 +81,7 @@ function validate( opts, options ) { if ( hasOwnProp( options, 'readonly' ) ) { opts.readonly = options.readonly; if ( !isBoolean( opts.readonly ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean primitive. Option: `%s`.', 'readonly', opts.readonly ) ); + return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', opts.readonly ) ); } } return null;