Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
string-interpolation.ts
export function interpolate(template: string, ...replacements: string[]): string {
return template.replace(/{([^{}]*)}/g, (match, point) => replacements[point] ?? match);
}
export function keyedInterpolate(template: string, replacements: Record<string, string>): string {
return template.replace(/{([^{}]*)}/g, (match, point) => replacements[point] ?? match);
}
@lxsmnsyc
Copy link
Author

lxsmnsyc commented Sep 30, 2020

image

@lxsmnsyc
Copy link
Author

lxsmnsyc commented Sep 30, 2020

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment