astro-ghostcms/.pnpm-store/v3/files/7c/0384c7b3562e427b597c3caa74a...

32 lines
881 B
Plaintext

import { trimSlashes } from "../path.js";
import { validateGetStaticPathsParameter } from "./validation.js";
function getParams(array) {
const fn = (match) => {
const params = {};
array.forEach((key, i) => {
if (key.startsWith("...")) {
params[key.slice(3)] = match[i + 1] ? match[i + 1] : void 0;
} else {
params[key] = match[i + 1];
}
});
return params;
};
return fn;
}
function stringifyParams(params, route) {
const validatedParams = Object.entries(params).reduce((acc, next) => {
validateGetStaticPathsParameter(next, route.component);
const [key, value] = next;
if (value !== void 0) {
acc[key] = typeof value === "string" ? trimSlashes(value) : value.toString();
}
return acc;
}, {});
return JSON.stringify(route.generate(validatedParams));
}
export {
getParams,
stringifyParams
};