import { isEmpty, isNil, pipe, range } from 'ramda'; import { SyntheticEvent } from 'react'; export const rangeOf = (size: number, mappingFn: (value: number) => T, startAt = 1): T[] => range(startAt, size + 1).map(mappingFn); export type Empty = null | undefined | '' | never[]; export const hasValue = (value: T | Empty): value is T => !isNil(value) && !isEmpty(value); export const handleEventPreventingDefault = (handler: () => T) => pipe( (e: SyntheticEvent) => e.preventDefault(), handler, ); export type Nullable = { [P in keyof T]: T[P] | null }; type Optional = T | null | undefined; export type OptionalString = Optional; export type RecursivePartial = { [P in keyof T]?: RecursivePartial; }; export const nonEmptyValueOrNull = (value: T): T | null => isEmpty(value) ? null : value; export const capitalize = (value: T): string => `${value.charAt(0).toUpperCase()}${value.slice(1)}`;