UNPKG

2.18 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.isPromise = exports.isInjectable = exports.isRegExp = exports.isDate = exports.isArray = exports.isObject = exports.isString = exports.isNumber = exports.isFunction = exports.isNullOrUndefined = exports.isNull = exports.isDefined = exports.isUndefined = void 0;
4/**
5 * Predicates
6 *
7 * These predicates return true/false based on the input.
8 * Although these functions are exported, they are subject to change without notice.
9 *
10 * @packageDocumentation
11 */
12var hof_1 = require("./hof");
13var toStr = Object.prototype.toString;
14var tis = function (t) { return function (x) { return typeof x === t; }; };
15exports.isUndefined = tis('undefined');
16exports.isDefined = hof_1.not(exports.isUndefined);
17exports.isNull = function (o) { return o === null; };
18exports.isNullOrUndefined = hof_1.or(exports.isNull, exports.isUndefined);
19exports.isFunction = tis('function');
20exports.isNumber = tis('number');
21exports.isString = tis('string');
22exports.isObject = function (x) { return x !== null && typeof x === 'object'; };
23exports.isArray = Array.isArray;
24exports.isDate = (function (x) { return toStr.call(x) === '[object Date]'; });
25exports.isRegExp = (function (x) { return toStr.call(x) === '[object RegExp]'; });
26/**
27 * Predicate which checks if a value is injectable
28 *
29 * A value is "injectable" if it is a function, or if it is an ng1 array-notation-style array
30 * where all the elements in the array are Strings, except the last one, which is a Function
31 */
32function isInjectable(val) {
33 if (exports.isArray(val) && val.length) {
34 var head = val.slice(0, -1), tail = val.slice(-1);
35 return !(head.filter(hof_1.not(exports.isString)).length || tail.filter(hof_1.not(exports.isFunction)).length);
36 }
37 return exports.isFunction(val);
38}
39exports.isInjectable = isInjectable;
40/**
41 * Predicate which checks if a value looks like a Promise
42 *
43 * It is probably a Promise if it's an object, and it has a `then` property which is a Function
44 */
45exports.isPromise = hof_1.and(exports.isObject, hof_1.pipe(hof_1.prop('then'), exports.isFunction));
46//# sourceMappingURL=predicates.js.map
\No newline at end of file