mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 10:17:48 +00:00
Add support for sets to _.toPairs methods.
This commit is contained in:
33
lodash.js
33
lodash.js
@@ -1146,6 +1146,23 @@
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts `set` to its value-value pairs.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {Object} set The set to convert.
|
||||||
|
* @returns {Array} Returns the value-value pairs.
|
||||||
|
*/
|
||||||
|
function setToPairs(set) {
|
||||||
|
var index = -1,
|
||||||
|
result = Array(set.size);
|
||||||
|
|
||||||
|
set.forEach(function(value) {
|
||||||
|
result[++index] = [value, value];
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the number of symbols in `string`.
|
* Gets the number of symbols in `string`.
|
||||||
*
|
*
|
||||||
@@ -4908,7 +4925,13 @@
|
|||||||
function createToPairs(keysFunc) {
|
function createToPairs(keysFunc) {
|
||||||
return function(object) {
|
return function(object) {
|
||||||
var tag = getTag(object);
|
var tag = getTag(object);
|
||||||
return tag == mapTag ? mapToArray(object) : baseToPairs(object, keysFunc(object));
|
if (tag == mapTag) {
|
||||||
|
return mapToArray(object);
|
||||||
|
}
|
||||||
|
if (tag == setTag) {
|
||||||
|
return setToPairs(object);
|
||||||
|
}
|
||||||
|
return baseToPairs(object, keysFunc(object));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -12906,8 +12929,8 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an array of own enumerable string keyed-value pairs for `object`
|
* Creates an array of own enumerable string keyed-value pairs for `object`
|
||||||
* which can be consumed by `_.fromPairs`. If `object` is a map, its entries
|
* which can be consumed by `_.fromPairs`. If `object` is a map or set, its
|
||||||
* are returned.
|
* entries are returned.
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
* @memberOf _
|
* @memberOf _
|
||||||
@@ -12932,8 +12955,8 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an array of own and inherited enumerable string keyed-value pairs
|
* Creates an array of own and inherited enumerable string keyed-value pairs
|
||||||
* for `object` which can be consumed by `_.fromPairs`. If `object` is a map,
|
* for `object` which can be consumed by `_.fromPairs`. If `object` is a map
|
||||||
* its entries are returned.
|
* or set, its entries are returned.
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
* @memberOf _
|
* @memberOf _
|
||||||
|
|||||||
Reference in New Issue
Block a user