2012-01-08 00:35:11 +08:00
|
|
|
// Draws inspiration from pwgen and http://tools.arantius.com/password
|
|
|
|
var PhoneticKeyGenerator = function(options) {
|
|
|
|
// No options
|
|
|
|
};
|
|
|
|
|
|
|
|
// Generate a phonetic key
|
|
|
|
PhoneticKeyGenerator.prototype.createKey = function(keyLength) {
|
|
|
|
var text = '';
|
2014-03-25 09:23:31 +08:00
|
|
|
var start = Math.round(Math.random());
|
2012-01-08 00:35:11 +08:00
|
|
|
for (var i = 0; i < keyLength; i++) {
|
2014-03-25 09:20:05 +08:00
|
|
|
text += (i % 2 == start) ? this.randConsonant() : this.randVowel();
|
2012-01-08 00:35:11 +08:00
|
|
|
}
|
|
|
|
return text;
|
|
|
|
};
|
|
|
|
|
2014-03-25 09:20:05 +08:00
|
|
|
PhoneticKeyGenerator.consonants = 'bcdfghjklmnpqrstvwxyz';
|
2012-01-08 00:35:11 +08:00
|
|
|
PhoneticKeyGenerator.vowels = 'aeiou';
|
|
|
|
|
|
|
|
// Get an random vowel
|
|
|
|
PhoneticKeyGenerator.prototype.randVowel = function() {
|
|
|
|
return PhoneticKeyGenerator.vowels[
|
|
|
|
Math.floor(Math.random() * PhoneticKeyGenerator.vowels.length)
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
// Get an random consonant
|
|
|
|
PhoneticKeyGenerator.prototype.randConsonant = function() {
|
|
|
|
return PhoneticKeyGenerator.consonants[
|
|
|
|
Math.floor(Math.random() * PhoneticKeyGenerator.consonants.length)
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = PhoneticKeyGenerator;
|