{"library":"sprintf-js","title":"sprintf-js","type":"library","description":"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.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install sprintf-js"],"cli":null},"imports":["const { sprintf } = require('sprintf-js');","const { vsprintf } = require('sprintf-js');","var sprintf = require('sprintf-js').sprintf;\nvar vsprintf = require('sprintf-js').vsprintf;"],"auth":{"required":false,"env_vars":[]},"links":{"homepage":null,"github":"https://github.com/alexei/sprintf.js","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/sprintf-js","openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"const { sprintf, vsprintf } = require('sprintf-js');\n\n// Basic string formatting with argument reordering\nconst formattedString1 = sprintf('%2$s %3$s a %1$s', 'cracker', 'Polly', 'wants');\nconsole.log(formattedString1); // Expected: \"Polly wants a cracker\"\n\n// Formatting with an array of arguments\nconst alphabetLetters = ['a', 'b', 'c', 'd'];\nconst formattedString2 = vsprintf('The first 4 letters of the English alphabet are: %s, %s, %s and %s', alphabetLetters);\nconsole.log(formattedString2); // Expected: \"The first 4 letters of the English alphabet are: a, b, c and d\"\n\n// Example with numeric formatting (padding and precision)\nconst pi = 3.1415926535;\nconst formattedPi = sprintf('Pi to 2 decimal places: %.2f, padded to 10 chars with zero: %010.2f', pi, pi);\nconsole.log(formattedPi); // Expected: \"Pi to 2 decimal places: 3.14, padded to 10 chars with zero: 0000003.14\"\n\n// Example with named arguments (available since a minor version, not explicitly in 1.1.3 README but a common feature)\nconst user = { name: 'Dolly' };\nconst namedArgString = sprintf('Hello %(name)s', user);\nconsole.log(namedArgString); // Expected: \"Hello Dolly\"","lang":"javascript","description":"Demonstrates basic string formatting with positional arguments, array-based formatting using `vsprintf`, numeric formatting with padding and precision, and an example of named arguments.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}