aboutsummaryrefslogtreecommitdiff
path: root/test/bundler/dedent.ts
diff options
context:
space:
mode:
Diffstat (limited to 'test/bundler/dedent.ts')
-rw-r--r--test/bundler/dedent.ts25
1 files changed, 25 insertions, 0 deletions
diff --git a/test/bundler/dedent.ts b/test/bundler/dedent.ts
new file mode 100644
index 000000000..2e0027e58
--- /dev/null
+++ b/test/bundler/dedent.ts
@@ -0,0 +1,25 @@
+export default function dedent(str: string, ...args: any[]) {
+ if (Array.isArray(str)) {
+ let result = "";
+ let numArgs = args.length;
+ for (let i = 0; i < str.length; i++) {
+ result += dedent(str[i]);
+ if (i < numArgs) result += args[i];
+ }
+ str = result;
+ }
+ let indent = Infinity;
+ const lines = str
+ .replace(/^\s*\n/, "")
+ .trimEnd()
+ .split("\n");
+ for (const line of lines) {
+ let thisIndent = 0;
+ for (const char of line) {
+ if (char === " ") thisIndent++;
+ else break;
+ }
+ if (thisIndent < indent) indent = thisIndent;
+ }
+ return lines.map(line => line.slice(indent)).join("\n");
+}