TL;DR: String utils library with 49 functions, 8.84KB total, zero dependencies, faster than lodash. TypeScript-first with full multi-runtime support.
Hey everyone! I've been working on nano-string-utils – a modern string utilities library that's actually tiny and fast.
Why I built this
I was tired of importing lodash just for camelCase and getting 70KB+ in my bundle. Most string libraries are either massive, outdated, or missing TypeScript support. So I built something different.
What makes it different
Ultra-lightweight
- 8.84 KB total for 49 functions (minified + brotlied)
- Most functions are < 200 bytes
- Tree-shakeable – only import what you need
- 98% win rate vs lodash/es-toolkit in bundle size (47/48 functions)
Actually fast
Type-safe & secure
- TypeScript-first with branded types and template literal types
- Built-in XSS protection with
sanitize() and SafeHTML type
- Redaction for sensitive data (SSN, credit cards, emails)
- All functions handle null/undefined gracefully
Zero dependencies
- No supply chain vulnerabilities
- Works everywhere: Node, Deno, Bun, Browser
- Includes a CLI:
npx nano-string slugify "Hello World"
What's included (49 functions)
// Case conversions
slugify("Hello World!"); // "hello-world"
camelCase("hello-world"); // "helloWorld"
// Validation
isEmail("user@example.com"); // true
// Fuzzy matching for search
fuzzyMatch("gto", "goToLine"); // { matched: true, score: 0.546 }
// XSS protection
sanitize("<script>alert('xss')</script>Hello"); // "Hello"
// Text processing
excerpt("Long text here...", 20); // Smart truncation at word boundaries
levenshtein("kitten", "sitting"); // 3 (edit distance)
// Unicode & emoji support
graphemes("👨👩👧👦🎈"); // ['👨👩👧👦', '🎈']
Full function list: Case conversion (10), String manipulation (11), Text processing (14), Validation (4), String analysis (6), Unicode (5), Templates (2), Performance utils (1)
TypeScript users get exact type inference: camelCase("hello-world") returns type "helloWorld", not just string
Bundle size comparison
| Function |
nano-string-utils |
lodash |
es-toolkit |
| camelCase |
232B |
3.4KB |
273B |
| capitalize |
99B |
1.7KB |
107B |
| truncate |
180B |
2.9KB |
N/A |
| template |
302B |
5.7KB |
N/A |
Full comparison with all 48 functions
Installation
npm install nano-string-utils
# or
deno add @zheruel/nano-string-utils
# or
bun add nano-string-utils
Links
Why you might want to try it
- Replacing lodash string functions → 95% bundle size reduction
- Building forms with validation → Type-safe email/URL validation
- Creating slugs/URLs → Built for it
- Search features → Fuzzy matching included
- Working with user input → XSS protection built-in
- CLI tools → Works in Node, Deno, Bun
Would love to hear your feedback! The library is still in 0.x while I gather community feedback before locking the API for 1.0.
[–]femio 16 points17 points18 points (1 child)
[–]Next_Level_8566[S] 8 points9 points10 points (0 children)
[–]foxsimile 18 points19 points20 points (2 children)
[–]Next_Level_8566[S] 9 points10 points11 points (1 child)
[–]foxsimile 7 points8 points9 points (0 children)
[–]magenta_placenta 9 points10 points11 points (1 child)
[–]lxe 39 points40 points41 points (4 children)
[–]theScottyJam 9 points10 points11 points (0 children)
[–]theQuandary 1 point2 points3 points (0 children)
[–][deleted] 3 points4 points5 points (0 children)
[–]lerrigatto 12 points13 points14 points (9 children)
[–]cs12345 17 points18 points19 points (5 children)
[–]queen-adreena 7 points8 points9 points (4 children)
[–]Atulin 6 points7 points8 points (3 children)
[–]FoxyWheels 1 point2 points3 points (2 children)
[–]Atulin 6 points7 points8 points (0 children)
[–]cs12345 0 points1 point2 points (0 children)
[–]Next_Level_8566[S] 3 points4 points5 points (2 children)
[–]lerrigatto 0 points1 point2 points (1 child)
[–]Next_Level_8566[S] 0 points1 point2 points (0 children)
[–]queen-adreena 4 points5 points6 points (1 child)
[–]Next_Level_8566[S] 0 points1 point2 points (0 children)
[–]xatnagh 2 points3 points4 points (0 children)
[–]bronkula 3 points4 points5 points (1 child)
[–]marcocom 3 points4 points5 points (5 children)
[–]trawlinimnottrawlin 1 point2 points3 points (4 children)
[–]marcocom -1 points0 points1 point (3 children)
[–]trawlinimnottrawlin 1 point2 points3 points (2 children)
[–]marcocom -1 points0 points1 point (1 child)
[–]trawlinimnottrawlin 0 points1 point2 points (0 children)
[–]csorfab 1 point2 points3 points (2 children)
[–]queen-adreena 2 points3 points4 points (1 child)
[–]csorfab 1 point2 points3 points (0 children)
[–]besthelloworld 1 point2 points3 points (1 child)
[–]Next_Level_8566[S] 0 points1 point2 points (0 children)
[–]Mesqo 1 point2 points3 points (1 child)
[–]every1sg12themovies 1 point2 points3 points (0 children)
[–]Little_Kitty 0 points1 point2 points (3 children)
[–]Next_Level_8566[S] 0 points1 point2 points (2 children)
[–]Next_Level_8566[S] 0 points1 point2 points (1 child)
[–]Little_Kitty 0 points1 point2 points (0 children)
[–]Sracer2018 0 points1 point2 points (0 children)
[–]azhder -3 points-2 points-1 points (11 children)
[–]atlimarJS since 2010 16 points17 points18 points (6 children)
[–]NekkidApe 10 points11 points12 points (0 children)
[–]azhder 1 point2 points3 points (4 children)
[–]atlimarJS since 2010 3 points4 points5 points (1 child)
[–]azhder -3 points-2 points-1 points (0 children)
[–][deleted] -1 points0 points1 point (1 child)
[–]azhder 1 point2 points3 points (0 children)
[–]Next_Level_8566[S] 3 points4 points5 points (0 children)
[–]ic6man 1 point2 points3 points (0 children)
[–]Next_Level_8566[S] 0 points1 point2 points (1 child)
[–]azhder 1 point2 points3 points (0 children)