Skip to content

Commit bec565f

Browse files
committed
Auto-generated commit
1 parent f8f3f4c commit bec565f

9 files changed

Lines changed: 89 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,14 @@ A total of 38 issues were closed in this release:
264264

265265
<details>
266266

267+
- [`a4557ba`](https://github.com/stdlib-js/stdlib/commit/a4557ba86aebbc0535f0989f59ba3461ad6b1d89) - **refactor:** perform explicit dtype validation _(by Athan Reines)_
268+
- [`bfc9322`](https://github.com/stdlib-js/stdlib/commit/bfc9322020792df4f47ea649d6fbed509284f6bd) - **refactor:** perform explicit dtype validation _(by Athan Reines)_
269+
- [`b85a1da`](https://github.com/stdlib-js/stdlib/commit/b85a1da40b6ea52d966f7294933908c5d4c839d9) - **refactor:** perform expliict dtype argument validation _(by Athan Reines)_
270+
- [`9d06cf9`](https://github.com/stdlib-js/stdlib/commit/9d06cf9a66cd23f2640a7b20652748152cb90ee9) - **refactor:** perform explicit dtype validation _(by Athan Reines)_
271+
- [`68ef3ce`](https://github.com/stdlib-js/stdlib/commit/68ef3cef76a8f6080cf8cf4171b9a449c969315b) - **refactor:** perform explicit dtype validation _(by Athan Reines)_
272+
- [`5706abd`](https://github.com/stdlib-js/stdlib/commit/5706abd84b709abebb6ac0721cf6cc5caded2906) - **refactor:** clean-up dtype validation logic _(by Athan Reines)_
273+
- [`dfccbcd`](https://github.com/stdlib-js/stdlib/commit/dfccbcd1e30c2b7afc9b1c133b94ca96ac5751d2) - **refactor:** use dedicated utility for joining array elements _(by Athan Reines)_
274+
- [`3323474`](https://github.com/stdlib-js/stdlib/commit/3323474c193b0a1cf6501ea8bf54381392562af6) - **refactor:** explicitly validate a provided input dtype _(by Athan Reines)_
267275
- [`9165bd6`](https://github.com/stdlib-js/stdlib/commit/9165bd6bd22746c8e69c14e75fd931485515a194) - **feat:** add `falses` to namespace _(by Athan Reines)_
268276
- [`836f561`](https://github.com/stdlib-js/stdlib/commit/836f5610785c2b1eb8efd5d5234fec349dac8f1d) - **feat:** add `array/base/falses` _(by Athan Reines)_
269277
- [`afb3293`](https://github.com/stdlib-js/stdlib/commit/afb32938742a510a3357156736067ee8fdaba07d) - **feat:** add `trues` to namespace _(by Athan Reines)_

nans-like/lib/main.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,22 @@
2020

2121
// MODULES //
2222

23+
var contains = require( './../../base/assert/contains' ).factory;
2324
var dtype = require( './../../dtype' );
2425
var full = require( './../../full' );
2526
var Complex128 = require( '@stdlib/complex/float64/ctor' );
2627
var Complex64 = require( '@stdlib/complex/float32/ctor' );
28+
var dtypes = require( './../../dtypes' );
29+
var join = require( './../../base/join' );
2730
var format = require( '@stdlib/string/format' );
2831

2932

3033
// VARIABLES //
3134

3235
var Z128 = new Complex128( NaN, NaN );
3336
var Z64 = new Complex64( NaN, NaN );
34-
var DTYPES = [ 'float64', 'float32', 'complex128', 'complex64', 'generic' ];
37+
var DTYPES = dtypes( 'floating_point_and_generic' );
38+
var isValidDType = contains( DTYPES );
3539

3640

3741
// MAIN //
@@ -63,11 +67,11 @@ function nansLike( x ) {
6367
}
6468
if ( arguments.length > 1 ) {
6569
dt = arguments[ 1 ];
66-
if ( DTYPES.indexOf( dt ) === -1 ) {
67-
throw new TypeError( format( 'invalid argument. Second argument must be one of the following: "%s". Value: `%s`.', DTYPES.join( '", "' ), dt ) );
70+
if ( !isValidDType( dt ) ) {
71+
throw new TypeError( format( 'invalid argument. Second argument must be one of the following: "%s". Value: `%s`.', join( DTYPES, '", "' ), dt ) );
6872
}
69-
} else if ( DTYPES.indexOf( dt ) === -1 ) {
70-
throw new TypeError( format( 'invalid argument. First argument must be one of the following data types: "%s". Value: `%s`.', DTYPES.join( '", "' ), dt ) );
73+
} else if ( !isValidDType( dt ) ) {
74+
throw new TypeError( format( 'invalid argument. First argument must have one of the following data types: "%s". Value: `%s`.', join( DTYPES, '", "' ), dt ) );
7175
}
7276
if ( dt === 'complex128' ) {
7377
v = Z128;

nans/lib/main.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ var Complex64 = require( '@stdlib/complex/float32/ctor' );
2626
var full = require( './../../full' );
2727
var defaults = require( './../../defaults' );
2828
var dtypes = require( './../../dtypes' );
29+
var join = require( './../../base/join' );
2930
var format = require( '@stdlib/string/format' );
3031

3132

@@ -64,7 +65,7 @@ function nans( length ) {
6465
if ( arguments.length > 1 ) {
6566
dtype = arguments[ 1 ];
6667
if ( !isValidDType( dtype ) ) {
67-
throw new TypeError( format( 'invalid argument. Second argument must be one of the following: "%s". Value: `%s`.', DTYPES.join( '", "' ), dtype ) );
68+
throw new TypeError( format( 'invalid argument. Second argument must be one of the following: "%s". Value: `%s`.', join( DTYPES, '", "' ), dtype ) );
6869
}
6970
} else {
7071
dtype = DEFAULT_DTYPE;

one-to-like/lib/main.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,20 @@
2020

2121
// MODULES //
2222

23+
var contains = require( './../../base/assert/contains' ).factory;
2324
var oneTo = require( './../../one-to' );
2425
var dtype = require( './../../dtype' );
26+
var dtypes = require( './../../dtypes' );
27+
var join = require( './../../base/join' );
2528
var format = require( '@stdlib/string/format' );
2629

2730

31+
// VARIABLES //
32+
33+
var DTYPES = dtypes( 'numeric_and_generic' );
34+
var isValidDType = contains( DTYPES );
35+
36+
2837
// MAIN //
2938

3039
/**
@@ -51,6 +60,11 @@ function oneToLike( x ) {
5160
}
5261
if ( arguments.length > 1 ) {
5362
dt = arguments[ 1 ];
63+
if ( !isValidDType( dt ) ) {
64+
throw new TypeError( format( 'invalid argument. Second argument must be one of the following: "%s". Value: `%s`.', join( DTYPES, '", "' ), dt ) );
65+
}
66+
} else if ( !isValidDType( dt ) ) {
67+
throw new TypeError( format( 'invalid argument. First argument must have one of the following data types: "%s". Value: `%s`.', join( DTYPES, '", "' ), dt ) );
5468
}
5569
return oneTo( x.length, dt );
5670
}

ones-like/lib/main.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,22 @@
2020

2121
// MODULES //
2222

23+
var contains = require( './../../base/assert/contains' ).factory;
2324
var dtype = require( './../../dtype' );
2425
var full = require( './../../full' );
2526
var Complex128 = require( '@stdlib/complex/float64/ctor' );
2627
var Complex64 = require( '@stdlib/complex/float32/ctor' );
28+
var dtypes = require( './../../dtypes' );
29+
var join = require( './../../base/join' );
2730
var format = require( '@stdlib/string/format' );
2831

2932

3033
// VARIABLES //
3134

3235
var Z128 = new Complex128( 1.0, 0.0 );
3336
var Z64 = new Complex64( 1.0, 0.0 );
37+
var DTYPES = dtypes( 'numeric_and_generic' );
38+
var isValidDType = contains( DTYPES );
3439

3540

3641
// MAIN //
@@ -62,6 +67,11 @@ function onesLike( x ) {
6267
}
6368
if ( arguments.length > 1 ) {
6469
dt = arguments[ 1 ];
70+
if ( !isValidDType( dt ) ) {
71+
throw new TypeError( format( 'invalid argument. Second argument must be one of the following: "%s". Value: `%s`.', join( DTYPES, '", "' ), dt ) );
72+
}
73+
} else if ( !isValidDType( dt ) ) {
74+
throw new TypeError( format( 'invalid argument. First argument must have one of the following data types: "%s". Value: `%s`.', join( DTYPES, '", "' ), dt ) );
6575
}
6676
if ( dt === 'complex128' ) {
6777
v = Z128;

ones/lib/main.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,22 @@
2020

2121
// MODULES //
2222

23+
var contains = require( './../../base/assert/contains' ).factory;
2324
var Complex128 = require( '@stdlib/complex/float64/ctor' );
2425
var Complex64 = require( '@stdlib/complex/float32/ctor' );
2526
var full = require( './../../full' );
27+
var dtypes = require( './../../dtypes' );
2628
var defaults = require( './../../defaults' );
29+
var join = require( './../../base/join' );
30+
var format = require( '@stdlib/string/format' );
2731

2832

2933
// VARIABLES //
3034

3135
var Z128 = new Complex128( 1.0, 0.0 );
3236
var Z64 = new Complex64( 1.0, 0.0 );
37+
var DTYPES = dtypes( 'numeric_and_generic' );
38+
var isValidDType = contains( DTYPES );
3339
var DEFAULT_DTYPE = defaults.get( 'dtypes.default' );
3440

3541

@@ -58,6 +64,9 @@ function ones( length ) {
5864

5965
if ( arguments.length > 1 ) {
6066
dtype = arguments[ 1 ];
67+
if ( !isValidDType( dtype ) ) {
68+
throw new TypeError( format( 'invalid argument. Second argument must be one of the following: "%s". Value: `%s`.', join( DTYPES, '", "' ), dtype ) );
69+
}
6170
} else {
6271
dtype = DEFAULT_DTYPE;
6372
}

zero-to-like/lib/main.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,20 @@
2020

2121
// MODULES //
2222

23+
var contains = require( './../../base/assert/contains' ).factory;
2324
var zeroTo = require( './../../zero-to' );
2425
var dtype = require( './../../dtype' );
26+
var dtypes = require( './../../dtypes' );
27+
var join = require( './../../base/join' );
2528
var format = require( '@stdlib/string/format' );
2629

2730

31+
// VARIABLES //
32+
33+
var DTYPES = dtypes( 'numeric_and_generic' );
34+
var isValidDType = contains( DTYPES );
35+
36+
2837
// MAIN //
2938

3039
/**
@@ -51,6 +60,11 @@ function zeroToLike( x ) {
5160
}
5261
if ( arguments.length > 1 ) {
5362
dt = arguments[ 1 ];
63+
if ( !isValidDType( dt ) ) {
64+
throw new TypeError( format( 'invalid argument. Second argument must be one of the following: "%s". Value: `%s`.', join( DTYPES, '", "' ), dt ) );
65+
}
66+
} else if ( !isValidDType( dt ) ) {
67+
throw new TypeError( format( 'invalid argument. First argument must have one of the following data types: "%s". Value: `%s`.', join( DTYPES, '", "' ), dt ) );
5468
}
5569
return zeroTo( x.length, dt );
5670
}

zeros-like/lib/main.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,18 @@
2020

2121
// MODULES //
2222

23-
var format = require( '@stdlib/string/format' );
23+
var contains = require( './../../base/assert/contains' ).factory;
2424
var dtype = require( './../../dtype' );
2525
var zeros = require( './../../zeros' );
26+
var dtypes = require( './../../dtypes' );
27+
var join = require( './../../base/join' );
28+
var format = require( '@stdlib/string/format' );
29+
30+
31+
// VARIABLES //
32+
33+
var DTYPES = dtypes( 'numeric_and_generic' );
34+
var isValidDType = contains( DTYPES );
2635

2736

2837
// MAIN //
@@ -51,6 +60,11 @@ function zerosLike( x ) {
5160
}
5261
if ( arguments.length > 1 ) {
5362
dt = arguments[ 1 ];
63+
if ( !isValidDType( dt ) ) {
64+
throw new TypeError( format( 'invalid argument. Second argument must be one of the following: "%s". Value: `%s`.', join( DTYPES, '", "' ), dt ) );
65+
}
66+
} else if ( !isValidDType( dt ) ) {
67+
throw new TypeError( format( 'invalid argument. First argument must have one of the following data types: "%s". Value: `%s`.', join( DTYPES, '", "' ), dt ) );
5468
}
5569
return zeros( x.length, dt );
5670
}

zeros/lib/main.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,21 @@
2020

2121
// MODULES //
2222

23+
var contains = require( './../../base/assert/contains' ).factory;
2324
var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive;
2425
var ctors = require( './../../ctors' );
2526
var gzeros = require( './../../base/zeros' );
27+
var dtypes = require( './../../dtypes' );
2628
var defaults = require( './../../defaults' );
29+
var join = require( './../../base/join' );
2730
var format = require( '@stdlib/string/format' );
2831

2932

3033
// VARIABLES //
3134

3235
var DEFAULT_DTYPE = defaults.get( 'dtypes.default' );
36+
var DTYPES = dtypes( 'numeric_and_generic' );
37+
var isValidDType = contains( DTYPES );
3338

3439

3540
// MAIN //
@@ -59,6 +64,9 @@ function zeros( length ) {
5964
}
6065
if ( arguments.length > 1 ) {
6166
dtype = arguments[ 1 ];
67+
if ( !isValidDType( dtype ) ) {
68+
throw new TypeError( format( 'invalid argument. Second argument must be one of the following: "%s". Value: `%s`.', join( DTYPES, '", "' ), dtype ) );
69+
}
6270
} else {
6371
dtype = DEFAULT_DTYPE;
6472
}

0 commit comments

Comments
 (0)