mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 15:57:48 +00:00
Expose _.isLength.
This commit is contained in:
committed by
John-David Dalton
parent
3d25b2fd9b
commit
7e726735ba
33
lodash.js
33
lodash.js
@@ -1122,19 +1122,6 @@
|
||||
return value > -1 && value % 1 == 0 && value < length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if `value` is a valid array-like length.
|
||||
*
|
||||
* **Note:** This function is based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
|
||||
*
|
||||
* @private
|
||||
* @param {*} value The value to check.
|
||||
* @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
|
||||
*/
|
||||
function isLength(value) {
|
||||
return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used by `trimmedLeftIndex` and `trimmedRightIndex` to determine if a
|
||||
* character code is whitespace.
|
||||
@@ -1480,8 +1467,8 @@
|
||||
* `head`, `identity`, `includes`, `indexOf`, `inRange`, `isArguments`, `isArray`,
|
||||
* `isArrayLike`, `isArrayLikeObject`, `isBoolean`, `isDate`, `isElement`,
|
||||
* `isEmpty`, `isEqual`, `isEqualWith`, `isError`, `isFinite`, `isFunction`,
|
||||
* `isInteger`, `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`,
|
||||
* `isNumber`, `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`,
|
||||
* `isInteger`, `isLength`, `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`,
|
||||
* `isNull`, `isNumber`, `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`,
|
||||
* `isSafeInteger`, `isString`, `isUndefined`, `isTypedArray`, `join`, `kebabCase`,
|
||||
* `last`, `lastIndexOf`, `lowerCase`, `lowerFirst`, `lt`, `lte`, `max`, `min`,
|
||||
* `noConflict`, `noop`, `now`, `pad`, `padLeft`, `padRight`, `parseInt`, `pop`,
|
||||
@@ -9318,6 +9305,21 @@
|
||||
return typeof value == 'number' && value == toInteger(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if `value` is a valid array-like length.
|
||||
*
|
||||
* **Note:** This function is based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Lang
|
||||
* @param {*} value The value to check.
|
||||
* @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
|
||||
*/
|
||||
function isLength(value) {
|
||||
return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
|
||||
* (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
|
||||
@@ -13428,6 +13430,7 @@
|
||||
lodash.isFinite = isFinite;
|
||||
lodash.isFunction = isFunction;
|
||||
lodash.isInteger = isInteger;
|
||||
lodash.isLength = isLength;
|
||||
lodash.isMatch = isMatch;
|
||||
lodash.isMatchWith = isMatchWith;
|
||||
lodash.isNaN = isNaN;
|
||||
|
||||
66
test/test.js
66
test/test.js
@@ -572,7 +572,7 @@
|
||||
|
||||
if (isModularize && !(amd || isNpm)) {
|
||||
lodashStable.each(['internal/baseEach', 'internal/isIndex',
|
||||
'internal/isIterateeCall', 'internal/isLength'], function(relPath) {
|
||||
'internal/isIterateeCall'], function(relPath) {
|
||||
var func = require(path.join(basePath, relPath)),
|
||||
funcName = path.basename(relPath);
|
||||
|
||||
@@ -829,41 +829,6 @@
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
QUnit.module('isLength');
|
||||
|
||||
(function() {
|
||||
var func = _._isLength;
|
||||
|
||||
QUnit.test('should return `true` for lengths', function(assert) {
|
||||
assert.expect(3);
|
||||
|
||||
if (func) {
|
||||
assert.strictEqual(func(0), true);
|
||||
assert.strictEqual(func(3), true);
|
||||
assert.strictEqual(func(MAX_SAFE_INTEGER), true);
|
||||
}
|
||||
else {
|
||||
skipTest(assert, 3);
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.test('should return `false` for non-lengths', function(assert) {
|
||||
assert.expect(4);
|
||||
|
||||
if (func) {
|
||||
assert.strictEqual(func(-1), false);
|
||||
assert.strictEqual(func('1'), false);
|
||||
assert.strictEqual(func(1.1), false);
|
||||
assert.strictEqual(func(MAX_SAFE_INTEGER + 1), false);
|
||||
}
|
||||
else {
|
||||
skipTest(assert, 4);
|
||||
}
|
||||
});
|
||||
}());
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
QUnit.module('lodash constructor');
|
||||
|
||||
(function() {
|
||||
@@ -8599,6 +8564,33 @@
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
QUnit.module('lodash.isLength');
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
QUnit.module('isLength');
|
||||
|
||||
(function() {
|
||||
QUnit.test('should return `true` for lengths', function(assert) {
|
||||
assert.expect(3);
|
||||
|
||||
assert.strictEqual(_.isLength(0), true);
|
||||
assert.strictEqual(_.isLength(3), true);
|
||||
assert.strictEqual(_.isLength(MAX_SAFE_INTEGER), true);
|
||||
});
|
||||
|
||||
QUnit.test('should return `false` for non-lengths', function(assert) {
|
||||
assert.expect(4);
|
||||
|
||||
assert.strictEqual(_.isLength(-1), false);
|
||||
assert.strictEqual(_.isLength('1'), false);
|
||||
assert.strictEqual(_.isLength(1.1), false);
|
||||
assert.strictEqual(_.isLength(MAX_SAFE_INTEGER + 1), false);
|
||||
});
|
||||
}());
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
QUnit.module('lodash.isMatch');
|
||||
|
||||
(function() {
|
||||
@@ -22028,7 +22020,7 @@
|
||||
var acceptFalsey = lodashStable.difference(allMethods, rejectFalsey);
|
||||
|
||||
QUnit.test('should accept falsey arguments', function(assert) {
|
||||
assert.expect(272);
|
||||
assert.expect(273);
|
||||
|
||||
var emptyArrays = lodashStable.map(falsey, lodashStable.constant([]));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user