Skip to content

Commit b85a1da

Browse files
committed
refactor: perform expliict dtype argument 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 9d06cf9 commit b85a1da

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

  • lib/node_modules/@stdlib/array/zeros/lib

lib/node_modules/@stdlib/array/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( '@stdlib/array/base/assert/contains' ).factory;
2324
var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive;
2425
var ctors = require( '@stdlib/array/ctors' );
2526
var gzeros = require( '@stdlib/array/base/zeros' );
27+
var dtypes = require( '@stdlib/array/dtypes' );
2628
var defaults = require( '@stdlib/array/defaults' );
29+
var join = require( '@stdlib/array/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)