UNPKG

datum-merge

Version:

Simplified diff and merging for deeply nested objects

88 lines (87 loc) 2.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.typeOfValue = exports.emptyValue = exports.isArrayOfSame = exports.isArrayOf = exports.emptyArray = exports.isArrayOfAny = exports.emptyObject = exports.isObject = exports.integerString = exports.emptyString = exports.isNullish = exports.isPrimitive = exports.isBoolean = exports.isNumber = exports.isString = void 0; function isString(value) { return typeof value === 'string'; } exports.isString = isString; function isNumber(value) { return typeof value === 'number'; } exports.isNumber = isNumber; function isBoolean(value) { return typeof value === 'boolean'; } exports.isBoolean = isBoolean; function isPrimitive(value) { return ['string', 'number', 'boolean'].includes(typeof value); } exports.isPrimitive = isPrimitive; function isNullish(value) { return value === undefined || value === null; } exports.isNullish = isNullish; function emptyString(str) { return (str == null) || (str === '') || (/^\s*$/.test(str)); } exports.emptyString = emptyString; function integerString(str) { return ((str != null) && (str !== '') && Number.isSafeInteger(Number(str.toString()))); } exports.integerString = integerString; function isObject(value) { return typeof value === 'object' && !Array.isArray(value) && value !== null; } exports.isObject = isObject; function emptyObject(obj) { return (obj === undefined) || (obj === null) || (!Object.keys(obj).length); } exports.emptyObject = emptyObject; function isArrayOfAny(value) { return Array.isArray(value); } exports.isArrayOfAny = isArrayOfAny; function emptyArray(arr) { return Array.isArray(arr) && !(arr === null || arr === void 0 ? void 0 : arr.length); } exports.emptyArray = emptyArray; function isArrayOf(arr, typeCheck) { return Array.isArray(arr) && arr.length > 0 && arr.every(typeCheck); } exports.isArrayOf = isArrayOf; function isArrayOfSame(arr) { return Array.isArray(arr) && new Set(arr.map((e) => typeof e)).size === 1 ? typeof arr[0] : false; } exports.isArrayOfSame = isArrayOfSame; function emptyValue(value) { return (value === undefined) || (value === null) || (Array.isArray(value) && !value.length) || (typeof value === "object" && !Object.keys(value).length); } exports.emptyValue = emptyValue; function typeOfValue(value) { const type = typeof value; if (type !== 'object') { return type; } else if (Array.isArray(value)) { return 'array'; } else { return 'object'; } } exports.typeOfValue = typeOfValue;