brocabulary
Advanced tools
Comparing version 0.0.1 to 0.1.0
19
index.js
var fs = require('fs') | ||
, dictFile = __dirname + '/data/dict'; | ||
, listenshtein = require('listenshtein'); | ||
var dictFile = __dirname + '/data/dict'; | ||
function rand(l) { | ||
return Math.floor(Math.random()*l); | ||
} | ||
function brocabulary(cb) { | ||
@@ -10,5 +16,14 @@ var self = {} | ||
self.random = function() { | ||
return dict[Math.floor(Math.random()*dict.length)]; | ||
return dict[rand(dict.length)]; | ||
}; | ||
self.broify = function(words) { | ||
if(typeof words === 'string') words = words.split(' '); | ||
for(var i = 0, l = words.length; i < l; i++) { | ||
var match = listenshtein(words[i], dict, 3); | ||
if(match) words[i] = match; | ||
} | ||
return words.join(' '); | ||
}; | ||
cb = (cb || function() {}); | ||
@@ -15,0 +30,0 @@ s.on('end', function() { cb(self); }); |
{ | ||
"name": "brocabulary", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "Expand your brocabulary", | ||
@@ -11,3 +11,6 @@ "main": "index.js", | ||
"author": "Drew Stokes", | ||
"license": "BSD" | ||
"license": "BSD", | ||
"dependencies": { | ||
"listenshtein": "0.0.0" | ||
} | ||
} |
@@ -12,3 +12,5 @@ var assert = require('assert') | ||
assert.ok(b.random().length); | ||
console.log(b.broify('tuxedo')); | ||
assert(b.broify('tuxedo') === 'Tuxedbro'); | ||
}); | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
4305
6
43
38
1
+ Addedlistenshtein@0.0.0
+ Addedfast-levenshtein@1.0.7(transitive)
+ Addedlistenshtein@0.0.0(transitive)