build(deps-dev): Bump jsdom from 23.0.1 to 23.1.0 in /ui/web
[e-mobility-charging-stations-simulator.git] / ui / web / src / composables / Utils.ts
index 8ce3b6eca5b37c27dca29faf6a970ea8a0f9a980..7f070e49a8aa7fde7f8e268f6369172494c8e13c 100644 (file)
@@ -1,47 +1,19 @@
-export default class Utils {
-  // STATE
-  public static isUndefined(value: unknown): boolean {
-    return typeof value === 'undefined';
-  }
-
-  public static ifUndefined<T>(value: T | undefined, isValue: T): T {
-    if (Utils.isUndefined(value) === true) return isValue;
-    return value as T;
-  }
-
-  public static isIterable<T>(obj: T): boolean {
-    if (obj === null || obj === undefined) {
-      return false;
-    }
-    return typeof (obj as any)[Symbol.iterator] === 'function';
-  }
-
-  // public static ifNotIterableDo<T>(obj: T, cb: () => void): void {
-  //   if (this.isIterable(obj) === false) cb();
-  // }
+export const ifUndefined = <T>(value: T | undefined, isValue: T): T => {
+  if (value === undefined) return isValue
+  return value as T
+}
 
-  public static async promiseWithTimeout<T>(
-    promise: Promise<T>,
-    timeoutMs: number,
-    timeoutError: Error,
-    timeoutCallback: () => void = () => {
-      /* This is intentional */
-    }
-  ): Promise<T> {
-    // Create a timeout promise that rejects in timeout milliseconds
-    const timeoutPromise = new Promise<never>((_, reject) => {
-      setTimeout(() => {
-        timeoutCallback();
-        reject(timeoutError);
-      }, timeoutMs);
-    });
+// const isIterable = <T>(obj: T): boolean => {
+//   if (obj == null) {
+//     return false
+//   }
+//   return typeof (obj as unknown as Iterable<T>)[Symbol.iterator] === 'function'
+// }
 
-    // Returns a race between timeout promise and the passed promise
-    return Promise.race<T>([promise, timeoutPromise]);
-  }
+// const ifNotIterableDo = <T>(obj: T, cb: () => void): void => {
+//   if (isIterable(obj) === false) cb()
+// }
 
-  // FUNCTIONAL
-  // public static compose<T>(...fns: ((arg: T) => T)[]): (x: T) => T {
-  //   return (x: T) => fns.reduceRight((y, fn) => fn(y), x);
-  // }
-}
+// export const compose = <T>(...fns: ((arg: T) => T)[]): ((x: T) => T) => {
+//   return (x: T) => fns.reduceRight((y, fn) => fn(y), x)
+// }