import { Maybe } from "./types.js" export const removeKeyFromObj = ( obj: {[key: string]: T}, key: string ): {[key: string]: T} => { const { [key]: omit, ...rest } = obj // eslint-disable-line return rest } export const updateOrRemoveKeyFromObj = ( obj: {[key: string]: T}, key: string, val: Maybe ): {[key: string]: T} => ( val === null ? removeKeyFromObj(obj, key) : { ...obj, [key]: val } ) export const mapObj = ( obj: {[key: string]: T}, fn: (val: T, key: string) => S ): {[key: string]: S} => { const newObj = {} as {[key: string]: S} Object.entries(obj).forEach(([key, value]) => { newObj[key] = fn(value, key) }) return newObj } export const mapObjAsync = async ( obj: {[key: string]: T}, fn: (val: T, key: string) => Promise ): Promise<{[key: string]: S}> => { const newObj = {} as {[key: string]: S} await Promise.all( Object.entries(obj).map(async ([key, value]) => { newObj[key] = await fn(value, key) }) ) return newObj } export const arrContains = (arr: T[], val: T): boolean => { return arr.indexOf(val) > -1 } export const asyncWaterfall = async (val: T, operations: ((val: T) => Promise)[]): Promise => { let acc = val for(let i=0; i