mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-03 08:37:49 +00:00
Add _.asArray method.
This commit is contained in:
committed by
John-David Dalton
parent
13e4b959a4
commit
ee499b36ea
36
lodash.js
36
lodash.js
@@ -10432,6 +10432,41 @@
|
||||
return value <= other;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a `value` to an array.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Lang
|
||||
* @param {*} value The value to convert.
|
||||
* @returns {Array} Returns the converted array.
|
||||
* @example
|
||||
*
|
||||
* _.toArray({ 'a': 1, 'b': 2 });
|
||||
* // => [{ 'a': 1, 'b': 2 }]
|
||||
*
|
||||
* _.toArray([1, 2, 3]);
|
||||
* // => [1, 2, 3]
|
||||
*
|
||||
* _.toArray('abc');
|
||||
* // => ['abc']
|
||||
*
|
||||
* _.toArray(1);
|
||||
* // => [1]
|
||||
*
|
||||
* _.toArray(null);
|
||||
* // => [null]
|
||||
*/
|
||||
function asArray(value) {
|
||||
if (isArray(value)) {
|
||||
return copyArray(value);
|
||||
}
|
||||
if (iteratorSymbol && value && value[iteratorSymbol] && !isString(value)) {
|
||||
return iteratorToArray(value[iteratorSymbol]());
|
||||
}
|
||||
return [value];
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts `value` to an array.
|
||||
*
|
||||
@@ -14206,6 +14241,7 @@
|
||||
// Add functions that return wrapped values when chaining.
|
||||
lodash.after = after;
|
||||
lodash.ary = ary;
|
||||
lodash.asArray = asArray;
|
||||
lodash.assign = assign;
|
||||
lodash.assignIn = assignIn;
|
||||
lodash.assignInWith = assignInWith;
|
||||
|
||||
Reference in New Issue
Block a user