├── .gitignore ├── index.js ├── .travis.yml ├── package.json ├── test.js ├── README.md └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | # tmp files 2 | lib-cov 3 | *.seed 4 | *.log 5 | *.csv 6 | *.dat 7 | *.out 8 | *.pid 9 | *.gz 10 | 11 | # tmp folders 12 | pids/ 13 | logs/ 14 | results/ 15 | coverage/ 16 | 17 | # node.js 18 | node_modules/ 19 | npm-debug.log 20 | package-lock.json 21 | 22 | # osx 23 | .DS_Store 24 | .nyc_output 25 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const isObject = require(`is-object`) 2 | const isWindow = require(`is-window`) 3 | 4 | function isNode(val) { 5 | if (!isObject(val) || !isWindow(window) || !(`Node` in window)) { 6 | return false 7 | } 8 | 9 | return typeof val.nodeType === `number` 10 | && typeof val.nodeName === `string` 11 | } 12 | 13 | module.exports = isNode 14 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | node_js: 2 | - "8" 3 | - "10" 4 | - "12" 5 | - "node" 6 | sudo: false 7 | language: node_js 8 | script: "npm run test" 9 | after_success: "npm i -g codecov && npm run coverage && codecov" 10 | before_install: 11 | - npm i 12 | addons: 13 | apt: 14 | packages: 15 | - xvfb 16 | install: 17 | - export DISPLAY=':99.0' 18 | - Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 & 19 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "is-dom", 3 | "version": "1.1.0", 4 | "description": "Check if the given object is a dom node", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "browserify test.js | tape-run" 8 | }, 9 | "repository": "npm-dom/is-dom", 10 | "keywords": [ 11 | "dom", 12 | "html", 13 | "is dom", 14 | "dom node", 15 | "dom object" 16 | ], 17 | "license": "MIT", 18 | "dependencies": { 19 | "is-object": "^1.0.1", 20 | "is-window": "^1.0.2" 21 | }, 22 | "devDependencies": { 23 | "browserify": "^16.2.3", 24 | "tape": "^4.10.2", 25 | "tape-run": "^6.0.0" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const test = require(`tape`) 3 | 4 | const isDom = require(`./index.js`) 5 | 6 | test(`is-dom`, t => { 7 | t.plan(14) 8 | console.log(`wat`) 9 | t.equal(isDom(null), false) 10 | t.equal(isDom(null), false) 11 | t.equal(isDom(false), false) 12 | t.equal(isDom(new Date()), false) 13 | 14 | t.equal(isDom(), false) 15 | t.equal(isDom([]), false) 16 | t.equal(isDom(2), false) 17 | t.equal(isDom(`foo`), false) 18 | t.equal(isDom(/asda/), false) 19 | t.equal(isDom({}), false) 20 | 21 | 22 | t.equal(isDom({ nodeType: 1, nodeName: `BODY` }), true) 23 | t.equal(isDom(document.createElement(`body`)), true) 24 | t.equal(isDom(window), false) 25 | t.equal(isDom(document), true) 26 | }) 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # is-dom 2 | [![NPM version][npm-image]][npm-url] 3 | [![build status][travis-image]][travis-url] 4 | [![Test coverage][coveralls-image]][coveralls-url] 5 | [![Downloads][downloads-image]][downloads-url] 6 | 7 | Check if the given object is a dom node. 8 | 9 | ## Installation 10 | ```sh 11 | $ npm install is-dom 12 | ``` 13 | 14 | ## Usage 15 | ```js 16 | var isDom = require('is-dom') 17 | 18 | isDom(window.document) 19 | // => true 20 | ``` 21 | 22 | ## License 23 | [MIT](https://tldrlegal.com/license/mit-license) 24 | 25 | [npm-image]: https://img.shields.io/npm/v/is-dom.svg?style=flat-square 26 | [npm-url]: https://npmjs.org/package/is-dom 27 | [travis-image]: https://img.shields.io/travis/npm-dom/is-dom.svg?style=flat-square 28 | [travis-url]: https://travis-ci.org/npm-dom/is-dom 29 | [coveralls-image]: https://img.shields.io/coveralls/npm-dom/is-dom.svg?style=flat-square 30 | [coveralls-url]: https://coveralls.io/r/npm-dom/is-dom?branch=master 31 | [downloads-image]: http://img.shields.io/npm/dm/is-dom.svg?style=flat-square 32 | [downloads-url]: https://npmjs.org/package/is-dom 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. --------------------------------------------------------------------------------