shlink-web-client/src/utils/utils.ts
2023-08-04 11:16:01 +02:00

14 lines
446 B
TypeScript

import { pipe, range } from 'ramda';
import type { SyntheticEvent } from 'react';
type Optional<T> = T | null | undefined;
export type OptionalString = Optional<string>;
export const handleEventPreventingDefault = <T>(handler: () => T) => pipe(
(e: SyntheticEvent) => e.preventDefault(),
handler,
);
export const rangeOf = <T>(size: number, mappingFn: (value: number) => T, startAt = 1): T[] =>
range(startAt, size + 1).map(mappingFn);