-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.js
45 lines (33 loc) · 937 Bytes
/
common.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
'use strict'
const fs = require('fs')
const defined = require('defined')
exports.readOptions = (input) => {
const output = {}
// Languages
output.languages = []
const setLang = (val) => {
if (Array.isArray(val))
output.languages.push(...val)
else
output.languages.push(val)
}
setLang(input.languages)
setLang(input.lang)
setLang(input.l)
output.languages = output.languages.filter(Boolean)
if (!output.languages.length)
throw new Error('i18nify: You must specify at least one language')
// Default
output.default = defined(input.default, input.d, output.languages[0])
return output
}
const realpathCache = new Map()
exports.realpath = function(file, cb) {
if (realpathCache.has(file))
return process.nextTick(() => cb(null, realpathCache.get(file)))
fs.realpath(file, (err, rp) => {
if (err) return cb(err)
realpathCache.set(file, rp)
cb(null, rp)
})
}