UNPKG

@mdaemon/validate

Version:

A validation library used by MDaemon Remote Administration

97 lines (87 loc) 3.98 kB
export interface MDaemonValidPassword { special: boolean; lower: boolean; upper: boolean; number: boolean; length: number; min?: boolean; max?: boolean; } export interface MDaemonPasswordRequirements { upper?: boolean; lower?: boolean; number?: boolean; special?: boolean; min?: number; max?: number; } export interface ISchema { type?: 'string' | 'number' | 'boolean' | 'array' | 'object'; required?: boolean; minLength?: number; maxLength?: number; minimum?: number; maximum?: number; minItems?: number; maxItems?: number; options?: any[]; validate?: (value: any) => boolean; pattern?: string; properties?: Record<string, ISchema>; arraySchema?: ISchema; } export interface ISchemaValidationResult { valid: boolean; errors: string[]; } export function validateDomain(domain: string, useWildCards: boolean): boolean; export function validateEmailAddress(email: string, useWildCards: boolean): boolean; export function validateHeaderName(name: string): boolean; export function validateHeaderValue(value: string): boolean; export function validateHeader(header: string): boolean; export function validateIPAddress(ip: string, useWildCards: boolean): boolean; export function validateInt(value: string): boolean; export function validateWindowsFileName(str: string): boolean; export function validateWindowsPath(str: string, useWildCards: boolean): boolean; export function validateLdapDN(str: string): boolean; export function hasUpperCase(str: string): boolean; export function hasLowerCase(str: string): boolean; export function hasNumber(str: string): boolean; export function hasSpecial(str: string): boolean; export function validatePassword(str: string, bRequireSpecial: boolean, nMinLength?: number, nMaxLength?: number): MDaemonValidPassword; export function isValidPassword(str: string, bRequireSpecial: boolean, nMinLength: number, nMaxLength: number): boolean; export function setPasswordRequirements(obj: Partial<MDaemonValidPassword>): boolean; export function resetPasswordRequirements(): void; // Schema-related functions export function getSchema(name: string): ISchema | undefined; export function updateSchema(name: string, schema: ISchema): void; export function createSchemaValidator(name: string, schema: ISchema): (input: any) => ISchemaValidationResult; export interface MDaemonValidate { domain: (domain: string, useWildCards: boolean | null) => boolean; email: (email: string, useWildCards: boolean | null) => boolean; hasLowerCase: (name: string) => boolean; hasNumber: (str: string) => boolean; hasSpecial: (str: string) => boolean; hasUpperCase: (str: string) => boolean; header: (header: string) => boolean; headerName: (name: string) => boolean; headerValue: (value: string) => boolean; ldapDN: (str: string) => boolean; ip: (ip: string, useWildCards: boolean | null) => boolean; isInt: (value: string) => boolean; password: (str: string, bRequireSpecial: boolean, nMinLength?: number, nMaxLength?: number) => MDaemonValidPassword; isValidPassword: (str: string, bRequireSpecial: boolean, nMinLength: number, nMaxLength: number) => boolean; windowsFileName: (str: string) => boolean; windowsPath: (str: string, useWildCards: boolean | null) => boolean; phoneNumber: (str: string) => boolean; // Schema-related methods getSchema: (name: string) => ISchema | undefined; updateSchema: (name: string, schema: ISchema) => void; createSchemaValidator: (name: string, schema: ISchema) => (input: any) => ISchemaValidationResult; setPasswordRequirements: (obj: Partial<MDaemonPasswordRequirements>) => boolean; resetPasswordRequirements: () => void; } declare namespace validate { type ProtoType = MDaemonValidate; } export default validate;