UNPKG

nino-validator

Version:

A lightweight npm package for validating UK National Insurance Numbers (NINO)

187 lines (161 loc) 10.2 kB
# Changelog All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [1.0.0] - 2024-12-19 ### Added - **Core NINO Validation** - Complete implementation with full HMRC compliance - `validateNINO()` function with comprehensive rule validation - `formatNINO()` for standard UK government spacing (AB 12 34 56 C) - `parseNINO()` to extract NINO components into structured data - `generateRandomNINO()` for testing and development purposes - **Validation Features** - Full compliance with HMRC NINO rules and regulations - Invalid prefix validation (BG, GB, NK, KN, TN, NT, ZZ, etc.) - Invalid first/second letter validation (D, F, I, Q, U, V) - Invalid suffix validation (D, F, I, Q, U, V) - Repeated digit pattern validation (prevents 111111, 222222, etc.) - Comprehensive validation options: - `allowSpaces` - Allow spaces in input (default: true) - `requireSuffix` - Require suffix letter (default: false) - **Module Support & Compatibility** - **CommonJS Support** - Traditional `require()` syntax - **ESM Module Support** - Modern `import/export` syntax - **Dual Package Exports** - Seamless support for both module systems - **TypeScript Declaration Files** - Complete type definitions for enhanced IDE support - **Browser Compatibility** - Works in all modern browsers - **Cross-platform Support** - Node.js 14+ on all platforms - **Performance & Benchmarking** - **Blazing Fast Performance** - 5,000,000+ operations per second - **Comprehensive Benchmark Suite** - Detailed performance analysis and optimization - Full benchmark suite (`npm run benchmark`) with memory analysis and pattern testing - CI-friendly lightweight benchmarks (`npm run benchmark:ci`) with pass/fail gates - Memory-focused benchmarks (`npm run benchmark:memory`) with garbage collection control - **Performance Ratings System** - Automatic threshold validation (Excellent/Good/Poor) - **High-Resolution Timing** - Nanosecond precision benchmarks using `process.hrtime.bigint()` - **Memory Profiling** - Detailed usage tracking and leak detection - **Performance Insights** - Automated analysis comparing different input types - **Bulk Processing** - 3,000,000+ NINOs per second in batch operations - **Development & Testing** - **Zero Dependencies** - No external packages required - **100% Test Coverage** - Comprehensive test suite for all functionality - **ESM Test Suite** - Dedicated tests for ES Module functionality - **Jest Integration** - Professional testing setup with coverage reporting - **ESLint Configuration** - Code quality and consistency enforcement - **CI Integration** - Performance benchmark gates to prevent regressions - **Documentation & Examples** - **Comprehensive README** - Complete usage guide with examples - **JSDoc Documentation** - Detailed function documentation with examples - **API Reference** - Complete function signatures and parameters - **Real-world Examples** - Form validation, database storage, test data generation - **TypeScript Integration Guide** - Usage examples with type safety - **Browser Usage Instructions** - CDN and direct usage examples - **Performance Guidelines** - Optimization tips and benchmark interpretation - **Benchmark Documentation** - Detailed analysis and usage instructions - **Enhanced Error Messages** - Comprehensive detailed validation with `validateNINOWithDetails()` - Machine-readable error codes for programmatic handling - Human-readable error messages with specific problem identification - Helpful suggestions for fixing common validation issues - Structured ValidationResult object with isValid, error, errorCode, and suggestion fields - **Additional Validation Edge Cases** - Extended input validation and error handling - Null and undefined input handling with specific error messages - Type validation for non-string inputs (arrays, objects, booleans, numbers) - Empty string and whitespace-only input validation - Extremely long input protection (security consideration) - Special character and Unicode rejection (emojis, symbols, control characters) - Enhanced space handling with configurable allowSpaces option - Detailed length validation with character count reporting - Format-specific error detection (prefix format, number format, suffix format) - Individual letter validation with specific error codes for HMRC rules - Number pattern validation including repeated digit detection - Enhanced prefix validation with specific invalid prefix reporting - **Extended Browser Compatibility Testing** - Comprehensive cross-platform validation - Interactive browser test suite (`test/browser-compatibility.html`) - Environment detection and reporting (browser, platform, viewport) - Function availability testing across different JavaScript environments - Performance benchmarking in browser environments (10,000+ ops/sec validation) - Real-time interactive validation testing with all functions - Cross-browser compatibility verification for modern browsers - Mobile and desktop browser support validation - Error handling verification in browser contexts ### Enhanced Features - **Validation Function Architecture** - Improved code organization and maintainability - Helper functions to reduce complexity in main validation logic - Step-by-step validation process with clear error points - Consistent error handling patterns across all validation stages - Performance optimization through efficient error-first validation - Clean separation of concerns between validation logic and error reporting - **Testing Coverage** - Expanded test suite with 150+ additional test cases - Comprehensive edge case testing for all input types - Error message validation and error code verification - Unicode and special character handling tests - Performance and memory validation testing - Browser environment compatibility testing - Interactive testing capabilities for manual verification - **TypeScript Support** - Enhanced type definitions and exports - ValidationResult interface for detailed error responses - Complete function signatures with new validateNINOWithDetails - Updated module exports for both CommonJS and ESM - Enhanced JSDoc documentation with detailed examples ### Security - **Input Validation** - Comprehensive validation for all functions - **Safe Handling** - Graceful handling of null/undefined inputs - **Infinite Loop Protection** - Safeguards in random generation algorithms - **Type Safety** - Runtime validation with TypeScript support ### Performance - **Documented Performance** - Verified 700,000+ to 5,000,000+ operations per second - **Memory Efficiency** - <0.1MB memory usage for 10,000 operations - **Performance Baselines** - Established benchmarks for regression detection - **All Functions Rated "Excellent"** - Consistently >100,000 ops/sec performance - **Zero Performance Degradation** - Maintains speed with large datasets ### Technical Details - **Package Structure** - Dual exports in package.json for module compatibility - **Build System** - npm scripts for testing both CommonJS and ESM modules - **Configuration Files** - Jest, ESLint, and TypeScript configurations - **Error Code System** - Standardized machine-readable error identification - NULL_INPUT, INVALID_TYPE, EMPTY_INPUT, INPUT_TOO_LONG - SPACES_NOT_ALLOWED, INVALID_CHARACTERS, TOO_SHORT, TOO_LONG - INVALID_PREFIX_FORMAT, INVALID_NUMBER_FORMAT, MISSING_REQUIRED_SUFFIX - INVALID_SUFFIX_FORMAT, INVALID_FORMAT, INVALID_PREFIX - INVALID_FIRST_LETTER, INVALID_SECOND_LETTER, INVALID_SUFFIX - INVALID_NUMBER_PATTERN - **Browser Test Suite Features** - Real-time validation testing with immediate feedback - Performance benchmarking (typically 50,000+ ops/sec in browsers) - Random NINO generation with validation verification - Interactive input testing with all available functions - Environment detection and compatibility reporting - **File Structure**: - `index.js` - CommonJS module - `index.mjs` - ES Module version - `index.d.ts` - TypeScript declarations - `test/` - CommonJS test suite - `test-esm/` - ESM test suite - `test/browser-compatibility.html` - Browser test suite - `benchmark/` - Performance testing suite ## [Unreleased] ### Added - **Internationalization (i18n) Support** - Multi-language error messages and localization - Full support for English (`en`) and Greek (`el`) languages - `setLanguage()` function to switch between supported languages - `getCurrentLanguage()` to get current language setting - `getSupportedLanguages()` to list all available languages - `isLanguageSupported()` to check language availability - `detectLanguage()` for automatic language detection from environment - `initializeI18n()` for automatic setup with options - All error messages translated into Greek with proper parameter interpolation - Language switching maintains error codes for consistent programming interfaces - Browser and Node.js environment detection for automatic language selection - Comprehensive test coverage for both languages with 34+ i18n-specific tests - Full TypeScript declarations for all internationalization functions ### Planned - Additional validation rules based on user feedback - Performance monitoring and analytics integration --- ## Version History - **1.0.0** - Complete initial release with full HMRC compliance, dual module support, comprehensive benchmarking, and documentation ## Support For questions, bug reports, or feature requests: - 📧 Email: byron.thanopoulos@gmail.com - 🐛 Issues: [GitHub Issues](https://github.com/icodenet/nino-validator/issues) - 💬 Discussions: [GitHub Discussions](https://github.com/icodenet/nino-validator/discussions)