UNPKG

@speedup/string-to

Version:

Convert all the string variables into their actual data type using different parsers

68 lines (67 loc) 1.81 kB
/** * Parser type */ export declare type ValidateSync = (val?: string, options?: any) => boolean; export declare type Validate = (val?: string, options?: any) => Promise<boolean>; export declare type ParseSync<T> = (val?: string, options?: any) => T; export declare type Parse<T> = (val?: string, options?: any) => Promise<T>; export declare type validateAndParseSync<T> = (val?: string, defaultValue?: T | undefined, options?: { validatorOptions?: any; parserOptions?: any; }) => T | undefined; export declare type validateAndParse<T> = (val?: string, defaultValue?: T | undefined, options?: { validatorOptions?: any; parserOptions?: any; }) => Promise<T | undefined>; export declare type ParserF<T> = { /** * Ensure that the value is parsable (Sync mode) */ validateSync: ValidateSync; /** * Ensure that the value is parsable */ validate: Validate; /** * Parse a property into type T (Sync mode) */ parseSync: ParseSync<T>; /** * Parse a property into type T */ parse: Parse<T>; /** * Validate and parse */ validateAndParseSync: validateAndParseSync<T>; /** * Validate and parse */ validateAndParse: validateAndParse<T>; }; export interface Parser<T> { /** * Ensure that the value is parsable (Sync mode) */ validateSync: ValidateSync; /** * Ensure that the value is parsable */ validate: Validate; /** * Parse a property into type T (Sync mode) */ parseSync: ParseSync<T>; /** * Parse a property into type T */ parse: Parse<T>; /** * Validate and parse */ validateAndParseSync: validateAndParseSync<T>; /** * Validate and parse */ validateAndParse: validateAndParse<T>; }