import { hash } from "ohash";// "g82Nh7Lh3CURFX9zCBhc5xgU0K7L0V1qkoHyRsKNqA4"console.log(hash({ foo: "bar" }));
serialize(input)
Serializes any input value into a string for hashing.
[!IMPORTANT]
serialize method uses best efforts to generate stable serialized values; however, it is not designed for security purposes. Keep in mind that there is always a chance of intentional collisions caused by user input.
import { serialize } from "ohash";// "{foo:'bar'}"console.log(serialize({ foo: "bar" }));
digest(str)
Hashes a string using the SHA-256 algorithm and encodes it in Base64URL format.
import { digest } from "ohash";// "f4OxZX_x_FO5LcGBSKHWXfwtSx-j1ncoSt3SABJtkGk"console.log(digest("Hello World!"));
isEqual(obj1, obj2)
Compare two objects using === and then fallbacks to compare based on their serialized values.
sha256 implementation originally based on brix/crypto-js.
Migration from v1
v1
v2
objectHash(value) (stable digest string like object:1:string:3:foo:...)
serialize(value) for a stable string, or hash(value) for a SHA-256 hash
hash(value)
Still hash(value) (implementation changed; output format differs)
There is no v2 helper that reproduces the exact v1 objectHash string format. Use serialize when you need a stable structural string, and hash when you need a short digest.