@dark-engine/core
Version:
The lightweight and powerful UI rendering engine without dependencies and written in TypeScript (Browser, Node.js, Android, iOS, Windows, Linux, macOS)
105 lines (104 loc) • 3.82 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
exports.stringify =
exports.createError =
exports.mapRecord =
exports.createIndexKey =
exports.nextTick =
exports.detectAreDepsDifferent =
exports.flatten =
exports.illegal =
exports.throwThis =
exports.formatErrorMsg =
exports.logError =
exports.falseFn =
exports.trueFn =
exports.dummyFn =
exports.getTime =
exports.hasKeys =
exports.keys =
exports.detectIsEqual =
exports.detectIsPromise =
exports.detectIsFalsy =
exports.detectIsEmpty =
exports.detectIsNull =
exports.detectIsArray =
exports.detectIsBoolean =
exports.detectIsObject =
exports.detectIsTextBased =
exports.detectIsString =
exports.detectIsNumber =
exports.detectIsUndefined =
exports.detectIsFunction =
void 0;
const constants_1 = require('../constants');
const detectIsFunction = o => typeof o === 'function';
exports.detectIsFunction = detectIsFunction;
const detectIsUndefined = o => typeof o === 'undefined';
exports.detectIsUndefined = detectIsUndefined;
const detectIsNumber = o => typeof o === 'number';
exports.detectIsNumber = detectIsNumber;
const detectIsString = o => typeof o === 'string';
exports.detectIsString = detectIsString;
const detectIsTextBased = o => typeof o === 'string' || typeof o === 'number';
exports.detectIsTextBased = detectIsTextBased;
const detectIsObject = o => typeof o === 'object';
exports.detectIsObject = detectIsObject;
const detectIsBoolean = o => typeof o === 'boolean';
exports.detectIsBoolean = detectIsBoolean;
const detectIsArray = Array.isArray;
exports.detectIsArray = detectIsArray;
const detectIsNull = o => o === null;
exports.detectIsNull = detectIsNull;
const detectIsEmpty = o => o === null || typeof o === 'undefined';
exports.detectIsEmpty = detectIsEmpty;
const detectIsFalsy = o => o === null || typeof o === 'undefined' || o === false;
exports.detectIsFalsy = detectIsFalsy;
const detectIsPromise = o => o instanceof Promise;
exports.detectIsPromise = detectIsPromise;
const detectIsEqual = Object.is;
exports.detectIsEqual = detectIsEqual;
const keys = Object.keys;
exports.keys = keys;
const hasKeys = o => keys(o).length > 0;
exports.hasKeys = hasKeys;
const getTime = () => Date.now();
exports.getTime = getTime;
const dummyFn = () => {};
exports.dummyFn = dummyFn;
const trueFn = () => true;
exports.trueFn = trueFn;
const falseFn = () => false;
exports.falseFn = falseFn;
const logError = (...args) => !detectIsUndefined(console) && console.error(...args);
exports.logError = logError;
const formatErrorMsg = (x, prefix = constants_1.LIB) => `[${prefix}]: ${x}`;
exports.formatErrorMsg = formatErrorMsg;
function throwThis(x) {
throw x;
}
exports.throwThis = throwThis;
const illegal = (x, prefix = constants_1.LIB) => throwThis(new Error(formatErrorMsg(x, prefix)));
exports.illegal = illegal;
const flatten = x => x.flat(Infinity);
exports.flatten = flatten;
function detectAreDepsDifferent(prevDeps, nextDeps) {
if (prevDeps === nextDeps || (prevDeps.length === 0 && nextDeps.length === 0)) return false;
const max = Math.max(prevDeps.length, nextDeps.length);
for (let i = 0; i < max; i++) {
if (!detectIsEqual(prevDeps[i], nextDeps[i])) return true;
}
return false;
}
exports.detectAreDepsDifferent = detectAreDepsDifferent;
const nextTick = callback => Promise.resolve().then(callback);
exports.nextTick = nextTick;
const createIndexKey = idx => `${constants_1.INDEX_KEY}:${idx}`;
exports.createIndexKey = createIndexKey;
const mapRecord = record => keys(record).map(x => record[x]);
exports.mapRecord = mapRecord;
const createError = x => (x instanceof Error ? x : new Error(String(x)));
exports.createError = createError;
const stringify = JSON.stringify;
exports.stringify = stringify;
//# sourceMappingURL=utils.js.map