Plato on Github
Report Home
src/arraylike.js
Maintainability
86.29
Lines of code
55
Difficulty
8.41
Estimated Errors
0.13
Function weight
By Complexity
By SLOC
/** * @file Array detection * @since 0.1.5 */ /*#ifndef(UMD)*/ "use strict"; /*exported _gpfArraySlice*/ // [].slice.call /*exported _gpfArrayTail*/ // [].slice.call(,1) /*exported _gpfIsArray*/ // Return true if the parameter is an array /*exported _gpfIsArrayLike*/ // Return true if the parameter looks like an array /*#endif*/ function _gpfArraySlice (array, from, to) { return Array.prototype.slice.call(array, from, to || array.length); } var _GPF_ARRAYLIKE_TAIL_FROMINDEX = 1; function _gpfArrayTail (array) { return _gpfArraySlice(array, _GPF_ARRAYLIKE_TAIL_FROMINDEX); } /** * Return true if the parameter is an array * * @param {*} value Value to test * @return {Boolean} True if the value is an array * @since 0.2.1 */ var _gpfIsArray = Array.isArray; function _gpfArrayHasValidLengthProperty (obj) { if (obj) { return Math.floor(obj.length) === obj.length; } return false; } /** * Return true if the parameter looks like an array, meaning a property length is available and members can be * accessed through the [] operator. The length property does not have to be writable. * * @param {Object} obj Object to test * @return {Boolean} True if array-like * @since 0.1.5 */ function _gpfIsArrayLike (obj) { return _gpfIsArray(obj) || _gpfArrayHasValidLengthProperty(obj); } /** * @gpf:sameas _gpfIsArrayLike * @since 0.1.5 */ gpf.isArrayLike = _gpfIsArrayLike;