-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
will only handle the most basic filters for now, but it's a start; ne…
…eds tests
- Loading branch information
1 parent
3883aa3
commit 1abbf60
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|