UNPKG

ts-nano-form

Version:

A simple and versatile way to make forms. Lightweight and dependency free.

124 lines (107 loc) 3.9 kB
export declare type CreateFormProps<T> = { name: string; initialValues?: Record<string, any>; resolver?: (values: T) => Record<string, any> | undefined; options: { formOptions: FormOptions; maskOptions: MaskOptions; moneyOptions: MoneyOptions; }; }; export declare type CreateFormRef = <T>(params: { name: string; initialValues?: Record<string, any>; resolver?: (values: T) => Record<string, any> | undefined; }) => CreateFormType<T>; export declare type CreateFormType<T> = { name: string; getIsValid: () => boolean; getValues: () => T; getErrors: () => T; subscribeAllValues: (listener: (value: any, prevValue: any) => void) => Record<string, any>; subscribeAllErrors: (listener: (value: any, prevValue: any) => void) => Record<string, any>; clearValues: () => void; reset: (values: Record<string, any>) => void; resetValues: () => void; resetErrors: () => void; field: (name: string) => Field; submit: (fetcher: (values: T) => void) => void; }; export declare const createStore: (initial?: any) => Store; export declare const DEFAULT_FORM_OPTIONS: { showLogErrors: boolean; }; export declare const DEFAULT_MASK_OPTIONS: { map: Map<string, MapOptions>; }; export declare const DEFAULT_MONEY_OPTIONS: { thousands: string; decimal: string; precision: number; allowNegative: boolean; }; export declare type Field = { getValue: () => any; getValueStore: () => Store; getMasked: (maskRule: string | string[]) => string; getUnmasked: () => string; getMoneyMasked: () => string; getMoneyUnmasked: () => string; getError: () => string; getErrorStore: () => Store; setError: (value: string) => string; setValue: (value: any) => any; setUnmasked: (value: any) => string; setMasked: (value: string, maskRule: string | string[]) => string; setMoney: (value: string) => string; setMoneyMasked: (value: string) => string; subscribeValue: (listener: (value: any, prevValue: any) => void) => () => void; subscribeError: (listener: (value: any, prevValue: any) => void) => () => void; }; export declare type FormOptions = { showLogErrors: boolean; }; export declare type MapOptions = { pattern: RegExp; transform?: (prevValue: string, newChar: string) => { prevValue: string; newChar: string; }; }; export declare type MaskOptions = { map: Map<string, MapOptions>; beforeMask?: (value: string) => string; afterMask?: (value: string) => string; }; export declare type MoneyOptions = { thousands: string; decimal: string; precision: number; prefix?: string; allowNegative?: boolean; beforeMask?: (value: string) => string; afterMask?: (value: string) => string; }; declare const NanoForm: (params?: NanoFormProps) => NanoFormType; export default NanoForm; export declare type NanoFormProps = { maskOptions?: MaskOptions; moneyOptions?: MoneyOptions; formOptions?: FormOptions; }; export declare type NanoFormType = { mask: (value: string, maskRule: string | string[], maskOptions?: MaskOptions) => string; unmask: (value: string, maskOptions?: MaskOptions) => string; maskMoney: (value: string, moneyOptions?: MoneyOptions) => string; unmaskMoney: (value: string, moneyOptions?: MoneyOptions) => string; getPlaceholder: (value: string, maskOptions?: MaskOptions) => string; createForm: CreateFormRef; getForm: (name: string) => CreateFormType<any>; }; export declare type Store = { subscribe: (listener: (value: any, prevValue: any) => void) => () => void; emit: (value: any, prevValue: any) => void; get: () => any; set: (newValue: any) => void; }; export { }