Registry / serialization / object-inspect

object-inspect

JSON →
library1.13.4jsnpmunverified

object-inspect is a robust JavaScript utility that provides string representations of arbitrary JavaScript objects, designed for both Node.js and browser environments. Its primary function is to serialize objects into a human-readable string, handling complex data structures like circular references, DOM elements, and various built-in types (e.g., Map, Set, WeakMap, WeakSet, BigInt, WeakRef). The current stable version is 1.13.4. While there isn't a strict release cadence, the project actively incorporates support for new JavaScript features and addresses edge cases, with recent updates adding WeakRef and BigInt support. Key differentiators include its configurable output through options like `depth`, `quoteStyle`, `maxStringLength`, `customInspect`, `indent`, and `numericSeparator`, allowing fine-grained control over the serialization process, making it a versatile alternative or complement to Node.js's built-in `util.inspect` where cross-environment compatibility or customizability is paramount.

npm install object-inspect
INSTALL
IMPORT
SIG · OBJECT-INSPECT
O
object-inspect
serializationjavascriptv1.13.4
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

inspect
const inspect = require('object-inspect');
import inspect from 'object-inspect';
This is the correct CommonJS `require` pattern for Node.js environments. The package is primarily CJS-first, supporting Node.js versions as old as 0.4.
inspect
import inspect from 'object-inspect';
const inspect = require('object-inspect');
For ES Modules, `import inspect from 'object-inspect'` is the standard. If using TypeScript, ensure `esModuleInterop` is enabled in `tsconfig.json` for proper type resolution; otherwise, you might need `import inspect = require('object-inspect');`.

Demonstrates `object-inspect`'s ability to handle circular references, control output depth and formatting, and serialize various built-in and primitive types like BigInt, Date, and Map.

const inspect = require('object-inspect'); // Example 1: Circular reference handling const obj = { a: 1, b: [3, 4] }; obj.c = obj; console.log('Circular object:', inspect(obj)); // Expected output: Circular object: { a: 1, b: [ 3, 4 ], c: [Circular] } // Example 2: Deep object with truncation and custom quote style const deepObj = { a: { b: { c: [1, 2, { d: 'hello world string longer than max length example' }], }, }, func: function myFunc() {}, sym: Symbol('test'), }; console.log('\nDeep object (default):', inspect(deepObj)); console.log('Deep object (depth=2, maxStringLength=10, quoteStyle=\'single\'):', inspect(deepObj, { depth: 2, maxStringLength: 10, quoteStyle: 'single' })); // Example 3: BigInt, Date, and Map objects with numeric separators and indent const mixedData = { id: 123456789012345678901234567890n, // BigInt date: new Date('2023-10-26T10:00:00Z'), map: new Map([['key1', 'val1'], ['key2', 'val2']]), }; console.log('\nMixed data (numericSeparator=true, indent=\' \'):', inspect(mixedData, { numericSeparator: true, indent: ' ' }));
Debug
Known issues
gotchaThe `customInspect` option, introduced in v1.8.0, defaults to `true`. This means if an object has a `Symbol.for('nodejs.util.inspect.custom')` method or an `inspect` property (for compatibility), it will be invoked. If you intend to bypass custom inspect methods and always get `object-inspect`'s default string representation, set `customInspect: false`.
fix
Use `inspect(obj, { customInspect: false })` to ignore custom inspect methods, or `inspect(obj, { customInspect: 'symbol' })` to only respect symbol-based custom methods.
affects: >=1.8.0
gotcha`object-inspect` aims for compatibility with Node.js's `util.inspect` but is a separate, cross-environment utility. Its output may not always perfectly mirror the exact string representation provided by Node.js's built-in `util.inspect`, especially with evolving Node.js versions or highly specific edge cases.
fix
For critical Node.js-specific inspection, prefer `require('util').inspect` if the environment is guaranteed to be Node.js. Use `object-inspect` when cross-environment consistency or specific custom options are prioritized.
affects: All versions
gotchaWhen inspecting DOM elements in a browser environment, `object-inspect` provides a concise representation (e.g., `<div id="beep">...</div>`). It does not perform full HTML serialization or provide detailed child node information beyond an ellipsis for brevity.
fix
If detailed HTML or full DOM tree serialization is required, use browser-native APIs like `element.outerHTML` or `new XMLSerializer().serializeToString(document)`.
affects: All versions
Errors
Common errors & fixes
TypeError: inspect is not a function
The `inspect` function was not correctly imported or required into the current module context.
fix
In CommonJS modules, use `const inspect = require('object-inspect');`. In ES Modules, use `import inspect from 'object-inspect';`. Verify module type configuration if using TypeScript.
Object output is truncated or lacks detail (e.g., `[Object]`, `[Array]`, or short strings)
The default `depth` or `maxStringLength` options are limiting the output's detail, or you have not explicitly configured them for your needs.
fix
Increase the `depth` option (e.g., `inspect(obj, { depth: Infinity })` for full depth) and/or adjust `maxStringLength` (e.g., `inspect(obj, { maxStringLength: null })` for no string truncation) in the `inspect` function call.
Upgrade
Version history
1.13.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
object-inspect — npm install object-inspect · libregistry