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

ft-next-handlebars

v1.3.3

Published

Enhanced handlebars for use in next applications

Downloads

3

Readme

next-handlebars

Enhanced handlebars for use in next applications

Express applications

require('ft-next-handlebars')(app, options)

Where options may have the following properties

  • directory: String - absolute path to the current application's working directory REQUIRED
  • partialsDir: Array of directories containing partials. This is concatenated to the default value of ./bower_components/
  • layoutsDir: String - the directory in which express-handlebars layouts are contained
  • defaultLayout: Name of the default layout to use. Defaults to false
  • helpers: Map of custom helpers to add to handlebars (see below for a list those included by default)
  • viewsDirectory: String - subdirectory where the application's views are stored (default /views)

Returns a promise which resolves when all partials in the supplied directories have been registered

To use the express-handlebars instance by itself (occassionally useful for consuming templates from bower_components outside of the context of an express app) use require('ft-next-handlebars').standalone(options)

A handlebars instance with all next helpers, but without partials, is also exposed at require('ft-next-handlebars').handlebars;

Client side javascript

require('next-handlebars')(options)

Where options may have the following properties

  • helpers: Map of custom helpers to add to handlebars (see below for a list those included by default)

Returns a handlebars instance

Other server side applications

Should you need to use handlebars with all the next helpers but without next-express use require('ft-next-handlebars').handlebars(options), which has the same API a the client side module

THE HELPERS

Inheritance helpers

Block inheritance

This is achieved by means of two helpers:

  • outputBlock used in the parent template to indicate where content should be output. Can also define default content
  • defineBlock used in the child template to define the desired output to insert into the block
// parent.html
<header>thing</header>
{{#outputBlock 'my-block'}}default content{{/outputBlock}}
<footer>thing</footer>

// child.html
{{#defineBlock 'my-block'}}
	Mustaches to process: {{someVar}}
{{/defineBlock}}
{{> parent}}

usePartial

Allows a partial to be selected based on the value of a variable

  • {{{usePartial 'path/to/partial'}}} Note a '>' is not required in the path and you will normally need triple mustaches

Content helpers

dateformat

Outputting date objects as strings

  • {{#dateformat}}{{ a date object }}{{/dateformat}} outputs an isoString
  • {{#dateformat "dddd, d mmmm, yyyy"}}{{ a date object }}{{/dateformat}} outputs the date formatted as 'Tuesday, 3 February, 2014'

encode

Encoding strings to be output safely in html

  • {{encode q mode='uriComponent'}} outputs the result of encodeURIComponent(q) ({{encode q }} will also do this)
  • {{encode q mode='uri'}} outputs the result of encodeURI(q)

topicUrl

Takes a topic identifier (currently something like topic:"European%20Cars") and converts to a next stream url /stream/topic/European%20Cars

  • {{topicUrl searchString}}

paragraphs

Outputting some paragraphs from a larger chunk of html, zero indexed

  • {{{paragraphs body start=0 end=1}}} will output the first paragraph of body. Note the triple mustaches

removeImageTags

Strips all image tags from a chunk of html

  • {{{removeImageTags body}}} Note the triple mustaches

resize

Replaces an image url with an image service url, serving an appropriately resized image

  • {{#resize 200}}http://images.com/pic.jpg{{/resize}}

json

Outputs an object as json.

  • {{json obj}} - for use within data attributes and elsewhere in html (will convert '"' to '"' etc..)
  • {{{json obj}}} - for outputting the json unencoded

decodeHtmlEntities

Decodes a (very limited) safe list* of HTML entities into their respective characters (* = not &, <, >, ", ' or ``)

  • {{decodeHtmlEntities 'lorem&nbsp;ipsum&nbsp;dolar'}} outputs lorem ipsum dolar

Logic helpers

ifEquals

Outputs contents if a thing is equal to a value

  • {{#ifEquals thing 'value'}} some content {{else}} some fallback content {{/ifEquals}}

ifAll

Outputs contents if a number of things are truthy Note that handlebars has a slightly odd understanding of truthiness

  • {{#ifAll thing1 thing2 thing3}} some content {{else}} some fallback content {{/ifAll}}

ifSome

Outputs contents if at least one of a number of things is truthy Note that handlebars has a slightly odd understanding of truthiness

  • {{#ifSome thing1 thing2 thing3}} some content {{else}} some fallback content {{/ifSome}}

Iteration helpers

slice

Loop through a subset of items

  • `{{#slice items limit="2" offset="4"}} some content {{/slice}}