mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 10:17:48 +00:00
Add _.entries and _.entriesIn aliases.
This commit is contained in:
@@ -12,6 +12,8 @@ exports.aliasToReal = {
|
|||||||
'dissocPath': 'unset',
|
'dissocPath': 'unset',
|
||||||
'each': 'forEach',
|
'each': 'forEach',
|
||||||
'eachRight': 'forEachRight',
|
'eachRight': 'forEachRight',
|
||||||
|
'entries': 'toPairs',
|
||||||
|
'entriesIn': 'toPairsIn',
|
||||||
'equals': 'isEqual',
|
'equals': 'isEqual',
|
||||||
'extend': 'assignIn',
|
'extend': 'assignIn',
|
||||||
'extendWith': 'assignInWith',
|
'extendWith': 'assignInWith',
|
||||||
|
|||||||
@@ -12298,6 +12298,7 @@
|
|||||||
* @static
|
* @static
|
||||||
* @memberOf _
|
* @memberOf _
|
||||||
* @since 4.0.0
|
* @since 4.0.0
|
||||||
|
* @alias entries
|
||||||
* @category Object
|
* @category Object
|
||||||
* @param {Object} object The object to query.
|
* @param {Object} object The object to query.
|
||||||
* @returns {Array} Returns the new array of key-value pairs.
|
* @returns {Array} Returns the new array of key-value pairs.
|
||||||
@@ -12324,6 +12325,7 @@
|
|||||||
* @static
|
* @static
|
||||||
* @memberOf _
|
* @memberOf _
|
||||||
* @since 4.0.0
|
* @since 4.0.0
|
||||||
|
* @alias entriesIn
|
||||||
* @category Object
|
* @category Object
|
||||||
* @param {Object} object The object to query.
|
* @param {Object} object The object to query.
|
||||||
* @returns {Array} Returns the new array of key-value pairs.
|
* @returns {Array} Returns the new array of key-value pairs.
|
||||||
@@ -15048,6 +15050,8 @@
|
|||||||
lodash.zipWith = zipWith;
|
lodash.zipWith = zipWith;
|
||||||
|
|
||||||
// Add aliases.
|
// Add aliases.
|
||||||
|
lodash.entries = toPairs;
|
||||||
|
lodash.entriesIn = toPairsIn;
|
||||||
lodash.extend = assignIn;
|
lodash.extend = assignIn;
|
||||||
lodash.extendWith = assignInWith;
|
lodash.extendWith = assignInWith;
|
||||||
|
|
||||||
|
|||||||
45
test/test.js
45
test/test.js
@@ -22084,28 +22084,54 @@
|
|||||||
QUnit.module('lodash.toPairs');
|
QUnit.module('lodash.toPairs');
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
QUnit.test('should create a two dimensional array of key-value pairs', function(assert) {
|
QUnit.test('should be aliased', function(assert) {
|
||||||
|
assert.expect(1);
|
||||||
|
|
||||||
|
assert.strictEqual(_.entries, _.toPairs);
|
||||||
|
});
|
||||||
|
}());
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
QUnit.module('lodash.toPairsIn');
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
QUnit.test('should be aliased', function(assert) {
|
||||||
|
assert.expect(1);
|
||||||
|
|
||||||
|
assert.strictEqual(_.entriesIn, _.toPairsIn);
|
||||||
|
});
|
||||||
|
}());
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
QUnit.module('toPairs methods');
|
||||||
|
|
||||||
|
lodashStable.each(['toPairs', 'toPairsIn'], function(methodName) {
|
||||||
|
var func = _[methodName];
|
||||||
|
|
||||||
|
QUnit.test('`_.' + methodName + '` should create a two dimensional array of key-value pairs', function(assert) {
|
||||||
assert.expect(1);
|
assert.expect(1);
|
||||||
|
|
||||||
var object = { 'a': 1, 'b': 2 };
|
var object = { 'a': 1, 'b': 2 };
|
||||||
assert.deepEqual(_.toPairs(object), [['a', 1], ['b', 2]]);
|
assert.deepEqual(func(object), [['a', 1], ['b', 2]]);
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('should work with an object that has a `length` property', function(assert) {
|
QUnit.test('`_.' + methodName + '` should work with an object that has a `length` property', function(assert) {
|
||||||
assert.expect(1);
|
assert.expect(1);
|
||||||
|
|
||||||
var object = { '0': 'a', '1': 'b', 'length': 2 };
|
var object = { '0': 'a', '1': 'b', 'length': 2 };
|
||||||
assert.deepEqual(_.toPairs(object), [['0', 'a'], ['1', 'b'], ['length', 2]]);
|
assert.deepEqual(func(object), [['0', 'a'], ['1', 'b'], ['length', 2]]);
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('should work with strings', function(assert) {
|
QUnit.test('`_.' + methodName + '` should work with strings', function(assert) {
|
||||||
assert.expect(2);
|
assert.expect(2);
|
||||||
|
|
||||||
lodashStable.each(['xo', Object('xo')], function(string) {
|
lodashStable.each(['xo', Object('xo')], function(string) {
|
||||||
assert.deepEqual(_.toPairs(string), [['0', 'x'], ['1', 'o']]);
|
assert.deepEqual(func(string), [['0', 'x'], ['1', 'o']]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}());
|
});
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
@@ -24693,6 +24719,7 @@
|
|||||||
'times',
|
'times',
|
||||||
'toArray',
|
'toArray',
|
||||||
'toPairs',
|
'toPairs',
|
||||||
|
'toPairsIn',
|
||||||
'union',
|
'union',
|
||||||
'uniq',
|
'uniq',
|
||||||
'values',
|
'values',
|
||||||
@@ -24704,7 +24731,7 @@
|
|||||||
var acceptFalsey = lodashStable.difference(allMethods, rejectFalsey);
|
var acceptFalsey = lodashStable.difference(allMethods, rejectFalsey);
|
||||||
|
|
||||||
QUnit.test('should accept falsey arguments', function(assert) {
|
QUnit.test('should accept falsey arguments', function(assert) {
|
||||||
assert.expect(302);
|
assert.expect(305);
|
||||||
|
|
||||||
var emptyArrays = lodashStable.map(falsey, alwaysEmptyArray);
|
var emptyArrays = lodashStable.map(falsey, alwaysEmptyArray);
|
||||||
|
|
||||||
@@ -24742,7 +24769,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('should return an array', function(assert) {
|
QUnit.test('should return an array', function(assert) {
|
||||||
assert.expect(70);
|
assert.expect(72);
|
||||||
|
|
||||||
var array = [1, 2, 3];
|
var array = [1, 2, 3];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user