UNPKG

@aplus-frontend/utils

Version:

Utils for Aplus frontend team.

49 lines (48 loc) 1.45 kB
"use strict"; Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); const utils = require("@fruits-chain/utils"); const lodashEs = require("lodash-es"); function upperFirst(str) { return str.charAt(0).toUpperCase() + str.slice(1); } function wait(ms) { let timerId; return new Promise((resolve) => { timerId = setTimeout(() => { resolve(timerId); }, ms); }); } function deepMerge(source, target, mergeArrays = "replace") { if (!target) { return source; } if (!source) { return target; } return lodashEs.mergeWith({}, source, target, (sourceValue, targetValue) => { if (utils.isArray(targetValue) && utils.isArray(sourceValue)) { switch (mergeArrays) { case "union": return lodashEs.unionWith(sourceValue, targetValue, lodashEs.isEqual); case "intersection": return lodashEs.intersectionWith(sourceValue, targetValue, lodashEs.isEqual); case "concat": return sourceValue.concat(targetValue); case "replace": return targetValue; default: throw new Error( `Unknown merge array strategy: ${mergeArrays}` ); } } if (utils.isObject(targetValue) && utils.isObject(sourceValue)) { return deepMerge(sourceValue, targetValue, mergeArrays); } return void 0; }); } exports.deepMerge = deepMerge; exports.upperFirst = upperFirst; exports.wait = wait;