Skip to content

Commit f277504

Browse files
committed
Added colors to output
1 parent 76e2e87 commit f277504

File tree

5 files changed

+16
-7
lines changed

5 files changed

+16
-7
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ var jsonData = {
4848
"distance": 2
4949
}
5050

51-
var response = convert.toPlainText(jsonData);
51+
var response = convert.toPlainText(jsonData,color=true);
5252
console.log(response);
53+
5354
```
5455

5556
## Output

index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var typeOf = require("./lib/lib.js").typeOf;
2424
var trimWhitespace = require("./lib/helper.js");
2525

2626
// Function to convert JSON to PLAIN TEXT
27-
function toPlainText(data) {
27+
function toPlainText(data, color = false) {
2828
var handlers,
2929
indentLevel = "";
3030
handlers = {
@@ -91,7 +91,14 @@ function toPlainText(data) {
9191
if (k.length <= 20) {
9292
var space = " ".repeat(20 - k.length);
9393
}
94-
output += k + space + ": " + handler(val).toString().replace(/"/g, "");
94+
if (color == true) {
95+
output += `\x1b[33m${k}\x1b[0m${space} : \x1b[32m${handler(val)
96+
.toString()
97+
.replace(/"/g, "")}\x1b[0m`;
98+
} else {
99+
output += k + space + ": " + handler(val).toString().replace(/"/g, "");
100+
}
101+
95102
});
96103
return output;
97104
},

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "json-to-plain-text",
3-
"version": "1.0.4",
3+
"version": "1.0.5",
44
"description": "Convert any json to plain text",
55
"main": "index.js",
66
"directories": {

test/test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@ var jsonData = {
2424
distance: 2,
2525
};
2626

27-
var response = convert.toPlainText(jsonData);
27+
28+
var response = convert.toPlainText(jsonData,color=true);
2829
console.log(response);

0 commit comments

Comments
 (0)