Skip to content

Commit 4e440cd

Browse files
committed
[Refactor] consolidate wrapping logic for boxed primitives into a function.
1 parent df44a20 commit 4e440cd

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

index.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ module.exports = function inspect_ (obj, opts, depth, seen) {
4949
}
5050
if (isSymbol(obj)) {
5151
var symString = Symbol.prototype.toString.call(obj);
52-
return typeof obj === 'object' ? 'Object(' + symString + ')' : symString;
52+
return typeof obj === 'object' ? markBoxed(symString) : symString;
5353
}
5454
if (isElement(obj)) {
5555
var s = '<' + String(obj.nodeName).toLowerCase();
@@ -106,13 +106,13 @@ module.exports = function inspect_ (obj, opts, depth, seen) {
106106
return String(obj);
107107
}
108108
if (isNumber(obj)) {
109-
return 'Object(' + Number(obj) + ')';
109+
return markBoxed(Number(obj));
110110
}
111111
if (isBoolean(obj)) {
112-
return 'Object(' + booleanValueOf.call(obj) + ')';
112+
return markBoxed(booleanValueOf.call(obj));
113113
}
114114
if (isString(obj)) {
115-
return 'Object(' + inspect(String(obj)) + ')';
115+
return markBoxed(inspect(String(obj)));
116116
}
117117
if (!isDate(obj) && !isRegExp(obj)) {
118118
var xs = [], keys = [];
@@ -212,3 +212,7 @@ function inspectString (str) {
212212
return '\\x' + (n < 0x10 ? '0' : '') + n.toString(16);
213213
}
214214
}
215+
216+
function markBoxed (str) {
217+
return 'Object(' + str + ')';
218+
}

0 commit comments

Comments
 (0)