Files
lodash/lang/toArray.js
John-David Dalton 5379c1996b Bump to v3.0.0.
2015-01-25 13:44:01 -08:00

30 lines
624 B
JavaScript

import arrayCopy from '../internal/arrayCopy';
import isLength from '../internal/isLength';
import values from '../object/values';
/**
* Converts `value` to an array.
*
* @static
* @memberOf _
* @category Lang
* @param {*} value The value to convert.
* @returns {Array} Returns the converted array.
* @example
*
* (function() { return _.toArray(arguments).slice(1); })(1, 2, 3);
* // => [2, 3]
*/
function toArray(value) {
var length = value ? value.length : 0;
if (!isLength(length)) {
return values(value);
}
if (!length) {
return [];
}
return arrayCopy(value);
}
export default toArray;