Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

json-stringify-pretty-compact

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-stringify-pretty-compact - npm Package Compare versions

Comparing version 2.0.0 to 3.0.0

20

CHANGELOG.md

@@ -0,11 +1,11 @@

### Version 3.0.0 (2021-02-20)
- Changed: The TypeScript definition is now closer to `JSON.stringify`. It’s slightly stricter, but I doubt you’ll notice a difference.
- Added: `"type": "commonjs", "exports": "./index.js", "types": "index.d.ts"` to package.json. I doubt you’ll notice any difference from this either.
### Version 2.0.0 (2019-02-02)
- Removed: The `margins` option. Check out
[@aitodotai/json-stringify-pretty-compact] if you miss it. This package is now
purely a combination of `JSON.stringify(obj)` and
`JSON.stringify(obj, null, 2)` with no additional formatting features on top
of that.
- Removed: The `margins` option. Check out [@aitodotai/json-stringify-pretty-compact] if you miss it. This package is now purely a combination of `JSON.stringify(obj)` and `JSON.stringify(obj, null, 2)` with no additional formatting features on top of that.
- Added: Support for the [replacer] argument.
- Changed: Passing `undefined` to options now result in the default value being
used. This is to align with how destructuring defaults work in ES2015.
- Changed: Passing `undefined` to options now result in the default value being used. This is to align with how destructuring defaults work in ES2015.

@@ -22,4 +22,3 @@ ### Version 1.2.0 (2018-04-22)

- Fixed: String contents are no longer accidentally modified in some cases.
Thanks to @powellquiring!
- Fixed: String contents are no longer accidentally modified in some cases. Thanks to @powellquiring!

@@ -36,4 +35,3 @@ ### Version 1.0.3 (2017-03-30)

- Fixed: Commas are now accounted for when calculating the available length of a
line, so that they do not appear outside `options.maxLength`.
- Fixed: Commas are now accounted for when calculating the available length of a line, so that they do not appear outside `options.maxLength`.

@@ -40,0 +38,0 @@ ### Version 1.0.0 (2014-11-01)

declare module "json-stringify-pretty-compact" {
const stringify: (
object: any,
export default function stringify(
value: any,
options?: {

@@ -8,8 +8,6 @@ indent?: number | string;

replacer?:
| ((key: string, value: any) => any)
| (number | string)[]
| null;
| ((this: any, key: string, value: any) => any)
| (number | string)[];
}
) => string;
export = stringify;
): string;
}

@@ -43,5 +43,8 @@ "use strict";

if (string.length <= length) {
prettified = string.replace(stringOrChar, function(match, stringLiteral) {
return stringLiteral || match + " ";
});
prettified = string.replace(
stringOrChar,
function (match, stringLiteral) {
return stringLiteral || match + " ";
}
);
if (prettified.length <= length) {

@@ -48,0 +51,0 @@ return prettified;

{
"name": "json-stringify-pretty-compact",
"version": "2.0.0",
"version": "3.0.0",
"author": "Simon Lydell",
"license": "MIT",
"description": "The best of both `JSON.stringify(obj)` and `JSON.stringify(obj, null, indent)`.",
"main": "index.js",
"type": "commonjs",
"exports": "./index.js",
"types": "index.d.ts",
"repository": "lydell/json-stringify-pretty-compact",

@@ -25,18 +27,11 @@ "files": [

"scripts": {
"eslint": "eslint .",
"eslint:fix": "npm run eslint -- --fix",
"prettier": "prettier --write \"**/*.{md,ts}\"",
"jest": "jest",
"coverage": "jest --coverage",
"test": "npm run eslint && npm run coverage",
"test": "eslint . --report-unused-disable-directives && prettier --check . && jest --coverage",
"prepublishOnly": "npm test"
},
"devDependencies": {
"eslint": "5.13.0",
"eslint-config-lydell": "13.0.0",
"eslint-plugin-jest": "22.2.2",
"eslint-plugin-prettier": "3.0.1",
"jest": "24.0.0",
"prettier": "1.16.3"
"eslint": "7.20.0",
"eslint-plugin-jest": "24.1.5",
"jest": "26.6.3",
"prettier": "2.2.1"
}
}

@@ -1,8 +0,4 @@

# json-stringify-pretty-compact [![Build Status][travis-badge]][travis-link]
# json-stringify-pretty-compact
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”.
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”.

@@ -23,7 +19,3 @@ <!-- prettier-ignore -->

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.
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.

@@ -42,38 +34,16 @@ ## Installation

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`).
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`:
- 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.
- replacer: Defaults to undefined. Works exactly like the second parameter of
[JSON.stringify].
- 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.
- replacer: Defaults to undefined. Works exactly like the second parameter of [JSON.stringify].
`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: 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.
`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]!
## Development
You need Node.js 10 and npm 6.
### npm scripts
- `npm run eslint`: Run [ESLint] \(including [Prettier]).
- `npm run eslint:fix`: Autofix [ESLint] errors.
- `npm run prettier`: Run [Prettier] for files other than JS.
- `npm run jest`: Run unit tests. During development, `npm run jest -- --watch`
is nice.
- `npm run coverage`: Run unit tests with code coverage.
- `npm test`: Check that everything works.
## License

@@ -83,9 +53,3 @@

<!-- prettier-ignore-start -->
[@aitodotai/json-stringify-pretty-compact]: https://www.npmjs.com/package/@aitodotai/json-stringify-pretty-compact
[eslint]: https://eslint.org/
[json.stringify]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify
[prettier]: https://prettier.io/
[travis-badge]: https://travis-ci.org/lydell/json-stringify-pretty-compact.svg?branch=master
[travis-link]: https://travis-ci.org/lydell/json-stringify-pretty-compact
<!-- prettier-ignore-end -->

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc