forked from jablan/polumenta
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
39 lines (35 loc) · 1.36 KB
/
index.js
File metadata and controls
39 lines (35 loc) · 1.36 KB
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
const letters = require("./letters");
const getRandomInt = max => {
max = Math.floor(max);
return Math.floor(Math.random() * (max - 0));
};
const getGenderEnding = (gender, choosenScript) => {
switch (gender) {
case "male":
return letters[choosenScript].d[0];
case "neutral":
return letters[choosenScript].d[1];
case "female":
return letters[choosenScript].d[2];
default:
return letters[choosenScript].d[0];
}
};
const getPolumenta = (script, gender) => {
const choosenScript = script || "latin";
const choosenGender = gender || "male";
let currentPolumenta = "";
currentPolumenta += letters[choosenScript].a[getRandomInt(letters[choosenScript].a.length)];
currentPolumenta += letters[choosenScript].b[getRandomInt(letters[choosenScript].b.length)];
currentPolumenta += letters[choosenScript].c[getRandomInt(letters[choosenScript].c.length)];
return (currentPolumenta += getGenderEnding(choosenGender, choosenScript));
};
/**
* Generate Polumenta
* @param {string} script Script - 'latin' or 'cyrilic', default is 'latin' (this parameter changes script of Polumenta's name)
* @param {string} gender Gender - 'male', 'neutral' or 'female', default is 'male' (this parameter changes last letter of Polumenta's name)
* @return {string}
*/
module.exports = (script, gender) => {
return getPolumenta(script, gender);
};