From a927821c9b98e9624a5d1a14bd73d790bfe6109d Mon Sep 17 00:00:00 2001 From: Chad Ostrowski Date: Sun, 6 Aug 2017 14:05:01 -0400 Subject: [PATCH] Country names: correctly uppercase names like 'EU' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Always perform the capitalization-correction for country names. If we did this naïvely, using the same regex as before, it would change things like "Falkland Islands" to "Falkland ISLANDS". The new regex checks on word boundary, `\b`, instead of space, `\s`, which means even single words like `Eu` are found. It then checks for exactly two letters, where the first is uppercase and the second lowercase. Here's exactly what it affects: * All "Regional Indicator Symbol Letters AC"-type names that don't have data in emojiLib * There are some flags in emojiLib for which it uses two-character abbreviations instead of full country names (see muan/emojilib#131). These countries are: CN, EU, FR, DE, IT, JP, RU, KR, ES, TR, UK, US This new regex corrects these from Cn, Eu, Fr, etc. --- scripts/build-data.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/build-data.js b/scripts/build-data.js index 016d379..bf60617 100644 --- a/scripts/build-data.js +++ b/scripts/build-data.js @@ -78,8 +78,9 @@ emojiData.forEach((datum) => { datum.name = inflection.titleize(datum.name || '') - if (datum.category == 'Flags' && !emojiLibMatch) { - datum.name = datum.name.replace(/\s(\w+)$/, (letters) => letters.toUpperCase()) + if (datum.category == 'Flags') { + // uppercase two-letter country codes + datum.name = datum.name.replace(/\b[A-Z]([a-z])$/, letters => letters.toUpperCase()) } if (!datum.name) {