parent
af6ba02012
commit
53b9c770e6
@ -0,0 +1,31 @@ |
||||
{ |
||||
"name": "weeapass", |
||||
"version": "1.0.0", |
||||
"description": "Weeaboo password generator", |
||||
"main": "index.js", |
||||
"scripts": { |
||||
"test": "echo \"Error: no test specified\" && exit 1" |
||||
}, |
||||
"repository": { |
||||
"type": "git", |
||||
"url": "git+https://github.com/hjri/Weeapass.git" |
||||
}, |
||||
"keywords": [ |
||||
"password", |
||||
"generator" |
||||
], |
||||
"author": "hj", |
||||
"license": "ISC", |
||||
"bugs": { |
||||
"url": "https://github.com/hjri/Weeapass/issues" |
||||
}, |
||||
"homepage": "https://github.com/hjri/Weeapass#readme", |
||||
"dependencies": { |
||||
"chalk": "^1.1.1", |
||||
"chance": "^1.0.1", |
||||
"commander": "^2.9.0", |
||||
"lodash": "^4.6.1", |
||||
"weighted": "^0.3.0", |
||||
"weighted-random": "^0.1.0" |
||||
} |
||||
} |
@ -0,0 +1,115 @@ |
||||
var _ = require('lodash'), |
||||
baked = false; |
||||
chance = new require('chance')(), |
||||
classes = [ |
||||
'syllable', |
||||
'vowel-only', |
||||
'n', |
||||
'youon', |
||||
'syllable-youon' |
||||
], |
||||
consonants = { |
||||
'b': 100, |
||||
'c': 75, |
||||
'd': 100, |
||||
'f': 50, |
||||
'g': 100, |
||||
'h': 50, |
||||
'j': 100, |
||||
'k': 100, |
||||
'l': 'r', |
||||
'm': 100, |
||||
'n': 75, |
||||
'p': 50, |
||||
'q': 0, |
||||
'r': 50, |
||||
's': 100, |
||||
't': 0, |
||||
'v': 25, |
||||
'w': 'v', |
||||
'x': 0, |
||||
'z': 50 |
||||
}, |
||||
vowels = ['a', 'i', 'e', 'o', 'u'], |
||||
youonConsonants = ['k', 's', 'c'], |
||||
generateFunctions = { |
||||
'syllable': function(vowel, consonant) { |
||||
return consonant + vowel; |
||||
}, |
||||
'youon': function(vowel) { |
||||
return 'y' + vowel; |
||||
}, |
||||
'n': function() { |
||||
return 'n'; |
||||
}, |
||||
'syllable-youon': function(vowel, consonant) { |
||||
return consonant + 'y' + vowel; |
||||
}, |
||||
'vowel-only': function(vowel) { |
||||
return vowel; |
||||
} |
||||
}, |
||||
bakeArrays = function(options) { |
||||
// Make reusable??
|
||||
if (baked) return; |
||||
options = options || {}; |
||||
consonants = _.each(consonants, function(v, k) { |
||||
if (typeof v === 'string') { |
||||
consonants[k] = consonants[v]; |
||||
}; |
||||
}); |
||||
|
||||
// make c2sh and c2t cross-compatible?
|
||||
if (options.s2sh) { |
||||
consonants.sh = consonants.s; |
||||
consonants.ch = consonants.c; |
||||
delete consonants.s; |
||||
delete consonants.c; |
||||
} |
||||
if (options.c2t) { |
||||
consonants.t = consonants.c; |
||||
delete consonants.c; |
||||
} |
||||
options.engrish && delete consonants.l; |
||||
options.noW && delete consonants.w; |
||||
options.noV && delete consonants.v; |
||||
baked = true; |
||||
}, |
||||
generateNextSyllable = function(previousSyllables) { |
||||
var classProbability = { |
||||
'syllable': 100, |
||||
'syllable-youon': 12, |
||||
'n': 25, |
||||
'vowel-only': 50, |
||||
'youon': 25 |
||||
}; |
||||
// TODO add '-' support?
|
||||
if (_.last(previousSyllables) && _.last(previousSyllables).class === 'n') { |
||||
classProbability.n = 0; |
||||
} |
||||
classProbability['vowel-only'] = classProbability['vowel-only'] / |
||||
(_.filter(previousSyllables, function(syll) { |
||||
return syll.class === 'vowel'; |
||||
}).length + 1); |
||||
var nextClass = chance.weighted( _.keys(classProbability), _.values(classProbability)), |
||||
consSet = _.includes(nextClass, 'youon') ? _.pick(consonants, youonConsonants) : consonants, |
||||
consonant = chance.weighted(_.keys(consSet),_.values(consSet)), |
||||
vowel = chance.pick(vowels), |
||||
next = generateFunctions[nextClass](vowel, consonant); |
||||
|
||||
return { |
||||
class: nextClass, |
||||
text: next |
||||
}; |
||||
}, |
||||
word = [], |
||||
makeWord = function(options, length) { |
||||
bakeArrays(options); |
||||
var index = 0, |
||||
word = []; |
||||
for(index;index<length;index++){ |
||||
word.push(generateNextSyllable(word)); |
||||
} |
||||
return _(word).map(function(w){return w.text;}).join(''); |
||||
}; |
||||
module.exports = makeWord; |
@ -0,0 +1,15 @@ |
||||
/** |
||||
* Module dependencies. |
||||
*/ |
||||
|
||||
var program = require('commander'); |
||||
|
||||
program |
||||
.version('1.0.0') |
||||
.option('-c, --cheese [type]', 'Add the specified type of cheese [marble]', 'marble') |
||||
|
||||
console.log('you ordered a pizza with:'); |
||||
if (program.peppers) console.log(' - peppers'); |
||||
if (program.pineapple) console.log(' - pineapple'); |
||||
if (program.bbqSauce) console.log(' - bbq'); |
||||
console.log(' - %s cheese', program.cheese); |
Loading…
Reference in new issue