modern-inspect
v0.0.3
Published
Modern way to format any value into string representations.
Maintainers
Readme
modern-inspect
A modern library to format any value into a string representation.
Works much like Node.js - util.inspect, but without relying on the Node.js runtime. It's usually intended for debugging (displaying) any value in the terminal console or formatting it as plain text for logs.
Features
- 🚀 Super tiny (
~1.5kBgzipped) with no dependencies - 📦 Works in browsers, Node.js, and other environments
- 🎩 Modern implementation
- 💪🏻 Full TypeScript support
Usage
pnpm i modern-inspectimport { inspect } from 'modern-inspect';
inspect(1); // => "1"
inspect({ foo: 'bar' }); // => "{foo: 'bar'}"
inspect([
true,
new URL('https://example.com'),
/** some circular obj */
/** Map, Set, ... */
]);
// => "[true, URL(https://example.com), Circular(~), Map(2) {...}, Set(2) [...]]"Options
interface InspectOptions {
/**
* If output compacted string (removing newlines and indentation)
*
* @default false
*/
compact?: boolean
/**
* Filter out specific properties from the object.
*/
filter?: (obj: any, prop: string | number | symbol) => boolean
/**
* Customize specific value's stringified result.
*/
transform?: (obj: any, prop: string | number | symbol, stringified: string) => string
}Thanks
💚 This library is mainly based on (or a fork implementation of) these excellent projects:
