Skip to main content

runty

Extensible conditional string micro templates

import { runty } from 'runty';
const fns = { plural: ([num]) => Number(num) !== 1 };
const template = runty.string(
'There {$plural(%count)?are:is} {%count} item{$plural(%count)?s} in your cart.',
{ fns }
);
template({ count: 1 });
// "There is 1 item in your cart."
template({ count: 3 });
// "There are 3 items in your cart."

Simple, but powerful

Runty's template syntax is simple and easy to learn, but powerful enough to handle almost any complex string formatting needs.

Built to be extended

Define your own custom functions or try some of ours! Use runty as the foundation for your project's string formatting engine.

Bundle-bloat friendly

Small, tree-shakeable library with zero dependencies.

Template engine alone:
~4.11kB minified (~1.77kB gzipped)

With entire fns standard library:
~6.55kB minified (~2.48kB gzipped)

Parse once, execute multiple times

Templates are parsed and compiled into re-usable functions.

Optional Array output

Drop React components in the middle of a string — or use it for fine-grained control of the stringification of your template.

TypeScript friendly

Built with TypeScript, so it comes with types!