Skip to content

Instantly share code, notes, and snippets.

@creationix
Created May 7, 2010 05:52
Show Gist options
  • Select an option

  • Save creationix/393112 to your computer and use it in GitHub Desktop.

Select an option

Save creationix/393112 to your computer and use it in GitHub Desktop.
From 40200f12d958f9820019376c8e7f3c74b171a368 Mon Sep 17 00:00:00 2001
From: Tim Caswell <tim@creationix.com>
Date: Fri, 7 May 2010 00:51:45 -0500
Subject: [PATCH] Add custom hook to sys.inspect
This allows Buffer.prototype.inspect to be used.
When truncating values use the proper type, not
always [Object]
---
lib/sys.js | 10 +++++++---
1 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/lib/sys.js b/lib/sys.js
index 7bf582d..1980e54 100644
--- a/lib/sys.js
+++ b/lib/sys.js
@@ -32,6 +32,9 @@ var error = exports.error = function (x) {
exports.inspect = function (obj, showHidden, depth) {
var seen = [];
function format(value, recurseTimes) {
+ if (value && typeof value.inspect === 'function') {
+ return value.inspect(recurseTimes);
+ }
// Primitive types cannot have properties
switch (typeof value) {
case 'undefined': return 'undefined';
@@ -97,10 +100,11 @@ exports.inspect = function (obj, showHidden, depth) {
if (recurseTimes < 0) {
if (value instanceof RegExp) {
- return '' + value;
- } else {
- return "[Object]";
+ return value.toString();
}
+ return "[" +
+ (typeof value).replace(/^([a-z])/, function (d) { return d.toUpperCase(); }) +
+ "]";
}
output = keys.map(function (key) {
--
1.7.0.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment