pretty-format2 is a JavaScript library for stringifying any value into a human-readable format, designed to be faster and more feature-rich than alternatives like JSON.stringify, pretty-format, and util.inspect. Version 2.0.4 is a work-in-progress with no stable release yet; the package is experimental and subject to breaking changes. Key differentiators include support for plugins, custom indentation, color themes via ANSI escape codes, and a streaming API. It aims to be more performant than pretty-format and more customizable than util.inspect for both Node.js and browser environments.
npm install pretty-format2Verified import paths — ran on the pinned version, not inferred.
Demonstrates basic usage of prettyFormat with options for indentation, function name printing, color theme, and highlighting.
Pin to exact version and monitor releases for changes.
Use ESM import with named syntax: import { prettyFormat } from 'pretty-format2'.Replace `colors` with `theme` in the options object.
Pre-check environment or provide a polyfill for ANSI sequences.
Install react-is as a dependency: npm install react-is
Switch to ESM import: import { prettyFormat } from 'pretty-format2'Upgrade Node.js to version 12 or later, or use a transpiler like Babel.
Install ansi-styles manually: npm install ansi-styles
Use: prettyFormat(obj, { highlight: true })