-
Notifications
You must be signed in to change notification settings - Fork 0
ds.predicates
The ds.predicates
module is a collection of functions which indicate whether a particular predicate (property) holds true for a particular object.
isArrayOf(object, predicate, [length=true])
Checks if object
is an array and predicate
holds true for all its elements.
ds.predicates.isArrayOf([0, 1, 2], ds.predicates.isNumber);
// => true
ds.predicates.isArrayOf([0, 1, 2], ds.predicates.isNegativeNumber);
// => false
ds.predicates.isArrayOf([], ds.predicates.isNumber);
// => false
ds.predicates.isArrayOf([], ds.predicates.isNumber, false);
// => true
ds.predicates.isArrayOf([0, 1, 2], ds.predicates.isPositiveNumber, 3);
// => true
ds.predicates.isArrayOf([0, 1, 2], ds.predicates.isPositiveNumber, 4);
// => false
-
* object The object to check.
-
Function:Boolean predicate A predicate which is evaluated for each array element.
-
Boolean|Number [length=true] Either a boolean indicating whether the array must be non-empty (
true
), may be empty (false
), or a number indicating the number of elements the array must have.
-
Boolean Returns
true
ifobject
is an array andpredicate
holds true for all its elements, and thelength
condition holds true, otherwise returnsfalse
.
-
Error Throws if
predicate
is not a function.
isDate(object)
Checks if object
is a date.
- * object The object to check.
-
Boolean Returns
true
ifobject
is a date, otherwise returnsfalse
.
isFunction(object, [length=true])
Checks if object
is a function.
-
* object The object to check.
-
Boolean|Number [length=true] Either a boolean indicating whether the function must expect arguments (
true
), may expect no arguments (false
), or a number indicating the number of arguments the function must expect.
-
Boolean Returns
true
ifobject
is a function and thelength
condition holds true, otherwise returnsfalse
.
isInteger(object)
Checks if object
is an integer number.
- * object The object to check.
-
Boolean Returns
true
ifobject
is an integer number, else returnsfalse
.
isNegativeInteger(object)
Checks if object
is a negative integer number.
- * object The object to check.
-
Boolean Returns
true
ifobject
is an integer number < 0, else returnsfalse
.
isNegativeNumber(object)
Checks if object
is a negative number.
- * object The object to check.
-
Boolean Returns
true
ifobject
is a number < 0, otherwise returnsfalse
.
isNumber(object)
Checks if object
is a number.
- * object The object to check.
-
Boolean Returns
true
ifobject
is a number, otherwise returnsfalse
.
isPositiveInteger(object, [withZero=true])
Checks if object
is a positive integer number.
-
* object The object to check.
-
Boolean [withZero=true] Indicates if zero is a valid positive number or not.
-
Boolean Returns
true
ifobject
is an integer number >= 0 or > 0, depending onwithZero
, otherwise returnsfalse
.
-
Error Throws if
withZero
is provided and is not a boolean.
isPositiveNumber(object, [withZero=true])
Checks if object
is a positive number.
-
* object The object to check.
-
Boolean [withZero=true] Indicates if zero is a valid positive number or not.
-
Boolean Returns
true
ifobject
is a number >= 0 or > 0, depending onwithZero
, otherwise returnsfalse
.
-
Error Throws if
withZero
is provided and is not a boolean.