{"id":13454732,"url":"https://github.com/sindresorhus/pretty-bytes","last_synced_at":"2025-05-11T11:01:36.378Z","repository":{"id":13970538,"uuid":"16671126","full_name":"sindresorhus/pretty-bytes","owner":"sindresorhus","description":"Convert bytes to a human readable string: 1337 → 1.34 kB","archived":false,"fork":false,"pushed_at":"2025-04-29T11:07:09.000Z","size":64,"stargazers_count":1171,"open_issues_count":4,"forks_count":84,"subscribers_count":11,"default_branch":"main","last_synced_at":"2025-05-08T06:35:59.912Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sindresorhus.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":".github/security.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"sindresorhus","open_collective":"sindresorhus","buy_me_a_coffee":"sindresorhus","custom":"https://sindresorhus.com/donate"}},"created_at":"2014-02-09T17:24:38.000Z","updated_at":"2025-05-07T00:52:26.000Z","dependencies_parsed_at":"2025-02-04T21:38:37.323Z","dependency_job_id":null,"html_url":"https://github.com/sindresorhus/pretty-bytes","commit_stats":{"total_commits":75,"total_committers":18,"mean_commits":4.166666666666667,"dds":0.28,"last_synced_commit":"71d686a4cefb314c13b57107de5add5789753900"},"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fpretty-bytes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fpretty-bytes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fpretty-bytes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fpretty-bytes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sindresorhus","download_url":"https://codeload.github.com/sindresorhus/pretty-bytes/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253077388,"owners_count":21850309,"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-07-31T08:00:57.408Z","updated_at":"2025-05-11T11:01:36.292Z","avatar_url":"https://github.com/sindresorhus.png","language":"JavaScript","readme":"# pretty-bytes\n\n\u003e Convert bytes to a human readable string: `1337` → `1.34 kB`\n\nUseful for displaying file sizes for humans.\n\n*Note that it uses base-10 (e.g. kilobyte).\n[Read about the difference between kilobyte and kibibyte.](https://web.archive.org/web/20150324153922/https://pacoup.com/2009/05/26/kb-kb-kib-whats-up-with-that/)*\n\n## Install\n\n```sh\nnpm install pretty-bytes\n```\n\n## Usage\n\n```js\nimport prettyBytes from 'pretty-bytes';\n\nprettyBytes(1337);\n//=\u003e '1.34 kB'\n\nprettyBytes(100);\n//=\u003e '100 B'\n\n// Display with units of bits\nprettyBytes(1337, {bits: true});\n//=\u003e '1.34 kbit'\n\n// Display file size differences\nprettyBytes(42, {signed: true});\n//=\u003e '+42 B'\n\n// Localized output using German locale\nprettyBytes(1337, {locale: 'de'});\n//=\u003e '1,34 kB'\n```\n\n## API\n\n### prettyBytes(number, options?)\n\n#### number\n\nType: `number | bigint`\n\nThe number to format.\n\n#### options\n\nType: `object`\n\n##### signed\n\nType: `boolean`\\\nDefault: `false`\n\nInclude plus sign for positive numbers. If the difference is exactly zero a space character will be prepended instead for better alignment.\n\n##### bits\n\nType: `boolean`\\\nDefault: `false`\n\nFormat the number as [bits](https://en.wikipedia.org/wiki/Bit) instead of [bytes](https://en.wikipedia.org/wiki/Byte). This can be useful when, for example, referring to [bit rate](https://en.wikipedia.org/wiki/Bit_rate).\n\n##### binary\n\nType: `boolean`\\\nDefault: `false`\n\nFormat the number using the [Binary Prefix](https://en.wikipedia.org/wiki/Binary_prefix) instead of the [SI Prefix](https://en.wikipedia.org/wiki/SI_prefix). This can be useful for presenting memory amounts. However, this should not be used for presenting file sizes.\n\n##### locale\n\nType: `boolean | string`\\\nDefault: `false` *(No localization)*\n\n**Important:** Only the number and decimal separator are localized. The unit title is not and will not be localized.\n\n- If `true`: Localize the output using the system/browser locale.\n- If `string`: Expects a [BCP 47 language tag](https://en.wikipedia.org/wiki/IETF_language_tag) (For example: `en`, `de`, …)\n- If `string[]`: Expects a list of [BCP 47 language tags](https://en.wikipedia.org/wiki/IETF_language_tag) (For example: `en`, `de`, …)\n\n##### minimumFractionDigits\n\nType: `number`\\\nDefault: `undefined`\n\nThe minimum number of fraction digits to display.\n\nIf neither `minimumFractionDigits` or `maximumFractionDigits` are set, the default behavior is to round to 3 significant digits.\n\n```js\nimport prettyBytes from 'pretty-bytes';\n\n// Show the number with at least 3 fractional digits\nprettyBytes(1900, {minimumFractionDigits: 3});\n//=\u003e '1.900 kB'\n\nprettyBytes(1900);\n//=\u003e '1.9 kB'\n```\n\n##### maximumFractionDigits\n\nType: `number`\\\nDefault: `undefined`\n\nThe maximum number of fraction digits to display.\n\nIf neither `minimumFractionDigits` or `maximumFractionDigits` are set, the default behavior is to round to 3 significant digits.\n\n```js\nimport prettyBytes from 'pretty-bytes';\n\n// Show the number with at most 1 fractional digit\nprettyBytes(1920, {maximumFractionDigits: 1});\n//=\u003e '1.9 kB'\n\nprettyBytes(1920);\n//=\u003e '1.92 kB'\n```\n\n##### space\n\nType: `boolean`\\\nDefault: `true`\n\nPut a space between the number and unit.\n\n```js\nimport prettyBytes from 'pretty-bytes';\n\nprettyBytes(1920, {space: false});\n//=\u003e '1.9kB'\n\nprettyBytes(1920);\n//=\u003e '1.92 kB'\n```\n\n## FAQ\n\n### Why kB and not KB?\n\n`k` is the [standardized SI prefix](https://en.wikipedia.org/wiki/Metric_prefix) for kilo.\n\n## Related\n\n- [pretty-bytes-cli](https://github.com/sindresorhus/pretty-bytes-cli) - CLI for this module\n- [pretty-ms](https://github.com/sindresorhus/pretty-ms) - Convert milliseconds to a human readable string\n","funding_links":["https://github.com/sponsors/sindresorhus","https://opencollective.com/sindresorhus","https://buymeacoffee.com/sindresorhus","https://sindresorhus.com/donate"],"categories":["Packages","包","JavaScript","others","Humanize","目录","前端常用","Number"],"sub_categories":["Humanize","人性化"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fpretty-bytes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsindresorhus%2Fpretty-bytes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fpretty-bytes/lists"}