mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-05 17:37:50 +00:00
Make _.isEmpty work as expected on buffers.
This commit is contained in:
committed by
John-David Dalton
parent
583b03ba5f
commit
271f64ee3f
@@ -10173,8 +10173,8 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if `value` is an empty object or collection. A value is considered
|
* Checks if `value` is an empty object or collection. 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, buffer, string, or jQuery-like
|
||||||
* with a length of `0` or has no own enumerable string keyed properties.
|
* collection with a length of `0` or has no own enumerable string keyed properties.
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
* @memberOf _
|
* @memberOf _
|
||||||
@@ -10201,8 +10201,8 @@
|
|||||||
*/
|
*/
|
||||||
function isEmpty(value) {
|
function isEmpty(value) {
|
||||||
if (isArrayLike(value) &&
|
if (isArrayLike(value) &&
|
||||||
(isArray(value) || isString(value) ||
|
(isArray(value) || isString(value) || isFunction(value.splice) ||
|
||||||
isFunction(value.splice) || isArguments(value))) {
|
isArguments(value) || isBuffer(value))) {
|
||||||
return !value.length;
|
return !value.length;
|
||||||
}
|
}
|
||||||
for (var key in value) {
|
for (var key in value) {
|
||||||
|
|||||||
10
test/test.js
10
test/test.js
@@ -8658,7 +8658,7 @@
|
|||||||
var args = arguments;
|
var args = arguments;
|
||||||
|
|
||||||
QUnit.test('should return `true` for empty values', function(assert) {
|
QUnit.test('should return `true` for empty values', function(assert) {
|
||||||
assert.expect(8);
|
assert.expect(10);
|
||||||
|
|
||||||
var expected = lodashStable.map(empties, alwaysTrue),
|
var expected = lodashStable.map(empties, alwaysTrue),
|
||||||
actual = lodashStable.map(empties, _.isEmpty);
|
actual = lodashStable.map(empties, _.isEmpty);
|
||||||
@@ -8672,6 +8672,14 @@
|
|||||||
assert.strictEqual(_.isEmpty(/x/), true);
|
assert.strictEqual(_.isEmpty(/x/), true);
|
||||||
assert.strictEqual(_.isEmpty(symbol), true);
|
assert.strictEqual(_.isEmpty(symbol), true);
|
||||||
assert.strictEqual(_.isEmpty(), true);
|
assert.strictEqual(_.isEmpty(), true);
|
||||||
|
|
||||||
|
if (Buffer) {
|
||||||
|
assert.strictEqual(_.isEmpty(new Buffer(0)), true);
|
||||||
|
assert.strictEqual(_.isEmpty(new Buffer(1)), false);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
skipAssert(assert, 2);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('should return `false` for non-empty values', function(assert) {
|
QUnit.test('should return `false` for non-empty values', function(assert) {
|
||||||
|
|||||||
Reference in New Issue
Block a user