0.1.1 • Published 1 year ago

@builtbyastrals/prettion v0.1.1

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

prettion

A simple utility to prettify JSON output for terminal debugging with color support.

Requirements

  • Node.js >= 18.0.0

Installation

npm install @builtbyastrals/prettion

Usage

const prettion = require('@builtbyastrals/prettion').default;
// or using ES modules
// import prettion from '@builtbyastrals/prettion';

// Example usage with an API response object
const response = {
  status: 'success',
  data: {
    users: [
      { id: 1, name: 'John', active: true },
      { id: 2, name: 'Jane', active: false }
    ],
    totalCount: 2
  }
};

// Pretty print with default options (colored output with 2-space indentation)
console.log(prettion(response));

// Customize formatting
console.log(prettion(response, {
  indent: 4,        // Use 4 spaces for indentation
  colors: true,     // Enable colors (default)
  sortKeys: true    // Sort object keys alphabetically
}));

// Prettify a JSON string
const jsonString = '{"name":"John","age":30,"isActive":true}';
console.log(prettion(jsonString));

Options

OptionTypeDefaultDescription
indentnumber2Number of spaces for indentation
colorsbooleantrueEnable colored output
sortKeysbooleanfalseSort object keys alphabetically

Features

  • Pretty-prints JSON with proper indentation
  • Syntax highlighting with colors for better readability
  • Handles both JSON objects and strings
  • Customizable indentation
  • Option to sort object keys alphabetically
  • Graceful handling of invalid inputs

License

MIT

0.1.1

1 year ago

0.1.0

1 year ago