1 export default class Utils
{
3 public static isUndefined(value
: unknown
): boolean {
4 return typeof value
=== 'undefined';
7 public static ifUndefined
<T
>(value
: T
| undefined, isValue
: T
): T
{
8 if (Utils
.isUndefined(value
) === true) return isValue
;
12 public static isIterable
<T
>(obj
: T
): boolean {
13 if (obj
=== null || obj
=== undefined) {
16 return typeof (obj
as any)[Symbol
.iterator
] === 'function';
19 // public static ifNotIterableDo<T>(obj: T, cb: () => void): void {
20 // if (this.isIterable(obj) === false) cb();
23 public static async promiseWithTimeout
<T
>(
27 timeoutCallback
: () => void = () => {
28 /* This is intentional */
31 // Create a timeout promise that rejects in timeout milliseconds
32 const timeoutPromise
= new Promise
<never>((_
, reject
) => {
39 // Returns a race between timeout promise and the passed promise
40 return Promise
.race
<T
>([promise
, timeoutPromise
]);
44 // public static compose<T>(...fns: ((arg: T) => T)[]): (x: T) => T {
45 // return (x: T) => fns.reduceRight((y, fn) => fn(y), x);