/* eslint-disable @typescript-eslint/ban-types */ /* eslint-disable @typescript-eslint/no-explicit-any */ import * as D from "@effect-ts/core/Collections/Immutable/Dictionary" import type { Dictionary } from "@effect-ts/core/Collections/Immutable/Dictionary" export * from "./utils/extend.js" export const unsafeRight = (ei: Either) => { if (ei.isLeft()) { console.error(ei.left) throw ei.left } return ei.right } export const unsafeSome = (makeErrorMessage: () => string) => (o: Opt) => { if (o.isNone()) { throw new Error(makeErrorMessage()) } return o.value } export function toString(v: unknown) { return `${v}` } export const isTruthy = (item: T | null | undefined): item is T => Boolean(item) export const typedKeysOf = (obj: T) => Object.keys(obj) as (keyof T)[] // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion export const typedValuesOf = (obj: T) => Object.values(obj) as ValueOf[] type ValueOf = T[keyof T] export type Constructor = { new(...args: any[]): T } export type ThenArg = T extends Promise ? U : T extends (...args: any[]) => Promise ? V : T export function dropUndefined( input: Dictionary ): Dictionary { const newR = pipe( input, D.filter((x): x is A => x !== undefined) ) return newR } type GetTag = T extends { _tag: infer K } ? K : never export const isOfType = (tag: GetTag) => (e: { _tag: string }): e is T => e._tag === tag export function capitalize(string: T): Capitalize { return (string.charAt(0).toUpperCase() + string.slice(1)) as Capitalize } export function uncapitalize(string: T): Uncapitalize { return (string.charAt(0).toLowerCase() + string.slice(1)) as Uncapitalize } export function pretty(o: unknown): string { return JSON.stringify(o, undefined, 2) ?? "undefined" }