Registry / serialization / pretty-format2

pretty-format2

JSON →
library2.0.4jsnpmunverified

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-format2
INSTALL
IMPORT
SIG · PRETTY-FORMAT2
P
pretty-format2
serializationjavascriptv2.0.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.

prettyFormat
import { prettyFormat } from 'pretty-format2'
const prettyFormat = require('pretty-format2')
The package is ESM-only; CommonJS require is not supported.
plugins
import { plugins } from 'pretty-format2'
import plugins from 'pretty-format2/plugins'
Plugins are exported as a named export from the main entry, not a separate path.
PrettyFormatOptions
import type { PrettyFormatOptions } from 'pretty-format2'
import { PrettyFormatOptions } from 'pretty-format2'
Use type import for TypeScript types to avoid runtime bundling issues.

Demonstrates basic usage of prettyFormat with options for indentation, function name printing, color theme, and highlighting.

import { prettyFormat } from 'pretty-format2'; const obj = { name: 'example', nested: { a: 1, b: 2 }, date: new Date('2023-01-01'), regex: /test/gi, fn: function() { return true; }, [Symbol('id')]: 42, }; const formatted = prettyFormat(obj, { indent: 2, printFunctionName: true, highlight: true, theme: { key: 'yellow', string: 'green', number: 'blue', boolean: 'magenta', null: 'red', undefined: 'grey', }, }); console.log(formatted);
Debug
Known issues
gotchaThe package is marked as WIP and experimental; no stable release yet. Breaking changes may occur between minor versions.
fix
Pin to exact version and monitor releases for changes.
affects: >=2.0.0
breakingVersion 2.0.0 changed from a default export to named exports. CommonJS require broke.
fix
Use ESM import with named syntax: import { prettyFormat } from 'pretty-format2'.
affects: >=2.0.0
deprecatedThe option 'colors' was renamed to 'theme' in version 2.0.0. The old name still works but will be removed in a future release.
fix
Replace `colors` with `theme` in the options object.
affects: >=2.0.0 <3.0.0
gotchaHighlight option only works in Node.js terminals that support ANSI escape codes. Browser output may show raw codes.
fix
Pre-check environment or provide a polyfill for ANSI sequences.
affects: >=2.0.0
gotchaReact element detection requires the optional dependency 'react-is'. If not installed, React elements will print as plain objects.
fix
Install react-is as a dependency: npm install react-is
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: prettyFormat is not a function
Using CommonJS require on an ESM-only package.
fix
Switch to ESM import: import { prettyFormat } from 'pretty-format2'
SyntaxError: Unexpected token 'export'
Using older Node.js version (<12) that doesn't support ESM syntax.
fix
Upgrade Node.js to version 12 or later, or use a transpiler like Babel.
Module not found: Can't resolve 'ansi-styles'
Optional dependency ansi-styles not installed but tried to use color theme.
fix
Install ansi-styles manually: npm install ansi-styles
prettyFormat(...).highlight is not a function
Passing options incorrectly: highlight should be a boolean, not invoked as a method.
fix
Use: prettyFormat(obj, { highlight: true })
Upgrade
Version history
2.0.4latest on npm
Audit
Dependencies
ansi-stylesoptionalUsed for color support in terminal output
react-isoptionalUsed for detecting React elements and determining their type
Agent activity
2 hits · last 30 days
node
2
Resources
pretty-format2 — npm install pretty-format2 · libregistry