Skip to content

Commit

Permalink
will only handle the most basic filters for now, but it's a start; ne…
Browse files Browse the repository at this point in the history
…eds tests
  • Loading branch information
Anthropohedron committed Apr 19, 2015
1 parent 3883aa3 commit 1abbf60
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lib/filter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*jslint vars: true, white: true, plusplus: true, todo: true */
"use strict";

function subToRE(sub) {
var newSub = [
new RegExp(sub.find, sub.flag),
sub.repl
];
//TODO: check repl to determine whether it requires
//TODO: a function instead of a simple substitution
return newSub;
}

function Filter(config) {
this.subs = config.subs.map(subToRE);
}

Filter.prototype = {

exec: function execFilter(text) {
this.subs.forEach(function(sub) {
text = text.replace(sub[0], sub[1]);
});
return text;
}

};

exports.Filter = Filter;

0 comments on commit 1abbf60

Please sign in to comment.