Download lib/filterHash.ts from abc1181/Leads: direct link, hf CLI and curl.
- Browser
- Download file 763 Bytes
-
https://huggingface.co/spaces/abc1181/Leads/resolve/main/lib/filterHash.ts
- Command line
-
hf download hf://spaces/abc1181/Leads/lib/filterHash.ts
-
curl -L -o filterHash.ts https://huggingface.co/spaces/abc1181/Leads/resolve/main/lib/filterHash.ts
763 Bytes
| import { createHash } from "node:crypto"; | |
| export interface FilterInput { | |
| locations: unknown; | |
| keywords: unknown; | |
| toggles: unknown; | |
| cap: number; | |
| } | |
| function stableStringify(v: unknown): string { | |
| if (v === null || typeof v !== "object") return JSON.stringify(v); | |
| if (Array.isArray(v)) return `[${v.map(stableStringify).join(",")}]`; | |
| const keys = Object.keys(v as Record<string, unknown>).sort(); | |
| return `{${keys.map((k) => JSON.stringify(k) + ":" + stableStringify((v as Record<string, unknown>)[k])).join(",")}}`; | |
| } | |
| export function filterHash(input: FilterInput): string { | |
| return createHash("sha1").update(stableStringify(input)).digest("hex"); | |
| } | |
| export function sha1(s: string): string { | |
| return createHash("sha1").update(s).digest("hex"); | |
| } | |