@ls-stack/utils 3.17.0 → 3.17.1
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.
- package/lib/dedent.cjs +42 -23
- package/lib/dedent.d.cts +12 -4
- package/lib/dedent.d.ts +12 -4
- package/lib/dedent.js +42 -23
- package/package.json +5 -1
package/lib/dedent.cjs
CHANGED
|
@@ -23,33 +23,52 @@ __export(dedent_exports, {
|
|
|
23
23
|
dedent: () => dedent
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(dedent_exports);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
var dedent = createDedent({});
|
|
27
|
+
function createDedent(options) {
|
|
28
|
+
d.withOptions = (newOptions) => createDedent({ ...options, ...newOptions });
|
|
29
|
+
return d;
|
|
30
|
+
function d(strings, ...values) {
|
|
31
|
+
const raw = typeof strings === "string" ? [strings] : strings.raw;
|
|
32
|
+
const {
|
|
33
|
+
escapeSpecialCharacters = Array.isArray(strings),
|
|
34
|
+
trimWhitespace = true
|
|
35
|
+
} = options;
|
|
36
|
+
let result = "";
|
|
37
|
+
for (let i = 0; i < raw.length; i++) {
|
|
38
|
+
let next = raw[i];
|
|
39
|
+
if (escapeSpecialCharacters) {
|
|
40
|
+
next = next.replace(/\\\n[ \t]*/g, "").replace(/\\`/g, "`").replace(/\\\$/g, "$").replace(/\\\{/g, "{");
|
|
41
|
+
}
|
|
42
|
+
result += next;
|
|
43
|
+
if (i < values.length) {
|
|
44
|
+
result += values[i];
|
|
45
|
+
}
|
|
33
46
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
47
|
+
const lines = result.split("\n");
|
|
48
|
+
let mindent = null;
|
|
49
|
+
for (const l of lines) {
|
|
50
|
+
const m = l.match(/^(\s+)\S+/);
|
|
51
|
+
if (m) {
|
|
52
|
+
const indent = m[1].length;
|
|
53
|
+
if (!mindent) {
|
|
54
|
+
mindent = indent;
|
|
55
|
+
} else {
|
|
56
|
+
mindent = Math.min(mindent, indent);
|
|
57
|
+
}
|
|
45
58
|
}
|
|
46
59
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
60
|
+
if (mindent !== null) {
|
|
61
|
+
const m = mindent;
|
|
62
|
+
result = lines.map((l) => l[0] === " " || l[0] === " " ? l.slice(m) : l).join("\n");
|
|
63
|
+
}
|
|
64
|
+
if (trimWhitespace) {
|
|
65
|
+
result = result.trim();
|
|
66
|
+
}
|
|
67
|
+
if (escapeSpecialCharacters) {
|
|
68
|
+
result = result.replace(/\\n/g, "\n");
|
|
69
|
+
}
|
|
70
|
+
return result;
|
|
51
71
|
}
|
|
52
|
-
return result.trim().replace(/\\n/g, "\n");
|
|
53
72
|
}
|
|
54
73
|
// Annotate the CommonJS export names for ESM import in node:
|
|
55
74
|
0 && (module.exports = {
|
package/lib/dedent.d.cts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
interface DedentOptions {
|
|
2
|
+
escapeSpecialCharacters?: boolean;
|
|
3
|
+
trimWhitespace?: boolean;
|
|
4
|
+
}
|
|
5
|
+
interface Dedent {
|
|
6
|
+
(literals: string): string;
|
|
7
|
+
(strings: TemplateStringsArray, ...values: unknown[]): string;
|
|
8
|
+
withOptions: CreateDedent;
|
|
9
|
+
}
|
|
10
|
+
type CreateDedent = (options: DedentOptions) => Dedent;
|
|
11
|
+
declare const dedent: Dedent;
|
|
4
12
|
|
|
5
|
-
export { dedent };
|
|
13
|
+
export { type CreateDedent, type Dedent, type DedentOptions, dedent };
|
package/lib/dedent.d.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
interface DedentOptions {
|
|
2
|
+
escapeSpecialCharacters?: boolean;
|
|
3
|
+
trimWhitespace?: boolean;
|
|
4
|
+
}
|
|
5
|
+
interface Dedent {
|
|
6
|
+
(literals: string): string;
|
|
7
|
+
(strings: TemplateStringsArray, ...values: unknown[]): string;
|
|
8
|
+
withOptions: CreateDedent;
|
|
9
|
+
}
|
|
10
|
+
type CreateDedent = (options: DedentOptions) => Dedent;
|
|
11
|
+
declare const dedent: Dedent;
|
|
4
12
|
|
|
5
|
-
export { dedent };
|
|
13
|
+
export { type CreateDedent, type Dedent, type DedentOptions, dedent };
|
package/lib/dedent.js
CHANGED
|
@@ -1,31 +1,50 @@
|
|
|
1
1
|
// src/dedent.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
var dedent = createDedent({});
|
|
3
|
+
function createDedent(options) {
|
|
4
|
+
d.withOptions = (newOptions) => createDedent({ ...options, ...newOptions });
|
|
5
|
+
return d;
|
|
6
|
+
function d(strings, ...values) {
|
|
7
|
+
const raw = typeof strings === "string" ? [strings] : strings.raw;
|
|
8
|
+
const {
|
|
9
|
+
escapeSpecialCharacters = Array.isArray(strings),
|
|
10
|
+
trimWhitespace = true
|
|
11
|
+
} = options;
|
|
12
|
+
let result = "";
|
|
13
|
+
for (let i = 0; i < raw.length; i++) {
|
|
14
|
+
let next = raw[i];
|
|
15
|
+
if (escapeSpecialCharacters) {
|
|
16
|
+
next = next.replace(/\\\n[ \t]*/g, "").replace(/\\`/g, "`").replace(/\\\$/g, "$").replace(/\\\{/g, "{");
|
|
17
|
+
}
|
|
18
|
+
result += next;
|
|
19
|
+
if (i < values.length) {
|
|
20
|
+
result += values[i];
|
|
21
|
+
}
|
|
9
22
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
23
|
+
const lines = result.split("\n");
|
|
24
|
+
let mindent = null;
|
|
25
|
+
for (const l of lines) {
|
|
26
|
+
const m = l.match(/^(\s+)\S+/);
|
|
27
|
+
if (m) {
|
|
28
|
+
const indent = m[1].length;
|
|
29
|
+
if (!mindent) {
|
|
30
|
+
mindent = indent;
|
|
31
|
+
} else {
|
|
32
|
+
mindent = Math.min(mindent, indent);
|
|
33
|
+
}
|
|
21
34
|
}
|
|
22
35
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
36
|
+
if (mindent !== null) {
|
|
37
|
+
const m = mindent;
|
|
38
|
+
result = lines.map((l) => l[0] === " " || l[0] === " " ? l.slice(m) : l).join("\n");
|
|
39
|
+
}
|
|
40
|
+
if (trimWhitespace) {
|
|
41
|
+
result = result.trim();
|
|
42
|
+
}
|
|
43
|
+
if (escapeSpecialCharacters) {
|
|
44
|
+
result = result.replace(/\\n/g, "\n");
|
|
45
|
+
}
|
|
46
|
+
return result;
|
|
27
47
|
}
|
|
28
|
-
return result.trim().replace(/\\n/g, "\n");
|
|
29
48
|
}
|
|
30
49
|
export {
|
|
31
50
|
dedent
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ls-stack/utils",
|
|
3
3
|
"description": "Typescript utils",
|
|
4
|
-
"version": "3.17.
|
|
4
|
+
"version": "3.17.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
7
7
|
"lib"
|
|
@@ -18,6 +18,10 @@
|
|
|
18
18
|
"import": "./lib/main.js",
|
|
19
19
|
"require": "./lib/main.cjs"
|
|
20
20
|
},
|
|
21
|
+
"./__snapshots__": {
|
|
22
|
+
"import": "./lib/__snapshots__.js",
|
|
23
|
+
"require": "./lib/__snapshots__.cjs"
|
|
24
|
+
},
|
|
21
25
|
"./arrayUtils": {
|
|
22
26
|
"import": "./lib/arrayUtils.js",
|
|
23
27
|
"require": "./lib/arrayUtils.cjs"
|