handlebars-subexpression-helpers
Advanced tools
Comparing version 1.0.1 to 1.0.2
{ | ||
"name": "handlebars-subexpression-helpers", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Some simple yet useful subexpression helpers for handlebars", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# handlebars-subexpression-helpers | ||
Some useful helpers for handlebars | ||
Readme coming soon. | ||
Some simple yet useful subexpression helpers for handlebars | ||
From the Handlebars docs: | ||
<blockquote>Handlebars offers support for subexpressions, which allows you to invoke multiple helpers within a single mustache, and pass in the results of inner helper invocations as arguments to outer helpers. Subexpressions are delimited by parentheses.</blockquote> | ||
``` | ||
{{outer-helper (inner-helper 'abc') 'def'}} | ||
``` | ||
<blockquote>In this case, inner-helper will get invoked with the string argument 'abc', and whatever the inner-helper function returns will get passed in as the first argument to outer-helper (and 'def' will get passed in as the second argument to outer-helper.</blockquote> | ||
To make your life easier I created a set of simple and useful helpers for Handlebars which can exclusively be used as subexpression-helpers. | ||
## Usage | ||
### Node.js | ||
`npm install handlebars-subexpression-helpers` | ||
Then you just need to `require` the module and pass your Handlebars instance to the `.register()` method: | ||
``` | ||
var Handlebars = require('handlebars'); | ||
require('handlebars-subexpression-helpers').register(Handlebars); | ||
``` | ||
Done. Now you can use all of the included helpers. | ||
`<p>Manuel – Status: {{#if (isEqual user.status 'unconfirmed') }} Not yet activated {{else}} Active {{/if}}</p>` | ||
If you don't need all helpers you can also require single helpers. All of them export a `register()` method which expect your Handlebars instance to be passed: | ||
``` | ||
var Handlebars = require('handlebars'); | ||
require("handlebars-subexpression-helpers/dist/lib/helpers/is-array").register(Handlebars); | ||
require("handlebars-subexpression-helpers/dist/lib/helpers/typeof").register(Handlebars); | ||
``` | ||
## List of helpers | ||
For a complete list, have a look at <a href="dist/lib/helpers">dist/lib/helpers</a>. | ||
While the filename is separated by dashes, the helper name itself is camelCase. So `is-array.js` can be used as `isArray` for example. |
@@ -9,3 +9,3 @@ import assert from "assert"; | ||
it('should all be true', (done) => { | ||
it('should return true if all given values are truthy', (done) => { | ||
@@ -24,3 +24,3 @@ let source = '{{#if (and true true true)}}passed{{/if}}'; | ||
it('should all be true', (done) => { | ||
it('should return true if all given values are truthy', (done) => { | ||
@@ -39,3 +39,3 @@ let source = '{{#if (and true (not false) true)}}passed{{/if}}'; | ||
it('should work with strings', (done) => { | ||
it('should return true if all given values are truthy', (done) => { | ||
@@ -42,0 +42,0 @@ let source = '{{#if (and true "pass")}}passed{{/if}}'; |
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
31207
51
667
47
6