mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 15:27:50 +00:00
33 lines
683 B
JavaScript
33 lines
683 B
JavaScript
import arrayCopy from '../internal/arrayCopy';
|
|
import getLength from '../internal/getLength';
|
|
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 ? getLength(value) : 0;
|
|
if (!isLength(length)) {
|
|
return values(value);
|
|
}
|
|
if (!length) {
|
|
return [];
|
|
}
|
|
return arrayCopy(value);
|
|
}
|
|
|
|
export default toArray;
|