From 7935ed32be37760d772fbe093038161acb84162f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 9 Jun 2025 00:32:55 +0000 Subject: [PATCH] Transform error messages --- lib/from_iterator.js | 4 +- lib/from_iterator_map.js | 4 +- lib/main.js | 219 +++++++++++++++++++-------------------- package.json | 2 +- 4 files changed, 112 insertions(+), 117 deletions(-) diff --git a/lib/from_iterator.js b/lib/from_iterator.js index a942fd6..5dab2ea 100644 --- a/lib/from_iterator.js +++ b/lib/from_iterator.js @@ -22,7 +22,7 @@ var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); var isComplexLike = require( '@stdlib/assert-is-complex-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var real = require( '@stdlib/complex-float64-real' ); var imag = require( '@stdlib/complex-float64-imag' ); @@ -53,7 +53,7 @@ function fromIterator( it ) { } else if ( isComplexLike( z ) ) { out.push( real( z ), imag( 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( '00P24', z ) ); } } return out; diff --git a/lib/from_iterator_map.js b/lib/from_iterator_map.js index 3dbefc8..670f558 100644 --- a/lib/from_iterator_map.js +++ b/lib/from_iterator_map.js @@ -22,7 +22,7 @@ var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); var isComplexLike = require( '@stdlib/assert-is-complex-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var real = require( '@stdlib/complex-float64-real' ); var imag = require( '@stdlib/complex-float64-imag' ); @@ -58,7 +58,7 @@ function fromIteratorMap( it, clbk, thisArg ) { } else if ( isComplexLike( z ) ) { out.push( real( z ), imag( 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( '00P25', z ) ); } } return out; diff --git a/lib/main.js b/lib/main.js index 430816c..203f266 100644 --- a/lib/main.js +++ b/lib/main.js @@ -49,7 +49,7 @@ var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); var getter = require( '@stdlib/array-base-getter' ); var accessorGetter = require( '@stdlib/array-base-accessor-getter' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var fromIterator = require( './from_iterator.js' ); var fromIteratorMap = require( './from_iterator_map.js' ); var fromArray = require( './from_array.js' ); @@ -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 Complex128Array || - ( - 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 Complex128Array || // 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 Complex128Array() { 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( '00P26', len ) ); } // We failed, so fall back to directly setting values... buf = new Float64Array( arguments[0] ); @@ -234,27 +229,27 @@ function Complex128Array() { } 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( '00P27', len ) ); } buf = new Float64Array( 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( '00PE9', BYTES_PER_ELEMENT, buf.byteLength ) ); } buf = new Float64Array( 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( '00P29', 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( '00P2A', 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 ) ); + throw new TypeError( format( '00P2A', buf ) ); } buf = fromIterator( buf ); if ( buf instanceof Error ) { @@ -262,33 +257,33 @@ function Complex128Array() { } buf = new Float64Array( 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( '00P2A', 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( '00P2B', 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( '00P2C', 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( '00PEA', 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( '00P2E', BYTES_PER_ELEMENT, len ) ); } buf = new Float64Array( 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( '00P2F', 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( '00P2G', len*BYTES_PER_ELEMENT ) ); } buf = new Float64Array( buf, byteOffset, len*2 ); } @@ -392,16 +387,16 @@ setReadOnly( Complex128Array, '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('00P01') ); } if ( !isComplexArrayConstructor( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00P02') ); } 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( '00P2H', clbk ) ); } if ( nargs > 2 ) { thisArg = arguments[ 2 ]; @@ -422,7 +417,7 @@ setReadOnly( Complex128Array, '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( '00P25', v ) ); } j += 2; // stride } @@ -450,7 +445,7 @@ setReadOnly( Complex128Array, '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 two. Length: `%u`.', len ) ); + throw new RangeError( format( '00P2I', len ) ); } out = new this( len/2 ); buf = out._buffer; // eslint-disable-line no-underscore-dangle @@ -472,7 +467,7 @@ setReadOnly( Complex128Array, '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( '00P25', v ) ); } j += 2; // stride } @@ -483,7 +478,7 @@ setReadOnly( Complex128Array, '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( '00P2J', src ) ); } if ( clbk ) { tmp = fromIteratorMap( buf, clbk, thisArg ); @@ -501,7 +496,7 @@ setReadOnly( Complex128Array, '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( '00P2J', src ) ); }); /** @@ -526,10 +521,10 @@ setReadOnly( Complex128Array, '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('00P01') ); } if ( !isComplexArrayConstructor( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00P02') ); } args = []; for ( i = 0; i < arguments.length; i++ ) { @@ -594,10 +589,10 @@ setReadOnly( Complex128Array, 'of', function of() { */ setReadOnly( Complex128Array.prototype, 'at', function at( idx ) { if ( !isComplexArray( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00P02') ); } if ( !isInteger( idx ) ) { - throw new TypeError( format( 'invalid argument. Must provide an integer. Value: `%s`.', idx ) ); + throw new TypeError( format( '00P8A', idx ) ); } if ( idx < 0 ) { idx += this._length; @@ -718,7 +713,7 @@ setReadOnly( Complex128Array.prototype, 'BYTES_PER_ELEMENT', Complex128Array.BYT */ setReadOnly( Complex128Array.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('00P02') ); } // 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 ) { @@ -773,7 +768,7 @@ setReadOnly( Complex128Array.prototype, 'entries', function entries() { var i; var j; if ( !isComplexArray( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00P02') ); } self = this; buffer = this._buffer; @@ -879,10 +874,10 @@ setReadOnly( Complex128Array.prototype, 'every', function every( predicate, this var buf; var i; if ( !isComplexArray( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00P02') ); } if ( !isFunction( predicate ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) ); + throw new TypeError( format( '00P3c', predicate ) ); } buf = this._buffer; for ( i = 0; i < this._length; i++ ) { @@ -942,16 +937,16 @@ setReadOnly( Complex128Array.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('00P02') ); } if ( !isComplexLike( value ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a complex number. Value: `%s`.', value ) ); + throw new TypeError( format( '00PFG', 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( '00P7f', start ) ); } if ( start < 0 ) { start += len; @@ -961,7 +956,7 @@ setReadOnly( Complex128Array.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( '00P2z', end ) ); } if ( end < 0 ) { end += len; @@ -1036,10 +1031,10 @@ setReadOnly( Complex128Array.prototype, 'filter', function filter( predicate, th var i; var z; if ( !isComplexArray( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00P02') ); } if ( !isFunction( predicate ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) ); + throw new TypeError( format( '00P3c', predicate ) ); } buf = this._buffer; out = []; @@ -1092,10 +1087,10 @@ setReadOnly( Complex128Array.prototype, 'find', function find( predicate, thisAr var i; var z; if ( !isComplexArray( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00P02') ); } if ( !isFunction( predicate ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) ); + throw new TypeError( format( '00P3c', predicate ) ); } buf = this._buffer; for ( i = 0; i < this._length; i++ ) { @@ -1140,10 +1135,10 @@ setReadOnly( Complex128Array.prototype, 'findIndex', function findIndex( predica var i; var z; if ( !isComplexArray( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00P02') ); } if ( !isFunction( predicate ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) ); + throw new TypeError( format( '00P3c', predicate ) ); } buf = this._buffer; for ( i = 0; i < this._length; i++ ) { @@ -1195,10 +1190,10 @@ setReadOnly( Complex128Array.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('00P02') ); } if ( !isFunction( predicate ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) ); + throw new TypeError( format( '00P3c', predicate ) ); } buf = this._buffer; for ( i = this._length-1; i >= 0; i-- ) { @@ -1243,10 +1238,10 @@ setReadOnly( Complex128Array.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('00P02') ); } if ( !isFunction( predicate ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) ); + throw new TypeError( format( '00P3c', predicate ) ); } buf = this._buffer; for ( i = this._length-1; i >= 0; i-- ) { @@ -1289,10 +1284,10 @@ setReadOnly( Complex128Array.prototype, 'forEach', function forEach( fcn, thisAr var i; var z; if ( !isComplexArray( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00P02') ); } if ( !isFunction( fcn ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', fcn ) ); + throw new TypeError( format( '00P3c', fcn ) ); } buf = this._buffer; for ( i = 0; i < this._length; i++ ) { @@ -1342,10 +1337,10 @@ setReadOnly( Complex128Array.prototype, 'forEach', function forEach( fcn, thisAr */ setReadOnly( Complex128Array.prototype, 'get', function get( idx ) { if ( !isComplexArray( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00P02') ); } if ( !isNonNegativeInteger( idx ) ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', idx ) ); + throw new TypeError( format( '00P2K', idx ) ); } if ( idx >= this._length ) { return; @@ -1411,14 +1406,14 @@ setReadOnly( Complex128Array.prototype, 'includes', function includes( searchEle var im; var i; if ( !isComplexArray( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00P02') ); } if ( !isComplexLike( searchElement ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a complex number. Value: `%s`.', searchElement ) ); + throw new TypeError( format( '00PFG', 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( '00P7f', fromIndex ) ); } if ( fromIndex < 0 ) { fromIndex += this._length; @@ -1481,14 +1476,14 @@ setReadOnly( Complex128Array.prototype, 'indexOf', function indexOf( searchEleme var im; var i; if ( !isComplexArray( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00P02') ); } if ( !isComplexLike( searchElement ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a complex number. Value: `%s`.', searchElement ) ); + throw new TypeError( format( '00PFG', 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( '00P7f', fromIndex ) ); } if ( fromIndex < 0 ) { fromIndex += this._length; @@ -1540,14 +1535,14 @@ setReadOnly( Complex128Array.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('00P02') ); } 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( '00P3F', separator ) ); } out = []; buf = this._buffer; @@ -1590,7 +1585,7 @@ setReadOnly( Complex128Array.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('00P02') ); } self = this; len = this._length; @@ -1701,14 +1696,14 @@ setReadOnly( Complex128Array.prototype, 'lastIndexOf', function lastIndexOf( sea var im; var i; if ( !isComplexArray( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00P02') ); } if ( !isComplexLike( searchElement ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a complex number. Value: `%s`.', searchElement ) ); + throw new TypeError( format( '00PFG', 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( '00P7f', fromIndex ) ); } if ( fromIndex >= this._length ) { fromIndex = this._length - 1; @@ -1776,10 +1771,10 @@ setReadOnly( Complex128Array.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('00P02') ); } if ( !isFunction( fcn ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', fcn ) ); + throw new TypeError( format( '00P3c', fcn ) ); } buf = this._buffer; out = new this.constructor( this._length ); @@ -1793,7 +1788,7 @@ setReadOnly( Complex128Array.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( '00P25', v ) ); } } return out; @@ -1840,10 +1835,10 @@ setReadOnly( Complex128Array.prototype, 'reduce', function reduce( reducer, init var i; if ( !isComplexArray( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00P02') ); } if ( !isFunction( reducer ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', reducer ) ); + throw new TypeError( format( '00P3c', reducer ) ); } buf = this._buffer; len = this._length; @@ -1905,10 +1900,10 @@ setReadOnly( Complex128Array.prototype, 'reduceRight', function reduceRight( red var i; if ( !isComplexArray( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00P02') ); } if ( !isFunction( reducer ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', reducer ) ); + throw new TypeError( format( '00P3c', reducer ) ); } buf = this._buffer; len = this._length; @@ -1986,7 +1981,7 @@ setReadOnly( Complex128Array.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('00P02') ); } len = this._length; buf = this._buffer; @@ -2077,20 +2072,20 @@ setReadOnly( Complex128Array.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('00P02') ); } 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( '00P2L', 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( '00P2M', idx ) ); } idx *= 2; buf[ idx ] = real( value ); @@ -2100,7 +2095,7 @@ setReadOnly( Complex128Array.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('00P03') ); } sbuf = value._buffer; @@ -2142,10 +2137,10 @@ setReadOnly( Complex128Array.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( '00P26', 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('00P03') ); } sbuf = value; @@ -2178,7 +2173,7 @@ setReadOnly( Complex128Array.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('00P03') ); } idx *= 2; for ( i = 0; i < N; i++ ) { @@ -2189,7 +2184,7 @@ setReadOnly( Complex128Array.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( '00P2N', value ) ); /* eslint-enable no-underscore-dangle */ }); @@ -2276,7 +2271,7 @@ setReadOnly( Complex128Array.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('00P02') ); } buf = this._buffer; len = this._length; @@ -2285,7 +2280,7 @@ setReadOnly( Complex128Array.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( '00P7e', start ) ); } if ( start < 0 ) { start += len; @@ -2297,7 +2292,7 @@ setReadOnly( Complex128Array.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( '00P7f', end ) ); } if ( end < 0 ) { end += len; @@ -2357,10 +2352,10 @@ setReadOnly( Complex128Array.prototype, 'some', function some( predicate, thisAr var buf; var i; if ( !isComplexArray( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00P02') ); } if ( !isFunction( predicate ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) ); + throw new TypeError( format( '00P3c', predicate ) ); } buf = this._buffer; for ( i = 0; i < this._length; i++ ) { @@ -2453,10 +2448,10 @@ setReadOnly( Complex128Array.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('00P02') ); } if ( !isFunction( compareFcn ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', compareFcn ) ); + throw new TypeError( format( '00P3c', compareFcn ) ); } buf = this._buffer; len = this._length; @@ -2551,7 +2546,7 @@ setReadOnly( Complex128Array.prototype, 'subarray', function subarray( begin, en var buf; var len; if ( !isComplexArray( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00P02') ); } buf = this._buffer; len = this._length; @@ -2560,7 +2555,7 @@ setReadOnly( Complex128Array.prototype, 'subarray', function subarray( begin, en 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( '00P7e', begin ) ); } if ( begin < 0 ) { begin += len; @@ -2572,7 +2567,7 @@ setReadOnly( Complex128Array.prototype, 'subarray', function subarray( begin, en 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( '00P7f', end ) ); } if ( end < 0 ) { end += len; @@ -2626,7 +2621,7 @@ setReadOnly( Complex128Array.prototype, 'toLocaleString', function toLocaleStrin var buf; var i; if ( !isComplexArray( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00P02') ); } if ( arguments.length === 0 ) { loc = []; @@ -2640,7 +2635,7 @@ setReadOnly( Complex128Array.prototype, 'toLocaleString', function toLocaleStrin } 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( '00P2V', options ) ); } buf = this._buffer; out = []; @@ -2707,7 +2702,7 @@ setReadOnly( Complex128Array.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('00P02') ); } len = this._length; out = new this.constructor( len ); @@ -2802,10 +2797,10 @@ setReadOnly( Complex128Array.prototype, 'toSorted', function toSorted( compareFc var len; var i; if ( !isComplexArray( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a complex number array.' ); + throw new TypeError( format('00P02') ); } if ( !isFunction( compareFcn ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', compareFcn ) ); + throw new TypeError( format( '00P3c', compareFcn ) ); } buf = this._buffer; len = this._length; @@ -2840,7 +2835,7 @@ setReadOnly( Complex128Array.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('00P02') ); } out = []; buf = this._buffer; @@ -2898,7 +2893,7 @@ setReadOnly( Complex128Array.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('00P02') ); } self = this; buf = this._buffer; @@ -3009,20 +3004,20 @@ setReadOnly( Complex128Array.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('00P02') ); } if ( !isInteger( index ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an integer. Value: `%s`.', index ) ); + throw new TypeError( format( '00P7e', 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( '00PFP', index ) ); } if ( !isComplexLike( value ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a complex number. Value: `%s`.', value ) ); + throw new TypeError( format( '00PFQ', 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 f0715e1..be00af4 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",