Update lib/key_generators/phonetic.js
This commit is contained in:
parent
7b5b55da5e
commit
6abc863848
|
@ -1,13 +1,25 @@
|
||||||
|
const vowels = 'aeiou';
|
||||||
|
const consonants = 'bcdfghjklmnpqrstvwxyz';
|
||||||
|
|
||||||
|
const randOf = (collection) => {
|
||||||
|
return () => collection[Math.floor(Math.random() * collection.length)];
|
||||||
|
};
|
||||||
|
|
||||||
|
const randVowel = randOf(vowels);
|
||||||
|
const randConsonant = randOf(consonants);
|
||||||
|
|
||||||
module.exports = class PhoneticKeyGenerator {
|
module.exports = class PhoneticKeyGenerator {
|
||||||
|
|
||||||
createKey(keyLength) {
|
createKey(keyLength) {
|
||||||
let text = '';
|
let text = '';
|
||||||
let isConsonant = Math.random() < 0.5;
|
let chooseConsonant = Math.random() < 0.5; // Randomly start with consonant or vowel
|
||||||
|
|
||||||
for (let i = 0; i < keyLength; i++) {
|
for (let i = 0; i < keyLength; i++) {
|
||||||
text += isConsonant ? randConsonant() : randVowel();
|
text += chooseConsonant ? randConsonant() : randVowel();
|
||||||
isConsonant = !isConsonant; // Toggle between consonant and vowel
|
chooseConsonant = !chooseConsonant; // Alternate between consonant and vowel
|
||||||
}
|
}
|
||||||
|
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue