File tree Expand file tree Collapse file tree 2 files changed +37
-8
lines changed
lib/node_modules/@stdlib/ndarray/base/assert/is-data-type-object Expand file tree Collapse file tree 2 files changed +37
-8
lines changed Original file line number Diff line number Diff line change 2323var isInteger = require ( '@stdlib/assert/is-integer' ) . isPrimitive ;
2424var isString = require ( '@stdlib/assert/is-string' ) . isPrimitive ;
2525var 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*/
4849function 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
Original file line number Diff line number Diff 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+
5378tape ( 'the function returns `false` if not provided an ndarray data type object' , function test ( t ) {
5479 var values ;
5580 var bool ;
You can’t perform that action at this time.
0 commit comments