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.1.3 to 2.2.0

example.js

4

package.json
{
"name": "json-colorizer",
"version": "2.1.3",
"version": "2.2.0",
"description": "A library to format JSON with colors for display in the console",

@@ -21,3 +21,3 @@ "main": "src/lib/index.js",

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

@@ -24,0 +24,0 @@ "bugs": {

@@ -26,3 +26,12 @@ # json-colorizer

## Pretty-printing output
To pretty-print the resulting JSON, pass the `pretty: true` option to the options object:
```js
const colorize = require('json-colorizer');
const json = '{"foo": "bar"}';
console.log(colorize(json, { pretty: true }));
```
## Specifying colors

@@ -32,3 +41,3 @@

You can specify a color to use for coloring individual tokens by providing a `colors` object. This should map token types to the names of color functions (see the [chalk styles reference](https://www.npmjs.com/package/chalk#styles)).
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)).

@@ -35,0 +44,0 @@ A color can also be specified as a hex value starting with the `#` symbol.

@@ -16,5 +16,4 @@ const chalk = require('chalk');

exports.colorize = function colorize(tokens, options) {
const opts = options || {};
const colors = opts.colors || {};
exports.colorize = function colorize(tokens, options = {}) {
const colors = options.colors || {};

@@ -21,0 +20,0 @@ return tokens.reduce((acc, token) => {

@@ -5,3 +5,3 @@ const lexer = require('./lexer');

module.exports = function colorizeJson(json, options) {
return colorizer.colorize(lexer.getTokens(json), options);
return colorizer.colorize(lexer.getTokens(json, options), options);
};

@@ -14,5 +14,12 @@ const tokenTypes = [

exports.getTokens = function getTokens(json) {
let input = typeof json === 'string' ? json : JSON.stringify(json);
exports.getTokens = function getTokens(json, options = {}) {
let input;
if (options.pretty) {
const inputObj = typeof json === 'string' ? JSON.parse(json) : json;
input = JSON.stringify(inputObj, null, 2);
} else {
input = typeof json === 'string' ? json : JSON.stringify(json);
}
let tokens = [];

@@ -19,0 +26,0 @@ let foundToken;

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