8000 Transform error messages · stdlib-js/array-to-fancy@65d7480 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 65d7480

Browse files
committed
Transform error messages
1 parent 37a4418 commit 65d7480

File tree

9 files changed

+28
-28
lines changed

9 files changed

+28
-28
lines changed

lib/factory.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var isArrayLike = require( '@stdlib/assert-is-array-like' );
2525
var Proxy = require( '@stdlib/proxy-ctor' );
2626
var arraylike2object = require( '@stdlib/array-base-arraylike2object' );
2727
var assign = require( '@stdlib/object-assign' );
28-
var format = require( '@stdlib/string-format' );
28+
var format = require( '@stdlib/error-tools-fmtprodmsg' );
2929
var setElementWrapper = require( './set_element_wrapper.js' );
3030
var getArrayWrapper = require( './get_array_wrapper.js' );
3131
var hasProxySupport = require( './has_proxy_support.js' );
@@ -126,7 +126,7 @@ function factory() {
126126
var dt;
127127
var o;
128128
if ( !isArrayLike( x ) && !isCollection( x ) ) {
129-
throw new TypeError( format( 'invalid argument. First argument must be array-like. Value: `%s`.', x ) );
129+
throw new TypeError( format( '1rX38', x ) );
130130
}
131131
if ( hasProxySupport ) {
132132
opts = assign( {}, OPTIONS );

lib/get_elements.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
var take = require( '@stdlib/array-take' );
2424
var mskfilter = require( '@stdlib/array-mskfilter' );
2525
var mskreject = require( '@stdlib/array-mskreject' );
26-
var format = require( '@stdlib/string-format' );
26+
var format = require( '@stdlib/error-tools-fmtprodmsg' );
2727
var prop2array = require( './prop2array.js' );
2828

2929

lib/prop2array.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
// MODULES //
2222

2323
var trim = require( '@stdlib/string-base-trim' );
24-
var format = require( '@stdlib/string-format' );
24+
var format = require( '@stdlib/error-tools-fmtprodmsg' );
2525

2626

2727
// FUNCTIONS //

lib/prop2slice.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var trim = require( '@stdlib/string-base-trim' );
2424
var seq2slice = require( '@stdlib/slice-base-seq2slice' );
2525
var str2slice = require( '@stdlib/slice-base-str2slice' );
2626
var startsWith = require( '@stdlib/string-base-starts-with' );
27-
var format = require( '@stdlib/string-format' );
27+
var format = require( '@stdlib/error-tools-fmtprodmsg' );
2828
var RE_SUBSEQ = require( './re_subseq.js' );
2929

3030

@@ -89,7 +89,7 @@ function isSubsequence( prop ) {
8989
function parseSlice( raw, str ) {
9090
var s = str2slice( str );
9191
if ( s === null ) {
92-
throw new Error( format( 'invalid operation. Unsupported slice operation. Value: `%s`.', raw ) );
92+
throw new Error( format( '1rXEn', raw ) );
9393
}
9494
return s;
9595
}
@@ -114,15 +114,15 @@ function parseSubsequence( raw, str, max, strict ) {
114114
var s = seq2slice( str, max, true );
115115
if ( s.code ) {
116116
if ( s.code === 'ERR_SLICE_INVALID_INCREMENT' ) {
117-
throw new Error( format( 'invalid operation. A subsequence increment must be a non-zero integer. Value: `%s`.', raw ) );
117+
throw new Error( format( '1rXEq', raw ) );
118118
}
119119
if ( s.code === 'ERR_SLICE_INVALID_SUBSEQUENCE' ) {
120-
throw new Error( format( 'invalid operation. Unsupported slice operation. Value: `%s`.', raw ) );
120+
throw new Error( format( '1rXEn', raw ) );
121121
}
122122
// NOTE: the following error check must come last due to fall-through when in non-strict mode...
123123
if ( s.code === 'ERR_SLICE_OUT_OF_BOUNDS' ) {
124124
if ( strict ) {
125-
throw new RangeError( format( 'invalid operation. Slice exceeds array bounds.' ) );
125+
throw new RangeError( format( '1rXFU' ) );
126126
}
127127
// Repeat parsing, this time allowing for out-of-bounds slices:
128128
s = seq2slice( str, max, false );

lib/resolve_index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
// MODULES //
2222

2323
var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' );
24-
var format = require( '@stdlib/string-format' );
24+
var format = require( '@stdlib/error-tools-fmtprodmsg' );
2525

2626

2727
// MAIN //

lib/set_elements.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var put = require( '@stdlib/array-put' );
3030
var place = require( '@stdlib/array-place' );
3131
var convert = require( '@stdlib/array-convert' );
3232
var where = require( '@stdlib/array-base-where' ).assign;
33-
var format = require( '@stdlib/string-format' );
33+
var format = require( '@stdlib/error-tools-fmtprodmsg' );
3434
var prop2array = require( './prop2array.js' );
3535
var errMessage = require( './error_message.js' );
3636

@@ -106,7 +106,7 @@ function setElements( target, property, value, ctx ) {
106106
}
107107
// Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the target array data type is floating-point...
108108
if ( !isMostlySafeCast( vdt, tdt ) ) {
109-
throw new TypeError( format( 'invalid operation. Assigned value cannot be safely cast to the target array data type. Data types: [%s, %s].', vdt, tdt ) );
109+
throw new TypeError( format( '1rXEw', vdt, tdt ) );
110110
}
111111
// When performing a real-to-complex assignment, interpret the real-valued array as containing real components with implied imaginary components equal to zero and explicitly convert to a complex-valued array...
112112
if ( isComplexDataType( tdt ) && isRealDataType( vdt ) ) {

lib/validate.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' );
2424
var hasOwnProp = require( '@stdlib/assert-has-own-property' );
2525
var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;
2626
var isMethodIn = require( '@stdlib/assert-is-method-in' );
27-
var format = require( '@stdlib/string-format' );
27+
var format = require( '@stdlib/error-tools-fmtprodmsg' );
2828

2929

3030
// MAIN //
@@ -51,12 +51,12 @@ var format = require( '@stdlib/string-format' );
5151
*/
5252
function validate( opts, options ) {
5353
if ( !isObject( options ) ) {
54-
return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
54+
return new TypeError( format( '1rX2V', options ) );
5555
}
5656
if ( hasOwnProp( options, 'strict' ) ) {
5757
opts.strict = options.strict;
5858
if ( !isBoolean( opts.strict ) ) {
59-
return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', opts.strict ) );
59+
return new TypeError( format( '1rX2o', 'strict', opts.strict ) );
6060
}
6161
}
6262
if ( hasOwnProp( options, 'cache' ) ) {

lib/validator.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ var isSafeCast = require( '@stdlib/array-base-assert-is-safe-data-type-cast' );
3232
var minDataType = require( '@stdlib/array-min-dtype' );
3333
var minSignedIntegerDataType = require( '@stdlib/array-base-min-signed-integer-dtype' );
3434
var complexDataType = require( '@stdlib/complex-dtype' );
35-
var format = require( '@stdlib/string-format' );
35+
var format = require( '@stdlib/error-tools-fmtprodmsg' );
3636

3737

3838
// FUNCTIONS //
@@ -75,7 +75,7 @@ function validateBoolean( value, dtype ) {
7575
if ( isBoolean( value ) ) {
7676
return null;
7777
}
78-
return new TypeError( format( 'invalid operation. Assigned value cannot be safely cast to the target array data type. Data types: [%s, %s].', typeof value, dtype ) );
78+
return new TypeError( format( '1rXEw', typeof value, dtype ) );
7979
}
8080

8181
/**
@@ -101,9 +101,9 @@ function validateRealFloating( value, dtype ) {
101101
return null;
102102
}
103103
if ( isComplexLike( value ) ) {
104-
return new TypeError( format( 'invalid operation. Assigned value cannot be safely cast to the target array data type. Data types: [%s, %s].', complexDataType( value ), dtype ) );
104+
return new TypeError( format( '1rXEw', complexDataType( value ), dtype ) );
105105
}
106-
return new TypeError( format( 'invalid operation. Assigned value cannot be safely cast to the target array data type. Data types: [%s, %s].', typeof value, dtype ) );
106+
return new TypeError( format( '1rXEw', typeof value, dtype ) );
107107
}
108108

109109
/**
@@ -128,7 +128,7 @@ function validateComplexFloating( value, dtype ) {
128128
if ( isNumber( value ) || isComplexLike( value ) ) {
129129
return null;
130130
}
131-
return new TypeError( format( 'invalid operation. Assigned value cannot be safely cast to the target array data type. Data types: [%s, %s].', typeof value, dtype ) );
131+
return new TypeError( format( '1rXEw', typeof value, dtype ) );
132132
}
133133

134134
/**
@@ -151,18 +151,18 @@ function validateSignedInteger( value, dtype ) {
151151
var vdt;
152152
if ( isNumber( value ) ) {
153153
if ( !isInteger( value ) ) {
154-
return new TypeError( format( 'invalid operation. Assigned value cannot be safely cast to the target array data type. Data types: [%s, %s].', minDataType( value ), dtype ) );
154+
return new TypeError( format( '1rXEw', minDataType( value ), dtype ) );
155155
}
156156
vdt = minSignedIntegerDataType( value );
157157
if ( isSafeCast( vdt, dtype ) ) {
158158
return null;
159159
}
160-
return new TypeError( format( 'invalid operation. Assigned value cannot be safely cast to the target array data type. Data types: [%s, %s].', vdt, dtype ) );
160+
return new TypeError( format( '1rXEw', vdt, dtype ) );
161161
}
162162
if ( isComplexLike( value ) ) {
163-
return new TypeError( format( 'invalid operation. Assigned value cannot be safely cast to the target array data type. Data types: [%s, %s].', complexDataType( value ), dtype ) );
163+
return new TypeError( format( '1rXEw', complexDataType( value ), dtype ) );
164164
}
165-
return new TypeError( format( 'invalid operation. Assigned value cannot be safely cast to the target array data type. Data types: [%s, %s].', typeof value, dtype ) );
165+
return new TypeError( format( '1rXEw', typeof value, dtype ) );
166166
}
167167

168168
/**
@@ -188,12 +188,12 @@ function validateUnsignedInteger( value, dtype ) {
188188
if ( isSafeCast( vdt, dtype ) ) {
189189
return null;
190190
}
191-
return new TypeError( format( 'invalid operation. Assigned value cannot be safely cast to the target array data type. Data types: [%s, %s].', vdt, dtype ) );
191+
return new TypeError( format( '1rXEw', vdt, dtype ) );
192192
}
193193
if ( isComplexLike( value ) ) {
194-
return new TypeError( format( 'invalid operation. Assigned value cannot be safely cast to the target array data type. Data types: [%s, %s].', complexDataType( value ), dtype ) );
194+
return new TypeError( format( '1rXEw', complexDataType( value ), dtype ) );
195195
}
196-
return new TypeError( format( 'invalid operation. Assigned value cannot be safely cast to the target array data type. Data types: [%s, %s].', typeof value, dtype ) );
196+
return new TypeError( format( '1rXEw', typeof value, dtype ) );
197197
}
198198

199199

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
"@stdlib/string-base-replace": "^0.2.2",
8282
"@stdlib/string-base-starts-with": "^0.2.2",
8383
"@stdlib/string-base-trim": "^0.2.2",
84-
"@stdlib/string-format": "^0.2.2",
84+
"@stdlib/error-tools-fmtprodmsg": "^0.2.2",
8585
"@stdlib/types": "^0.4.3",
8686
"@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2",
8787
"@stdlib/error-tools-fmtprodmsg": "^0.2.2"

0 commit comments

Comments
 (0)
0