import * as O from "fp-ts/lib/Option" export function renderIfNoFetchOrFetchDefined( fetch: Record | undefined, name: string, renderer: (fetch: F | undefined) => O.Option, ): O.Option { if (fetch === undefined) { return renderer(undefined) } else { const f: F | undefined = fetch[name] if (f === undefined) { return O.none } else { return renderer(f) } } } export function writeEmptyStringOrNull(s: string | null | undefined, emptyStringInsteadOfNull: boolean): string | null { if (s === null || s === undefined) { return emptyStringInsteadOfNull ? "" : null } else { return s } } export function filterDouble(value: string): number | null { if (value === "") { return null } const result = Number(value) return Number.isNaN(result) ? null : result } export function formatDateTime(date: Date): string { return date.toISOString().replace(/\.\d{3}Z$/, "+0000") } export function formatDateTimeIsoString(date: string): string { return date.replace(/\.\d{3}Z$/, "+0000") } export function formatDate(date: Date): string { return date.toISOString().replace(/T.*/, "") } export function isEmpty(obj: object) { for (const _x in obj) { return false } return true }