https://github.com/tomeraberbach/strict-diff
🔬 Find all observable differences between two values.
https://github.com/tomeraberbach/strict-diff
diff npm-package strict
Last synced: about 2 months ago
JSON representation
🔬 Find all observable differences between two values.
- Host: GitHub
- URL: https://github.com/tomeraberbach/strict-diff
- Owner: TomerAberbach
- License: mit
- Created: 2026-04-04T00:13:29.000Z (2 months ago)
- Default Branch: main
- Last Pushed: 2026-04-07T02:57:27.000Z (about 2 months ago)
- Last Synced: 2026-04-07T04:30:24.130Z (about 2 months ago)
- Topics: diff, npm-package, strict
- Language: TypeScript
- Homepage: https://npm.im/strict-diff
- Size: 188 KB
- Stars: 3
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
strict-diff
Find all observable differences between two values.
## Features
- **Strict:** Finds the most minuscule differences between values
- **Structured:** Diff objects have paths and left vs right values
- **Lazy:** Returns a lazy iterable over the diffs
## Install
```sh
$ npm i strict-diff
```
## Usage
```js
import strictDiff from 'strict-diff'
// Primitive value diff
console.log([...strictDiff(1, 2)])
//=> [{ kind: 'value', path: [], left: 1, right: 2 }]
// Type diff
console.log([...strictDiff(null, undefined)])
//=> [{ kind: 'type', path: [], left: 'null', right: 'undefined' }]
// Object property value diff
console.log([...strictDiff({ a: 1 }, { a: 2 })])
//=> [
// {
// kind: 'value',
// path: [
// { kind: 'property', index: 0, key: 'a' },
// { kind: 'internal-slot', slot: 'Value' },
// ],
// left: 1,
// right: 2,
// },
// ]
// Object key diff
console.log([...strictDiff({ a: 1 }, { b: 1 })])
//=> [{ kind: 'key', path: [], index: 0, left: 'a', right: 'b' }]
// Property descriptor diff (non-writable vs writable)
const left = Object.defineProperty({}, `a`, {
value: 1,
writable: false,
enumerable: true,
configurable: true,
})
console.log([...strictDiff(left, { a: 1 })])
//=> [
// {
// kind: 'value',
// path: [
// { kind: 'property', index: 0, key: 'a' },
// { kind: 'internal-slot', slot: 'Writable' },
// ],
// left: false,
// right: true,
// },
// ]
// Reference structure diff (shared object used at different positions)
const shared1 = {}
const shared2 = {}
const leftArray = [shared1, shared2, shared1, shared2]
const rightArray = [shared1, shared2, shared1, shared1]
console.log([...strictDiff(leftArray, rightArray)])
//=> [
// {
// kind: 'reference',
// path: [
// { kind: 'property', index: 3, key: 3 },
// { kind: 'internal-slot', slot: 'Value' },
// ],
// leftFirstSeenPath: [
// { kind: 'property', index: 1, key: 1 },
// { kind: 'internal-slot', slot: 'Value' },
// ],
// rightFirstSeenPath: [
// { kind: 'property', index: 0, key: 0 },
// { kind: 'internal-slot', slot: 'Value' },
// ],
// },
// ]
// Lazily iterated
const diffs = strictDiff({ a: 1, b: 2 }, { a: 99, b: 99 })
const [firstDiff] = diffs
console.log(firstDiff)
//=> {
// kind: 'value',
// path: [
// { kind: 'property', index: 0, key: 'a' },
// { kind: 'internal-slot', slot: 'Value' },
// ],
// left: 1,
// right: 99,
// }
```
See [the tests](./src/index.test.ts) for other example diffs.
## Contributing
Stars are always welcome!
For bugs and feature requests,
[please create an issue](https://github.com/TomerAberbach/strict-diff/issues/new).
## License
[MIT](https://github.com/TomerAberbach/strict-diff/blob/main/license) ©
[Tomer Aberbach](https://github.com/TomerAberbach)