-
- // public static ifNotIterableDo<T>(obj: T, cb: () => void): void {
- // if (this.isIterable(obj) === false) cb();
- // }
-
- 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);
- });
-
- // Returns a race between timeout promise and the passed promise
- return Promise.race<T>([promise, timeoutPromise]);
+ if (typeof value === 'number') {
+ return Math.trunc(value)
+ }
+ let changedValue: number = value as number
+ if (typeof value === 'string') {
+ changedValue = parseInt(value)
+ }
+ if (isNaN(changedValue)) {
+ throw new Error(`Cannot convert to integer: '${String(value)}'`)