import clone from 'just-clone';
-import Constants from './Constants';
-import { WebSocketCloseEventStatusString } from '../types/WebSocket';
+// import { Constants } from './internal';
+import { Constants } from './Constants';
+import { WebSocketCloseEventStatusString } from '../types';
-export default class Utils {
+export class Utils {
private constructor() {
// This is intentional
}
return clone<T>(object);
}
+ public static hasOwnProp(object: unknown, property: PropertyKey): boolean {
+ return Utils.isObject(object) && Object.hasOwn(object as object, property);
+ }
+
+ public static isCFEnvironment(): boolean {
+ return !Utils.isNullOrUndefined(process.env.VCAP_APPLICATION);
+ }
+
public static isIterable<T>(obj: T): boolean {
return !Utils.isNullOrUndefined(obj) ? typeof obj[Symbol.iterator] === 'function' : false;
}
}
public static isEmptyArray(object: unknown | unknown[]): boolean {
- if (!Array.isArray(object)) {
- return true;
- }
- if (object.length > 0) {
- return false;
- }
- return true;
+ return Array.isArray(object) && object.length === 0;
+ }
+
+ public static isNotEmptyArray(object: unknown | unknown[]): boolean {
+ return Array.isArray(object) && object.length > 0;
}
public static isEmptyObject(obj: object): boolean {
* @param retryNumber - the number of retries that have already been attempted
* @returns delay in milliseconds
*/
- public static exponentialDelay(retryNumber = 0): number {
+ public static exponentialDelay(retryNumber = 0, maxDelayRatio = 0.2): number {
const delay = Math.pow(2, retryNumber) * 100;
- const randomSum = delay * 0.2 * Utils.secureRandom(); // 0-20% of the delay
+ const randomSum = delay * maxDelayRatio * Utils.secureRandom(); // 0-20% of the delay
return delay + randomSum;
}