Releases: Zheruel/nano-string-utils
v0.7.0 - Branded Types for TypeScript
🎉 Branded Types for Compile-Time Type Safety
This release introduces branded types to nano-string-utils, providing compile-time type safety for validated strings in TypeScript applications with zero runtime overhead.
✨ What's New
Branded Types System
- New
brandednamespace export containing all branded type utilities - Three core branded types:
Email,URL, andSlug - Generic
Brand<K, T>utility for creating custom branded types
15 New Functions
Type Guards - Runtime validation with type narrowing:
isValidEmail()- Validates and narrows to Email typeisValidUrl()- Validates and narrows to URL typeisSlug()- Validates and narrows to Slug type
Builder Functions - Safe construction with validation:
toEmail()- ReturnsEmail | nulltoUrl()- ReturnsURL | nulltoSlug()- Always returnsSlug(transforms input)
Assertion Functions - Runtime assertions with type narrowing:
assertEmail()- ThrowsBrandedTypeErrorif invalidassertUrl()- ThrowsBrandedTypeErrorif invalidassertSlug()- ThrowsBrandedTypeErrorif invalid
Unsafe Variants - For trusted inputs:
unsafeEmail()- Direct cast without validationunsafeUrl()- Direct cast without validationunsafeSlug()- Direct cast without validation
Utilities:
ensureSlug()- Intelligently handles existing slugs or transforms new onesBrandedTypeError- Custom error class for validation failures
📊 Performance & Size
- Zero runtime overhead - Types are completely erased at compilation
- Tree-shakeable - Only imported when explicitly used
- Bundle size - Remains under 6.5KB limit (6.35KB CJS)
- Type guards - Identical performance to base validators
- Unsafe variants - ~18M ops/sec (simple type casts)
📖 Example Usage
```typescript
import { branded } from 'nano-string-utils';
// Type-safe email handling
const email = branded.toEmail('[email protected]');
if (email) {
sendNewsletter(email); // email is typed as Email
}
// Assertion-based validation
const input = getUserInput();
branded.assertEmail(input);
// input is now typed as Email
sendEmail(input);
// Type guards for narrowing
if (branded.isValidUrl(input)) {
// input is now typed as URL
fetch(input);
}
```
📦 Installation
```bash
npm install [email protected]
or
yarn add [email protected]
or
pnpm add [email protected]
```
🧪 Testing
- 100% test coverage including type-level tests
- 5 new test suites with 893 total passing tests
- Performance benchmarks confirming no degradation
📚 Documentation
Full documentation and examples available in the README
Full Changelog: v0.6.0...v0.7.0
v0.6.0 - TypeScript Function Overloads
🎉 TypeScript Function Overloads
This release adds comprehensive TypeScript function overload signatures to improve type inference and developer experience.
✨ What's New
TypeScript Function Overloads - Enhanced type inference for 13 functions:
- Better IDE autocomplete and parameter hints
- More precise return type inference based on arguments
- Functions with overloads:
truncate,pad,padStart,padEnd,template,templateSafe,excerpt,highlight,fuzzyMatch,memoize,randomString,toASCII,removeNonPrintable - No breaking changes - fully backward compatible
📦 Installation
npm install [email protected]📝 Full Changelog
See CHANGELOG.md for complete details.
v0.5.2 - Benchmarking System & Performance Optimizations
🚀 Release v0.5.2
✨ Added
- Comprehensive Benchmarking System
- Bundle size analysis comparing nano-string-utils, lodash, and es-toolkit
- Performance benchmarks using Vitest bench for ops/sec comparisons
- Automated benchmark runner with markdown report generation
- GitHub Actions CI integration for automated benchmarking
⚡ Performance
- Case Conversions: 30-40% improvement via unified
wordsutility - truncate: 97.6% improvement - now 2.1-2.6x faster than lodash
- template: 25x faster than lodash
- capitalize: 2.4x faster than lodash
- pad: Optimized with native String.repeat()
🐛 Fixed
- Fixed Unicode/emoji handling in
truncatefor proper boundary detection - Fixed multi-character emoji padding in
padfunction
📦 Bundle Size
- Slightly increased to 5.97KB (CJS) / 5.64KB (ESM)
- Still well under 6.5KB limit
- Wins 10 out of 11 functions vs competitors
📊 Benchmark Results
See detailed comparisons in benchmarks/benchmark-results.md
Full Changelog: v0.5.1...v0.5.2
v0.5.1 - Regex Performance Optimization
🚀 Performance Improvements
This release focuses on optimizing regex patterns across the entire codebase for significant performance improvements.
✨ What's Changed
Performance Optimizations
- Pre-compiled all static regex patterns across 21 functions for 2-3x performance improvement
- Case Conversion (8 functions):
camelCase,pascalCase,kebabCase,snakeCase,constantCase,dotCase,pathCase- pre-compiled 5-7 patterns each - HTML Processing (4 functions):
escapeHtml,stripHtml,highlight- optimized regex and lookup tables - Text Processing (6 functions):
sentenceCase(10 patterns),titleCase(4 patterns),fuzzyMatch,slugify,pluralize,deburr - Utilities (3 functions):
wordCount,isEmail,excerpt- eliminated regex recreation overhead - Combined sequential replacements in
highlightfunction for single-pass HTML escaping
📊 Results
- ✅ All 822 tests pass with 97.72% coverage
- ✅ Bundle size maintained under 6KB (5.64 kB ESM, 5.97 kB CJS)
- ✅ No breaking changes - same API preserved
📦 Installation
npm install [email protected]Full Changelog: v0.5.0...v0.5.1
v0.5.0 - Memoization Utility
What's New
Added
memoize- LRU cache wrapper for expensive string operations with configurable size and TTL- Configurable cache size (default: 100 entries)
- Optional time-to-live (TTL) for cache entries
- Support for multi-argument functions
- Automatic cache eviction using LRU strategy
Installation
npm install [email protected]Full Changelog
https://github.com/Zheruel/nano-string-utils/blob/main/CHANGELOG.md#050---2025-09-04
v0.4.1 - Performance optimizations
Performance Improvements
This release focuses on algorithmic performance optimizations across 7 string utility functions.
Optimized Functions
- hashString: Replaced with FNV-1a implementation for better distribution
- levenshtein: Added prefix/suffix trimming optimization
- deburr: Consolidated 14+ regex operations into single pattern
- fuzzyMatch: Progressive threshold checking and short-circuit evaluation
- toASCII: Replaced 155+ regex operations with single-pass Map lookup
- normalizeWhitespace: Pre-compiled patterns and single-pass regex
- removeNonPrintable: Replaced 4 regex passes with range comparisons
Impact
- Significant performance improvements for strings with many replaceable characters
- Reduced complexity from O(n*m) to O(n) in several cases
- Bundle size remains under 6KB limit (5.13 kB ESM / 5.48 kB CJS)
- All optimizations maintain backward compatibility
- Zero dependencies maintained
Full Changelog: v0.4.0...v0.4.1
Release v0.4.0 - Add 9 new string utility functions
What's New
Added 9 new powerful string utility functions while maintaining the library's zero-dependency, tree-shakeable design.
🎯 Text Processing
excerpt()- Create smart text excerpts with word boundary awarenesshighlight()- Highlight search terms in text with customizable wrappers
🔍 String Comparison & Fuzzy Matching
diff()- Compute simple string diffs showing additions/deletionslevenshtein()- Calculate edit distance between strings with early terminationlevenshteinNormalized()- Normalized similarity score (0-1) for fuzzy matchingfuzzyMatch()- Sublime Text-style fuzzy string matching for command palettes
📝 Language Processing
pluralize()- Convert singular words to plural with English grammar rulessingularize()- Convert plural words to singular with irregular forms support
📦 Bundle Size
- ESM: 4.88 KB minified + brotlied
- CJS: 5.22 KB minified + brotlied
- All functions remain individually tree-shakeable
✅ Quality
- 801 tests passing with 100% coverage
- Full TypeScript support with strict mode
- Optimized for both size and performance
📥 Installation
```bash
npm install [email protected]
```
Full Changelog: v0.3.0...v0.4.0
v0.3.0 - Advanced Unicode string utilities
🎉 New Features
This release introduces 6 new advanced string manipulation utilities focused on Unicode handling, character normalization, and ASCII conversion.
New Utilities
codePoints- Convert strings into arrays of Unicode code pointsgraphemes- Split strings into grapheme clusters (emoji-aware)isASCII- Check if string contains only ASCII characterstoASCII- Convert strings to ASCII-safe representation with transliterationnormalizeWhitespace- Normalize various Unicode whitespace charactersremoveNonPrintable- Remove control and formatting characters
Key Features
- 🌍 Full Unicode Support - Properly handles emojis, combining characters, and complex Unicode
- 🔤 Smart Transliteration - Greek and Cyrillic character conversion in toASCII
- ⚙️ Configurable Options - Fine-tune behavior for whitespace and character handling
- 📦 Ultra-lightweight - Each utility under 1KB minified
- 🎯 100% Test Coverage - Comprehensive testing including edge cases
Installation
# NPM
npm install [email protected]
# JSR
npx jsr add @zheruel/[email protected]What's Changed
- Add 6 new Unicode string manipulation utilities with comprehensive test coverage
- Enhanced Unicode handling across the library
- Support for complex emoji sequences and grapheme clusters
- Greek and Cyrillic transliteration support
Full Changelog: v0.2.0...v0.3.0
v0.2.0 - 11 New String Utilities
What's New
This release adds 11 powerful new string utilities to the library, expanding our collection from 15 to 26 functions!
✨ New Functions
Template Processing
template()- String interpolation with variables and nested object supporttemplateSafe()- HTML-escaped version of template for safe rendering
Padding Utilities
pad()- Pad string on both sides to target lengthpadStart()- Pad string on the left to target lengthpadEnd()- Pad string on the right to target length
Case Conversions
titleCase()- Proper title capitalization with customizable exceptionsconstantCase()- Convert to CONSTANT_CASE formatdotCase()- Convert to dot.case formatpathCase()- Convert to path/case formatsentenceCase()- Capitalize first letter of each sentence
Text Processing
deburr()- Remove diacritics/accents from Latin characters (é→e, ñ→n)
📦 Installation
npm install [email protected]🚀 Features
- All functions maintain < 1KB bundle size
- Full TypeScript support with comprehensive types
- Unicode-aware implementations for proper emoji handling
- 100% test coverage for all new functions
- Zero dependencies
📖 Full Changelog
See CHANGELOG.md
v0.1.0 - Initial Release
Initial Release 🎉
Added
- Initial release with 15 essential string utilities
slugify- Convert strings to URL-safe slugstruncate- Truncate strings with ellipsiscapitalize- Capitalize first lettercamelCase- Convert to camelCasesnakeCase- Convert to snake_casekebabCase- Convert to kebab-casepascalCase- Convert to PascalCasestripHtml- Remove HTML tags from stringsescapeHtml- Escape HTML special charactersrandomString- Generate random stringshashString- Simple string hashingreverse- Reverse string charactersisEmail- Email validationisUrl- URL validationwordCount- Count words in text- Full TypeScript support with type definitions
- Dual ESM/CJS builds for maximum compatibility
- Tree-shakeable exports for optimal bundle size
- Zero runtime dependencies
- Comprehensive test suite with 202 tests
- Detailed JSDoc documentation for all functions
Technical Details
- Built with TypeScript 5.9
- Supports Node.js 18+
- Bundle size < 1KB (minified + gzipped)
- 100% test coverage for utility functions
- Modern build tooling with tsup and Vitest
Installation
npm install nano-string-utils