anitimejs
Version:
Thư viện xử lý chuỗi số và thời gian trong JavaScript/Typescript
93 lines (92 loc) • 3.02 kB
TypeScript
/**
* Các loại validation có thể thực hiện
*/
export type ValidationType = "email" | "password" | "phone" | "url";
/**
* Các loại masking có thể thực hiện
*/
export type MaskingType = "email" | "phone" | "card";
/**
* Các loại xử lý chuỗi
*/
export type StringProcessingType = "stripHtml" | "extractUrls" | "parseUrl";
/**
* Các loại mã hóa
*/
export type CryptoType = "hash" | "encrypt" | "decrypt";
/**
* Tùy chọn cho validation mật khẩu
*/
export interface PasswordOptions {
minLength: number;
requireUppercase: boolean;
requireLowercase: boolean;
requireNumbers: boolean;
requireSpecial: boolean;
}
/**
* Kết quả phân tích URL
*/
export interface ParsedUrl {
protocol: string;
host: string;
hostname: string;
port: string;
pathname: string;
search: string;
hash: string;
params: Record<string, string>;
}
/**
* Class chính xử lý các hàm regex và mã hóa
*/
export declare class RegexHelperClass {
/**
* Thực hiện validation theo loại
* @param type Loại validation
* @param value Giá trị cần kiểm tra
* @param options Tùy chọn (cho password)
* @returns true nếu hợp lệ, false nếu không
*/
validate(type: ValidationType, value: string, options?: Partial<PasswordOptions> | string): boolean;
/**
* Thực hiện ẩn thông tin theo loại
* @param type Loại ẩn thông tin
* @param value Giá trị cần ẩn
* @param options Tùy chọn bổ sung
* @returns Chuỗi đã được ẩn thông tin
*/
mask(type: MaskingType, value: string, options?: number): string;
/**
* Xử lý chuỗi theo loại
* @param type Loại xử lý
* @param value Chuỗi cần xử lý
* @returns Kết quả xử lý
*/
process(type: StringProcessingType, value: string): string | string[] | ParsedUrl;
/**
* Thực hiện mã hóa/băm theo loại
* @param type Loại mã hóa
* @param value Chuỗi cần mã hóa
* @param key Khóa mã hóa (cho encrypt/decrypt)
* @returns Kết quả mã hóa
*/
crypto(type: CryptoType, value: string, key?: string): string;
/**
* Các hàm private bên dưới
*/
validateEmail(email: string): boolean;
validatePassword(password: string, options: PasswordOptions): boolean;
validatePhone(phone: string, country?: "VN" | "US" | "INT"): boolean;
validateUrl(url: string): boolean;
stripHtml(html: string): string;
extractUrls(text: string): string[];
parseUrl(url: string): ParsedUrl;
maskEmail(email: string): string;
maskPhone(phone: string, visibleDigits?: number): string;
maskCard(cardNumber: string, visibleDigits?: number): string;
simpleHash(input: string): string;
simpleEncrypt(input: string, key: string): string;
simpleDecrypt(encrypted: string, key: string): string;
}
export declare const RegexHelper: RegexHelperClass;