Skip to content

Commit a4557ba

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 bfc9322 commit a4557ba

File tree

1 file changed

+14
-0
lines changed
  • lib/node_modules/@stdlib/array/one-to-like/lib

1 file changed

+14
-0
lines changed

lib/node_modules/@stdlib/array/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( '@stdlib/array/base/assert/contains' ).factory;
2324
var oneTo = require( '@stdlib/array/one-to' );
2425
var dtype = require( '@stdlib/array/dtype' );
26+
var dtypes = require( '@stdlib/array/dtypes' );
27+
var join = require( '@stdlib/array/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
}

0 commit comments

Comments
 (0)