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

json-colorizer

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-colorizer - npm Package Compare versions

Comparing version 2.2.2 to 3.0.0

dist/index.js

38

package.json
{
"name": "json-colorizer",
"version": "2.2.2",
"version": "3.0.0",
"description": "A library to format JSON with colors for display in the console",
"main": "src/lib/index.js",
"main": "dist/index.js",
"files": [
"src/lib"
],
"types": "src/lib/index.d.ts",
"types": "dist/index.d.ts",
"scripts": {
"test": "mocha src/test",
"test:watch": "mocha -w src/test",
"prettify": "prettier --write src/**/*.js",
"lint": "eslint src"
"build": "tsc",
"prepublishOnly": "tsc"
},

@@ -25,3 +23,3 @@ "repository": {

],
"author": "Joe Attardi <jattardi@gmail.com> (http://joeattardi.codes)",
"author": "Joe Attardi <jattardi@gmail.com> (http://joeattardi.com)",
"license": "MIT",

@@ -31,26 +29,8 @@ "bugs": {

},
"dependencies": {
"chalk": "^2.4.1",
"lodash.get": "^4.4.2"
},
"devDependencies": {
"chai": "^4.2.0",
"eslint": "^5.9.0",
"eslint-plugin-prettier": "^3.0.0",
"husky": "^1.1.4",
"lint-staged": "^8.0.5",
"mocha": "^5.2.0",
"prettier": "^1.15.2"
"typescript": "^5.4.5"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"src/**/*.js": [
"prettier --write",
"git add"
]
"dependencies": {
"colorette": "^2.0.20"
}
}

@@ -14,12 +14,14 @@ # json-colorizer

```js
const colorize = require('json-colorizer');
console.log(colorize({ "foo": "bar" });
const { colorize } = require('json-colorizer');
console.log(colorize({ "foo": "bar" }));
```
If you pass a string to the colorize function, it will treat it as pre-serialized JSON. This can be used in order to colorize pretty-printed JSON:
You can also pass a JavaScript object to the `colorize` function:
```js
const colorize = require('json-colorizer');
const json = JSON.stringify({"foo": "bar"}, null, 2);
console.log(colorize(json);
const { colorize } = require('json-colorizer');
console.log(colorize({
foo: 'bar',
baz: 42
}));
```

@@ -29,25 +31,22 @@

To pretty-print the resulting JSON, pass the `pretty: true` option to the options object:
By default, the output JSON will be pretty-printed with an indentation of 2 spaces. You can adjust this by passing the `indent` option.
```js
const colorize = require('json-colorizer');
const json = '{"foo": "bar"}';
console.log(colorize(json, { pretty: true }));
const { colorize } = require('json-colorizer');
console.log(colorize({
foo: 'bar',
baz: 42
}, { indent: 4 }));
```
## Specifying colors
## Customizing the colors
__NOTE__: Prior to version 2.x, the colors were specified by referencing `chalk` color functions directly. This required requiring `chalk` into the file. Starting with version 2.x, the colors are specified as a string which is the name (or property path) to the desired color function.
You can override any of the colors used for token types by providing a `colors` option. This should map token types to the names of color functions. These color functions are contained in the `color` object exported by the library.
You can specify a color to use for coloring individual tokens by providing a `colors` object in the options object. This should map token types to the names of color functions (see the [chalk styles reference](https://www.npmjs.com/package/chalk#styles)).
```js
const { colorize, color } = require('json-colorizer');
A color can also be specified as a hex value starting with the `#` symbol.
```js
const colorize = require('json-colorizer');
console.log(colorize({ "foo": "bar" }, {
console.log(colorize({ foo: 'bar' }, {
colors: {
STRING_KEY: 'green',
STRING_LITERAL: 'magenta.bold',
NUMBER_LITERAL: '#FF0000'
StringLiteral: color.red
}

@@ -57,12 +56,26 @@ }));

The tokens available are:
The list of valid token types and color functions are listed below.
* `BRACE`
* `BRACKET`
* `COLON`
* `COMMA`
* `STRING_KEY`
* `STRING_LITERAL`
* `NUMBER_LITERAL`
* `BOOLEAN_LITERAL`
* `NULL_LITERAL`
### Token types
- `Brace`: curly braces (`{`, `}`)
- `Bracket`: square brackets (`[`, `]`)
- `Colon`: colon character (`:`)
- `Comma`: comma character (`,`)
- `StringKey`: the key in a key/value pair
- `NumberLiteral`: a number value
- `StringLiteral`: a string value
- `BooleanLiteral`: a boolean literal (`true`, `false`)
- `NullLiteral`: the literal `null` value
### Color functions in the `color` object
- `black`
- `red`
- `green`
- `yellow`
- `blue`
- `magenta`
- `cyan`
- `white`
- `gray`
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