Add is.domElement()
This commit is contained in:
parent
27d15f40bd
commit
b3903e8ec5
4 changed files with 22 additions and 0 deletions
2
index.js
2
index.js
|
|
@ -161,4 +161,6 @@ is.inRange = (x, range) => {
|
|||
throw new TypeError(`Invalid range: ${util.inspect(range)}`);
|
||||
};
|
||||
|
||||
is.domElement = x => is.object(x) && x.nodeType === 1;
|
||||
|
||||
module.exports = is;
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@
|
|||
],
|
||||
"devDependencies": {
|
||||
"ava": "*",
|
||||
"jsdom": "^11.3.0",
|
||||
"xo": "*"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -145,6 +145,10 @@ Check if `value` (number) is in the range of `0` to `upperBound`.
|
|||
is.inRange(3, 10);
|
||||
```
|
||||
|
||||
##### .domElement(value)
|
||||
|
||||
Returns `true` if `value` is a domElement.
|
||||
|
||||
|
||||
## FAQ
|
||||
|
||||
|
|
|
|||
15
test.js
15
test.js
|
|
@ -1,5 +1,6 @@
|
|||
import util from 'util';
|
||||
import test from 'ava';
|
||||
import {JSDOM} from 'jsdom';
|
||||
import m from '.';
|
||||
|
||||
const isNode8orHigher = Number(process.versions.node.split('.')[0]) >= 8;
|
||||
|
|
@ -358,3 +359,17 @@ test('is.inRange', t => {
|
|||
m.inRange(0, [1, 2, 3]);
|
||||
});
|
||||
});
|
||||
|
||||
test('is.domElement', t => {
|
||||
const {document} = (new JSDOM(`...`)).window;
|
||||
t.true(m.domElement(document.createElement('div')));
|
||||
t.false(m.domElement('hello world'));
|
||||
t.false(m.domElement([]));
|
||||
t.false(m.domElement(new Map()));
|
||||
t.false(m.domElement(null));
|
||||
t.false(m.domElement(undefined));
|
||||
t.false(m.domElement(0));
|
||||
t.false(m.domElement(NaN));
|
||||
t.false(m.domElement(Infinity));
|
||||
t.false(m.domElement({}));
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue