Skip to content

Commit 6e2d8c0

Browse files
committed
Removed Colors
1 parent d35e475 commit 6e2d8c0

File tree

14 files changed

+333
-5460
lines changed

14 files changed

+333
-5460
lines changed

.github/workflows/test.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: JSON to plain text lib tests
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
matrix:
15+
node-version: [18.x, 20.x]
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
21+
- name: Setup Node.js ${{ matrix.node-version }}
22+
uses: actions/setup-node@v4
23+
with:
24+
node-version: ${{ matrix.node-version }}
25+
cache: npm
26+
27+
- name: Install dependencies
28+
run: npm install
29+
30+
- name: Run tests
31+
run: npm test

.gitignore

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
node_modules
22
coverage
33

4+
# Ignore lock files (optional, up to you)
5+
package-lock.json
6+
yarn.lock
47

5-
6-
7-
8+
# Ignore misc
9+
*.log
810

911

1012

.npmignore

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,31 @@
1+
# Ignore source and test files
12
src/
2-
3-
# Ignore development and configuration files
4-
node_modules/
53
test/
6-
.github
4+
5+
# Ignore build configs
6+
tsconfig.json
7+
tsconfig.cjs.json
8+
jest.config.ts
9+
10+
# Ignore environment/config files
711
.eslintrc.json
12+
.eslintrc
813
.eslintignore
9-
.prettierignore
1014
.prettierrc.json
11-
jest.config.ts
12-
coverage
15+
.prettierignore
16+
17+
# Ignore VCS & GitHub files
18+
.gitignore
19+
.github/
20+
21+
# Ignore documentation (optional, keep README & LICENSE usually)
22+
CHANGELOG.md
23+
CODE_OF_CONDUCT.md
24+
SECURITY.md
25+
26+
# Ignore lock files (optional, up to you)
27+
package-lock.json
28+
yarn.lock
29+
30+
# Ignore misc
31+
*.log

.prettierignore

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,11 @@
22
build
33
dist
44
node_modules
5-
coverage
5+
coverage
6+
7+
# Ignore lock files (optional, up to you)
8+
package-lock.json
9+
yarn.lock
10+
11+
# Ignore misc
12+
*.log

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
8+
## [1.2.0] - 2023-12-8
9+
10+
- Removed coloring to support browsers.
11+
712
## [1.1.4] - 2023-12-8
813

914
- Fixed some mistakes.

README.md

Lines changed: 90 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -2,140 +2,146 @@
22

33
[![Version](https://img.shields.io/npm/v/json-to-plain-text.svg)](https://www.npmjs.com/package/json-to-plain-text)
44
[![Stars](https://img.shields.io/github/stars/sumithemmadi/json-to-plain-text)](https://github.com/sumithemmadi/json-to-plain-text/stargazers)
5-
[![Download](https://img.shields.io/npm/dt/json-to-plain-text.svg)](https://github.com/sumithemmadi/json-to-plain-text)
6-
[![License](https://img.shields.io/npm/l/json-to-plain-text.svg)](https://github.com/sumithemmadi/json-to-plain-text/blob/main/LICENSE)
5+
[![Downloads](https://img.shields.io/npm/dt/json-to-plain-text.svg)](https://www.npmjs.com/package/json-to-plain-text)
6+
[![License](https://img.shields.io/npm/l/json-to-plain-text.svg)](LICENSE)
77
[![Maintenance](https://img.shields.io/npms-io/maintenance-score/json-to-plain-text)](https://github.com/sumithemmadi/json-to-plain-text)
88
[![Issues](https://img.shields.io/github/issues/sumithemmadi/json-to-plain-text)](https://github.com/sumithemmadi/json-to-plain-text/issues)
99
[![GitHub Sponsors](https://img.shields.io/github/sponsors/sumithemmadi)](https://github.com/sponsors/sumithemmadi)
10-
[![install size](https://img.shields.io/badge/dynamic/json?url=https://packagephobia.com/v2/api.json?p=json-to-plain-text&query=$.install.pretty&label=install%20size)](https://packagephobia.now.sh/result?p=json-to-plain-text)
11-
[![npm bundle size](https://img.shields.io/bundlephobia/minzip/json-to-plain-text)](https://bundlephobia.com/package/json-to-plain-text@latest)
10+
[![Install size](https://img.shields.io/badge/dynamic/json?url=https://packagephobia.com/v2/api.json?p=json-to-plain-text&query=$.install.pretty&label=install%20size)](https://packagephobia.com/result?p=json-to-plain-text)
11+
[![Bundle size](https://img.shields.io/bundlephobia/minzip/json-to-plain-text)](https://bundlephobia.com/package/json-to-plain-text@latest)
1212
[![Known Vulnerabilities](https://snyk.io/test/npm/json-to-plain-text/badge.svg)](https://snyk.io/test/npm/json-to-plain-text)
1313

14-
`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.
14+
---
1515

16-
## Installation
16+
## 📖 Overview
1717

18-
1. Install `json-to-plain-text` npm package.
18+
`json-to-plain-text` is a lightweight npm package that converts **JSON** into a clean, human-readable **plain-text**.
1919

20-
```bash
21-
npm install json-to-plain-text
22-
```
20+
Think of it as `JSON.stringify()`, but prettier, friendlier, and tailored for **logs, debugging, and CLI output**.
2321

24-
2. Import the `jsonToPlainText` function:
22+
> [!NOTE]
23+
> From version **2.0.0+**, this package outputs plain text only.
24+
> If you need **colored output**, please use [version 1.1.4](https://www.npmjs.com/package/json-to-plain-text/v/1.1.4) .
2525
26-
```js
27-
import { jsonToPlainText } from "json-to-plain-text";
28-
```
26+
---
2927

30-
## Usage
28+
## ✨ Features
3129

32-
The `jsonToPlainText` function accepts two parameters: `data` and `options`.
30+
- 🔹 Convert JSON objects into easy-to-read plain text
31+
- ⚡ Tiny & fast (zero dependencies)
32+
- 🛠 Configurable separators, spacing, quotes, and array formatting
33+
- ✅ Great for **logs, debugging, reports, and CLI tools**
3334

34-
### Parameters
35+
---
3536

36-
- `data` (required): The input data to convert. It can be JSON-like data or plain JavaScript objects.
37+
## 🔍 Why use this?
3738

38-
- `options` (optional): Configuration options for customizing the output. It is an object with the following properties:
39+
Use `json-to-plain-text` when you need:
40+
- 📑 **Readable logs** – no more squinting at raw JSON
41+
- 🖥 **CLI outputs** – format objects neatly for the terminal
42+
- 🧪 **Debugging helpers** – quickly inspect nested objects
43+
- 📝 **Reports/configs** – human-friendly data printing
3944

40-
- `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.
41-
- `seperator` (string, default: `:`): seperate keys and values.
45+
---
4246

43-
- `spacing` (boolean, default: `true`): Whether to include spacing before colons. Set to `true` for formatted spacing or `false` to remove spacing before colons.
47+
## 🚀 Installation
4448

45-
- `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.
49+
```bash
50+
npm install json-to-plain-text
51+
```
52+
53+
---
54+
55+
## 📦 Usage
56+
57+
```js
58+
import { jsonToPlainText } from "json-to-plain-text";
59+
```
60+
61+
---
62+
63+
## ⚙️ API
4664

47-
- `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.
65+
```ts
66+
jsonToPlainText(data: unknown, options?: Options): string
67+
```
68+
69+
### Parameters
70+
71+
- **`data`** *(required)* – JSON-like input or JavaScript object.
72+
- **`options`** *(optional)* – Customize the formatting.
73+
74+
| Option | Type | Default | Description |
75+
|---------------------------|---------|---------|-------------|
76+
| `separator` | string | `:` | Character used between keys and values. |
77+
| `spacing` | boolean | `true` | Align keys with spacing before colons. |
78+
| `squareBracketsForArray` | boolean | `false` | Display arrays inside `[]`. |
79+
| `doubleQuotesForKeys` | boolean | `false` | Wrap object keys in double quotes. |
80+
| `doubleQuotesForValues` | boolean | `false` | Wrap string values in double quotes. |
4881

49-
- `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.
82+
---
5083

51-
### Example
84+
## 💡 Example
5285

53-
```typescript
86+
```ts
5487
import { jsonToPlainText, Options } from "json-to-plain-text";
5588

56-
let data = {
89+
const data = {
5790
place_id: "173937105",
5891
osm_type: "way",
59-
osm_id: "319992693",
6092
lat: "17.861533866867224",
6193
lon: "78.8081441896764",
62-
display_name:
63-
"Satadar Nagar, Ward 116 Allapur, Hyderabad, Kukatpally mandal, Telangana, 500018, India",
6494
address: {
65-
neighbourhood: "Satadar Nagar",
66-
suburb: "Ward 116 Allapur",
6795
city: "Hyderabad",
68-
county: "Kukatpally mandal",
6996
state: "Telangana",
70-
postcode: "500018",
7197
country: "India",
72-
country_code: "in",
7398
},
74-
extratags: {},
75-
namedetails: {},
76-
boundingbox: ["17.8598497", "17.8623087", "78.8079136", "78.8082658"],
7799
distance: 2,
78100
};
79101

80-
81-
// This is optional
82102
const options: Options = {
83-
color: true, // Whether to apply colors to the output or not
84-
spacing: true, // Whether to include spacing before colons or not
85-
seperator: ":", // seperate keys and values.
86-
squareBracketsForArray: false, // Whether to use square brackets for arrays or not
87-
doubleQuotesForKeys: false, // Whether to use double quotes for object keys or not
88-
doubleQuotesForValues: false, // Whether to use double quotes for string values or not
89-
}
90-
91-
// Convert the data to formatted plain text representation
92-
const plainText = jsonToPlainText(data, options);
93-
console.log(plainText);
103+
separator: ":",
104+
spacing: true,
105+
squareBracketsForArray: false,
106+
doubleQuotesForKeys: false,
107+
doubleQuotesForValues: false,
108+
};
109+
110+
console.log(jsonToPlainText(data, options));
94111
```
95112

96-
### Output
113+
### Output
97114

98115
```yaml
99-
place_id : 173937105
100-
osm_type : way
101-
osm_id : 319992693
102-
lat : 17.861533866867224
103-
lon : 78.8081441896764
104-
display_name : Satadar Nagar, Ward 116 Allapur, Hyderabad, Kukatpally mandal, Telangana, 500018, India
105-
address :
106-
neighbourhood : Satadar Nagar
107-
suburb : Ward 116 Allapur
108-
city : Hyderabad
109-
county : Kukatpally mandal
110-
state : Telangana
111-
postcode : 500018
112-
country : India
113-
country_code : in
114-
extratags : {}
115-
namedetails : {}
116-
boundingbox : 17.8598497, 17.8623087, 78.8079136, 78.8082658
117-
distance : 2
116+
place_id : 173937105
117+
osm_type : way
118+
lat : 17.861533866867224
119+
lon : 78.8081441896764
120+
address :
121+
city : Hyderabad
122+
state : Telangana
123+
country : India
124+
distance : 2
118125
```
119-
## 💝 Sponsor and support me
120126
121-
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.
127+
---
122128
123-
[:heart: Sponsor me on github](https://github.com/sponsors/sumithemmadi?o=sd&sc=t)
129+
## 💝 Support
124130
125-
<a href='https://ko-fi.com/W7W4OZNLF' target='_blank'><img height='40' style='border:0px;height:40px;' src='https://storage.ko-fi.com/cdn/kofi3.png?v=3' border='0' alt='Buy Me a Coffee at ko-fi.com' /></a>
131+
If this project helps you, consider supporting my open-source work:
126132
127-
<a href="https://www.buymeacoffee.com/sumithemmadi"> <img align="left" src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" height="40" width="180" alt="sumithemmadi" /></a><br><br>
133+
- [💖 SPONSOR ME ON GITHUB](https://github.com/sponsors/sumithemmadi?o=sd&sc=t)
128134
129-
### 💖 Sponsors
135+
A huge thanks to all sponsors for supporting my work!
130136
131-
[![Sponsors](https://sumithemmadi.github.io/sponsors.svg)](https://github.com/sponsors/sumithemmadi/)
137+
---
132138
133-
- A huge thanks to my sponsors for their support.
139+
## 📜 License
134140
135-
## License
141+
This project is licensed under the [MIT License](LICENSE).
136142
137-
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
143+
---
138144
139-
## Author
145+
## 👨‍💻 Author
140146
141-
- [Sumith Emmadi](https://github.com/sumithemmadi)
147+
- [Sumith Emmadi](https://github.com/sumithemmadi)

dist/cjs/index.d.ts

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
interface Options {
2-
color?: boolean;
32
spacing?: boolean;
43
seperator?: string;
54
squareBracketsForArray?: boolean;
@@ -8,36 +7,6 @@ interface Options {
87
}
98
/**
109
* Convert JSON-like data or plain JavaScript objects to formatted plain text representation.
11-
*
12-
* @function jsonToPlainText
13-
* @param data {unknown} - The input data to convert. Can be JSON-like data or plain JavaScript objects.
14-
* @param options {Options} - (Optional) Configuration options for customizing the output.
15-
* - color {boolean} - Whether to apply colors to the output (default: true).
16-
* - spacing {boolean} - Whether to include spacing after colons (default: true).
17-
* - seperator {string} - seperator. Default ':',
18-
* - squareBracketsForArray {boolean} - Whether to use square brackets for arrays (default: false).
19-
* - doubleQuotesForKeys {boolean} - Whether to use double quotes for object keys (default: false).
20-
* - doubleQuotesForValues {boolean} - Whether to use double quotes for string values (default: false).
21-
* @returns {string} - The formatted plain text representation of the input data.
22-
* @example
23-
* // Basic usage:
24-
* const data = { name: "John", age: 30, isEmployed: true };
25-
* const options = {
26-
* color: true,
27-
* spacing: true,
28-
* seperator?: "=";
29-
* squareBracketsForArray: false,
30-
* doubleQuotesForKeys: false,
31-
* doubleQuotesForValues: false,
32-
* }
33-
* const plainText = jsonToPlainText(data);
34-
* console.log(plainText);
35-
*
36-
* // Output:
37-
* //
38-
* // name = "John",
39-
* // age = 30,
40-
* // isEmployed = true
4110
*/
42-
declare function jsonToPlainText(data: unknown, options: Options): string;
11+
declare function jsonToPlainText(data: unknown, options?: Options): string;
4312
export { jsonToPlainText, Options };

0 commit comments

Comments
 (0)