Skip to content

Releases: Zheruel/nano-string-utils

v0.7.0 - Branded Types for TypeScript

06 Sep 16:57
e4fc662

Choose a tag to compare

🎉 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 branded namespace export containing all branded type utilities
  • Three core branded types: Email, URL, and Slug
  • 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 type
  • isValidUrl() - Validates and narrows to URL type
  • isSlug() - Validates and narrows to Slug type

Builder Functions - Safe construction with validation:

  • toEmail() - Returns Email | null
  • toUrl() - Returns URL | null
  • toSlug() - Always returns Slug (transforms input)

Assertion Functions - Runtime assertions with type narrowing:

  • assertEmail() - Throws BrandedTypeError if invalid
  • assertUrl() - Throws BrandedTypeError if invalid
  • assertSlug() - Throws BrandedTypeError if invalid

Unsafe Variants - For trusted inputs:

  • unsafeEmail() - Direct cast without validation
  • unsafeUrl() - Direct cast without validation
  • unsafeSlug() - Direct cast without validation

Utilities:

  • ensureSlug() - Intelligently handles existing slugs or transforms new ones
  • BrandedTypeError - 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

06 Sep 16:03

Choose a tag to compare

🎉 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

05 Sep 23:07
0d2e3a1

Choose a tag to compare

🚀 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 words utility
  • 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 truncate for proper boundary detection
  • Fixed multi-character emoji padding in pad function

📦 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

04 Sep 16:17
356396b

Choose a tag to compare

🚀 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 highlight function 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

04 Sep 15:35
cf1eb2d

Choose a tag to compare

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

03 Sep 20:21

Choose a tag to compare

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

03 Sep 16:35
9d14478

Choose a tag to compare

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 awareness
  • highlight() - Highlight search terms in text with customizable wrappers

🔍 String Comparison & Fuzzy Matching

  • diff() - Compute simple string diffs showing additions/deletions
  • levenshtein() - Calculate edit distance between strings with early termination
  • levenshteinNormalized() - Normalized similarity score (0-1) for fuzzy matching
  • fuzzyMatch() - Sublime Text-style fuzzy string matching for command palettes

📝 Language Processing

  • pluralize() - Convert singular words to plural with English grammar rules
  • singularize() - 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

03 Sep 14:40
9353bbd

Choose a tag to compare

🎉 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 points
  • graphemes - Split strings into grapheme clusters (emoji-aware)
  • isASCII - Check if string contains only ASCII characters
  • toASCII - Convert strings to ASCII-safe representation with transliteration
  • normalizeWhitespace - Normalize various Unicode whitespace characters
  • removeNonPrintable - 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

02 Sep 19:14

Choose a tag to compare

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 support
  • templateSafe() - HTML-escaped version of template for safe rendering

Padding Utilities

  • pad() - Pad string on both sides to target length
  • padStart() - Pad string on the left to target length
  • padEnd() - Pad string on the right to target length

Case Conversions

  • titleCase() - Proper title capitalization with customizable exceptions
  • constantCase() - Convert to CONSTANT_CASE format
  • dotCase() - Convert to dot.case format
  • pathCase() - Convert to path/case format
  • sentenceCase() - 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

01 Sep 14:11
f834b84

Choose a tag to compare

Initial Release 🎉

Added

  • Initial release with 15 essential string utilities
  • slugify - Convert strings to URL-safe slugs
  • truncate - Truncate strings with ellipsis
  • capitalize - Capitalize first letter
  • camelCase - Convert to camelCase
  • snakeCase - Convert to snake_case
  • kebabCase - Convert to kebab-case
  • pascalCase - Convert to PascalCase
  • stripHtml - Remove HTML tags from strings
  • escapeHtml - Escape HTML special characters
  • randomString - Generate random strings
  • hashString - Simple string hashing
  • reverse - Reverse string characters
  • isEmail - Email validation
  • isUrl - URL validation
  • wordCount - 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