full site update
This commit is contained in:
21
node_modules/ohash/LICENSE
generated
vendored
Normal file
21
node_modules/ohash/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Pooya Parsa <pooya@pi0.io>
|
||||
|
||||
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.
|
149
node_modules/ohash/README.md
generated
vendored
Normal file
149
node_modules/ohash/README.md
generated
vendored
Normal file
@@ -0,0 +1,149 @@
|
||||
# #️ ohash
|
||||
|
||||
<!-- automd:badges bundlephobia codecov -->
|
||||
|
||||
[](https://npmjs.com/package/ohash)
|
||||
[](https://npm.chart.dev/ohash)
|
||||
[](https://bundlephobia.com/package/ohash)
|
||||
[](https://codecov.io/gh/unjs/ohash)
|
||||
|
||||
<!-- /automd -->
|
||||
|
||||
Simple object hashing, serialization and comparison utils.
|
||||
|
||||
> [!NOTE]
|
||||
> You are on active v2 development branch. Check [v1](https://github.com/unjs/ohash/tree/v1) for old ohash v1 docs and [release notes](https://github.com/unjs/ohash/releases/tag/v2.0.1) for migration.
|
||||
|
||||
## Usage
|
||||
|
||||
Install [`ohash`](https://www.npmjs.com/package/ohash):
|
||||
|
||||
```sh
|
||||
# ✨ Auto-detect (npm, yarn, pnpm, bun or deno)
|
||||
npx nypm i ohash
|
||||
```
|
||||
|
||||
**Import:**
|
||||
|
||||
```js
|
||||
// ESM import
|
||||
import { hash, serialize, digest, isEqual } from "ohash";
|
||||
import { diff } from "ohash/utils";
|
||||
|
||||
// Dynamic import
|
||||
const { hash, serialize, digest, isEqual } = await import("ohash");
|
||||
const { diff } = await import("ohash/utils");
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Import from CDN</summary>
|
||||
|
||||
```js
|
||||
import { hash, serialize, digest, isEqual } from "https://esm.sh/ohash";
|
||||
import { diff } from "https://esm.sh/ohash/utils";
|
||||
|
||||
// Dynamic import
|
||||
const { hash, serialize, digest, isEqual } = await import(
|
||||
"https://esm.sh/ohash"
|
||||
);
|
||||
const { diff } = await import("https://esm.sh/ohash/utils");
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
## `hash(input)`
|
||||
|
||||
Hashes any JS value into a string.
|
||||
|
||||
The input is first [serialized](#serializeinput) then it is [hashed](#digeststr).
|
||||
|
||||
```js
|
||||
import { hash } from "ohash";
|
||||
|
||||
// "g82Nh7Lh3CURFX9zCBhc5xgU0K7L0V1qkoHyRsKNqA4"
|
||||
console.log(hash({ foo: "bar" }));
|
||||
```
|
||||
|
||||
## `serialize(input)`
|
||||
|
||||
Serializes any input value into a string for hashing.
|
||||
|
||||
> [!IMPORTANT] > `serialize` method uses best efforts to generate stable serialized values; however, it is not designed for security purposes. Keep in mind that there is always a chance of intentional collisions caused by user input.
|
||||
|
||||
```js
|
||||
import { serialize } from "ohash";
|
||||
|
||||
// "{foo:'bar'}"
|
||||
console.log(serialize({ foo: "bar" }));
|
||||
```
|
||||
|
||||
## `digest(str)`
|
||||
|
||||
Hashes a string using the [SHA-256](https://en.wikipedia.org/wiki/SHA-2) algorithm and encodes it in [Base64URL](https://base64.guru/standards/base64url) format.
|
||||
|
||||
```ts
|
||||
import { digest } from "ohash";
|
||||
|
||||
// "f4OxZX_x_FO5LcGBSKHWXfwtSx-j1ncoSt3SABJtkGk"
|
||||
console.log(digest("Hello World!"));
|
||||
```
|
||||
|
||||
## `isEqual(obj1, obj2)`
|
||||
|
||||
Compare two objects using `===` and then fallbacks to compare based on their [serialized](#serializeinput) values.
|
||||
|
||||
```js
|
||||
import { isEqual } from "ohash";
|
||||
|
||||
// true
|
||||
console.log(isEqual({ a: 1, b: 2 }, { b: 2, a: 1 }));
|
||||
```
|
||||
|
||||
## `diff(obj1, obj2)`
|
||||
|
||||
Compare two objects with nested [serialization](#serializeinput-options). Returns an array of changes.
|
||||
|
||||
The returned value is an array of diff entries with `$key`, `$hash`, `$value`, and `$props`. When logging, a string version of the changelog is displayed.
|
||||
|
||||
```js
|
||||
import { diff } from "ohash/utils";
|
||||
|
||||
const createObject = () => ({
|
||||
foo: "bar",
|
||||
nested: {
|
||||
y: 123,
|
||||
bar: {
|
||||
baz: "123",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const obj1 = createObject();
|
||||
const obj2 = createObject();
|
||||
|
||||
obj2.nested.x = 123;
|
||||
delete obj2.nested.y;
|
||||
obj2.nested.bar.baz = 123;
|
||||
|
||||
const diff = diff(obj1, obj2);
|
||||
|
||||
// [-] Removed nested.y
|
||||
// [~] Changed nested.bar.baz from "123" to 123
|
||||
// [+] Added nested.x
|
||||
console.log(diff(obj1, obj2));
|
||||
```
|
||||
|
||||
## Contribute
|
||||
|
||||
- Clone this repository
|
||||
- Enable [Corepack](https://github.com/nodejs/corepack) using `corepack enable`
|
||||
- Install dependencies using `pnpm install`
|
||||
- Run interactive tests using `pnpm dev`
|
||||
|
||||
## License
|
||||
|
||||
Made with 💛 Published under [MIT License](./LICENSE).
|
||||
|
||||
Object serialization originally based on [puleos/object-hash](https://github.com/puleos/object-hash) by [Scott Puleo](https://github.com/puleos/).
|
||||
|
||||
sha256 implementation originally based on [brix/crypto-js](https://github.com/brix/crypto-js).
|
10
node_modules/ohash/dist/crypto/js/index.d.mts
generated
vendored
Normal file
10
node_modules/ohash/dist/crypto/js/index.d.mts
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* Hashes a string using the SHA-256 algorithm and encodes it in Base64URL format.
|
||||
*
|
||||
* @param {string} message - The message to hash.
|
||||
*
|
||||
* @returns {string} The hash of the message.
|
||||
*/
|
||||
declare function digest(message: string): string;
|
||||
|
||||
export { digest };
|
3
node_modules/ohash/dist/crypto/js/index.mjs
generated
vendored
Normal file
3
node_modules/ohash/dist/crypto/js/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
const z=[1779033703,-1150833019,1013904242,-1521486534,1359893119,-1694144372,528734635,1541459225],R=[1116352408,1899447441,-1245643825,-373957723,961987163,1508970993,-1841331548,-1424204075,-670586216,310598401,607225278,1426881987,1925078388,-2132889090,-1680079193,-1046744716,-459576895,-272742522,264347078,604807628,770255983,1249150122,1555081692,1996064986,-1740746414,-1473132947,-1341970488,-1084653625,-958395405,-710438585,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,-2117940946,-1838011259,-1564481375,-1474664885,-1035236496,-949202525,-778901479,-694614492,-200395387,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,-2067236844,-1933114872,-1866530822,-1538233109,-1090935817,-965641998],S="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",r=[];class k{_data=new l;_hash=new l([...z]);_nDataBytes=0;_minBufferSize=0;finalize(e){e&&this._append(e);const s=this._nDataBytes*8,t=this._data.sigBytes*8;return this._data.words[t>>>5]|=128<<24-t%32,this._data.words[(t+64>>>9<<4)+14]=Math.floor(s/4294967296),this._data.words[(t+64>>>9<<4)+15]=s,this._data.sigBytes=this._data.words.length*4,this._process(),this._hash}_doProcessBlock(e,s){const t=this._hash.words;let i=t[0],o=t[1],a=t[2],c=t[3],h=t[4],g=t[5],f=t[6],y=t[7];for(let n=0;n<64;n++){if(n<16)r[n]=e[s+n]|0;else {const d=r[n-15],j=(d<<25|d>>>7)^(d<<14|d>>>18)^d>>>3,B=r[n-2],x=(B<<15|B>>>17)^(B<<13|B>>>19)^B>>>10;r[n]=j+r[n-7]+x+r[n-16];}const m=h&g^~h&f,p=i&o^i&a^o&a,u=(i<<30|i>>>2)^(i<<19|i>>>13)^(i<<10|i>>>22),b=(h<<26|h>>>6)^(h<<21|h>>>11)^(h<<7|h>>>25),w=y+b+m+R[n]+r[n],M=u+p;y=f,f=g,g=h,h=c+w|0,c=a,a=o,o=i,i=w+M|0;}t[0]=t[0]+i|0,t[1]=t[1]+o|0,t[2]=t[2]+a|0,t[3]=t[3]+c|0,t[4]=t[4]+h|0,t[5]=t[5]+g|0,t[6]=t[6]+f|0,t[7]=t[7]+y|0;}_append(e){typeof e=="string"&&(e=l.fromUtf8(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes;}_process(e){let s,t=this._data.sigBytes/64;e?t=Math.ceil(t):t=Math.max((t|0)-this._minBufferSize,0);const i=t*16,o=Math.min(i*4,this._data.sigBytes);if(i){for(let a=0;a<i;a+=16)this._doProcessBlock(this._data.words,a);s=this._data.words.splice(0,i),this._data.sigBytes-=o;}return new l(s,o)}}class l{words;sigBytes;constructor(e,s){e=this.words=e||[],this.sigBytes=s===void 0?e.length*4:s;}static fromUtf8(e){const s=unescape(encodeURIComponent(e)),t=s.length,i=[];for(let o=0;o<t;o++)i[o>>>2]|=(s.charCodeAt(o)&255)<<24-o%4*8;return new l(i,t)}toBase64(){const e=[];for(let s=0;s<this.sigBytes;s+=3){const t=this.words[s>>>2]>>>24-s%4*8&255,i=this.words[s+1>>>2]>>>24-(s+1)%4*8&255,o=this.words[s+2>>>2]>>>24-(s+2)%4*8&255,a=t<<16|i<<8|o;for(let c=0;c<4&&s*8+c*6<this.sigBytes*8;c++)e.push(S.charAt(a>>>6*(3-c)&63));}return e.join("")}concat(e){if(this.words[this.sigBytes>>>2]&=4294967295<<32-this.sigBytes%4*8,this.words.length=Math.ceil(this.sigBytes/4),this.sigBytes%4)for(let s=0;s<e.sigBytes;s++){const t=e.words[s>>>2]>>>24-s%4*8&255;this.words[this.sigBytes+s>>>2]|=t<<24-(this.sigBytes+s)%4*8;}else for(let s=0;s<e.sigBytes;s+=4)this.words[this.sigBytes+s>>>2]=e.words[s>>>2];this.sigBytes+=e.sigBytes;}}function digest(_){return new k().finalize(_).toBase64()}
|
||||
|
||||
export { digest };
|
10
node_modules/ohash/dist/crypto/node/index.d.mts
generated
vendored
Normal file
10
node_modules/ohash/dist/crypto/node/index.d.mts
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* Hashes a string using the SHA-256 algorithm and encodes it in Base64URL format.
|
||||
*
|
||||
* @param {string} data - data message to hash.
|
||||
*
|
||||
* @returns {string} The hash of the data.
|
||||
*/
|
||||
declare function digest(data: string): string;
|
||||
|
||||
export { digest };
|
5
node_modules/ohash/dist/crypto/node/index.mjs
generated
vendored
Normal file
5
node_modules/ohash/dist/crypto/node/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import { createHash } from 'node:crypto';
|
||||
|
||||
const e=globalThis.process?.getBuiltinModule?.("crypto")?.hash,r="sha256",s="base64url";function digest(t){if(e)return e(r,t,s);const o=createHash(r).update(t);return globalThis.process?.versions?.webcontainer?o.digest().toString(s):o.digest(s)}
|
||||
|
||||
export { digest };
|
26
node_modules/ohash/dist/index.d.mts
generated
vendored
Normal file
26
node_modules/ohash/dist/index.d.mts
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
export { digest } from 'ohash/crypto';
|
||||
export { i as isEqual } from './shared/ohash.CMR0vuBX.mjs';
|
||||
|
||||
/**
|
||||
* Serializes any input value into a string for hashing.
|
||||
*
|
||||
* This method uses best efforts to generate stable serialized values.
|
||||
* However, it is not designed for security purposes.
|
||||
* Keep in mind that there is always a chance of intentional collisions caused by user input.
|
||||
*
|
||||
* @param input any value to serialize
|
||||
* @return {string} serialized string value
|
||||
*/
|
||||
declare function serialize(input: any): string;
|
||||
|
||||
/**
|
||||
* Hashes any JS value into a string.
|
||||
*
|
||||
* The input is first serialized and then hashed.
|
||||
*
|
||||
* @param input any value to serialize
|
||||
* @return {string} hash value
|
||||
*/
|
||||
declare function hash(input: any): string;
|
||||
|
||||
export { hash, serialize };
|
10
node_modules/ohash/dist/index.mjs
generated
vendored
Normal file
10
node_modules/ohash/dist/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import { s as serialize } from './shared/ohash.D__AXeF1.mjs';
|
||||
export { i as isEqual } from './shared/ohash.D__AXeF1.mjs';
|
||||
import { digest } from 'ohash/crypto';
|
||||
export { digest } from 'ohash/crypto';
|
||||
|
||||
function hash(input) {
|
||||
return digest(serialize(input));
|
||||
}
|
||||
|
||||
export { hash, serialize };
|
9
node_modules/ohash/dist/shared/ohash.CMR0vuBX.d.mts
generated
vendored
Normal file
9
node_modules/ohash/dist/shared/ohash.CMR0vuBX.d.mts
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* Compare two objects using reference equality and stable deep hashing.
|
||||
* @param {any} object1 First object
|
||||
* @param {any} object2 Second object
|
||||
* @return {boolean} true if equal and false if not
|
||||
*/
|
||||
declare function isEqual(object1: any, object2: any): boolean;
|
||||
|
||||
export { isEqual as i };
|
9
node_modules/ohash/dist/shared/ohash.CMR0vuBX.d.ts
generated
vendored
Normal file
9
node_modules/ohash/dist/shared/ohash.CMR0vuBX.d.ts
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* Compare two objects using reference equality and stable deep hashing.
|
||||
* @param {any} object1 First object
|
||||
* @param {any} object2 Second object
|
||||
* @return {boolean} true if equal and false if not
|
||||
*/
|
||||
declare function isEqual(object1: any, object2: any): boolean;
|
||||
|
||||
export { isEqual as i };
|
13
node_modules/ohash/dist/shared/ohash.D__AXeF1.mjs
generated
vendored
Normal file
13
node_modules/ohash/dist/shared/ohash.D__AXeF1.mjs
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
function serialize(o){return typeof o=="string"?`'${o}'`:new c().serialize(o)}const c=/*@__PURE__*/function(){class o{#t=new Map;compare(t,r){const e=typeof t,n=typeof r;return e==="string"&&n==="string"?t.localeCompare(r):e==="number"&&n==="number"?t-r:String.prototype.localeCompare.call(this.serialize(t,true),this.serialize(r,true))}serialize(t,r){if(t===null)return "null";switch(typeof t){case "string":return r?t:`'${t}'`;case "bigint":return `${t}n`;case "object":return this.$object(t);case "function":return this.$function(t)}return String(t)}serializeObject(t){const r=Object.prototype.toString.call(t);if(r!=="[object Object]")return this.serializeBuiltInType(r.length<10?`unknown:${r}`:r.slice(8,-1),t);const e=t.constructor,n=e===Object||e===void 0?"":e.name;if(n!==""&&globalThis[n]===e)return this.serializeBuiltInType(n,t);if(typeof t.toJSON=="function"){const i=t.toJSON();return n+(i!==null&&typeof i=="object"?this.$object(i):`(${this.serialize(i)})`)}return this.serializeObjectEntries(n,Object.entries(t))}serializeBuiltInType(t,r){const e=this["$"+t];if(e)return e.call(this,r);if(typeof r?.entries=="function")return this.serializeObjectEntries(t,r.entries());throw new Error(`Cannot serialize ${t}`)}serializeObjectEntries(t,r){const e=Array.from(r).sort((i,a)=>this.compare(i[0],a[0]));let n=`${t}{`;for(let i=0;i<e.length;i++){const[a,l]=e[i];n+=`${this.serialize(a,true)}:${this.serialize(l)}`,i<e.length-1&&(n+=",");}return n+"}"}$object(t){let r=this.#t.get(t);return r===void 0&&(this.#t.set(t,`#${this.#t.size}`),r=this.serializeObject(t),this.#t.set(t,r)),r}$function(t){const r=Function.prototype.toString.call(t);return r.slice(-15)==="[native code] }"?`${t.name||""}()[native]`:`${t.name}(${t.length})${r.replace(/\s*\n\s*/g,"")}`}$Array(t){let r="[";for(let e=0;e<t.length;e++)r+=this.serialize(t[e]),e<t.length-1&&(r+=",");return r+"]"}$Date(t){try{return `Date(${t.toISOString()})`}catch{return "Date(null)"}}$ArrayBuffer(t){return `ArrayBuffer[${new Uint8Array(t).join(",")}]`}$Set(t){return `Set${this.$Array(Array.from(t).sort((r,e)=>this.compare(r,e)))}`}$Map(t){return this.serializeObjectEntries("Map",t.entries())}}for(const s of ["Error","RegExp","URL"])o.prototype["$"+s]=function(t){return `${s}(${t})`};for(const s of ["Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array"])o.prototype["$"+s]=function(t){return `${s}[${t.join(",")}]`};for(const s of ["BigInt64Array","BigUint64Array"])o.prototype["$"+s]=function(t){return `${s}[${t.join("n,")}${t.length>0?"n":""}]`};return o}();
|
||||
|
||||
function isEqual(object1, object2) {
|
||||
if (object1 === object2) {
|
||||
return true;
|
||||
}
|
||||
if (serialize(object1) === serialize(object2)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export { isEqual as i, serialize as s };
|
31
node_modules/ohash/dist/utils/index.d.mts
generated
vendored
Normal file
31
node_modules/ohash/dist/utils/index.d.mts
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
export { i as isEqual } from '../shared/ohash.CMR0vuBX.mjs';
|
||||
|
||||
/**
|
||||
* Calculates the difference between two objects and returns a list of differences.
|
||||
*
|
||||
* @param {any} obj1 - The first object to compare.
|
||||
* @param {any} obj2 - The second object to compare.
|
||||
* @param {HashOptions} [opts={}] - Configuration options for hashing the objects. See {@link HashOptions}.
|
||||
* @returns {DiffEntry[]} An array with the differences between the two objects.
|
||||
*/
|
||||
declare function diff(obj1: any, obj2: any): DiffEntry[];
|
||||
declare class DiffEntry {
|
||||
key: string;
|
||||
type: "changed" | "added" | "removed";
|
||||
newValue: DiffHashedObject;
|
||||
oldValue?: DiffHashedObject | undefined;
|
||||
constructor(key: string, type: "changed" | "added" | "removed", newValue: DiffHashedObject, oldValue?: DiffHashedObject | undefined);
|
||||
toString(): string;
|
||||
toJSON(): string;
|
||||
}
|
||||
declare class DiffHashedObject {
|
||||
key: string;
|
||||
value: any;
|
||||
hash?: string | undefined;
|
||||
props?: Record<string, DiffHashedObject> | undefined;
|
||||
constructor(key: string, value: any, hash?: string | undefined, props?: Record<string, DiffHashedObject> | undefined);
|
||||
toString(): string;
|
||||
toJSON(): string;
|
||||
}
|
||||
|
||||
export { diff };
|
31
node_modules/ohash/dist/utils/index.d.ts
generated
vendored
Normal file
31
node_modules/ohash/dist/utils/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
export { i as isEqual } from '../shared/ohash.CMR0vuBX.js';
|
||||
|
||||
/**
|
||||
* Calculates the difference between two objects and returns a list of differences.
|
||||
*
|
||||
* @param {any} obj1 - The first object to compare.
|
||||
* @param {any} obj2 - The second object to compare.
|
||||
* @param {HashOptions} [opts={}] - Configuration options for hashing the objects. See {@link HashOptions}.
|
||||
* @returns {DiffEntry[]} An array with the differences between the two objects.
|
||||
*/
|
||||
declare function diff(obj1: any, obj2: any): DiffEntry[];
|
||||
declare class DiffEntry {
|
||||
key: string;
|
||||
type: "changed" | "added" | "removed";
|
||||
newValue: DiffHashedObject;
|
||||
oldValue?: DiffHashedObject | undefined;
|
||||
constructor(key: string, type: "changed" | "added" | "removed", newValue: DiffHashedObject, oldValue?: DiffHashedObject | undefined);
|
||||
toString(): string;
|
||||
toJSON(): string;
|
||||
}
|
||||
declare class DiffHashedObject {
|
||||
key: string;
|
||||
value: any;
|
||||
hash?: string | undefined;
|
||||
props?: Record<string, DiffHashedObject> | undefined;
|
||||
constructor(key: string, value: any, hash?: string | undefined, props?: Record<string, DiffHashedObject> | undefined);
|
||||
toString(): string;
|
||||
toJSON(): string;
|
||||
}
|
||||
|
||||
export { diff };
|
92
node_modules/ohash/dist/utils/index.mjs
generated
vendored
Normal file
92
node_modules/ohash/dist/utils/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
import { s as serialize } from '../shared/ohash.D__AXeF1.mjs';
|
||||
export { i as isEqual } from '../shared/ohash.D__AXeF1.mjs';
|
||||
|
||||
function diff(obj1, obj2) {
|
||||
const h1 = _toHashedObject(obj1);
|
||||
const h2 = _toHashedObject(obj2);
|
||||
return _diff(h1, h2);
|
||||
}
|
||||
function _diff(h1, h2) {
|
||||
const diffs = [];
|
||||
const allProps = /* @__PURE__ */ new Set([
|
||||
...Object.keys(h1.props || {}),
|
||||
...Object.keys(h2.props || {})
|
||||
]);
|
||||
if (h1.props && h2.props) {
|
||||
for (const prop of allProps) {
|
||||
const p1 = h1.props[prop];
|
||||
const p2 = h2.props[prop];
|
||||
if (p1 && p2) {
|
||||
diffs.push(..._diff(h1.props?.[prop], h2.props?.[prop]));
|
||||
} else if (p1 || p2) {
|
||||
diffs.push(
|
||||
new DiffEntry((p2 || p1).key, p1 ? "removed" : "added", p2, p1)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (allProps.size === 0 && h1.hash !== h2.hash) {
|
||||
diffs.push(new DiffEntry((h2 || h1).key, "changed", h2, h1));
|
||||
}
|
||||
return diffs;
|
||||
}
|
||||
function _toHashedObject(obj, key = "") {
|
||||
if (obj && typeof obj !== "object") {
|
||||
return new DiffHashedObject(key, obj, serialize(obj));
|
||||
}
|
||||
const props = {};
|
||||
const hashes = [];
|
||||
for (const _key in obj) {
|
||||
props[_key] = _toHashedObject(obj[_key], key ? `${key}.${_key}` : _key);
|
||||
hashes.push(props[_key].hash);
|
||||
}
|
||||
return new DiffHashedObject(key, obj, `{${hashes.join(":")}}`, props);
|
||||
}
|
||||
class DiffEntry {
|
||||
constructor(key, type, newValue, oldValue) {
|
||||
this.key = key;
|
||||
this.type = type;
|
||||
this.newValue = newValue;
|
||||
this.oldValue = oldValue;
|
||||
}
|
||||
toString() {
|
||||
return this.toJSON();
|
||||
}
|
||||
toJSON() {
|
||||
switch (this.type) {
|
||||
case "added": {
|
||||
return `Added \`${this.key}\``;
|
||||
}
|
||||
case "removed": {
|
||||
return `Removed \`${this.key}\``;
|
||||
}
|
||||
case "changed": {
|
||||
return `Changed \`${this.key}\` from \`${this.oldValue?.toString() || "-"}\` to \`${this.newValue.toString()}\``;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
class DiffHashedObject {
|
||||
constructor(key, value, hash, props) {
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
this.hash = hash;
|
||||
this.props = props;
|
||||
}
|
||||
toString() {
|
||||
if (this.props) {
|
||||
return `{${Object.keys(this.props).join(",")}}`;
|
||||
} else {
|
||||
return JSON.stringify(this.value);
|
||||
}
|
||||
}
|
||||
toJSON() {
|
||||
const k = this.key || ".";
|
||||
if (this.props) {
|
||||
return `${k}({${Object.keys(this.props).join(",")}})`;
|
||||
}
|
||||
return `${k}(${this.value})`;
|
||||
}
|
||||
}
|
||||
|
||||
export { diff };
|
57
node_modules/ohash/package.json
generated
vendored
Normal file
57
node_modules/ohash/package.json
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
{
|
||||
"name": "ohash",
|
||||
"version": "2.0.11",
|
||||
"description": "Simple object hashing, serialization and comparison utils.",
|
||||
"repository": "unjs/ohash",
|
||||
"license": "MIT",
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/index.d.mts",
|
||||
"default": "./dist/index.mjs"
|
||||
},
|
||||
"./utils": {
|
||||
"types": "./dist/utils/index.d.mts",
|
||||
"default": "./dist/utils/index.mjs"
|
||||
},
|
||||
"./crypto": {
|
||||
"node": {
|
||||
"types": "./dist/crypto/node/index.d.mts",
|
||||
"default": "./dist/crypto/node/index.mjs"
|
||||
},
|
||||
"default": {
|
||||
"types": "./dist/crypto/js/index.d.mts",
|
||||
"default": "./dist/crypto/js/index.mjs"
|
||||
}
|
||||
}
|
||||
},
|
||||
"types": "./dist/index.d.mts",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"devDependencies": {
|
||||
"@types/node": "^22.13.5",
|
||||
"@vitest/coverage-v8": "^3.0.7",
|
||||
"automd": "^0.4.0",
|
||||
"changelogen": "^0.6.0",
|
||||
"esbuild": "^0.25.0",
|
||||
"eslint": "^9.21.0",
|
||||
"eslint-config-unjs": "^0.4.2",
|
||||
"mitata": "^1.0.34",
|
||||
"prettier": "^3.5.2",
|
||||
"typescript": "^5.7.3",
|
||||
"unbuild": "^3.5.0",
|
||||
"vitest": "^3.0.7"
|
||||
},
|
||||
"scripts": {
|
||||
"bench": "vitest bench",
|
||||
"build": "unbuild",
|
||||
"dev": "vitest dev",
|
||||
"lint": "eslint . && prettier -c src test",
|
||||
"lint:fix": "automd && eslint --fix . && prettier -w src test",
|
||||
"release": "pnpm test && changelogen --release --push && pnpm publish",
|
||||
"test": "pnpm lint && vitest run --coverage && pnpm test:types",
|
||||
"test:types": "tsc --noEmit"
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user