/
githubmirror
/
amphtml
Обзор
Документация
Войти
/
githubmirror
/
amphtml
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
testing/helpers/cleanHtml.ts
20 строк
574 B
Scott Rippey
✨ [bento-mega-menu] Implemented bento mega menu (#38197)
24 май 2022, 01:25
Не верифицирован
24 май 2022, 01:25
ed0c674
Код
Авторство
О чём код?
/** * Simple logic for cleaning attributes from html. * Useful for creating "snapshots" in tests. * @param html - A string of HTML * @param [keepAttrs] - An optional array of attributes to keep */ export function cleanHtml(html: string, keepAttrs?: string[]): string { html = html.replace(/\s([-\w]+)(="[^"]*")/g, ($0, $attr) => { return keepAttrs?.includes($attr) ? $0 : ''; }); // Condense whitespace: html = cleanWhitespace(html); return html; } export function cleanWhitespace(html: string): string { return html.trim().replace(/\s\s+/g, ' '); }