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 🙏

© 2026 – Pkg Stats / Ryan Hefner

metalsmith-interpolate

v0.1.2

Published

metalsmith helper to interpolate strings

Readme

metalsmith-interpolate

nodei.co

npm

github-issues

stars

forks

metalsmith helper to interpolate strings

install

npm i --save metalsmith-interpolate

usage

metalsmith-interpolate is not a plugin, it's a module designed to be used within plugins to provide a consistent interpolation API.

Suppose you made a plugin to generate a coverImage property for each article

import {
  each,
  keys
} from 'lodash'
import metalsmith from 'metalsmith'
import interpolate from 'metalsmith-interpolate'

metalsmith()
...
.use((files, metalsmith, done) => {
  each(multimatch(keys(files), 'articles/**.*'), (src) => {
    files[src].coverImage = interpolate('images/{name}.jpg', src, files)
  })
})
.build()

tokens

tokens from path

properties returned by path.parse:

┌─────────────────────┬────────────┐
│          dir        │    base    │
├──────┬              ├──────┬─────┤
│ root │              │ name │ ext │
"  /    home/user/dir / file  .txt "
└──────┴──────────────┴──────┴─────┘
  • {base} name & ext
  • {name}
  • {ext} includes the . in .txt
  • {dir} path from src directory

tokens from meta

any properties from the metalsmith files structure can be used as tokens

tokens from moment

basically any format tokens from moment including only characters defined by /[MDY\-_\.\/]/. So {YYYY/MMMM} returns 2016/October or whatever.

If a date field is set in a file's frontmatter, then that value will be used, otherwise ctime (file created time) is used instead. Note that moment can only parse dates formatted in limited ways.

custom tokens

simple value tokens

You can add multiple objects to the interpolate arguments to make those properties available as tokens.

metalsmith()
...
.use((files, metalsmith, done) => {
  each(multimatch(keys(files), 'articles/**.*'), (src) => {
    let dimensions = {
      width: 200,
      height: 300
    }
    files[src].coverImage = interpolate(
      'images/{name}_{width}_{height}.jpg',
      src,
      files,
      dimensions
    )
  })
})
.build()

calculated value tokens

You can also add custom a custom resolver function

import { interpolate, resolvers } from 'metalsmith-interpolate'

resolvers.unshift((token, meta) => if (token == 'firstTag') return meta.tags[0])

metalsmith()
...
.use((files, metalsmith, done) => {
  each(multimatch(keys(files), 'articles/**.*'), (src) => {
    files[src].title = interpolate('{title} ({firstTag})', src, files)
  })
})
.build()

The meta argument passed to resolvers contains meta from metalsmith files structure, plus path property, plus any additional properties you passed in.

The first resolver in the array which returns either a truthy value or an 0 length string will be substituted for a given token.

slugify on the fly

prefix a token with - or _ like {-title} to slugify the token's value.

compatibility

dist/index.js is fully compatible with node 6.3.1

dist/node4/index.js is compatible with node 4 LTS, require it like so: var mimeType = require('metalsmith-interpolate/dist/node4')

Author

Levi Wheatcroft [email protected]

Contributing

Contributions welcome; Please submit all pull requests against the master branch.

License

MIT