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

diff-json-data

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

diff-json-data - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

lib/diff.mjs

2

lib/diff.js

@@ -60,2 +60,2 @@ const diff = (value1, value2, key1 = 'value1', key2 = 'value2', strict = false) => {

export default diff
module.exports = diff
{
"name": "diff-json-data",
"version": "1.0.2",
"main": "index.js",
"version": "1.0.3",
"main": "./lib/diff.js",
"license": "MIT",

@@ -15,3 +15,4 @@ "type": "module",

"dependencies": {
"commander": "^9.3.0"
"commander": "^9.3.0",
"diff-json-data": "^1.0.2"
},

@@ -22,3 +23,9 @@ "repository": {

"directory": "packages/diff-json-data"
},
"exports": {
".": {
"require": "./lib/diff.js",
"import": "./lib/diff.mjs"
}
}
}

@@ -1,5 +0,15 @@

# diff-json-data
# <center>diff-json-data</center>
## Install
这是一个你可能需要的小工具~
它用于对比两个 json 之间的差异,然后最终输出一个 json 描述差异。这在你需要在两次接口返回的大量数据中找茬儿,寻找出中间的差异的时候还是挺好用的。
我最近做的一项工作就是,接口底层链路变更了,导致返回的数据与原本的数据存在着差异,我需要对比新旧接口返回数据的差异去做转换以及兼容。每次拿到两个非常庞大的对象的时候真的非常要命,看似没什么不同实际上,在对象深层的地方藏着非常细微的差别,导致了下游程序的崩溃。最终为了稳妥,我还是写了一个小工具来辅助我的工作,就是这个 diff-json-data。
[GitHub](https://github.com/winily/diff-json-data) 欢迎 star
## 如何安装
全局安装然后使用 cli
```shell

@@ -11,2 +21,49 @@ npm install -g diff-json-data

当然你也可以集成到你的项目里面去做一些奇怪的事情
```shell
npm install diff-json-data
# or
yarn add diff-json-data
```
## 如何使用
### 1. cli 的使用就非常的简单
```shell
diffjs -c path ./data1.json ./data2.json key new_interface old_interface
```
-c 表示你要进行两个 json 文件的对比
path 指令后面指定两个能寻找的到 json 文件的路径,使用空格隔开
key 指令后面指定两个 key 最终它会在 result.json 中体现,你也可以不指定,默认 key1 key2
你还可以使用 out 指令置顶结果 json 输出路径例如
```shell
diffjs -c path ./data1.json ./data2.json out ./interface_result.json
```
### 2. 集成到项目
这个项目就只导出了一个 diff function, 所以就直接拿到就用就行了
输入:
(value1: object, value2: object, key1 = 'value1', key2 = 'value2', strict = false)
输出差异结构对象
E.g:
```js
import diff from 'diff-json-data'
const result = diff({ hello: 'hhahah' }, { hello: 'hhahah', a: 1 })
console.log(result)
```
## E.g

@@ -90,1 +147,7 @@

```
## 如果有用
1 分也是爱~
<img src="https://github.com/winily/winily/blob/main/give_money.jpg" style="width: 200px;"/>
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