alchemy 2.0.0-beta.2 → 2.0.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Tagged template literal for removing indentation from a block of text.
3
+ *
4
+ * If the first line is empty, it will be ignored.
5
+ */
6
+ export function dedent(strings: TemplateStringsArray, ...values: unknown[]): string;
7
+ export function dedent(text: string): string;
8
+ export function dedent(
9
+ stringsOrText: TemplateStringsArray | string,
10
+ ...values: unknown[]
11
+ ): string {
12
+ const raw =
13
+ typeof stringsOrText === "string"
14
+ ? stringsOrText
15
+ : String.raw({ raw: stringsOrText }, ...values);
16
+
17
+ let lines = raw.split("\n");
18
+
19
+ while (lines.length > 0 && lines[0].trim() === "") {
20
+ lines = lines.slice(1);
21
+ }
22
+
23
+ while (lines.length > 0 && lines[lines.length - 1].trim() === "") {
24
+ lines = lines.slice(0, lines.length - 1);
25
+ }
26
+
27
+ if (lines.length === 0) {
28
+ return "";
29
+ }
30
+
31
+ let minIndentLength = Number.POSITIVE_INFINITY;
32
+ for (const line of lines) {
33
+ if (line.trim() !== "") {
34
+ const indent = line.match(/^[ \t]*/)?.[0];
35
+ if (indent != null && indent.length < minIndentLength) {
36
+ minIndentLength = indent.length;
37
+ }
38
+ }
39
+ }
40
+
41
+ if (minIndentLength === Number.POSITIVE_INFINITY) {
42
+ return lines.join("\n");
43
+ }
44
+
45
+ lines = lines.map((line) => {
46
+ if (line.trim() === "") {
47
+ return line;
48
+ }
49
+ return line.startsWith(" ".repeat(minIndentLength)) ||
50
+ line.startsWith("\t".repeat(minIndentLength))
51
+ ? line.substring(minIndentLength)
52
+ : line;
53
+ });
54
+
55
+ return lines.join("\n");
56
+ }
package/src/Util/index.ts CHANGED
@@ -3,6 +3,7 @@ export * from "./base32.ts";
3
3
  export * from "./camel.ts";
4
4
  export * from "./class.ts";
5
5
  export * from "./data.ts";
6
+ export * from "./dedent.ts";
6
7
  export * from "./instance.ts";
7
8
  export * from "./pointer.ts";
8
9
  export * from "./schema-to-type.ts";