Files
hub-monorepo/packages/hub-nodejs/examples/replicate-data-postgres/util.ts
Varun Srinivasan 4c38067c15 chore: switch from eslint/prettier to rome (#1074)
* chore: add rome config files

* chore: add rome into configs and ci

* chore: remove eslint annotations

* chore: update annotations for rome ignores

* chore: remove prettier
2023-07-04 19:09:15 -07:00

23 lines
1013 B
TypeScript

import { fromFarcasterTime } from "@farcaster/hub-nodejs";
export function farcasterTimeToDate(time: undefined): undefined;
export function farcasterTimeToDate(time: null): null;
export function farcasterTimeToDate(time: number): Date;
export function farcasterTimeToDate(time: number | null | undefined): Date | null | undefined;
export function farcasterTimeToDate(time: number | null | undefined): Date | null | undefined {
if (time === undefined) return undefined;
if (time === null) return null;
const result = fromFarcasterTime(time);
if (result.isErr()) throw result.error;
return new Date(result.value);
}
export function bytesToHex(bytes: undefined): undefined;
export function bytesToHex(bytes: null): null;
export function bytesToHex(bytes: Uint8Array): string;
export function bytesToHex(bytes: Uint8Array | null | undefined): string | null | undefined {
if (bytes === undefined) return undefined;
if (bytes === null) return null;
return `0x${Buffer.from(bytes).toString("hex")}`;
}