-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
46 lines (34 loc) · 1.01 KB
/
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
42
43
44
45
46
'use strict'
import { getTranslations, getUserLanguage } from './src/language.js'
status.BROWSER_LANG = typeof window !== 'undefined' &&
(window.navigator.userLanguage || window.navigator.language || '').toLowerCase()
const codes = getTranslations()[getUserLanguage()]
// array of status codes
status.codes = populateStatusesMap(status, codes)
function populateStatusesMap (statuses, codes) {
const arr = []
for (const code in codes) {
const message = codes[code]
const status = Number(code)
// Populate properties
statuses[status] = message
statuses[message] = status
statuses[message.toLowerCase()] = status
// Add to array
arr.push(status)
}
return arr
}
export function status (code, lang) {
const codes = getTranslations()[getUserLanguage(lang)]
// array of status codes
const statuses = {}
populateStatusesMap(statuses, codes)
if (typeof code === 'number') {
if (!statuses[code]) return
} else {
return
}
return statuses[code]
}
export default status