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

30 lines
922 B
Plaintext

"use strict";
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;
}
module.exports = compilePattern;