index.d.mts 964 B

1234567891011121314151617181920
  1. type PlainObject = Record<string, any>;
  2. type Data = PlainObject | ValidTypes[];
  3. type Key = string | number;
  4. type KeyType<P, D> = P | D extends any[] ? Key : keyof P | keyof D;
  5. type ValidTypes = string | boolean | number | PlainObject;
  6. type Value = ValidTypes | ValidTypes[];
  7. interface TreeChanges<K> {
  8. added: (key?: K, value?: Value) => boolean;
  9. changed: (key?: K | string, actual?: Value, previous?: Value) => boolean;
  10. changedFrom: (key: K | string, previous: Value, actual?: Value) => boolean;
  11. decreased: (key: K, actual?: Value, previous?: Value) => boolean;
  12. emptied: (key?: K) => boolean;
  13. filled: (key?: K) => boolean;
  14. increased: (key: K, actual?: Value, previous?: Value) => boolean;
  15. removed: (key?: K, value?: Value) => boolean;
  16. }
  17. declare function treeChanges<P extends Data, D extends Data, K = KeyType<P, D>>(previousData: P, data: D): TreeChanges<K>;
  18. export { Data, KeyType, TreeChanges, Value, treeChanges as default };