to-fmt
v1.0.2
Published
Convert literal template into formatter function
Downloads
4
Readme
Convert template literal to formatter function.
Install
With npm:
npm i to-fmt
Usage
Hello world example:
import f from 'to-fmt';
const format = f`Hello, ${String}!`;
format('World'); // -> 'Hello, World!'
Number formatter:
import f from 'to-fmt';
const toFixed = n => number => number.toFixed(n);
const format = f`Value is ${toFixed(2)}!`;
format(1); // -> 'Value is 1.00!'
format(3.14159); // -> 'Value is 3.14!'
Multiple values example:
import f from 'to-fmt';
import bytes from 'pretty-bytes';
const format = f`"${String}" size is ${bytes}!`;
format('index.js', 605); // -> '"index.js" size is 605 B'
License
MIT.
Copyright
© 2018, Rumkin.