Gathering detailed insights and metrics for @aitodotai/json-stringify-pretty-compact
Gathering detailed insights and metrics for @aitodotai/json-stringify-pretty-compact
Gathering detailed insights and metrics for @aitodotai/json-stringify-pretty-compact
Gathering detailed insights and metrics for @aitodotai/json-stringify-pretty-compact
The best of both `JSON.stringify(obj)` and `JSON.stringify(obj, null, indent)`.
npm install @aitodotai/json-stringify-pretty-compact
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
6 Stars
37 Commits
4 Forks
1 Watchers
4 Branches
Updated on Mar 12, 2023
Latest Version
1.3.0
Package Id
@aitodotai/json-stringify-pretty-compact@1.3.0
Unpacked Size
10.00 kB
Size
4.29 kB
File Count
6
NPM Version
6.4.1
Node Version
8.12.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Fork information: This is a maintained fork which implements these additional options: maxNesting
, arrayMargins
, and objectMargins
.
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 (and the “replacer” argument)
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 @aitodotai/json-stringify-pretty-compact
1var stringify = require("json-stringify-pretty-compact")
stringify(obj, [options])
It’s like JSON.stringify(obj, null, options.indent)
, except that objects and
arrays are on one line if they fit (according to options.maxLength
).
options
:
indent: Defaults to 2. Works exactly like the third parameter of
JSON.stringify
.
maxLength: Defaults to 80. Lines will be tried to be kept at maximum this many characters long.
maxNesting: Defaults to Infinity
. The maximum amount of allowed inline nesting for objects or arrays
By default, the output can contain arbitrary amount of nested structures (as long as the maxLength is not exceeded), like below:
1{"a": [{"b": ["test1", "test2"]}, {"c": true}]}}
When maxNesting is set to 0
, the output doesn't allow any nesting:
1{ 2 "a": [ 3 { 4 "b": [ 5 "test1", 6 "test2" 7 ] 8 }, 9 { 10 "c": true 11 } 12 ] 13}
margins: Defaults to false
. Whether or not to add “margins” around brackets
and braces:
false
: {"a": [1]}
true
: { "a": [ 1 ] }
arrayMargins: Defaults to false
. Whether or not to add “margins” around brackets:
false
: {"a": [1]}
true
: {"a": [ 1 ]}
arrayMargins: Defaults to true
. Whether or not to add “margins” around braces:
false
: {"a": [1]}
true
: { "a": [1] }
stringify(obj, {maxLength: 0, indent: indent})
gives the exact same result as
JSON.stringify(obj, null, indent)
.
stringify(obj, {maxLength: Infinity})
gives the exact same result as
JSON.stringify(obj)
, except that there are spaces after colons and commas.
Example of publishing new release with patch change:
npm run publish -- patch
MIT.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 0/26 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- 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
Reason
34 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
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