Clean seller metadata display names
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 40s

This commit is contained in:
Cauê Faleiros
2026-06-24 13:03:55 -03:00
parent b129307bae
commit ca9615a1fd
5 changed files with 57 additions and 13 deletions

26
src/displayFormatters.ts Normal file
View File

@@ -0,0 +1,26 @@
const SMALL_WORDS = new Set(['da', 'de', 'do', 'das', 'dos', 'e']);
export const removeTrailingSellerId = (value: string) => {
return value.replace(/\s*#\d+\s*$/, '').trim();
};
export const formatDisplayName = (value: string) => {
const normalized = String(value || '').replace(/\s+/g, ' ').trim();
if (!normalized) return '';
const withoutSellerId = removeTrailingSellerId(normalized);
const withoutNumericPrefix = withoutSellerId.replace(/^\[\d+\]\s*/, '').trim();
const isUppercaseName = /[A-ZÁÀÂÃÉÈÊÍÏÓÔÕÖÚÇÑ]/.test(withoutNumericPrefix) &&
withoutNumericPrefix === withoutNumericPrefix.toUpperCase();
if (!isUppercaseName) return withoutNumericPrefix;
return withoutNumericPrefix
.toLocaleLowerCase('pt-BR')
.split(' ')
.map((word, index) => {
if (index > 0 && SMALL_WORDS.has(word)) return word;
return word.charAt(0).toLocaleUpperCase('pt-BR') + word.slice(1);
})
.join(' ');
};