@hkbyte/validator
Version:
Package for JSON Schema Validations and Parsing
86 lines (85 loc) • 3.94 kB
TypeScript
import { TypeBase } from '../base';
declare type ParsedType = string | null | undefined;
export declare type MobilePhoneLocaleType = 'am-Am' | 'ar-AE' | 'ar-BH' | 'ar-DZ' | 'ar-EG' | 'ar-IQ' | 'ar-JO' | 'ar-KW' | 'ar-SA' | 'ar-SY' | 'ar-TN' | 'az-AZ' | 'bs-BA' | 'be-BY' | 'bg-BG' | 'bn-BD' | 'cs-CZ' | 'da-DK' | 'de-DE' | 'de-AT' | 'de-CH' | 'el-GR' | 'en-AU' | 'en-CA' | 'en-GB' | 'en-GG' | 'en-GH' | 'en-HK' | 'en-MO' | 'en-IE' | 'en-IN' | 'en-KE' | 'en-MT' | 'en-MU' | 'en-NG' | 'en-NZ' | 'en-PK' | 'en-PH' | 'en-RW' | 'en-SG' | 'en-SL' | 'en-UG' | 'en-US' | 'en-TZ' | 'en-ZA' | 'en-ZM' | 'en-ZW' | 'es-CL' | 'es-CO' | 'es-CR' | 'es-EC' | 'es-ES' | 'es-MX' | 'es-PA' | 'es-PY' | 'es-UY' | 'et-EE' | 'fa-IR' | 'fi-FI' | 'fj-FJ' | 'fo-FO' | 'fr-BE' | 'fr-FR' | 'fr-GF' | 'fr-GP' | 'fr-MQ' | 'fr-RE' | 'he-IL' | 'hu-HU' | 'id-ID' | 'it-IT' | 'ja-JP' | 'kk-KZ' | 'kl-GL' | 'ko-KR' | 'lt-LT' | 'ms-MY' | 'nb-NO' | 'ne-NP' | 'nl-BE' | 'nl-NL' | 'nn-NO' | 'pl-PL' | 'pt-BR' | 'pt-PT' | 'ro-RO' | 'ru-RU' | 'sl-SI' | 'sk-SK' | 'sr-RS' | 'sv-SE' | 'th-TH' | 'tr-TR' | 'uk-UA' | 'uz-UZ' | 'vi-VN' | 'zh-CN' | 'zh-HK' | 'zh-MO' | 'zh-TW';
export declare type PostalCodeLocaleType = 'AD' | 'AT' | 'AU' | 'AZ' | 'BE' | 'BG' | 'BR' | 'CA' | 'CH' | 'CZ' | 'DE' | 'DK' | 'DZ' | 'EE' | 'ES' | 'FI' | 'FR' | 'GB' | 'GR' | 'HR' | 'HU' | 'ID' | 'IE' | 'IL' | 'IN' | 'IR' | 'IS' | 'IT' | 'JP' | 'KE' | 'LI' | 'LT' | 'LU' | 'LV' | 'MT' | 'MX' | 'NL' | 'NO' | 'NP' | 'NZ' | 'PL' | 'PR' | 'PT' | 'RO' | 'RU' | 'SA' | 'SE' | 'SI' | 'TN' | 'TW' | 'UA' | 'US' | 'ZA' | 'ZM';
declare type PreValidations = {
nullable?: boolean;
trim?: 'all' | 'left' | 'right';
optional?: boolean;
nonEmpty?: boolean;
};
declare type Validations = {
email?: boolean;
alpha?: boolean;
alphaNumeric?: boolean;
numeric?: boolean;
base64?: boolean;
creditCard?: boolean;
date?: boolean;
isoDate?: boolean;
hexColor?: boolean;
ipV4?: boolean;
ipV6?: boolean;
json?: boolean;
jsonAllowPrimitives?: boolean;
jwt?: boolean;
mimeType?: boolean;
mobilePhone?: boolean;
mobilePhoneLocales?: MobilePhoneLocaleType[];
mongoObjectId?: boolean;
port?: boolean;
postalCode?: boolean;
postalCodeLocale?: PostalCodeLocaleType;
semVer?: boolean;
url?: boolean;
pattern?: RegExp;
patternName?: string;
min?: number;
max?: number;
length?: number;
case?: 'uppercase' | 'lowercase';
};
declare type PostValidations = {
returnDefaultOnNull?: boolean;
returnDefaultOnEmpty?: boolean;
format?: 'capitalize' | 'uppercase' | 'lowercase';
default?: ParsedType;
};
export declare class TypeString extends TypeBase<NonNullable<ParsedType>> {
private preValidations;
private validations;
private postValidations;
constructor();
trim(trimOption?: PreValidations['trim']): this;
nullable(returnDefaultOnNull?: boolean): this;
nonEmpty(returnDefaultOnEmpty?: boolean): this;
email(): this;
alpha(): this;
alphaNumeric(): this;
numeric(): this;
base64(): this;
creditCard(): this;
date(iso?: boolean): this;
mobilePhone(...locales: MobilePhoneLocaleType[]): this;
postalCode(locale?: PostalCodeLocaleType): this;
hexColor(): this;
ipV4(): this;
ipV6(): this;
json(): this;
jwt(): this;
mongoObjectId(): this;
mimeType(): this;
port(): this;
semVer(): this;
url(): this;
pattern(pattern: RegExp, name?: string): this;
min(minimumLength: number): this;
max(maximumLength: number): this;
length(length: number): this;
case(values: Validations['case']): this;
optional(): this;
default(defaultValue: PostValidations['default']): this;
format(formatOption: PostValidations['format']): this;
parse(payload: unknown): Promise<ParsedType>;
}
export {};