{"id":18910049,"url":"https://github.com/cheton/readable-size","last_synced_at":"2025-04-15T06:31:08.434Z","repository":{"id":57348646,"uuid":"139010491","full_name":"cheton/readable-size","owner":"cheton","description":"Converts bytes into human readable size units.","archived":false,"fork":false,"pushed_at":"2019-08-27T11:51:18.000Z","size":13,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-29T16:26:41.210Z","etag":null,"topics":["bytes","file","filesize","human","readable","size","units"],"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/cheton.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":null,"patreon":null,"open_collective":"cheton","ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2018-06-28T11:43:15.000Z","updated_at":"2020-04-10T10:11:54.000Z","dependencies_parsed_at":"2022-08-30T18:51:11.059Z","dependency_job_id":null,"html_url":"https://github.com/cheton/readable-size","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cheton%2Freadable-size","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cheton%2Freadable-size/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cheton%2Freadable-size/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cheton%2Freadable-size/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cheton","download_url":"https://codeload.github.com/cheton/readable-size/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247465553,"owners_count":20943200,"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":["bytes","file","filesize","human","readable","size","units"],"created_at":"2024-11-08T09:39:10.048Z","updated_at":"2025-04-15T06:31:08.398Z","avatar_url":"https://github.com/cheton.png","language":"JavaScript","funding_links":["https://opencollective.com/cheton"],"categories":[],"sub_categories":[],"readme":"# readable-size [![build status](https://travis-ci.org/cheton/readable-size.svg?branch=master)](https://travis-ci.org/cheton/readable-size) [![Coverage Status](https://coveralls.io/repos/github/cheton/readable-size/badge.svg?branch=master)](https://coveralls.io/github/cheton/readable-size?branch=master)\n[![NPM](https://nodei.co/npm/readable-size.png?downloads=true\u0026stars=true)](https://www.npmjs.com/package/readable-size)\n\nConverts bytes into human readable size units: B, KB, MB, GB, TB, PB, EB, ZB, YB.\n\n## Installation\n\n```bash\nnpm install --save readable-size\n```\n\n## Examples\n\n```js\nreadableSize(1); // '1 B'\nreadableSize(1023); // '1023 B'\nreadableSize(1024); // '1.00 KB'\nreadableSize(1025); // '1.00 KB'\nreadableSize(1000000); // '976 KB'\nreadableSize(1023999); // '999 KB'\nreadableSize(1024000); // '0.97 MB'\nreadableSize(1048575); // '0.99 MB'\nreadableSize(1048576); // '1.00 MB'\nreadableSize(1048577); // '1.00 MB'\nreadableSize(1000000000); // '953 MB'\nreadableSize(1048575999); // '999 MB'\nreadableSize(1048576000); // '0.97 GB'\nreadableSize(1073741823); // '0.99 GB'\nreadableSize(1073741824); // '1.00 TB'\n```\n\n### Output\n\nThe output is one of `'string'`, `'array'`, `'object'`, or function type.\n\n#### 'string'\n\n```js\nreadableSize(1024, { output: 'string' }); // '1.00 KB'\nreadableSize(1024, { output: 'string', format: '{{size}} ({{unit}})' }); // '1.00 (KB)'\n```\n\n#### 'array'\n\n```js\nreadableSize(1024, { output: 'array' }); // [ '1.00', 'KB' ]\n```\n\n#### 'object'\n\n```js\nreadableSize(1024, { output: 'object' }); // { size: '1.00', unit: 'KB' }\n```\n\n#### function\n\n```js\nreadableSize(999, { // '999 bytes'\n    output: ({ size, unit }) =\u003e {\n        unit = { B: 'bytes' }[unit] || unit;\n        return `${size} ${unit}`;\n    }\n});\n```\n\n### Separators\n\n#### English\n\n```js\nconst options = {\n    separator: {\n        thousands: ',',\n        decimal: '.',\n    }\n};\nreadableSize(999, options); // '999 B'\nreadableSize(1000, options); // '1,000 B'\nreadableSize(1024, options); // '1.00 KB'\n```\n\n#### French\n\n```js\nconst options = {\n    separator: {\n        thousands: ' ',\n        decimal: ',',\n    }\n};\nreadableSize(999, options); // '999 B'\nreadableSize(1000, options); // '1 000 B'\nreadableSize(1024, options); // '1,00 KB'\n```\n\n#### Dutch\n\n```js\nconst options = {\n    separator: {\n        thousands: '.',\n        decimal: ',',\n    }\n};\nreadableSize(999, options); // '999 B'\nreadableSize(1000, options); // '1.000 B'\nreadableSize(1024, options); // '1,00 KB'\n```\n\n## Options\n\n### separator\n\n_*(boolean)*_ Enable separators, default is `false`\n\n_*(object)*_ Specifies the thousands and decimal separators, default is:\n\n```js\nseparator: {\n    thousands: ',',\n    decimal: '.'\n}\n```\n\n### output\n\n_*('string')*_ The output is defined by the format string, default is `'{{size}} {{unit}}'`\n\n_*('array')*_ The output is `[size, unit]`\n\n_*('object')*_ The output is `{ size, unit }`\n\n_*(function)*_ A user-defined output function:\n\n```js\nformat: ({ size, unit }) =\u003e {\n    unit = { 'B': 'bytes' }[unit] || unit;\n    return `${size} ${unit}`;\n}\n```\n\n### format\n\n_*(string)*_ The format string, default is `'{{size}} {{unit}}'`\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcheton%2Freadable-size","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcheton%2Freadable-size","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcheton%2Freadable-size/lists"}