Nothing Special   »   [go: up one dir, main page]

Skip to content

A fast 450b sprintf & vsprintf format specifier focused on strings with no dependencies. ⚡️

License

Notifications You must be signed in to change notification settings

joseluisq/sprintfit

Repository files navigation

Sprintfit Build Status npm npm JavaScript Style Guide

A fast 450b sprintf & vsprintf format specifier focused on strings with no dependencies. ⚡

Note: 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 build
yarn benchmark

🚀 Try beanchmark online

sprintf

package ops/sec rme
Sprintfit 2,601,688 ±5.19% (77 runs sampled)
SprintfJS 1,117,038 ±1.66% (60 runs sampled)
PrintJ 1,046,954 ±2.78% (91 runs sampled)

Done in 18.00s.

vsprintf

package ops/sec rme
Sprintfit 2,774,358 ±4.03% (79 runs sampled)
PrintJ 905,327 ±3.64% (79 runs sampled)
SprintfJS 675,621 ±7.06% (63 runs sampled)

Done in 18.34s.

Node v12

Node: v12.16.1

# sprintf
1) Sprintfit: sprintf() x 2,041,472 ops/sec ±3.13% (83 runs sampled)
2) SprintfJS: sprintf() x 915,427 ops/sec ±2.79% (84 runs sampled)
3) PrintJ: sprintf() x 1,114,252 ops/sec ±3.55% (79 runs sampled)

Fastest is 1) Sprintfit: sprintf()

# vsprintf
1) Sprintfit: vsprintf() x 2,281,271 ops/sec ±0.52% (91 runs sampled)
2) SprintfJS: vsprintf() x 704,705 ops/sec ±2.24% (84 runs sampled)
3) PrintJ: vsprintf() x 1,193,415 ops/sec ±2.13% (83 runs sampled)

Fastest is 1) Sprintfit: vsprintf()

Done in 36.05s.

Contributions

Feel free to send some Pull request or issue.

License

MIT license

© 2018-present Jose Quintana

About

A fast 450b sprintf & vsprintf format specifier focused on strings with no dependencies. ⚡️

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published