UNPKG

@wesjet/function.js

Version:
19 lines (18 loc) 684 B
import * as tracing_1 from "@effect-ts/core/Tracing"; const fileName_1 = "packages/@wesjet/function.js/src/hash.ts"; /** * Copyright (c) Wesbitty, Inc. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * */ import { xxhash64 } from 'hash-wasm'; import { T, Tagged } from './effect/index.js'; export const hashObject = (obj) => { return T.tryCatchPromise(() => xxhash64(stringifyIfNeeded(obj)), (error) => new HashError({ error }), fileName_1 + ":16:27"); }; export class HashError extends Tagged('HashError') { } const stringifyIfNeeded = (_) => (typeof _ === 'string' ? _ : JSON.stringify(_));