Gathering detailed insights and metrics for @tduyng/prettyoutput
Gathering detailed insights and metrics for @tduyng/prettyoutput
Gathering detailed insights and metrics for @tduyng/prettyoutput
Gathering detailed insights and metrics for @tduyng/prettyoutput
A high-performance Node.js library for pretty JavaScript and JSON objects.
npm install @tduyng/prettyoutput
Typescript
Module System
Min. Node Version
Node Version
NPM Version
TypeScript (91.82%)
JavaScript (8.02%)
Shell (0.16%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
120 Commits
1 Watchers
1 Branches
4 Contributors
Updated on Mar 28, 2025
Latest Version
2.0.1
Package Id
@tduyng/prettyoutput@2.0.1
Unpacked Size
153.94 kB
Size
34.55 kB
File Count
48
NPM Version
10.9.2
Node Version
22.13.1
Published on
Feb 20, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
@tduyng/prettyoutput is a fast, customizable library for formatting JavaScript/JSON objects into a human-readable, YAML-style output.
node:util.inspect
.commander.js
for CLI.1npm add @tduyng/prettyoutput 2yarn add @tduyng/prettyoutput 3pnpm add @tduyng/prettyoutput
@tduyng/prettyoutput is extremely easy to use. Just require it in your project and call the function with your data:
1import { prettyOutput } from '@tduyng/prettyoutput' 2 3const data = { 4 username: 'tduyng', 5 url: 'https://github.com/tduyng', 6 projects: ['@tduyng/prettyoutput', '@tduyng/logger'], 7} 8 9console.log(prettyOutput(data))
Sample output:
1username: tduyng 2url: https://github.com/tduyng 3projects: 4 - @tduyng/prettyoutput 5 - @tduyng/logger
Other example:
prettyOutput(data, options, indent)
1- {\*} data : The JavaScript or JSON object to format 2- {Object} [options] : Optional. See options below 3- {number} [indent] : Optional. Indent all output
1- {number} [indentationLength] : Length of indentation (in terms of space) 2- {number} [maxDepth] : maximum sublevel of nested objects/arrays output. Default: 3 3- {boolean}[noColor] : disable colors. Default: false 4- {colors} [colors] : Output colors. See below 5- {boolean}[alignKeyValues] : Align key values. Default: true 6- {boolean}[hideUndefined] : Do not display undefined values. Default: false
1- {string} [keys] : Objects keys color. Default: green 2- {string} [dash] : Array prefixing dash ("- "). Default: green 3- {string} [number] : Numbers color. Default: blue 4- {string} [string] : Strings color. Default: no color 5- {string} [true] : Boolean value 'true' color. Default: green 6- {string} [false] : Boolean value 'false' color. Default: red 7- {string} [null] : 'Null' color. Default: grey 8- {string} [undefined] : 'Undefined' color. Default: grey
Example using options :
1import { prettyOutput } from '@tduyng/prettyoutput' 2 3const data = { 4 username: 'tduyng', 5 url: 'https://github.com/tduyng', 6 projects: ['@tduyng/prettyoutput', '@tduyng/logger'], 7} 8 9const options = { 10 noColor: true, 11 maxDepth: 5, 12 colors: { 13 keys: 'blue', 14 null: 'red', 15 }, 16} 17 18console.log(prettyOutput(data, options, 2))
You can also use prettyoutput directly from the command line to format files or standard input.
You can also use prettyoutput directly from the command line to format files or standard input.
There are multiple aliases available for the CLI, allowing you to use the command that best fits your workflow:
1# Pretty print a JSON file 2pretty package.json # for ESM 3prettyoutput package.json # for ESM 4pretty-cjs package.json # for CJS 5prettyoutput-cjs package.json # for CJS
Example CLI Output:
--indent
: Set the indentation level (default: 2).--depth
: Limit the depth of object printing (default: 3).--noColor
: Disable colored output.1# Format with custom indentation, depth, and no color 2prettyoutput --indent=4 --depth=5 --noColor package.json
or
1# Indent 4, max depth 5, disable colors 2cat package.json | prettyoutput --indent=4 --depth=5 --noColor
1# Pretty print a JSON file 2prettyoutput package.json # for ESM 3pretty package.json # for ESM 4prettyoutput-cjs package.json # for CJS 5pretty-cjs package.json # for CJS
Example CLI Output:
--indent
: Set the indentation level (default: 2).--depth
: Limit the depth of object printing (default: 3).--noColor
: Disable colored output.1# Format with custom indentation, depth, and no color 2prettyoutput --indent=4 --depth=5 --noColor package.json
or
1# Indent 4, max depth 5, disable colors 2cat package.json | prettyoutput --indent=4 --depth=5 --noColor
Performance is key for logging, and prettyoutput is built to be fast. Compared to alternatives like util.inspect
and prettyjson
, it consistently performs 1.x-3.x times faster.
1pnpm run benchmark
Tested on Node.js 22.8.0
1LEVELS | KEYS | LOOPS | WEIGHTS 23 | 20 | 100 | serializable: 0.9 array: 0.3 object: 0.5 multilineString: 0.3 error: 0.2 3 4NAME | MIN | MAX | MEAN | TOTAL 5prettyoutput | 1 ms 417 µs 200 ns | 35 ms 930 µs 467 ns | 2 ms 5 µs 439 ns | 200 ms 543 µs 970 ns 6prettyjson | 4 ms 56 µs 696 ns | 9 ms 317 µs 632 ns | 4 ms 473 µs 214 ns | 447 ms 321 µs 437 ns 7util.inspect | 3 ms 895 µs 505 ns | 12 ms 743 µs 60 ns | 4 ms 463 µs 826 ns | 446 ms 382 µs 620 ns 8@poppinss/dumper | 12 ms 185 µs 629 ns | 24 ms 81 µs 159 ns | 14 ms 167 µs 609 ns | 1 s 416 ms 760 µs 966 ns 9-------------------------------------------------------------------------------------------------------------- 10 11 12LEVELS | KEYS | LOOPS | WEIGHTS 134 | 20 | 100 | serializable: 0.9 array: 0.3 object: 0.5 multilineString: 0.3 error: 0.2 14 15NAME | MIN | MAX | MEAN | TOTAL 16prettyoutput | 7 ms 741 µs 194 ns | 118 ms 124 µs 145 ns | 11 ms 263 µs 170 ns | 1 s 126 ms 317 µs 3 ns 17prettyjson | 18 ms 281 µs 941 ns | 28 ms 144 µs 657 ns | 19 ms 861 µs 800 ns | 1 s 986 ms 180 µs 75 ns 18util.inspect | 28 ms 601 µs 804 ns | 57 ms 71 µs 136 ns | 31 ms 647 µs 947 ns | 3 s 164 ms 794 µs 787 ns 19@poppinss/dumper | 61 ms 791 µs 290 ns | 94 ms 660 µs 42 ns | 69 ms 241 µs 879 ns | 6 s 924 ms 187 µs 908 ns 20-------------------------------------------------------------------------------------------------------------- 21 22 23LEVELS | KEYS | LOOPS | WEIGHTS 244 | 40 | 200 | serializable: 0.9 array: 0.3 object: 0.5 multilineString: 0.3 error: 0.2 25 26NAME | MIN | MAX | MEAN | TOTAL 27prettyoutput | 322 ms 378 µs 833 ns | 2 s 470 ms 343 µs 997 ns | 408 ms 177 µs 619 ns | 81 s 635 ms 523 µs 870 ns 28prettyjson | 413 ms 885 µs 631 ns | 949 ms 765 µs 323 ns | 498 ms 554 µs 581 ns | 99 s 710 ms 916 µs 350 ns 29util.inspect | 728 ms 839 µs 615 ns | 1 s 938 ms 281 µs 319 ns | 838 ms 188 µs 569 ns | 167 s 637 ms 713 µs 859 ns 30@poppinss/dumper | 1 s 389 ms 498 µs 39 ns | 2 s 445 ms 781 µs 141 ns | 1 s 634 ms 909 µs 384 ns | 326 s 981 ms 876 µs 857 ns 31-------------------------------------------------------------------------------------------------------------- 32 33 34LEVELS | KEYS | LOOPS | WEIGHTS 355 | 20 | 100 | serializable: 0.9 array: 0.3 object: 0.5 multilineString: 0.3 error: 0.2 36 37NAME | MIN | MAX | MEAN | TOTAL 38prettyoutput | 201 ms 29 µs 587 ns | 1 s 651 ms 200 µs 25 ns | 245 ms 777 µs 771 ns | 24 s 577 ms 777 µs 190 ns 39prettyjson | 229 ms 631 µs 36 ns | 467 ms 527 µs 984 ns | 269 ms 62 µs 662 ns | 26 s 906 ms 266 µs 294 ns 40util.inspect | 828 ms 156 µs 412 ns | 1 s 884 ms 775 µs 777 ns | 920 ms 237 µs 642 ns | 92 s 23 ms 764 µs 261 ns 41@poppinss/dumper | 889 ms 54 µs 772 ns | 1 s 323 ms 199 µs 230 ns | 1 s 14 ms 384 µs 206 ns | 101 s 438 ms 420 µs 665 ns 42--------------------------------------------------------------------------------------------------------------
For detailed benchmark results, refer to the benchmark documentation.
Clone the repository and install development dependencies:
1pnpm install
Run tests:
1pnpm run test 2# or pnpm run coverage
If you'd like to contribute to this project, feel free to submit issues and pull requests. Contributions are always welcome!
@tduyng/prettyoutput is based on the original prettyoutput project, which is now archived. Special thanks to @bnadim for creating the original project, and to all contributors who helped enhance it over time.
No vulnerabilities found.
No security vulnerabilities found.