mirror of
https://github.com/LukeHagar/arbiter.git
synced 2025-12-10 04:19:26 +00:00
Saving all progress
This commit is contained in:
21
node_modules/microdiff/LICENSE
generated
vendored
Normal file
21
node_modules/microdiff/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2021 AsyncBanana
|
||||
|
||||
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.
|
||||
92
node_modules/microdiff/README.md
generated
vendored
Normal file
92
node_modules/microdiff/README.md
generated
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
<div align="center">
|
||||
|
||||

|
||||
|
||||
Microdiff is a tiny (<1kb), fast, zero dependency object and array comparison library. It is significantly faster than most other deep comparison libraries, and has full TypeScript support.
|
||||
|
||||
> 💡 I recommend reading this blog post:
|
||||
>
|
||||
> **[Building the fastest object and array differ](https://byteofdev.com/posts/microdiff/)** for an explanation of how Microdiff achieves its size and speed.
|
||||
|
||||
  
|
||||
|
||||
</div>
|
||||
|
||||
# Features
|
||||
|
||||
- 🚀 More than double the speed of other object diff libraries
|
||||
- 📦 Extremely lightweight, <1kb minified
|
||||
- 🌎 Supports Deno, Node, Bun, the web, and even service workers. Also comes with built-in Typescript types
|
||||
- 🔰 Very easy to use, having just a single `diff()` function
|
||||
- 📅 Full support for objects like `new Date()` and `new RegExp()`
|
||||
|
||||
# Get started
|
||||
|
||||
First, install Microdiff
|
||||
|
||||
```
|
||||
npm i microdiff
|
||||
```
|
||||
|
||||
If you are using Deno, you can import it from Deno.land with the link `https://deno.land/x/microdiff@VERSION/index.ts` (remember to change `@VERSION` to the version you want to use).
|
||||
|
||||
After you install it, import it and run it on two objects.
|
||||
|
||||
```js
|
||||
import diff from "microdiff";
|
||||
|
||||
const obj1 = {
|
||||
originalProperty: true,
|
||||
};
|
||||
const obj2 = {
|
||||
originalProperty: true,
|
||||
newProperty: "new",
|
||||
};
|
||||
|
||||
console.log(diff(obj1, obj2));
|
||||
// [{type: "CREATE", path: ["newProperty"], value: "new"}]
|
||||
```
|
||||
|
||||
If you are using CommonJS, you can import it like this:
|
||||
|
||||
```js
|
||||
const diff = require("microdiff").default;
|
||||
```
|
||||
|
||||
There are three different types of changes: `CREATE`, `REMOVE`, and `CHANGE`.
|
||||
The `path` property gives a path to the property in the new object (or the old object in the case of `REMOVE`).
|
||||
Each element in the paths is a key to the next property a level deeper until you get to the property changed, and it is a string or a number, depending on whether the object is an Array or Object (Objects with number keys will still be strings).
|
||||
The `value` property exists in types `CREATE` and `CHANGE`, and it contains the value of the property added/changed/deleted.
|
||||
The `oldValue` property exists in the type `CHANGE` and `REMOVE`, and it contains the old value of the property.
|
||||
|
||||
# Cycles support
|
||||
|
||||
By default, Microdiff supports cyclical references, but if you are sure that the object has no cycles like parsed JSON, you can disable cycles using the `cyclesFix` option.
|
||||
|
||||
```js
|
||||
diff(obj1, obj2, { cyclesFix: false });
|
||||
```
|
||||
|
||||
# Benchmarks
|
||||
|
||||
```
|
||||
Geometric mean of time per operation relative to Microdiff (no cycles) (100%==equal time, lower is better)
|
||||
microdiff (no cycles): 100%
|
||||
microdiff: 149%
|
||||
deep-diff: 197%
|
||||
deep-object-diff: 288%
|
||||
jsDiff: 1565%
|
||||
```
|
||||
|
||||
These results are from a suite of benchmarks matching real world use cases of multiple open-source repos using various diffing algorithm, running under Node 22.12.0 on a Ryzen 7950x clocked at ~4.30 GHz. The benchmarks are run through [mitata](https://github.com/evanwashere/mitata) to minimize random variation and time most accurately. You can view the full benchmark code in [bench.js](https://github.com/AsyncBanana/microdiff/blob/master/bench.js) and the benchmarks themselves at [benchmarks/applied](https://github.com/AsyncBanana/microdiff/tree/master/benchmarks/applied).
|
||||
|
||||
Of course, [these benchmarks should be taken with a grain of salt](https://byteofdev.com/posts/javascript-benchmarking-mess/) due to the inherent errors present in benchmarking JavaScript, but if you want to run them on your own computer in your own runtime/setup, run `bench.js`.
|
||||
|
||||
# Contributing
|
||||
|
||||
Thanks for helping the project out! Contributing is pretty simple. Fork the repository (if you need more information on how to do this, check out [this GitHub guide](https://docs.github.com/en/get-started/quickstart/contributing-to-projects)), clone it to your computer, and start programming! To compile the program, run `npm run build` (replace `npm` with `pnpm` or `yarn` if you are using one of those). This will create CommonJS and ESM modules in `/dist`.
|
||||
|
||||
To benchmark microdiff, you can run `npm run bench`. This will automatically build Microdiff and run a benchmarking program comparing microdiff to other common diffing libraries.
|
||||
|
||||
Finally, Microdiff has an extensive test suite which you should take advantage of. To make sure everything is working correctly, you can run `npm run test`. `npm run test` builds the project and then runs the entire test suite on the new version. If you are fixing a bug, be sure to add a test for that.
|
||||
Also, make sure you read the [Code of Conduct](https://github.com/AsyncBanana/microdiff/blob/master/CODE_OF_CONDUCT.md) before contributing.
|
||||
59
node_modules/microdiff/dist/index.cjs
generated
vendored
Normal file
59
node_modules/microdiff/dist/index.cjs
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = diff;
|
||||
const richTypes = { Date: true, RegExp: true, String: true, Number: true };
|
||||
function diff(obj, newObj, options = { cyclesFix: true }, _stack = []) {
|
||||
let diffs = [];
|
||||
const isObjArray = Array.isArray(obj);
|
||||
for (const key in obj) {
|
||||
const objKey = obj[key];
|
||||
const path = isObjArray ? +key : key;
|
||||
if (!(key in newObj)) {
|
||||
diffs.push({
|
||||
type: "REMOVE",
|
||||
path: [path],
|
||||
oldValue: obj[key],
|
||||
});
|
||||
continue;
|
||||
}
|
||||
const newObjKey = newObj[key];
|
||||
const areCompatibleObjects = typeof objKey === "object" &&
|
||||
typeof newObjKey === "object" &&
|
||||
Array.isArray(objKey) === Array.isArray(newObjKey);
|
||||
if (objKey &&
|
||||
newObjKey &&
|
||||
areCompatibleObjects &&
|
||||
!richTypes[Object.getPrototypeOf(objKey)?.constructor?.name] &&
|
||||
(!options.cyclesFix || !_stack.includes(objKey))) {
|
||||
diffs.push.apply(diffs, diff(objKey, newObjKey, options, options.cyclesFix ? _stack.concat([objKey]) : []).map((difference) => {
|
||||
difference.path.unshift(path);
|
||||
return difference;
|
||||
}));
|
||||
}
|
||||
else if (objKey !== newObjKey &&
|
||||
// treat NaN values as equivalent
|
||||
!(Number.isNaN(objKey) && Number.isNaN(newObjKey)) &&
|
||||
!(areCompatibleObjects &&
|
||||
(isNaN(objKey)
|
||||
? objKey + "" === newObjKey + ""
|
||||
: +objKey === +newObjKey))) {
|
||||
diffs.push({
|
||||
path: [path],
|
||||
type: "CHANGE",
|
||||
value: newObjKey,
|
||||
oldValue: objKey,
|
||||
});
|
||||
}
|
||||
}
|
||||
const isNewObjArray = Array.isArray(newObj);
|
||||
for (const key in newObj) {
|
||||
if (!(key in obj)) {
|
||||
diffs.push({
|
||||
type: "CREATE",
|
||||
path: [isNewObjArray ? +key : key],
|
||||
value: newObj[key],
|
||||
});
|
||||
}
|
||||
}
|
||||
return diffs;
|
||||
}
|
||||
22
node_modules/microdiff/dist/index.d.cts
generated
vendored
Normal file
22
node_modules/microdiff/dist/index.d.cts
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
export interface DifferenceCreate {
|
||||
type: "CREATE";
|
||||
path: (string | number)[];
|
||||
value: any;
|
||||
}
|
||||
export interface DifferenceRemove {
|
||||
type: "REMOVE";
|
||||
path: (string | number)[];
|
||||
oldValue: any;
|
||||
}
|
||||
export interface DifferenceChange {
|
||||
type: "CHANGE";
|
||||
path: (string | number)[];
|
||||
value: any;
|
||||
oldValue: any;
|
||||
}
|
||||
export type Difference = DifferenceCreate | DifferenceRemove | DifferenceChange;
|
||||
interface Options {
|
||||
cyclesFix: boolean;
|
||||
}
|
||||
export default function diff(obj: Record<string, any> | any[], newObj: Record<string, any> | any[], options?: Partial<Options>, _stack?: Record<string, any>[]): Difference[];
|
||||
export {};
|
||||
22
node_modules/microdiff/dist/index.d.ts
generated
vendored
Normal file
22
node_modules/microdiff/dist/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
export interface DifferenceCreate {
|
||||
type: "CREATE";
|
||||
path: (string | number)[];
|
||||
value: any;
|
||||
}
|
||||
export interface DifferenceRemove {
|
||||
type: "REMOVE";
|
||||
path: (string | number)[];
|
||||
oldValue: any;
|
||||
}
|
||||
export interface DifferenceChange {
|
||||
type: "CHANGE";
|
||||
path: (string | number)[];
|
||||
value: any;
|
||||
oldValue: any;
|
||||
}
|
||||
export type Difference = DifferenceCreate | DifferenceRemove | DifferenceChange;
|
||||
interface Options {
|
||||
cyclesFix: boolean;
|
||||
}
|
||||
export default function diff(obj: Record<string, any> | any[], newObj: Record<string, any> | any[], options?: Partial<Options>, _stack?: Record<string, any>[]): Difference[];
|
||||
export {};
|
||||
56
node_modules/microdiff/dist/index.js
generated
vendored
Normal file
56
node_modules/microdiff/dist/index.js
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
const richTypes = { Date: true, RegExp: true, String: true, Number: true };
|
||||
export default function diff(obj, newObj, options = { cyclesFix: true }, _stack = []) {
|
||||
let diffs = [];
|
||||
const isObjArray = Array.isArray(obj);
|
||||
for (const key in obj) {
|
||||
const objKey = obj[key];
|
||||
const path = isObjArray ? +key : key;
|
||||
if (!(key in newObj)) {
|
||||
diffs.push({
|
||||
type: "REMOVE",
|
||||
path: [path],
|
||||
oldValue: obj[key],
|
||||
});
|
||||
continue;
|
||||
}
|
||||
const newObjKey = newObj[key];
|
||||
const areCompatibleObjects = typeof objKey === "object" &&
|
||||
typeof newObjKey === "object" &&
|
||||
Array.isArray(objKey) === Array.isArray(newObjKey);
|
||||
if (objKey &&
|
||||
newObjKey &&
|
||||
areCompatibleObjects &&
|
||||
!richTypes[Object.getPrototypeOf(objKey)?.constructor?.name] &&
|
||||
(!options.cyclesFix || !_stack.includes(objKey))) {
|
||||
diffs.push.apply(diffs, diff(objKey, newObjKey, options, options.cyclesFix ? _stack.concat([objKey]) : []).map((difference) => {
|
||||
difference.path.unshift(path);
|
||||
return difference;
|
||||
}));
|
||||
}
|
||||
else if (objKey !== newObjKey &&
|
||||
// treat NaN values as equivalent
|
||||
!(Number.isNaN(objKey) && Number.isNaN(newObjKey)) &&
|
||||
!(areCompatibleObjects &&
|
||||
(isNaN(objKey)
|
||||
? objKey + "" === newObjKey + ""
|
||||
: +objKey === +newObjKey))) {
|
||||
diffs.push({
|
||||
path: [path],
|
||||
type: "CHANGE",
|
||||
value: newObjKey,
|
||||
oldValue: objKey,
|
||||
});
|
||||
}
|
||||
}
|
||||
const isNewObjArray = Array.isArray(newObj);
|
||||
for (const key in newObj) {
|
||||
if (!(key in obj)) {
|
||||
diffs.push({
|
||||
type: "CREATE",
|
||||
path: [isNewObjArray ? +key : key],
|
||||
value: newObj[key],
|
||||
});
|
||||
}
|
||||
}
|
||||
return diffs;
|
||||
}
|
||||
42
node_modules/microdiff/package.json
generated
vendored
Normal file
42
node_modules/microdiff/package.json
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"name": "microdiff",
|
||||
"version": "1.5.0",
|
||||
"description": "Small, fast, zero dependency deep object and array comparison",
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.js",
|
||||
"exports": {
|
||||
"import": "./dist/index.js",
|
||||
"require": "./dist/index.cjs"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc --module CommonJS && mv \"dist/index.js\" \"dist/index.cjs\" && mv \"dist/index.d.ts\" \"dist/index.d.cts\" && tsc --module es2020 && prettier -w dist/*",
|
||||
"test": "npm run build && node --test ./tests/*",
|
||||
"bench": "npm run build && node --expose-gc bench.js",
|
||||
"prepublish": "npm run build"
|
||||
},
|
||||
"keywords": [
|
||||
"diff",
|
||||
"comparison"
|
||||
],
|
||||
"author": "AsyncBanana",
|
||||
"license": "MIT",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"devDependencies": {
|
||||
"deep-diff": "^1.0.2",
|
||||
"deep-object-diff": "^1.1.9",
|
||||
"diff": "^7.0.0",
|
||||
"mitata": "^1.0.19",
|
||||
"picocolors": "^1.1.1",
|
||||
"prettier": "^3.4.1",
|
||||
"typescript": "^5.7.2"
|
||||
},
|
||||
"type": "module",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/AsyncBanana/microdiff"
|
||||
},
|
||||
"homepage": "https://github.com/AsyncBanana/microdiff#readme",
|
||||
"bugs": "https://github.com/AsyncBanana/microdiff/issues"
|
||||
}
|
||||
Reference in New Issue
Block a user