{"id":15042682,"url":"https://github.com/sindresorhus/chunkify","last_synced_at":"2025-04-05T13:09:27.210Z","repository":{"id":54268786,"uuid":"333391854","full_name":"sindresorhus/chunkify","owner":"sindresorhus","description":"Split an iterable into evenly sized chunks","archived":false,"fork":false,"pushed_at":"2023-12-27T16:31:24.000Z","size":10,"stargazers_count":154,"open_issues_count":0,"forks_count":7,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-29T05:25:11.306Z","etag":null,"topics":["array","array-chunk","array-manipulations","javascript","npm-package"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sindresorhus.png","metadata":{"funding":{"github":"sindresorhus","open_collective":"sindresorhus","custom":"https://sindresorhus.com/donate"},"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2021-01-27T11:02:02.000Z","updated_at":"2025-01-07T20:11:44.000Z","dependencies_parsed_at":"2023-12-31T17:06:40.561Z","dependency_job_id":"2fd9a8e6-2f20-4341-97be-28f46458368c","html_url":"https://github.com/sindresorhus/chunkify","commit_stats":{"total_commits":8,"total_committers":2,"mean_commits":4.0,"dds":0.125,"last_synced_commit":"974b6bf50374b3d2ce4791cf3587249c903bd667"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fchunkify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fchunkify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fchunkify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fchunkify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sindresorhus","download_url":"https://codeload.github.com/sindresorhus/chunkify/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246648844,"owners_count":20811609,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["array","array-chunk","array-manipulations","javascript","npm-package"],"created_at":"2024-09-24T20:47:44.595Z","updated_at":"2025-04-05T13:09:27.189Z","avatar_url":"https://github.com/sindresorhus.png","language":"JavaScript","readme":"# chunkify\n\n\u003e Split an iterable into evenly sized chunks\n\n## Install\n\n```sh\nnpm install chunkify\n```\n\n## Usage\n\n```js\nimport chunkify from 'chunkify';\n\nconsole.log([...chunkify([1, 2, 3, 4], 2)]);\n//=\u003e [[1, 2], [3, 4]]\n\nconsole.log([...chunkify([1, 2, 3, 4], 3)]);\n//=\u003e [[1, 2, 3], [4]]\n```\n\n## API\n\n### chunkify(iterable, chunkSize)\n\nReturns an iterable with the chunks. The last chunk could be smaller.\n\n#### iterable\n\nType: `Iterable` *(for example, `Array`)*\n\nThe iterable to chunkify.\n\n#### chunkSize\n\nType: `number` *(integer)*\\\nMinimum: `1`\n\nThe size of the chunks.\n\n## Use-cases\n\n### Batch processing\n\nWhen dealing with large datasets, breaking data into manageable chunks can optimize the batch processing tasks.\n\n```js\nimport chunkify from 'chunkify';\n\nconst largeDataSet = [...Array(1000).keys()];\nconst chunkedData = chunkify(largeDataSet, 50);\n\nfor (const chunk of chunkedData) {\n\tprocessBatch(chunk);\n}\n```\n\n### Parallel processing\n\nDividing data into chunks can be useful in parallel processing to distribute workload evenly across different threads or workers.\n\n```js\nimport {Worker} from 'node:worker_threads';\nimport chunkify from 'chunkify';\n\nconst data = [/* some large dataset */];\nconst chunkedData = chunkify(data, 20);\n\nfor (const [index, chunk] of chunkedData.entries()) {\n\tconst worker = new Worker('./worker.js', {\n\t\tworkerData: {\n\t\t\tchunk,\n\t\t\tindex\n\t\t}\n\t});\n}\n```\n\n### Network requests\n\nSplitting a large number of network requests into chunks can help in managing the load on the network and preventing rate limiting.\n\n```js\nimport chunkify from 'chunkify';\n\nconst urls = [/* Array of URLs */];\n\nconst chunkedUrls = chunkify(urls, 10);\n\nfor (const chunk of chunkedUrls) {\n\tawait Promise.all(chunk.map(url =\u003e fetch(url)));\n}\n```\n","funding_links":["https://github.com/sponsors/sindresorhus","https://opencollective.com/sindresorhus","https://sindresorhus.com/donate"],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fchunkify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsindresorhus%2Fchunkify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fchunkify/lists"}