✨ feat(substore): 支持规范化带连字符的节点区域特征名称
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user