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

28 lines
665 B
JavaScript
Raw Normal View History

// Draws inspiration from pwgen and http://tools.arantius.com/password
const randOf = (collection) => {
2020-08-28 04:39:03 +02:00
return () => {
return collection[Math.floor(Math.random() * collection.length)];
};
};
// Helper methods to get an random vowel or consonant
const randVowel = randOf('aeiou');
const randConsonant = randOf('bcdfghjklmnpqrstvwxyz');
module.exports = class PhoneticKeyGenerator {
2020-08-28 04:39:03 +02:00
// Generate a phonetic key of alternating consonant & vowel
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++){
text += (i % 2 == start) ? randConsonant() : randVowel();
}
2020-08-28 04:39:03 +02:00
return text;
}
};