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

This comment has been minimized.

Copy link
Owner Author

@LXSMNSYC LXSMNSYC commented Sep 30, 2020

image

@LXSMNSYC

This comment has been minimized.

Copy link
Owner Author

@LXSMNSYC LXSMNSYC commented Sep 30, 2020

image

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