{"id":19529920,"url":"https://github.com/loopmode/utf8-byte-chunks","last_synced_at":"2025-02-26T02:43:12.645Z","repository":{"id":57388986,"uuid":"138738266","full_name":"loopmode/utf8-byte-chunks","owner":"loopmode","description":"Utility to split a string into chunks of a given byte size","archived":false,"fork":false,"pushed_at":"2018-06-26T14:22:10.000Z","size":5,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-05-28T16:05:58.421Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/loopmode.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-06-26T12:56:50.000Z","updated_at":"2021-09-23T20:13:38.000Z","dependencies_parsed_at":"2022-09-19T02:30:36.135Z","dependency_job_id":null,"html_url":"https://github.com/loopmode/utf8-byte-chunks","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loopmode%2Futf8-byte-chunks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loopmode%2Futf8-byte-chunks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loopmode%2Futf8-byte-chunks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loopmode%2Futf8-byte-chunks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/loopmode","download_url":"https://codeload.github.com/loopmode/utf8-byte-chunks/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240783109,"owners_count":19856776,"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":[],"created_at":"2024-11-11T01:28:07.922Z","updated_at":"2025-02-26T02:43:12.610Z","avatar_url":"https://github.com/loopmode.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# utf8-byte-chunks\n\nA utility that splits a given string into chunks of a maximum size in bytes.\n\n## use case\n\nThe primary use case was feeding user input to a chat API that accepts input of max 255 bytes per message.\n\nLimiting the number of input characters was not an option. Users should be able to submit larger text, e.g. copy-pasted from some documents, potentially containing multibyte characters.\n\nThe most viable option seemed to be sending multiple requests, each carrying up to 255 bytes of text, until the entire message was sent.\n\n## installation\n\nVia npm:\n\n```javascript\nnpm install --save utf8-byte-chunks\n```\n\nVia yarn:\n\n```javascript\nyarn add utf8-byte-chunks\n```\n\n\n## Example usage\n\n\n```javascript\n\nimport getBytesizedChunks from 'utf8-byte-chunks';\n\nasync handleSubmit(event) {\n    event.preventDefault();\n\n    // split the current text into chunks, then submit each of them individually\n    const chunks = getBytesizedChunks(this.state.text, 255);\n    for (let chunk of chunks) {\n        if (this._isMounted) {\n            await ChatStore.submitMessage(chunk);\n        }\n    }\n\n    if (this._isMounted) {\n        this.setState({ text: '' }, this.focusInput);\n    }\n}\n```\n\n## Options\n\n### Split on spaces\n\nPass `true` as the third argument (`splitOnSpace`) to avoid the initial value to be split in the middle of a word and respect spaces instead.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floopmode%2Futf8-byte-chunks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Floopmode%2Futf8-byte-chunks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floopmode%2Futf8-byte-chunks/lists"}