UNPKG

nehoid

Version:

Advanced unique ID generation utility with multi-layer encoding, collision detection, and context-aware features

105 lines 3.94 kB
import { ValidationOptions, HealthScore } from "../types/index.js"; /** * Validation utilities for NehoID identifiers. * * This module provides comprehensive validation capabilities for IDs generated by NehoID, * including format checking, collision detection, batch validation, and health scoring. * All validation methods are static and can be used independently or through the main NehoID class. */ export declare class Validators { /** * Validates a single ID against configured rules and formats. * * Performs comprehensive validation including format checking, entropy analysis, * and optional collision detection based on the provided options. * * @param id - The ID string to validate * @param options - Optional validation configuration * @returns True if the ID passes all validation checks, false otherwise * * @example * ```typescript * // Basic format validation * const isValid = Validators.validate('user-abc123def'); * * // With collision checking * const isUnique = Validators.validate('user-abc123def', { * checkCollisions: true * }); * * // Full validation with repair * const isValidAndRepaired = Validators.validate('corrupted-id', { * checkFormat: true, * repairCorrupted: true * }); * ``` */ static validate(id: string, options?: ValidationOptions): boolean; /** * Validates multiple IDs in a single batch operation. * * This method is optimized for validating large numbers of IDs efficiently. * It processes IDs in parallel when possible and returns results in the same order. * * @param ids - Array of ID strings to validate * @param options - Optional validation configuration applied to all IDs * @returns Array of boolean values corresponding to each input ID's validation result * * @example * ```typescript * const ids = ['user-123', 'admin-456', 'guest-789']; * const results = Validators.validateBatch(ids); * // Output: [true, true, false] * * // With detailed validation * const detailedResults = Validators.validateBatch(ids, { * checkFormat: true, * checkCollisions: true * }); * ``` * * @example * ```typescript * // Process validation results * const validationResults = Validators.validateBatch(userIds); * const validIds = userIds.filter((_, index) => validationResults[index]); * const invalidCount = validationResults.filter(result => !result).length; * ``` */ static validateBatch(ids: string[], options?: ValidationOptions): { valid: string[]; invalid: string[]; duplicates: string[]; }; /** * Performs a comprehensive health check on an ID. * * Analyzes the ID's entropy, predictability, and overall quality, * providing a health score and actionable recommendations for improvement. * * @param id - The ID string to analyze * @returns A health score object containing score, entropy level, predictability, and recommendations * * @example * ```typescript * const health = Validators.healthCheck('weak-id-123'); * console.log(`Score: ${health.score}`); // 0.3 * console.log(`Entropy: ${health.entropy}`); // 'low' * console.log('Recommendations:', health.recommendations); * // Output: ['Consider using a longer ID', 'Add random components'] * ``` * * @example * ```typescript * // Quality assurance for generated IDs * const newId = NehoID.generate(); * const health = Validators.healthCheck(newId); * * if (health.score < 0.7) { * console.warn('Low quality ID generated:', health.recommendations); * } * ``` */ static healthCheck(id: string): HealthScore; } //# sourceMappingURL=validation.d.ts.map