1
0
Fork 0
mirror of https://github.com/SunRed/haste-server.git synced 2024-11-24 02:00:17 +01:00
haste-server/lib/key_generators/phonetic.js

24 lines
616 B
JavaScript
Raw Normal View History

2020-08-29 00:39:07 +02:00
//inspiration from pwgen and https://tools.arantius.com/password
2020-08-29 00:39:07 +02:00
//helper function to get a random consonant / vowel
function randArray(collection){
return collection[ Math.floor(Math.random() * collection.length) ];
}
2020-08-29 00:39:07 +02:00
const vovels = 'aeiou';
const consonants = 'bcdfghjklmnpqrstvwxyz';
module.exports = class PhoneticKeyGenerator {
2020-08-29 00:39:07 +02:00
//generate a phonetic key consisting of random consonant & vowel
2020-08-28 04:39:03 +02:00
createKey(keyLength){
let text = '';
const start = Math.floor(Math.random() * 2);
2020-08-28 04:39:03 +02:00
for (let i = 0; i < keyLength; i++){
2020-08-29 00:39:07 +02:00
text += randArray(i % 2 == start ? consonants : vovels);
2020-08-28 04:39:03 +02:00
}
return text;
}
};