UNPKG

util-ex

Version:

Browser-friendly enhanced util fully compatible with standard node.js

24 lines (23 loc) 1 kB
/** * Formats a string using placeholder tokens. * * If the first argument is a string, it is treated as a format string that * specifies placeholders for the subsequent arguments, which will be inserted * into the string in place of the placeholders. The placeholders are * specified using '%s' for string, '%d' for number, and '%j' for JSON. * * If the first argument is not a string, all arguments will be inspected and * concatenated into a space-separated string. * * @param {string|any} f - The format string or object to be formatted. * @param {...any} args - The values to be inserted into the format string. * @returns {string} The formatted string. * * @example * format('%s %s', 'hello', 'world'); // 'hello world' * format('%d %s', 42, 'answer'); // '42 answer' * format('%j', { foo: 'bar' }); // '{'foo':'bar'}' * format('no placeholders', 'needed'); // 'no placeholders needed' */ export function format(f: string | any, ...args: any[]): string; export default format;