forked from Alheimsins/b5-johnson-120-ipip-neo-pi-r
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
59 lines (52 loc) · 1.4 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
47
48
49
50
51
52
53
54
55
56
57
58
59
const { knuthShuffle } = require('knuth-shuffle')
const languages = require('./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.getItems = (lang = 'en', shuffle = false) => {
let choices, questions
try {
questions = require(`./data/${lang}/questions.json`)
choices = require(`./data/${lang}/choices`)
} catch (error) {
throw new Error('Inventory not found. Try another language input.')
}
const inventory = shuffle === true ? knuthShuffle(questions) : questions
return inventory.map((question, i) => Object.assign(question, { num: ++i, choices: choices[question.keyed] }))
}
module.exports.getInfo = () => (
{
name: "Johnson's IPIP NEO-PI-R",
id: 'johnson-120-ipip-neo-pi-r',
shortId: 'b5-120',
time: 10,
questions: 120,
note: 'Recommended',
languages
}
)
module.exports.getChoices = (lang = 'en') => {
let choices
try {
choices = require(`./data/${lang}/choices`)
} catch (error) {
throw new Error('Choices not found. Try another language input.')
}
return choices
}
module.exports.getQuestions = (lang = 'en') => {
let questions
try {
questions = require(`./data/${lang}/questions`)
} catch (error) {
throw new Error('Questions not found. Try another language input.')
}
return questions
}