Last active
September 30, 2020 18:07
-
-
Save lxsmnsyc/9b4016b49bec70876783061d953a02e5 to your computer and use it in GitHub Desktop.
string-interpolation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment