import type { IObjectOf , NumOrString } from "@thi.ng/api" ; import { illegalArgs } from "@thi.ng/errors/illegal-arguments" ; const TPL = /\{(\d+)\}/g ; const TPL_K = /\{([a-z0-9_.-]+)\}/gi ; example param src param args export const interpolate = ( src , ... args ) => args . length > 0 ? src . replace ( TPL , ( _ , id ) => String ( args [ parseInt ( id , 10 ) ] ) ) : src ; /**
 * Similar to  interpolate , but uses alphanumeric placeholders in the
 * template string and an object of values for the stated keys.
 *
 *  example param src param keys export const interpolateKeys = ( src , keys ) => src . replace ( TPL_K , ( _ , id ) => keys [ id ] != undefined ? String ( keys [ id ] ) : illegalArgs ( `missing key: ${ id }` ) ) ;