npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

json-to-plain-text

v1.1.4

Published

json-to-plain-text

Downloads

31,127

Readme

json-to-plain-text

Version Stars Download License Maintenance Issues GitHub Sponsors install size npm bundle size Known Vulnerabilities

json-to-plain-text is a npm module that converts JSON-like data or plain JavaScript objects to a formatted plain text representation. It allows you to convert JSON-like data or plain JavaScript objects into human-readable format.

Installation

  1. Install json-to-plain-text npm package.

    npm install json-to-plain-text
  2. Import the jsonToPlainText function:

    import { jsonToPlainText } from "json-to-plain-text";

Usage

The jsonToPlainText function accepts two parameters: data and options.

Parameters

  • data (required): The input data to convert. It can be JSON-like data or plain JavaScript objects.

  • options (optional): Configuration options for customizing the output. It is an object with the following properties:

    • color (boolean, default: true): Whether to apply colors to the output or not. Set to true to add colors using the chalk library or false for plain text output.

    • seperator (string, default: :): seperate keys and values.

    • spacing (boolean, default: true): Whether to include spacing before colons. Set to true for formatted spacing or false to remove spacing before colons.

    • squareBracketsForArray (boolean, default: false): Whether to use square brackets for arrays. Set to true to enclose arrays in square brackets or false to display arrays without brackets.

    • doubleQuotesForKeys (boolean, default: false): Whether to use double quotes for object keys. Set to true to wrap object keys in double quotes or false to keep them as they are.

    • doubleQuotesForValues (boolean, default: false): Whether to use double quotes for string values. Set to true to add double quotes around string values or false to display them without quotes.

Example

import { jsonToPlainText, Options } from "json-to-plain-text";

let data = {
  place_id: "173937105",
  osm_type: "way",
  osm_id: "319992693",
  lat: "17.861533866867224",
  lon: "78.8081441896764",
  display_name:
    "Satadar Nagar, Ward 116 Allapur, Hyderabad, Kukatpally mandal, Telangana, 500018, India",
  address: {
    neighbourhood: "Satadar Nagar",
    suburb: "Ward 116 Allapur",
    city: "Hyderabad",
    county: "Kukatpally mandal",
    state: "Telangana",
    postcode: "500018",
    country: "India",
    country_code: "in",
  },
  extratags: {},
  namedetails: {},
  boundingbox: ["17.8598497", "17.8623087", "78.8079136", "78.8082658"],
  distance: 2,
};


// This is optional
const options: Options = {
  color: true,                      // Whether to apply colors to the output or not
  spacing: true,                    // Whether to include spacing before colons or not
  seperator: ":",                   // seperate keys and values.
  squareBracketsForArray: false,    // Whether to use square brackets for arrays or not
  doubleQuotesForKeys: false,       // Whether to use double quotes for object keys or not
  doubleQuotesForValues: false,     // Whether to use double quotes for string values or not
}

// Convert the data to formatted plain text representation
const plainText = jsonToPlainText(data, options);
console.log(plainText);

Output

place_id      : 173937105
osm_type      : way
osm_id        : 319992693
lat           : 17.861533866867224
lon           : 78.8081441896764
display_name  : Satadar Nagar, Ward 116 Allapur, Hyderabad, Kukatpally mandal, Telangana, 500018, India
address       : 
neighbourhood : Satadar Nagar
suburb        : Ward 116 Allapur
city          : Hyderabad
county        : Kukatpally mandal
state         : Telangana
postcode      : 500018
country       : India
country_code  : in
extratags     : {}
namedetails   : {}
boundingbox   : 17.8598497, 17.8623087, 78.8079136, 78.8082658
distance      : 2

💝 Sponsor and support me

If you find my projects helpful or inspiring, consider supporting me through GitHub Sponsors. Your sponsorship helps me dedicate more time and effort to open source development and creating impactful projects.

:heart: Sponsor me on github

💖 Sponsors

Sponsors

  • A huge thanks to my sponsors for their support.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Author