[d24f17c] | 1 | format
|
---|
| 2 | ======
|
---|
| 3 |
|
---|
| 4 | printf, sprintf, and vsprintf for JavaScript
|
---|
| 5 |
|
---|
| 6 |
|
---|
| 7 | Installation
|
---|
| 8 | ============
|
---|
| 9 |
|
---|
| 10 | npm install format
|
---|
| 11 |
|
---|
| 12 | The code works in browsers as well, you can copy these functions into your project
|
---|
| 13 | or otherwise include them with your other JavaScript.
|
---|
| 14 |
|
---|
| 15 | Usage
|
---|
| 16 | =====
|
---|
| 17 |
|
---|
| 18 | var format = require('format')
|
---|
| 19 | , printf = format.printf
|
---|
| 20 | , vsprintf = format.vsprintf
|
---|
| 21 | // or if you want to keep it old school
|
---|
| 22 | , sprintf = format
|
---|
| 23 |
|
---|
| 24 | // Print 'hello world'
|
---|
| 25 | printf('%s world', 'hello')
|
---|
| 26 |
|
---|
| 27 | var what = 'life, the universe, and everything'
|
---|
| 28 | format('%d is the answer to %s', 42, what)
|
---|
| 29 | // => '42 is the answer to life, the universe, and everything'
|
---|
| 30 |
|
---|
| 31 | vsprintf('%d is the answer to %s', [42, what])
|
---|
| 32 | // => '42 is the answer to life, the universe, and everything'
|
---|
| 33 |
|
---|
| 34 | Supported format specifiers: b, c, d, f, o, s, x, and X.
|
---|
| 35 |
|
---|
| 36 | See `man 3 printf` or `man 1 printf` for details.
|
---|
| 37 |
|
---|
| 38 | Precision is supported for floating point numbers.
|
---|
| 39 |
|
---|
| 40 | License
|
---|
| 41 | =======
|
---|
| 42 |
|
---|
| 43 | Copyright 2010 - 2014 Sami Samhuri sami@samhuri.net
|
---|
| 44 |
|
---|
| 45 | [MIT license](http://sjs.mit-license.org)
|
---|
| 46 |
|
---|