Add isArrayLike builtin (#453)

This commit is contained in:
Max Graey
2019-02-27 22:47:52 +02:00
committed by Daniel Wirtz
parent e8b0767143
commit aad263e670
8 changed files with 327 additions and 212 deletions

View File

@ -215,6 +215,13 @@ globalScope["isString"] = function isString(arg) {
};
globalScope["isArray"] = Array.isArray;
globalScope["isArrayLike"] = function isArrayLike(expr) {
return expr
&& typeof expr === 'object'
&& typeof expr.length === 'number'
&& expr.length >= 0
&& Math.trunc(expr.length) === expr.length;
}
globalScope["isDefined"] = function isDefined(expr) {
return typeof expr !== "undefined";