mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 15:27:50 +00:00
Add _.entries and _.entriesIn aliases.
This commit is contained in:
@@ -12,6 +12,8 @@ exports.aliasToReal = {
|
||||
'dissocPath': 'unset',
|
||||
'each': 'forEach',
|
||||
'eachRight': 'forEachRight',
|
||||
'entries': 'toPairs',
|
||||
'entriesIn': 'toPairsIn',
|
||||
'equals': 'isEqual',
|
||||
'extend': 'assignIn',
|
||||
'extendWith': 'assignInWith',
|
||||
|
||||
@@ -12298,6 +12298,7 @@
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @since 4.0.0
|
||||
* @alias entries
|
||||
* @category Object
|
||||
* @param {Object} object The object to query.
|
||||
* @returns {Array} Returns the new array of key-value pairs.
|
||||
@@ -12324,6 +12325,7 @@
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @since 4.0.0
|
||||
* @alias entriesIn
|
||||
* @category Object
|
||||
* @param {Object} object The object to query.
|
||||
* @returns {Array} Returns the new array of key-value pairs.
|
||||
@@ -15048,6 +15050,8 @@
|
||||
lodash.zipWith = zipWith;
|
||||
|
||||
// Add aliases.
|
||||
lodash.entries = toPairs;
|
||||
lodash.entriesIn = toPairsIn;
|
||||
lodash.extend = assignIn;
|
||||
lodash.extendWith = assignInWith;
|
||||
|
||||
|
||||
45
test/test.js
45
test/test.js
@@ -22084,28 +22084,54 @@
|
||||
QUnit.module('lodash.toPairs');
|
||||
|
||||
(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);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
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',
|
||||
'toArray',
|
||||
'toPairs',
|
||||
'toPairsIn',
|
||||
'union',
|
||||
'uniq',
|
||||
'values',
|
||||
@@ -24704,7 +24731,7 @@
|
||||
var acceptFalsey = lodashStable.difference(allMethods, rejectFalsey);
|
||||
|
||||
QUnit.test('should accept falsey arguments', function(assert) {
|
||||
assert.expect(302);
|
||||
assert.expect(305);
|
||||
|
||||
var emptyArrays = lodashStable.map(falsey, alwaysEmptyArray);
|
||||
|
||||
@@ -24742,7 +24769,7 @@
|
||||
});
|
||||
|
||||
QUnit.test('should return an array', function(assert) {
|
||||
assert.expect(70);
|
||||
assert.expect(72);
|
||||
|
||||
var array = [1, 2, 3];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user