UNPKG

@thi.ng/strings

Version:

Various string formatting & utility functions

53 lines 1.56 kB
import type { IObjectOf, NumOrString } from "@thi.ng/api"; /** * Takes a string template with embedded `{number}` style terms and any * number of args. Replaces numbered terms with their respective args * given. * * @remarks * Also see {@link interpolateKeys}. * * @example * ```ts tangle:../export/interpolate.ts * import { interpolate } from "@thi.ng/strings"; * * console.log( * interpolate("let {0}: {2} = {1};", "a", 42, "number") * ); * // "let a: number = 42;" * ``` * * @param src - * @param args - */ export declare const interpolate: (src: string, ...args: any[]) => string; /** * Similar to {@link interpolate}, but uses alphanumeric placeholders in the * template string and an object of values for the stated keys. Unless * `ignoreMissing` is true (default: false), referencing a missing key will * throw an error. If `ignoreMissing` is true a referenced missing key will * remain as is (i.e. un-interpolated). * * @example * ```ts tangle:../export/interpolate-keys.ts * import { interpolateKeys } from "@thi.ng/strings"; * * console.log( * interpolateKeys( * "let {id}: {type} = {val};", { id: "a", type: "number", val: 42 } * ) * ); * // "let a: number = 42;" * * console.log( * interpolateKeys("{id} = {missing}", { id: "abc" }, true) * ); * // "abc = {missing}" * ``` * * @param src - * @param keys - * @param ignoreMissing - */ export declare const interpolateKeys: (src: string, keys: IObjectOf<NumOrString>, ignoreMissing?: boolean) => string; //# sourceMappingURL=interpolate.d.ts.map