Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
Support for template string on trimIndent
Browse files Browse the repository at this point in the history
  • Loading branch information
testersen committed Nov 17, 2023
1 parent c4e98e1 commit f878700
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/util/trimIndent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,17 @@ function trimEnd(line: string) {
return line.replace(LAST_WHITESPACE, "");
}

export function trimIndent(str: string) {
export function trimIndent(
template: TemplateStringsArray,
...args: unknown[]
): string;
export function trimIndent(content: string): string;
export function trimIndent(
content: string | TemplateStringsArray,
...args: unknown[]
): string {
let str =
typeof content === "string" ? content : String.raw(content, ...args);
const firstLines = str.match(FIRST_LINES)?.groups?.firstLines || "";
const lastLines = str.match(LAST_LINES)?.groups?.lastLines || "";
str = str.substring(firstLines.length, str.length - lastLines.length);
Expand Down

0 comments on commit f878700

Please sign in to comment.