Loupe Object Inspection Utility

3.2.1 · active · verified Sun Apr 19

Loupe is a robust, cross-platform utility for converting JavaScript objects into string representations, designed to work consistently in both Node.js and browser environments. It provides functionality similar to Node.js' built-in `util.inspect()`, making it a valuable tool for debugging and generating human-readable output of complex data structures. The current stable major version is `4.x`, with `v4.0.0` introducing significant breaking changes regarding custom inspection methods. The package maintains a moderate release cadence, with minor and patch updates preceding major version increments, reflecting ongoing development and refinement. As a core component within the Chai.js assertion library ecosystem, Loupe's key differentiator is its unified inspection behavior across diverse JavaScript runtimes, addressing the common challenge of inconsistent object serialization.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to import and use the `inspect` function with various data types, including objects, arrays, dates, regexes, functions, and a custom-inspectable object (v4.x style).

import { inspect } from 'loupe';

// Basic types
console.log(inspect({ foo: 'bar', baz: 123 }));
console.log(inspect([1, 'two', { three: 3 }]));
console.log(inspect(new Date('2023-01-15T10:00:00Z')));
console.log(inspect(/pattern/gi));

// Functions
function greet(name) { return `Hello, ${name}`; }
console.log(inspect(greet));

// Complex objects with custom inspection (v4.x compatible)
const customInspectable = {
  value: 'secret',
  [Symbol('nodejs.util.inspect.custom')]: function(depth, opts) {
    return `CustomObject { value: '${this.value.slice(0, 3)}...' }`;
  }
};
console.log(inspect(customInspectable));

// Errors and Promises
const error = new Error('Something went wrong');
console.log(inspect(error));
console.log(inspect(Promise.resolve(42)));

view raw JSON →