{"id":19229006,"url":"https://github.com/caomeiyouren/better-bytes","last_synced_at":"2026-03-05T16:03:53.529Z","repository":{"id":236502378,"uuid":"792693649","full_name":"CaoMeiYouRen/better-bytes","owner":"CaoMeiYouRen","description":"Better byte base conversion. Supports two base conversions: kilo binary byte (2^10) and kilobyte (10^3)。更好的字节进制换算。支持 千位二进制字节(2^10) 和 千字节(10^3) 两种进制换算","archived":false,"fork":false,"pushed_at":"2026-02-28T20:23:19.000Z","size":1137,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-02-28T23:24:49.916Z","etag":null,"topics":["byte","bytes","kilo-binary-byte","kilobyte","parse","parser","utility"],"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/CaoMeiYouRen.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-04-27T09:52:23.000Z","updated_at":"2026-02-28T20:23:15.000Z","dependencies_parsed_at":"2024-04-27T14:03:45.889Z","dependency_job_id":"396db64a-37eb-4dfa-ba6a-b3ea55072836","html_url":"https://github.com/CaoMeiYouRen/better-bytes","commit_stats":null,"previous_names":["caomeiyouren/better-bytes"],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/CaoMeiYouRen/better-bytes","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CaoMeiYouRen%2Fbetter-bytes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CaoMeiYouRen%2Fbetter-bytes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CaoMeiYouRen%2Fbetter-bytes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CaoMeiYouRen%2Fbetter-bytes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CaoMeiYouRen","download_url":"https://codeload.github.com/CaoMeiYouRen/better-bytes/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CaoMeiYouRen%2Fbetter-bytes/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30134581,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-05T15:35:27.018Z","status":"ssl_error","status_checked_at":"2026-03-05T15:35:23.768Z","response_time":93,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["byte","bytes","kilo-binary-byte","kilobyte","parse","parser","utility"],"created_at":"2024-11-09T15:31:49.450Z","updated_at":"2026-03-05T16:03:53.517Z","avatar_url":"https://github.com/CaoMeiYouRen.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003ebetter-bytes \u003c/h1\u003e\n\u003cp\u003e\n  \u003ca href=\"https://www.npmjs.com/package/better-bytes\" target=\"_blank\"\u003e\n    \u003cimg alt=\"Version\" src=\"https://img.shields.io/npm/v/better-bytes.svg\"\u003e\n  \u003c/a\u003e\n    \u003ca href=\"https://www.npmjs.com/package/better-bytes\" target=\"_blank\"\u003e\n    \u003cimg alt=\"npm publish\" src=\"https://img.shields.io/npm/dt/better-bytes?label=npm%20downloads\u0026color=yellow\"\u003e\n  \u003c/a\u003e\n  \u003cimg src=\"https://img.shields.io/badge/node-%3E%3D18-blue.svg\" \u003e\n  \u003ca href=\"https://github.com/CaoMeiYouRen/better-bytes/actions?query=workflow%3ARelease\" target=\"_blank\"\u003e\n    \u003cimg alt=\"GitHub Workflow Status\" src=\"https://img.shields.io/github/actions/workflow/status/CaoMeiYouRen/better-bytes/release.yml?branch=master\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://app.codecov.io/gh/CaoMeiYouRen/better-bytes\" target=\"_blank\"\u003e\n     \u003cimg alt=\"Codecov\" src=\"https://img.shields.io/codecov/c/github/CaoMeiYouRen/better-bytes\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/CaoMeiYouRen/better-bytes#readme\" target=\"_blank\"\u003e\n    \u003cimg alt=\"Documentation\" src=\"https://img.shields.io/badge/documentation-yes-brightgreen.svg\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/CaoMeiYouRen/better-bytes/graphs/commit-activity\" target=\"_blank\"\u003e\n    \u003cimg alt=\"Maintenance\" src=\"https://img.shields.io/badge/Maintained%3F-yes-green.svg\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/CaoMeiYouRen/better-bytes/blob/master/LICENSE\" target=\"_blank\"\u003e\n    \u003cimg alt=\"License: MIT\" src=\"https://img.shields.io/github/license/CaoMeiYouRen/better-bytes?color=yellow\" /\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n\u003e Better byte base conversion. Supports two base conversions: kilo binary byte (2^10) and kilobyte (10^3).\n\u003e\n\u003e Reference link: [Prefixes for binary multiples](https://physics.nist.gov/cuu/Units/binary.html) ; [Binary prefix](https://en.wikipedia.org/wiki/Binary_prefix#IEC_prefixes)\n\u003e\n\u003e 更好的字节进制换算。支持 千位二进制字节(2^10) 和 千字节(10^3) 两种进制换算\n\u003e\n\u003e 参考链接：[Prefixes for binary multiples](https://physics.nist.gov/cuu/Units/binary.html) ; [Binary prefix](https://en.wikipedia.org/wiki/Binary_prefix#IEC_prefixes)\n\n## 🏠 Home/主页\n\n[https://github.com/CaoMeiYouRen/better-bytes#readme](https://github.com/CaoMeiYouRen/better-bytes#readme)\n\n## 📦 Dependency Requirements/依赖要求\n\n-   node \u003e=18\n\n## 🚀 Installation/安装\n\n```sh\nnpm install better-bytes\n```\n\n## 👨‍💻 Usage/使用\n\n```ts\nimport { format, parse } from \"better-bytes\";\n\nformat(1024); // '1.00 KiB'\nformat(1073741824); // '1.00 GiB'\nformat(1125899906842624n); // '1.00 PiB'\n\nformat(1572864, { standard: \"kilobinary\" }); // '1.50 MiB'\nformat(1500000, { standard: \"kilo\" }); // '1.50 MB'\n\nformat(1234, { decimal: 3, standard: \"kilobinary\" }); // '1.205 KiB'\nformat(1234, { decimal: 3, standard: \"kilo\" }); // '1.234 KB\n\nformat(1.1); // Error: 'Data must be integer'\nformat(-1); // Error: 'Data must be greater than or equal to 0'\nformat(\"invalid\"); // Error: 'Data must be a number or bigint'\nformat(NaN); // Error: 'Data must be finite'\n\nparse(\"1KiB\"); // 1024\nparse(\"1GiB\"); // 1073741824\n\nparse(\"1KB\"); // 1000\nparse(\"1GB\"); // 1000000000\n\nparse(\"1KB\", { forceKilobinary: true }); // 1024\nparse(\"1GB\", { forceKilobinary: true }); // 1073741824\n\nparse(\"1.5KiB\"); // 1536\nparse(\"1.5KB\"); // 1500\n\nparse(\"1024\"); // 1024\nparse(\"1000.5\"); // 1000\n\nparse(\"1.123456789012345GiB\"); // 1206302541\nparse(\"1.123456789012345GB\"); // 1123456789\n\nparse(\"9007199254740991YiB\"); // 10633823966279325802638835764831453184n\nparse(\"9007199254740991YB\"); // 9007199254740991000000000000000000000n\n\nparse(\"+1KiB\"); // 1024\n\nparse(\"-1KiB\"); // null\nparse(\"1XB\"); // null\nparse(\"invalid\"); // null\nparse(\"Infinity\"); // null\nparse(123); // Error: Data must be a string\n```\n\n### format(data: number | bigint, options: Options = {}): string\n\nFormat the given value in bytes into a string.\n\n将给定的字节值格式化为字符串。\n\n**Arguments**\n\n| Name    | Type               | Description                                     |\n| ------- | ------------------ | ----------------------------------------------- |\n| data    | `number`｜`bigint` | Number value to format. 要格式化的数值          |\n| options | `object`           | Conversion options for `format`. 格式化的选项。 |\n\n**Options**\n\n| Property      | Type                  | Description                                                                                                              |\n| ------------- | --------------------- | ------------------------------------------------------------------------------------------------------------------------ |\n| decimal       | `number`｜`undefined` | Maximum number of decimal places to include in output. Default: `2`. 输出中包含的最大小数位数。默认值：`2`。             |\n| standard      | `kilobinary`｜`kilo`  | base. kilobinary = 2^10 ; kilo = 10^3. Default: `kilobinary`. 进制规范。千位二进制=2^10；千位=10^3。默认值：`kilobinary` |\n| unitSeparator | `string`｜`undefined` | Separator to use between number and unit. Default: `' '`. 用于数字和单位之间的分隔符。默认值：`' '`                      |\n\n**Returns**\n\n| Name    | Type     | Description                                                                                                                                                         |\n| ------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| results | `string` | Return string. For non number or bigint, as well as cases less than 0, exceptions are thrown. 返回 string。对于非 number 或 bigint，以及小于 0 的情况，均抛出异常。 |\n\n### parse(data: string): number | bigint | null\n\nParse the string value into an integer in bytes. If no unit is given, it is assumed the value is in bytes.\n\n将字符串值解析为以字节为单位的整数。如果没有给出单位，则假定该值以字节为单位。\n\n**Arguments**\n\n| Name    | Type     | Description                             |\n| ------- | -------- | --------------------------------------- |\n| data    | `string` | String value to parse. 要解析的字符串。 |\n| options | `object` | Parsed options. 解析的选项。            |\n\n**Options**\n\n| Property        | Type                   | Description                                                                                                              |\n| --------------- | ---------------------- | ------------------------------------------------------------------------------------------------------------------------ |\n| forceKilobinary | `boolean`｜`undefined` | If true, consider kilo as kilobinary, i.e. using 2^10 base. 如果为真，则将千位进制视为千位二进制，即使用 2^10 进制换算。 |\n\n**Returns**\n\n| Name    | Type                       | Description                                                                                                                                      |\n| ------- | -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |\n| results | `number`｜`bigint`｜`null` | Returns null on error. Otherwise, return the value of number or bigint in bytes. 出错时返回 null。否则以字节为单位返回 number 或 bigint 的数值。 |\n\n## 🛠️ Development/开发\n\n```sh\nnpm run dev\n```\n\n## 🔧 Build/编译\n\n```sh\nnpm run build\n```\n\n## 🧪 Test/测试\n\n```sh\nnpm run test\n```\n\n## 🔍 Lint\n\n```sh\nnpm run lint\n```\n\n## 💾 Commit\n\n```sh\nnpm run commit\n```\n\n## 👤 Author/作者\n\n**CaoMeiYouRen**\n\n-   Website: [https://blog.cmyr.ltd/](https://blog.cmyr.ltd/)\n\n-   GitHub: [@CaoMeiYouRen](https://github.com/CaoMeiYouRen)\n\n## 🤝 Contribution/贡献\n\nWelcome to contribute, ask questions or propose new features! \u003cbr /\u003eIf you have any questions, please check the [issues page](https://github.com/CaoMeiYouRen/better-bytes/issues). \u003cbr/\u003e For contributions or new feature proposals, please refer to the [contributing guide](https://github.com/CaoMeiYouRen/better-bytes/blob/master/CONTRIBUTING.md).\n\n欢迎 贡献、提问或提出新功能！\u003cbr /\u003e如有问题请查看 [issues page](https://github.com/CaoMeiYouRen/better-bytes/issues). \u003cbr/\u003e贡献或提出新功能可以查看[contributing guide](https://github.com/CaoMeiYouRen/better-bytes/blob/master/CONTRIBUTING.md).\n\n## 💰 Support/支持\n\nIf you find this project useful, please give it a ⭐️. Thank you very much.\n\n如果觉得这个项目有用的话请给一颗 ⭐️，非常感谢\n\n## 📝 License\n\nCopyright © 2024 [CaoMeiYouRen](https://github.com/CaoMeiYouRen).\u003cbr /\u003e\nThis project is [MIT](https://github.com/CaoMeiYouRen/better-bytes/blob/master/LICENSE) licensed.\n\n## 🖥️ Reference project/参考项目\n\n-   [bytes.js](https://github.com/visionmedia/bytes.js)\n-   [filesize.js](https://github.com/avoidwork/filesize.js)\n\n---\n\n_This README was generated with ❤️ by [cmyr-template-cli](https://github.com/CaoMeiYouRen/cmyr-template-cli)_\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaomeiyouren%2Fbetter-bytes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcaomeiyouren%2Fbetter-bytes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaomeiyouren%2Fbetter-bytes/lists"}