Skip to content

Commit d4dd808

Browse files
committedFeb 19, 2025·
refactor: rename stringDigest to digest
1 parent 04fb415 commit d4dd808

File tree

6 files changed

+15
-17
lines changed

6 files changed

+15
-17
lines changed
 

‎README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ deno install ohash
4343

4444
```js
4545
// ESM import
46-
import { hash, serialize, isEqual, diff, stringDigest } from "ohash";
46+
import { hash, serialize, isEqual, diff, digest } from "ohash";
4747

4848
// ..or dnamic import
49-
const { hash, serialize, stringDigest } = await import("ohash");
49+
const { hash, serialize, digest } = await import("ohash");
5050
```
5151

5252
### `hash(object, options?)`
@@ -130,7 +130,7 @@ const diff = diff(obj1, obj2);
130130
console.log(diff(obj1, obj2));
131131
```
132132

133-
### `stringDigest`
133+
### `digest`
134134

135135
Create a [sha256](https://en.wikipedia.org/wiki/SHA-2) digest from input and returns the hash as a base64 string.
136136

@@ -139,10 +139,10 @@ Create a [sha256](https://en.wikipedia.org/wiki/SHA-2) digest from input and ret
139139
> This behavior differs from standard SHA-256 + Base64 encoding.
140140
141141
```ts
142-
import { stringDigest } from "ohash";
142+
import { digest } from "ohash";
143143

144144
// "pZGm1Av0IEBKARczz7exkNYsZb8LzaMrV7J32a2fFG4"
145-
console.log(stringDigest("Hello World"));
145+
console.log(digest("Hello World"));
146146
```
147147

148148
## 💻 Development

‎src/crypto/js/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ import { SHA256 } from "./sha256";
77
* **Note:** The `+`, `/`, and `=` characters are removed from the base64 result to maximize compatibility.
88
* This behavior differs from standard SHA-256 + Base64 encoding.
99
*/
10-
export function stringDigest(message: string) {
10+
export function digest(message: string) {
1111
return new SHA256().finalize(message).toString(Base64);
1212
}

‎src/crypto/node/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { createHash } from "node:crypto";
66
* **Note:** The `+`, `/`, and `=` characters are removed from the base64 result to maximize compatibility.
77
* This behavior differs from standard SHA-256 + Base64 encoding.
88
*/
9-
export function stringDigest(date: string): string {
9+
export function digest(date: string): string {
1010
return createHash("sha256")
1111
.update(date)
1212
.digest("base64")

‎src/hash.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { serialize, type SerializeOptions } from "./serialize";
2-
import { stringDigest } from "ohash/crypto";
2+
import { digest } from "ohash/crypto";
33

44
/**
55
* Hashes any JS value into a string.
@@ -16,5 +16,5 @@ import { stringDigest } from "ohash/crypto";
1616
export function hash(object: any, options: SerializeOptions = {}): string {
1717
const hashed =
1818
typeof object === "string" ? object : serialize(object, options);
19-
return stringDigest(hashed).slice(0, 10);
19+
return digest(hashed).slice(0, 10);
2020
}

‎src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export { serialize, type SerializeOptions } from "./serialize";
33
export { hash } from "./hash";
44

55
// Crypto
6-
export { stringDigest } from "ohash/crypto";
6+
export { digest } from "ohash/crypto";
77

88
// Utils
99
export { isEqual } from "./utils/is-equal";

‎test/crypto.test.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,14 @@ const impls = {
1111
// distJs: cryptoDistJS,
1212
};
1313

14-
describe("crypto:stringDigest", () => {
15-
for (const [name, { stringDigest }] of Object.entries(impls)) {
14+
describe("crypto:digest", () => {
15+
for (const [name, { digest }] of Object.entries(impls)) {
1616
describe(name, () => {
17-
it("stringDigest", () => {
18-
expect(stringDigest("Hello World")).toBe(
17+
it("digest", () => {
18+
expect(digest("Hello World")).toBe(
1919
"pZGm1Av0IEBKARczz7exkNYsZb8LzaMrV7J32a2fFG4",
2020
);
21-
expect(stringDigest("")).toBe(
22-
"47DEQpj8HBSaTImW5JCeuQeRkm5NMpJWZG3hSuFU",
23-
);
21+
expect(digest("")).toBe("47DEQpj8HBSaTImW5JCeuQeRkm5NMpJWZG3hSuFU");
2422
});
2523
});
2624
}

0 commit comments

Comments
 (0)
Please sign in to comment.