Add is.domElement() (#11)
This commit is contained in:
parent
6268253ec6
commit
75ac3cd574
4 changed files with 42 additions and 1 deletions
12
index.js
12
index.js
|
|
@ -161,6 +161,18 @@ is.inRange = (x, range) => {
|
|||
throw new TypeError(`Invalid range: ${util.inspect(range)}`);
|
||||
};
|
||||
|
||||
const NODE_TYPE_ELEMENT = 1;
|
||||
const DOM_PROPERTIES_TO_CHECK = [
|
||||
'innerHTML',
|
||||
'ownerDocument',
|
||||
'style',
|
||||
'attributes',
|
||||
'nodeValue'
|
||||
];
|
||||
|
||||
is.domElement = x => is.object(x) && x.nodeType === NODE_TYPE_ELEMENT && is.string(x.nodeName) &&
|
||||
!is.plainObject(x) && DOM_PROPERTIES_TO_CHECK.every(property => property in x);
|
||||
|
||||
is.infinite = x => x === Infinity || x === -Infinity;
|
||||
|
||||
const isEmptyStringOrArray = x => (is.string(x) || is.array(x)) && x.length === 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue