UNPKG

@uirouter/core

Version:

UI-Router Core: Framework agnostic, State-based routing for JavaScript Single Page Apps

46 lines 2.18 kB
"use strict"; 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 = hof_1.not(exports.isUndefined); exports.isNull = function (o) { return o === null; }; exports.isNullOrUndefined = hof_1.or(exports.isNull, exports.isUndefined); exports.isFunction = tis('function'); exports.isNumber = tis('number'); exports.isString = tis('string'); exports.isObject = function (x) { return x !== null && typeof x === 'object'; }; 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 (exports.isArray(val) && val.length) { var head = val.slice(0, -1), tail = val.slice(-1); return !(head.filter(hof_1.not(exports.isString)).length || tail.filter(hof_1.not(exports.isFunction)).length); } return 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 = hof_1.and(exports.isObject, hof_1.pipe(hof_1.prop('then'), exports.isFunction)); //# sourceMappingURL=predicates.js.map