Skip to content

Commit

Permalink
fix: improve global object and DOM detection
Browse files Browse the repository at this point in the history
Fixes #91
  • Loading branch information
jetpacmonkey authored and meeber committed Oct 31, 2017
1 parent e10c4e5 commit e7aa747
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,20 @@
* MIT Licensed
*/
var promiseExists = typeof Promise === 'function';
var globalObject = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : self; // eslint-disable-line
var isDom = 'location' in globalObject && 'document' in globalObject;

/* eslint-disable no-undef */
var globalObject = typeof self === 'object' ? self : global; // eslint-disable-line id-blacklist

/*
* All of these attributes must be available on the global object for the current environment
* to be considered a DOM environment (browser)
*/
var isDom = typeof window === 'object' &&
'document' in window &&
'navigator' in window &&
'HTMLElement' in window;
/* eslint-enable */

var symbolExists = typeof Symbol !== 'undefined';
var mapExists = typeof Map !== 'undefined';
var setExists = typeof Set !== 'undefined';
Expand Down Expand Up @@ -160,7 +172,7 @@ module.exports = function typeDetect(obj) {
* Test: `Object.prototype.toString.call(document.createElement('blockquote'))``
* - IE <=10 === "[object HTMLBlockElement]"
*/
if (obj instanceof HTMLElement && obj.tagName === 'BLOCKQUOTE') {
if (obj instanceof globalObject.HTMLElement && obj.tagName === 'BLOCKQUOTE') {
return 'HTMLQuoteElement';
}

Expand All @@ -176,7 +188,7 @@ module.exports = function typeDetect(obj) {
* - Firefox === "[object HTMLTableCellElement]"
* - Safari === "[object HTMLTableCellElement]"
*/
if (obj instanceof HTMLElement && obj.tagName === 'TD') {
if (obj instanceof globalObject.HTMLElement && obj.tagName === 'TD') {
return 'HTMLTableDataCellElement';
}

Expand All @@ -192,7 +204,7 @@ module.exports = function typeDetect(obj) {
* - Firefox === "[object HTMLTableCellElement]"
* - Safari === "[object HTMLTableCellElement]"
*/
if (obj instanceof HTMLElement && obj.tagName === 'TH') {
if (obj instanceof globalObject.HTMLElement && obj.tagName === 'TH') {
return 'HTMLTableHeaderCellElement';
}
}
Expand Down

0 comments on commit e7aa747

Please sign in to comment.