Small sprintf and vsprintf format specifier focused on strings.
npm install sprintfit> Small sprintf and vsprintf format specifier focused on strings. :zap:
__:information_source: Notice:__ sprintf and vsprintf will treat their arguments as strings only. If you are looking for the full specification you could try sprintf.js or printj.
``sh`
yarn add sprintfit
`sh`
npm install sprintfit
UMD file is also available on unpkg:
`html`
You can use the library via window.sprintfit.
Return a formatted string and accepts a variable number of arguments.
`js
import { sprintf } from 'sprintfit'
sprintf('date: %s-%s-%s', 2018, 07, 25)
// date: 2018-07-25
`
Operates as sprintf() but accepts an array of arguments.
`js
import { vsprintf } from 'sprintfit'
vsprintf('date: %s-%s-%s', [ 2018, 07, 28 ])
// date: 2018-07-28
`
- Node: v8.11.3^2.1.4
- BenchmarkJS: ^1.1.1
- [Sprintf-js][2]: ^1.1.2
- [Printj][3]:
`sh``
yarn benchmark
#### sprintf
| package | ops/sec | rme
--- | --- | ---
[Sprintfit][1] | __2,601,688__ | ±5.19% (77 runs sampled)
[SprintfJS][2] | 1,117,038 | ±1.66% (60 runs sampled)
[PrintJ][3] | 1,046,954 | ±2.78% (91 runs sampled)
_Done in 18.00s._
#### vsprintf
| package | ops/sec | rme
--- | --- | ---
[Sprintfit][1] | __2,774,358__ | ±4.03% (79 runs sampled)
[PrintJ][3] | 905,327 | ±3.64% (79 runs sampled)
[SprintfJS][2] | 675,621 | ±7.06% (63 runs sampled)
_Done in 18.34s._
[1]: https://github.com/joseluisq/sprintfit
[2]: https://github.com/alexei/sprintf.js
[3]: https://github.com/SheetJS/printj
Feel free to send some Pull request or issue.
© 2018 José Luis Quintana