Convert template literal to formatter function.
With npm:
npm i to-fmt
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', 1024); // -> '"index.js" size is 1 KiB'
MIT.
© 2018, Rumkin.