Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

adding more filters

  • Loading branch information...
commit c3de9ae4eae64b3cb2db1db422048fc0c4fb3ea7 1 parent 0b16f89
@paularmstrong paularmstrong authored
Showing with 40 additions and 0 deletions.
  1. +16 −0 lib/filters.js
  2. +24 −0 tests/filters.test.js
View
16 lib/filters.js
@@ -25,6 +25,22 @@ _filters = {
length: function () {
return '(function () { return ' + this + '.length; })()';
+ },
+
+ url_encode: function () {
+ return '(function () { return encodeURIComponent(' + this + '); })()';
+ },
+
+ url_decode: function () {
+ return '(function () { return decodeURIComponent(' + this + '); })()';
+ },
+
+ json_encode: function () {
+ return '(function () { return JSON.stringify(' + this + '); })()';
+ },
+
+ striptags: function () {
+ return '(function () { return ' + this + '.toString().replace(/(<([^>]+)>)/ig, ""); })()';
}
};
View
24 tests/filters.test.js
@@ -48,6 +48,30 @@ exports.length = function (test) {
test.done();
};
+exports.url_encode = function (test) {
+ var input = "param=1&anotherParam=2";
+ test.strictEqual("param%3D1%26anotherParam%3D2", eval(filters.wrap('input', ['url_encode'])));
+ test.done();
+};
+
+exports.url_decode = function (test) {
+ var input = "param%3D1%26anotherParam%3D2";
+ test.strictEqual("param=1&anotherParam=2", eval(filters.wrap('input', ['url_decode'])));
+ test.done();
+};
+
+exports.json_encode = function (test) {
+ var input = { foo: 'bar', baz: [1, 2, 3] };
+ test.strictEqual('{"foo":"bar","baz":[1,2,3]}', eval(filters.wrap('input', ['json_encode'])));
+ test.done();
+};
+
+exports.striptags = function (test) {
+ var input = '<h1>foo</h1> <div class="blah">hi</div>';
+ test.strictEqual('foo hi', eval(filters.wrap('input', ['striptags'])));
+ test.done();
+};
+
exports.multiple = function (test) {
var input = ['aWEsoMe', 'sAuCe'];
test.strictEqual('Awesome Sauce', eval(filters.wrap('input', ['join(\' \')', 'title'])));
Please sign in to comment.
Something went wrong with that request. Please try again.