Update phonetic.js

This commit is contained in:
wioniqle-q 2021-11-15 14:54:33 +03:00 committed by GitHub
commit 26b1617edf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,27 +1,23 @@
// Draws inspiration from pwgen and http://tools.arantius.com/password // Draws inspiration from pwgen and http://tools.arantius.com/password
const randOf = (collection) => {
return () => {
return collection[Math.floor(Math.random() * collection.length)];
};
};
// Helper methods to get an random vowel or consonant // Helper methods to get an random vowel or consonant
const randVowel = randOf('aeiou'); const randOf = (collection) => {
const randConsonant = randOf('bcdfghjklmnpqrstvwxyz'); return () => {
return collection[Math.floor(Math.random() * collection.length)];
};
}, randVowel = randOf('aeiou'), randConsonant = randOf('bcdfghjklmnpqrstvwxyz');
module.exports = class PhoneticKeyGenerator { module.exports = class PhoneticKeyGenerator {
// Generate a phonetic key of alternating consonant & vowel // Generate a phonetic key of alternating consonant & vowel
createKey(keyLength) { createKey(keyLength) {
let text = ''; let text = '';
const start = Math.round(Math.random()); const start = Math.round(Math.random());
for (let i = 0; i < keyLength; i++) { for (let i = 0; i < keyLength; i++) {
text += (i % 2 == start) ? randConsonant() : randVowel(); text += i % 2 !== start ? randVowel() : randConsonant();
}
return text;
} }
return text;
}
}; };