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

31 lines
915 B
Plaintext

const PATTERN_REGEX = /%(-)?(\d+)?(?:\.(\d+))?([a-zA-Z%])(?:\{([^}]+)\})?/g;
function compilePattern(pattern, createConverter, literalConverter) {
const converters = [];
let lastIndex = 0;
let match;
while ((match = PATTERN_REGEX.exec(pattern)) !== null) {
const [full, align, minWidth, precision, specifier, format] = match;
if (match.index > lastIndex) {
converters.push(literalConverter(pattern.substring(lastIndex, match.index)));
}
const converter = createConverter(
specifier,
align === "-",
parseInt(minWidth || "0", 10),
parseInt(precision || "0", 10),
format
);
if (converter) {
converters.push(converter);
}
lastIndex = match.index + full.length;
}
if (lastIndex < pattern.length) {
converters.push(literalConverter(pattern.substring(lastIndex)));
}
return converters;
}
export {
compilePattern as default
};