Gathering detailed insights and metrics for json-stringify-pretty-compact
Gathering detailed insights and metrics for json-stringify-pretty-compact
Gathering detailed insights and metrics for json-stringify-pretty-compact
Gathering detailed insights and metrics for json-stringify-pretty-compact
The best of both `JSON.stringify(obj)` and `JSON.stringify(obj, null, indent)`.
npm install json-stringify-pretty-compact
99.5
Supply Chain
83.2
Quality
75.6
Maintenance
100
Vulnerability
100
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
252 Stars
66 Commits
32 Forks
6 Watching
1 Branches
4 Contributors
Updated on 24 Oct 2024
Minified
Minified + Gzipped
JavaScript (68.57%)
HTML (31.43%)
Cumulative downloads
Total Downloads
Last day
-8%
187,184
Compared to previous day
Last week
1%
1,080,394
Compared to previous week
Last month
9%
4,575,324
Compared to previous month
Last year
63.2%
44,042,554
Compared to previous year
The output of JSON.stringify comes in two flavors: compact and pretty. The former is usually too compact to be read by humans, while the latter sometimes is too spacious. This module trades performance for a compromise between the two. The result is a pretty compact string, where “pretty” means both “kind of” and “nice”.
1{ 2 "bool": true, 3 "short array": [1, 2, 3], 4 "long array": [ 5 {"x": 1, "y": 2}, 6 {"x": 2, "y": 1}, 7 {"x": 1, "y": 1}, 8 {"x": 2, "y": 2} 9 ] 10}
While the “pretty” mode of JSON.stringify puts every item of arrays and objects on its own line, this module puts the whole array or object on a single line, unless the line becomes too long (the default maximum is 80 characters). Making arrays and objects multi-line is the only attempt made to enforce the maximum line length; if that doesn’t help then so be it.
npm install json-stringify-pretty-compact
1import stringify from "json-stringify-pretty-compact";
Note: This is an ESM only package. (I haven’t written that gist, but it’s a great resource.)
If you need CommonJS, install version 3.0.0. You won’t be missing out on anything: This package is done. No more features will be added, and no bugs have been found in years.
Want a CLI? Check out avantgardnerio/json-stringify-pretty-compact-cli!
Web version? Check out the online demo!
stringify(obj, options = {})
It’s like JSON.stringify(obj, options.replacer, options.indent)
, except that objects and arrays are on one line if they fit (according to options.maxLength
).
options
:
stringify(obj, {maxLength: 0, indent: indent})
gives the exact same result as JSON.stringify(obj, null, indent)
. (However, if you use a replacer
, integer keys might be moved first.)
stringify(obj, {maxLength: Infinity})
gives the exact same result as JSON.stringify(obj)
, except that there are spaces after colons and commas.
Want more options? Check out @aitodotai/json-stringify-pretty-compact!
MIT.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
1 existing vulnerabilities detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 2
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
Found 1/16 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More