-
Notifications
You must be signed in to change notification settings - Fork 45
/
index.js
41 lines (30 loc) · 927 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const getTemplate = require('./lib/get-template')
const generateResult = require('./lib/generate-result')
const languages = require('./lib/data/languages.json')
function languageSort (a, b) {
if (a.text < b.text) {
return -1
}
if (a.text > b.text) {
return 1
}
return 0
}
languages.sort(languageSort)
module.exports = data => {
if (!data) {
throw new Error('Missing required input')
}
const template = getTemplate(data.lang || 'en')
if (!data.scores) {
throw new Error('Missing required input data.scores')
}
if (!template) {
throw new Error('Template not found. Try another data.lang input.')
}
return generateResult(data.scores, template)
}
module.exports.getInfo = () => ({ languages })
module.exports.getTemplate = (language = 'en') => getTemplate(language)
module.exports.getDomain = require('./lib/get-domain')
module.exports.getFacet = require('./lib/get-facet')