1
0
Fork 0
mirror of https://github.com/SunRed/haste-server.git synced 2024-11-27 11:20:18 +01:00
haste-server/lib/key_generators/phonetic.js
zneix 7808ccf009
Rewrote key generator tests, fixed vowels
-Tests were not brought up to date with some updates that were done to key generator modules.
-Apparently original creator had no idea that 'y' is a vowel; fixed this issue and reflected changes in actual files.
2020-09-23 01:07:32 +02:00

25 lines
686 B
JavaScript

//inspiration from pwgen and https://tools.arantius.com/password
//helper function to get a random array element
function randArray(collection){
return collection[ Math.floor(Math.random() * collection.length) ];
}
const vovels = 'aeiouy';
const consonants = 'bcdfghjklmnpqrstvwxz';
module.exports = class PhoneticKeyGenerator {
//generate a phonetic key consisting of random consonant & vowel
createKey(keyLength){
let text = '';
const start = Math.floor(Math.random() * 2);
//start == 0 - starts with consonant
//start == 1 - starts with vovel
for (let i = 0; i < keyLength; i++){
text += randArray(i % 2 == start ? consonants : vovels);
}
return text;
}
};