+22
-29
lines changedFilter options
+22
-29
lines changed Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
1
1
// --- Static ---
2
2
3
-
export const from = Array.from
4
-
export const isArray = Array.isArray
3
+
export const from = (...args) => Array.from(...args)
4
+
export const isArray = val => Array.isArray(val)
5
5
6
6
// --- Instance ---
7
7
Original file line number Diff line number Diff line change
@@ -78,11 +78,13 @@ export const eventOff = (el, evtName, handler, options) => {
78
78
export const removeNode = el => el && el.parentNode && el.parentNode.removeChild(el)
79
79
80
80
// Determine if an element is an HTML element
81
-
export const isElement = el => Boolean(el && el.nodeType === Node.ELEMENT_NODE)
81
+
export const isElement = el => !!(el && el.nodeType === Node.ELEMENT_NODE)
82
82
83
83
// Determine if an HTML element is visible - Faster than CSS check
84
84
export const isVisible = el => {
85
-
if (!isElement(el) || !contains(d.body, el)) {
85
+
if (!isElement(el) || !el.parentNode || !contains(d.body, el)) {
86
+
// Note this can fail for shadow dom elements since they
87
+
// are not a direct descendant of document.body
86
88
return false
87
89
}
88
90
if (el.style.display === 'none') {
@@ -94,7 +96,7 @@ export const isVisible = el => {
94
96
// So any tests that need isVisible will fail in JSDOM
95
97
// Except when we override the getBCR prototype in some tests
96
98
const bcr = getBCR(el)
97
-
return Boolean(bcr && bcr.height > 0 && bcr.width > 0)
99
+
return !!(bcr && bcr.height > 0 && bcr.width > 0)
98
100
}
99
101
100
102
// Determine if an element is disabled
@@ -117,12 +119,7 @@ export const select = (selector, root) =>
117
119
(isElement(root) ? root : d).querySelector(selector) || null
118
120
119
121
// Determine if an element matches a selector
120
-
export const matches = (el, selector) => {
121
-
if (!isElement(el)) {
122
-
return false
123
-
}
124
-
return matchesEl.call(el, selector)
125
-
}
122
+
export const matches = (el, selector) => (isElement(el) ? matchesEl.call(el, selector) : false)
126
123
127
124
// Finds closest element matching selector. Returns `null` if not found
128
125
export const closest = (selector, root, includeRoot = false) => {
@@ -138,12 +135,8 @@ export const closest = (selector, root, includeRoot = false) => {
138
135
}
139
136
140
137
// Returns true if the parent element contains the child element
141
-
export const contains = (parent, child) => {
142
-
if (!parent || !isFunction(parent.contains)) {
143
-
return false
144
-
}
145
-
return parent.contains(child)
146
-
}
138
+
export const contains = (parent, child) =>
139
+
parent && isFunction(parent.contains) ? parent.contains(child) : false
147
140
148
141
// Get an element given an ID
149
142
export const getById = id => d.getElementById(/^#/.test(id) ? id.slice(1) : id) || null
Original file line number Diff line number Diff line change
@@ -2,18 +2,18 @@ import { isArray } from './array'
2
2
3
3
// --- Static ---
4
4
5
-
export const assign = Object.assign
6
-
export const getOwnPropertyNames = Object.getOwnPropertyNames
7
-
export const keys = Object.keys
8
-
export const defineProperties = Object.defineProperties
9
-
export const defineProperty = Object.defineProperty
10
-
export const freeze = Object.freeze
11
-
export const getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor
12
-
export const getOwnPropertySymbols = Object.getOwnPropertySymbols
13
-
export const getPrototypeOf = Object.getPrototypeOf
14
-
export const create = Object.create
15
-
export const isFrozen = Object.isFrozen
16
-
export const is = Object.is
5
+
export const assign = (...args) => Object.assign(...args)
6
+
export const create = (proto, optionalProps) => Object.create(proto, optionalProps)
7
+
export const defineProperties = (obj, props) => Object.defineProperties(obj, props)
8
+
export const defineProperty = (obj, prop, descr) => Object.defineProperty(obj, prop, descr)
9
+
export const freeze = obj => Object.freeze(obj)
10
+
export const getOwnPropertyNames = obj => Object.getOwnPropertyNames(obj)
11
+
export const getOwnPropertyDescriptor = (obj, prop) => Object.getOwnPropertyDescriptor(obj, prop)
12
+
export const getOwnPropertySymbols = obj => Object.getOwnPropertySymbols(obj)
13
+
export const getPrototypeOf = obj => Object.getPrototypeOf(obj)
14
+
export const is = (value1, value2) => Object.is(value1, value2)
15
+
export const isFrozen = obj => Object.isFrozen(obj)
16
+
export const keys = obj => Object.keys(obj)
17
17
18
18
// --- "Instance" ---
19
19
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4