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

helper-cache

Package Overview
Dependencies
Maintainers
2
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

helper-cache - npm Package Compare versions

Comparing version 0.4.1 to 0.4.2

1

index.js

@@ -226,2 +226,3 @@ /*!

var nextCallback = function (err, results) {
if (err) return cb(err);
content = content.replace(helper.id, results);

@@ -228,0 +229,0 @@ next(null, content);

2

package.json
{
"name": "helper-cache",
"description": "Easily get and set helper functions to pass to any application or template engine.",
"version": "0.4.1",
"version": "0.4.2",
"homepage": "https://github.com/jonschlinkert/helper-cache",

@@ -6,0 +6,0 @@ "author": {

@@ -85,3 +85,65 @@ /*!

it('should bubble up an error.', function (done) {
var helper = cache();
var partials = {
foo: {
data: { 'bar': 'baz' },
content: 'Hi there <%= bar %>'
},
bar: {
data: { 'baz': 'bang' },
content: 'This is <%= baz %>'
}
};
function render (content, options, cb) {
content = _.template(content, options, { imports: helper.getHelper() });
return helper.resolve(content, function (err, content) {
if (err) return cb(err);
return cb(null, content);
});
}
helper.addAsyncHelper('lower', function (str, callback) {
callback(null, str.toLowerCase());
});
helper.addAsyncHelper('upper', function (str, callback) {
callback(null, str.toUpperCase());
});
helper.addAsyncHelper('sleep', function (ms, msg, callback) {
var start = new Date();
setTimeout(function () {
var end = new Date();
var elapsed = end - start;
callback(null, elapsed + ' ' + msg);
}, ms);
});
helper.addAsyncHelper('partial', function (name, locals, callback) {
var partial = partials[name];
if (typeof locals === 'function') {
callback = locals;
locals = {};
}
if (!partial) return callback(new Error('Partial ' + name + ' not found!'));
render(partial.content, _.extend({}, partial.data, locals), callback);
});
var template = [
'Elapsed: <%= sleep(50, "milliseconds") %>',
'Lower: <%= lower(name) %>',
'Upper: <%= upper(name) %>',
'Partial-1: <%= partial("foo") %>',
'Partial-2: <%= partial("bar", { baz: "beep boop bop" }) %>',
'Partial-3: <%= partial("blah") %>'
].join('\n');
var content = render(template, {name: 'Brian Woodward'}, function (err, content) {
if (err) return done();
return done(new Error('Expected an error'));
});
});
});
});

@@ -50,3 +50,33 @@ /*!

});
});
it('should handle an error.', function (done) {
var helper = cache();
helper.addAsyncHelper('lower', function (str, callback) {
callback(null, str.toLowerCase());
});
helper.addAsyncHelper('upper', function (str, callback) {
callback(null, str.toUpperCase());
});
helper.addAsyncHelper('error', function (ms, msg, callback) {
var start = new Date();
setTimeout(function () {
var end = new Date();
var elapsed = end - start;
callback(new Error('Something bad happened'));
}, ms);
});
var template = [
'Elapsed: <%= error(50, "milliseconds") %>',
'Lower: <%= lower(name) %>',
'Upper: <%= upper(name) %>'
].join('\n');
var content = _.template(template, {name: 'Brian Woodward'}, { imports: helper.getHelper() });
helper.resolve(content, function (err, content) {
if (err) return done();
done(new Error('Expected an error to be thrown.'));
});
});

@@ -53,0 +83,0 @@

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