Skip to content

Commit

Permalink
perf: cache config for punctuation removal
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrsh committed Jul 19, 2017
1 parent 82d4e34 commit 0f08f85
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
14 changes: 8 additions & 6 deletions dist/wade.js
Expand Up @@ -9,7 +9,11 @@
(typeof module === "object" && module.exports) ? module.exports = factory() : root.Wade = factory();
}(this, function() {
var stopWords = ['about', 'after', 'all', 'also', 'am', 'an', 'and', 'another', 'any', 'are', 'as', 'at', 'be', 'because', 'been', 'before', 'being', 'between', 'both', 'but', 'by', 'came', 'can', 'come', 'could', 'did', 'do', 'each', 'for', 'from', 'get', 'got', 'has', 'had', 'he', 'have', 'her', 'here', 'him', 'himself', 'his', 'how', 'if', 'in', 'into', 'is', 'it', 'like', 'make', 'many', 'me', 'might', 'more', 'most', 'much', 'must', 'my', 'never', 'now', 'of', 'on', 'only', 'or', 'other', 'our', 'out', 'over', 'said', 'same', 'see', 'should', 'since', 'some', 'still', 'such', 'take', 'than', 'that', 'the', 'their', 'them', 'then', 'there', 'these', 'they', 'this', 'those', 'through', 'to', 'too', 'under', 'up', 'very', 'was', 'way', 'we', 'well', 'were', 'what', 'where', 'which', 'while', 'who', 'with', 'would', 'you', 'your', 'a', 'i'];
var punctuationRE = /\.|\,|\!/g;
var punctuationRE = /[.,!?:;"']/g;
var config = {
stopWords: stopWords,
punctuationRE: punctuationRE
};

var getRoot = function(pattern, index) {
var node = index;
Expand Down Expand Up @@ -96,15 +100,15 @@
}

var removePunctuation = function(str) {
return str.replace(punctuationRE, "");
return str.replace(config.punctuationRE, "");
}

var removeStopWords = function(str) {
var words = getWords(str);
var i = words.length;

while((i--) !== 0) {
if(stopWords.indexOf(words[i]) !== -1) {
if(Wade.config.stopWords.indexOf(words[i]) !== -1) {
words.splice(i, 1);
}
}
Expand Down Expand Up @@ -216,9 +220,7 @@
}
}

Wade.config = {
stopWords: stopWords
};
Wade.config = config;

Wade.version = "0.3.1";

Expand Down
2 changes: 1 addition & 1 deletion dist/wade.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions src/index.js
@@ -1,5 +1,9 @@
var stopWords = ['about', 'after', 'all', 'also', 'am', 'an', 'and', 'another', 'any', 'are', 'as', 'at', 'be', 'because', 'been', 'before', 'being', 'between', 'both', 'but', 'by', 'came', 'can', 'come', 'could', 'did', 'do', 'each', 'for', 'from', 'get', 'got', 'has', 'had', 'he', 'have', 'her', 'here', 'him', 'himself', 'his', 'how', 'if', 'in', 'into', 'is', 'it', 'like', 'make', 'many', 'me', 'might', 'more', 'most', 'much', 'must', 'my', 'never', 'now', 'of', 'on', 'only', 'or', 'other', 'our', 'out', 'over', 'said', 'same', 'see', 'should', 'since', 'some', 'still', 'such', 'take', 'than', 'that', 'the', 'their', 'them', 'then', 'there', 'these', 'they', 'this', 'those', 'through', 'to', 'too', 'under', 'up', 'very', 'was', 'way', 'we', 'well', 'were', 'what', 'where', 'which', 'while', 'who', 'with', 'would', 'you', 'your', 'a', 'i'];
var punctuationRE = /[.,!?:;"']/g;
var config = {
stopWords: stopWords,
punctuationRE: punctuationRE
};

var getRoot = function(pattern, index) {
var node = index;
Expand Down Expand Up @@ -86,7 +90,7 @@ var lowercase = function(str) {
}

var removePunctuation = function(str) {
return str.replace(Wade.config.punctuationRE, "");
return str.replace(config.punctuationRE, "");
}

var removeStopWords = function(str) {
Expand Down Expand Up @@ -206,9 +210,6 @@ Wade.save = function(search) {
}
}

Wade.config = {
stopWords: stopWords,
punctuationRE: punctuationRE,
};
Wade.config = config;

Wade.version = "__VERSION__";

0 comments on commit 0f08f85

Please sign in to comment.