{"id":20472,"library":"pretty-format2","title":"pretty-format2","description":"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.","status":"active","version":"2.0.4","language":"javascript","source_language":"en","source_url":"https://github.com/thejameskyle/pretty-format2","tags":["javascript"],"install":[{"cmd":"npm install pretty-format2","lang":"bash","label":"npm"},{"cmd":"yarn add pretty-format2","lang":"bash","label":"yarn"},{"cmd":"pnpm add pretty-format2","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used for color support in terminal output","package":"ansi-styles","optional":true},{"reason":"Used for detecting React elements and determining their type","package":"react-is","optional":true}],"imports":[{"note":"The package is ESM-only; CommonJS require is not supported.","wrong":"const prettyFormat = require('pretty-format2')","symbol":"prettyFormat","correct":"import { prettyFormat } from 'pretty-format2'"},{"note":"Plugins are exported as a named export from the main entry, not a separate path.","wrong":"import plugins from 'pretty-format2/plugins'","symbol":"plugins","correct":"import { plugins } from 'pretty-format2'"},{"note":"Use type import for TypeScript types to avoid runtime bundling issues.","wrong":"import { PrettyFormatOptions } from 'pretty-format2'","symbol":"PrettyFormatOptions","correct":"import type { PrettyFormatOptions } from 'pretty-format2'"}],"quickstart":{"code":"import { prettyFormat } from 'pretty-format2';\n\nconst obj = {\n  name: 'example',\n  nested: { a: 1, b: 2 },\n  date: new Date('2023-01-01'),\n  regex: /test/gi,\n  fn: function() { return true; },\n  [Symbol('id')]: 42,\n};\n\nconst formatted = prettyFormat(obj, {\n  indent: 2,\n  printFunctionName: true,\n  highlight: true,\n  theme: {\n    key: 'yellow',\n    string: 'green',\n    number: 'blue',\n    boolean: 'magenta',\n    null: 'red',\n    undefined: 'grey',\n  },\n});\n\nconsole.log(formatted);","lang":"typescript","description":"Demonstrates basic usage of prettyFormat with options for indentation, function name printing, color theme, and highlighting."},"warnings":[{"fix":"Pin to exact version and monitor releases for changes.","message":"The package is marked as WIP and experimental; no stable release yet. Breaking changes may occur between minor versions.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Use ESM import with named syntax: import { prettyFormat } from 'pretty-format2'.","message":"Version 2.0.0 changed from a default export to named exports. CommonJS require broke.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Replace `colors` with `theme` in the options object.","message":"The option 'colors' was renamed to 'theme' in version 2.0.0. The old name still works but will be removed in a future release.","severity":"deprecated","affected_versions":">=2.0.0 <3.0.0"},{"fix":"Pre-check environment or provide a polyfill for ANSI sequences.","message":"Highlight option only works in Node.js terminals that support ANSI escape codes. Browser output may show raw codes.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Install react-is as a dependency: npm install react-is","message":"React element detection requires the optional dependency 'react-is'. If not installed, React elements will print as plain objects.","severity":"gotcha","affected_versions":">=2.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Switch to ESM import: import { prettyFormat } from 'pretty-format2'","cause":"Using CommonJS require on an ESM-only package.","error":"TypeError: prettyFormat is not a function"},{"fix":"Upgrade Node.js to version 12 or later, or use a transpiler like Babel.","cause":"Using older Node.js version (<12) that doesn't support ESM syntax.","error":"SyntaxError: Unexpected token 'export'"},{"fix":"Install ansi-styles manually: npm install ansi-styles","cause":"Optional dependency ansi-styles not installed but tried to use color theme.","error":"Module not found: Can't resolve 'ansi-styles'"},{"fix":"Use: prettyFormat(obj, { highlight: true })","cause":"Passing options incorrectly: highlight should be a boolean, not invoked as a method.","error":"prettyFormat(...).highlight is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}