index.d.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. interface HashOptions {
  2. /**
  3. *
  4. */
  5. excludeKeys?: ((key: string) => boolean) | undefined;
  6. /**
  7. * hash object keys, values ignored
  8. */
  9. excludeValues?: boolean | undefined;
  10. /**
  11. * ignore unknown object types
  12. */
  13. ignoreUnknown?: boolean | undefined;
  14. /**
  15. * optional function that replaces values before hashing
  16. */
  17. replacer?: ((value: any) => any) | undefined;
  18. /**
  19. * consider 'name' property of functions for hashing
  20. */
  21. respectFunctionNames?: boolean | undefined;
  22. /**
  23. * consider function properties when hashing
  24. */
  25. respectFunctionProperties?: boolean | undefined;
  26. /**
  27. * Respect special properties (prototype, letructor) when hashing to distinguish between types
  28. */
  29. respectType?: boolean | undefined;
  30. /**
  31. * Sort all arrays before hashing
  32. */
  33. unorderedArrays?: boolean | undefined;
  34. /**
  35. * Sort `Set` and `Map` instances before hashing
  36. */
  37. unorderedObjects?: boolean | undefined;
  38. /**
  39. * Sort `Set` and `Map` instances before hashing
  40. */
  41. unorderedSets?: boolean | undefined;
  42. }
  43. /**
  44. * Serialize any JS value into a stable, hashable string
  45. * @param {object} object value to hash
  46. * @param {HashOptions} options hashing options
  47. * @return {string} serialized value
  48. * @api public
  49. */
  50. declare function objectHash(object: any, options?: HashOptions): string;
  51. /**
  52. * Hash any JS value into a string
  53. * @param {object} object value to hash
  54. * @param {HashOptions} options hashing options
  55. * @return {string} hash value
  56. * @api public
  57. */
  58. declare function hash(object: any, options?: HashOptions): string;
  59. /**
  60. * JS Implementation of MurmurHash3 (r136) (as of May 20, 2011)
  61. *
  62. * @param {Uint8Array | string} key ASCII only
  63. * @param {number} seed Positive integer only
  64. * @return {number} 32-bit positive integer hash
  65. */
  66. declare function murmurHash(key: Uint8Array | string, seed?: number): number;
  67. declare function sha256(message: string): string;
  68. declare function sha256base64(message: string): string;
  69. /**
  70. * Compare two objects using reference equality and stable deep hashing.
  71. * @param {any} object1 First object
  72. * @param {any} object2 Second object
  73. * @param {HashOptions} hash options
  74. * @return {boolean} true if equal and false if not
  75. * @api public
  76. */
  77. declare function isEqual(object1: any, object2: any, hashOptions?: HashOptions): boolean;
  78. declare function diff(obj1: any, obj2: any, opts?: HashOptions): DiffEntry[];
  79. declare class DiffEntry {
  80. key: string;
  81. type: "changed" | "added" | "removed";
  82. newValue: DiffHashedObject;
  83. oldValue?: DiffHashedObject | undefined;
  84. constructor(key: string, type: "changed" | "added" | "removed", newValue: DiffHashedObject, oldValue?: DiffHashedObject | undefined);
  85. toString(): string;
  86. toJSON(): string;
  87. }
  88. declare class DiffHashedObject {
  89. key: string;
  90. value: any;
  91. hash?: string | undefined;
  92. props?: Record<string, DiffHashedObject> | undefined;
  93. constructor(key: string, value: any, hash?: string | undefined, props?: Record<string, DiffHashedObject> | undefined);
  94. toString(): string;
  95. toJSON(): string;
  96. }
  97. export { diff, hash, isEqual, murmurHash, objectHash, sha256, sha256base64 };