ignore license import * as lodash from 'lodash' ; import { Omit } from 'type-zoo/types' ; /**
 * _.omit with types
 */ export function omit < T extends object , K extends keyof T > ( o , keys ) { return < any > lodash . omit ( o , ... keys ) ; } /**
 * Filter non null values from a map.
 */ export function filterNonNullValues < K extends string , V > ( o ) { return lodash . reduce ( o , ( acc , value , key ) => ( notNull ( value ) ? { ... acc , [ key ] : value } : acc ) , { } as any ) ; } /** Type assert that a value is not null */ export function notNull < T > ( value ) { return value !== null && value !== undefined ; } /**
 * _.mapValues with types
 */ export function mapValuesWithStringKeys < T extends object , V > ( o , fn ) { return lodash . mapValues ( o , fn ) ; } /**
 * Like Object.keys() but with types.
 * Typescript is having a debate on this so we can just implement it ourselves:
 * https://github.com/Microsoft/TypeScript/pull/12253#issuecomment-263132208
 */ export function keys < T > ( o ) { return Object . keys ( o ) as ( keyof T ) [ ] ; } /**
 * Object.entries with types
 */ export function entries < T extends { [ k ] : any [ ] ; } > ( o ) ; export function entries < T extends { [ k ] : any ; } > ( o ) ; export function entries < T > ( o ) { return Object . entries ( o ) as any ; } /**
 * Returns true if we are in a process run under nodejs. Useful to figure out
 * if a function is being called from the backend or the frontend.
 **/ export function isRunUnderNode ( ) { return ( typeof process !== 'undefined' && ( process as any ) . release && ( process as any ) . release . name === 'node' ) ; } /**
 * Same as `sleep`, but with promises.
 */ export async function sleep ( timeInMillis ) { return new Promise < void > ( y => setTimeout ( y , timeInMillis ) ) ; } /**
 * Opposite of keyof
 */ export type ValueOf < T > = T [ keyof T ] ; /**
 * This function is used to make sure that types are exhaustive. Putting it at the end
 * of a switch statement will only throw if x has an assignable type.
 */ export function assertUnreachable ( x , shouldThrow ) { const err = new Error ( x ) ; if ( shouldThrow ) { throw err ; } return null as never ; }