@hookform/resolvers
Version:
React Hook Form validation resolvers: Yup, Joi, Superstruct, Zod, Vest, Class Validator, io-ts, Nope, computed-types, TypeBox, arktype, Typanion, Effect-TS and VineJS
19 lines (16 loc) • 431 B
text/typescript
import * as Either from 'fp-ts/Either';
import { pipe } from 'fp-ts/function';
const arrayToPath = (paths: Either.Either<string, number>[]): string =>
paths.reduce(
(previous, path, index) =>
pipe(
path,
Either.fold(
(key) => `${index > 0 ? '.' : ''}${key}`,
(key) => `[${key}]`,
),
(path) => `${previous}${path}`,
),
'',
);
export default arrayToPath;