1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = void 0;
|
7 | var _default = createDedent({});
|
8 | exports.default = _default;
|
9 | function createDedent(options) {
|
10 | dedent.withOptions = newOptions => createDedent({
|
11 | ...options,
|
12 | ...newOptions
|
13 | });
|
14 | return dedent;
|
15 | function dedent(strings, ...values) {
|
16 | const raw = typeof strings === "string" ? [strings] : strings.raw;
|
17 | const {
|
18 | escapeSpecialCharacters = Array.isArray(strings)
|
19 | } = options;
|
20 |
|
21 |
|
22 | let result = "";
|
23 | for (let i = 0; i < raw.length; i++) {
|
24 | let next = raw[i];
|
25 | if (escapeSpecialCharacters) {
|
26 |
|
27 | next = next.replace(/\\\n[ \t]*/g, "").replace(/\\`/g, "`").replace(/\\\$/g, "$").replace(/\\{/g, "{");
|
28 | }
|
29 | result += next;
|
30 | if (i < values.length) {
|
31 |
|
32 | result += values[i];
|
33 | }
|
34 | }
|
35 |
|
36 |
|
37 | const lines = result.split("\n");
|
38 | let mindent = null;
|
39 | for (const l of lines) {
|
40 | const m = l.match(/^(\s+)\S+/);
|
41 | if (m) {
|
42 | const indent = m[1].length;
|
43 | if (!mindent) {
|
44 |
|
45 | mindent = indent;
|
46 | } else {
|
47 | mindent = Math.min(mindent, indent);
|
48 | }
|
49 | }
|
50 | }
|
51 | if (mindent !== null) {
|
52 | const m = mindent;
|
53 | result = lines
|
54 |
|
55 |
|
56 | .map(l => l[0] === " " || l[0] === "\t" ? l.slice(m) : l).join("\n");
|
57 | }
|
58 | return result
|
59 |
|
60 | .trim()
|
61 |
|
62 | .replace(/\\n/g, "\n");
|
63 | }
|
64 | }
|
65 | module.exports = exports.default;
|
66 | module.exports.default = exports.default;
|