npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hbl-comparison

v0.1.0

Published

A helper for Handlebars that adds comparison functions.

Downloads

4

Readme

hbl-comparison

A helper for Handlebars that adds comparison functions. Meant to supercede helpers/handlebars-helpers' comparison helpers.

Usage

const Handlebars = require('handlebars');
require('hbl-comparison').default();

const tpl = Handlebars.compile('{{#lt 2 4}}Tiny number.{{else}}Big number.{{/lt}}');
console.log(tpl()); // result : 'Tiny number.' 

Package documentation

{{#and a b }}

If both a and b are true, the block is rendered. Otherwise, the inverse is rendered.

Usage :

<!-- great: true, magnifice: true -->
{{#and great magnifice }}
A
{{else}}
B
{{/and}}

Result : A

{{#compare a op b }}

Compares a and b with an operator. If the result is true, the block is rendered. Otherwise, the inverse is rendered.

The operator must be a string (enclose in strings). The conventional operators are supported : >, >=, ==, ===, !=, !==, <=, <. typeof is also supported, where a is checked to be the typeof b.

Usage :

{{#compare 2 != 2}}
A
{{else}}
B
{{/compare}}

Result : B

{{#contains array value }}

Checks if an array contains a value. If it does, the block is rendered. Otherwise, the inverse is rendered.

Usage :

{{#contains ['a','b','c'] "d" }}
A
{{else}}
B
{{/contains}}

Result : B

{{ default value defaultValue }}

Checks if a value is undefined. If it is, the defaultValue is rendered — otherwise, the value is.

Usage : {{ default apple "Whoops, I forgot to define something" }}

Result : Whoops, I forgot to define something

{{#eq a b }}

Checks if a === b. If the result is true, the block is rendered. Otherwise, the inverse is rendered.

Usage :

{{#eq 2 2}}
A
{{else}}
B
{{/eq}}

Result : A

{{#gt a b }}

Checks if a > b. If the result is true, the block is rendered. Otherwise, the inverse is rendered.

Usage :

{{#gt 2 2}}
A
{{else}}
B
{{/gt}}

Result : B

{{#gte a b }}

Checks if a >= b. If the result is true, the block is rendered. Otherwise, the inverse is rendered.

Usage :

{{#gte 2 2}}
A
{{else}}
B
{{/gte}}

Result : A

{{#has "a b" }}

Checks if an array has a pattern. If it does, the block is rendered. Otherwise, the inverse is rendered.

Usage :

<!-- context: 'CCC' -->
{{#has context "C"}}
A
{{else}}
B
{{/has}}

Result : A

{{#ifEven num }}

Checks if num is even. If it is, the block is rendered. Otherwise, the inverse is rendered.

Usage :

{{#ifEven 2 }}
A
{{else}}
B
{{/ifEven}}

Result : A

{{#ifNth a b }}

Checks if a is divisible by b evenly (no remainder). If it is, the block is rendered. Otherwise, the inverse is rendered.

Usage :

{{#ifNth 4 2 }}
A
{{else}}
B
{{/ifNth}}

Result : A

{{#ifOdd num }}

Checks if num is odd. If it is, the block is rendered. Otherwise, the inverse is rendered.

Usage :

{{#ifOdd 2 }}
A
{{else}}
B
{{/ifOdd}}

Result : B

{{#is a b }}

Checks if a == b. If it is, the block is rendered. Otherwise, the inverse is rendered.

Usage :

{{#is 2 3 }}
A
{{else}}
B
{{/is}}

Result : B

{{ isFalsey val }}

Checks if val is false. If it is, the block is rendered. Otherwise, the inverse is rendered.

Usage : {{ isFalsey false }}

Result : true

{{#isnt a b }}

Checks if a != b. If it is, the block is rendered. Otherwise, the inverse is rendered.

Usage :

{{#isnt 2 3 }}
A
{{else}}
B
{{/isnt}}

Result : A

{{ isTruthy val }}

Checks if val is true. If it is, the block is rendered. Otherwise, the inverse is rendered.

Usage : {{ isTruthy false }}

Result : false

{{#lt a b }}

Checks if a < b. If the result is true, the block is rendered. Otherwise, the inverse is rendered.

Usage :

{{#lt 2 2}}
A
{{else}}
B
{{/lt}}

Result : B

{{#lte a b }}

Checks if a <= b. If the result is true, the block is rendered. Otherwise, the inverse is rendered.

Usage :

{{#lte 2 2}}
A
{{else}}
B
{{/lte}}

Result : A

{{#neither a b }}

Checks if a and b are false. If it is, the block is rendered. Otherwise, the inverse is rendered.

Usage :

{{#neither false true }}
A
{{else}}
B
{{/neither}}

Result : B

{{ not val }}

Checks if val is false. If it is, the block is rendered. Otherwise, the inverse is rendered.

Usage : {{ not false }}

Result : true

{{#or a b }}

If either a or b are true, the block is rendered. Otherwise, the inverse is rendered.

Usage :

<!-- great: true -->
{{#or great false }}
A
{{else}}
B
{{/or}}

Result : A

{{#unlessEq a b }}

Checks if a !== b. If the result is true, the block is rendered. Otherwise, the inverse is rendered.

Usage :

{{#unlessEq 2 2}}
A
{{else}}
B
{{/unlessEq}}

Result : B

{{#unlessGt a b }}

Checks if a <= b. If the result is true, the block is rendered. Otherwise, the inverse is rendered.

Usage :

{{#unlessGt 2 2}}
A
{{else}}
B
{{/unlessEq}}

Result : B

{{#unlessGteq a b }}

Checks if a < b. If the result is true, the block is rendered. Otherwise, the inverse is rendered.

Usage :

{{#unlessEq 2 2}}
A
{{else}}
B
{{/unlessEq}}

Result : A

{{#unlessLt a b }}

Checks if a >= b. If the result is true, the block is rendered. Otherwise, the inverse is rendered.

Usage :

{{#unlessEq 2 2}}
A
{{else}}
B
{{/unlessEq}}

Result : B

{{#unlessLteq a b }}

Checks if a > b. If the result is true, the block is rendered. Otherwise, the inverse is rendered.

Usage :

{{#unlessEq 2 2}}
A
{{else}}
B
{{/unlessEq}}

Result : A

Acknowledgements

This package is licensed under the 3-Clause BSD licence. A copy of it can be found in the LICENSE file in the root of the source repository and in the root of the package directory.