From 0c749864f567f0aaa45bd0d335980b424b916ee6 Mon Sep 17 00:00:00 2001 From: Sebastian Vollnhals Date: Fri, 27 Sep 2013 13:16:24 +0200 Subject: [PATCH] added blocking interface --- package.json | 2 +- readme.md | 10 ++++++++-- typo.js | 3 +++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 02bc3a7..d048ccd 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "typojs", "description": "Generates typical typing errors for any given string", - "version": "0.1.0", + "version": "0.1.1", "repository": { "type": "git", "url": "git://github.com/yetzt/node-typojs.git" diff --git a/readme.md b/readme.md index effdfc6..5ad8ad4 100644 --- a/readme.md +++ b/readme.md @@ -30,8 +30,10 @@ var typo = require("typojs"); ### typo(string, extended, callback(typos)) * `string` is a String you want to get typos for -* `extended` generates more, less common typos -* `callback` is a callback method with all generated typos as first argument +* `extended` generates more, less common typos (optional) +* `callback` is a callback method with all generated typos as first argument (optional) + +_If no callback method is specified, the generated typos will be returned instead._ ## Example @@ -39,10 +41,14 @@ var typo = require("typojs"); var typo = require("typojs"); +/* with callback */ typo("Whatever", true, function(typos){ console.log(typos); }); +/* without callback */ +console.log(typo("Whatever", true)); + ```` ## Dedication diff --git a/typo.js b/typo.js index 53143af..3c54aa8 100755 --- a/typo.js +++ b/typo.js @@ -136,6 +136,9 @@ var typo = function(word, extended, callback) { if (typos.indexOf(t) < 0) typos.push(t); }); + /* act blocking if no callback is given */ + if (typeof callback !== "function") return typos; + /* call back */ callback(typos);