Parses format string into data map with respect to printf syntax
const parse = require("sprintf-kit/parse");const data = parse("Some %s with %d count");// `data` resolves with following content:{ literals: ["Some ", " with ", " count"], placeholders: [ { type: "s", content: "%s" }, { type: "d", content: "%d" } ], isParameterIndexingValid: true}
data spec:
literals - Surrounding string literals
placeholders - Meta data of parsed placholders.
Placeholder properties map (refer to spec for explanation of each property)
parameter - (optional) parameter setting (e.g. 1)
flags - (optional) array of flags (e.g. ["0", "-"])
width - (optional) width (e.g. 4 or "*" if dynamic)
precision - (optional) precision (e.g. 4 or "*" if dynamic)
length - (optional) length (e.g. "z")
type - Modifier type (e.g. "s" or "d")
content - Full string representation of placeholder (e.g. "%s")
isParameterIndexingValid - Whether parameter indexing is valid across all placeholders.
e.g. if no placeholders come with parameters it'll be true. If some but not all of them will come with parameters, it'll be false (if used, then all placeholders should use them).
Format function generator
// Configure format function that resolves 's' and 'd' modifierslet format = require("sprintf-kit")({ d: require("sprintf-kit/modifiers/d"), s: require("sprintf-kit/modifiers/s")});format("Some %s with %d count %x boo", "foo", 12, "ignored"); // Some foo with 12 count %x boo// Special `rest` formater can be used to handle leftover argumentsformat = require("sprintf-kit")({ d: require("sprintf-kit/modifiers/d"), s: require("sprintf-kit/modifiers/s"), rest: args => " " + args.
Parts resolver generator
Resolver returns resolved data in form of object parts, which maybe helpful if additional programmatical processing is needed