country-codes-list
Version:
List of codes per country (languages, calling codes, currency codes, etc) with full TypeScript support.
18 lines (17 loc) • 583 B
text/typescript
/**
* Replaces placeholders in a string with values from an object.
* @param template - The string containing placeholders.
* @param data - The object containing key-value pairs for replacement.
* @returns The string with placeholders replaced by values.
*/
export default function supplant(template: string, data: any): string {
return template.replace(
/{([^{}]*)}/g,
(match: string, key: string): string => {
const value = data[key];
return typeof value === "string" || typeof value === "number"
? value.toString()
: match;
}
);
}