diff --git a/lib/main.js b/lib/main.js index b322cfe..ed1aa9a 100644 --- a/lib/main.js +++ b/lib/main.js @@ -35,7 +35,7 @@ var hasIteratorSymbolSupport = require( '@stdlib/assert-has-iterator-symbol-supp var ITERATOR_SYMBOL = require( '@stdlib/symbol-iterator' ); var iterLength = require( '@stdlib/iter-length' ); var defaults = require( '@stdlib/array-defaults' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // VARIABLES // @@ -266,18 +266,18 @@ function filledarrayBy() { if ( isString( dtype ) ) { // Invoking this function with arguments `f( dtype, clbk[, thisArg] )` is not allowed (otherwise, we'd need to also allow `f( clbk[, thisArg] )`)... if ( nargs > 1 ) { - throw new TypeError( 'invalid arguments. Must provide a length, typed array, array-like object, or an iterable.' ); + throw new TypeError( format('00h05') ); } ctor = ctors( dtype ); if ( ctor === null ) { - throw new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) ); + throw new TypeError( format( '00h2Y', dtype ) ); } // Return an empty array having the specified dtype: return new ctor( 0 ); } // For all other supported invocations, we need at least two arguments... if ( nargs < 2 ) { - throw new TypeError( 'invalid arguments. Must provide a length, typed array, array-like object, or an iterable.' ); + throw new TypeError( format('00h05') ); } // At this point, we need to do some argument juggling... nargs -= 1; // henceforth, the number of available arguments is `nargs+1` @@ -292,7 +292,7 @@ function filledarrayBy() { // Check if we were provided only a callback and a "this" context.. if ( nargs === 0 ) { - throw new TypeError( 'invalid arguments. Must provide a length, typed array, array-like object, or an iterable.' ); + throw new TypeError( format('00h05') ); } } else { // "this" context is left undefined... @@ -305,12 +305,12 @@ function filledarrayBy() { nargs -= 1; clbk = arguments[ nargs ]; if ( !isFunction( clbk ) ) { - throw new TypeError( format( 'invalid argument. Callback argument must be a function. Value: `%s`.', clbk ) ); + throw new TypeError( format( '00h2b', clbk ) ); } } // If were were only provided 2 arguments and the last argument was not a function, we've been provided an insufficient number of arguments... else { - throw new TypeError( 'invalid arguments. Must provide a length, typed array, array-like object, or an iterable.' ); + throw new TypeError( format('00h05') ); } // Now that we've processed the callback arguments, let's continue working backward to see if we've been provided a `dtype` argument... nargs -= 1; @@ -322,7 +322,7 @@ function filledarrayBy() { } ctor = ctors( dtype ); if ( ctor === null ) { - throw new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) ); + throw new TypeError( format( '00h2Y', dtype ) ); } // At this point, we've resolved the output array data type, and now we can actually create the output array... if ( dtype === 'generic' ) { @@ -337,26 +337,26 @@ function filledarrayBy() { return filledArray( len, clbk, thisArg ); } if ( isArrayBuffer( arg ) ) { - throw new Error( 'invalid arguments. Creating a generic array from an ArrayBuffer is not supported.' ); + throw new Error( format('00h04') ); } if ( isObject( arg ) ) { if ( HAS_ITERATOR_SYMBOL === false ) { - throw new TypeError( format( 'invalid argument. Environment lacks Symbol.iterator support. Must provide a length, typed array, or array-like object. Value: `%s`.', arg ) ); + throw new TypeError( format( '00h2Z', arg ) ); } if ( !isFunction( arg[ ITERATOR_SYMBOL ] ) ) { - throw new TypeError( format( 'invalid argument. Must provide a length, typed array, array-like object, or an iterable. Value: `%s`.', arg ) ); + throw new TypeError( format( '00h2a', arg ) ); } arg = arg[ ITERATOR_SYMBOL ](); if ( !isFunction( arg.next ) ) { - throw new TypeError( format( 'invalid argument. Must provide a length, typed array, array-like object, or an iterable. Value: `%s`.', arg ) ); + throw new TypeError( format( '00h2a', arg ) ); } return filledArrayIterator( arg, clbk, thisArg ); } - throw new TypeError( format( 'invalid argument. Must provide a length, typed array, array-like object, or an iterable. Value: `%s`.', arg ) ); + throw new TypeError( format( '00h2a', arg ) ); } else if ( isArrayBuffer( arg ) ) { - throw new Error( 'invalid arguments. Creating a generic array from an ArrayBuffer is not supported.' ); + throw new Error( format('00h04') ); } - throw new TypeError( format( 'invalid argument. Must provide a length, typed array, array-like object, or an iterable. Value: `%s`.', arg ) ); + throw new TypeError( format( '00h2a', arg ) ); } if ( nargs === 0 ) { // length || array-like || ArrayBuffer || iterable arg = arguments[ 0 ]; @@ -368,18 +368,18 @@ function filledarrayBy() { arr = new ctor( arg ); } else if ( isObject( arg ) ) { if ( HAS_ITERATOR_SYMBOL === false ) { - throw new TypeError( format( 'invalid argument. Environment lacks Symbol.iterator support. Must provide a length, typed array, or array-like object. Value: `%s`.', arg ) ); + throw new TypeError( format( '00h2Z', arg ) ); } if ( !isFunction( arg[ ITERATOR_SYMBOL ] ) ) { - throw new TypeError( format( 'invalid argument. Must provide a length, typed array, array-like object, or an iterable. Value: `%s`.', arg ) ); + throw new TypeError( format( '00h2a', arg ) ); } arg = arg[ ITERATOR_SYMBOL ](); if ( !isFunction( arg.next ) ) { - throw new TypeError( format( 'invalid argument. Must provide a length, typed array, array-like object, or an iterable. Value: `%s`.', arg ) ); + throw new TypeError( format( '00h2a', arg ) ); } arr = new ctor( iterLength( arg ) ); } else { - throw new TypeError( format( 'invalid argument. Must provide a length, typed array, array-like object, or an iterable. Value: `%s`.', arg ) ); + throw new TypeError( format( '00h2a', arg ) ); } } else if ( nargs === 1 ) { arr = new ctor( arguments[0], arguments[1] ); // (ArrayBuffer, byteOffset) diff --git a/package.json b/package.json index 42e92b1..b5ac3ab 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,7 @@ "@stdlib/assert-is-string": "^0.2.2", "@stdlib/blas-ext-base-gfill-by": "^0.2.1", "@stdlib/iter-length": "^0.2.2", - "@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/error-tools-fmtprodmsg": "^0.2.2"