New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

handlepers

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

handlepers

A small collection of useful helpers for Handlebars.js and express-hbs

  • 0.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Handlepers

A small collection of usefull helpers collection for express-hbs and Handlebars.js.

Forked from danharper/Handlebars-Helpers

To use, just include helpers.js after you include Handlebars. Or, if you're using AMD/Node, just require the file.

Provided Helpers

Comparisons

Given one argument, is acts exactly like if:

{{#is x}} ... {{else}} ... {{/is}}

Given two arguments, is compares the two are equal (a non-strict, == comparison, so 5 == '5' is true)

{{#is x y}} ... {{else}} ... {{/is}}

Given three arguments, the second argument becomes the comparator.

{{#is x "not" y}} ... {{else}} ... {{/is}}
{{#is 5 ">=" 2}} ... {{else}} ... {{/is}}

Several comparators are built-in:

  • == (same as not providing a comparator)
  • !=
  • not (alias for !=)
  • ===
  • !==
  • >
  • >=
  • <
  • <=
  • in (check a value exists in either a comma-separated string, or an array, see below)
// Loose equality checking
{{#is x y}} ... {{else}} ... {{/is}}
{{#is x "==" y}} ... {{else}} ... {{/is}}

{{#is x "!=" y}} ... {{else}} ... {{/is}}
{{#is x "not" y}} ... {{else}} ... {{/is}}

// Strict equality checking
{{#is x "===" y}} ... {{else}} ... {{/is}}
{{#is x "!==" y}} ... {{else}} ... {{/is}}

// Greater/Less Than
{{#is x ">" y}} ... {{else}} ... {{/is}}
{{#is x ">=" y}} ... {{else}} ... {{/is}}

{{#is x "<" y}} ... {{else}} ... {{/is}}
{{#is x "<=" y}} ... {{else}} ... {{/is}}

// In comma separated list, or array
{{#is x "in" "foo,bar"}} ... {{else}} ... {{/is}}
{{#is x "in" anArray}} ... {{else}} ... {{/is}}
Registering Custom is comparators

You can extend the provided comparators by registering your own, like so:

// in browser
HandlebarsHelpersRegistry.add('same', function (left, right) { return left === right; });

// with AMD/Node
var HandlebarsHelpersRegistry = require('path/to/helpers');
HandlebarsHelpersRegistry.add('same', function (left, right) { return left === right; });

// usage
var template = '{{#is x "same" y}} Are the same {{else}} Not the same {{/is}}';
Handlebars.compile(template)({ x: 5, y: '5' }); // => " Not the same "

With

You can change context of the block

{{#with newContext}} ... {{/with}}
// or
{{#with newContextVar=oldContextVar}} ... {{/with}}
// or both
{{#with newContext var1=oldVar1 var2=oldVar2}} ... {{/with}}

Switch

Returns value, that matches one of hash key or default value

{{switch conditionVar X='val1' Y=var1 default='default value'}}

Logging

Log one or multiple values to the console:

{{log foo bar}}

Log one or multiple values to the console, with the current context:

{{debug foo bar}}

nl2br

Convert new lines (\r\n, \n\r, \r, \n) to line breaks

{{nl2br description}}

=======

Keywords

FAQs

Package last updated on 22 Apr 2014

Did you know?

Socket

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.

Install

Related posts

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