return value
}
if (isString(value) || typeof value === 'number') {
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const valueToDate = new Date(value)
if (isNaN(valueToDate.getTime())) {
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
throw new Error(`Cannot convert to date: '${value}'`)
}
return valueToDate
export const getRandomInteger = (max = Constants.MAX_RANDOM_INTEGER, min = 0): number => {
max = Math.floor(max)
- if (min != null && min !== 0) {
+ if (min !== 0) {
min = Math.ceil(min)
return Math.floor(randomInt(min, max + 1))
}
}
export const getRandomFloatRounded = (max = Number.MAX_VALUE, min = 0, scale = 2): number => {
- if (min != null && min !== 0) {
+ if (min !== 0) {
return roundTo(getRandomFloat(max, min), scale)
}
return roundTo(getRandomFloat(max), scale)
}
export const isObject = (item: unknown): boolean => {
- return !isNullOrUndefined(item) && typeof item === 'object' && !Array.isArray(item)
+ return item != null && typeof item === 'object' && !Array.isArray(item)
}
type CloneableData =
}
export const isCFEnvironment = (): boolean => {
- return !isNullOrUndefined(env.VCAP_APPLICATION)
+ return env.VCAP_APPLICATION != null
}
export const isIterable = <T>(obj: T): boolean => {
- return !isNullOrUndefined(obj) ? typeof obj[Symbol.iterator as keyof T] === 'function' : false
+ return obj != null ? typeof obj[Symbol.iterator as keyof T] === 'function' : false
}
const isString = (value: unknown): boolean => {
}
export const isEmptyString = (value: unknown): boolean => {
- return isNullOrUndefined(value) || (isString(value) && (value as string).trim().length === 0)
+ return value == null || (isString(value) && (value as string).trim().length === 0)
}
export const isNotEmptyString = (value: unknown): boolean => {
return isString(value) && (value as string).trim().length > 0
}
-export const isUndefined = (value: unknown): boolean => {
- return value === undefined
-}
-
-export const isNullOrUndefined = (value: unknown): boolean => {
- return value == null
-}
-
export const isEmptyArray = (object: unknown): boolean => {
return Array.isArray(object) && object.length === 0
}
}
export const isEmptyObject = (obj: object): boolean => {
- if (obj?.constructor !== Object) {
+ if (obj.constructor !== Object) {
return false
}
// Iterates over the keys of an object, if
}
}
if (
- !isUndefined(
- WebSocketCloseEventStatusString[code as keyof typeof WebSocketCloseEventStatusString]
- )
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
+ WebSocketCloseEventStatusString[code as keyof typeof WebSocketCloseEventStatusString] != null
) {
return WebSocketCloseEventStatusString[code as keyof typeof WebSocketCloseEventStatusString]
}
): ((...args: A) => R) => {
let result: R
return (...args: A) => {
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (fn != null) {
result = fn.apply<T, A, R>(context, args)
;(fn as unknown as undefined) = (context as unknown as undefined) = undefined