{"id":28558516,"url":"https://github.com/shelfio/array-chunk-by-size","last_synced_at":"2025-06-25T12:34:49.288Z","repository":{"id":26588769,"uuid":"109286924","full_name":"shelfio/array-chunk-by-size","owner":"shelfio","description":"Chunk array of objects by their size in JSON","archived":false,"fork":false,"pushed_at":"2025-05-31T00:29:34.000Z","size":70,"stargazers_count":4,"open_issues_count":10,"forks_count":3,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-05-31T11:07:27.767Z","etag":null,"topics":["arrays","chunk","chunking","node-module","npm-package","splitting"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/shelfio.png","metadata":{"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,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-11-02T15:57:01.000Z","updated_at":"2025-04-14T12:50:52.000Z","dependencies_parsed_at":"2023-12-21T04:24:03.660Z","dependency_job_id":"13a737dc-b7d9-490f-9812-b364c9f37ad6","html_url":"https://github.com/shelfio/array-chunk-by-size","commit_stats":{"total_commits":29,"total_committers":5,"mean_commits":5.8,"dds":0.6896551724137931,"last_synced_commit":"ee1799bbe34b3ddbcd54759e76ddc0b7d31e0ea4"},"previous_names":["vladgolubev/array-chunk-by-size"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shelfio%2Farray-chunk-by-size","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shelfio%2Farray-chunk-by-size/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shelfio%2Farray-chunk-by-size/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shelfio%2Farray-chunk-by-size/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shelfio","download_url":"https://codeload.github.com/shelfio/array-chunk-by-size/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shelfio%2Farray-chunk-by-size/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259033838,"owners_count":22795772,"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":["arrays","chunk","chunking","node-module","npm-package","splitting"],"created_at":"2025-06-10T08:09:04.797Z","updated_at":"2025-06-10T08:09:06.344Z","avatar_url":"https://github.com/shelfio.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# array-chunk-by-size [![CircleCI](https://img.shields.io/circleci/project/shelfio/array-chunk-by-size.svg)](https://circleci.com/gh/shelfio/array-chunk-by-size)\n\n\u003e Chunk array of objects by their size in JSON\n\n## Install\n\n```\n$ yarn add @shelf/array-chunk-by-size\n```\n\n## Usage\n\nUseful if you want to split large array into smaller, but limited by JSON size.\n\nEach array chunk will be up to specified amount of bytes when stringified into JSON.\n\n```js\nimport {chunkArray} from '@shelf/array-chunk-by-size';\n\nconst bigArray = [{a: 1}, {b: 2}, {c: 3}];\nconst twoKilobytes = 2 * 1024;\n\nconst smallerArrays = chunkArray({input: bigArray, bytesSize: twoKilobytes});\n// =\u003e [ [ ... ], [ ... ] ] and so on\n```\n\nAlternatively, you might pass a custom size calculation function.\nFor example, to chunk array by LLM tokens size:\n\n```js\nimport {chunkArray} from '@shelf/array-chunk-by-size';\nimport {encode} from 'gpt-3-encoder';\n\nconst bigArray = ['msg-1', 'msg-2'];\nconst gpt3MaxTokens = 4000;\n\nconst smallerArrays = chunkArray({\n  input: bigArray,\n  bytesSize: gpt3MaxTokens,\n  sizeCalcFunction: item =\u003e encode(item).length,\n});\n```\n\n## See Also\n\n- [fast-chunk-string](https://github.com/shelfio/fast-chunk-string)\n- [fast-normalize-spaces](https://github.com/shelfio/fast-normalize-spaces)\n- [fast-natural-order-by](https://github.com/shelfio/fast-natural-order-by)\n- [fast-uslug](https://github.com/shelfio/fast-uslug)\n\n## Publish\n\n```sh\n$ git checkout master\n$ yarn version\n$ yarn publish\n$ git push origin master --tags\n```\n\n## License\n\nMIT © [Shelf](https://shelf.io)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshelfio%2Farray-chunk-by-size","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshelfio%2Farray-chunk-by-size","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshelfio%2Farray-chunk-by-size/lists"}