Skip to content

Commit 42f8116

Browse files
committed
stable-hash
1 parent 71f0096 commit 42f8116

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/io.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { juxt, pairRight, stack } from "./juxt.ts";
2-
import { prop, spread } from "./operator.ts";
3-
1+
import crypto from "node:crypto";
2+
import stableHash from "npm:stable-hash";
43
import { pipe } from "./composition.ts";
4+
import { juxt, pairRight, stack } from "./juxt.ts";
55
import { map } from "./map.ts";
66
import { applySpec } from "./mapping.ts";
7+
import { prop, spread } from "./operator.ts";
78
import { sleep } from "./time.ts";
89
import { AsyncFunction, ElementOf } from "./typing.ts";
910

@@ -173,3 +174,10 @@ export const retry = <F extends AsyncFunction>(
173174
times: number,
174175
f: F,
175176
) => conditionalRetry(() => true)(waitMs, times, f);
177+
178+
export const hash = <T>(x: T, maxLength: number) =>
179+
// @ts-expect-error not sure why
180+
crypto.createHash("MD5").update(stableHash(x)).digest("hex").substring(
181+
0,
182+
maxLength,
183+
);

0 commit comments

Comments
 (0)