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

@xiedacon/hbs-helpers

v1.0.1

Published

Easy way to use and write handerbars helpers.

Downloads

1

Readme

hbs-helpers

Build Status JavaScript Style Guide MIT

Requirements

Node.js v8.x

Usage

const handlebars = require('handlebars')

require('@xiedacon/hbs-helpers')({
  handlebars: handlebars
})

// with local helpers
require('@xiedacon/hbs-helpers')({
  handlebars: handlebars,
  helpers: {
    greatThenThree: ([n]) => n > 3
  }
})

// with alias
require('@xiedacon/hbs-helpers')({
  handlebars: handlebars,
  aliases: {
    unlessEq: 'notEq'
    // or
    unlessEq: ['notEq']
  }
})

API

All helpers can be use as block helpers

{{#eq a 'a'}}

{{/eq}}

or inline helpers

{{#and (eq a 'a') (eq b 'b')}}
  {{dosomething}}
{{/and}}

Base

  • get

    Params:

    • obj {any}
    • path {string}
    • def {any}
    • returns {any}

    like _.get

    Example:

    // a: { a: '1' }
    {{get a 'a'}}
    // returns: ['1']
    
    // a: { a: '1' }
    {{get a 'b' '2'}}
    // returns: ['2']
  • set

    Params:

    • obj {any}
    • path {string}
    • val {any}

    like _.set

    Example:

    // a: {}
    {{set a 'a' '1'}}
    // a: { a: '1' }
  • default

    Params:

    • obj {any}
    • def {any}
    • returns {any}

    Example:

    // a: 1
    {{default a 2}}
    // returns: 1
    
    // a: undefined
    {{default a 2}}
    // returns: 2
  • and

    Params:

    • bool* {any}
    • returns {Boolean}

    Example:

    // a: 1
    // b: 2
    // c: 3
    {{#and (eq a 1) (eq b 2) c}}
      // a === 1 && b === 2 && c
    {{/and}}
  • or

    Params:

    • bool* {any}
    • returns {Boolean}

    Example:

    // a: 1
    // b: 2
    // c: 3
    {{#or (eq a 1) (eq b 2) c}}
      // a === 1 || b === 2 || c
    {{/or}}
  • isEmpty

    Params:

    • val {any}
    • returns {Boolean}

    like _.isEmpty

    Example:

    // a: { a: '1' }
    {{#isEmpty a}}
      // _.isEmpty(a)
    {{/isEmpty}}
  • eq

    Params:

    • val1 {any}
    • val2 {any}
    • returns {Boolean}

    Example:

    // a: 1
    // b: 1
    {{#eq a b}}
      // a === b
    {{/eq}}
  • unlessEq

    Params:

    • val1 {any}
    • val2 {any}
    • returns {Boolean}

    Example:

    // a: 1
    // b: 1
    {{#unlessEq a b}}
      // a !== b
    {{/unlessEq}}
  • gt

    Params:

    • val1 {any}
    • val2 {any}
    • returns {Boolean}

    Example:

    // a: 1
    // b: 1
    {{#gt a b}}
      // a > b
    {{/gt}}
  • gte

    Params:

    • val1 {any}
    • val2 {any}
    • returns {Boolean}

    Example:

    // a: 1
    // b: 1
    {{#gte a b}}
      // a >= b
    {{/gte}}
  • lt

    Params:

    • val1 {any}
    • val2 {any}
    • returns {Boolean}

    Example:

    // a: 1
    // b: 1
    {{#lt a b}}
      // a < b
    {{/lt}}
  • lte

    Params:

    • val1 {any}
    • val2 {any}
    • returns {Boolean}

    Example:

    // a: 1
    // b: 1
    {{#lte a b}}
      // a <= b
    {{/lte}}
  • is

    Params:

    • val1 {any}
    • val2 {any}
    • returns {Boolean}

    Example:

    // a: 1
    // b: 1
    {{#is a b}}
      // a == b
    {{/is}}
  • isnt

    Params:

    • val1 {any}
    • val2 {any}
    • returns {Boolean}

    Example:

    // a: 1
    // b: 1
    {{#isnt a b}}
      // a != b
    {{/isnt}}
  • not

    Params:

    • val {any}
    • returns {Boolean}

    Example:

    // a: 1
    {{#not a}}
      // !a
    {{/not}}
  • encodeURI

    Params:

    • val {String}
    • returns {String}

    When error throw, the raw value well be return

    Example:

    // a: '%'
    {{encodeURI a}} // encodeURI(a)
    // returns: '%25'  
  • decodeURI

    Params:

    • val {String}
    • returns {String}

    When error throw, the raw value well be return

    Example:

    // a: '%25'
    {{decodeURI a}} // decodeURI(a)
    // returns: '%'  
  • encodeURIComponent

    Params:

    • val {String}
    • returns {String}

    When error throw, the raw value well be return

    Example:

    // a: '?'
    {{encodeURIComponent a}} // encodeURIComponent(a)
    // returns: '%3F'
  • decodeURIComponent

    Params:

    • val {String}
    • returns {String}

    When error throw, the raw value well be return

    Example:

    // a: '%3F'
    {{decodeURIComponent a}} // decodeURIComponent(a)
    // returns: '?'

Array

Supported functions:

For iterator Array, you should use build-in helper each

Json

  • stringify

    Params:

    • obj {any}
    • returns {String}

    Example:

    // a: { a: '1' }
    {{stringify a}}
    // returns: '{"a":"1"}'

Math

  • All build-in functions on Math are support

    Example:

    // a: -1
    {{abs a}}
    // returns: 1
  • add

    Params:

    • val* {any}
    • returns {String/Number}

    Example:

    // a: 1
    // b: 2
    // c: 3
    {{add a b c}}
    // returns: 6
    
    // a: '1'
    // b: 2
    // c: 3
    {{add a b c}}
    // returns: '123'
  • subtract

    Params:

    • val* {any}
    • returns {Number}

    Example:

    // a: 6
    // b: 2
    // c: 3
    {{subtract a b c}}
    // returns: 1
  • multiply

    Params:

    • val* {any}
    • returns {Number}

    Example:

    // a: 1
    // b: 2
    // c: 3
    {{multiply a b c}}
    // returns: 6
  • divide

    Params:

    • val* {any}
    • returns {Number}

    Example:

    // a: 6
    // b: 2
    // c: 3
    {{divide a b c}}
    // returns: 1
  • avg

    Params:

    • val* {any}
    • returns {Number}

    Example:

    // a: 1
    // b: 2
    // c: 3
    {{avg a b c}}
    // returns: 2

Number

  • All build-in functions on Number and Number.prototype are support

    Example:

    // a: 1
    {{#isNaN a}}
      // Number.isNaN(a)
    {{/isNaN}}

    First argument of prototype functions must be a number or number like string

    // a: 1
    {{toFixed a 2}}
    // returns: '1.00'
  • number

    Params:

    • val {any}
    • returns {Number}

    Example:

    // a: '1'
    {{number a}}
    // returns: 1

Object

  • keys

    Params:

    • val {any}

    Example:

    // a: { a: '1' }
    {{#keys a}}
      this // current key
      @index // current index
    {{/keys}}
    
    or inline
    
    // a: { a: '1' }
    {{keys a}}
    // returns: ['a']
  • values

    Params:

    • val {any}

    Example:

    // a: { a: '1' }
    {{#values a}}
      this // current value
      @index // current index
    {{/values}}
    
    or inline
    
    // a: { a: '1' }
    {{values a}}
    // returns: ['1']
  • entries

    Params:

    • val {any}

    Example:

    // a: { a: '1' }
    {{#entries a}}
      @index // current index
      @key // current key
      @value // current value
    {{/entries}}
    
    or inline
    
    // a: { a: '1' }
    {{entries a}}
    // returns: [['a', '1']]

String

Supported functions:

All helpers can be use as block helpers or inline helpers

Never let your mind limit your imagination

License

MIT License

Copyright (c) 2017 xiedacon