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

fishbars

v0.10.2

Published

Helpers for Handlebars templates used at FishBrain

Downloads

35

Readme

Build Status Coverage Status

fishbars

Helpers for Handlebars templates used at FishBrain

Installation

npm install fishbars

Getting started

var handlebars = require("handlebars");
var fishbars = require("fishbars");

fishbars.registerHelpers(handlebars, {
  language: 'sv'
});

var template = handlebars.compile("{{translate greeting}} {{name}}");
var result = template({ name: 'jakob', greeting: { sv: 'hej', en: 'hi' } });

console.log(result); // hej jakob

Features

There is one function independent of user settings:

image

It take three arguments; a comparison operator, a size and an array of photos. It then returns the photo that satisfy the given given comparions. If more than one does, it selects the one that is closest to the requirement.

var template = handlebars.compile("{{image '>=' '64x64' photos }}");
var result = template({
    photos: photos: [{
        url: "file1.png",
        size: "140x140"
    }, {
        url: "file2.png",
        size: "600x600"
    }]
});

console.log(result); // file1.png

There are also five functions depending on user settings:

translate
weight
length
temperature
speed

Translate is used as in the "getting started"-example above. Given a string as language in registerHelpers, that key is looked up when translate is called on an object in the template. You can use any language code you want; to the function it's just a key in a lookup.

The remaining four functions are used to convert a number (given in SI-units) to a string representation in the configured unit, including the unit abbreviation. For example, getting my length in feet would go like this:

var handlebars = require("handlebars");
var fishbars = require("fishbars");

fishbars.registerHelpers(handlebars, {
  units: {
    weight: 'lb'
  }
});

var template = handlebars.compile("{{name}} is {{length myLength}} tall");
var result = template({ name: 'jakob', myLength: 1.81 }); // note that length is given in meters

console.log(result); // Jakob is 5.94 ft tall

The full configuration would look like this:

fishbars.registerHelpers(handlebars, {
  language: 'sv',
  units: {
    weight: 'kg',     // or 'lb'
    length: 'm',      // or 'ft'
    temperature: 'C', // or 'F'
    speed: 'm/s'      // or 'km/h' or 'mph' or 'kn'
  }
});

Developing

Make sure you have node installed. Running node -v should give you v0.10.29 or above.

Run npm install to install the dependencies of the project.

Run npm test to run all the tests. It will also show you the test coverage on completion.

You can run a subset of the tests using TESTS="some pattern" npm test, where the pattern is matched to the names of the tests.

In order to release a new version of the library, run make release VERSION=x.x.x. Your package file, git tags, coveralls and the global npm repository will all automatically be updated (but only if the tests pass, your working tree is clean and if you're on the right branch - master of course).