export type ConstOrPromise < T > = T | Promise < T > ; export type ContextFunc < Context , ReturnType > = ( context : Context ) => ConstOrPromise < ReturnType > ; export type ContextPathFunc < Context , ReturnType > = ( context : Context , path : string ) => ConstOrPromise < ReturnType > ; export type ConstOrContextFunc < Context , ReturnType > = ReturnType | ContextFunc < Context , ReturnType > ; export type ConstOrContextPathFunc < Context , ReturnType > = ReturnType | ContextPathFunc < Context , ReturnType > ; export interface RegExpLike { readonly source : string ; readonly flags ? : string ; } export function isObject ( something ) { return typeof something === 'object' && something !== null ; } export function hasTruthyKey ( something , key ) { return isObject ( something ) && key in something && Boolean ( something [ key ] ) ; } export function isRegExpExecArray ( something ) { if ( ! Array . isArray ( something ) ) { return false ; } if ( typeof something [ 0 ] !== 'string' ) { return false ; } if ( ! ( 'index' in something && 'input' in something ) ) { return false ; } return true ; } export function filterNonNullable < T > ( ) { return ( o ) : o is NonNullable < T > => o !== null && o !== undefined ; }