Skip to content

Commit 31cb339

Browse files
committed
refactor: add instanceof check to increase perf
--- 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: passed - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 0aef010 commit 31cb339

File tree

2 files changed

+37
-8
lines changed
  • lib/node_modules/@stdlib/ndarray/base/assert/is-data-type-object

2 files changed

+37
-8
lines changed

lib/node_modules/@stdlib/ndarray/base/assert/is-data-type-object/lib/main.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive;
2424
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
2525
var hasProp = require( '@stdlib/assert/has-property' );
26+
var DataType = require( '@stdlib/ndarray/dtype-ctor' );
2627

2728

2829
// MAIN //
@@ -47,14 +48,17 @@ var hasProp = require( '@stdlib/assert/has-property' );
4748
*/
4849
function isDataTypeObject( value ) {
4950
return (
50-
typeof value === 'object' &&
51-
value !== null &&
52-
isInteger( value.alignment ) &&
53-
isInteger( value.byteLength ) &&
54-
isString( value.byteOrder ) &&
55-
isString( value.char ) &&
56-
isInteger( value.enum ) &&
57-
hasProp( value, 'value' )
51+
value instanceof DataType ||
52+
(
53+
typeof value === 'object' &&
54+
value !== null &&
55+
isInteger( value.alignment ) &&
56+
isInteger( value.byteLength ) &&
57+
isString( value.byteOrder ) &&
58+
isString( value.char ) &&
59+
isInteger( value.enum ) &&
60+
hasProp( value, 'value' )
61+
)
5862
);
5963
}
6064

lib/node_modules/@stdlib/ndarray/base/assert/is-data-type-object/test/test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,31 @@ tape( 'the function returns `true` if provided an ndarray data type object', fun
5050
t.end();
5151
});
5252

53+
tape( 'the function returns `true` if provided an ndarray data type-like object', function test( t ) {
54+
var values;
55+
var bool;
56+
var obj;
57+
var i;
58+
59+
obj = {
60+
'alignment': 8,
61+
'byteLength': 8,
62+
'byteOrder': 'host',
63+
'char': 'd',
64+
'enum': 12,
65+
'value': 'float64'
66+
};
67+
68+
values = [
69+
obj
70+
];
71+
for ( i = 0; i < values.length; i++ ) {
72+
bool = isDataTypeObject( values[ i ] );
73+
t.strictEqual( bool, true, 'returns expected value when provided '+values[ i ] );
74+
}
75+
t.end();
76+
});
77+
5378
tape( 'the function returns `false` if not provided an ndarray data type object', function test( t ) {
5479
var values;
5580
var bool;

0 commit comments

Comments
 (0)