讨论打包
This commit is contained in:
108
.output/server/node_modules/packrup/dist/index.mjs
generated
vendored
Normal file
108
.output/server/node_modules/packrup/dist/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,108 @@
|
||||
function asArray(input) {
|
||||
return Array.isArray(input) ? input : [input];
|
||||
}
|
||||
const InternalKeySymbol = "_$key";
|
||||
function packObject(input, options) {
|
||||
const keys = Object.keys(input);
|
||||
let [k, v] = keys;
|
||||
options = options || {};
|
||||
options.key = options.key || k;
|
||||
options.value = options.value || v;
|
||||
options.resolveKey = options.resolveKey || ((k2) => k2);
|
||||
const resolveKey = (index) => {
|
||||
const arr = asArray(options[index]);
|
||||
return arr.find((k2) => {
|
||||
if (typeof k2 === "string" && k2.includes(".")) {
|
||||
return k2;
|
||||
}
|
||||
return k2 && keys.includes(k2);
|
||||
});
|
||||
};
|
||||
const resolveValue = (k2, input2) => {
|
||||
if (k2.includes(".")) {
|
||||
const paths = k2.split(".");
|
||||
let val = input2;
|
||||
for (const path of paths)
|
||||
val = val[path];
|
||||
return val;
|
||||
}
|
||||
return input2[k2];
|
||||
};
|
||||
k = resolveKey("key") || k;
|
||||
v = resolveKey("value") || v;
|
||||
const dedupeKeyPrefix = input.key ? `${InternalKeySymbol}${input.key}-` : "";
|
||||
let keyValue = resolveValue(k, input);
|
||||
keyValue = options.resolveKey(keyValue);
|
||||
return {
|
||||
[`${dedupeKeyPrefix}${keyValue}`]: resolveValue(v, input)
|
||||
};
|
||||
}
|
||||
|
||||
function packArray(input, options) {
|
||||
const packed = {};
|
||||
for (const i of input) {
|
||||
const packedObj = packObject(i, options);
|
||||
const pKey = Object.keys(packedObj)[0];
|
||||
const isDedupeKey = pKey.startsWith(InternalKeySymbol);
|
||||
if (!isDedupeKey && packed[pKey]) {
|
||||
packed[pKey] = Array.isArray(packed[pKey]) ? packed[pKey] : [packed[pKey]];
|
||||
packed[pKey].push(Object.values(packedObj)[0]);
|
||||
} else {
|
||||
packed[isDedupeKey ? pKey.split("-").slice(1).join("-") || pKey : pKey] = packedObj[pKey];
|
||||
}
|
||||
}
|
||||
return packed;
|
||||
}
|
||||
|
||||
function packString(input) {
|
||||
const output = {};
|
||||
input.split(" ").forEach(
|
||||
(item) => {
|
||||
const val = item.replace(/"/g, "").split("=");
|
||||
output[val[0]] = val[1];
|
||||
}
|
||||
);
|
||||
return output;
|
||||
}
|
||||
|
||||
function unpackToArray(input, options) {
|
||||
const unpacked = [];
|
||||
const kFn = options.resolveKeyData || ((ctx) => ctx.key);
|
||||
const vFn = options.resolveValueData || ((ctx) => ctx.value);
|
||||
for (const [k, v] of Object.entries(input)) {
|
||||
unpacked.push(...(Array.isArray(v) ? v : [v]).map((i) => {
|
||||
const ctx = { key: k, value: i };
|
||||
const val = vFn(ctx);
|
||||
if (typeof val === "object")
|
||||
return unpackToArray(val, options);
|
||||
if (Array.isArray(val))
|
||||
return val;
|
||||
return {
|
||||
[typeof options.key === "function" ? options.key(ctx) : options.key]: kFn(ctx),
|
||||
[typeof options.value === "function" ? options.value(ctx) : options.value]: val
|
||||
};
|
||||
}).flat());
|
||||
}
|
||||
return unpacked;
|
||||
}
|
||||
|
||||
function unpackToString(value, options) {
|
||||
return Object.entries(value).map(([key, value2]) => {
|
||||
if (typeof value2 === "object")
|
||||
value2 = unpackToString(value2, options);
|
||||
if (options.resolve) {
|
||||
const resolved = options.resolve({ key, value: value2 });
|
||||
if (typeof resolved !== "undefined")
|
||||
return resolved;
|
||||
}
|
||||
if (typeof value2 === "number")
|
||||
value2 = value2.toString();
|
||||
if (typeof value2 === "string" && options.wrapValue) {
|
||||
value2 = value2.replace(new RegExp(options.wrapValue, "g"), `\\${options.wrapValue}`);
|
||||
value2 = `${options.wrapValue}${value2}${options.wrapValue}`;
|
||||
}
|
||||
return `${key}${options.keyValueSeparator || ""}${value2}`;
|
||||
}).join(options.entrySeparator || "");
|
||||
}
|
||||
|
||||
export { InternalKeySymbol, packArray, packObject, packString, unpackToArray, unpackToString };
|
||||
61
.output/server/node_modules/packrup/package.json
generated
vendored
Normal file
61
.output/server/node_modules/packrup/package.json
generated
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
{
|
||||
"name": "packrup",
|
||||
"type": "module",
|
||||
"version": "0.1.2",
|
||||
"packageManager": "pnpm@8.15.4",
|
||||
"description": "Node Schema.org for Simple and Automated Google Rich Results",
|
||||
"author": "Harlan Wilton <harlan@harlanzw.com>",
|
||||
"license": "MIT",
|
||||
"funding": "https://github.com/sponsors/harlan-zw",
|
||||
"homepage": "https://github.com/harlan-zw/packrup#readme",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/harlan-zw/packrup.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/harlan-zw/packrup/issues"
|
||||
},
|
||||
"keywords": [
|
||||
"pack object",
|
||||
"pack string",
|
||||
"pack array"
|
||||
],
|
||||
"sideEffects": false,
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./dist/index.mjs",
|
||||
"require": "./dist/index.cjs"
|
||||
}
|
||||
},
|
||||
"main": "dist/index.cjs",
|
||||
"module": "dist/index.mjs",
|
||||
"types": "dist/index.d.ts",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"devDependencies": {
|
||||
"@antfu/eslint-config": "^2.8.0",
|
||||
"@types/fs-extra": "^11.0.4",
|
||||
"@vitest/ui": "^1.3.1",
|
||||
"bumpp": "^9.4.0",
|
||||
"eslint": "^8.57.0",
|
||||
"fs-extra": "^11.2.0",
|
||||
"jsdom": "^24.0.0",
|
||||
"typescript": "^5.4.2",
|
||||
"unbuild": "^2.0.0",
|
||||
"utility-types": "^3.11.0",
|
||||
"vitest": "^1.3.1"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "unbuild",
|
||||
"stub": "unbuild --stub",
|
||||
"test": "vitest",
|
||||
"export:sizes": "npx export-size . -r",
|
||||
"release": "pnpm build && bumpp && pnpm -r publish --no-git-checks",
|
||||
"lint": "eslint . --fix"
|
||||
},
|
||||
"__npminstall_done": true,
|
||||
"_from": "packrup@0.1.2",
|
||||
"_resolved": "https://registry.npmmirror.com/packrup/-/packrup-0.1.2.tgz"
|
||||
}
|
||||
Reference in New Issue
Block a user