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

erb

v1.3.3

Published

Compile a given Embedded RuBy (ERB) template using variables and functions defined in given a JavaScript object

Downloads

49,056

Readme

erb

JavaScript Style Guide Build Status

Compile a given Embedded RuBy (ERB) template using variables and functions defined in given a JavaScript object.

Installation

npm install --save erb

Usage

Executing

const erb = require('erb');

const data = {
  "fields": {
    "first": "Morty",
    "second": "Rick"
  },
  "values": {
    "additions": "with pattie, breaded and fried"
  },
  "functions": {
    "title": [
      [
        1,
        "One Chicken Fried Steak"
      ],
      [
        2,
        3,
        "Two or Three Chicken Fried Steaks"
      ]
    ]
  }
}

erb({
  timeout: 5000,
  data: data,
  template: '<%= @first %> had <%= title(1) %> <%= additions %>.\n<%= @second %> had <%= title(2, 3) %> <%= additions %>.'
}).then(console.log, console.error);

would result in

Morty had One Chicken Fried Steak with pattie, breaded and fried.
Rick had Two or Three Chicken Fried Steaks with pattie, breaded and fried.

API

erb(opts)

opts is a simple JSON object with these properties:

  • timeout (optional, integer) - number of milliseconds (defaults to 5000) to wait for the template evaluation to finish before terminating with error
  • data (optional, object) - an object that contains these properties:
    • fields (optional, object) - the keys of this object are instance variable names to be used in the ERB template and values are the values of the instance variables
    • values (optional, object) - the keys of this object are variable names to be used in the ERB template and values are the values of the variables
    • functions (optional, object) - the keys of this object are function names to be used in the ERB template and values are special arrays - the items match the function call arguments with the last item being the value returned by the function when called with these arguments.
  • template (required, string) - the ERB template to be compiled

Building

Requires Bundler.

npm run build

Contributing

  • do not do existing API-breaking changes - the test suite should remain unchanged forever, except when you add new features
  • if you do a pull request, then it must have a precise title and exactly the change the title describes - otherwise do several pull requests