npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@jitesoft/sprintf

v2.1.7

Published

Sprintf function for javascript.

Downloads

135

Readme

Sprintf

npm (scoped) Known Vulnerabilities pipeline status coverage report npm Back project

JS implementation of the useful sprintf c-function.
We try to keep the API as close to the original implementation as possible, while some features might be hard to implement in JavaScript the following features are available:

Placeholder support.

%i: Integer (decimal)
%d: Integer (decimal)
%o: Octal
%x: Hex (lower case)
%X: Hex (upper case)
%e: Scientific notation (lower case)
%E: Scientific notation (upper case)
%f: Float
%a: Hex float (lower case)
%A: Hex float (upper case)
%c: Char
%s: String
%j: Json (object which will be stringified if possible)

Precision support for float.

By using the %.<number>f syntax, you are able to specify precision for float types (f, a, A). If precision is higher than the value passed, 0's will be appended to the result and it will not be rounded, while if the value is longer (char count) than the precision value, it will cut the result at the specific point.

Example:

const floatP  = sprintf('abc %.5f', 1.12345678); // 'abc 1.12345'
const floatP2 = sprintf('abc %.5f', 1.12);       // 'abc 1.12000'

Left-padding support for integer.

The same syntax as for floats can be used to pad integers (d, i) with 0's.
If the pad value is lower than the length of the integer, nothing will happen.


const intP  = sprintf('abc %.5s', 123); // 'abc 00123'
const intP2 = sprintf('abc %.1s', 123); // 'abc 123'

Sub-strings

The same syntax as for integer and floats can be used to substring strings.
If the string is shorter than the value, nothing will be changed.


const stringP  = sprintf('abc %.5s', 'abc123abc');     // 'abc abc12'
const stringP2 = sprintf('abc %.10000s', 'abc123abc'); // 'abc abc123abc'

Missing features to be implemented in future versions:

  • Flags
    • %.* precision specifier
    • width specifier
    • *width specifier
    • %- left justify
    • %+ right justify
    • %space pad,
    • %# prefix for octal and hex
    • %0 0-pad
  • Specifiers
    • g, G for shortest rep of %e/%f & %E/%F.