Build NapCat Artifacts / Windows Loader Test (push) Canceled after 0s
Build NapCat Artifacts / Type Check & Test (push) Canceled after 0s
Build NapCat Artifacts / Build NapCat.Framework (push) Canceled after 0s
Build NapCat Artifacts / Build NapCat.Shell (push) Canceled after 0s
30 lines
922 B
Plaintext
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;
|