Update utils.js
This commit is contained in:
parent
7888841f17
commit
6c80207144
|
@ -1,7 +1,8 @@
|
||||||
const { orderBy } = require('natural-orderby')
|
const { orderBy } = require('natural-orderby')
|
||||||
const iso6393 = require('@freearhey/iso-639-3')
|
|
||||||
const transliteration = require('transliteration')
|
const transliteration = require('transliteration')
|
||||||
|
const countries = require('../data/countries')
|
||||||
const categories = require('../data/categories')
|
const categories = require('../data/categories')
|
||||||
|
const languages = require('../data/languages')
|
||||||
const regions = require('../data/regions')
|
const regions = require('../data/regions')
|
||||||
|
|
||||||
const utils = {}
|
const utils = {}
|
||||||
|
@ -50,11 +51,19 @@ utils.code2name = function (code) {
|
||||||
}
|
}
|
||||||
|
|
||||||
utils.language2code = function (name) {
|
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
|
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) {
|
utils.sortBy = function (arr, fields, order = null) {
|
||||||
fields = fields.map(field => {
|
fields = fields.map(field => {
|
||||||
if (field === 'resolution.height') return channel => channel.resolution.height || 0
|
if (field === 'resolution.height') return channel => channel.resolution.height || 0
|
||||||
|
|
Loading…
Reference in New Issue