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

@kimzuni/templify

v1.3.0

Published

Flexible template string processor for JavaScript and TypeScript.

Readme

@kimzuni/templify

CI Release NPM version

Flexible template string processor for JavaScript and TypeScript.

Supports customizable template delimiters, spacing rules, and fallback values. Supports both ESM and CommonJS.

Installation

# npm
npm install @kimzuni/templify

# yarn
yarn add @kimzuni/templify

# bun
bun add @kimzuni/templify

Example

const { compile } = require("@kimzuni/templify");

const template = "{key1} {key1 } { key2} {key1}";
const options = { key: /[a-zA-Z0-9_-]+/, open: "{", close: "}", spacing: -1, fallback: undefined };
const data = { key1: "value1", key3: "value3" };

const c = compile(template, options);

console.log( c.keys() );
// ["key1", "key2"]

console.log( c.matches() );
// ["{key1}", "{key1 }", "{ key2}"]

console.log( c.groups() );
/*
{
	key1: ["{key1}", "{key1 }"],
	key2: ["{ key2}"],
}
*/

console.log( c.render(data) );
// "value1 value1 { key2} value1"

with array

const { compile } = require("@kimzuni/templify");

const template = "{0} {1} {2} {1}";
const data = ["item1", "item2"];

const c = compile(template);

console.log( c.render(data) );
// "item1 item2 {2} item2"

without compile

const { keys, matches, groups, render } = require("@kimzuni/templify");

console.log( keys(template, options) );
console.log( matches(template, options) );
console.log( groups(template, options) );
console.log( render(template, data, options) );

Options

All options are optional.

key

Regex pattern defining valid characters for placeholder keys. This controls what is allowed between the opening and closing delimiters.

| Type | Default value | |--------------------|---------------| | string, RegExp | /\w+/ |

const template = "{ key } { key1 }";
const data = { key: "value", key1: "value1" };
const options = { key: /[a-z]+/ };

const result = render(template, data, options);
console.log(result); // "value { key1 }"

open/close

Custom delimiters for placeholders. The open string marks the start, and close marks the end of a placeholder in the template.

| key | Type | Default value | |-------|----------|---------------| | open | string | "{" | | close | string | "}" |

const template = "{{ key1 }} { key1 }";
const data = { key1: "value1" };
const options = { open: "{{", close: "}}" };

const result = render(template, data, options);
console.log(result); // "value1 { key1 }"

spacing

Controls how whitespace inside placeholders is handled.

| key | Type | Default value | Info | |--------|----------------------|---------------|-----------------------------------------------------------------| | strict | boolean | false | Requires the number of spaces on both sides to be exactly equal | | size | number, number[] | -1 | Specifies the allowed number of spaces |

const template = "{key1} { key1 } {  key1  } {   key1   } {   key1 }";
const data = { key1: "value1" };

console.log(render(template, data, {
	spacing: -1,
}));
// "value1 value1 value1 value1 value1"

console.log(render(template, data, {
	spacing: {
		size: -1,
	},
}));
// "value1 value1 value1 value1 value1"

console.log(render(template, data, {
	spacing: {
		size: 1,
	},
}));
// "{key1} value1 {  key1  } {   key1   } {   key1 }"

console.log(render(template, data, {
	spacing: {
		size: [1, 3],
	},
}));
// "{key1} value1 {  key1  } value1 value1"

console.log(render(template, data, {
	spacing: {
		strict: true,
		size: 1,
	},
}));
// "{key1} value1 {  key1  } value1 {   key1 }"

fallback

Value to use when a placeholder key is missing in the provided data. If not set, the placeholder remains unchanged.

| Type | Default value | |----------------------------------------------------|---------------| | string, number, boolean, null, undefined | undefined |

const template = "{key1} { key1 } {  key1  } {   key1   } {   key1 }";
const data = { key1: "value1" };

console.log(render(template, data, {
	fallback: undefined,
}));
// "{key1} value1 {  key1  } {   key1   } {   key1 }"

console.log(render(template, data, {
	fallback: "x",
}));
// "x value1 x x x"

console.log(render(template, data, {
	fallback: null,
}));
// "null value1 null null null"

Override Options

Options used to override compile options during rendering.

Support Options:

const { compile } = require("@kimzuni/templify");

const template = "{ key1 }/{ key2 }/{ key3 }";
const options = { fallback: "fallback" };
const data = { key1: "value1", key3: "value3" };

const c = compile(template, options);

console.log( c.render(data) );
// "value1/fallback/value3"

console.log( c.render(data, { fallback: undefined }) );
// "value1/{ key2 }/value3"

console.log( c.render(data, { fallback: "x" }) );
// "value1/x/value3"

console.log( c.render(data, { fallback: null }) );
// "value1/null/value3"