mirror of
https://github.com/seejohnrun/haste-server
synced 2025-08-22 13:13:28 -07:00
Update phonetic.js
This commit is contained in:
parent
ff39de1101
commit
26b1617edf
1 changed files with 14 additions and 18 deletions
|
@ -1,14 +1,10 @@
|
||||||
// Draws inspiration from pwgen and http://tools.arantius.com/password
|
// Draws inspiration from pwgen and http://tools.arantius.com/password
|
||||||
|
// Helper methods to get an random vowel or consonant
|
||||||
const randOf = (collection) => {
|
const randOf = (collection) => {
|
||||||
return () => {
|
return () => {
|
||||||
return collection[Math.floor(Math.random() * collection.length)];
|
return collection[Math.floor(Math.random() * collection.length)];
|
||||||
};
|
};
|
||||||
};
|
}, randVowel = randOf('aeiou'), randConsonant = randOf('bcdfghjklmnpqrstvwxyz');
|
||||||
|
|
||||||
// Helper methods to get an random vowel or consonant
|
|
||||||
const randVowel = randOf('aeiou');
|
|
||||||
const randConsonant = randOf('bcdfghjklmnpqrstvwxyz');
|
|
||||||
|
|
||||||
module.exports = class PhoneticKeyGenerator {
|
module.exports = class PhoneticKeyGenerator {
|
||||||
|
|
||||||
|
@ -18,7 +14,7 @@ module.exports = class PhoneticKeyGenerator {
|
||||||
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;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue