From 24e2268e96f6897bf8add49d697c24662b7b7a70 Mon Sep 17 00:00:00 2001 From: freearhey Date: Sat, 6 Mar 2021 21:14:34 +0300 Subject: [PATCH] Add name2id function --- scripts/utils.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/scripts/utils.js b/scripts/utils.js index c0c86b3446..4d4e053f40 100644 --- a/scripts/utils.js +++ b/scripts/utils.js @@ -6,6 +6,7 @@ const urlParser = require('url') const escapeStringRegexp = require('escape-string-regexp') const markdownInclude = require('markdown-include') const iso6393 = require('iso-639-3') +const transliteration = require('transliteration') const regions = require('./regions') const categories = require('./categories') const intlDisplayNames = new Intl.DisplayNames(['en'], { @@ -15,6 +16,13 @@ const intlDisplayNames = new Intl.DisplayNames(['en'], { const utils = {} +utils.name2id = function (name) { + return transliteration + .transliterate(name) + .replace(/\+/gi, 'Plus') + .replace(/[^a-z\d]+/gi, '') +} + utils.code2flag = function (code) { code = code.toUpperCase() switch (code) {