MCPcopy Create free account
hub / github.com/angular/dev-infra / dedent

Function dedent

ng-dev/utils/testing/dedent.ts:13–28  ·  view source on GitHub ↗
(strings: TemplateStringsArray, ...values: any[])

Source from the content-addressed store, hash-verified

11 * literal. The smallest common indentation will be omitted.
12 */
13export function dedent(strings: TemplateStringsArray, ...values: any[]) {
14 let joinedString = '';
15 for (let i = 0; i < values.length; i++) {
16 joinedString += `${strings[i]}${values[i]}`;
17 }
18 joinedString += strings[strings.length - 1];
19
20 const matches = joinedString.match(/^[ \t]*(?=\S)/gm);
21 if (matches === null) {
22 return joinedString;
23 }
24
25 const minLineIndent = Math.min(...matches.map((el) => el.length));
26 const omitMinIndentRegex = new RegExp(`^[ \\t]{${minLineIndent}}`, 'gm');
27 return minLineIndent > 0 ? joinedString.replace(omitMinIndentRegex, '') : joinedString;
28}

Callers 3

changelog.spec.tsFile · 0.85
createChangelogEntryFunction · 0.85
changelogPatternFunction · 0.85

Calls 1

matchMethod · 0.45

Tested by 1

createChangelogEntryFunction · 0.68