/
githubmirror
/
components
Обзор
Документация
Войти
/
githubmirror
/
components
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/cdk/testing/private/text-dedent.ts
28 строк
935 B
Naji
docs: replace angular.io links with angular.dev (#29734)
19 сен 2024, 13:57
Не верифицирован
19 сен 2024, 13:57
5782834
Код
Авторство
О чём код?
/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.dev/license */ /** * Template string function that can be used to dedent a given string * literal. The smallest common indentation will be omitted. */ export function dedent(strings: TemplateStringsArray, ...values: any[]) { let joinedString = ''; for (let i = 0; i < values.length; i++) { joinedString += `${strings[i]}${values[i]}`; } joinedString += strings[strings.length - 1]; const matches = joinedString.match(/^[ \t]*(?=\S)/gm); if (matches === null) { return joinedString; } const minLineIndent = Math.min(...matches.map(el => el.length)); const omitMinIndentRegex = new RegExp(`^[ \\t]{${minLineIndent}}`, 'gm'); return minLineIndent > 0 ? joinedString.replace(omitMinIndentRegex, '') : joinedString; }