{"library":"sprintf-kit","title":"sprintf-kit","type":"library","description":"sprintf-kit is a JavaScript library providing a modular `printf` format string parser and basic formatter. It allows developers to create custom `sprintf`-like functions by explicitly configuring specific modifier resolvers (e.g., for `%s`, `%d`). The library's core is its detailed `printf` syntax parser, which breaks down format strings into literals and placeholder metadata. It also offers a format function generator and a parts resolver generator, enabling granular control over how strings are processed and substitutions are applied. Currently at version 2.0.2, the package has seen infrequent but recent maintenance, with the last major update (v2.0.0) occurring in 2018, focusing on internal structure and advanced parsing capabilities. Its modularity and explicit modifier configuration differentiate it from simpler `sprintf` implementations that might bundle all modifiers by default.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install sprintf-kit"],"cli":null},"imports":["const format = require('sprintf-kit');","const parse = require('sprintf-kit/parse');","const getResolver = require('sprintf-kit/get-resolver');","const s = require('sprintf-kit/modifiers/s');"],"auth":{"required":false,"env_vars":[]},"links":{"homepage":null,"github":"https://github.com/medikoo/sprintf-kit","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/sprintf-kit","openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"const format = require('sprintf-kit');\nconst s = require('sprintf-kit/modifiers/s');\nconst d = require('sprintf-kit/modifiers/d');\nconst clc = require('cli-color');\n\n// Configure a format function with string and decimal modifiers\nconst customFormat = format({\n  s: s,\n  d: d,\n  // Optional: add a 'rest' formatter for unhandled arguments\n  rest: args => args.length > 0 ? ` (and ${args.join(', ')})` : ''\n});\n\nconsole.log(customFormat('Hello %s, you have %d new messages.', 'Alice', 5));\n// Expected output: \"Hello Alice, you have 5 new messages.\"\n\nconsole.log(customFormat('User %s logged in from %s, but ignored %d.', 'Bob', '192.168.1.1', 10, 'extra arg'));\n// Expected output: \"User Bob logged in from 192.168.1.1, but ignored 10. (and extra arg)\"\n\n// Example with custom literal decoration (e.g., for console coloring)\nconst coloredFormat = format({\n  s: s,\n  d: d,\n  literal: literal => clc.green(literal) // Make non-placeholder text green\n});\n\nconsole.log(coloredFormat('This is a %s message with a %d number.', 'colorful', 123));","lang":"javascript","description":"This quickstart demonstrates how to set up a custom `sprintf` formatter using `sprintf-kit`, including defining specific modifiers and optionally styling literal parts of the string with an external library like `cli-color`.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}