Skip to content

Commit 68ef3ce

Browse files
committed
refactor: perform explicit dtype validation
--- 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 5706abd commit 68ef3ce

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

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

lib/node_modules/@stdlib/array/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( '@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( 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;

0 commit comments

Comments
 (0)