Files
NapCatQQ/.pnpm-store/v3/files/f2/50f425b34fb6c8cd78955a93729d7a960a1b9cd6e13b88fb47e7f40ad53e2773382430961ec8a47a5f4a1bc7dc8dc2a8c6caf783c451a04d6047d5953a5875
T
TanTan e311ca3275
Build NapCat Artifacts / Type Check & Test (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

86 lines
2.8 KiB
Plaintext

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const cloneDeep = require("lodash.clonedeep");
const isEqual = require("lodash.isequal");
var AttributeMap;
(function (AttributeMap) {
function compose(a = {}, b = {}, keepNull = false) {
if (typeof a !== 'object') {
a = {};
}
if (typeof b !== 'object') {
b = {};
}
let attributes = cloneDeep(b);
if (!keepNull) {
attributes = Object.keys(attributes).reduce((copy, key) => {
if (attributes[key] != null) {
copy[key] = attributes[key];
}
return copy;
}, {});
}
for (const key in a) {
if (a[key] !== undefined && b[key] === undefined) {
attributes[key] = a[key];
}
}
return Object.keys(attributes).length > 0 ? attributes : undefined;
}
AttributeMap.compose = compose;
function diff(a = {}, b = {}) {
if (typeof a !== 'object') {
a = {};
}
if (typeof b !== 'object') {
b = {};
}
const attributes = Object.keys(a)
.concat(Object.keys(b))
.reduce((attrs, key) => {
if (!isEqual(a[key], b[key])) {
attrs[key] = b[key] === undefined ? null : b[key];
}
return attrs;
}, {});
return Object.keys(attributes).length > 0 ? attributes : undefined;
}
AttributeMap.diff = diff;
function invert(attr = {}, base = {}) {
attr = attr || {};
const baseInverted = Object.keys(base).reduce((memo, key) => {
if (base[key] !== attr[key] && attr[key] !== undefined) {
memo[key] = base[key];
}
return memo;
}, {});
return Object.keys(attr).reduce((memo, key) => {
if (attr[key] !== base[key] && base[key] === undefined) {
memo[key] = null;
}
return memo;
}, baseInverted);
}
AttributeMap.invert = invert;
function transform(a, b, priority = false) {
if (typeof a !== 'object') {
return b;
}
if (typeof b !== 'object') {
return undefined;
}
if (!priority) {
return b; // b simply overwrites us without priority
}
const attributes = Object.keys(b).reduce((attrs, key) => {
if (a[key] === undefined) {
attrs[key] = b[key]; // null is a valid value
}
return attrs;
}, {});
return Object.keys(attributes).length > 0 ? attributes : undefined;
}
AttributeMap.transform = transform;
})(AttributeMap || (AttributeMap = {}));
exports.default = AttributeMap;
//# sourceMappingURL=AttributeMap.js.map