Prints a JSON structure (or any POJO) to the console. Can print to a single line or to a tree structure.
Install the package using NPM or Yarn:
npm install pojo-dump # or yarn add pojo-dump
The library provides the following exports:
toLine
: Formats data into a compact, single-line JSON-like representation.toTree
: Formats data into a tree-like structure for better readability.logTree
: Logs the tree-like structure to the console.Print to a single line:
import { toLine } from 'pojo-dump'; const data = [null, true, false, 123, 0.1, 'as\ndf', [1, 2, 3], { foo: 'bar' }]; console.log(toLine(data)); // [ !n, !t, !f, 123, .1, "as" ⏎ "df", [ 1, 2, 3 ], { foo = "bar" } ]
Print to a multi-line tree layout:
import { toTree } from 'pojo-dump'; const data = { foo: 'bar', nested: [1, 2, { key: 'value' }] }; console.log(toTree(data)); /* Output: ╿ ├─ foo = "bar" └─ nested ├─ [0]: 1 ├─ [1]: 2 └─ [2] └─ key = "value" */
Constant literals:
console.log(toLine([true, false, null, undefined])); // Output: [ !t, !f, !n, !u ]
Number literals:
console.log(toLine([1000, 0.1])); // Output: [ 1,000, .1 ]
Formatting strings with special characters:
console.log(toLine('hello\nworld')); // Output: "hello" ⏎ "world"
Formatting binary data:
console.log(toLine(new Uint8Array([104, 101, 108, 108, 111]))); // Output: Uint8Array { 68 65 6C 6C 6F }
Apache 2.0
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4