Skip to content

Commit c3fca8e

Browse files
committed
feat: init
1 parent 1c3f750 commit c3fca8e

27 files changed

Lines changed: 7824 additions & 276 deletions

.eslintignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# package.json is formatted by package managers, so we ignore it here
2+
package.json
3+
build
4+
node_modules

.prettierignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
# package.json is formatted by package managers, so we ignore it here
2-
package.json
2+
build
3+
node_modules

.prettierrc.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = {
2+
"printWidth": 100,
3+
"trailingComma": "all",
4+
"singleQuote": false,
5+
"semi": true,
6+
"tabWidth": 2,
7+
"quoteProps": "as-needed",
8+
"jsxSingleQuote": false,
9+
"arrowParens": "always"
10+
}

README.md

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,73 @@
1-
# json-diff-patch
1+
# JsonDiffPatch
22

3-
Find Diff in JSON
3+
This document provides an overview of the test suite for the JsonDiffPatch library, which is designed to showcase the capabilities and features of the library through various examples and test cases.
4+
5+
## Overview
6+
7+
JsonDiffPatch is a library that allows for the diffing and patching of JSON objects.
8+
9+
```bash
10+
npm install json-diff-patch
11+
```
12+
13+
1. Import JsonDiffPatch in your project:
14+
15+
```javascript
16+
import { DiffPatcher } from 'json-diff-patch';
17+
```
18+
19+
2. Create a `DiffPatcher` instance:
20+
21+
```javascript
22+
const diffPatcher = new DiffPatcher();
23+
```
24+
25+
3. Use the `diff`, `patch`, and `reverse` methods to work with your JSON objects:
26+
27+
- **Diff**: To find the difference between two objects.
28+
- **Patch**: To apply a patch to an object.
29+
- **Reverse**: To reverse a patch.
30+
31+
## Examples
32+
33+
### Diffing Two Objects
34+
35+
```javascript
36+
const left = { name: 'John', age: 25 };
37+
const right = { name: 'John', age: 26 };
38+
39+
const delta = diffPatcher.diff(left, right);
40+
console.log(delta);
41+
// Output: { age: [25, 26] }
42+
```
43+
44+
### Patching an Object
45+
46+
```javascript
47+
const original = { name: 'John', age: 25 };
48+
const delta = { age: [25, 26] };
49+
50+
const patched = diffPatcher.patch(original, delta);
51+
console.log(patched);
52+
// Output: { name: 'John', age: 26 }
53+
```
54+
55+
### Using Property Filter
56+
57+
In scenarios where you want to ignore certain properties during diffing, you can use the `propertyFilter` option.
58+
59+
```javascript
60+
const options = {
61+
propertyFilter: function(name) {
62+
return name.slice(0, 1) !== '$';
63+
},
64+
};
65+
const diffPatcherWithFilter = new DiffPatcher(options);
66+
67+
const left = { data: { $volatile: 123, stable: 456 } };
68+
const right = { data: { $volatile: 124, stable: 456 } };
69+
70+
const delta = diffPatcherWithFilter.diff(left, right);
71+
console.log(delta);
72+
// Output: undefined (since the change is in a filtered property)
73+
```

package.json

Lines changed: 24 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,14 @@
1919
"test:lint": "eslint src --ext .ts",
2020
"test:prettier": "prettier \"src/**/*.ts\" --list-different",
2121
"test:spelling": "cspell \"{README.md,.github/*.md,src/**/*.ts}\"",
22-
"test:unit": "nyc --silent ava",
22+
"test:unit": "cross-env CI=true vitest",
2323
"check-cli": "run-s test diff-integration-tests check-integration-tests",
2424
"check-integration-tests": "run-s check-integration-test:*",
2525
"diff-integration-tests": "mkdir -p diff && rm -rf diff/test && cp -r test diff/test && rm -rf diff/test/test-*/.git && cd diff && git init --quiet && git add -A && git commit --quiet --no-verify --allow-empty -m 'WIP' && echo '\\n\\nCommitted most recent integration test output in the \"diff\" directory. Review the changes with \"cd diff && git diff HEAD\" or your preferred git diff viewer.'",
2626
"watch:build": "tsc -p tsconfig.json -w",
27-
"watch:test": "nyc --silent ava --watch",
28-
"cov": "run-s build test:unit cov:html cov:lcov && open-cli coverage/index.html",
29-
"cov:html": "nyc report --reporter=html",
30-
"cov:lcov": "nyc report --reporter=lcov",
31-
"cov:send": "run-s cov:lcov && codecov",
32-
"cov:check": "nyc report && nyc check-coverage --lines 100 --functions 100 --branches 100",
27+
"watch:test": "vitest --watch",
28+
"test:ui": "run-s test:watch -- --ui",
29+
"test:coverage": "run-s test:unit -- run --coverage",
3330
"doc": "run-s doc:html && open-cli build/docs/index.html",
3431
"doc:html": "typedoc src/ --exclude **/*.spec.ts --target ES6 --mode file --out build/docs",
3532
"doc:json": "typedoc src/ --exclude **/*.spec.ts --target ES6 --mode file --json build/docs/typedoc.json",
@@ -39,34 +36,30 @@
3936
"prepare-release": "run-s reset-hard test cov:check doc:html version doc:publish"
4037
},
4138
"engines": {
42-
"node": ">=10"
43-
},
44-
"dependencies": {
45-
"@bitauth/libauth": "^1.17.1"
39+
"node": ">=14"
4640
},
4741
"devDependencies": {
48-
"@ava/typescript": "^1.1.1",
49-
"@istanbuljs/nyc-config-typescript": "^1.0.1",
50-
"@typescript-eslint/eslint-plugin": "^4.0.1",
51-
"@typescript-eslint/parser": "^4.0.1",
52-
"ava": "^3.12.1",
53-
"codecov": "^3.5.0",
54-
"cspell": "^4.1.0",
42+
"@typescript-eslint/eslint-plugin": "^7.16.1",
43+
"@typescript-eslint/parser": "^7.16.1",
44+
"@vitest/coverage-istanbul": "^2.0.3",
45+
"@vitest/ui": "^2.0.3",
46+
"cross-env": "^7.0.3",
47+
"cspell": "^8.11.0",
5548
"cz-conventional-changelog": "^3.3.0",
56-
"eslint": "^7.8.0",
57-
"eslint-config-prettier": "^6.11.0",
49+
"eslint": "^9.7.0",
50+
"eslint-config-prettier": "^9.1.0",
5851
"eslint-plugin-eslint-comments": "^3.2.0",
59-
"eslint-plugin-functional": "^3.0.2",
60-
"eslint-plugin-import": "^2.22.0",
61-
"gh-pages": "^3.1.0",
52+
"eslint-plugin-functional": "^6.6.3",
53+
"eslint-plugin-import": "^2.29.1",
54+
"gh-pages": "^6.1.1",
6255
"npm-run-all": "^4.1.5",
63-
"nyc": "^15.1.0",
64-
"open-cli": "^6.0.1",
65-
"prettier": "^2.1.1",
66-
"standard-version": "^9.0.0",
67-
"ts-node": "^9.0.0",
68-
"typedoc": "^0.19.0",
69-
"typescript": "^4.0.2"
56+
"open-cli": "^8.0.0",
57+
"prettier": "^3.3.3",
58+
"standard-version": "^9.5.0",
59+
"ts-node": "^10.9.2",
60+
"typedoc": "^0.26.4",
61+
"typescript": "^5.5.3",
62+
"vitest": "^2.0.3"
7063
},
7164
"files": [
7265
"build/main",
@@ -76,31 +69,5 @@
7669
"CHANGELOG.md",
7770
"LICENSE",
7871
"README.md"
79-
],
80-
"ava": {
81-
"failFast": true,
82-
"timeout": "60s",
83-
"typescript": {
84-
"rewritePaths": {
85-
"src/": "build/main/"
86-
}
87-
},
88-
"files": [
89-
"!build/module/**"
90-
]
91-
},
92-
"config": {
93-
"commitizen": {
94-
"path": "cz-conventional-changelog"
95-
}
96-
},
97-
"prettier": {
98-
"singleQuote": true
99-
},
100-
"nyc": {
101-
"extends": "@istanbuljs/nyc-config-typescript",
102-
"exclude": [
103-
"**/*.spec.js"
104-
]
105-
}
72+
]
10673
}

0 commit comments

Comments
 (0)