{"id":50794575,"url":"https://github.com/brandonhimpfen/data-size-parser","last_synced_at":"2026-06-12T13:32:12.908Z","repository":{"id":346646491,"uuid":"1190951737","full_name":"brandonhimpfen/data-size-parser","owner":"brandonhimpfen","description":"A tiny, practical parser for human-readable data sizes.","archived":false,"fork":false,"pushed_at":"2026-03-24T19:29:28.000Z","size":5,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-03-26T00:49:51.075Z","etag":null,"topics":["data","data-size","data-sizes","npm","open-source","web-design","web-development"],"latest_commit_sha":null,"homepage":"https://www.himpfen.com/data-size-parser/","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/brandonhimpfen.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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"ko_fi":"brandonhimpfen","custom":["https://paypal.me/brandonhimpfen","https://github.com/brandonhimpfen/donate"]}},"created_at":"2026-03-24T19:25:43.000Z","updated_at":"2026-03-25T02:59:12.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/brandonhimpfen/data-size-parser","commit_stats":null,"previous_names":["brandonhimpfen/data-size-parser"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/brandonhimpfen/data-size-parser","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brandonhimpfen%2Fdata-size-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brandonhimpfen%2Fdata-size-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brandonhimpfen%2Fdata-size-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brandonhimpfen%2Fdata-size-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brandonhimpfen","download_url":"https://codeload.github.com/brandonhimpfen/data-size-parser/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brandonhimpfen%2Fdata-size-parser/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34247461,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-12T02:00:06.859Z","response_time":109,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["data","data-size","data-sizes","npm","open-source","web-design","web-development"],"created_at":"2026-06-12T13:32:11.429Z","updated_at":"2026-06-12T13:32:12.902Z","avatar_url":"https://github.com/brandonhimpfen.png","language":"JavaScript","funding_links":["https://ko-fi.com/brandonhimpfen","https://paypal.me/brandonhimpfen","https://github.com/brandonhimpfen/donate"],"categories":[],"sub_categories":[],"readme":"# data-size-parser\n\nA tiny, practical parser for human-readable data sizes.\n\nThis package converts values like `10MB`, `2gb`, `512 KiB`, and `1.5 TiB` into bytes. It is designed to be small, predictable, and easy to use in scripts, CLIs, data tooling, and storage-related workflows.\n\nIt can be used as both a practical utility and a lightweight reference for normalizing storage size inputs.\n\n## Why this project exists\n\nHuman-readable data sizes appear everywhere.\n\nConfiguration files, CLI flags, dashboards, logs, APIs, and documentation often represent storage sizes as strings. Those strings are easy for people to read, but they are not immediately useful for systems that need exact byte values.\n\nA parser solves that boundary problem.\n\nInstead of writing ad hoc conversion logic in every project, `data-size-parser` provides a single, explicit way to interpret common decimal and binary size units.\n\n## What it supports\n\nThe parser supports:\n\n- bytes: `B`, `byte`, `bytes`\n- decimal units: `KB`, `MB`, `GB`, `TB`, `PB`\n- binary units: `KiB`, `MiB`, `GiB`, `TiB`, `PiB`\n- uppercase and lowercase input\n- optional spaces between value and unit\n- integer and decimal values\n\nExamples:\n\n- `10MB` → `10000000`\n- `2gb` → `2000000000`\n- `512 KiB` → `524288`\n- `1.5 TiB` → `1649267441664`\n\n## Install\n\n```bash\nnpm install data-size-parser\n```\n\n## Example\n\n```js\nimport { parseDataSize } from \"data-size-parser\";\n\nparseDataSize(\"10MB\");\n// 10000000\n\nparseDataSize(\"2gb\");\n// 2000000000\n\nparseDataSize(\"512 KiB\");\n// 524288\n\nparseDataSize(\"1.5 TiB\");\n// 1649267441664\n```\n\n## API\n\n### `parseDataSize(input)`\n\nParses a human-readable data size string and returns the size in bytes as an integer.\n\n```js\nimport { parseDataSize } from \"data-size-parser\";\n\nconst bytes = parseDataSize(\"256MB\");\n// 256000000\n```\n\n### `tryParseDataSize(input)`\n\nAttempts to parse a human-readable data size string and returns `null` instead of throwing when parsing fails.\n\n```js\nimport { tryParseDataSize } from \"data-size-parser\";\n\ntryParseDataSize(\"64GiB\");\n// 68719476736\n\ntryParseDataSize(\"not-a-size\");\n// null\n```\n\n### `formatSupportedUnits()`\n\nReturns a list of supported unit labels.\n\n```js\nimport { formatSupportedUnits } from \"data-size-parser\";\n\nformatSupportedUnits();\n// [\"B\", \"KB\", \"MB\", \"GB\", \"TB\", \"PB\", \"KiB\", \"MiB\", \"GiB\", \"TiB\", \"PiB\"]\n```\n\n## Design Principles\n\nThis project is intentionally minimal.\n\nIt focuses on one job: turning human-readable data size strings into byte values without introducing unnecessary complexity.\n\nThe design emphasizes:\n\n- Simplicity over abstraction\n- Predictability over magic\n- Clear unit handling over ambiguous shortcuts\n- Small utilities that are easy to reuse\n\n## Non-Goals\n\nThis project does not attempt to:\n\n- format bytes back into display strings.\n- infer units from context beyond the provided input.\n- handle bit-based units such as `Mbps` or `Kibit`.\n- act as a general-purpose measurement parser.\n\nIt is focused only on parsing storage size strings into bytes.\n\n## Edge Cases\n\n- `parseDataSize(\"100\")` is treated as bytes.\n- leading and trailing whitespace is ignored.\n- decimal values are allowed for all supported units.\n- invalid or unknown units throw a descriptive error.\n- negative values are rejected.\n\n## Roadmap\n\nFuture extensions may include:\n\n- stricter parsing modes.\n- optional bigint support for very large values.\n- formatter companion package.\n- ESM + TypeScript declaration support.\n\n## Repository\n\nGitHub: https://github.com/brandonhimpfen/data-size-parser\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrandonhimpfen%2Fdata-size-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrandonhimpfen%2Fdata-size-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrandonhimpfen%2Fdata-size-parser/lists"}