-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
executable file
·26 lines (21 loc) · 771 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
const en = require('./en.json');
const es = require('./es.json');
const fr = require('./fr.json');
const de = require('./de.json');
const CONDITIONS = { en, es, fr, de };
function startingCondition(lang, onlyLatest) {
if (!CONDITIONS.hasOwnProperty(lang)) {
throw new Error(`
Unknown language: ${lang}.
Supported languages: ${Object.keys(CONDITIONS).join(',')}.
If you'd like to contribute, please visit:
https://github.com/higgins/starting-condition
`);
}
conditions = onlyLatest ? CONDITIONS[lang].latest : CONDITIONS[lang].archive.concat(CONDITIONS[lang].latest);
return conditions[Math.floor(Math.random() * conditions.length)];
};
if (global.window) {
global.window.startingCondition = startingCondition;
}
module.exports = startingCondition;