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 🙏

© 2025 – Pkg Stats / Ryan Hefner

jsprint-format

v2.0.0

Published

Cross-platform PHP like sprintf/vsprintf formatting utility for browsers and Node.js

Downloads

3

Readme

JS Print Format

A lightweight, cross-platform formatting library for sprintf/vsprintf-style output—just like PHP’s, but now for modern JavaScript and TypeScript.

  • Supports Node.js and browser environments
  • Handles positional, named, and variadic arguments
  • Typed for maximum confidence with TypeScript
  • UMD + ESM + CommonJS builds included

🚀 Installation

npm install jsprint-format

Or via CDN:

<!-- jsDeliver -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jsprint-format.min.js"></script>

<!-- unpkg -->
<script src="https://unpkg.com/[email protected]/dist/jsprint-format.min.js"></script>

✨ Usage

Importing

import { sprintf, vsprintf } from 'jsprint-format';

Or in a browser (via UMD):

<script src="jsprint-format.min.js"></script>
<script>
  const result = sprintf("Hello, %s!", "John");
</script>

🧪 Examples

📌 Basic formatting

sprintf("Hello, %s!", "world"); // "Hello, world!"
sprintf("Age -> %d", 35);       // "Age -> 35"
sprintf("Pi: %.2f", 3.14159);   // "Pi: 3.14"

🧠 Named Parameters

sprintf("Name: %(name)s, Age: %(age)d", { name: "Alice", age: 30 });
// => "Name: Alice, Age: 30"

sprintf("Coordinates: x = %(x).2f, y = %(y).2f", { x: 12.345, y: 67.89 });
// => "Coordinates: x = 12.35, y = 67.89"

🔢 Positional Arguments

sprintf("Order: %1$s, %3$s, %2$s", "first", "second", "third");
// => "Order: first, third, second"

sprintf("%2$s costs $%1$.2f", 12.346, "Apple");
// => "Apple costs $12.35"

🎯 Padding & Width

sprintf("Padded Number: %04d", 42);         // "Padded Number: 0042"
sprintf("Padded: [%10s]", "pad");           // "Padded: [       pad]"
sprintf("Zero-padded: [%010d]", 42);        // "Zero-padded: [0000000042]"
sprintf("Space padding: [%10s]", "test");   // "Space padding: [      test]"

🧬 Objects & Arrays

sprintf("Array: %s", [1, 2, 3]);                      // "Array: [1,2,3]"
sprintf("Object: %s", { key: "value" });              // "Object: {\"key\":\"value\"}"
sprintf("Nested: %s", { key: { nested: true } });     // "Nested: {\"key\":{\"nested\":true}}"

🧩 Special Cases

sprintf("Boolean: %s", true);       // "Boolean: true"
sprintf("Null value: %s", null);    // "Null value: null"
sprintf("Undefined: %s", undefined); // "Undefined: "

sprintf("Discount: %d%%", 20);      // "Discount: 20%"
sprintf("100%% Complete");          // "100% Complete"

📚 vsprintf

The vsprintf variant takes the format string and an array:

vsprintf("Name: %s, Age: %d", ["Harshal", 28]); // "Name: Harshal, Age: 28"

vsprintf("%2$s costs $%1$.2f", [12.3456, "Banana"]);
// => "Banana costs $12.35"

vsprintf("Nested object: %s", [{ x: 1, y: [2, 3] }]);
// => "Nested object: {\"x\":1,\"y\":[2,3]}"

📜 License

Released under the MIT License


👨‍💻 Author

Made with ❤️ by Harshal Khairnar
Founder, Hitraa Technologies
📧 [email protected]