Skip to content

Commit eae31ea

Browse files
authored
refactor: tiny improvements (#39)
1 parent 06bb604 commit eae31ea

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

.changeset/silver-mayflies-beam.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"domiso": patch
3+
---
4+
5+
refactor: tiny improvements

src/index.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@ function getTagName(el: ChildNode | DocumentOrFragment) {
2525
const DISALLOWED_FORM_ATTR_TAG_NAMES =
2626
'button,fieldset,input,label,meter,object,output,select,textarea'.split(',')
2727

28-
const DISALLOWED_ATTR_NAMES = [
29-
'autofocus',
30-
...'fld,formatas,src'.split(',').map(it => `data${it}`),
31-
]
28+
const DISALLOWED_ATTR_NAMES = 'autofocus,datafld,dataformatas,datasrc'.split(
29+
',',
30+
)
3231

3332
const sanitizeAttributes = (el: Element) => {
3433
const tagName = getTagName(el)
@@ -181,12 +180,10 @@ export const sanitize = (
181180
),
182181
)
183182

184-
return (
185-
(fragment && type === TEXT_HTML
186-
? doc.body.innerHTML
187-
: // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- https://github.com/microsoft/TypeScript/issues/50078
188-
doc.documentElement?.outerHTML) || ''
189-
)
183+
return fragment && type === TEXT_HTML
184+
? doc.body.innerHTML
185+
: // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- https://github.com/microsoft/TypeScript/issues/50078
186+
doc.documentElement?.outerHTML || ''
190187
}
191188

192189
export const sanitizeSvg = (svg: string) => sanitize(svg, IMAGE_SVG_XML)

0 commit comments

Comments
 (0)