1.0.1 • Published 6 years ago

sprintfit v1.0.1

Weekly downloads
603
License
MIT
Repository
github
Last release
6 years ago

Sprintfit Build Status npm npm JavaScript Style Guide

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.

Install

Yarn

yarn add sprintfit

NPM

npm install sprintfit

UMD file is also available on unpkg:

<script src="https://unpkg.com/sprintfit/sprintfit.umd.min.js"></script>

You can use the library via window.sprintfit.

Usage

sprintf

Return a formatted string and accepts a variable number of arguments.

import { sprintf } from 'sprintfit'

sprintf('date: %s-%s-%s', 2018, 07, 25)
// date: 2018-07-25

vsprintf

Operates as sprintf() but accepts an array of arguments.

import { vsprintf } from 'sprintfit'

vsprintf('date: %s-%s-%s', [ 2018, 07, 28 ])
// date: 2018-07-28

Benchmarks

yarn benchmark

sprintf

packageops/secrme
Sprintfit2,601,688±5.19% (77 runs sampled)
SprintfJS1,117,038±1.66% (60 runs sampled)
PrintJ1,046,954±2.78% (91 runs sampled)

Done in 18.00s.

vsprintf

packageops/secrme
Sprintfit2,774,358±4.03% (79 runs sampled)
PrintJ905,327±3.64% (79 runs sampled)
SprintfJS675,621±7.06% (63 runs sampled)

Done in 18.34s.

Contributions

Feel free to send some Pull request or issue.

License

MIT license

© 2018 José Luis Quintana