object-inspect
Advanced tools
Comparing version
23
index.js
@@ -25,3 +25,4 @@ module.exports = function inspect_ (obj, opts, depth, seen) { | ||
else if (typeof obj === 'function') { | ||
return '[Function' + (obj.name ? ': ' + obj.name : '') + ']'; | ||
var name = nameOf(obj); | ||
return '[Function' + (name ? ': ' + name : '') + ']'; | ||
} | ||
@@ -49,8 +50,7 @@ else if (typeof HTMLElement !== 'undefined' && obj instanceof HTMLElement) { | ||
for (var key in obj) { | ||
if ({}.hasOwnProperty.call(obj, key)) { | ||
if (/[^\w$]/.test(key)) { | ||
xs.push(inspect(key) + ': ' + inspect(obj[key], obj)); | ||
} | ||
else xs.push(key + ': ' + inspect(obj[key], obj)); | ||
if (!has(obj, key)) continue; | ||
if (/[^\w$]/.test(key)) { | ||
xs.push(inspect(key) + ': ' + inspect(obj[key], obj)); | ||
} | ||
else xs.push(key + ': ' + inspect(obj[key], obj)); | ||
} | ||
@@ -77,1 +77,12 @@ return '{ ' + xs.join(', ') + ' }'; | ||
} | ||
function has (obj, key) { | ||
if (!{}.hasOwnProperty) return true; | ||
return {}.hasOwnProperty.call(obj, key); | ||
} | ||
function nameOf (f) { | ||
if (f.name) return f.name; | ||
var m = f.toString().match(/^function\s*([\w$]+)/); | ||
if (m) return m[1]; | ||
} |
{ | ||
"name": "object-inspect", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "string representations of objects in node and the browser", | ||
"main": "index.js", | ||
"dependencies": { | ||
"tape": "~1.0.4" | ||
}, | ||
"scripts": { | ||
"test": "tape test/*.js" | ||
}, | ||
"testling": { | ||
"files": [ "test/*.js", "test/browser/*.js" ], | ||
"browsers": [ | ||
"ie/6..latest", | ||
"chrome/latest", | ||
"firefox/latest", | ||
"safari/latest", | ||
"opera/latest", | ||
"iphone/latest", | ||
"ipad/latest", | ||
"android/latest" | ||
] | ||
}, | ||
"repository": { | ||
@@ -7,0 +26,0 @@ "type": "git", |
Sorry, the diff of this file is not supported yet
6970
34.24%11
57.14%114
46.15%60
7.14%1
Infinity%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added