diff --git a/lib/from_iterator.js b/lib/from_iterator.js index 41c7ca4..c9ff26a 100644 --- a/lib/from_iterator.js +++ b/lib/from_iterator.js @@ -24,7 +24,7 @@ var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); var isComplexLike = require( '@stdlib/assert-is-complex-like' ); var realf = require( '@stdlib/complex-float32-real' ); var imagf = require( '@stdlib/complex-float32-imag' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -53,7 +53,7 @@ function fromIterator( it ) { } else if ( isComplexLike( z ) ) { out.push( realf( z ), imagf( z ) ); } else { - return new TypeError( format( 'invalid argument. An iterator must return either a two-element array containing real and imaginary components or a complex number. Value: `%s`.', z ) ); + return new TypeError( format( '00R24', z ) ); } } return out; diff --git a/lib/from_iterator_map.js b/lib/from_iterator_map.js index e72b6e6..c71a2c3 100644 --- a/lib/from_iterator_map.js +++ b/lib/from_iterator_map.js @@ -24,7 +24,7 @@ var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); var isComplexLike = require( '@stdlib/assert-is-complex-like' ); var realf = require( '@stdlib/complex-float32-real' ); var imagf = require( '@stdlib/complex-float32-imag' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -58,7 +58,7 @@ function fromIteratorMap( it, clbk, thisArg ) { } else if ( isComplexLike( z ) ) { out.push( realf( z ), imagf( z ) ); } else { - return new TypeError( format( 'invalid argument. Callback must return either a two-element array containing real and imaginary components or a complex number. Value: `%s`.', z ) ); + return new TypeError( format( '00R25', z ) ); } } return out; diff --git a/lib/main.js b/lib/main.js index 7952245..edf8d77 100644 --- a/lib/main.js +++ b/lib/main.js @@ -42,7 +42,7 @@ var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-propert var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); var Float32Array = require( '@stdlib/array-float32' ); var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var realf = require( '@stdlib/complex-float32-real' ); var imagf = require( '@stdlib/complex-float32-imag' ); var floor = require( '@stdlib/math-base-special-floor' ); @@ -71,21 +71,16 @@ var HAS_ITERATOR_SYMBOL = hasIteratorSymbolSupport(); * @returns {boolean} boolean indicating if a value is a complex typed array */ function isComplexArray( value ) { - return ( - value instanceof Complex64Array || - ( - typeof value === 'object' && - value !== null && - ( - value.constructor.name === 'Complex64Array' || - value.constructor.name === 'Complex128Array' - ) && - typeof value._length === 'number' && // eslint-disable-line no-underscore-dangle - - // NOTE: we don't perform a more rigorous test here for a typed array for performance reasons, as robustly checking for a typed array instance could require walking the prototype tree and performing relatively expensive constructor checks... - typeof value._buffer === 'object' // eslint-disable-line no-underscore-dangle - ) - ); + return (value instanceof Complex64Array || // eslint-disable-line no-underscore-dangle + (// eslint-disable-line no-underscore-dangle + typeof value === 'object' && + value !== null && + ( + value.constructor.name === 'Complex64Array' || + value.constructor.name === 'Complex128Array' + ) && + typeof value._length === 'number' && // NOTE: we don't perform a more rigorous test here for a typed array for performance reasons, as robustly checking for a typed array instance could require walking the prototype tree and performing relatively expensive constructor checks... + typeof value._buffer === 'object')); } /** @@ -223,7 +218,7 @@ function Complex64Array() { if ( buf === null ) { // We failed and we are now forced to allocate a new array :-( if ( !isEven( len ) ) { - throw new RangeError( format( 'invalid argument. Array-like object arguments must have a length which is a multiple of two. Length: `%u`.', len ) ); + throw new RangeError( format( '00R26', len ) ); } // We failed, so fall back to directly setting values... buf = new Float32Array( arguments[0] ); @@ -234,27 +229,27 @@ function Complex64Array() { } else if ( isComplex128Array( buf ) ) { buf = reinterpret128( buf, 0 ); } else if ( !isEven( len ) ) { - throw new RangeError( format( 'invalid argument. Array-like object and typed array arguments must have a length which is a multiple of two. Length: `%u`.', len ) ); + throw new RangeError( format( '00R27', len ) ); } buf = new Float32Array( buf ); } } else if ( isArrayBuffer( arguments[0] ) ) { buf = arguments[ 0 ]; if ( !isInteger( buf.byteLength/BYTES_PER_ELEMENT ) ) { - throw new RangeError( format( 'invalid argument. ArrayBuffer byte length must be a multiple of %u. Byte length: `%u`.', BYTES_PER_ELEMENT, buf.byteLength ) ); + throw new RangeError( format( '00RE9', BYTES_PER_ELEMENT, buf.byteLength ) ); } buf = new Float32Array( buf ); } else if ( isObject( arguments[0] ) ) { buf = arguments[ 0 ]; if ( HAS_ITERATOR_SYMBOL === false ) { - throw new TypeError( format( 'invalid argument. Environment lacks Symbol.iterator support. Must provide a length, ArrayBuffer, typed array, or array-like object. Value: `%s`.', buf ) ); + throw new TypeError( format( '00R29', buf ) ); } if ( !isFunction( buf[ ITERATOR_SYMBOL ] ) ) { - throw new TypeError( format( 'invalid argument. Must provide a length, ArrayBuffer, typed array, array-like object, or an iterable. Value: `%s`.', buf ) ); + throw new TypeError( format( '00R2A', buf ) ); } buf = buf[ ITERATOR_SYMBOL ](); if ( !isFunction( buf.next ) ) { - throw new TypeError( format( 'invalid argument. Must provide a length, ArrayBuffer, typed array, array-like object, or an iterable. Value: `%s`.', buf ) ); // FIXME: `buf` is what is returned from above, NOT the original value + throw new TypeError( format( '00R2A', buf ) ); // FIXME: `buf` is what is returned from above, NOT the original value } buf = fromIterator( buf ); if ( buf instanceof Error ) { @@ -262,33 +257,33 @@ function Complex64Array() { } buf = new Float32Array( buf ); } else { - throw new TypeError( format( 'invalid argument. Must provide a length, ArrayBuffer, typed array, array-like object, or an iterable. Value: `%s`.', arguments[0] ) ); + throw new TypeError( format( '00R2A', arguments[0] ) ); } } else { buf = arguments[ 0 ]; if ( !isArrayBuffer( buf ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ArrayBuffer. Value: `%s`.', buf ) ); + throw new TypeError( format( '00R2B', buf ) ); } byteOffset = arguments[ 1 ]; if ( !isNonNegativeInteger( byteOffset ) ) { - throw new TypeError( format( 'invalid argument. Byte offset must be a nonnegative integer. Value: `%s`.', byteOffset ) ); + throw new TypeError( format( '00R2C', byteOffset ) ); } if ( !isInteger( byteOffset/BYTES_PER_ELEMENT ) ) { - throw new RangeError( format( 'invalid argument. Byte offset must be a multiple of %u. Value: `%u`.', BYTES_PER_ELEMENT, byteOffset ) ); + throw new RangeError( format( '00REA', BYTES_PER_ELEMENT, byteOffset ) ); } if ( nargs === 2 ) { len = buf.byteLength - byteOffset; if ( !isInteger( len/BYTES_PER_ELEMENT ) ) { - throw new RangeError( format( 'invalid arguments. ArrayBuffer view byte length must be a multiple of %u. View byte length: `%u`.', BYTES_PER_ELEMENT, len ) ); + throw new RangeError( format( '00R2E', BYTES_PER_ELEMENT, len ) ); } buf = new Float32Array( buf, byteOffset ); } else { len = arguments[ 2 ]; if ( !isNonNegativeInteger( len ) ) { - throw new TypeError( format( 'invalid argument. Length must be a nonnegative integer. Value: `%s`.', len ) ); + throw new TypeError( format( '00R2F', len ) ); } if ( (len*BYTES_PER_ELEMENT) > (buf.byteLength-byteOffset) ) { - throw new RangeError( format( 'invalid arguments. ArrayBuffer has insufficient capacity. Either decrease the array length or provide a bigger buffer. Minimum capacity: `%u`.', len*BYTES_PER_ELEMENT ) ); + throw new RangeError( format( '00R2G', len*BYTES_PER_ELEMENT ) ); } buf = new Float32Array( buf, byteOffset, len*2 ); } @@ -392,16 +387,16 @@ setReadOnly( Complex64Array, 'from', function from( src ) { var i; var j; if ( !isFunction( this ) ) { - throw new TypeError( 'invalid invocation. `this` context must be a constructor.' ); + throw new TypeError( format('00R01') ); } if ( !isComplexArrayConstructor( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00R02') ); } nargs = arguments.length; if ( nargs > 1 ) { clbk = arguments[ 1 ]; if ( !isFunction( clbk ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', clbk ) ); + throw new TypeError( format( '00R2H', clbk ) ); } if ( nargs > 2 ) { thisArg = arguments[ 2 ]; @@ -422,7 +417,7 @@ setReadOnly( Complex64Array, 'from', function from( src ) { buf[ j ] = v[ 0 ]; buf[ j+1 ] = v[ 1 ]; } else { - throw new TypeError( format( 'invalid argument. Callback must return either a two-element array containing real and imaginary components or a complex number. Value: `%s`.', v ) ); + throw new TypeError( format( '00R25', v ) ); } j += 2; // stride } @@ -450,7 +445,7 @@ setReadOnly( Complex64Array, 'from', function from( src ) { // If an array does not contain only complex number objects, then we assume interleaved real and imaginary components... if ( flg ) { if ( !isEven( len ) ) { - throw new RangeError( format( 'invalid argument. First argument must have a length which is a multiple of %u. Length: `%u`.', 2, len ) ); + throw new RangeError( format( '00REB', 2, len ) ); } out = new this( len/2 ); buf = out._buffer; // eslint-disable-line no-underscore-dangle @@ -472,7 +467,7 @@ setReadOnly( Complex64Array, 'from', function from( src ) { buf[ j ] = v[ 0 ]; buf[ j+1 ] = v[ 1 ]; } else { - throw new TypeError( format( 'invalid argument. Callback must return either a two-element array containing real and imaginary components or a complex number. Value: `%s`.', v ) ); + throw new TypeError( format( '00R25', v ) ); } j += 2; // stride } @@ -483,7 +478,7 @@ setReadOnly( Complex64Array, 'from', function from( src ) { if ( isObject( src ) && HAS_ITERATOR_SYMBOL && isFunction( src[ ITERATOR_SYMBOL ] ) ) { // eslint-disable-line max-len buf = src[ ITERATOR_SYMBOL ](); if ( !isFunction( buf.next ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object or an iterable. Value: `%s`.', src ) ); + throw new TypeError( format( '00R2J', src ) ); } if ( clbk ) { tmp = fromIteratorMap( buf, clbk, thisArg ); @@ -501,7 +496,7 @@ setReadOnly( Complex64Array, 'from', function from( src ) { } return out; } - throw new TypeError( format( 'invalid argument. First argument must be an array-like object or an iterable. Value: `%s`.', src ) ); + throw new TypeError( format( '00R2J', src ) ); }); /** @@ -526,10 +521,10 @@ setReadOnly( Complex64Array, 'of', function of() { var args; var i; if ( !isFunction( this ) ) { - throw new TypeError( 'invalid invocation. `this` context must be a constructor.' ); + throw new TypeError( format('00R01') ); } if ( !isComplexArrayConstructor( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00R02') ); } args = []; for ( i = 0; i < arguments.length; i++ ) { @@ -593,10 +588,10 @@ setReadOnly( Complex64Array, 'of', function of() { */ setReadOnly( Complex64Array.prototype, 'at', function at( idx ) { if ( !isComplexArray( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00R02') ); } if ( !isInteger( idx ) ) { - throw new TypeError( format( 'invalid argument. Must provide an integer. Value: `%s`.', idx ) ); + throw new TypeError( format( '00R8A', idx ) ); } if ( idx < 0 ) { idx += this._length; @@ -717,7 +712,7 @@ setReadOnly( Complex64Array.prototype, 'BYTES_PER_ELEMENT', Complex64Array.BYTES */ setReadOnly( Complex64Array.prototype, 'copyWithin', function copyWithin( target, start ) { if ( !isComplexArray( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00R02') ); } // FIXME: prefer a functional `copyWithin` implementation which addresses lack of universal browser support (e.g., IE11 and Safari) or ensure that typed arrays are polyfilled if ( arguments.length === 2 ) { @@ -771,7 +766,7 @@ setReadOnly( Complex64Array.prototype, 'entries', function entries() { var FLG; var i; if ( !isComplexArray( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00R02') ); } self = this; buf = this._buffer; @@ -873,10 +868,10 @@ setReadOnly( Complex64Array.prototype, 'every', function every( predicate, thisA var buf; var i; if ( !isComplexArray( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00R02') ); } if ( !isFunction( predicate ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) ); + throw new TypeError( format( '00R3c', predicate ) ); } buf = this._buffer; for ( i = 0; i < this._length; i++ ) { @@ -936,16 +931,16 @@ setReadOnly( Complex64Array.prototype, 'fill', function fill( value, start, end var im; var i; if ( !isComplexArray( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00R02') ); } if ( !isComplexLike( value ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a complex number. Value: `%s`.', value ) ); + throw new TypeError( format( '00RFG', value ) ); } buf = this._buffer; len = this._length; if ( arguments.length > 1 ) { if ( !isInteger( start ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', start ) ); + throw new TypeError( format( '00R7f', start ) ); } if ( start < 0 ) { start += len; @@ -955,7 +950,7 @@ setReadOnly( Complex64Array.prototype, 'fill', function fill( value, start, end } if ( arguments.length > 2 ) { if ( !isInteger( end ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be an integer. Value: `%s`.', end ) ); + throw new TypeError( format( '00R2z', end ) ); } if ( end < 0 ) { end += len; @@ -1030,10 +1025,10 @@ setReadOnly( Complex64Array.prototype, 'filter', function filter( predicate, thi var i; var z; if ( !isComplexArray( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00R02') ); } if ( !isFunction( predicate ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) ); + throw new TypeError( format( '00R3c', predicate ) ); } buf = this._buffer; out = []; @@ -1087,10 +1082,10 @@ setReadOnly( Complex64Array.prototype, 'find', function find( predicate, thisArg var i; var z; if ( !isComplexArray( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00R02') ); } if ( !isFunction( predicate ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) ); + throw new TypeError( format( '00R3c', predicate ) ); } buf = this._buffer; for ( i = 0; i < this._length; i++ ) { @@ -1136,10 +1131,10 @@ setReadOnly( Complex64Array.prototype, 'findIndex', function findIndex( predicat var i; var z; if ( !isComplexArray( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00R02') ); } if ( !isFunction( predicate ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) ); + throw new TypeError( format( '00R3c', predicate ) ); } buf = this._buffer; for ( i = 0; i < this._length; i++ ) { @@ -1192,10 +1187,10 @@ setReadOnly( Complex64Array.prototype, 'findLast', function findLast( predicate, var i; var z; if ( !isComplexArray( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00R02') ); } if ( !isFunction( predicate ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) ); + throw new TypeError( format( '00R3c', predicate ) ); } buf = this._buffer; for ( i = this._length-1; i >= 0; i-- ) { @@ -1241,10 +1236,10 @@ setReadOnly( Complex64Array.prototype, 'findLastIndex', function findLastIndex( var i; var z; if ( !isComplexArray( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00R02') ); } if ( !isFunction( predicate ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) ); + throw new TypeError( format( '00R3c', predicate ) ); } buf = this._buffer; for ( i = this._length-1; i >= 0; i-- ) { @@ -1287,10 +1282,10 @@ setReadOnly( Complex64Array.prototype, 'forEach', function forEach( fcn, thisArg var i; var z; if ( !isComplexArray( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00R02') ); } if ( !isFunction( fcn ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', fcn ) ); + throw new TypeError( format( '00R3c', fcn ) ); } buf = this._buffer; for ( i = 0; i < this._length; i++ ) { @@ -1340,10 +1335,10 @@ setReadOnly( Complex64Array.prototype, 'forEach', function forEach( fcn, thisArg */ setReadOnly( Complex64Array.prototype, 'get', function get( idx ) { if ( !isComplexArray( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00R02') ); } if ( !isNonNegativeInteger( idx ) ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', idx ) ); + throw new TypeError( format( '00R2K', idx ) ); } if ( idx >= this._length ) { return; @@ -1391,14 +1386,14 @@ setReadOnly( Complex64Array.prototype, 'includes', function includes( searchElem var im; var i; if ( !isComplexArray( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00R02') ); } if ( !isComplexLike( searchElement ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a complex number. Value: `%s`.', searchElement ) ); + throw new TypeError( format( '00RFG', searchElement ) ); } if ( arguments.length > 1 ) { if ( !isInteger( fromIndex ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', fromIndex ) ); + throw new TypeError( format( '00R7f', fromIndex ) ); } if ( fromIndex < 0 ) { fromIndex += this._length; @@ -1461,14 +1456,14 @@ setReadOnly( Complex64Array.prototype, 'indexOf', function indexOf( searchElemen var im; var i; if ( !isComplexArray( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00R02') ); } if ( !isComplexLike( searchElement ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a complex number. Value: `%s`.', searchElement ) ); + throw new TypeError( format( '00RFG', searchElement ) ); } if ( arguments.length > 1 ) { if ( !isInteger( fromIndex ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', fromIndex ) ); + throw new TypeError( format( '00R7f', fromIndex ) ); } if ( fromIndex < 0 ) { fromIndex += this._length; @@ -1520,14 +1515,14 @@ setReadOnly( Complex64Array.prototype, 'join', function join( separator ) { var sep; var i; if ( !isComplexArray( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00R02') ); } if ( arguments.length === 0 ) { sep = ','; } else if ( isString( separator ) ) { sep = separator; } else { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', separator ) ); + throw new TypeError( format( '00R3F', separator ) ); } out = []; buf = this._buffer; @@ -1570,7 +1565,7 @@ setReadOnly( Complex64Array.prototype, 'keys', function keys() { var FLG; var i; if ( !isComplexArray( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00R02') ); } self = this; len = this._length; @@ -1681,14 +1676,14 @@ setReadOnly( Complex64Array.prototype, 'lastIndexOf', function lastIndexOf( sear var im; var i; if ( !isComplexArray( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00R02') ); } if ( !isComplexLike( searchElement ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a complex number. Value: `%s`.', searchElement ) ); + throw new TypeError( format( '00RFG', searchElement ) ); } if ( arguments.length > 1 ) { if ( !isInteger( fromIndex ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', fromIndex ) ); + throw new TypeError( format( '00R7f', fromIndex ) ); } if ( fromIndex >= this._length ) { fromIndex = this._length - 1; @@ -1774,10 +1769,10 @@ setReadOnly( Complex64Array.prototype, 'map', function map( fcn, thisArg ) { var i; var v; if ( !isComplexArray( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00R02') ); } if ( !isFunction( fcn ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', fcn ) ); + throw new TypeError( format( '00R3c', fcn ) ); } buf = this._buffer; out = new this.constructor( this._length ); @@ -1791,7 +1786,7 @@ setReadOnly( Complex64Array.prototype, 'map', function map( fcn, thisArg ) { outbuf[ 2*i ] = v[ 0 ]; outbuf[ (2*i)+1 ] = v[ 1 ]; } else { - throw new TypeError( format( 'invalid argument. Callback must return either a two-element array containing real and imaginary components or a complex number. Value: `%s`.', v ) ); + throw new TypeError( format( '00R25', v ) ); } } return out; @@ -1838,10 +1833,10 @@ setReadOnly( Complex64Array.prototype, 'reduce', function reduce( reducer, initi var i; if ( !isComplexArray( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00R02') ); } if ( !isFunction( reducer ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', reducer ) ); + throw new TypeError( format( '00R3c', reducer ) ); } buf = this._buffer; len = this._length; @@ -1903,10 +1898,10 @@ setReadOnly( Complex64Array.prototype, 'reduceRight', function reduceRight( redu var i; if ( !isComplexArray( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00R02') ); } if ( !isFunction( reducer ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', reducer ) ); + throw new TypeError( format( '00R3c', reducer ) ); } buf = this._buffer; len = this._length; @@ -1984,7 +1979,7 @@ setReadOnly( Complex64Array.prototype, 'reverse', function reverse() { var i; var j; if ( !isComplexArray( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00R02') ); } len = this._length; buf = this._buffer; @@ -2075,20 +2070,20 @@ setReadOnly( Complex64Array.prototype, 'set', function set( value ) { var i; var j; if ( !isComplexArray( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00R02') ); } buf = this._buffer; if ( arguments.length > 1 ) { idx = arguments[ 1 ]; if ( !isNonNegativeInteger( idx ) ) { - throw new TypeError( format( 'invalid argument. Index argument must be a nonnegative integer. Value: `%s`.', idx ) ); + throw new TypeError( format( '00R2L', idx ) ); } } else { idx = 0; } if ( isComplexLike( value ) ) { if ( idx >= this._length ) { - throw new RangeError( format( 'invalid argument. Index argument is out-of-bounds. Value: `%u`.', idx ) ); + throw new RangeError( format( '00R2M', idx ) ); } idx *= 2; buf[ idx ] = realf( value ); @@ -2098,7 +2093,7 @@ setReadOnly( Complex64Array.prototype, 'set', function set( value ) { if ( isComplexArray( value ) ) { N = value._length; if ( idx+N > this._length ) { - throw new RangeError( 'invalid arguments. Target array lacks sufficient storage to accommodate source values.' ); + throw new RangeError( format('00R03') ); } sbuf = value._buffer; @@ -2140,10 +2135,10 @@ setReadOnly( Complex64Array.prototype, 'set', function set( value ) { // If an array does not contain only complex numbers, then we assume interleaved real and imaginary components... if ( flg ) { if ( !isEven( N ) ) { - throw new RangeError( format( 'invalid argument. Array-like object arguments must have a length which is a multiple of two. Length: `%u`.', N ) ); + throw new RangeError( format( '00R26', N ) ); } if ( idx+(N/2) > this._length ) { - throw new RangeError( 'invalid arguments. Target array lacks sufficient storage to accommodate source values.' ); + throw new RangeError( format('00R03') ); } sbuf = value; @@ -2176,7 +2171,7 @@ setReadOnly( Complex64Array.prototype, 'set', function set( value ) { } // If an array contains only complex numbers, then we need to extract real and imaginary components... if ( idx+N > this._length ) { - throw new RangeError( 'invalid arguments. Target array lacks sufficient storage to accommodate source values.' ); + throw new RangeError( format('00R03') ); } idx *= 2; for ( i = 0; i < N; i++ ) { @@ -2187,7 +2182,7 @@ setReadOnly( Complex64Array.prototype, 'set', function set( value ) { } return; } - throw new TypeError( format( 'invalid argument. First argument must be either a complex number, an array-like object, or a complex number array. Value: `%s`.', value ) ); + throw new TypeError( format( '00R2N', value ) ); /* eslint-enable no-underscore-dangle */ }); @@ -2274,7 +2269,7 @@ setReadOnly( Complex64Array.prototype, 'slice', function slice( start, end ) { var len; var i; if ( !isComplexArray( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00R02') ); } buf = this._buffer; len = this._length; @@ -2283,7 +2278,7 @@ setReadOnly( Complex64Array.prototype, 'slice', function slice( start, end ) { end = len; } else { if ( !isInteger( start ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an integer. Value: `%s`.', start ) ); + throw new TypeError( format( '00R7e', start ) ); } if ( start < 0 ) { start += len; @@ -2295,7 +2290,7 @@ setReadOnly( Complex64Array.prototype, 'slice', function slice( start, end ) { end = len; } else { if ( !isInteger( end ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', end ) ); + throw new TypeError( format( '00R7f', end ) ); } if ( end < 0 ) { end += len; @@ -2355,10 +2350,10 @@ setReadOnly( Complex64Array.prototype, 'some', function some( predicate, thisArg var buf; var i; if ( !isComplexArray( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00R02') ); } if ( !isFunction( predicate ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) ); + throw new TypeError( format( '00R3c', predicate ) ); } buf = this._buffer; for ( i = 0; i < this._length; i++ ) { @@ -2451,10 +2446,10 @@ setReadOnly( Complex64Array.prototype, 'sort', function sort( compareFcn ) { var i; var j; if ( !isComplexArray( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00R02') ); } if ( !isFunction( compareFcn ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', compareFcn ) ); + throw new TypeError( format( '00R3c', compareFcn ) ); } buf = this._buffer; len = this._length; @@ -2549,7 +2544,7 @@ setReadOnly( Complex64Array.prototype, 'subarray', function subarray( begin, end var buf; var len; if ( !isComplexArray( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00R02') ); } buf = this._buffer; len = this._length; @@ -2558,7 +2553,7 @@ setReadOnly( Complex64Array.prototype, 'subarray', function subarray( begin, end end = len; } else { if ( !isInteger( begin ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an integer. Value: `%s`.', begin ) ); + throw new TypeError( format( '00R7e', begin ) ); } if ( begin < 0 ) { begin += len; @@ -2570,7 +2565,7 @@ setReadOnly( Complex64Array.prototype, 'subarray', function subarray( begin, end end = len; } else { if ( !isInteger( end ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', end ) ); + throw new TypeError( format( '00R7f', end ) ); } if ( end < 0 ) { end += len; @@ -2624,7 +2619,7 @@ setReadOnly( Complex64Array.prototype, 'toLocaleString', function toLocaleString var buf; var i; if ( !isComplexArray( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00R02') ); } if ( arguments.length === 0 ) { loc = []; @@ -2638,7 +2633,7 @@ setReadOnly( Complex64Array.prototype, 'toLocaleString', function toLocaleString } else if ( isObject( options ) ) { opts = options; } else { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '00R2V', options ) ); } buf = this._buffer; out = []; @@ -2705,7 +2700,7 @@ setReadOnly( Complex64Array.prototype, 'toReversed', function toReversed() { var i; var j; if ( !isComplexArray( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00R02') ); } len = this._length; out = new this.constructor( len ); @@ -2800,10 +2795,10 @@ setReadOnly( Complex64Array.prototype, 'toSorted', function toSorted( compareFcn var len; var i; if ( !isComplexArray( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00R02') ); } if ( !isFunction( compareFcn ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', compareFcn ) ); + throw new TypeError( format( '00R3c', compareFcn ) ); } buf = this._buffer; len = this._length; @@ -2838,7 +2833,7 @@ setReadOnly( Complex64Array.prototype, 'toString', function toString() { var buf; var i; if ( !isComplexArray( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00R02') ); } out = []; buf = this._buffer; @@ -2896,7 +2891,7 @@ setReadOnly( Complex64Array.prototype, 'values', function values() { var buf; var i; if ( !isComplexArray( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00R02') ); } self = this; buf = this._buffer; @@ -3007,20 +3002,20 @@ setReadOnly( Complex64Array.prototype, 'with', function copyWith( index, value ) var out; var len; if ( !isComplexArray( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00R02') ); } if ( !isInteger( index ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an integer. Value: `%s`.', index ) ); + throw new TypeError( format( '00R7e', index ) ); } len = this._length; if ( index < 0 ) { index += len; } if ( index < 0 || index >= len ) { - throw new RangeError( format( 'invalid argument. Index argument is out-of-bounds. Value: `%s`.', index ) ); + throw new RangeError( format( '00RFP', index ) ); } if ( !isComplexLike( value ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a complex number. Value: `%s`.', value ) ); + throw new TypeError( format( '00RFQ', value ) ); } out = new this.constructor( this._buffer ); buf = out._buffer; // eslint-disable-line no-underscore-dangle diff --git a/package.json b/package.json index 31c497c..8bc6caf 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "@stdlib/math-base-special-floor": "^0.2.3", "@stdlib/strided-base-reinterpret-complex128": "^0.2.2", "@stdlib/strided-base-reinterpret-complex64": "^0.2.1", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/symbol-iterator": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.3",