Skip to content

Commit

Permalink
special isElement() check
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Jul 26, 2013
1 parent ffbf1d4 commit 882768a
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ module.exports = function inspect_ (obj, opts, depth, seen) {
var name = nameOf(obj);
return '[Function' + (name ? ': ' + name : '') + ']';
}
else if (typeof HTMLElement !== 'undefined' && obj instanceof HTMLElement) {
var s = '<' + String(obj.tagName).toLowerCase();
else if (isElement(obj)) {
var s = '<' + String(obj.nodeName).toLowerCase();
var attrs = obj.attributes || [];
for (var i = 0; i < attrs.length; i++) {
s += ' ' + attrs[i].name + '="' + quote(attrs[i].value) + '"';
Expand Down Expand Up @@ -91,3 +91,13 @@ function indexOf (xs, x) {
}
return -1;
}

function isElement (x) {
if (!x || typeof x !== 'object') return false;
if (typeof HTMLElement !== 'undefined') {
return x instanceof HTMLElement;
}
else return typeof x.nodeName === 'string'
&& typeof x.getAttribute === 'function'
;
}

0 comments on commit 882768a

Please sign in to comment.