2020-08-26 20:37:36 +02:00
|
|
|
import { isEmpty, isNil, pipe, range } from 'ramda';
|
|
|
|
import { SyntheticEvent } from 'react';
|
2020-08-22 18:32:48 +02:00
|
|
|
|
|
|
|
export const rangeOf = <T>(size: number, mappingFn: (value: number) => T, startAt = 1): T[] =>
|
|
|
|
range(startAt, size + 1).map(mappingFn);
|
|
|
|
|
|
|
|
export type Empty = null | undefined | '' | never[];
|
|
|
|
|
|
|
|
export const hasValue = <T>(value: T | Empty): value is T => !isNil(value) && !isEmpty(value);
|
2020-08-24 18:52:52 +02:00
|
|
|
|
2020-08-26 20:37:36 +02:00
|
|
|
export const handleEventPreventingDefault = <T>(handler: () => T) => pipe(
|
|
|
|
(e: SyntheticEvent) => e.preventDefault(),
|
|
|
|
handler,
|
|
|
|
);
|
|
|
|
|
2020-08-24 18:52:52 +02:00
|
|
|
export type Nullable<T> = {
|
|
|
|
[P in keyof T]: T[P] | null
|
|
|
|
};
|
2020-08-26 20:03:23 +02:00
|
|
|
|
|
|
|
type Optional<T> = T | null | undefined;
|
|
|
|
|
|
|
|
export type OptionalString = Optional<string>;
|
2020-09-09 19:16:04 +02:00
|
|
|
|
|
|
|
export type RecursivePartial<T> = {
|
|
|
|
[P in keyof T]?: RecursivePartial<T[P]>;
|
|
|
|
};
|
2021-08-21 17:53:06 +02:00
|
|
|
|
|
|
|
export const nonEmptyValueOrNull = <T>(value: T): T | null => isEmpty(value) ? null : value;
|
2021-09-25 08:20:56 +02:00
|
|
|
|
|
|
|
export const capitalize = <T extends string>(value: T): string => `${value.charAt(0).toUpperCase()}${value.slice(1)}`;
|