UNPKG

ts-guards

Version:
59 lines 1.89 kB
"use strict"; /** * Data and Structure types * See also: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures */ Object.defineProperty(exports, "__esModule", { value: true }); exports.isObject = exports.isNotNullOrUndefined = exports.isSymbol = exports.isBigInt = exports.isString = exports.isNumber = exports.isBoolean = exports.isUndefined = exports.isNull = void 0; // Structural Root Primitive function isNull(x) { return x === null; } exports.isNull = isNull; // Primitive Data Types function isUndefined(x) { return typeof x === 'undefined'; } exports.isUndefined = isUndefined; function isBoolean(x) { return typeof x === 'boolean'; } exports.isBoolean = isBoolean; function isNumber(x) { return typeof x === 'number'; } exports.isNumber = isNumber; function isString(x) { return typeof x === 'string'; } exports.isString = isString; function isBigInt(x) { return typeof x === 'bigint'; } exports.isBigInt = isBigInt; function isSymbol(x) { return typeof x === 'symbol'; } exports.isSymbol = isSymbol; // Convenience Primitive Type function isNotNullOrUndefined(x) { return !isNull(x) && !isUndefined(x); } exports.isNotNullOrUndefined = isNotNullOrUndefined; // Structural Types function isObject(x) { return typeof x === 'object' && x !== null; } exports.isObject = isObject; // TODO: is there a way to actually test for functions? // Also, we can assume that function is not a thing to test for since it should not be delivered as unsafe IO // export function isFunction(x: unknown): x is () => any { // return typeof x === 'function' && x !== null; // } // export function isFunction(x: unknown): x is function { // return typeof x === 'function'; // } // export function isFunctions<K extends Function>(x: unknown): x is K { // return typeof x === 'function'; // } //# sourceMappingURL=primitive-type.js.map