Skip to content

Instantly share code, notes, and snippets.

@lxsmnsyc
Last active September 30, 2020 18:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lxsmnsyc/9b4016b49bec70876783061d953a02e5 to your computer and use it in GitHub Desktop.
Save lxsmnsyc/9b4016b49bec70876783061d953a02e5 to your computer and use it in GitHub Desktop.
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

image

@lxsmnsyc
Copy link
Author

image

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