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

handlebars-ramda-helpers

v1.7.0

Published

Provide powerful data processing capabilities for handlebars, by adding the ramda function as helpers.

Downloads

8,546

Readme

handlebars-ramda-helpers

version downloads license dependencies coveralls

Provide powerful data processing capabilities for handlebars, by adding the ramda function as helpers.

Usage

Adding r__ before the ramda function name is the handlebars helpers name. Let see an example:

import * as Handlebars from 'handlebars'
import * as HandlebarsRamdaHelpers from 'handlebars-ramda-helpers'

// register helpers before compile
HandlebarsRamdaHelpers.register(Handlebars)


const view = {
  books: [
    { type: 'computer', name: 'C Primer Plus', price: 10 },
    { type: 'computer', name: 'An Introduction to Programming in Go', price: 20 },
    { type: 'computer', name: 'Javascript the definitive guide', price: 100 },
    { type: 'comic', name: 'One Piece', price: 100 },
  ]
}

const template = `
I have a lot of books:

{{~r__define 'divide' (r__compose (r__join '')  (r__repeat '-'))}}

{{r__padRight 40 ' ' 'bookName'}} | bookPrice
{{divide 40}} | {{divide 10}}
{{#each books}}
{{r__padRight 40 ' ' name}} | {{r__padRight 10 ' ' price}}
{{/each}}

{{r__define 'priceList' (r__pluck 'price' books)}}
The total value of these books is approx {{r__sum priceList}}.

I have {{r__count (r__propEq 'type' 'comic') books}} comic books and {{r__count (r__propEq 'type' 'computer') books}} computer books.
`


Handlebars.compile(template)(view)

The Output:

I have a lot of books:

bookName                                 | bookPrice
---------------------------------------- | ----------
C Primer Plus                            | 10
An Introduction to Programming in Go     | 20
Javascript the definitive guide          | 100
One Piece                                | 100


The total value of these books is approx 230.

I have 1 comic books and 3 computer books.

For more functions, please see Ramda Doc.

Extension

In order to facilitate the use of ramda in handlebars, some extension functions have been added.

Helpers

name | description :-----------------|:--------------------------- r__define | Define a variable on context {{r__define "variableName" "variableValue"}} r__Array | Create an array {{r__Array "0" "1" "2"}} r__Object | Create an object {{r__Object "key1"="value1" "key2"="value2"}} r__isObject | R.is(Object) r__isNumber | R.is(Number) r__isString | R.is(String) r__isArray | R.is(Array) r__isFunction | R.is(Function) r__isBoolean | R.is(Boolean) r__isTrue | R.identical(R.T()) r__isFalse | R.identical(R.F()) r__allIs | R.useWith(R.all, [R.is, R.identity]) r__allIsObject | R.all(R.is(Object)) r__allIsNumber | R.all(R.is(Number)) r__allIsString | R.all(R.is(String)) r__allIsArray | R.all(R.is(Array)) r__allIsFunction | R.all(R.is(Function)) r__allIsBoolean | R.all(R.is(Boolean)) r__allIsTrue | R.all(R.identical(R.T())) r__allIsFalse | R.all(R.identical(R.F())) r__padLeft | R.curry((fillString, maxLength, str) => String(str).padStart(maxLength, fillString)) r__padRight | R.curry((fillString, maxLength, str) => String(str).padEnd(maxLength, fillString)) r__notEquals | R.complement(R.equals) r__pathNotEq | R.complement(R.pathEq) r__propNotEq | R.complement(R.propEq)

If a function was defined by {{r__define "fn" (r__equals "example")}}, the fn should be used like an helper, rather than a variable.

Error: {{r__all fn (r__Array "example" "example")}}

Correct:{{r__all (fn) (r__Array "example" "example")}}

Block Helpers

name | description :-----------------|:--------------------------- r__define | Define a variable on context {{#r__define "variableName"}}"variableValue"{{/r__define}} r__toUpper | R.toUpper r__toLower | R.toLower r__trim | R.trim

All block helpers can use as non-block helper

Contributing & Development

If there is any doubt, it is very welcome to discuss the issue together. Please read Contributor Covenant Code of Conduct and CONTRIBUTING.