Specify string keyed properties. [closes #2081] [ci skip]

This commit is contained in:
John-David Dalton
2016-03-03 18:02:47 -08:00
parent e4b3cde0a4
commit 25121a86bb
2 changed files with 77 additions and 72 deletions

View File

@@ -8421,7 +8421,7 @@
/** /**
* Gets the size of `collection` by returning its length for array-like * Gets the size of `collection` by returning its length for array-like
* values or the number of own enumerable properties for objects. * values or the number of own enumerable string keyed properties for objects.
* *
* @static * @static
* @memberOf _ * @memberOf _
@@ -10011,7 +10011,7 @@
/** /**
* Checks if `value` is an empty collection or object. A value is considered * Checks if `value` is an empty collection or object. A value is considered
* empty if it's an `arguments` object, array, string, or jQuery-like collection * empty if it's an `arguments` object, array, string, or jQuery-like collection
* with a length of `0` or has no own enumerable properties. * with a length of `0` or has no own enumerable string keyed properties.
* *
* @static * @static
* @memberOf _ * @memberOf _
@@ -10977,8 +10977,8 @@
} }
/** /**
* Converts `value` to a plain object flattening inherited enumerable * Converts `value` to a plain object flattening inherited enumerable string
* properties of `value` to own properties of the plain object. * keyed properties of `value` to own properties of the plain object.
* *
* @static * @static
* @memberOf _ * @memberOf _
@@ -11071,9 +11071,9 @@
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
/** /**
* Assigns own enumerable properties of source objects to the destination * Assigns own enumerable string keyed properties of source objects to the
* object. Source objects are applied from left to right. Subsequent sources * destination object. Source objects are applied from left to right.
* overwrite property assignments of previous sources. * Subsequent sources overwrite property assignments of previous sources.
* *
* **Note:** This method mutates `object` and is loosely based on * **Note:** This method mutates `object` and is loosely based on
* [`Object.assign`](https://mdn.io/Object/assign). * [`Object.assign`](https://mdn.io/Object/assign).
@@ -11243,7 +11243,8 @@
/** /**
* Creates an object that inherits from the `prototype` object. If a `properties` * Creates an object that inherits from the `prototype` object. If a `properties`
* object is given its own enumerable properties are assigned to the created object. * object is given its own enumerable string keyed properties are assigned to
* the created object.
* *
* @static * @static
* @memberOf _ * @memberOf _
@@ -11280,10 +11281,10 @@
} }
/** /**
* Assigns own and inherited enumerable properties of source objects to the * Assigns own and inherited enumerable string keyed properties of source
* destination object for all destination properties that resolve to `undefined`. * objects to the destination object for all destination properties that
* Source objects are applied from left to right. Once a property is set, * resolve to `undefined`. Source objects are applied from left to right.
* additional values of the same property are ignored. * Once a property is set, additional values of the same property are ignored.
* *
* **Note:** This method mutates `object`. * **Note:** This method mutates `object`.
* *
@@ -11405,10 +11406,10 @@
} }
/** /**
* Iterates over own and inherited enumerable properties of an object invoking * Iterates over own and inherited enumerable string keyed properties of an
* `iteratee` for each property. The iteratee is invoked with three arguments: * object invoking `iteratee` for each property. The iteratee is invoked with
* (value, key, object). Iteratee functions may exit iteration early by explicitly * three arguments: (value, key, object). Iteratee functions may exit iteration
* returning `false`. * early by explicitly returning `false`.
* *
* @static * @static
* @memberOf _ * @memberOf _
@@ -11469,8 +11470,8 @@
} }
/** /**
* Iterates over own enumerable properties of an object invoking `iteratee` * Iterates over own enumerable string keyed properties of an object invoking
* for each property. The iteratee is invoked with three arguments: * `iteratee` for each property. The iteratee is invoked with three arguments:
* (value, key, object). Iteratee functions may exit iteration early by * (value, key, object). Iteratee functions may exit iteration early by
* explicitly returning `false`. * explicitly returning `false`.
* *
@@ -11529,8 +11530,8 @@
} }
/** /**
* Creates an array of function property names from own enumerable properties * Creates an array of function property names from own enumerable string
* of `object`. * keyed properties of `object`.
* *
* @static * @static
* @since 0.1.0 * @since 0.1.0
@@ -11748,7 +11749,7 @@
var invoke = rest(baseInvoke); var invoke = rest(baseInvoke);
/** /**
* Creates an array of the own enumerable property names of `object`. * Creates an array of the own enumerable string keyed property names of `object`.
* *
* **Note:** Non-object values are coerced to objects. See the * **Note:** Non-object values are coerced to objects. See the
* [ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys) * [ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys)
@@ -11796,7 +11797,8 @@
} }
/** /**
* Creates an array of the own and inherited enumerable property names of `object`. * Creates an array of the own and inherited enumerable string keyed property
* names of `object`.
* *
* **Note:** Non-object values are coerced to objects. * **Note:** Non-object values are coerced to objects.
* *
@@ -11841,8 +11843,8 @@
/** /**
* The opposite of `_.mapValues`; this method creates an object with the * The opposite of `_.mapValues`; this method creates an object with the
* same values as `object` and keys generated by running each own enumerable * same values as `object` and keys generated by running each own enumerable
* property of `object` through `iteratee`. The iteratee is invoked with * string keyed property of `object` through `iteratee`. The iteratee is
* three arguments: (value, key, object). * invoked with three arguments: (value, key, object).
* *
* @static * @static
* @memberOf _ * @memberOf _
@@ -11870,8 +11872,9 @@
/** /**
* Creates an object with the same keys as `object` and values generated by * Creates an object with the same keys as `object` and values generated by
* running each own enumerable property of `object` through `iteratee`. The * running each own enumerable string keyed property of `object` through
* iteratee is invoked with three arguments: (value, key, object). * `iteratee`. The iteratee is invoked with three arguments:
* (value, key, object).
* *
* @static * @static
* @memberOf _ * @memberOf _
@@ -11906,12 +11909,12 @@
/** /**
* This method is like `_.assign` except that it recursively merges own and * This method is like `_.assign` except that it recursively merges own and
* inherited enumerable properties of source objects into the destination * inherited enumerable string keyed properties of source objects into the
* object. Source properties that resolve to `undefined` are skipped if a * destination object. Source properties that resolve to `undefined` are
* destination value exists. Array and plain object properties are merged * skipped if a destination value exists. Array and plain object properties
* recursively.Other objects and value types are overridden by assignment. * are merged recursively.Other objects and value types are overridden by
* Source objects are applied from left to right. Subsequent sources * assignment. Source objects are applied from left to right. Subsequent
* overwrite property assignments of previous sources. * sources overwrite property assignments of previous sources.
* *
* **Note:** This method mutates `object`. * **Note:** This method mutates `object`.
* *
@@ -11983,7 +11986,8 @@
/** /**
* The opposite of `_.pick`; this method creates an object composed of the * The opposite of `_.pick`; this method creates an object composed of the
* own and inherited enumerable properties of `object` that are not omitted. * own and inherited enumerable string keyed properties of `object` that are
* not omitted.
* *
* @static * @static
* @since 0.1.0 * @since 0.1.0
@@ -12010,9 +12014,9 @@
/** /**
* The opposite of `_.pickBy`; this method creates an object composed of * The opposite of `_.pickBy`; this method creates an object composed of
* the own and inherited enumerable properties of `object` that `predicate` * the own and inherited enumerable string keyed properties of `object` that
* doesn't return truthy for. The predicate is invoked with two arguments: * `predicate` doesn't return truthy for. The predicate is invoked with two
* (value, key). * arguments: (value, key).
* *
* @static * @static
* @memberOf _ * @memberOf _
@@ -12184,8 +12188,8 @@
} }
/** /**
* Creates an array of own enumerable key-value pairs for `object` which * Creates an array of own enumerable string keyed-value pairs for `object`
* can be consumed by `_.fromPairs`. * which can be consumed by `_.fromPairs`.
* *
* @static * @static
* @memberOf _ * @memberOf _
@@ -12210,8 +12214,8 @@
} }
/** /**
* Creates an array of own and inherited enumerable key-value pairs for * Creates an array of own and inherited enumerable string keyed-value pairs
* `object` which can be consumed by `_.fromPairs`. * for `object` which can be consumed by `_.fromPairs`.
* *
* @static * @static
* @memberOf _ * @memberOf _
@@ -12238,8 +12242,8 @@
/** /**
* An alternative to `_.reduce`; this method transforms `object` to a new * An alternative to `_.reduce`; this method transforms `object` to a new
* `accumulator` object which is the result of running each of its own enumerable * `accumulator` object which is the result of running each of its own enumerable
* properties through `iteratee`, with each invocation potentially mutating * string keyed properties through `iteratee`, with each invocation potentially
* the `accumulator` object. The iteratee is invoked with four arguments: * mutating the `accumulator` object. The iteratee is invoked with four arguments:
* (accumulator, value, key, object). Iteratee functions may exit iteration * (accumulator, value, key, object). Iteratee functions may exit iteration
* early by explicitly returning `false`. * early by explicitly returning `false`.
* *
@@ -12378,7 +12382,7 @@
} }
/** /**
* Creates an array of the own enumerable property values of `object`. * Creates an array of the own enumerable string keyed property values of `object`.
* *
* **Note:** Non-object values are coerced to objects. * **Note:** Non-object values are coerced to objects.
* *
@@ -12408,7 +12412,8 @@
} }
/** /**
* Creates an array of the own and inherited enumerable property values of `object`. * Creates an array of the own and inherited enumerable string keyed property
* values of `object`.
* *
* **Note:** Non-object values are coerced to objects. * **Note:** Non-object values are coerced to objects.
* *
@@ -14056,9 +14061,9 @@
}); });
/** /**
* Adds all own enumerable function properties of a source object to the * Adds all own enumerable string keyed function properties of a source object
* destination object. If `object` is a function then methods are added to * to the destination object. If `object` is a function then methods are added
* its prototype as well. * to its prototype as well.
* *
* **Note:** Use `_.runInContext` to create a pristine `lodash` function to * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
* avoid conflicts caused by modifying the original. * avoid conflicts caused by modifying the original.

View File

@@ -369,7 +369,7 @@
}); });
/** /**
* Removes all own enumerable properties from a given object. * Removes all own enumerable string keyed properties from a given object.
* *
* @private * @private
* @param {Object} object The object to empty. * @param {Object} object The object to empty.
@@ -6075,7 +6075,7 @@
lodashStable.each(['forIn', 'forInRight'], function(methodName) { lodashStable.each(['forIn', 'forInRight'], function(methodName) {
var func = _[methodName]; var func = _[methodName];
QUnit.test('`_.' + methodName + '` iterates over inherited properties', function(assert) { QUnit.test('`_.' + methodName + '` iterates over inherited string keyed properties', function(assert) {
assert.expect(1); assert.expect(1);
function Foo() { this.a = 1; } function Foo() { this.a = 1; }
@@ -6529,7 +6529,7 @@
assert.deepEqual(actual, expected); assert.deepEqual(actual, expected);
}); });
QUnit.test('`_.' + methodName + '` should assign own ' + (isAssign ? '' : 'and inherited ') + 'source properties', function(assert) { QUnit.test('`_.' + methodName + '` should assign own ' + (isAssign ? '' : 'and inherited ') + 'string keyed source properties', function(assert) {
assert.expect(1); assert.expect(1);
function Foo() { this.a = 1; } function Foo() { this.a = 1; }
@@ -9877,7 +9877,7 @@
assert.strictEqual(_.isMatch(object, { 'a': { 'b': { 'c': 1 } } }), true); assert.strictEqual(_.isMatch(object, { 'a': { 'b': { 'c': 1 } } }), true);
}); });
QUnit.test('should match inherited `object` properties', function(assert) { QUnit.test('should match inherited string keyed `object` properties', function(assert) {
assert.expect(1); assert.expect(1);
function Foo() { this.a = 1; } function Foo() { this.a = 1; }
@@ -12218,12 +12218,22 @@
func = _[methodName], func = _[methodName],
isKeys = methodName == 'keys'; isKeys = methodName == 'keys';
QUnit.test('`_.' + methodName + '` should return the keys of an object', function(assert) { QUnit.test('`_.' + methodName + '` should return the string keyed property names of `object`', function(assert) {
assert.expect(1); assert.expect(1);
assert.deepEqual(func({ 'a': 1, 'b': 1 }).sort(), ['a', 'b']); assert.deepEqual(func({ 'a': 1, 'b': 1 }).sort(), ['a', 'b']);
}); });
QUnit.test('`_.' + methodName + '` should ' + (isKeys ? 'not ' : '') + 'include inherited string keyed properties', function(assert) {
assert.expect(1);
function Foo() { this.a = 1; }
Foo.prototype.b = 2;
var expected = isKeys ? ['a'] : ['a', 'b'];
assert.deepEqual(func(new Foo).sort(), expected);
});
QUnit.test('`_.' + methodName + '` should coerce primitives to objects (test in IE 9)', function(assert) { QUnit.test('`_.' + methodName + '` should coerce primitives to objects (test in IE 9)', function(assert) {
assert.expect(2); assert.expect(2);
@@ -12263,7 +12273,7 @@
assert.deepEqual(func(array).sort(), ['0', 'a']); assert.deepEqual(func(array).sort(), ['0', 'a']);
}); });
QUnit.test('`_.' + methodName + '` should ' + (isKeys ? 'not ' : '') + 'include inherited properties of arrays', function(assert) { QUnit.test('`_.' + methodName + '` should ' + (isKeys ? 'not ' : '') + 'include inherited string keyed properties of arrays', function(assert) {
assert.expect(1); assert.expect(1);
var expected = isKeys ? ['0'] : ['0', 'a']; var expected = isKeys ? ['0'] : ['0', 'a'];
@@ -12299,7 +12309,7 @@
assert.deepEqual(actual, expected); assert.deepEqual(actual, expected);
}); });
QUnit.test('`_.' + methodName + '` should ' + (isKeys ? 'not ' : '') + 'include inherited properties of `arguments` objects', function(assert) { QUnit.test('`_.' + methodName + '` should ' + (isKeys ? 'not ' : '') + 'include inherited string keyed properties of `arguments` objects', function(assert) {
assert.expect(1); assert.expect(1);
var values = [args, strictArgs], var values = [args, strictArgs],
@@ -12330,7 +12340,7 @@
assert.deepEqual(func(object).sort(), ['0', 'a']); assert.deepEqual(func(object).sort(), ['0', 'a']);
}); });
QUnit.test('`_.' + methodName + '` should ' + (isKeys ? 'not ' : '') + 'include inherited properties of string objects', function(assert) { QUnit.test('`_.' + methodName + '` should ' + (isKeys ? 'not ' : '') + 'include inherited string keyed properties of string objects', function(assert) {
assert.expect(1); assert.expect(1);
var expected = isKeys ? ['0'] : ['0', 'a']; var expected = isKeys ? ['0'] : ['0', 'a'];
@@ -12356,16 +12366,6 @@
Fake.prototype.constructor = Fake; Fake.prototype.constructor = Fake;
assert.deepEqual(func(Fake.prototype), ['constructor']); assert.deepEqual(func(Fake.prototype), ['constructor']);
}); });
QUnit.test('`_.' + methodName + '` should ' + (isKeys ? 'not ' : '') + 'include inherited properties', function(assert) {
assert.expect(1);
function Foo() { this.a = 1; }
Foo.prototype.b = 2;
var expected = isKeys ? ['a'] : ['a', 'b'];
assert.deepEqual(func(new Foo).sort(), expected);
});
}); });
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
@@ -12981,7 +12981,7 @@
assert.strictEqual(matches(object), true); assert.strictEqual(matches(object), true);
}); });
QUnit.test('should match inherited `object` properties', function(assert) { QUnit.test('should match inherited string keyed `object` properties', function(assert) {
assert.expect(1); assert.expect(1);
function Foo() { this.a = 1; } function Foo() { this.a = 1; }
@@ -13415,7 +13415,7 @@
}); });
}); });
QUnit.test('should match inherited `srcValue` properties', function(assert) { QUnit.test('should match inherited string keyed `srcValue` properties', function(assert) {
assert.expect(2); assert.expect(2);
function Foo() {} function Foo() {}
@@ -15460,7 +15460,7 @@
assert.deepEqual(func(object, prop(object, ['a', 'c'])), expected); assert.deepEqual(func(object, prop(object, ['a', 'c'])), expected);
}); });
QUnit.test('`_.' + methodName + '` should iterate over inherited properties', function(assert) { QUnit.test('`_.' + methodName + '` should iterate over inherited string keyed properties', function(assert) {
assert.expect(1); assert.expect(1);
function Foo() {} function Foo() {}
@@ -16511,7 +16511,7 @@
assert.deepEqual(func(object, prop(object, ['a', 'c'])), expected); assert.deepEqual(func(object, prop(object, ['a', 'c'])), expected);
}); });
QUnit.test('`_.' + methodName + '` should iterate over inherited properties', function(assert) { QUnit.test('`_.' + methodName + '` should iterate over inherited string keyed properties', function(assert) {
assert.expect(1); assert.expect(1);
function Foo() {} function Foo() {}
@@ -18745,7 +18745,7 @@
var args = arguments, var args = arguments,
array = [1, 2, 3]; array = [1, 2, 3];
QUnit.test('should return the number of own enumerable properties of an object', function(assert) { QUnit.test('should return the number of own enumerable string keyed properties of an object', function(assert) {
assert.expect(1); assert.expect(1);
assert.strictEqual(_.size({ 'one': 1, 'two': 2, 'three': 3 }), 3); assert.strictEqual(_.size({ 'one': 1, 'two': 2, 'three': 3 }), 3);
@@ -21973,7 +21973,7 @@
(function() { (function() {
var args = arguments; var args = arguments;
QUnit.test('should flatten inherited properties', function(assert) { QUnit.test('should flatten inherited string keyed properties', function(assert) {
assert.expect(1); assert.expect(1);
function Foo() { this.b = 2; } function Foo() { this.b = 2; }
@@ -23218,7 +23218,7 @@
assert.deepEqual(func(object), ['a', 'b', 2]); assert.deepEqual(func(object), ['a', 'b', 2]);
}); });
QUnit.test('`_.' + methodName + '` should ' + (isValues ? 'not ' : '') + ' include inherited property values', function(assert) { QUnit.test('`_.' + methodName + '` should ' + (isValues ? 'not ' : '') + 'include inherited string keyed property values', function(assert) {
assert.expect(1); assert.expect(1);
function Foo() { this.a = 1; } function Foo() { this.a = 1; }