Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

adding 'default' filter

  • Loading branch information...
commit a9d77a0d0f91c326952414dd83a56a0f238d5695 1 parent 76f82ac
@paularmstrong paularmstrong authored
Showing with 15 additions and 0 deletions.
  1. +3 −0  lib/filters.js
  2. +12 −0 tests/filters.test.js
View
3  lib/filters.js
@@ -113,6 +113,9 @@ _dateFormats = {
}
};
+exports.default = function (input, def) {
+ return (input || typeof input === 'number') ? input : def;
+};
exports.lower = function (input) {
return input.toString().toLowerCase();
View
12 tests/filters.test.js
@@ -1,5 +1,17 @@
var filters = require('../lib/filters');
+exports.default = function (test) {
+ var defOut = 'blah';
+ test.strictEqual('foo', filters.default('foo', defOut), 'string not overridden by default');
+ test.strictEqual(0, filters.default(0, defOut), 'zero not overridden by default');
+
+ test.strictEqual(defOut, filters.default('', defOut), 'empty string overridden by default');
+ test.strictEqual(defOut, filters.default(undefined, defOut), 'default overrides undefined');
+ test.strictEqual(defOut, filters.default(null, defOut), 'default overrides null');
+ test.strictEqual(defOut, filters.default(false, defOut), 'default overrides false');
+ test.done();
+};
+
exports.lower = function (test) {
var input = 'BaR';
test.strictEqual('bar', filters.lower(input));
Please sign in to comment.
Something went wrong with that request. Please try again.