object-inspect
Advanced tools
Comparing version 1.8.0 to 1.9.0
26
index.js
@@ -18,2 +18,5 @@ var hasMap = typeof Map === 'function' && Map.prototype; | ||
var bigIntValueOf = typeof BigInt === 'function' ? BigInt.prototype.valueOf : null; | ||
var gOPS = Object.getOwnPropertySymbols; | ||
var symToString = typeof Symbol === 'function' ? Symbol.prototype.toString : null; | ||
var isEnumerable = Object.prototype.propertyIsEnumerable; | ||
@@ -70,3 +73,3 @@ var inspectCustom = require('./util.inspect').custom; | ||
} | ||
if (typeof obj === 'bigint') { // eslint-disable-line valid-typeof | ||
if (typeof obj === 'bigint') { | ||
return String(obj) + 'n'; | ||
@@ -108,6 +111,7 @@ } | ||
var name = nameOf(obj); | ||
return '[Function' + (name ? ': ' + name : ' (anonymous)') + ']'; | ||
var keys = arrObjKeys(obj, inspect); | ||
return '[Function' + (name ? ': ' + name : ' (anonymous)') + ']' + (keys.length > 0 ? ' { ' + keys.join(', ') + ' }' : ''); | ||
} | ||
if (isSymbol(obj)) { | ||
var symString = Symbol.prototype.toString.call(obj); | ||
var symString = symToString.call(obj); | ||
return typeof obj === 'object' ? markBoxed(symString) : symString; | ||
@@ -318,6 +322,10 @@ } | ||
var x = { | ||
8: 'b', 9: 't', 10: 'n', 12: 'f', 13: 'r' | ||
8: 'b', | ||
9: 't', | ||
10: 'n', | ||
12: 'f', | ||
13: 'r' | ||
}[n]; | ||
if (x) { return '\\' + x; } | ||
return '\\x' + (n < 0x10 ? '0' : '') + n.toString(16); | ||
return '\\x' + (n < 0x10 ? '0' : '') + n.toString(16).toUpperCase(); | ||
} | ||
@@ -386,3 +394,11 @@ | ||
} | ||
if (typeof gOPS === 'function') { | ||
var syms = gOPS(obj); | ||
for (var j = 0; j < syms.length; j++) { | ||
if (isEnumerable.call(obj, syms[j])) { | ||
xs.push('[' + inspect(syms[j]) + ']: ' + inspect(obj[syms[j]], obj)); | ||
} | ||
} | ||
} | ||
return xs; | ||
} |
{ | ||
"name": "object-inspect", | ||
"version": "1.8.0", | ||
"version": "1.9.0", | ||
"description": "string representations of objects in node and the browser", | ||
"main": "index.js", | ||
"devDependencies": { | ||
"@ljharb/eslint-config": "^17.1.0", | ||
"aud": "^1.1.2", | ||
"core-js": "^2.6.11", | ||
"eslint": "^7.1.0", | ||
"@ljharb/eslint-config": "^17.3.0", | ||
"aud": "^1.1.3", | ||
"core-js": "^2.6.12", | ||
"eslint": "^7.14.0", | ||
"for-each": "^0.3.3", | ||
@@ -22,6 +22,6 @@ "nyc": "^10.3.2", | ||
"test": "npm run tests-only", | ||
"pretests-only": "node test-core-js", | ||
"tests-only": "tape test/*.js", | ||
"posttest": "npx aud --production", | ||
"coverage": "nyc npm run tests-only" | ||
"tests-only": "nyc npm run tests-only:tape", | ||
"pretests-only:tape": "node test-core-js", | ||
"tests-only:tape": "tape 'test/*.js'", | ||
"posttest": "npx aud --production" | ||
}, | ||
@@ -28,0 +28,0 @@ "testling": { |
@@ -5,6 +5,13 @@ var inspect = require('../'); | ||
test('circular', function (t) { | ||
t.plan(1); | ||
t.plan(2); | ||
var obj = { a: 1, b: [3, 4] }; | ||
obj.c = obj; | ||
t.equal(inspect(obj), '{ a: 1, b: [ 3, 4 ], c: [Circular] }'); | ||
var double = {}; | ||
double.a = [double]; | ||
double.b = {}; | ||
double.b.inner = double.b; | ||
double.b.obj = double; | ||
t.equal(inspect(double), '{ a: [ [Circular] ], b: { inner: [Circular], obj: [Circular] } }'); | ||
}); |
@@ -5,6 +5,7 @@ var inspect = require('../'); | ||
test('deep', function (t) { | ||
t.plan(2); | ||
t.plan(3); | ||
var obj = [[[[[[500]]]]]]; | ||
t.equal(inspect(obj), '[ [ [ [ [ [Array] ] ] ] ] ]'); | ||
t.equal(inspect(obj, { depth: 4 }), '[ [ [ [ [Array] ] ] ] ]'); | ||
t.equal(inspect(obj, { depth: 2 }), '[ [ [Array] ] ]'); | ||
}); |
@@ -15,5 +15,5 @@ var inspect = require('../'); | ||
}()); | ||
f.toString = function () { return 'function xxx () {}'; }; | ||
f.toString = function toStr() { return 'function xxx () {}'; }; | ||
var obj = [1, 2, f, 4]; | ||
t.equal(inspect(obj), '[ 1, 2, [Function (anonymous)], 4 ]'); | ||
t.equal(inspect(obj), '[ 1, 2, [Function (anonymous)] { toString: [Function: toStr] }, 4 ]'); | ||
}); | ||
@@ -20,0 +20,0 @@ |
@@ -24,5 +24,23 @@ var test = require('tape'); | ||
t.equal(inspect([obj, []], { customInspect: true }), '[ ' + (utilInspect.custom ? 'symbol' : 'string') + ', [] ]'); | ||
t.equal(inspect([obj, []], { customInspect: false }), '[ { inspect: [Function: stringInspect] }, [] ]'); | ||
t.equal( | ||
inspect([obj, []], { customInspect: false }), | ||
'[ { inspect: [Function: stringInspect]' + (utilInspect.custom ? ', [' + inspect(utilInspect.custom) + ']: [Function: custom]' : '') + ' }, [] ]' | ||
); | ||
}); | ||
test('symbols', { skip: !hasSymbols }, function (t) { | ||
t.plan(2); | ||
var obj = { a: 1 }; | ||
obj[Symbol('test')] = 2; | ||
obj[Symbol.iterator] = 3; | ||
Object.defineProperty(obj, Symbol('non-enum'), { | ||
enumerable: false, | ||
value: 4 | ||
}); | ||
t.equal(inspect(obj), '{ a: 1, [Symbol(test)]: 2, [Symbol(Symbol.iterator)]: 3 }', 'object with symbols'); | ||
t.equal(inspect([obj, []]), '[ { a: 1, [Symbol(test)]: 2, [Symbol(Symbol.iterator)]: 3 }, [] ]', 'object with symbols'); | ||
}); | ||
test('maxStringLength', function (t) { | ||
@@ -29,0 +47,0 @@ t.equal( |
@@ -10,4 +10,4 @@ var test = require('tape'); | ||
inspect(obj), | ||
"{ x: 'a\\r\\nb', y: '\\x05! \\x1f \\x12' }" | ||
"{ x: 'a\\r\\nb', y: '\\x05! \\x1F \\x12' }" | ||
); | ||
}); |
@@ -170,3 +170,7 @@ var inspect = require('../'); | ||
var match = 'abc abc'.match(/[ab]+/); | ||
delete match.groups; // for node < 10 | ||
t.equal(inspect(match), '[ \'ab\', index: 0, input: \'abc abc\' ]', 'RegExp match object shows properly'); | ||
t.end(); | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
49222
36
1088