nehoid
Version:
NehoID is a high-performance TypeScript library designed for generating, validating, and managing unique identifiers in enterprise-grade applications.
95 lines • 3.58 kB
TypeScript
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 and categorizes them into valid, invalid, and duplicates.
*
* @param ids - Array of ID strings to validate
* @param options - Optional validation configuration applied to all IDs
* @returns An object containing arrays of valid, invalid, and duplicate IDs
*
* @example
* ```typescript
* const ids = ['user-123', 'admin-456', 'guest-789', 'user-123'];
* const result = Validators.validateBatch(ids, { checkCollisions: true });
* // Output: {
* // valid: ['user-123', 'admin-456'],
* // invalid: ['guest-789'],
* // duplicates: ['user-123']
* // }
* ```
*/
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