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 🙏

© 2025 – Pkg Stats / Ryan Hefner

handlespy

v1.0.0

Published

A Node.js library to inspect the required variables in a handlebars template

Downloads

24

Readme

Handlespy

Handlespy is a simple Node.js library to inspect Handlebars templates for required variables. This is accomplished by iterating over the AST produced by the handlebars parser.

It also provides a helper to verify that a payload contains all required variables.

Installation

npm install handlespy
# or
yarn add handlespy

Usage

const { getRequiredVariables, getMissingVariables } = require('handlespy')

const template = `
A simple handlebar template containing a variable ({{someVariable}}) and a loop :

{{#each someLoop}}
- {{someProperty}}
{{/each}}
`

const requiredVariables = getRequiredVariables(template)
/*
[
  'someVariable',
  { loopVariable: 'someLoop', properties: [ 'someProperty' ] }
]
*/

const completePayload = {
  someVariable: 'Test',
  someLoop: [{ someProperty: 'Another test' }]
}

const incompletePayload = {
  // missing someVariable,
  someLoop: [
    { someProperty: 'Another test' },
    { unsupportedProperty: 'Final test' }, // someLoop[1] is missing the required someProperty
  ]
}

const test1 = getMissingVariables(completePayload, requiredVariables)
// []
const test2 = getMissingVariables(incompletePayload, requiredVariables)
/*
[ 'someVariable', 'someLoop[1].someProperty' ]
*/

API

getRequiredVariables

  • expects : (String) A handlebars template
  • returns : (Array) The required variables

Each item in the returned array can either be a string (denoting a simple variable), or an object (denoting an each loop) containing the following :

  • loopVariable (String) : the name of the variable
  • properties (Array) : the required properties on the looped variable
    • loops can be nested, so properties can contain another object with loopVariable and properties
    • if only this is used in the loop, properties is an empty array

getMissingVariables

  • expects :
    • (Object) The payload to check
    • One of the following :
      • (String) A handlebars template
      • (Array) or a required variables specification as returned by getRequiredVariables
  • returns : (Array) The missing variables

Each item in the returned array is a string, which can be of either of the following formats :

  • missingVariable : variable is missing in the payload
  • missingArray[] : a variable, which is used in an each loop, is present in the payload but isn't an array
  • item[2].missingProperty : an item in an array is missing a required properties

Contributing

If you find any bug or missing functionality in handlespy, don't hesitate to create an issue ! If you can provide a PR with a failing test, this would help greatly in solving the issue :)


Made with 💖 @ comet