main.js (1665B)
1 /** 2 * @license Apache-2.0 3 * 4 * Copyright (c) 2018 The Stdlib Authors. 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 'use strict'; 20 21 // MODULES // 22 23 var ndarray = require( '@stdlib/ndarray/base/ctor' ); 24 25 26 // MAIN // 27 28 /** 29 * Tests if a value is ndarray-like. 30 * 31 * @param {*} v - value to test 32 * @returns {boolean} boolean indicating if a value is ndarray-like 33 * 34 * @example 35 * var ndarray = require( '@stdlib/ndarray/ctor' ); 36 * 37 * var arr = ndarray( 'generic', [ 0, 0, 0, 0 ], [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); 38 * 39 * var bool = isndarrayLike( arr ); 40 * // returns true 41 * 42 * bool = isndarrayLike( [] ); 43 * // returns false 44 */ 45 function isndarrayLike( v ) { 46 return ( 47 v instanceof ndarray || 48 ( 49 v !== null && 50 typeof v === 'object' && 51 typeof v.data === 'object' && 52 typeof v.shape === 'object' && 53 typeof v.strides === 'object' && 54 typeof v.offset === 'number' && 55 typeof v.order === 'string' && 56 typeof v.ndims === 'number' && 57 typeof v.dtype === 'string' && 58 typeof v.length === 'number' && 59 typeof v.flags === 'object' && 60 typeof v.get === 'function' && 61 typeof v.set === 'function' 62 ) 63 ); 64 } 65 66 67 // EXPORTS // 68 69 module.exports = isndarrayLike;