From 2c3ab276ead08b827122b2eddc3fb9866bf22ac2 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sun, 6 Mar 2016 22:33:59 -0800 Subject: [PATCH] Add `_.entries` and `_.entriesIn` aliases. --- fp/_mapping.js | 2 ++ lodash.js | 4 ++++ test/test.js | 45 ++++++++++++++++++++++++++++++++++++--------- 3 files changed, 42 insertions(+), 9 deletions(-) diff --git a/fp/_mapping.js b/fp/_mapping.js index 1dbf0288b..952b80a37 100644 --- a/fp/_mapping.js +++ b/fp/_mapping.js @@ -12,6 +12,8 @@ exports.aliasToReal = { 'dissocPath': 'unset', 'each': 'forEach', 'eachRight': 'forEachRight', + 'entries': 'toPairs', + 'entriesIn': 'toPairsIn', 'equals': 'isEqual', 'extend': 'assignIn', 'extendWith': 'assignInWith', diff --git a/lodash.js b/lodash.js index ca2ead78e..8690ee567 100644 --- a/lodash.js +++ b/lodash.js @@ -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; diff --git a/test/test.js b/test/test.js index 1d75ba192..b0050991a 100644 --- a/test/test.js +++ b/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];