Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | import type { MapArray, MapTuple } from '@https-enable/types' export interface IsStreamOptions { /** * When this option is `true`, the method returns `false` if the stream has already been closed. * @default true */ checkOpen?: boolean } export function isStream(stream: any, { checkOpen = true }: IsStreamOptions = {}) { return stream !== null && typeof stream === 'object' && !!(stream.writable || stream.readable || !checkOpen || (stream.writable === undefined && stream.readable === undefined)) && typeof stream.pipe === 'function' } export function strEnum<T extends string>(o: Array<T>): { [K in T]: K } { return o.reduce((res, key) => { res[key] = key return res }, Object.create(null)) } export function numEnum<T extends string>(arr: Array<T>): MapArray<T> export function numEnum<const T extends readonly string[]>(arr: T): MapTuple<T> export function numEnum(arr: any[]): any { return arr.reduce((acc, key, index) => { acc[key] = index return acc }, {}) } export function isNil(value?: any, emptyStringCheck = false) { const checkList = [undefined, null, ''] if (emptyStringCheck !== true) { checkList.pop() } return checkList.includes(value) } |