@uirouter/core
Version:
UI-Router Core: Framework agnostic, State-based routing for JavaScript Single Page Apps
48 lines • 2.27 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.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;
/**
* Predicates
*
* These predicates return true/false based on the input.
* Although these functions are exported, they are subject to change without notice.
*
* @packageDocumentation
*/
var hof_1 = require("./hof");
var toStr = Object.prototype.toString;
var tis = function (t) { return function (x) { return typeof x === t; }; };
exports.isUndefined = tis('undefined');
exports.isDefined = (0, hof_1.not)(exports.isUndefined);
var isNull = function (o) { return o === null; };
exports.isNull = isNull;
exports.isNullOrUndefined = (0, hof_1.or)(exports.isNull, exports.isUndefined);
exports.isFunction = tis('function');
exports.isNumber = tis('number');
exports.isString = tis('string');
var isObject = function (x) { return x !== null && typeof x === 'object'; };
exports.isObject = isObject;
exports.isArray = Array.isArray;
exports.isDate = (function (x) { return toStr.call(x) === '[object Date]'; });
exports.isRegExp = (function (x) { return toStr.call(x) === '[object RegExp]'; });
/**
* Predicate which checks if a value is injectable
*
* A value is "injectable" if it is a function, or if it is an ng1 array-notation-style array
* where all the elements in the array are Strings, except the last one, which is a Function
*/
function isInjectable(val) {
if ((0, exports.isArray)(val) && val.length) {
var head = val.slice(0, -1), tail = val.slice(-1);
return !(head.filter((0, hof_1.not)(exports.isString)).length || tail.filter((0, hof_1.not)(exports.isFunction)).length);
}
return (0, exports.isFunction)(val);
}
exports.isInjectable = isInjectable;
/**
* Predicate which checks if a value looks like a Promise
*
* It is probably a Promise if it's an object, and it has a `then` property which is a Function
*/
exports.isPromise = (0, hof_1.and)(exports.isObject, (0, hof_1.pipe)((0, hof_1.prop)('then'), exports.isFunction));
//# sourceMappingURL=predicates.js.map