feat(substore): 支持规范化带连字符的节点区域特征名称

This commit is contained in:
Orion
2026-06-03 14:51:53 +08:00
parent 6c1e055281
commit ca3413a1ee
3 changed files with 44 additions and 1 deletions
+39
View File
@@ -191,6 +191,44 @@
.trim();
};
const 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 stripLineDescriptors = (name, descriptorKeywords) => {
const descriptorPattern = descriptorKeywords.map(escapeRegex).join('|');
const descriptorOnlyRegex = new RegExp(`^(?:${descriptorPattern})+$`, 'i');
@@ -223,6 +261,7 @@
flagToRegionCode,
joinAlias,
moveMultiplierToEnd,
normalizeHyphenatedRegionFeatures,
normalizeLeadingFlagSpacing,
normalizeMultiplierText,
normalizeRegionSequence,