X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=ui%2Fweb%2Fsrc%2Fcomposables%2FUtils.ts;h=2f9c1ac5e92e669e7113813a378da986f8f11236;hb=cfab8dc9ea7801746461d4e8d6ac9852deb678b5;hp=8cb957abba2c2e10a0edfc20d7daeb29b0a0b69f;hpb=2eb6954d7bc5bb0e88a3b20aa62db7b8b08395d1;p=e-mobility-charging-stations-simulator.git diff --git a/ui/web/src/composables/Utils.ts b/ui/web/src/composables/Utils.ts index 8cb957ab..2f9c1ac5 100644 --- a/ui/web/src/composables/Utils.ts +++ b/ui/web/src/composables/Utils.ts @@ -1,56 +1,3 @@ -import util from 'node:util'; - -export default class Utils { - // STATE - public static isUndefined(value: unknown): boolean { - return typeof value === 'undefined'; - } - - public static ifUndefined(value: T | undefined, isValue: T): T { - if (Utils.isUndefined(value) === true) return isValue; - return value as T; - } - - public static isIterable(obj: T): boolean { - if (obj === null || obj === undefined) { - return false; - } - return typeof (obj as any)[Symbol.iterator] === 'function'; - } - - // public static ifNotIterableDo(obj: T, cb: () => void): void { - // if (this.isIterable(obj) === false) cb(); - // } - - public static isPromisePending(promise: Promise): boolean { - return util.inspect(promise).includes('pending'); - } - - public static async promiseWithTimeout( - promise: Promise, - timeoutMs: number, - timeoutError: Error, - timeoutCallback: () => void = () => { - /* This is intentional */ - } - ): Promise { - // Create a timeout promise that rejects in timeout milliseconds - const timeoutPromise = new Promise((_, reject) => { - setTimeout(() => { - if (Utils.isPromisePending(promise)) { - timeoutCallback(); - // FIXME: The original promise shall be canceled - } - reject(timeoutError); - }, timeoutMs); - }); - - // Returns a race between timeout promise and the passed promise - return Promise.race([promise, timeoutPromise]); - } - - // FUNCTIONAL - // public static compose(...fns: ((arg: T) => T)[]): (x: T) => T { - // return (x: T) => fns.reduceRight((y, fn) => fn(y), x); - // } -} +// export const compose = (...fns: ((arg: T) => T)[]): ((x: T) => T) => { +// return (x: T) => fns.reduceRight((y, fn) => fn(y), x) +// }