Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added threshold, ignoreHtml, ignoreCode support

  • Loading branch information...
commit 9b90521b9242b267eb3a6ef2fa89dffd3f6e8e4a 1 parent 0a0688c
@tstone authored
Showing with 26 additions and 3 deletions.
  1. +14 −0 src/lib.js
  2. +12 −3 src/spell.js
View
14 src/lib.js
@@ -2,6 +2,20 @@
var _ = require('underscore');
+exports.cleanText = function(source, removeCode, removeHtml) {
+
+ if (removeCode) {
+ source = source.replace(/<code[^>]+>[\s\S]*?<\/code>/gi, '');
+ }
+
+ if (removeHtml) {
+ source = source.replace(/<[^>]+>/gi, '');
+ }
+
+ return source;
+
+};
+
exports.formatResult = function(resp, source) {
var sugObj = function(o) {
View
15 src/spell.js
@@ -18,18 +18,27 @@ var Checker = function(config){
Checker.prototype.check = function(s, callback){
+ var text = lib.cleanText(s);
+
request({
uri: 'http://www.google.com/tbproxy/spell?lang=' + this.config.language + '&hl=' + this.config.language,
method: 'POST',
- body: lib.reqXml(s, this.config)
+ body: lib.reqXml(text, this.config)
}, function(err, res, body){
if (err || res.statusCode !== 200) {
if (typeof callback === 'function') { callback(err); }
} else {
var parser = new xml2js.Parser({ attrkey: 'attrs', charkey: 'chars' });
parser.parseString(body, function(err, result){
- result = lib.formatResult(result, s);
- console.log(result);
+ result = lib.formatResult(result, text);
+
+ // Remove suggestions below confidence threshold
+ var threshold = this.config.threshold;
+ result.suggestions = result.suggestions.reduce(function(acc, x){
+ if (x.confidence >= threshold) { acc.push(x); }
+ return acc;
+ }, []);
+
if (typeof callback === 'function') { callback(undefined, result); }
}.bind(this));
}
Please sign in to comment.
Something went wrong with that request. Please try again.