UNPKG

7.82 kBJavaScriptView Raw
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 */
9Object.defineProperty(exports, "__esModule", { value: true });
10exports.trimNewlines = exports.stripIndents = exports.stripIndent = exports.indentBy = exports.oneLine = void 0;
11// eslint-disable-next-line @typescript-eslint/no-explicit-any
12function oneLine(strings, ...values) {
13 const endResult = String.raw(strings, ...values);
14 return endResult.replace(/(?:\r?\n(?:\s*))+/gm, ' ').trim();
15}
16exports.oneLine = oneLine;
17function 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}
26exports.indentBy = indentBy;
27// eslint-disable-next-line @typescript-eslint/no-explicit-any
28function 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}
40exports.stripIndent = stripIndent;
41// eslint-disable-next-line @typescript-eslint/no-explicit-any
42function stripIndents(strings, ...values) {
43 return String.raw(strings, ...values)
44 .split('\n')
45 .map((line) => line.trim())
46 .join('\n')
47 .trim();
48}
49exports.stripIndents = stripIndents;
50// eslint-disable-next-line @typescript-eslint/no-explicit-any
51function 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}
59exports.trimNewlines = trimNewlines;
60//# sourceMappingURL=data:application/json;base64,eyJ2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