You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Input will be serialized into a string like `object:1:string:3:foo:string:3:bar,`.
68
-
- Then it is hashed using [SHA-256](https://en.wikipedia.org/wiki/SHA-2) algorithm and encoded as a [base64](https://en.wikipedia.org/wiki/Base64) string.
69
-
-`+`, `/` and `=` characters will be removed and string trimmed to `10` chars.
70
-
71
-
### `serialize(object, options?)`
53
+
- If input is not a string, it will be serialized into a string like `object:1:string:3:foo:string:3:bar,` using [`serialize()`](#serializeinput-options).
54
+
- Then it is hashed using [SHA-256](https://en.wikipedia.org/wiki/SHA-2) algorithm and encoded as a [Base64](https://en.wikipedia.org/wiki/Base64) string using [`digest()`](#digeststr).
72
55
73
-
Serializes any value into a stable and safe string for hashing.
56
+
## `serialize(input, options?)`
74
57
75
-
**Usage:**
58
+
Serializes any input value into a string for usable hashing.
76
59
77
60
```js
78
61
import { serialize } from"ohash";
@@ -81,11 +64,23 @@ import { serialize } from "ohash";
81
64
console.log(serialize({ foo:"bar" }));
82
65
```
83
66
84
-
### `isEqual(obj1, obj2, options?)`
67
+
##`digest(str)`
85
68
86
-
Compare two objects using `==` then fallbacks to compare using `serialize`.
69
+
Create a [sha256](https://en.wikipedia.org/wiki/SHA-2) digest from input (string) and returns the hash as a base64 string.
87
70
88
-
Usage:
71
+
> [!IMPORTANT]
72
+
> The `+`, `/`, and `=` characters are removed from base64 result to maximize compatibility.
73
+
74
+
```ts
75
+
import { digest } from"ohash";
76
+
77
+
// "pZGm1Av0IEBKARczz7exkNYsZb8LzaMrV7J32a2fFG4"
78
+
console.log(digest("Hello World"));
79
+
```
80
+
81
+
## `isEqual(obj1, obj2, options?)`
82
+
83
+
Compare two objects using `===` then fallbacks to compare based on their [serialized](#serializeinput-options) values.
89
84
90
85
```js
91
86
import { isEqual } from"ohash";
@@ -94,14 +89,12 @@ import { isEqual } from "ohash";
94
89
console.log(isEqual({ a:1, b:2 }, { b:2, a:1 }));
95
90
```
96
91
97
-
###`diff(obj1, obj2, options?)`
92
+
## `diff(obj1, obj2, options?)`
98
93
99
-
Compare two objects with nested hashing. Returns an array of changes.
94
+
Compare two objects with nested [serialization](#serializeinput-options). Returns an array of changes.
100
95
101
96
Returned value is an array of diff entries with `$key`, `$hash`, `$value` and `$props`. When logging, a string version of changelog is displayed.
Made with 💛 Published under [MIT License](./LICENSE).
158
136
159
-
Published under [MIT License](./LICENSE). Based on [puleos/object-hash](https://github.com/puleos/object-hash) by [Scott Puleo](https://github.com/puleos/), and [brix/crypto-js](https://github.com/brix/crypto-js).
137
+
Based on [puleos/object-hash](https://github.com/puleos/object-hash) by [Scott Puleo](https://github.com/puleos/), and [brix/crypto-js](https://github.com/brix/crypto-js).
0 commit comments