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

88 lines
2.2 KiB
Plaintext

// src/common/assertion.ts
var __DEV__ = process.env.NODE_ENV !== "production";
var __TEST__ = process.env.NODE_ENV === "test";
function isArray(value) {
return Array.isArray(value);
}
function isObject(value) {
const type = typeof value;
return value != null && (type === "object" || type === "function") && !isArray(value);
}
// src/common/object.ts
var renameProp = (oldProp, newProp, { [oldProp]: old, ...others }) => ({
[newProp]: old,
...others
});
var copyObject = (obj) => {
if (!isObject(obj)) return obj;
if (obj instanceof Array) return [...obj];
return { ...obj };
};
var omitObject = (obj, omitKeys) => {
if (!isObject(obj)) return obj;
if (obj instanceof Array) return [...obj];
const newObj = { ...obj };
omitKeys.forEach((key) => newObj[key] && delete newObj[key]);
return newObj;
};
var cleanObject = (obj) => {
if (!isObject(obj)) return obj;
if (obj instanceof Array) return [...obj];
const newObj = { ...obj };
Object.keys(newObj).forEach((key) => {
if (newObj[key] === void 0 || newObj[key] === null) {
delete newObj[key];
}
});
return newObj;
};
var cleanObjectKeys = (obj, keys = []) => {
if (!isObject(obj)) return obj;
if (obj instanceof Array) return [...obj];
const newObj = { ...obj };
keys.forEach((key) => {
if (newObj[key]) {
delete newObj[key];
}
});
return newObj;
};
var getKeyValue = (obj, key) => {
if (!isObject(obj)) return obj;
if (obj instanceof Array) return [...obj];
return obj[key];
};
var getProp = (obj, path, fallback, index) => {
const key = typeof path === "string" ? path.split(".") : [path];
for (index = 0; index < key.length; index += 1) {
if (!obj) break;
obj = obj[key[index]];
}
return obj === void 0 ? fallback : obj;
};
var arrayToObject = (arr) => {
if (!arr.length || !Array.isArray(arr)) return {};
return arr.reduce((acc, item) => {
return { ...acc, ...item };
}, {});
};
function compact(object) {
const clone = Object.assign({}, object);
for (let key in clone) {
if (clone[key] === void 0) delete clone[key];
}
return clone;
}
export {
arrayToObject,
cleanObject,
cleanObjectKeys,
compact,
copyObject,
getKeyValue,
getProp,
omitObject,
renameProp
};