Skip to content

Instantly share code, notes, and snippets.

@VitorLuizC
Created August 23, 2021 16:48
Show Gist options
  • Save VitorLuizC/f80a9b51c3a686e5b5e35259bbf263fa to your computer and use it in GitHub Desktop.
Save VitorLuizC/f80a9b51c3a686e5b5e35259bbf263fa to your computer and use it in GitHub Desktop.
function interpolate(strings: TemplateStringsArray, interpolations: unknown[]): string {
return strings.reduce((interpolation, string, index) => (
interpolation.concat(String(index), string);
));
}
function normalizeWhiteSpaces(strings: TemplateStringsArray, ...interpolations: unknown[]): string {
const interpolation = interpolate(strings, interpolations);
return interpolation.replace(/\s+/g, ' ').trim();
}
const user = {
name: 'Vitor',
};
normalizeWhiteSpaces`
Hi, ${user.name}!
How are you doing?
`;
// => "Hi, Vitor! How are you doing?"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment