|
| 1 | +declare const GRANULARITY: Record<string, "basic" | "deep">; |
| 2 | +type ListDiffStatus = "added" | "equal" | "moved" | "deleted" | "updated"; |
| 3 | +type ObjectDiffStatus = "added" | "equal" | "deleted" | "updated"; |
| 4 | +type ObjectData = Record<string, any> | undefined | null; |
| 5 | +type ListData = any; |
| 6 | +type ObjectStatusTuple = readonly [ |
| 7 | + "added", |
| 8 | + "equal", |
| 9 | + "deleted", |
| 10 | + "updated" |
| 11 | +]; |
| 12 | +type ListStatusTuple = readonly [ |
| 13 | + "added", |
| 14 | + "equal", |
| 15 | + "deleted", |
| 16 | + "moved", |
| 17 | + "updated" |
| 18 | +]; |
| 19 | +type isEqualOptions = { |
| 20 | + ignoreArrayOrder?: boolean; |
| 21 | +}; |
| 22 | +type ObjectOptions = { |
| 23 | + ignoreArrayOrder?: boolean; |
| 24 | + showOnly?: { |
| 25 | + statuses: Array<ObjectStatusTuple[number]>; |
| 26 | + granularity?: (typeof GRANULARITY)[keyof typeof GRANULARITY]; |
| 27 | + }; |
| 28 | +}; |
| 29 | +type ListOptions = { |
| 30 | + showOnly?: Array<ListStatusTuple[number]>; |
| 31 | + referenceProperty?: string; |
| 32 | +}; |
| 33 | +type ListDiff = { |
| 34 | + type: "list"; |
| 35 | + status: ListDiffStatus; |
| 36 | + diff: { |
| 37 | + value: ListData; |
| 38 | + prevIndex: number | null; |
| 39 | + newIndex: number | null; |
| 40 | + indexDiff: number | null; |
| 41 | + status: ListDiffStatus; |
| 42 | + }[]; |
| 43 | +}; |
| 44 | +type SubProperties = { |
| 45 | + property: string; |
| 46 | + previousValue: any; |
| 47 | + currentValue: any; |
| 48 | + status: ObjectDiffStatus; |
| 49 | + subPropertiesDiff?: SubProperties[]; |
| 50 | +}; |
| 51 | +type ObjectDiff = { |
| 52 | + type: "object"; |
| 53 | + status: ObjectDiffStatus; |
| 54 | + diff: { |
| 55 | + property: string; |
| 56 | + previousValue: any; |
| 57 | + currentValue: any; |
| 58 | + status: ObjectDiffStatus; |
| 59 | + subPropertiesDiff?: SubProperties[]; |
| 60 | + }[]; |
| 61 | +}; |
| 62 | + |
| 63 | +/** |
| 64 | + * Returns the diff between two objects |
| 65 | + * @param {Record<string, any>} prevData - The original object. |
| 66 | + * @param {Record<string, any>} nextData - The new object. |
| 67 | + * @returns ObjectDiff |
| 68 | + */ |
| 69 | +declare function getObjectDiff(prevData: ObjectData, nextData: ObjectData, options?: ObjectOptions): ObjectDiff; |
| 70 | + |
| 71 | +/** |
| 72 | + * Returns the diff between two arrays |
| 73 | + * @param {Array<T>} prevList - The original array. |
| 74 | + * @param {Array<T>} nextList - The new array. |
| 75 | + * @returns ListDiff |
| 76 | + */ |
| 77 | +declare const getListDiff: <T>(prevList: T[] | null | undefined, nextList: T[] | null | undefined, options?: ListOptions) => ListDiff; |
| 78 | + |
| 79 | +/** |
| 80 | + * Returns true if two data are equal |
| 81 | + * @param {any} a - The original data. |
| 82 | + * @param {any} b- The data to compare. |
| 83 | + * @returns boolean |
| 84 | + */ |
| 85 | +declare function isEqual(a: any, b: any, options?: isEqualOptions): boolean; |
| 86 | +/** |
| 87 | + * Returns true if the provided value is an object |
| 88 | + * @param {any} value - The data to check. |
| 89 | + * @returns value is Record<string, any> |
| 90 | + */ |
| 91 | +declare function isObject(value: any): value is Record<string, any>; |
| 92 | + |
| 93 | +export { getListDiff, getObjectDiff, isEqual, isObject }; |
0 commit comments