sprintf-js is a JavaScript implementation of the `sprintf` and `vsprintf` functions, providing C-style string formatting capabilities for both browser and Node.js environments. The current stable version is 1.1.3, last published in 2016. It supports a comprehensive set of format specifiers, including argument reordering, padding, alignment, precision, and various type conversions (e.g., binary, octal, hexadecimal, scientific notation, and JSON for objects/arrays). Its key differentiators include a complete feature set for `sprintf` functionality and its lightweight nature, having no notable runtime dependencies. The package is considered mature and stable, with infrequent updates, making it a reliable choice for string interpolation when a dedicated templating engine is overkill.
npm install sprintf-jsVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic string formatting with positional arguments, array-based formatting using `vsprintf`, numeric formatting with padding and precision, and an example of named arguments.
If targeting older environments, ensure necessary polyfills are included (e.g., through a bundler like Webpack/Rollup with Babel, or by explicitly importing polyfills) before `sprintf-js` is loaded.
Use CommonJS `require` syntax: `const { sprintf, vsprintf } = require('sprintf-js');` or `const sprintf = require('sprintf-js').sprintf;`Ensure your build process includes polyfills for Node.js globals if bundling for the browser, especially when targeting environments that do not natively provide these. Verify that all required ES5/ES6+ polyfills mentioned in the `v1.1.1` warning are present.
No dependency data recorded yet.