obj-console
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

obj-console

Beautify terminal output of JS-objects with VSCode colors and custom format. 10K dist with no dependencies.

You can tune output to enhance readability of single objects or arrays. Or print compact brief of data just to understand, that data has appropriate form. For example, options: {unfoldDepth: 1, omitBrackets: true, omitEolCommas: true, quote: "", align: true} leads to output:

columns-object

unfold depth

Usage

import { objConsole, objFormat } from 'obj-console';

objConsole(someData);
objConsole(someData, options);

const str = objFormat(someData); // just format, no print
console.log(str); // same as objConsole(someData)

Options

interface FormatOptions {
  omitBrackets?: boolean;
  /** Ommit commas at the end of lines even in arrays */
  omitEolCommas?: boolean;
  /** Quotation marks to surround strings */
  quote?: "" | "'" | "\"";
  /** Quotation marks to surround keys in objects */
  keyQuote?: "" | "'" | "\"";
  /** All elemetns with index higher then `maxArrayLength`
   * will be ommited, text `...overall {n} elements` wil be added at the end */
  maxArrayLength?: number;
  /** Strings will be cutted to `maxStringLength`
   * text `... +{n}chrs` wil be added at the end */
  maxStringLength?: number;
  /** Maximum depth to scan object */
  maxDepth?: number;
  /** Spaces or other symbols for left padding  */
  padding?: string;
  /** Works on 1-st level */
  align?: boolean;
  /** If depth is more then `unfoldDepth`,
   * then objects will be printed in one line */
  unfoldDepth?: number;
}

Predefined options

import { objConsole, BRIEF } from 'obj-console';

objConsole(someData, BRIEF);
  • COMPACT
  • BRIEF
  • ONE_LINE
  • AS_JSON
  • COLUMNS

brief

Package Sidebar

Install

npm i obj-console

Weekly Downloads

3

Version

1.0.2

License

ISC

Unpacked Size

72.7 kB

Total Files

28

Last publish

Collaborators

  • mkant