minutesToSeconds,
secondsToMilliseconds
} from 'date-fns'
+import type { CircularBuffer } from 'mnemonist'
+import { is } from 'rambda'
import {
type JsonType,
}
let changedValue: number = value as number
if (typeof value === 'string') {
- changedValue = parseInt(value)
+ changedValue = Number.parseInt(value)
}
if (isNaN(changedValue)) {
throw new Error(`Cannot convert to integer: '${String(value)}'`)
}
let changedValue: number = value as number
if (typeof value === 'string') {
- changedValue = parseFloat(value)
+ changedValue = Number.parseFloat(value)
}
if (isNaN(changedValue)) {
throw new Error(`Cannot convert to float: '${String(value)}'`)
if (max < min) {
throw new RangeError('Invalid interval')
}
- if (max - min === Infinity) {
+ if (max - min === Number.POSITIVE_INFINITY) {
throw new RangeError('Invalid interval')
}
return (randomBytes(4).readUInt32LE() / 0xffffffff) * (max - min) + min
)
}
-export const extractTimeSeriesValues = (timeSeries: TimestampedData[]): number[] => {
- return timeSeries.map(timeSeriesItem => timeSeriesItem.value)
+export const extractTimeSeriesValues = (timeSeries: CircularBuffer<TimestampedData>): number[] => {
+ return (timeSeries.toArray() as TimestampedData[]).map(timeSeriesItem => timeSeriesItem.value)
}
export const clone = <T>(object: T): T => {
* @internal
*/
export const isAsyncFunction = (fn: unknown): fn is (...args: unknown[]) => Promise<unknown> => {
- return typeof fn === 'function' && fn.constructor.name === 'AsyncFunction'
+ return is(Function, fn) && fn.constructor.name === 'AsyncFunction'
}
export const isObject = (value: unknown): value is object => {
- return value != null && typeof value === 'object' && !Array.isArray(value)
+ return value != null && !Array.isArray(value) && is(Object, value)
}
export const hasOwnProp = (value: unknown, property: PropertyKey): boolean => {
return JSON.stringify(
object,
(_, value: Record<string, unknown>) => {
- if (value instanceof Map) {
+ if (is(Map, value)) {
switch (mapFormat) {
case MapStringifyFormat.object:
- return { ...Object.fromEntries<Map<string, Record<string, unknown>>>(value.entries()) }
+ return {
+ ...Object.fromEntries<Map<string, Record<string, unknown>>>(value.entries())
+ }
case MapStringifyFormat.array:
default:
return [...value]
}
- } else if (value instanceof Set) {
+ } else if (is(Set, value)) {
return [...value] as JsonType[]
}
return value