Skip to content

Commit d53304c

Browse files
author
Patrick Tran
committed
use long form checks rather than optional chaining
1 parent 753390d commit d53304c

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/dom-helper.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
const stripHtml = element => element?.innerHTML?.replace(/<[^>]*>?/gm, '')
1+
const stripHtml = element => {
2+
if (element && element.innerHTML) {
3+
return element.innerHTML.replace(/<[^>]*>?/gm, '')
4+
}
5+
6+
return null
7+
}
28

39
const parseStrDimensionToInt = elementSize => parseInt(elementSize, 10)
410

@@ -46,10 +52,12 @@ const hasClass = (element, className) => {
4652
}
4753

4854
const findFirstChildWithClassName = (element, className) => {
49-
const matches = element?.getElementsByClassName(className)
55+
if (element && element.getElementsByClassName) {
56+
const matches = element.getElementsByClassName(className)
5057

51-
if (matches && matches.length > 0) {
52-
return matches[0]
58+
if (matches && matches.length > 0) {
59+
return matches[0]
60+
}
5361
}
5462

5563
return null

0 commit comments

Comments
 (0)