Update utils.js

pull/2087/head
freearhey 4 years ago
parent 6a33900a10
commit 598a495239

@ -6,6 +6,10 @@ const urlParser = require('url')
const escapeStringRegexp = require('escape-string-regexp')
const markdownInclude = require('markdown-include')
const iso6393 = require('iso-639-3')
const intlDisplayNames = new Intl.DisplayNames(['en'], {
style: 'narrow',
type: 'region'
})
const utils = {}
@ -180,11 +184,6 @@ utils.code2name = function (code) {
return 'United States'
}
const intlDisplayNames = new Intl.DisplayNames(['en'], {
style: 'narrow',
type: 'region'
})
try {
return intlDisplayNames.of(code.toUpperCase())
} catch (e) {
@ -192,6 +191,23 @@ utils.code2name = function (code) {
}
}
utils.codeIsValid = function (code) {
switch (code.toLowerCase()) {
case 'int':
return true
case 'us':
return true
}
try {
intlDisplayNames.of(code.toUpperCase())
return true
} catch (e) {
return false
}
}
utils.language2code = function (name) {
const lang = iso6393.find(l => l.name === name)

Loading…
Cancel
Save