Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

wash

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wash - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

38

lib/builtins.js

@@ -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();

2

package.json
{
"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');

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc