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

61 lines
1.9 KiB
Plaintext

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Clone = Clone;
// ------------------------------------------------------------------
// ValueGuard
// ------------------------------------------------------------------
const index_1 = require("../guard/index");
// ------------------------------------------------------------------
// Clonable
// ------------------------------------------------------------------
function FromObject(value) {
const Acc = {};
for (const key of Object.getOwnPropertyNames(value)) {
Acc[key] = Clone(value[key]);
}
for (const key of Object.getOwnPropertySymbols(value)) {
Acc[key] = Clone(value[key]);
}
return Acc;
}
function FromArray(value) {
return value.map((element) => Clone(element));
}
function FromTypedArray(value) {
return value.slice();
}
function FromMap(value) {
return new Map(Clone([...value.entries()]));
}
function FromSet(value) {
return new Set(Clone([...value.entries()]));
}
function FromDate(value) {
return new Date(value.toISOString());
}
function FromValue(value) {
return value;
}
// ------------------------------------------------------------------
// Clone
// ------------------------------------------------------------------
/** Returns a clone of the given value */
function Clone(value) {
if ((0, index_1.IsArray)(value))
return FromArray(value);
if ((0, index_1.IsDate)(value))
return FromDate(value);
if ((0, index_1.IsTypedArray)(value))
return FromTypedArray(value);
if ((0, index_1.IsMap)(value))
return FromMap(value);
if ((0, index_1.IsSet)(value))
return FromSet(value);
if ((0, index_1.IsObject)(value))
return FromObject(value);
if ((0, index_1.IsValueType)(value))
return FromValue(value);
throw new Error('ValueClone: Unable to clone value');
}