Add name2id function

This commit is contained in:
freearhey 2021-03-06 21:14:34 +03:00
parent ae11c6b876
commit 24e2268e96

View File

@ -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) {