@newdash/newdash
Version:
javascript/typescript utility library
25 lines (24 loc) • 724 B
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.toLength = void 0;
const toInteger_1 = __importDefault(require("./toInteger"));
/** Used as references for the maximum length and index of an array. */
const MAX_ARRAY_LENGTH = 4294967295;
function toLength(value) {
if (!value) {
return 0;
}
value = (0, toInteger_1.default)(value);
if (value < 0) {
return 0;
}
if (value > MAX_ARRAY_LENGTH) {
return MAX_ARRAY_LENGTH;
}
return value;
}
exports.toLength = toLength;
exports.default = toLength;