Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@slimio/json-diff

Package Overview
Dependencies
Maintainers
5
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@slimio/json-diff - npm Package Compare versions

Comparing version
0.1.0
to
0.1.1
+4
-4
package.json
{
"name": "@slimio/json-diff",
"version": "0.1.0",
"version": "0.1.1",
"description": "Stdout difference from two JS Objects in the TTY",

@@ -43,7 +43,7 @@ "main": "index.js",

"@slimio/eslint-config": "^3.0.3",
"@slimio/psp": "^0.8.0",
"@slimio/psp": "^0.9.2",
"ava": "^2.4.0",
"cross-env": "^6.0.3",
"eslint": "^6.6.0",
"husky": "^3.0.9",
"eslint": "^6.7.0",
"husky": "^3.1.0",
"jsdoc": "^3.6.3",

@@ -50,0 +50,0 @@ "nyc": "^14.1.1",

"use strict";
// Require Third-party Dependencies
const { red, green } = require("kleur");
const { red, green, grey } = require("kleur");
// CONSTANTS
const INDENT = 4;
/**

@@ -17,3 +16,3 @@ * @function colorObj

if (indent === 1) {
console.log("{");
console.log(grey().bold("{"));
}

@@ -25,11 +24,40 @@ const [lastKey] = Object.entries(obj).pop();

switch (type) {
case "object":
case "object": {
getLine(code, type, value, { key, indent, comma });
colorObj(value, indent + 1);
console.log(`${" ".repeat(indent * INDENT)}}${comma ? "," : ""}`);
if (code === 0) {
colorObj(value, indent + 1);
console.log(grey().bold(`${" ".repeat(indent * INDENT)}}${comma ? "," : ""}`));
break;
}
const split = JSON.stringify(value, null, INDENT).split("\n");
split.shift();
let colorFn;
let sign;
switch (code) {
case 1:
colorFn = green;
sign = "+";
break;
case -1:
colorFn = red;
sign = "-";
break;
}
for (const [index, line] of split.entries()) {
// console.log("LINE:" + line);
if (index === split.length - 1) {
console.log(colorFn(`${sign}${" ".repeat(indent * INDENT).slice(1)}${line}${comma ? "," : ""}`));
continue;
}
console.log(colorFn(`${sign}${" ".repeat(indent * INDENT).slice(1)}${line}`));
}
break;
}
case "array":
getLine(code, type, value, { key, indent, comma });
colorArray(value, indent + 1);
console.log(`${" ".repeat(indent * INDENT)}]${comma ? "," : ""}`);
console.log(grey().bold(`${" ".repeat(indent * INDENT)}]${comma ? "," : ""}`));
break;

@@ -52,3 +80,3 @@ default:

if (indent === 1) {
console.log("}");
console.log(grey().bold("}"));
}

@@ -80,26 +108,25 @@ }

const { key, indent = 1, comma } = options;
let colorFunc;
let newVal;
switch (type) {
case "object":
value = "{";
newVal = "{";
break;
case "array":
value = "[";
newVal = "[";
break;
default:
if (comma === true) {
value += ",";
}
newVal = comma === true ? `${value},` : value;
// value += ",";
}
const str = typeof key === "undefined" ?
`${" ".repeat(indent * INDENT)}${value}` :
`${" ".repeat(indent * INDENT)}${key}: ${value}`;
`${" ".repeat(indent * INDENT)}${newVal}` :
`${" ".repeat(indent * INDENT)}${key}: ${newVal}`;
switch (code) {
case 1:
console.log(green(`+${str.slice(1)}`));
break;
case -1:
console.log(red(`-${str.slice(1)}`));
break;
default: console.log(str);
case 1: console.log(green(`+${str.slice(1)}`)); break;
case -1: console.log(red(`-${str.slice(1)}`)); break;
default: console.log(grey().bold(str));
}

@@ -106,0 +133,0 @@ }