houser-js-utils
Version:
A comprehensive collection of TypeScript utility functions for common development tasks including array manipulation, string processing, date handling, random number generation, validation, and much more.
92 lines (91 loc) • 2.87 kB
TypeScript
/**
* @module SecurityUtils
* @description A collection of utility functions for security operations including hashing, encryption, and validation.
* @example
* ```typescript
* import { SecurityUtils } from 'houser-js-utils';
*
* // Generate secure hash
* const hash = await SecurityUtils.hashString('password123');
*
* // Generate random token
* const token = SecurityUtils.generateRandomToken(32);
*
* // Sanitize user input
* const clean = SecurityUtils.sanitizeInput('<script>alert("xss")</script>');
* ```
*/
export declare const SecurityUtils: {
/**
* Decrypts a string using AES-GCM
* @param encryptedData - Data to decrypt
* @param key - Decryption key
* @returns Decrypted data
*/
decrypt(encryptedData: string, key: string): Promise<string>;
/**
* Encrypts a string using AES-GCM
* @param data - Data to encrypt
* @param key - Encryption key
* @returns Encrypted data
*/
encrypt(data: string, key: string): Promise<string>;
/**
* Generates a CSRF token
* @returns CSRF token
*/
generateCsrfToken(): Promise<string>;
/**
* Generates a random number between min and max
* @param min - Minimum value (inclusive)
* @param max - Maximum value (inclusive)
* @returns Random number
*/
generateRandomNumber(min: number, max: number): Promise<number>;
/**
* Generates a random string of specified length
* @param length - Length of the random string
* @returns Random string
*/
generateRandomString(length: number): Promise<string>;
/**
* Generates a secure password
* @param length - Length of the password
* @returns Generated password
*/
generateSecurePassword(length?: number): Promise<string>;
/**
* Hashes a string using SHA-256
* @param input - String to hash
* @returns Hashed string
*/
hashString(input: string): Promise<string>;
/**
* Sanitizes HTML input to prevent XSS attacks
* @param input - Input string to sanitize
* @returns Sanitized string
*/
sanitizeHtml: (input: string) => string;
/**
* Validates a CSRF token
* @param token - Token to validate
* @param storedToken - Stored token to compare against
* @returns True if tokens match
*/
validateCsrfToken: (token: string, storedToken: string) => boolean;
/**
* Checks if a password meets security requirements
* @param password - Password to check
* @returns Object containing validation results
*/
validatePassword: (password: string) => {
isValid: boolean;
requirements: {
minLength: boolean;
hasUpperCase: boolean;
hasLowerCase: boolean;
hasNumbers: boolean;
hasSpecialChar: boolean;
};
};
};