Update utils.js

pull/5149/head
Aleksandr Statciuk 3 years ago
parent 7888841f17
commit 6c80207144

@ -1,7 +1,8 @@
const { orderBy } = require('natural-orderby')
const iso6393 = require('@freearhey/iso-639-3')
const transliteration = require('transliteration')
const countries = require('../data/countries')
const categories = require('../data/categories')
const languages = require('../data/languages')
const regions = require('../data/regions')
const utils = {}
@ -50,11 +51,19 @@ utils.code2name = function (code) {
}
utils.language2code = function (name) {
const lang = iso6393.find(l => l.name === name)
const lang = languages.find(l => l.name === name)
return lang && lang.code ? lang.code : null
}
utils.country2language = function (code) {
const country = countries[code.toUpperCase()]
if (!country.languages.length) return ''
const language = languages.find(l => l.code === country.languages[0])
return language ? language.name : ''
}
utils.sortBy = function (arr, fields, order = null) {
fields = fields.map(field => {
if (field === 'resolution.height') return channel => channel.resolution.height || 0

Loading…
Cancel
Save