# purdy

> Pretty print objects in real purdy colors. Allows clearer visualization of objects than you get from most pretty printers due to colors. It will also print out the complete path to an object, something that's extremely useful for debugging. Purdy will als

Latest version **3.6.0** (published 2024-07-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install purdy
pnpm add purdy
yarn add purdy
bun add purdy
```

Provides the command `purdy`.

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.6.0 |
| Published | 2024-07-20 |
| First published | 2014-05-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/purdy) |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 17.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 133 |
| Author | Daniel Bretoi |
| Maintainers | danielb |
| Keywords | ansi, terminal, colors, pretty, print, color |

## Links

- npm: https://www.npmjs.com/package/purdy
- Repository: https://github.com/danielb2/purdy.js
- Issues: https://github.com/danielb2/purdy.js/issues
- npm.io page: https://npm.io/package/purdy

## Dependencies (3)

- [joi](https://npm.io/package/joi.md) ^17.0.0
- [chalk](https://npm.io/package/chalk.md) ^2.4.1
- [@hapi/bossy](https://npm.io/package/@hapi/bossy.md) ^6.0.1

## Alternatives

- [postcss-color-hex-alpha](https://npm.io/package/postcss-color-hex-alpha.md) — 6.4M weekly downloads
- [randomcolor](https://npm.io/package/randomcolor.md) — 348.0K weekly downloads
- [bows](https://npm.io/package/bows.md) — 1.3K weekly downloads
- [ep_prefer_color_scheme](https://npm.io/package/ep_prefer_color_scheme.md) — 260 weekly downloads
- [coc-yank](https://npm.io/package/coc-yank.md) — 61 weekly downloads

## Recent versions

- 3.6.0 (latest) — 2024-07-20
- 3.5.2 — 2024-07-11
- 3.5.1 — 2019-05-08
- 3.5.0 — 2019-05-08
- 3.4.1 — 2018-10-10
- 3.4.0 — 2018-10-10
- 3.3.0 — 2018-07-13
- 3.2.1 — 2018-07-13
- 3.2.0 — 2018-07-13
- 3.1.1 — 2018-06-05
- 3.1.0 — 2018-04-16
- 3.0.2 — 2017-08-25
- 2.2.1 — 2017-03-01
- 2.2.0 — 2016-05-22
- 2.1.0 — 2016-05-20
- … 31 more at https://npm.io/package/purdy/versions

## README

# Purdy ![build](https://travis-ci.org/danielb2/purdy.js.svg) ![coverage](https://img.shields.io/badge/coverage-100%25-green.svg)

Print things real purdy for nodejs.

## Usage

```javascript
    const Purdy = require('purdy');
    Purdy({list: [1,2,3], string: 'some string'});
```

### `Purdy(object, [options])`

![image](https://github.com/danielb2/purdy/raw/master/example.png)

Prints anything indented, and with arrays with index keys, and different
types in colors such that it's very easy to get an overview of what object
you're dealing with.

* `object` - anything, number, object, array, etc.
* `options` - optional object with the following keys.
    * `plain` - when `true`, prints result without colors. Defaults to `false` with tty, `true` when not.
    * `path` - when `true`, prints result with a path (To be used with [Hoek.reach()](https://github.com/spumko/hoek#reachobj-chain-options) or lodash.get, etc). Default: `false`
    * `pathPrefix` - prefix for path. Default: `// `
    * `arrayIndex` - enables index printing for arrays. Default: `true`
    * `indent` - defines the number of spaces to indent. Default: `4`
    * `align` - determines how to align object keys. Default: `left`
    * `depth` - tells purdy how many times to recurse while formatting the object. This is useful for viewing complicated objects. Default: `2`. Set to `null` to recurse indefinitely
    * `proto` - include the prototype chain and print all inherited properties as well. Default: `false`
    * `json` - attempt to parse strings beginning with { as JSON. Default: `false`


### `Purdy.stringify(object, [options])`

This function returns a string without printing it to stdout. This may prove
to be useful for log files other other applications.

``` javascript
const purdyString = Purdy.stringify({a: 'b'}, {plain: true});
writeLog(purdyString);
```

### `Purdy.purdy([options]);`

Useful if you want to print multiple objects like console.log

``` javascript
const purdy = Purdy.purdy({plain: true});
purdy.print('one', 'two');
purdy.stringify('one', 'two');
```

### Examples

The following code prints what's in the image above.

``` javascript
const mises = function mises () { this.moop = 3 }
const instance = new mises();
const circularObj = { };
circularObj.a = circularObj;
const obj = {
    integer: Date.now(),
    string: 'foo',
    anonPurdy: Purdy,
    defined: function Yes() {},
    nested: {hello: 'hapi'},
    error: new Error('bad'),
    null: null,
    undefined: undefined,
    regexp: new RegExp,
    falseBool: false,
    trueBool: true,
    symbol: Symbol('purdy'),
    emptyArr: [],
    circular: circularObj,
    date: new Date(),
    arrayWithVisibleIndex: [ 'one', 'two', 'three' ],
    instance: instance,
};
Purdy(obj);

```


### Command-line Interface

This package also installs the `purdy` CLI tool. Right now this just prints
any JSON file with default options.

`purdy package.json` will, for example, print the JSON contents of
package.json.

Similarly, `cat package.json | purdy -s`  will use stdin to print the contents.

A new option `-l` has been added to parse log files for newline delimited JSON (NDJSON).

`purdy -l logfile.log` will print that or `cat app.log | purdy -l -s`

## Contributing

This project adheres to the [hapi styleguide](https://github.com/hapijs/contrib/blob/master/Style.md).

## Acknowledgements
* Michael Dvorkin for [Awesome Print]

[Awesome Print]: https://github.com/michaeldv/awesome_print

---
_Source: https://npm.io/package/purdy · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
