1.0.2 ⢠Published 5 months ago
equal-chunks v1.0.2
š¦ equal-chunks
A simple utility to split payloads into equal-sized chunks.
Installation
This is a Node.js package available through the npm registry.
npm install equal-chunks
or via yarn:
yarn add equal-chunks
š Usage
1ļøā£ Import the Function
import { createChunksBySize } from "equal-chunks";
2ļøā£ Chunk a JSON Object
const data = { message: "Hello, this is a large payload that needs chunking!" };
const chunks = createChunksBySize(data, 10);
console.log(chunks);
š Output:
[
'{"message',
'":"Hello, ',
"this is a ",
"large payl",
"oad that n",
"eeds chunk",
'ing!"}',
];
ā” API Reference
createChunksBySize(payload, maxChunkSize);
Parameter | Type | Description |
---|---|---|
payload | object | string | The data to split into chunks. |
maxChunkSize | number | Maximum chunk size in bytes. |
š Returns: An array of chunked strings.
ā Why Choose equal-chunks?
āļø Supports both strings & JSON objects ā Works seamlessly with different data types.
āļø Splits data into evenly sized chunks ā Ensures consistency across chunks.
āļø Lightweight & dependency-free ā No external libraries required.
āļø Compatible with Node.js & Browsers ā Use it anywhere with ease.