appium-adb
Version:
Android Debug Bridge interface
60 lines • 2.15 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.defaultsDeep = exports.pick = exports.zip = exports.intersectionWith = exports.defaults = exports.cloneDeep = void 0;
const support_1 = require("@appium/support");
const cloneDeep = (value) => {
if (typeof globalThis.structuredClone === 'function') {
return globalThis.structuredClone(value);
}
return JSON.parse(JSON.stringify(value));
};
exports.cloneDeep = cloneDeep;
const defaults = (target, ...sources) => {
for (const source of sources) {
if (!source) {
continue;
}
for (const [key, value] of Object.entries(source)) {
if (target[key] === undefined) {
target[key] = value;
}
}
}
return target;
};
exports.defaults = defaults;
const _defaultsDeep = (target, ...sources) => {
for (const source of sources) {
if (!source) {
continue;
}
for (const [key, value] of Object.entries(source)) {
const current = target[key];
if (current === undefined) {
target[key] = support_1.util.isPlainObject(value) || Array.isArray(value) ? (0, exports.cloneDeep)(value) : value;
continue;
}
if (support_1.util.isPlainObject(current) && support_1.util.isPlainObject(value)) {
_defaultsDeep(current, value);
}
}
}
return target;
};
const intersectionWith = (first, second, comparator) => first.filter((item) => second.some((other) => comparator(item, other)));
exports.intersectionWith = intersectionWith;
const zip = (arrA, arrB) => {
const length = Math.max(arrA.length, arrB.length);
return Array.from({ length }, (_, idx) => [arrA[idx], arrB[idx]]);
};
exports.zip = zip;
const pick = (obj, keysArg) => keysArg.reduce((acc, key) => {
if (key in obj) {
acc[key] = obj[key];
}
return acc;
}, {});
exports.pick = pick;
const defaultsDeep = (target, ...sources) => _defaultsDeep(target, ...sources);
exports.defaultsDeep = defaultsDeep;
//# sourceMappingURL=core.js.map