Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
handlebars-utils
Advanced tools
Utils for handlebars helpers. Externalized from handlebars, to allow helpers to use the utils without having to depend on handlebars itself.
Utils for handlebars helpers. Externalized from handlebars, to allow helpers to use the utils without having to depend on handlebars itself.
Follow this project's author, Jon Schlinkert, for updates on this project and others.
(TOC generated by verb using markdown-toc)
Install with npm:
$ npm install --save handlebars-utils
var utils = require('handlebars-utils');
Returns true if a helper is a block helper.
Params
options
{Object}: Helper options objectreturns
{Boolean}Example
Handlebars.registerHelper('example', function(options) {
if (utils.isBlock(options)) {
// do something if this is a block helper
} else {
// do something else if this is a not block helper
}
});
Returns the given value or renders the block if it's a block helper.
Params
val
{any}options
{Object}context
{Object}returns
{String}: Either returns the value, or renders the block.Example
Handlebars.registerHelper('example', function(val, locals, options) {
return utils.fn(val, locals, options);
});
Returns the given value or renders the inverse block if it's a block helper.
Params
val
{any}options
{Object}context
{Object}returns
{String}: Either returns the value, or renders the inverse block.Example
Handlebars.registerHelper('example', function(val, locals, options) {
return utils.inverse(val, locals, options);
});
Gets the return value for a helper, by either rendering the block or inverse block if it's a block helper, or returning the given value (when truthy) or an empty string (when falsey) if it's a non-block expression.
Params
val
{any}options
{Object}context
{Object}returns
{String}Example
Handlebars.registerHelper('example', function(val, locals, options) {
return utils.value(val, locals, options);
});
Returns true if the given value is a handlebar options
object.
Params
val
{Object}returns
{Boolean}Example
Handlebars.registerHelper('example', function(val, locals, options) {
if (utils.isOptions(locals)) {
options = locals;
locals = {};
}
// do stuff
});
Returns true if the given value is undefined
or is a handlebars options hash (which means that a value was not passed by the user).
Params
value
{any}returns
{Boolean}Example
Handlebars.registerHelper('example', function(val, options) {
if (utils.isUndefined(val)) {
return '';
}
// do stuff
});
Returns true if an app
propery is on the context, which means the context was created by assemble, templates, verb, or any other library that follows this convention.
Params
value
{any}returns
{Boolean}Example
Handlebars.registerHelper('example', function(val, options) {
var context = options.hash;
if (utils.isApp(this)) {
context = Object.assign({}, this.context, context);
}
// do stuff
});
Creates an options object from the context
, locals
and options.
Handlebars' options.hash
is merged onto the options, and if the context
is created by templates, this.options
will be merged onto the
options as well.
Params
context
{Object}locals
{Object}: Options or localsoptions
{Object}returns
{Boolean}Get the context to use for rendering.
Params
thisArg
{Object}: Optional invocation context this
returns
{Object}Returns true if the given value is an object.
Params
val
{Object}returns
{Boolean}Example
console.log(utils.isObject(null));
//=> false
console.log(utils.isObject([]));
//=> false
console.log(utils.isObject(function() {}));
//=> false
console.log(utils.isObject({}));
//=> true
Returns true if the given value is "empty".
Params
value
{any}returns
{Boolean}Example
console.log(utils.isEmpty(0));
//=> false
console.log(utils.isEmpty(''));
//=> true
console.log(utils.isEmpty([]));
//=> true
console.log(utils.isEmpty({}));
//=> true
Returns the given value. If the value is a function it will be called with the current context, otherwise the value is returned.
Params
val
{any}returns
{any}Example
console.log(utils.result('foo'));
//=> 'foo'
console.log(utils.result(function() {
return 'foo';
}));
//=> 'foo'
Returns the given value as-is, unchanged.
Params
val
{any}returns
{any}Example
console.log(utils.result('foo'));
//=> 'foo'
console.log(utils.result(function() {
return 'foo';
}));
//=> [function]
Return true if val
is a non-empty string.
Params
val
{any}: The value to checkreturns
{Boolean}Cast the given val
to an array.
Params
val
{any}returns
{Array}Example
console.log(utils.arrayify(''));
//=> []
console.log(utils.arrayify('foo'));
//=> ['foo']
console.log(utils.arrayify(['foo']));
//=> ['foo']
Try to parse the given string
as JSON. Fails
gracefully and always returns an object if the value cannot be parsed.
Params
string
{String}returns
{Object}You might also be interested in these projects:
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Please read the contributing guide for advice on opening issues, pull requests, and coding standards.
(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)
To generate the readme, run the following command:
$ npm install -g verbose/verb#dev verb-generate-readme && verb
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
$ npm install && npm test
Jon Schlinkert
Copyright © 2017, Jon Schlinkert. Released under the MIT License.
This file was generated by verb-generate-readme, v0.6.0, on September 04, 2017.
FAQs
Utils for handlebars helpers. Externalized from handlebars, to allow helpers to use the utils without having to depend on handlebars itself.
The npm package handlebars-utils receives a total of 280,625 weekly downloads. As such, handlebars-utils popularity was classified as popular.
We found that handlebars-utils demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.