Skip to content

Commit 1aadfa6

Browse files
chore: update repository
1 parent 35fc9f5 commit 1aadfa6

16 files changed

Lines changed: 166 additions & 219 deletions

File tree

.eslintignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

.eslintrc

Lines changed: 0 additions & 7 deletions
This file was deleted.

.github/workflows/codeql.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ jobs:
4343

4444
steps:
4545
- name: Harden Runner
46-
uses: step-security/harden-runner@1b05615854632b887b69ae1be8cbefe72d3ae423 # v2.6.0
46+
uses: step-security/harden-runner@002fdce3c6a235733a90a27c80493a3241e56863 # v2.12.1
4747
with:
4848
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
4949
- name: Checkout repository
50-
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608
50+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
5151

5252
# Initializes the CodeQL tools for scanning.
5353
- name: Initialize CodeQL
54-
uses: github/codeql-action/init@74483a38d39275f33fcff5f35b679b5ca4a26a99
54+
uses: github/codeql-action/init@ce28f5bb42b7a9f2c824e633a3f6ee835bab6858 # v3.29.0
5555
with:
5656
languages: ${{ matrix.language }}
5757
# If you wish to specify custom queries, you can do so here or in a config file.
@@ -65,7 +65,7 @@ jobs:
6565
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java).
6666
# If this step fails, then you should remove it and run the build manually (see below)
6767
- name: Autobuild
68-
uses: github/codeql-action/autobuild@74483a38d39275f33fcff5f35b679b5ca4a26a99
68+
uses: github/codeql-action/autobuild@ce28f5bb42b7a9f2c824e633a3f6ee835bab6858 # v3.29.0
6969

7070
# ℹ️ Command-line programs to run using the OS shell.
7171
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
@@ -78,6 +78,6 @@ jobs:
7878
# ./location_of_script_within_repo/buildscript.sh
7979

8080
- name: Perform CodeQL Analysis
81-
uses: github/codeql-action/analyze@74483a38d39275f33fcff5f35b679b5ca4a26a99
81+
uses: github/codeql-action/analyze@ce28f5bb42b7a9f2c824e633a3f6ee835bab6858 # v3.29.0
8282
with:
8383
category: "/language:${{matrix.language}}"

.github/workflows/node.js.yml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ name: Node.js CI
55

66
on:
77
push:
8-
branches: [ "master" ]
8+
branches:
9+
- master
910
pull_request:
10-
branches: [ "master" ]
11+
branches:
12+
- master
1113

1214
permissions:
1315
contents: read
@@ -17,17 +19,17 @@ jobs:
1719
runs-on: ${{matrix.os}}
1820
strategy:
1921
matrix:
20-
node-version: [16.x, 18.x, 20.x]
21-
os: [ubuntu-latest, windows-latest, macos-latest]
22+
node-version: [20.x, 22.x, 24.x]
23+
os: [ubuntu-latest]
2224
steps:
2325
- name: Harden Runner
24-
uses: step-security/harden-runner@1b05615854632b887b69ae1be8cbefe72d3ae423 # v2.6.0
26+
uses: step-security/harden-runner@002fdce3c6a235733a90a27c80493a3241e56863 # v2.12.1
2527
with:
2628
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
2729

28-
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608
30+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2931
- name: Use Node.js ${{ matrix.node-version }}
30-
uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d
32+
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
3133
with:
3234
node-version: ${{ matrix.node-version }}
3335
- run: npm install

.github/workflows/scorecard.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@ jobs:
3232

3333
steps:
3434
- name: Harden Runner
35-
uses: step-security/harden-runner@1b05615854632b887b69ae1be8cbefe72d3ae423 # v2.6.0
35+
uses: step-security/harden-runner@002fdce3c6a235733a90a27c80493a3241e56863 # v2.12.1
3636
with:
3737
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
3838

3939
- name: "Checkout code"
40-
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
40+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
4141
with:
4242
persist-credentials: false
4343

4444
- name: "Run analysis"
45-
uses: ossf/scorecard-action@0864cf19026789058feabb7e87baa5f140aac736 # v2.3.1
45+
uses: ossf/scorecard-action@05b42c624433fc40578a4040d5cf5e36ddca8cde # v2.4.2
4646
with:
4747
results_file: results.sarif
4848
results_format: sarif
@@ -64,14 +64,14 @@ jobs:
6464
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
6565
# format to the repository Actions tab.
6666
- name: "Upload artifact"
67-
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
67+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
6868
with:
6969
name: SARIF file
7070
path: results.sarif
7171
retention-days: 5
7272

7373
# Upload the results to GitHub's code scanning dashboard.
7474
- name: "Upload to code-scanning"
75-
uses: github/codeql-action/upload-sarif@74483a38d39275f33fcff5f35b679b5ca4a26a99 # v2.22.5
75+
uses: github/codeql-action/upload-sarif@ce28f5bb42b7a9f2c824e633a3f6ee835bab6858 # v3.29.0
7676
with:
7777
sarif_file: results.sarif

.npmrc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
11
package-lock=false
2-
tag-version-prefix=""
3-
message="chore(release): %s"

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2018 TopCli
3+
Copyright (c) 2018-2025 TopCli
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/TopCli/Pretty-JSON/badge?style=for-the-badge)](https://api.securityscorecards.dev/projects/github.com/TopCli/Pretty-JSON)
66
![build](https://img.shields.io/github/actions/workflow/status/TopCli/Pretty-JSON/node.js.yml?style=for-the-badge)
77

8-
Stdout JSON in your terminal with colors. This package has been created to stdout clean and beautiful JSON in the SlimIO CLI.
8+
Pretty-print JSON to the terminal with syntax highlighting and structure-aware formatting.
99

1010
## Requirements
11-
- [Node.js](https://nodejs.org/en/) v16 or higher
11+
- [Node.js](https://nodejs.org/en/) v20 or higher
1212

1313
## Getting Started
1414

@@ -25,9 +25,9 @@ $ yarn add @topcli/pretty-json
2525
import prettyJSON from "@topcli/pretty-json";
2626

2727
prettyJSON({
28-
foo: "bar",
29-
hello: "world!",
30-
arr: [1, 2, 3]
28+
foo: "bar",
29+
hello: "world!",
30+
arr: [1, 2, 3]
3131
});
3232
```
3333

@@ -38,14 +38,13 @@ It will produce the following stdout:
3838
## API
3939

4040
### prettyJSON(obj: object): void
41-
Stdout a given JSON Object (Plain Object, Objects Prototype of Object or Array).
4241

43-
## Dependencies
42+
Prints a JSON-compatible object or array to the terminal with syntax highlighting and structured indentation.
4443

45-
|Name|Refactoring|Security Risk|Usage|
46-
|---|---|---|---|
47-
|[@slimio/is](https://github.com/SlimIO/is)|Minor|Low|Type checker|
48-
|[kleur](https://github.com/lukeed/kleur)|Minor|Low|TTY color|
44+
- Supports plain objects, arrays, and nested structures.
45+
- Skips functions and symbols.
46+
- Color-codes data types (strings, numbers, booleans, etc.).
47+
- Outputs readable, formatted JSON — ideal for CLI inspection.
4948

5049
## License
5150
MIT

eslint.config.mjs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Import Third-party Dependencies
2+
import { ESLintConfig } from "@openally/config.eslint";
3+
4+
export default [
5+
...ESLintConfig,
6+
{
7+
languageOptions: {
8+
sourceType: "module"
9+
}
10+
}
11+
];

index.js

Lines changed: 46 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,120 +1,119 @@
1-
// Require Third-party Dependencies
2-
import kleur from "kleur";
3-
import is from "@slimio/is";
1+
// Import Node.js Dependencies
2+
import { EOL } from "node:os";
3+
import { styleText } from "node:util";
44

5+
// Import Internal Dependencies
6+
import * as utils from "./src/utils.js";
57

6-
// Require Internal Dependencies
7-
import { maxKeyLength, primeColor } from "./src/utils.js";
8+
function logArray(arr, options = {}) {
9+
const {
10+
depth = 1,
11+
disableEndLine = false
12+
} = options;
813

9-
// CONSTANTS
10-
const EOL = "\n";
11-
12-
/**
13-
* @function logArray
14-
* @param {!Array<any>} arr
15-
* @param {number} [depth=1]
16-
* @param {boolean} [disableEndLine=false]
17-
* @returns {void}
18-
*/
19-
function logArray(arr, depth = 1, disableEndLine = false) {
2014
const backStart = depth === 2 ? " " : " ".repeat(depth - 1);
2115
const startSpace = depth === 1 ? " " : " ".repeat(depth);
2216
const lenMax = arr.length - 1;
2317
const returnLine = arr.length > 10;
24-
const firstIsObject = arr.length > 0 && is.plainObject(arr[0]);
18+
const firstIsObject = arr.length > 0 && utils.isPlainObject(arr[0]);
2519
let forceNext = false;
2620

2721
if (arr.length === 0) {
28-
process.stdout.write(`${kleur.gray("[]")}${disableEndLine ? "" : EOL}`);
22+
process.stdout.write(`${styleText("gray", "[]")}${disableEndLine ? "" : EOL}`);
2923

3024
return;
3125
}
3226

33-
process.stdout.write(`${kleur.gray("[")}${EOL}${firstIsObject ? "" : startSpace}`);
27+
process.stdout.write(`${styleText("gray", "[")}${EOL}${firstIsObject ? "" : startSpace}`);
3428
for (let id = 0; id < arr.length; id++) {
3529
const value = arr[id];
3630

37-
if (is.array(value)) {
31+
if (Array.isArray(value)) {
3832
if (id !== 0) {
3933
process.stdout.write(startSpace);
4034
}
41-
logArray(value, depth + 1, true);
35+
logArray(value, { depth: depth + 1, disableEndLine: true });
4236
forceNext = true;
4337
if (id !== lenMax) {
44-
process.stdout.write(kleur.gray(", "));
38+
process.stdout.write(styleText("gray", ", "));
4539
process.stdout.write(EOL);
4640
}
4741
}
48-
else if (is.plainObject(value)) {
49-
logObject(value, depth, true);
42+
else if (utils.isPlainObject(value)) {
43+
logObject(value, { depth, disableEndLine: true });
5044
forceNext = true;
5145
}
5246
else {
53-
// eslint-disable-next-line
54-
if ((returnLine && id > 0) || forceNext) {
47+
if ((returnLine && id > 0) || forceNext) {
5548
process.stdout.write(startSpace);
5649
forceNext = false;
5750
}
5851

59-
process.stdout.write(primeColor(value)(is.string(value) ? `'${value}'` : String(value)));
52+
const isString = typeof value === "string";
53+
process.stdout.write(utils.primeColor(value)(isString ? `'${value}'` : String(value)));
6054
if (id !== lenMax) {
61-
process.stdout.write(kleur.gray(", "));
55+
process.stdout.write(styleText("gray", ", "));
6256
if (returnLine) {
6357
process.stdout.write(EOL);
6458
}
6559
}
6660
}
6761
}
68-
process.stdout.write(`${EOL}${backStart}${kleur.gray("]")}${disableEndLine ? "" : EOL}`);
62+
process.stdout.write(`${EOL}${backStart}${styleText("gray", "]")}${disableEndLine ? "" : EOL}`);
6963
}
7064

71-
/**
72-
* @function logObject
73-
* @param {!object} obj
74-
* @param {number} [depth=1]
75-
* @param {boolean} [disableEndLine=false]
76-
* @returns {void}
77-
*/
78-
function logObject(obj, depth = 1, disableEndLine = false) {
79-
const betweenSpace = maxKeyLength(obj, 4);
65+
function logObject(obj, options = {}) {
66+
const {
67+
depth = 1,
68+
disableEndLine = false
69+
} = options;
70+
const betweenSpace = utils.maxKeyLength(obj, 4);
8071
const startSpace = depth === 1 ? " " : " ".repeat(depth);
8172
const entries = Object.entries(obj);
8273

8374
if (entries.length === 0) {
84-
process.stdout.write(`${kleur.gray("{}")}${disableEndLine ? "" : EOL}`);
75+
process.stdout.write(`${styleText("gray", "{}")}${disableEndLine ? "" : EOL}`);
8576

8677
return;
8778
}
8879

8980
for (let id = 0; id < entries.length; id++) {
9081
const [key, value] = entries[id];
91-
if (is.func(value) || is.symbol(value)) {
82+
if (["function", "symbol"].includes(typeof value)) {
9283
continue;
9384
}
9485

9586
if (id === 0) {
9687
process.stdout.write(EOL);
9788
}
98-
process.stdout.write(kleur.bold(kleur.white(`${startSpace}${key}: ${" ".repeat(betweenSpace - key.length)}`)));
99-
if (is.object(value)) {
100-
(Array.isArray(value) ? logArray : logObject)(value, depth + 1);
89+
process.stdout.write(styleText(["bold", "white"], `${startSpace}${key}: ${" ".repeat(betweenSpace - key.length)}`));
90+
if (utils.isPlainObject(value)) {
91+
logObject(value, { depth: depth + 1 });
92+
continue;
93+
}
94+
if (Array.isArray(value)) {
95+
logArray(value, { depth: depth + 1 });
10196
continue;
10297
}
10398

104-
process.stdout.write(primeColor(value)(is.string(value) ? `'${value}'` : String(value)));
99+
process.stdout.write(utils.primeColor(value)(typeof value === "string" ? `'${value}'` : String(value)));
105100
if (!disableEndLine) {
106101
process.stdout.write(EOL);
107102
}
108103
}
109104
}
110105

111106
export default function stdoutJSON(obj) {
112-
if (is.object(obj)) {
113-
(Array.isArray(obj) ? logArray : logObject)(obj);
114-
process.stdout.write(EOL);
107+
if (utils.isPlainObject(obj)) {
108+
logObject(obj);
109+
}
110+
else if (Array.isArray(obj)) {
111+
logArray(obj);
115112
}
116113
else {
117114
throw new Error(`${obj} should be object or array.`);
118115
}
116+
117+
process.stdout.write(EOL);
119118
}
120119

0 commit comments

Comments
 (0)