8000 Transform error messages · stdlib-js/array-bool@da9ba64 · GitHub
[go: up one dir, main page]

Skip to content

Commit da9ba64

Browse files
committed
Transform error messages
1 parent 9d2eb77 commit da9ba64

File tree

2 files changed

+47
-47
lines changed

2 files changed

+47
-47
lines changed

lib/main.js

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ var Boolean = require( '@stdlib/boolean-ctor' );
4040
var getter = require( '@stdlib/array-base-getter' );
4141
var floor = require( '@stdlib/math-base-special-floor' );
4242
var accessorGetter = require( '@stdlib/array-base-accessor-getter' );
43-
var format = require( '@stdlib/string-format' );
43+
var format = require( '@stdlib/error-tools-fmtprodmsg' );
4444
var fromIterator = require( './from_iterator.js' );
4545
var fromIteratorMap = require( './from_iterator_map.js' );
4646
var fromArray = require( './from_array.js' );
@@ -180,37 +180,37 @@ function BooleanArray() {
180180
buf = new Uint8Array( arg );
181181
} else if ( isObject( arg ) ) {
182182
if ( HAS_ITERATOR_SYMBOL === false ) {
183-
throw new TypeError( format( 'invalid argument. Environment lacks Symbol.iterator support. Must provide a length, ArrayBuffer, typed array, or array-like object. Value: `%s`.', arg ) );
183+
throw new TypeError( format( 'null29', arg ) );
184184
}
185185
if ( !isFunction( arg[ ITERATOR_SYMBOL ] ) ) {
186-
throw new TypeError( format( 'invalid argument. Must provide a length, ArrayBuffer, typed array, array-like object, or an iterable. Value: `%s`.', arg ) );
186+
throw new TypeError( format( 'null2A', arg ) );
187187
}
188188
buf = arg[ ITERATOR_SYMBOL ]();
189189
if ( !isFunction( buf.next ) ) {
190-
throw new TypeError( format( 'invalid argument. Must provide a length, ArrayBuffer, typed array, array-like object, or an iterable. Value: `%s`.', arg ) );
190+
throw new TypeError( format( 'null2A', arg ) );
191191
}
192192
buf = new Uint8Array( fromIterator( buf ) );
193193
} else {
194-
throw new TypeError( format( 'invalid argument. Must provide a length, ArrayBuffer, typed array, array-like object, or an iterable. Value: `%s`.', arg ) );
194+
throw new TypeError( format( 'null2A', arg ) );
195195
}
196196
} else {
197197
buf = arguments[ 0 ];
198198
if ( !isArrayBuffer( buf ) ) {
199-
throw new TypeError( format( 'invalid argument. First argument must be an ArrayBuffer. Value: `%s`.', buf ) );
199+
throw new TypeError( format( 'null2B', buf ) );
200200
}
201201
byteOffset = arguments[ 1 ];
202202
if ( !isNonNegativeInteger( byteOffset ) ) {
203-
throw new TypeError( format( 'invalid argument. Byte offset must be a nonnegative integer. Value: `%s`.', byteOffset ) );
203+
throw new TypeError( format( 'null2C', byteOffset ) );
204204
}
205205
if ( nargs === 2 ) {
206206
buf = new Uint8Array( buf, byteOffset );
207207
} else {
208208
len = arguments[ 2 ];
209209
if ( !isNonNegativeInteger( len ) ) {
210-
throw new TypeError( format( 'invalid argument. Length must be a nonnegative integer. Value: `%s`.', len ) );
210+
throw new TypeError( format( 'null2F', len ) );
211211
}
212212
if ( (len*BYTES_PER_ELEMENT) > (buf.byteLength-byteOffset) ) {
213-
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 ) );
213+
throw new RangeError( format( 'null2G', len*BYTES_PER_ELEMENT ) );
214214
}
215215
buf = new Uint8Array( buf, byteOffset, len );
216216
}
@@ -295,7 +295,7 @@ setReadOnly( BooleanArray, 'from', function from( src ) {
295295
var len;
296296
var i;
297297
if ( !isFunction( this ) ) {
298-
throw new TypeError( 'invalid invocation. `this` context must be a constructor.' );
298+
throw new TypeError( format('null01') );
299299
}
300300
if ( !isBooleanArrayConstructor( this ) ) {
301301
throw new TypeError( 'invalid invocation. `this` is not a boolean array.' );
@@ -304,7 +304,7 @@ setReadOnly( BooleanArray, 'from', function from( src ) {
304304
if ( nargs > 1 ) {
305305
clbk = arguments[ 1 ];
306306
if ( !isFunction( clbk ) ) {
307-
throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', clbk ) );
307+
throw new TypeError( format( 'null2H', clbk ) );
308308
}
309309
if ( nargs > 2 ) {
310310
thisArg = arguments[ 2 ];
@@ -330,7 +330,7 @@ setReadOnly( BooleanArray, 'from', function from( src ) {
330330
if ( isObject( src ) && HAS_ITERATOR_SYMBOL && isFunction( src[ ITERATOR_SYMBOL ] ) ) { // eslint-disable-line max-len
331331
buf = src[ ITERATOR_SYMBOL ]();
332332
if ( !isFunction( buf.next ) ) {
333-
throw new TypeError( format( 'invalid argument. First argument must be an array-like object or an iterable. Value: `%s`.', src ) );
333+
throw new TypeError( format( 'null2J', src ) );
334334
}
335335
if ( clbk ) {
336336
tmp = fromIteratorMap( buf, clbk, thisArg );
@@ -345,7 +345,7 @@ setReadOnly( BooleanArray, 'from', function from( src ) {
345345
}
346346
return out;
347347
}
348-
throw new TypeError( format( 'invalid argument. First argument must be an array-like object or an iterable. Value: `%s`.', src ) );
348+
throw new TypeError( format( 'null2J', src ) );
349349
});
350350

351351
/**
@@ -370,7 +370,7 @@ setReadOnly( BooleanArray, 'of', function of() {
370370
var args;
371371
var i;
372372
if ( !isFunction( this ) ) {
373-
throw new TypeError( 'invalid invocation. `this` context must be a constructor.' );
373+
throw new TypeError( format('null01') );
374374
}
375375
if ( !isBooleanArrayConstructor( this ) ) {
376376
throw new TypeError( 'invalid invocation. `this` is not a boolean array.' );
@@ -417,7 +417,7 @@ setReadOnly( BooleanArray.prototype, 'at', function at( idx ) {
417417
throw new TypeError( 'invalid invocation. `this` is not a boolean array.' );
418418
}
419419
if ( !isInteger( idx ) ) {
420-
throw new TypeError( format( 'invalid argument. Must provide an integer. Value: `%s`.', idx ) );
420+
throw new TypeError( format( 'null8A', idx ) );
421421
}
422422
len = this._length;
423423
buf = this._buffer;
@@ -685,7 +685,7 @@ setReadOnly( BooleanArray.prototype, 'every', function every( predicate, thisArg
685685
throw new TypeError( 'invalid invocation. `this` is not a boolean array.' );
686686
}
687687
if ( !isFunction( predicate ) ) {
688-
throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) );
688+
throw new TypeError( format( 'null3c', predicate ) );
689689
}
690690
buf = this._buffer;
691691
for ( i = 0; i < this._length; i++ ) {
@@ -741,7 +741,7 @@ setReadOnly( BooleanArray.prototype, 'fill', function fill( value, start, end )
741741
len = this._length;
742742
if ( arguments.length > 1 ) {
743743
if ( !isInteger( start ) ) {
744-
throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', start ) );
744+
throw new TypeError( format( 'null7f', start ) );
745745
}
746746
if ( start < 0 ) {
747747
start += len;
@@ -751,7 +751,7 @@ setReadOnly( BooleanArray.prototype, 'fill', function fill( value, start, end )
751751
}
752752
if ( arguments.length > 2 ) {
753753
if ( !isInteger( end ) ) {
754-
throw new TypeError( format( 'invalid argument. Third argument must be an integer. Value: `%s`.', end ) );
754+
throw new TypeError( format( 'null2z', end ) );
755755
}
756756
if ( end < 0 ) {
757757
end += len;
@@ -825,7 +825,7 @@ setReadOnly( BooleanArray.prototype, 'filter', function filter( predicate, thisA
825825
throw new TypeError( 'invalid invocation. `this` is not a boolean array.' );
826826
}
827827
if ( !isFunction( predicate ) ) {
828-
throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) );
828+
throw new TypeError( format( 'null3c', predicate ) );
829829
}
830830
buf = this._buffer;
831831
out = [];
@@ -873,7 +873,7 @@ setReadOnly( BooleanArray.prototype, 'find', function find( predicate, thisArg )
873873
throw new TypeError( 'invalid invocation. `this` is not a boolean array.' );
874874
}
875875
if ( !isFunction( predicate ) ) {
876-
throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) );
876+
throw new TypeError( format( 'null3c', predicate ) );
877877
}
878878
buf = this._buffer;
879879
for ( i = 0; i < this._length; i++ ) {
@@ -919,7 +919,7 @@ setReadOnly( BooleanArray.prototype, 'findIndex', function findIndex( predicate,
919919
throw new TypeError( 'invalid invocation. `this` is not a boolean array.' );
920920
}
921921
if ( !isFunction( predicate ) ) {
922-
throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) );
922+
throw new TypeError( format( 'null3c', predicate ) );
923923
}
924924
buf = this._buffer;
925925
for ( i = 0; i < this._length; i++ ) {
@@ -966,7 +966,7 @@ setReadOnly( BooleanArray.prototype, 'findLast', function findLast( predicate, t
966966
throw new TypeError( 'invalid invocation. `this` is not a boolean array.' );
967967
}
968968
if ( !isFunction( predicate ) ) {
969-
throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) );
969+
throw new TypeError( format( 'null3c', predicate ) );
970970
}
971971
buf = this._buffer;
972972
for ( i = this._length-1; i >= 0; i-- ) {
@@ -1012,7 +1012,7 @@ setReadOnly( BooleanArray.prototype, 'findLastIndex', function findLastIndex( pr
10121012
throw new TypeError( 'invalid invocation. `this` is not a boolean array.' );
10131013
}
10141014
if ( !isFunction( predicate ) ) {
1015-
throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) );
1015+
throw new TypeError( format( 'null3c', predicate ) );
10161016
}
10171017
buf = this._buffer;
10181018
for ( i = this._length-1; i >= 0; i-- ) {
@@ -1056,7 +1056,7 @@ setReadOnly( BooleanArray.prototype, 'forEach', function forEach( fcn, thisArg )
10561056
throw new TypeError( 'invalid invocation. `this` is not a boolean array.' );
10571057
}
10581058
if ( !isFunction( fcn ) ) {
1059-
throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', fcn ) );
1059+
throw new TypeError( format( 'null3c', fcn ) );
10601060
}
10611061
buf = this._buffer;
10621062
for ( i = 0; i < this._length; i++ ) {
@@ -1094,7 +1094,7 @@ setReadOnly( BooleanArray.prototype, 'get', function get( idx ) {
10941094
throw new TypeError( 'invalid invocation. `this` is not a boolean array.' );
10951095
}
10961096
if ( !isNonNegativeInteger( idx ) ) {
1097-
throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', idx ) );
1097+
throw new TypeError( format( 'null2K', idx ) );
10981098
}
10991099
if ( idx >= this._length ) {
11001100
return;
@@ -1142,7 +1142,7 @@ setReadOnly( BooleanArray.prototype, 'includes', function includes( searchElemen
11421142
}
11431143
if ( arguments.length > 1 ) {
11441144
if ( !isInteger( fromIndex ) ) {
1145-
throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', fromIndex ) );
1145+
throw new TypeError( format( 'null7f', fromIndex ) );
11461146
}
11471147
if ( fromIndex < 0 ) {
11481148
fromIndex += this._length;
@@ -1205,7 +1205,7 @@ setReadOnly( BooleanArray.prototype, 'indexOf', function indexOf( searchElement,
12051205
}
12061206
if ( arguments.length > 1 ) {
12071207
if ( !isInteger( fromIndex ) ) {
1208-
throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', fromIndex ) );
1208+
throw new TypeError( format( 'null7f', fromIndex ) );
12091209
}
12101210
if ( fromIndex < 0 ) {
12111211
fromIndex += this._length;
@@ -1259,7 +1259,7 @@ setReadOnly( BooleanArray.prototype, 'join', function join( separator ) {
12591259
}
12601260
if ( arguments.length > 0 ) {
12611261
if ( !isString( separator ) ) {
1262-
throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', separator ) );
1262+
throw new TypeError( format( 'null3F', separator ) );
12631263
}
12641264
} else {
12651265
separator = ',';
@@ -1421,7 +1421,7 @@ setReadOnly( BooleanArray.prototype, 'lastIndexOf', function lastIndexOf( search
14211421
}
14221422
if ( arguments.length > 1 ) {
14231423
if ( !isInteger( fromIndex ) ) {
1424-
throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', fromIndex ) );
1424+
throw new TypeError( format( 'null7f', fromIndex ) );
14251425
}
14261426
if ( fromIndex >= this._length ) {
14271427
fromIndex = this._length - 1;
@@ -1502,7 +1502,7 @@ setReadOnly( BooleanArray.prototype, 'map', function map( fcn, thisArg ) {
15021502
throw new TypeError( 'invalid invocation. `this` is not a boolean array.' );
15031503
}
15041504
if ( !isFunction( fcn ) ) {
1505-
throw new TypeError( 'invalid argument. First argument must be a function. Value: `%s`.', fcn );
1505+
throw new TypeError( format('null3c'), fcn );
15061506
}
15071507
buf = this._buffer;
15081508
out = new this.constructor( this._length );
@@ -1552,7 +1552,7 @@ setReadOnly( BooleanArray.prototype, 'reduce', function reduce( reducer, initial
15521552
throw new TypeError( 'invalid invocation. `this` is not a boolean array.' );
15531553
}
15541554
if ( !isFunction( reducer ) ) {
1555-
throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', reducer ) );
1555+
throw new TypeError( format( 'null3c', reducer ) );
15561556
}
15571557
buf = this._buffer;
15581558
len = this._length;
@@ -1611,7 +1611,7 @@ setReadOnly( BooleanArray.prototype, 'reduceRight', function reduceRight( reduce
16111611
throw new TypeError( 'invalid invocation. `this` is not a boolean array.' );
16121612
}
16131613
if ( !isFunction( reducer ) ) {
1614-
throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', reducer ) );
1614+
throw new TypeError( format( 'null3c', reducer ) );
16151615
}
16161616
buf = this._buffer;
16171617
len = this._length;
@@ -1742,15 +1742,15 @@ setReadOnly( BooleanArray.prototype, 'set', function set( value ) {
17421742
if ( arguments.length > 1 ) {
17431743
idx = arguments[ 1 ];
17441744
if ( !isNonNegativeInteger( idx ) ) {
1745-
throw new TypeError( format( 'invalid argument. Index argument must be a nonnegative integer. Value: `%s`.', idx ) );
1745+
throw new TypeError( format( 'null2L', idx ) );
17461746
}
17471747
} else {
17481748
idx = 0;
17491749
}
17501750
if ( isCollection( value ) ) {
17511751
N = value.length;
17521752
if ( idx+N > this._length ) {
1753-
throw new RangeError( 'invalid arguments. Target array lacks sufficient storage to accommodate source values.' );
1753+
throw new RangeError( format('null03') );
17541754
}
17551755
if ( isBooleanArray( value ) ) {
17561756
sbuf = value._buffer; // eslint-disable-line no-underscore-dangle
@@ -1779,7 +1779,7 @@ setReadOnly( BooleanArray.prototype, 'set', function set( value ) {
17791779
return;
17801780
}
17811781
if ( idx >= this._length ) {
1782-
throw new RangeError( format( 'invalid argument. Index argument is out-of-bounds. Value: `%u`.', idx ) );
1782+
throw new RangeError( format( 'null2M', idx ) );
17831783
}
17841784
buf[ idx ] = ( value ) ? 1 : 0;
17851785
});
@@ -1848,7 +1848,7 @@ setReadOnly( BooleanArray.prototype, 'slice', function slice( begin, end ) {
18481848
end = len;
18491849
} else {
18501850
if ( !isInteger( begin ) ) {
1851-
throw new TypeError( format( 'invalid argument. First argument must be an integer. Value: `%s`.', begin ) );
1851+
throw new TypeError( format( 'null7e', begin ) );
18521852
}
18531853
if ( begin < 0 ) {
18541854
begin += len;
@@ -1860,7 +1860,7 @@ setReadOnly( BooleanArray.prototype, 'slice', function slice( begin, end ) {
18601860
end = len;
18611861
} else {
18621862
if ( !isInteger( end ) ) {
1863-
throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', end ) );
1863+
throw new TypeError( format( 'null7f', end ) );
18641864
}
18651865
if ( end < 0 ) {
18661866
end += len;
@@ -1919,7 +1919,7 @@ setReadOnly( BooleanArray.prototype, 'some', function some( predicate, thisArg )
19191919
throw new TypeError( 'invalid invocation. `this` is not a boolean array.' );
19201920
}
19211921
if ( !isFunction( predicate ) ) {
1922-
throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) );
1922+
throw new TypeError( format( 'null3c', predicate ) );
19231923
}
19241924
buf = this._buffer;
19251925
for ( i = 0; i < this._length; i++ ) {
@@ -1984,7 +1984,7 @@ setReadOnly( BooleanArray.prototype, 'sort', function sort( compareFcn ) {
19841984
return this;
19851985
}
19861986
if ( !isFunction( compareFcn ) ) {
1987-
throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', compareFcn ) );
1987+
throw new TypeError( format( 'null3c', compareFcn ) );
19881988
}
19891989
buf.sort( compare );
19901990
return this;
@@ -2063,7 +2063,7 @@ setReadOnly( BooleanArray.prototype, 'subarray', function subarray( begin, end )
20632063
end = len;
20642064
} else {
20652065
if ( !isInteger( begin ) ) {
2066-
throw new TypeError( format( 'invalid argument. First argument must be an integer. Value: `%s`.', begin ) );
2066+
throw new TypeError( format( 'null7e', begin ) );
20672067
}
20682068
if ( begin < 0 ) {
20692069
begin += len;
@@ -2075,7 +2075,7 @@ setReadOnly( BooleanArray.prototype, 'subarray', function subarray( begin, end )
20752075
end = len;
20762076
} else {
20772077
if ( !isInteger( end ) ) {
2078-
throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', end ) );
2078+
throw new TypeError( format( 'null7f', end ) );
20792079
}
20802080
if ( end < 0 ) {
20812081
end += len;
@@ -2145,7 +2145,7 @@ setReadOnly( BooleanArray.prototype, 'toLocaleString', function toLocaleString(
21452145
} else if ( isObject( options ) ) {
21462146
opts = options;
21472147
} else {
2148-
throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
2148+
throw new TypeError( format( 'null2V', options ) );
21492149
}
21502150
buf = this._buffer;
21512151
out = [];
@@ -2268,7 +2268,7 @@ setReadOnly( BooleanArray.prototype, 'toSorted', function toSorted( compareFcn )
22682268
return out;
22692269
}
22702270
if ( !isFunction( compareFcn ) ) {
2271-
throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', compareFcn ) );
2271+
throw new TypeError( format( 'null3c', compareFcn ) );
22722272
}
22732273
outbuf.sort( compare );
22742274
return out;
@@ -2464,17 +2464,17 @@ setReadOnly( BooleanArray.prototype, 'with', function copyWith( index, value ) {
24642464
throw new TypeError( 'invalid invocation. `this` is not a boolean array.' );
24652465
}
24662466
if ( !isInteger( index ) ) {
2467-
throw new TypeError( format( 'invalid argument. First argument must be an integer. Value: `%s`.', index ) );
2467+
throw new TypeError( format( 'null7e', index ) );
24682468
}
24692469
len = this._length;
24702470
if ( index < 0 ) {
24712471
index += len;
24722472
}
24732473
if ( index < 0 || index >= len ) {
2474-
throw new RangeError( format( 'invalid argument. Index argument is out-of-bounds. Value: `%s`.', index ) );
2474+
throw new RangeError( format( 'nullFP', index ) );
24752475
}
24762476
if ( !isBoolean( value ) ) {
2477-
throw new TypeError( format( 'invalid argument. Second argument must be a boolean. Value: `%s`.', value ) );
2477+
throw new TypeError( format( 'null55', value ) );
24782478
}
24792479
out = new this.constructor( this._buffer );
24802480
buf = out._buffer; // eslint-disable-line no-underscore-dangle

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"@stdlib/assert-is-string-array": "^0.2.2",
5353
"@stdlib/boolean-ctor": "^0.2.2",
5454
"@stdlib/math-base-special-floor": "^0.2.3",
55-
"@stdlib/string-format": "^0.2.2",
55+
"@stdlib/error-tools-fmtprodmsg": "^0.2.2",
5656
"@stdlib/symbol-iterator": "^0.2.2",
5757
"@stdlib/types": "^0.4.3",
5858
"@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.3",

0 commit comments

Comments
 (0)
0