1 | "use strict";
|
---|
2 | /**
|
---|
3 | * @license
|
---|
4 | * Copyright Google LLC All Rights Reserved.
|
---|
5 | *
|
---|
6 | * Use of this source code is governed by an MIT-style license that can be
|
---|
7 | * found in the LICENSE file at https://angular.io/license
|
---|
8 | */
|
---|
9 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
10 | exports.trimNewlines = exports.stripIndents = exports.stripIndent = exports.indentBy = exports.oneLine = void 0;
|
---|
11 | // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
---|
12 | function oneLine(strings, ...values) {
|
---|
13 | const endResult = String.raw(strings, ...values);
|
---|
14 | return endResult.replace(/(?:\r?\n(?:\s*))+/gm, ' ').trim();
|
---|
15 | }
|
---|
16 | exports.oneLine = oneLine;
|
---|
17 | function indentBy(indentations) {
|
---|
18 | let i = '';
|
---|
19 | while (indentations--) {
|
---|
20 | i += ' ';
|
---|
21 | }
|
---|
22 | return (strings, ...values) => {
|
---|
23 | return i + stripIndent(strings, ...values).replace(/\n/g, '\n' + i);
|
---|
24 | };
|
---|
25 | }
|
---|
26 | exports.indentBy = indentBy;
|
---|
27 | // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
---|
28 | function stripIndent(strings, ...values) {
|
---|
29 | const endResult = String.raw(strings, ...values);
|
---|
30 | // remove the shortest leading indentation from each line
|
---|
31 | const match = endResult.match(/^[ \t]*(?=\S)/gm);
|
---|
32 | // return early if there's nothing to strip
|
---|
33 | if (match === null) {
|
---|
34 | return endResult;
|
---|
35 | }
|
---|
36 | const indent = Math.min(...match.map((el) => el.length));
|
---|
37 | const regexp = new RegExp('^[ \\t]{' + indent + '}', 'gm');
|
---|
38 | return (indent > 0 ? endResult.replace(regexp, '') : endResult).trim();
|
---|
39 | }
|
---|
40 | exports.stripIndent = stripIndent;
|
---|
41 | // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
---|
42 | function stripIndents(strings, ...values) {
|
---|
43 | return String.raw(strings, ...values)
|
---|
44 | .split('\n')
|
---|
45 | .map((line) => line.trim())
|
---|
46 | .join('\n')
|
---|
47 | .trim();
|
---|
48 | }
|
---|
49 | exports.stripIndents = stripIndents;
|
---|
50 | // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
---|
51 | function trimNewlines(strings, ...values) {
|
---|
52 | const endResult = String.raw(strings, ...values);
|
---|
53 | return (endResult
|
---|
54 | // Remove the newline at the start.
|
---|
55 | .replace(/^(?:\r?\n)+/, '')
|
---|
56 | // Remove the newline at the end and following whitespace.
|
---|
57 | .replace(/(?:\r?\n(?:\s*))$/, ''));
|
---|
58 | }
|
---|
59 | exports.trimNewlines = trimNewlines;
|
---|