Comparing version 0.1.0 to 0.1.1
@@ -122,5 +122,41 @@ var _ = require('underscore'); | ||
} | ||
} | ||
}; | ||
builtins.prototype.split = function(str, delim) { | ||
if(!_.isString(delim)) { | ||
throw new Error('InvalidTypeError - delim must be a string: ' + typeof delim); | ||
} | ||
if(_.isString(str)) { | ||
return str.split(delim); | ||
} else { | ||
throw new Error('InvalidTypeError - unsupported string type: ' + typeof str); | ||
} | ||
}; | ||
builtins.prototype.int = function(str) { | ||
if(_.isString(str)) { | ||
return parseInt(str); | ||
} else { | ||
throw new Error('InvalidTypeError - unsupported string type: ' + typeof str); | ||
} | ||
}; | ||
builtins.prototype.float = function(str) { | ||
if(_.isString(str)) { | ||
return parseFloat(str); | ||
} else { | ||
throw new Error('InvalidTypeError - unsupported string type: ' + typeof str); | ||
} | ||
}; | ||
builtins.prototype.str = function(x) { | ||
if(_.isString(x) || _.isArray(x) || _.isNumber(x)) { | ||
return x.toString(); | ||
} else { | ||
throw new Error('InvalidTypeError - unsupported type: ' + typeof x); | ||
} | ||
}; | ||
exports = module.exports = new builtins(); | ||
{ | ||
"name": "wash", | ||
"description": "a safe template rendering engine", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"main": "index", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -122,2 +122,53 @@ require('./util'); | ||
describe('split', function() { | ||
expect('{{ split("1", "") }}', '1'); | ||
expect('{{ split("1", ",") }}', '1'); | ||
// empty delim -> split all characters | ||
expect('{{ split("1,2,3", "") }}', '1,,,2,,,3'); | ||
expect('{{ split("1,2,3", ",") }}', '1,2,3'); | ||
expect('{{ split("1,2,3", 1) }}', '', function() { opt('throwsOnErrors', false); }); | ||
expectException('{{ split("1,2,3", 1) }}', function() { opt('throwsOnErrors', true); }); | ||
expect('{{ split(arr, ",") }}', '', function() { opt('throwsOnErrors', false); }); | ||
expectException('{{ split(arr, ",") }}', function() { opt('throwsOnErrors', true); }); | ||
expect('{{ split(func1, ",") }}', '', function() { opt('throwsOnErrors', false); }); | ||
expectException('{{ split(func1, ",") }}', function() { opt('throwsOnErrors', true); }); | ||
}); | ||
describe('int', function() { | ||
expect('{{ int("5") }}', '5'); | ||
expect('{{ int("1234") }}', '1234'); | ||
expect('{{ int("12.34") }}', '12'); | ||
expect('{{ int("0.34") }}', '0'); | ||
expect('{{ int(arr) }}', '', function() { opt('throwsOnErrors', false); }); | ||
expectException('{{ int(arr) }}', function() { opt('throwsOnErrors', true); }); | ||
}); | ||
describe('float', function() { | ||
expect('{{ float("5") }}', '5'); | ||
expect('{{ float("1234") }}', '1234'); | ||
expect('{{ float("12.34") }}', '12.34'); | ||
expect('{{ float("0.34") }}', '0.34'); | ||
expect('{{ float(arr) }}', '', function() { opt('throwsOnErrors', false); }); | ||
expectException('{{ float(arr) }}', function() { opt('throwsOnErrors', true); }); | ||
}); | ||
describe('str', function() { | ||
expect('{{ str("foo") }}', 'foo'); | ||
expect('{{ str(1234) }}', '1234'); | ||
expect('{{ str(ten) }}', '10'); | ||
expect('{{ str(arr) }}', '0,1,2,3,4'); | ||
expect('{{ str(func1) }}', '', function() { opt('throwsOnErrors', false); }); | ||
expectException('{{ str(func1)) }}', function() { opt('throwsOnErrors', true); }); | ||
expect('{{ str(a) }}', '', function() { opt('throwsOnErrors', false); }); | ||
expectException('{{ str(a)) }}', function() { opt('throwsOnErrors', true); }); | ||
}); | ||
describe('more edge cases', function() { | ||
@@ -124,0 +175,0 @@ expect('{{ len((foo)) }}', '3'); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
57963
1188