Skip to content

Commit 5706abd

Browse files
committed
refactor: clean-up dtype validation logic
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent dfccbcd commit 5706abd

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

  • lib/node_modules/@stdlib/array/nans-like/lib

lib/node_modules/@stdlib/array/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( '@stdlib/array/base/assert/contains' ).factory;
2324
var dtype = require( '@stdlib/array/dtype' );
2425
var full = require( '@stdlib/array/full' );
2526
var Complex128 = require( '@stdlib/complex/float64/ctor' );
2627
var Complex64 = require( '@stdlib/complex/float32/ctor' );
28+
var dtypes = require( '@stdlib/array/dtypes' );
29+
var join = require( '@stdlib/array/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;

0 commit comments

Comments
 (0)