alwz
Version:
Extendable library for typecasting
131 lines • 3.94 kB
JavaScript
import * as numbers from './constants/numbers.js';
export const integers = Object.fromEntries(Object.entries(numbers.integers)
.map(([name, [min, max]]) => {
return [
name,
(i) => typeof i === 'number' && min <= i && i <= max && Number.isInteger(i),
];
}));
export const floats = Object.fromEntries(Object.entries(numbers.floats)
.map(([name, [min, max]]) => {
return [
name,
(i) => typeof i === 'number' && min <= i && i <= max,
];
}));
/** @module is
* @description guard functions (pattern matching check)
*/
export default Object.assign(Object.assign(Object.assign({
/** @function undefined
* @memberof is */
undefined: (i) => i === undefined,
/** @function null
* @memberof is */
null: (i) => i === null,
/** @function void
* @description undefined or null
* @example
* is.void(null) // true
* is.void(0) // false
* @memberof is */
void: (i) => i === undefined || i === null,
/** @function value
* @description any value except undefined or null
* @example
* is.value(null) // false
* is.value(0) // true
* @memberof is */
value: (i) => i !== undefined && i !== null,
/** @function boolean
* @example
* is.boolean(1) // false
* is.boolean(true) // true
* @memberof is */
boolean: (i) => typeof i === 'boolean',
/**
* @function number
* @example
* is.number(NaN) // true
* is.number(Infinity) // true
* is.number(1) // true
* is.number('1') // false
* @memberof is */
number: (i) => typeof i === 'number' }, integers), floats), {
/** @name integers
* @description byte, short, int, long
* @example
* is.int(NaN) // false
* is.long(Infinity) // false
* is.uint(-1) // false
* is.uint(1) // true
* is.uint(1.5) // false
* @memberof is.number */
/** @name floats
* @description double
* @example
* is.double(NaN) // false
* is.double(Infinity) // false
* is.double(1.5) // true
* @memberof is.number */
/** @function bigint
* @memberof is */
bigint: (i) => typeof i === 'bigint',
/** @function string
* @memberof is */
string: (i) => typeof i === 'string',
/** @function symbol
* @memberof is */
symbol: (i) => typeof i === 'symbol',
/** @function function
* @memberof is */
function: (i) => typeof i === 'function',
/** @function object
* @description any object (null excluded)
* @example
* is.object(null) // false
* is.object({}) // true
* @memberof is */
object: (i) => typeof i === 'object' && i !== null,
/** @function Error
* @memberof is */
Error: (i) => i instanceof Error,
/** @function Array
* @example
* is.Array({}) // false
* is.Array([]) // true
* @memberof is */
Array: Array.isArray,
/** @function Date
* @memberof is */
Date: (i) => i instanceof Date,
/** @function RegExp
* @memberof is */
RegExp: (i) => i instanceof RegExp,
/** @function Promise
* @memberof is */
Promise: (i) => i instanceof Promise,
/** @function Set
* @memberof is */
Set: (i) => i instanceof Set,
/** @function WeakSet
* @memberof is */
WeakSet: (i) => i instanceof WeakSet,
/** @function Map
* @memberof is */
Map: (i) => i instanceof Map,
/** @function WeakMap
* @memberof is */
WeakMap: (i) => i instanceof WeakMap,
/** @function Iterable
* @description can be iterated
* @example
* is.Iterable(new Map()); // true
* is.Iterable([]); // true
* is.Iterable({}); // false
* @memberof is */
Iterable: (i) => typeof i === 'object'
&& i !== null
&& Symbol.iterator in i
&& typeof i[Symbol.iterator] === 'function' });
//# sourceMappingURL=is.js.map