Skip to content

rumkin/to-format

Repository files navigation

Convert template literal to formatter function.

npm Travis npm

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', 1024); // -> '"index.js" size is 1 KiB'

License

MIT.

Copyright

© 2018, Rumkin.

About

Convert string literal to formatter function

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published