Installations
npm install json-diff-ts-w
Developer Guide
Typescript
Yes
Module System
CommonJS
Node Version
12.18.0
NPM Version
6.14.4
Score
71.9
Supply Chain
99.4
Quality
75.2
Maintenance
100
Vulnerability
99.6
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (100%)
Developer
Merynek
Download Statistics
Total Downloads
366
Last Day
1
Last Week
3
Last Month
7
Last Year
54
GitHub Statistics
74 Commits
1 Watching
5 Branches
1 Contributors
Bundle Size
6.68 kB
Minified
2.35 kB
Minified + Gzipped
Package Meta Information
Latest Version
1.1.1
Package Id
json-diff-ts-w@1.1.1
Unpacked Size
31.72 kB
Size
7.20 kB
File Count
9
NPM Version
6.14.4
Node Version
12.18.0
Total Downloads
Cumulative downloads
Total Downloads
366
Last day
0%
1
Compared to previous day
Last week
200%
3
Compared to previous week
Last month
600%
7
Compared to previous month
Last year
-11.5%
54
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Peer Dependencies
1
json-diff-ts
A diff tool for JavaScript based on https://www.npmjs.com/package/diff-json (viruschidai@gmail.com) rewritten in TypeScript.
The most compelling feature of this diff library is the support for array keys instead of just indexes and is compatible with JSONPath.
Features
diff
If a key is specified for an embedded array, the diff will be generated based on the objects have same keys.
Examples:
1 2 var changesets = require('diff-json-ts'); 3 var newObj, oldObj; 4 5 oldObj = { 6 name: 'joe', 7 age: 55, 8 coins: [2, 5], 9 children: [ 10 {name: 'kid1', age: 1}, 11 {name: 'kid2', age: 2} 12 ]}; 13 14 newObj = { 15 name: 'smith', 16 coins: [2, 5, 1], 17 children: [ 18 {name: 'kid3', age: 3}, 19 {name: 'kid1', age: 0}, 20 {name: 'kid2', age: 2} 21 ]}; 22 23 24 // Assume children is an array of child object and the child object has 'name' as its primary key 25 diffs = changesets.diff(oldObj, newObj, {children: 'name'}); // keys can also be hierarchical e.g. {children: 'name', 'children.grandChildren', 'age'} 26 27 expect(diffs).to.eql([ 28 { 29 type: 'update', key: 'name', value: 'smith', oldValue: 'joe' 30 }, 31 { 32 type: 'update', key: 'coins', embededKey: '$index', changes: [ 33 {type: 'add', key: '2', value: 1 } 34 ] 35 }, 36 { 37 type: 'update', 38 key: 'children', 39 embededKey: 'name', 40 changes: [ 41 { 42 type: 'update', key: 'kid1', changes: [ 43 {type: 'update', key: 'age', value: 0, oldValue: 1 } 44 ] 45 }, 46 { 47 type: 'add', key: 'kid3', value: {name: 'kid3', age: 3 } 48 } 49 ] 50 }, 51 { 52 type: 'remove', key: 'age', value: 55 53 } 54 ]);
flattenChangeset
Converts the changeset into a flat atomic change list compatible with JSONPath.
Examples:
1const flatChanges = flattenChangeset(diffs); 2// convert changes back to changeset format 3const changeset = unflattenChanges(flatChanges.slice(1, 5)); 4// or use a JSONPath library to apply the patches 5// ...
The flatChange format will look like this:
1[ 2 { type: 'UPDATE', key: 'name', value: 'smith', oldValue: 'joe', path: '$.name', valueType: 'String' }, 3 { type: 'REMOVE', key: 'mixed', value: 10, path: '$.mixed', valueType: 'Number' }, 4 { type: 'UPDATE', key: 'inner', value: 2, oldValue: 1, path: '$.nested.inner', valueType: 'Number' }, 5 { 6 type: 'UPDATE', 7 key: 'date', 8 value: '2014-10-12T09:13:00.000Z', 9 oldValue: '2014-10-13T09:13:00.000Z', 10 path: '$.date', 11 valueType: 'Date' 12 }, 13 { type: 'ADD', key: '2', value: 1, path: '$.coins[2]', valueType: 'Number' }, 14 { type: 'REMOVE', key: '0', value: 'car', path: '$.toys[0]', valueType: 'String' }, 15 { type: 'REMOVE', key: '1', value: 'doll', path: '$.toys[1]', valueType: 'String' }, 16 { type: 'REMOVE', key: '0', path: '$.pets[0]', valueType: 'undefined' }, 17 { type: 'REMOVE', key: '1', value: null, path: '$.pets[1]', valueType: null }, 18 { type: 'UPDATE', key: 'age', value: 0, oldValue: 1, path: "$.children[?(@.name='kid1')].age", valueType: 'Number' }, 19 { 20 type: 'UPDATE', 21 key: 'value', 22 value: 'heihei', 23 oldValue: 'haha', 24 path: "$.children[?(@.name='kid1')].subset[?(@.id='1')].value", 25 valueType: 'String' 26 }, 27 { 28 type: 'REMOVE', 29 key: '2', 30 value: { id: 2, value: 'hehe' }, 31 path: "$.children[?(@.name='kid1')].subset[?(@.id='2')]", 32 valueType: 'Object' 33 }, 34 { type: 'ADD', key: 'kid3', value: { name: 'kid3', age: 3 }, path: '$.children', valueType: 'Object' } 35];
applyChange
Examples:
1 2 var changesets = require('diff-json-ts'); 3 var oldObj = { 4 name: 'joe', 5 age: 55, 6 coins: [2, 5], 7 children: [ 8 {name: 'kid1', age: 1}, 9 {name: 'kid2', age: 2} 10 ]}; 11 12 13 // Assume children is an array of child object and the child object has 'name' as its primary key 14 diffs = [ 15 { 16 type: 'update', key: 'name', value: 'smith', oldValue: 'joe' 17 }, 18 { 19 type: 'update', key: 'coins', embededKey: '$index', changes: [ 20 {type: 'add', key: '2', value: 1 } 21 ] 22 }, 23 { 24 type: 'update', 25 key: 'children', 26 embededKey: 'name', // The key property name of the elements in an array 27 changes: [ 28 { 29 type: 'update', key: 'kid1', changes: [ 30 {type: 'update', key: 'age', value: 0, oldValue: 1 } 31 ] 32 }, 33 { 34 type: 'add', key: 'kid3', value: {name: 'kid3', age: 3 } 35 } 36 ] 37 }, 38 { 39 type: 'remove', key: 'age', value: 55 40 } 41 ] 42 43 changesets.applyChanges(oldObj, diffs) 44 expect(oldObj).to.eql({ 45 name: 'smith', 46 coins: [2, 5, 1], 47 children: [ 48 {name: 'kid3', age: 3}, 49 {name: 'kid1', age: 0}, 50 {name: 'kid2', age: 2} 51 ]}); 52
revertChange
Examples:
1 2 var changesets = require('diff-json-ts'); 3 4 var newObj = { 5 name: 'smith', 6 coins: [2, 5, 1], 7 children: [ 8 {name: 'kid3', age: 3}, 9 {name: 'kid1', age: 0}, 10 {name: 'kid2', age: 2} 11 ]}; 12 13 // Assume children is an array of child object and the child object has 'name' as its primary key 14 diffs = [ 15 { 16 type: 'update', key: 'name', value: 'smith', oldValue: 'joe' 17 }, 18 { 19 type: 'update', key: 'coins', embededKey: '$index', changes: [ 20 {type: 'add', key: '2', value: 1 } 21 ] 22 }, 23 { 24 type: 'update', 25 key: 'children', 26 embededKey: 'name', // The key property name of the elements in an array 27 changes: [ 28 { 29 type: 'update', key: 'kid1', changes: [ 30 {type: 'update', key: 'age', value: 0, oldValue: 1 } 31 ] 32 }, 33 { 34 type: 'add', key: 'kid3', value: {name: 'kid3', age: 3 } 35 } 36 ] 37 }, 38 { 39 type: 'remove', key: 'age', value: 55 40 } 41 ] 42 43 changesets.revertChanges(newObj, diffs) 44 expect(newObj).to.eql { 45 name: 'joe', 46 age: 55, 47 coins: [2, 5], 48 children: [ 49 {name: 'kid1', age: 1}, 50 {name: 'kid2', age: 2} 51 ]}; 52
Get started
npm install diff-json-ts
Run the test
npm run test
Contact
Blog: https://blog.leitwolf.io
Twitter: @cglessner
Licence
The MIT License (MIT)
Copyright (c) 2019 Christian Glessner
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
The project is based on diff-json (https://www.npmjs.com/package/diff-json). Copyright 2013 viruschidai@gmail.com. for additional details.
Original License
The MIT License (MIT)
Copyright (c) 2013 viruschidai@gmail.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
dependency not pinned by hash detected -- score normalized to 4
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/node.dev.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/Merynek/json-diff-ts/node.dev.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/node.dev.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/Merynek/json-diff-ts/node.dev.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/node.master.js.yml:18: update your workflow using https://app.stepsecurity.io/secureworkflow/Merynek/json-diff-ts/node.master.js.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/node.master.js.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/Merynek/json-diff-ts/node.master.js.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/node.master.js.yml:30: update your workflow using https://app.stepsecurity.io/secureworkflow/Merynek/json-diff-ts/node.master.js.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/node.master.js.yml:31: update your workflow using https://app.stepsecurity.io/secureworkflow/Merynek/json-diff-ts/node.master.js.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/node.master.js.yml:36: update your workflow using https://app.stepsecurity.io/secureworkflow/Merynek/json-diff-ts/node.master.js.yml/master?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/node.master.js.yml:35
- Info: 0 out of 6 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 third-party GitHubAction dependencies pinned
- Info: 2 out of 3 npmCommand dependencies pinned
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/node.dev.yml:1
- Warn: no topLevel permission defined: .github/workflows/node.master.js.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
32 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-8r6j-v8pm-fqw3
- Warn: Project is vulnerable to: MAL-2023-462
- Warn: Project is vulnerable to: GHSA-qqgx-2p2h-9c37
- Warn: Project is vulnerable to: GHSA-896r-f27r-55mw
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-6c8f-qphg-qjgp
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m
- Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-5fw9-fq32-wv5p
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-3jfq-g458-7qm9
- Warn: Project is vulnerable to: GHSA-r628-mhmh-qjhw
- Warn: Project is vulnerable to: GHSA-9r2w-394v-53qc
- Warn: Project is vulnerable to: GHSA-5955-9wpr-37jh
- Warn: Project is vulnerable to: GHSA-qq89-hq3f-393p
- Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36
- Warn: Project is vulnerable to: GHSA-jgrx-mgxx-jf9v
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
- Warn: Project is vulnerable to: GHSA-p9pc-299p-vxgp
Score
2.8
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to json-diff-ts-w
@xdanangelxoqenpm/officia-omnis-dignissimos
[![NPM](https://img.shields.io/npm/v/@xdanangelxoqenpm/officia-omnis-dignissimos.svg?style=flat-square)](https://www.npmjs.com/package/@xdanangelxoqenpm/officia-omnis-dignissimos) [![GitHub Workflow Status (master)](https://img.shields.io/github/actions/w
@wemnyelezxnpm/error-ab-eligendi
[<img alt="build status" src="https://github.com/wemnyelezxnpm/error-ab-eligendi/workflows/test/badge.svg" height="20">][ci-url] [<img alt="Discord" src="https://img.shields.io/discord/853978108758851604?color=5865F2&label=Discord&logo=discord&logoColor=w
@diahkomalasarinpm/vitae-aperiam-cum
[![CI browser tests](https://github.com/diahkomalasarinpm/vitae-aperiam-cum/actions/workflows/xvfb-ci.yml/badge.svg)](https://github.com/diahkomalasarinpm/vitae-aperiam-cum/actions/workflows/xvfb-ci.yml) [![NPM version](https://badge.fury.io/js/readable-w