mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 02:47:50 +00:00
Add support for converting maps to _.toPairs and _.toPairsIn.
This commit is contained in:
26
lodash.js
26
lodash.js
@@ -2674,9 +2674,7 @@
|
||||
*/
|
||||
function baseGetAllKeys(object, keysFunc, symbolsFunc) {
|
||||
var result = keysFunc(object);
|
||||
return isArray(object)
|
||||
? result
|
||||
: arrayPush(result, symbolsFunc(object));
|
||||
return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -4879,6 +4877,20 @@
|
||||
return new Set(values);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a `_.toPairs` or `_.toPairsIn` function.
|
||||
*
|
||||
* @private
|
||||
* @param {Function} keysFunc The function to get the keys of a given object.
|
||||
* @returns {Function} Returns the new pairs function.
|
||||
*/
|
||||
function createToPairs(keysFunc) {
|
||||
return function(object) {
|
||||
var tag = getTag(object);
|
||||
return tag == mapTag ? mapToArray(object) : baseToPairs(object, keysFunc(object));
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a function that either curries or invokes `func` with optional
|
||||
* `this` binding and partially applied arguments.
|
||||
@@ -12893,9 +12905,7 @@
|
||||
* _.toPairs(new Foo);
|
||||
* // => [['a', 1], ['b', 2]] (iteration order is not guaranteed)
|
||||
*/
|
||||
function toPairs(object) {
|
||||
return baseToPairs(object, keys(object));
|
||||
}
|
||||
var toPairs = createToPairs(keys);
|
||||
|
||||
/**
|
||||
* Creates an array of own and inherited enumerable string keyed-value pairs
|
||||
@@ -12920,9 +12930,7 @@
|
||||
* _.toPairsIn(new Foo);
|
||||
* // => [['a', 1], ['b', 2], ['c', 1]] (iteration order is not guaranteed)
|
||||
*/
|
||||
function toPairsIn(object) {
|
||||
return baseToPairs(object, keysIn(object));
|
||||
}
|
||||
var toPairsIn = createToPairs(keysIn);
|
||||
|
||||
/**
|
||||
* An alternative to `_.reduce`; this method transforms `object` to a new
|
||||
|
||||
Reference in New Issue
Block a user