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

measy

v0.4.10

Published

Create files using any template engine as simple as possible. Just a template and a JSON/YAML file is enough.

Downloads

1,141

Readme

measy

Create files using any template engine as simple as possible. Just a template and a JSON/YAML file is enough.

Usage

$ npx measy README.hbs

Install

$ npm install measy
$ yarn add measy

NOTE: If you wish to use template engines other than nunjucks or handlebars, you must install the engines you wish to use: Add them to your package.json dependencies or install globally.

Examples

CLI Example

  • Create README.md from nunjucks template using package.json data:
$ measy README.njk
  • without Front Matter, load data from package.json and foo.yaml
$ measy --context-files package.json,foo.yaml --out README.md README.njk
  • Create a text file from handlebars template:
$ measy --context '{ codeName: "Jay" }' --out last.txt member.hbs
  • Process all templates in a given directory:
$ measy --out docs my-templates
  • Get help
$ measy --help

Template Example

Templates support Front Matter data in YAML format.

README.njk, README.hbs etc.

---
contextFiles: "package.json"
targetExtension: "md"
---
# {{ package.name }}

{{ package.description }}

# Examples

...some examples

Details

measy is simple command which creates files from templates combining data from JSON or JavaScript (or TypeScript with the help of ts-node) files. JSON files are parsed using JSON5. JS files can be used by exporting an object with module.exports or export default.

Front Matter

Any template file may contain a YAML front matter block. Data is processed by measy. The front matter must be the first thing in the file and must take the form of valid YAML set between triple-dashed (---) lines. Here is a basic example:

---
contextFiles: "package.json"
rootContextFiles: ["some.json", "lib/my-data.js"]
partialDirs: ["templates/partials"]
functionFiles: "helper.js"
rootFunctionFiles: "other-helper.js"
targetExtension: "md"
---

| Name | Type | Description | | ----------------- | ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- | | contextFiles | string|string[] | js, ts, JSON5 or YAML file names or array of file names get context data for template. File name without extension is used as key in context data. | | rootContextFiles | string|string[] | js, ts, JSON5 or YAML file name or array of file names to get context data for template. Result is merged into context directly. | | targetExtension | string | If there is no out attribute, sets filename extension of output file. | | functionFiles | string|string[] |  Files to get filter/helper functions prefixed with file name. i.e "uc()" func in "path/helper.js" becomes "helperUc" helper/filter. | | rootFunctionFiles | string|string[] | Files to get filter/helper functions prefixed with file name. i.e "uc()" func in "path/helper.js" becomes "uc" helper/filter.  | | partialDirs | string|string[] | Path or array of paths relative to file to get partials from. |

Example

package.json

{
  "name": "some-module",
  "version": "1.0.0"
}
// contextFiles: "package.json"
{
  someOtherData: "Hello",
  package: {
    name: "some-module",
    version: "1.0.0"
  }
}

// rootContextFiles: "package.json"
{
  someOtherData: "Hello",
  name: "some-module",
  version: "1.0.0"
}

CLI Options

| Option Name | Description | | ----------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | --template-extension (Required) | File extension of the templates. | | --target-extension <extension> | File extension to be used in generated files. If template file has 'extension' meta data (frontmatter), extension in meta data has higher precedence. | | --out <path> | File path (for templates) or directory path (for directory input) to generate files into. Defaults to <template path>. | | --context <json5> | Data to be passed to templates. | | --context-files <paths> | js, ts, JSON5 or YAML files to get data to be passed to templates under a key same as file name. | | --root-context-files | js, ts, JSON5 or YAML files to get data to be passed to templates. | | --partial-dirs <paths csv> | Paths of directories which contains partial files. | | --function-files <paths csv> | Files to get filter/helper functions prefixed with file name. i.e "uc()" func in "path/helper.js" becomes "helperUc" helper/filter. | | --root-function-files <paths csv> | Files to get filter/helper functions prefixed with file name. i.e "uc()" func in "path/helper.js" becomes "uc" helper/filter. | | --exclude-paths <paths csv> | Paths to be excluded (for directory input only) | | --engine <engine name> | Template engine to be used. Supports engines supported by consolidate. | | --include-meta | Whether to include meta data in generated files. | | --debug | Print stack trace in errors. | | --silence | Prevent console output. |

Custom Helpers & Filters

measy allows you to use your own custom handlebars helpers and nunjucks filters.

Either export functions directly or export an object with names and functions from a JavaScript file.

You may add helpers/filters either using --root-function-files & --function-files CLI options or rootFunctionFiles & functionFiles front matter header in templates.

my-helper.js

export default {
  ucFirst: (input) => input.charAt(0).toUpperCase() + input.slice(1),
}

my-helper.js

export function ucFirst(input) {
  return input.charAt(0).toUpperCase() + input.slice(1);
}

Using Helpers/Filters with Front Matter

$ measy README.njk

README.njk

---
rootFunctionFiles: "my-helper.js"
---
Hello {{  firstName | ucFirst  }}

README.hbs

---
rootFunctionFiles: "my-helper.js"
---
Hello {{  ucFirst firstName  }}

Using Helpers/Filters with Front Matter

$ measy --root-function-files my-helper.js README.njk

README.njk

Hello {{  firstName | ucFirst  }}

README.hbs

Hello {{  ucFirst firstName  }}

Supported Template Engines

Thanks to Consolidate.js

NOTE: If you wish to use template engines other than nunjucks or handlebars, you must install the engines you wish to use: Add them to your package.json dependencies or install globally.