Utils for handlebars helpers. Externalized from handlebars, to allow helpers to use the utils without having to depend on handlebars itself.
Installations
npm install handlebars-utils
Score
98.7
Supply Chain
99.5
Quality
75.5
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Developer
helpers
Developer Guide
Module System
CommonJS
Min. Node Version
>=0.10.0
Typescript Support
No
Node Version
9.1.0
NPM Version
5.5.1
Statistics
7 Stars
29 Commits
5 Forks
3 Watching
1 Branches
3 Contributors
Updated on 03 Jul 2020
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
53,845,674
Last day
0.4%
54,919
Compared to previous day
Last week
2.2%
308,334
Compared to previous week
Last month
5.2%
1,320,153
Compared to previous month
Last year
11.4%
14,266,703
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
2
Dev Dependencies
3
handlebars-utils
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
Install with npm:
1$ npm install --save handlebars-utils
Usage
1var utils = require('handlebars-utils');
API
.isBlock
Returns true if a helper is a block helper.
Params
options
{Object}: Helper options objectreturns
{Boolean}
Example
1Handlebars.registerHelper('example', function(options) {
2 if (utils.isBlock(options)) {
3 // do something if this is a block helper
4 } else {
5 // do something else if this is a not block helper
6 }
7});
.fn
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
1Handlebars.registerHelper('example', function(val, locals, options) {
2 return utils.fn(val, locals, options);
3});
.inverse
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
1Handlebars.registerHelper('example', function(val, locals, options) {
2 return utils.inverse(val, locals, options);
3});
.value
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
1Handlebars.registerHelper('example', function(val, locals, options) {
2 return utils.value(val, locals, options);
3});
.isOptions
Returns true if the given value is a handlebar options
object.
Params
val
{Object}returns
{Boolean}
Example
1Handlebars.registerHelper('example', function(val, locals, options) {
2 if (utils.isOptions(locals)) {
3 options = locals;
4 locals = {};
5 }
6 // do stuff
7});
.isUndefined
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
1Handlebars.registerHelper('example', function(val, options) {
2 if (utils.isUndefined(val)) {
3 return '';
4 }
5 // do stuff
6});
.isApp
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
1Handlebars.registerHelper('example', function(val, options) {
2 var context = options.hash;
3 if (utils.isApp(this)) {
4 context = Object.assign({}, this.context, context);
5 }
6 // do stuff
7});
.options
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}
.context
Get the context to use for rendering.
Params
thisArg
{Object}: Optional invocation contextthis
returns
{Object}
.isObject
Returns true if the given value is an object.
Params
val
{Object}returns
{Boolean}
Example
1console.log(utils.isObject(null)); 2//=> false 3console.log(utils.isObject([])); 4//=> false 5console.log(utils.isObject(function() {})); 6//=> false 7console.log(utils.isObject({})); 8//=> true
.isEmpty
Returns true if the given value is "empty".
Params
value
{any}returns
{Boolean}
Example
1console.log(utils.isEmpty(0)); 2//=> false 3console.log(utils.isEmpty('')); 4//=> true 5console.log(utils.isEmpty([])); 6//=> true 7console.log(utils.isEmpty({})); 8//=> true
.result
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
1console.log(utils.result('foo')); 2//=> 'foo' 3console.log(utils.result(function() { 4 return 'foo'; 5})); 6//=> 'foo'
.identity
Returns the given value as-is, unchanged.
Params
val
{any}returns
{any}
Example
1console.log(utils.result('foo')); 2//=> 'foo' 3console.log(utils.result(function() { 4 return 'foo'; 5})); 6//=> [function]
.isString
Return true if val
is a non-empty string.
Params
val
{any}: The value to checkreturns
{Boolean}
.arrayify
Cast the given val
to an array.
Params
val
{any}returns
{Array}
Example
1console.log(utils.arrayify('')); 2//=> [] 3console.log(utils.arrayify('foo')); 4//=> ['foo'] 5console.log(utils.arrayify(['foo'])); 6//=> ['foo']
.tryParse
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}
About
Related projects
You might also be interested in these projects:
- assemble: Get the rocks out of your socks! Assemble makes you fast at creating web projects… more | homepage
- handlebars-helpers: More than 130 Handlebars helpers in ~20 categories. Helpers can be used with Assemble, Generate… more | homepage
- template-helpers: Generic JavaScript helpers that can be used with any template engine. Handlebars, Lo-Dash, Underscore, or… more | homepage
- templates: System for creating and managing template collections, and rendering templates with any node.js template engine… more | homepage
Contributing
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.
Building docs
(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:
1$ npm install -g verbose/verb#dev verb-generate-readme && verb
Running tests
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:
1$ npm install && npm test
Author
Jon Schlinkert
License
Copyright © 2017, Jon Schlinkert. Released under the MIT License.
This file was generated by verb-generate-readme, v0.6.0, on September 04, 2017.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
security policy file detected
Details
- Info: security policy file detected: github.com/helpers/.github/SECURITY.md:1
- Info: Found linked content: github.com/helpers/.github/SECURITY.md:1
- Info: Found disclosure, vulnerability, and/or timelines in security policy: github.com/helpers/.github/SECURITY.md:1
- Info: Found text in security policy: github.com/helpers/.github/SECURITY.md:1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 1/28 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 2 are checked with a SAST tool
Score
3.9
/10
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to handlebars-utils
handlebars
Handlebars provides the power necessary to let you build semantic templates effectively with no frustration
@budibase/handlebars-helpers
More than 130 Handlebars helpers in ~20 categories. Helpers can be used with Assemble, Generate, Verb, Ghost, gulp-handlebars, grunt-handlebars, consolidate, or any node.js/Handlebars project.
handlebars-helpers
More than 130 Handlebars helpers in ~20 categories. Helpers can be used with Assemble, Generate, Verb, Ghost, gulp-handlebars, grunt-handlebars, consolidate, or any node.js/Handlebars project.
@transcend-io/handlebars-utils
Utility functions for handlebars templating with Transcend - available in node and client side.