♻️ refactor(core): 优化 substore 节点重命名与规范化逻辑
This commit is contained in:
+1
-38
@@ -26,43 +26,7 @@ async function loadRenameUtils() {
|
||||
|
||||
async function operator(proxies) {
|
||||
const utils = await loadRenameUtils();
|
||||
const normalizeHyphenatedRegionFeatures = utils.normalizeHyphenatedRegionFeatures || (name => {
|
||||
const hyphenatedMatch = String(name).match(/^([A-Z]{2})(?:\s+([A-Z]{3}))?-(.+)$/);
|
||||
if (!hyphenatedMatch) return name;
|
||||
|
||||
const countryCode = hyphenatedMatch[1];
|
||||
let regionCode = hyphenatedMatch[2]
|
||||
? `${countryCode} ${hyphenatedMatch[2]}`
|
||||
: countryCode;
|
||||
const tokens = hyphenatedMatch[3].split('-').map(token => token.trim()).filter(Boolean);
|
||||
|
||||
if (
|
||||
!hyphenatedMatch[2] &&
|
||||
tokens.length >= 2 &&
|
||||
/^[A-Z]{3}$/.test(tokens[0]) &&
|
||||
/^\d{1,2}$/.test(tokens[1])
|
||||
) {
|
||||
regionCode = `${countryCode} ${tokens.shift()}`;
|
||||
}
|
||||
|
||||
const sequenceIndex = tokens.findIndex(token => /^\d{1,2}$/.test(token));
|
||||
if (sequenceIndex === -1) return name;
|
||||
|
||||
const sequenceNumber = tokens[sequenceIndex].padStart(2, '0');
|
||||
const ingressTokens = tokens
|
||||
.slice(0, sequenceIndex)
|
||||
.map(token => token.toUpperCase());
|
||||
const egressTokens = tokens.slice(sequenceIndex + 1);
|
||||
const featureText = ingressTokens.length && egressTokens.length
|
||||
? `${ingressTokens.join('-')}-${egressTokens.join('-')}`
|
||||
: [...ingressTokens, ...egressTokens].join('-');
|
||||
|
||||
return [regionCode, sequenceNumber, featureText]
|
||||
.filter(Boolean)
|
||||
.join(' ')
|
||||
.replace(/\s{2,}/g, ' ')
|
||||
.trim();
|
||||
});
|
||||
const normalizeHyphenatedRegionFeatures = utils.normalizeHyphenatedRegionFeatures || (name => name);
|
||||
const globalCount = Object.create(null);
|
||||
const currentCount = Object.create(null);
|
||||
const baseNames = new Array(proxies.length);
|
||||
@@ -792,7 +756,6 @@ async function operator(proxies) {
|
||||
|
||||
core = core
|
||||
.replace(/^([A-Z]{2})\s*(实验性|标准|高级)\s+IEPL\s+专线\s*\d+(.*)$/i, '$1 $2$3')
|
||||
.replace(/搬瓦工荷兰/g, '搬瓦工')
|
||||
.replace(/\s{2,}/g, ' ')
|
||||
.trim();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user