Show HN: Ultra-lightweight chunker library with emoji support

3 weeks ago 2

chonkify logo

npm version license build status

Ultra-lightweight chunker for everything — arrays, strings, sets, maps, async iterables and more.

  • Works with everything: Array, String, Buffer, Set, Map, Array-like, TypedArray
  • Supports AsyncIterable (for await)
  • Correctly handles Unicode emoji and complex symbols 👨‍👩‍👧‍👦 🏳️‍🌈 🎉
  • Minimal size: core just 870 bytes, entire package ~5.5 kB
  • Zero dependencies
  • ESM-first, TypeScript-ready
import { chonk, chonkAsync } from 'chonkify'; // Basic examples chonk([1, 2, 3, 4], 2); // [[1, 2], [3, 4]] chonk('abcdef', 2); // ['ab', 'cd', 'ef'] // Unicode emoji support chonk('👍👌✌️😀', 2); // ['👍👌', '✌️😀'] chonk('👨‍👩‍👧‍👦🏳️‍🌈', 1); // ['👨‍👩‍👧‍👦', '🏳️‍🌈'] // Async usage: for await (const group of chonkAsync(fetchLines(), 100)) { console.log(group); }

Splits an iterable into groups of the specified size.

chonk([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4], [5]]

chonkAsync(asyncIterable, size)

Asynchronously splits an iterable into groups of the specified size.

// Process large datasets in batches for await (const batch of chonkAsync(dataStream, 100)) { await processBatch(batch); }

Can I use chonkify with Node.js?

Yes, chonkify works both in browsers and Node.js environments.

Does it support nested data structures?

Yes, chonkify can handle nested data structures as it groups elements without transforming them.

MIT

Read Entire Article