@lodestar/utils
Version:
Utilities required across multiple lodestar packages
64 lines • 1.84 kB
TypeScript
export type BufferType = Uint8Array | Uint32Array;
export type PrimitiveType = number | string | bigint | boolean | BufferType;
export type DiffableCollection = Record<string | number, PrimitiveType>;
export type Diffable = PrimitiveType | Array<PrimitiveType> | DiffableCollection;
export interface Diff {
objectPath: string;
errorMessage?: string;
val1: Diffable;
val2: Diffable;
}
export declare function diffUint8Array(val1: Uint8Array, val2: PrimitiveType, objectPath: string): Diff[];
export declare function diffUint32Array(val1: Uint32Array, val2: PrimitiveType, objectPath: string): Diff[];
export declare function getDiffs(val1: Diffable, val2: Diffable, objectPath: string): Diff[];
/**
* Find the different values on complex, nested objects. Outputs the path through the object to
* each value that does not match from val1 and val2. Optionally can output the values that differ.
*
* For objects that differ greatly, can write to a file instead of the terminal for analysis
*
* ## Example
* ```ts
* const obj1 = {
* key1: {
* key2: [
* { key3: 1 },
* { key3: new Uint8Array([1, 2, 3]) }
* ]
* },
* key4: new Uint32Array([1, 2, 3]),
* key5: 362436
* };
*
* const obj2 = {
* key1: {
* key2: [
* { key3: 1 },
* { key3: new Uint8Array([1, 2, 4]) }
* ]
* },
* key4: new Uint32Array([1, 2, 4])
* key5: true
* };
*
* diffObjects(obj1, obj2, true);
*
*
* ```
*
* ## Output
* ```sh
* val.key1.key2[1].key3
* - 0x010203
* - 0x010204
* val.key4[2]
* - 0x00000003
* - 0x00000004
* val.key5
* val1.key5 is not the same type as val2.key5
* - 362436
* - true
* ```
*/
export declare function diff(val1: unknown, val2: unknown, outputValues?: boolean, filename?: string): void;
//# sourceMappingURL=diff.d.ts.map