Add is.domElement() (#11)

This commit is contained in:
Melvin 2017-10-07 09:19:11 -07:00 committed by Sindre Sorhus
parent 6268253ec6
commit 75ac3cd574
4 changed files with 42 additions and 1 deletions

View file

@ -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;