https://github.com/rumkin/to-format
Convert string literal to formatter function
https://github.com/rumkin/to-format
javascript strings templates utils
Last synced: 10 months ago
JSON representation
Convert string literal to formatter function
- Host: GitHub
- URL: https://github.com/rumkin/to-format
- Owner: rumkin
- Created: 2018-04-20T19:47:07.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-04-26T18:05:41.000Z (about 8 years ago)
- Last Synced: 2025-07-26T00:29:35.991Z (11 months ago)
- Topics: javascript, strings, templates, utils
- Language: JavaScript
- Homepage:
- Size: 10.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Convert template literal to formatter function.
[](https://npmjs.com/package/to-fmt)
[](https://travis-ci.org/rumkin/to-format)



[](https://npmjs.com/packages/to-fmt)
## Install
With npm:
```bash
npm i to-fmt
```
## Usage
Hello world example:
```javascript
import f from 'to-fmt';
const format = f`Hello, ${String}!`;
format('World'); // -> 'Hello, World!'
```
Number formatter:
```javascript
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:
```javascript
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.