@jdlien/validator-utils
Version:
Validation and sanitization functions used by @jdlien/Validator.
72 lines (71 loc) • 3.44 kB
TypeScript
/**
* Validator Utils - Lightweight validation and parsing utilities
* Used by the @jdlien/validator package
*/
export declare function parseTime(value: string): {
hour: number;
minute: number;
second: number;
} | null;
export declare function isTime(value: string): boolean;
export declare function isMeridiem(token: string): boolean;
export declare function yearToFull(y: number | string): number;
export declare function parseDate(value: string | Date): Date;
export declare function parseDateTime(value: string | Date): Date | null;
export declare function formatDateTime(date: Date | string, format?: string): string;
export declare function momentToFPFormat(format: string): string;
export declare function isDate(value: string | Date): boolean;
export declare function isDateTime(value: string | Date): boolean;
export declare function parseDateToString(value: string | Date, format?: string): string;
export declare function parseDateTimeToString(value: string | Date, format?: string): string;
export declare function parseTimeToString(value: string, format?: string): string;
export declare function monthToNumber(str: string | number): number;
/**
* Parses a relative date offset like "-30d", "+2w", "30d", "-6m", "+1y"
* Returns a Date object relative to today, or null if invalid
*/
export declare function parseRelativeDate(offset: string): Date | null;
export declare function isDateInRange(date: Date, range: string): boolean;
export declare function isFormControl(el: any): boolean;
export declare function isType(el: HTMLInputElement | HTMLTextAreaElement, types: string | string[]): boolean;
export declare function isEmail(value: string): boolean;
export declare function parseNANPTel(value: string): string;
export declare function isNANPTel(value: string): boolean;
export declare function parseInteger(value: string): string;
export declare function isInteger(value: string): boolean;
export declare function parseNumber(value: string): string;
export declare function isNumber(value: string): boolean;
/**
* Parses a human-readable byte size string into bytes.
* Accepts: 500, 5B, 5K, 5KB, 5KiB, 5Ki, 5M, 5MB, 5MiB, etc.
* SI units (KB, MB) use powers of 1000; binary units (KiB, MiB) use powers of 1024.
* Returns NaN for invalid input.
*/
export declare function parseBytes(value: string): number;
/**
* Formats bytes as a human-readable string.
* @param bytes - The number of bytes
* @param decimal - If true (default), uses SI units (1000-based). If false, uses binary (1024-based).
* @returns Formatted string like "1.5 MB" or "512 B"
*/
export declare function formatBytes(bytes: number, decimal?: boolean): string;
export declare function parseUrl(value: string): string;
export declare function isUrl(value: string): boolean;
export declare function parseZip(value: string): string;
export declare function isZip(value: string): boolean;
export declare function parsePostalCA(value: string): string;
export declare function isPostalCA(value: string): boolean;
export declare function isColor(value: string): boolean;
export declare function parseColor(value: string): string;
interface ValidationResult {
valid: boolean;
error?: boolean;
messages: string[];
}
export declare function normalizeValidationResult(res: boolean | string | {
valid: boolean;
message?: string;
messages?: string | string[];
error?: boolean;
}): ValidationResult;
export {};