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 e985b89

Browse filesBrowse files
committed
Auto-generated commit
1 parent 39bd2d4 commit e985b89
Copy full SHA for e985b89

File tree

3 files changed

+14
-13
lines changed
Filter options

3 files changed

+14
-13
lines changed

‎.github/.keepalive

Copy file name to clipboardExpand all lines: .github/.keepalive
-1Lines changed: 0 additions & 1 deletion
This file was deleted.

‎lib/main.js

Copy file name to clipboardExpand all lines: lib/main.js
+13-12Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ var createBuffer = require( '@stdlib/ndarray-base-buffer' );
3939
var getType = require( '@stdlib/ndarray-base-buffer-dtype' );
4040
var arrayShape = require( '@stdlib/array-shape' );
4141
var flattenArray = require( '@stdlib/utils-flatten-array' );
42+
var format = require( '@stdlib/string-format' );
4243
var isArrayLikeObject = require( './is_array_like_object.js' );
4344
var defaults = require( './defaults.json' );
4445
var castBuffer = require( './cast_buffer.js' );
@@ -127,23 +128,23 @@ function array() {
127128
} else {
128129
options = arguments[ 0 ];
129130
if ( !isObject( options ) ) {
130-
throw new TypeError( 'invalid argument. Must provide either a valid data source, options argument, or both. Value: `' + options + '`.' );
131+
throw new TypeError( format( 'invalid argument. Must provide either a valid data source, options argument, or both. Value: `%s`.', options ) );
131132
}
132133
if ( hasOwnProp( options, 'buffer' ) ) {
133134
buffer = options.buffer;
134135
if ( !isArrayLikeObject( buffer ) ) { // weak test
135-
throw new TypeError( 'invalid option. `buffer` option must be an array-like object, typed-array-like, a Buffer, or an ndarray. Option: `' + buffer + '`.' );
136+
throw new TypeError( format( 'invalid option. `%s` option must be an array-like object, typed-array-like, a Buffer, or an ndarray. Option: `%s`.', 'buffer', buffer ) );
136137
}
137138
}
138139
}
139140
} else {
140141
buffer = arguments[ 0 ];
141142
if ( !isArrayLikeObject( buffer ) ) { // weak test
142-
throw new TypeError( 'invalid option. Data source must be an array-like object, typed-array-like, a Buffer, or an ndarray. Value: `' + buffer + '`.' );
143+
throw new TypeError( format( 'invalid option. Data source must be an array-like object, typed-array-like, a Buffer, or an ndarray. Value: `%s`.' , buffer ) );
143144
}
144145
options = arguments[ 1 ];
145146
if ( !isObject( options ) ) {
146-
throw new TypeError( 'invalid argument. Options argument must be an object. Value: `' + options + '`.' );
147+
throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
147148
}
148149
// Note: we ignore whether `options` has a `buffer` property
149150
}
@@ -163,23 +164,23 @@ function array() {
163164
if ( hasOwnProp( options, 'casting' ) ) {
164165
opts.casting = options.casting;
165166
if ( !isCastingMode( opts.casting ) ) {
166-
throw new TypeError( 'invalid option. `casting` option must be a recognized casting mode. Option: `' + opts.casting + '`.' );
167+
throw new TypeError( format( 'invalid option. `%s` option must be a recognized casting mode. Option: `%s`.', 'casting', opts.casting ) );
167168
}
168169
} else {
169170
opts.casting = defaults.casting;
170171
}
171172
if ( hasOwnProp( options, 'flatten' ) ) {
172173
opts.flatten = options.flatten;
173174
if ( !isBoolean( opts.flatten ) ) {
174-
throw new TypeError( 'invalid option. `flatten` option must be a boolean. Option: `' + opts.flatten + '`.' );
175+
throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'flatten', opts.flatten ) );
175176
}
176177
} else {
177178
opts.flatten = defaults.flatten;
178179
}
179180
if ( hasOwnProp( options, 'ndmin' ) ) {
180181
opts.ndmin = options.ndmin;
181182
if ( !isNonNegativeInteger( opts.ndmin ) ) {
182-
throw new TypeError( 'invalid option. `ndmin` option must be a nonnegative integer. Option: `' + opts.ndmin + '`.' );
183+
throw new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'ndmin', opts.ndmin ) );
183184
}
184185
// TODO: validate that minimum number of dimensions does not exceed the maximum number of possible dimensions (in theory, infinite; in practice, determined by max array length; see https://github.com/stdlib-js/stdlib/blob/ac350059877c036640775d6b30d0e98e840d07cf/lib/node_modules/%40stdlib/ndarray/ctor/lib/main.js#L57)
185186
} else {
@@ -190,10 +191,10 @@ function array() {
190191
if ( hasOwnProp( options, 'dtype' ) ) {
191192
dtype = options.dtype;
192193
if ( !isDataType( dtype ) ) {
193-
throw new TypeError( 'invalid option. `dtype` option must be a recognized data type. Option: `' + dtype + '`.' );
194+
throw new TypeError( format( 'invalid option. `%s` option must be a recognized data type. Option: `%s`.', 'dtype', dtype ) );
194195
}
195196
if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {
196-
throw new Error( 'invalid option. Data type cast is not allowed. Casting mode: `' + opts.casting + '`. From: `' + btype + '`. To: `' + dtype + '`.' );
197+
throw new Error( format( 'invalid option. Data type cast is not allowed. Casting mode: `%s`. From: `%s`. To: `%s`.', opts.casting, btype, dtype ) );
197198
}
198199
} else if ( btype ) {
199200
// TODO: reconcile difference in behavior when provided a generic array and no `dtype` option. Currently, we cast here, but do not allow casting a generic array (by default) when explicitly providing a `dtype` option.
@@ -231,7 +232,7 @@ function array() {
231232
order = defaults.order;
232233
}
233234
} else if ( !isOrder( order ) ) {
234-
throw new TypeError( 'invalid option. `order` option must be a recognized order. Option: `' + order + '`.' );
235+
throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', order ) );
235236
}
236237
} else {
237238
order = defaults.order;
@@ -254,7 +255,7 @@ function array() {
254255
if ( hasOwnProp( options, 'copy' ) ) {
255256
opts.copy = options.copy;
256257
if ( !isBoolean( opts.copy ) ) {
257-
throw new TypeError( 'invalid option. `copy` option must be a boolean. Option: `' + opts.copy + '`.' );
258+
throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'copy', opts.copy ) );
258259
}
259260
} else {
260261
opts.copy = defaults.copy;
@@ -263,7 +264,7 @@ function array() {
263264
if ( hasOwnProp( options, 'shape' ) ) {
264265
shape = options.shape;
265266
if ( !isArrayLikeObject( shape ) ) { // weak test
266-
throw new TypeError( 'invalid option. `shape` option must be an array-like object containing nonnegative integers. Option: `' + shape + '`.' );
267+
throw new TypeError( format( 'invalid option. `%s` option must be an array-like object containing nonnegative integers. Option: `%s`.', 'shape', shape ) );
267268
}
268269
ndims = shape.length;
269270
len = numel( shape );

‎package.json

Copy file name to clipboardExpand all lines: package.json
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"@stdlib/ndarray-base-strides2offset": "^0.0.x",
6161
"@stdlib/ndarray-base-strides2order": "^0.0.x",
6262
"@stdlib/ndarray-ctor": "^0.0.x",
63+
"@stdlib/string-format": "^0.0.x",
6364
"@stdlib/types": "^0.0.x",
6465
"@stdlib/utils-flatten-array": "^0.0.x"
6566
},

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.