Show HN: Ultra-lightweight chunker library with emoji support
18 Beardier 4 6/3/2025, 4:50:29 PM github.com ↗
I kept rewriting the same array.slice(i, i + n) logic in every project. Eventually, I decided to stop and just make a utility.
Chonkify is a small (~870B), zero-dependency JS/TS library for chunking any kind of data:
- Works with Array, String, Buffer, Set, Map, Array-like, TypedArray
- Handles AsyncIterable (great for batching streams)
- Unicode-safe (correctly handles grapheme clusters, emoji, etc.)
- ESM-first, TypeScript-ready
I mostly made it for myself, but figured others might find it useful too.
Would love feedback!
>Correctly handles Unicode emoji and complex symbols
I'm no JS/TS expert, but this sounds like it could be a case of making something behave like an inexperienced dev would expect at the cost of making it behave unexpectedly to an experienced dev.
JS strings are sequences of UTF16 code points, and that's part of their public API (e.g. 'split'), right? That's JS's choice (or mistake, depending on your feelings). So I would expect 'chonk' to treat strings as what they are. And then add a flag or separate method ('chonkGraphemes') instead.
But maybe this kind of "helpfulness" is normal in 3rd party JS APIs?