UNPKG

@ace-util/core

Version:
117 lines 2.79 kB
/** * check if value is null * @param val value * @returns true/false */ export function isNull(val) { return val === null; } /** * check if value is undefined * @param val value * @returns true/false */ export function isUndefined(val) { return typeof val === 'undefined'; } /** * alias to isUndefined * @deprecated Use `isUndefined` instead. This alias may cause confusion due to inconsistent naming conventions. * @param val value * @returns true/false */ export var isUndef = isUndefined; /** * check if value is a array * @param val value * @returns true/false */ export function isArray(val) { return Array.isArray(val); } /** * check if value is an object * @param val value * @returns true/false */ export function isObject(val) { return val !== null && typeof val === 'object'; } var toString = function (x) { return Object.prototype.toString.call(x); }; /** * check if value is a plain object * @param val value * @returns true/false */ export function isPlainObject(val) { return toString(val) === '[object Object]'; } /** * check if value is a date * @param val value * @returns true/false */ export function isDate(val) { return toString(val) === '[object Date]'; } /** * check if value is a function * @param val value * @returns true/false */ export function isFunction(val) { return typeof val === 'function'; } /** * Inlined Object.is polyfill. * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is */ export function objectIs(x, y) { if (x === y) { return x !== 0 || 1 / x === 1 / y; } // eslint-disable-next-line return x !== x && y !== y; } /** * check if value is primitive * https://developer.mozilla.org/en-US/docs/Glossary/Primitive * @param val value * @returns true/false */ export function isPrimitive(val) { return (typeof val === 'string' || typeof val === 'number' || typeof val === 'symbol' || typeof val === 'boolean' || typeof val === 'bigint' || typeof val === 'undefined' || val === null); } /** * compare two values are fully equal * @param x value x * @param y value y * @returns true/false */ export function equals(x, y) { var f1 = x instanceof Object; var f2 = y instanceof Object; if (!f1 || !f2) { return x === y; } if (Object.keys(x).length !== Object.keys(y).length) { return false; } var newX = Object.keys(x); for (var p in newX) { p = newX[p]; var a = x[p] instanceof Object; var b = y[p] instanceof Object; if ((a && b && !equals(x[p], y[p])) || (!(a && b) && x[p] !== y[p])) { return false; } } return true; } //# sourceMappingURL=types.js.map