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 23
23
var isInteger = require ( '@stdlib/assert/is-integer' ) . isPrimitive ;
24
24
var isString = require ( '@stdlib/assert/is-string' ) . isPrimitive ;
25
25
var hasProp = require ( '@stdlib/assert/has-property' ) ;
26
+ var DataType = require ( '@stdlib/ndarray/dtype-ctor' ) ;
26
27
27
28
28
29
// MAIN //
@@ -47,14 +48,17 @@ var hasProp = require( '@stdlib/assert/has-property' );
47
48
*/
48
49
function isDataTypeObject ( value ) {
49
50
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
+ )
58
62
) ;
59
63
}
60
64
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
50
50
t . end ( ) ;
51
51
} ) ;
52
52
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
+
53
78
tape ( 'the function returns `false` if not provided an ndarray data type object' , function test ( t ) {
54
79
var values ;
55
80
var bool ;
You can’t perform that action at this time.
0 commit comments