Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Hold on, we're currently generating a fresh version of this report
Generated on Jun 25, 2024 via pnpm

pretty-format 29.7.0

Stringify any JavaScript value.
Package summary
Share
0
issues
1
license
5
MIT
Package created
8 Mar 2015
Version published
12 Sep 2023
Maintainers
3
Total deps
5
Direct deps
3
License
MIT

Issues

0
This package has no issues

Licenses

MIT License

Permissive
OSI Approved
This is a human-readable summary of (and not a substitute for) the license. Disclaimer.
Can
commercial-use
modify
distribute
sublicense
private-use
Cannot
hold-liable
Must
include-copyright
include-license
5 Packages, Including:
@jest/schemas@29.6.3
@sinclair/typebox@0.27.8
ansi-styles@5.2.0
pretty-format@29.7.0
react-is@18.3.1
Disclaimer

This deed highlights only some of the key features and terms of the actual license. It is not a license and has no legal value. You should carefully review all of the terms and conditions of the actual license before using the licensed material.

Sandworm is not a law firm and does not provide legal services. Distributing, displaying, or linking to this deed or the license that it summarizes does not create a lawyer-client or any other relationship.

Direct Dependencies

3
All Dependencies CSV
β“˜ This is a list of pretty-format 's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.
NameVersionSizeLicenseTypeVulnerabilities
@jest/schemas29.6.31.94 kBMIT
prod
ansi-styles5.2.04.95 kBMIT
prod
react-is18.3.123.45 kBMIT
prod

Visualizations

Frequently Asked Questions

What does pretty-format do?

Pretty-format is a functional npm package to stringify JavaScript values, designed to serialize built-in JavaScript types and provide an easy way to serialize application-specific data types using built-in or user-specific plugins. It provides a decent way to display JavaScript objects in formatted, readable ways that are easy to understand.

How do you use pretty-format?

The installation process for pretty-format is remarkably straight-forward. Using the Yarn package manager through your terminal, you simply run the command yarn add pretty-format. Once installed, you can start using pretty-format by importing it into your project file:

In CommonJS,

const {format: prettyFormat} = require('pretty-format');

or in ES2015 modules,

import {format as prettyFormat} from 'pretty-format';

You can then leverage the prettyFormat function to format your JavaScript values. For example,

const val = {object: {}};
val.circularReference = val;
val[Symbol('foo')] = 'foo';
val.map = new Map([['prop', 'value']]);
val.array = [-0, Infinity, NaN];

console.log(prettyFormat(val)); // This will print the prettified version of the val object.

Additionally, pretty-format comes with a host of options to customize your stringifying needs. As an example:

function onClick() {}

const options = {
  printFunctionName: false,
};
console.log(prettyFormat(onClick, options)); // This will print '[Function]'

You can also use plugins to serialize application-specific data types. Here's how you do it with React elements:

import React from 'react';
import renderer from 'react-test-renderer';
import {plugins, format as prettyFormat} from 'pretty-format';

const {ReactElement, ReactTestComponent} = plugins;

const onClick = () => {};
const element = React.createElement('button', {onClick}, 'Hello World');

const formatted1 = prettyFormat(element, {
  plugins: [ReactElement],
  printFunctionName: false,
});

Where are the pretty-format docs?

Pretty-format documentation can be found on the official GitHub page of Jest where the package is hosted. It provides a detailed overview of how to use the package, the optional configurations, and also how to use it with plugins. This package is also integrated within Jest for snapshot tests. This makes it a go-to solution for developers using Jest for their tests or for those who want to take control of stringifying JavaScript values in a presentable and handy way.