bowhead-js
Tiny string interpolation library, written in TypeScript.
Installation
yarn add bowhead-js
Usage
import format from 'bowhead-js';
format('{1} {0} {1}', 1, 'haha');
format('{0|uppercase}', 'haha');
format('{0} {0|countable|fish|fishes}', '1');
format('{0} {0|countable|fish|fishes}', '2');
format('{0} {0|countable|fish|fishes}', '0');
format('{0} {0|countable|deer}', '1');
format('{0} {0|countable|deer}', '2');
Functions available
uppercase
to uppercaselowercase
to lowercasecapitalized
capitalizes first lettercountable
handles plurals
Error handling
By default, bowhead-js mutes index-out-of-range errors being thrown and returns error messages in resulting strings, you can disable this behavior by calling muteExceptions
:
import { muteExceptions } from 'bowhead-js';
format('{1} {7}', 23, 'haha'))
muteExceptions(false);
format('{1} {7}', 23, 'haha'))