New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

json-colorz

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-colorz - npm Package Compare versions

Comparing version 0.2.0 to 0.2.2

10

index.js

@@ -23,5 +23,11 @@ /*!

punc : 'yellow',
brack : 'yellow'
brack : 'yellow',
func : 'grey'
}
var display = {
func: false,
date: false
}
var level = {

@@ -42,2 +48,3 @@ show : false,

colors : colors,
display: display,
level : level,

@@ -70,2 +77,3 @@ params : params

jclrz.colors = colors
jclrz.display = display
jclrz.level = level

@@ -72,0 +80,0 @@ jclrz.params = params

69

lib/engine.js

@@ -8,3 +8,5 @@ var colorz = require('colorz')

return typeof value === 'object'
? toString.call(value)
? Object.prototype.toString.call(value)
.replace(/^\[object |\]$/g, '')
.toLowerCase()
: typeof value

@@ -14,3 +16,3 @@ }

function isObject (obj) {
return toString.call(obj) === '[object Object]'
return Object.prototype.toString.call(obj) === '[object Object]'
}

@@ -44,11 +46,22 @@

function indent (str, char, num) {
if (num === 0) return str
char = num > 1
? repeat(char, num)
: char
var re = /^(?!\s*$)/mg
return str.replace(re, char)
}
function getType (value) {
var map = {
'number' : 'num',
'string' : 'str',
'boolean' : 'bool',
'function' : 'func',
'null' : 'null',
'undefined' : 'undef',
'[object RegExp]' : 'regex'
'number' : 'num',
'string' : 'str',
'boolean' : 'bool',
'function' : 'func',
'null' : 'null',
'undefined' : 'undef',
'regexp' : 'regex',
'date' : 'date'
}

@@ -63,5 +76,4 @@ return map[kindOf(value)] || map['' + value]

for (key in obj) {
if (obj.hasOwnProperty(key)) {
(getType(obj[key]) === 'func') && delete obj[key] || (lastKey = key)
}
if (obj.hasOwnProperty(key)) lastKey = key
// (getType(obj[key]) === 'func') && delete obj[key] || (lastKey = key)
}

@@ -95,7 +107,9 @@ return lastKey

function colorify (value, level) {
var color = options.colors[getType(value)]
return generateLevel(level)
+ (getType(value) === 'str' ? colorifySpec('"', 'quot') : '')
+ useColorProvider('' + value, color)
+ (getType(value) === 'str' ? colorifySpec('"', 'quot') : '')
var type = getType(value)
var color = options.colors[type]
return generateLevel(type === 'func' ? 0 : level)
+ (type === 'str' ? colorifySpec('"', 'quot') : '')
+ useColorProvider(formatOutputType(value, type, level), color)
+ (type === 'str' ? colorifySpec('"', 'quot') : '')
}

@@ -108,2 +122,3 @@

function useColorProvider (str, color) {
if (!color) return str
if (options.params.colored) {

@@ -119,2 +134,19 @@ if (Array.isArray(color) && color.length > 1) {

function formatOutputType (value, type, level) {
if (type === 'func') {
if (options.display.func) {
var str = value.toString().split(/\n/)
var first = str[0] + '\n'
var rest = str.slice(1)
return first + indent(rest.join('\n'), ' ', generateLevel(level).length)
} else {
return '[Function]'
}
}
if (type === 'date' && !options.display.date) return '[Date]'
return '' + value
}
return {

@@ -164,3 +196,4 @@ gen: function (json, level, isChild) {

} else {
return generateLevel(isChild ? 0 : level) + colorify(json)
return generateLevel(isChild ? 0 : level)
+ colorify(json, typeof json === 'function' ? level : '')
}

@@ -167,0 +200,0 @@

{
"name": "json-colorz",
"version": "0.2.0",
"version": "0.2.2",
"description": "display a json or javascript object in the console with colorz",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -10,5 +10,5 @@ # json-colorz

## Why?
[Jsome](https://www.npmjs.com/package/jsome) uses [chalk](https://www.npmjs.com/package/chalk), has a command line interface and can be used in the browser. Json-colorz uses [colorz](https://www.npmjs.com/package/colorz), does not have a cli and is not configured to run in the browser. The motivation here was to stress test `colorz` and jsome (json-colorz) proved to be the module which would push `colorz` to its limits.
[Jsome](https://www.npmjs.com/package/jsome) uses [chalk](https://www.npmjs.com/package/chalk), has a command line interface and can be used in the browser. Json-colorz uses [colorz](https://www.npmjs.com/package/colorz), does not have a cli, is not configured to run in the browser, but can display functions and date calls within javascript objects. This is useful to me for debugging purposes. The main motivation here was to stress test `colorz`. Jsome/json-colorz proved to be the module which would push the limits.
So, I advocate to you, the user, USE [JSOME](https://github.com/Javascipt/Jsome). If you like this version, :+1:, but then go star [JSOME](https://github.com/Javascipt/Jsome). All credit for this code goes to Jsome author, [Khalid REHIOUI](https://www.npmjs.com/~javascript). What changes I have made are particular to my use case senarios. And I don't care much about stars and ratings.
So, I advocate to you, the user, USE [JSOME](https://github.com/Javascipt/Jsome). If you like this version, :+1:, great, fantastic. But then go star [JSOME](https://github.com/Javascipt/Jsome). All credit for this code goes to Jsome author, [Khalid REHIOUI](https://www.npmjs.com/~javascript). What changes I have made are particular to my use case senarios. And I don't care much about stars and ratings.

@@ -65,7 +65,7 @@ ## Installation

The following is a duplication of [jsome's readme](https://github.com/Javascipt/Jsome/blob/master/README.md). References changed where appropriate.
The following is a duplication of [jsome's readme](https://github.com/Javascipt/Jsome/blob/master/README.md). References changed and additions made where appropriate.
## API
The `jclrz` function returns the object passed as argument so that when debugging, you can print the value of an object without having to change a lot on your code
The `jclrz` function returns the object passed as an argument. When debugging, you can print the value of an object without having to change a lot on your code

@@ -132,3 +132,5 @@ ```javascript

'punc' : 'yellow', // commas seperating arrays and objects values -> [ , , , ]
'brack' : 'yellow' // for both {} and []
'brack' : 'yellow', // for both {} and []
'func' : 'grey' // stands for functions
// dates are not defined and will be displayed in the default term color.
}

@@ -146,5 +148,26 @@ ```

jclrz.colors.brack = ['yellow', 'bold']
jclrz.colors.date = ['red'] // you can defined a color for dates this way.
```
![jclrz](http://i.imgur.com/AKoAPJM.png)
![jclrz_no_func_date](http://i.imgur.com/e5l1Yox.png)
#### `jclrz.display`
You now have the option of displaying functions or dates within a javascript object. Functions are indented by the level at which they occur. Functions are also filtered out of arrays by default. This may be changed in the future, but only if there is demand for it.
```javascript
jclrz.display.func = true
jclrz.display.date = true
```
![jclrz_func_date](http://imgur.com/K4mrEME.png)
The default value of `display` is:
```javascript
jclrz.display = {
func: false,
date: false
}
```
#### `jclrz.params`

@@ -151,0 +174,0 @@

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