{"_id":"pretty-bytes@7.2.0","bugs":{"url":"https://github.com/sindresorhus/pretty-bytes/issues"},"dist":{"shasum":"e4727cc3b8ea2bec96d86e19c2e35984e791cbfd","tarball":"http://registry-npm.ywwl.com/pretty-bytes/download/pretty-bytes-7.2.0.tgz","fileCount":5,"integrity":"sha512-T2kroepGB5DRVbkN/nOpW03+VRWqdtJhZNuCW3wYk3chdPjgi4GcTBOaxWfHq1MIM0ypidxsSWbQaAiRpxnXmg==","signatures":[{"sig":"MEUCIQClIO/oKjitPDae3fO3ZXTifJyWJlp38NZ/aamLbJWGDQIgLNj7cLd9sPI/BHftv+03f6akPr6oS+IrWhNrYwPHzWQ=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQD3h2cdLR3p886SaE0vzae0VWgcO3g4qLRUZPQ1Un/pQwIhALVLmE8iB9Guba5yNKXsSpl7Q98lQ+WyjKj1J4fhmW4c"}],"unpackedSize":25102,"size":7042,"noattachment":false,"key":"/pretty-bytes/-/pretty-bytes-7.2.0.tgz"},"name":"pretty-bytes","type":"module","types":"./index.d.ts","author":{"url":"https://sindresorhus.com","name":"Sindre Sorhus","email":"sindresorhus@gmail.com"},"engines":{"node":">=20"},"exports":{"types":"./index.d.ts","default":"./index.js"},"funding":"https://github.com/sponsors/sindresorhus","gitHead":"a35ed21bb4169c0bf40942ffa2987a06b8cd2854","license":"MIT","scripts":{"test":"xo && ava && tsd"},"version":"7.2.0","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"homepage":"https://github.com/sindresorhus/pretty-bytes#readme","keywords":["pretty","bytes","byte","filesize","size","file","human","humanized","readable","si","data","locale","localization","localized"],"repository":{"url":"git+https://github.com/sindresorhus/pretty-bytes.git","type":"git"},"_npmVersion":"12.0.1","description":"Convert bytes to a human readable string: 1337 → 1.34 kB","directories":{},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"sideEffects":false,"_nodeVersion":"26.9.0","_hasShrinkwrap":false,"devDependencies":{"xo":"^0.60.0","ava":"^6.2.0","tsd":"^0.32.0"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/pretty-bytes_7.2.0_1790421288661_0.26825565299684717"},"readme":"# pretty-bytes\n\n> 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//=> '1.34 kB'\n\nprettyBytes(100);\n//=> '100 B'\n\n// Display with units of bits\nprettyBytes(1337, {bits: true});\n//=> '1.34 kbit'\n\n// Display file size differences\nprettyBytes(42, {signed: true});\n//=> '+42 B'\n\n// Localized output using German locale\nprettyBytes(1337, {locale: 'de'});\n//=> '1,34 kB'\n\n// Fixed width for alignment (useful for progress bars and tables)\nprettyBytes(1337, {fixedWidth: 8});\n//=> ' 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\nA `bigint` of any size is accepted. Past roughly `1e332` bytes the scaled value no longer fits a `number`, and it is written out in full from the exact quotient, so it carries no grouping and no localized decimal separator, the same as a value below `1e-100`.\n\nByte counts are otherwise formatted with the precision of a JavaScript number, which holds about 16 significant digits, so above roughly `1e17` bytes the trailing digits of the output may not be exact. A value that rounds up onto a unit boundary can therefore be printed in the larger unit, so `999499999999999999` bytes is `1 EB` rather than `999 PB`.\n\n> [!NOTE]\n> Rounding uses `Number#toPrecision`, so at an exact tie the direction comes from how that value is stored as a floating point number. `1005` bytes is `1.005 kB` and rounds down to `1 kB`, while `1125` bytes is `1.125 kB` and rounds up to `1.13 kB`.\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```js\nimport prettyBytes from 'pretty-bytes';\n\nprettyBytes(1337, {bits: true});\n//=> '1.34 kbit'\n```\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```js\nimport prettyBytes from 'pretty-bytes';\n\nprettyBytes(1000, {binary: true});\n//=> '1000 B'\n\nprettyBytes(1024, {binary: true});\n//=> '1 KiB'\n```\n\n##### locale\n\nType: `boolean | string | string[]`\\\nDefault: `false`\n\n- If `false`: Output won't be localized.\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> [!IMPORTANT]\n> Only the number and decimal separator are localized. The unit title is not and will not be localized.\n\n> [!NOTE]\n> A value below `1e-100` bytes needs more than the 100 fraction digits `Intl.NumberFormat` accepts, so it is written out with plain digits instead of a localized decimal separator.\n\n```js\nimport prettyBytes from 'pretty-bytes';\n\nprettyBytes(1337, {locale: 'de'});\n//=> '1,34 kB'\n```\n\n##### minimumFractionDigits\n\nType: `number`\\\nDefault: `undefined`\n\nThe minimum number of fraction digits to display.\n\nIf neither `minimumFractionDigits` nor `maximumFractionDigits` is set, the default behavior is to round to 3 significant digits.\n\nMust be an integer between 0 and 100. Throws a `TypeError` for invalid values.\n\nMust not be greater than `maximumFractionDigits`, which throws a `RangeError` when both are set.\n\n> [!NOTE]\n> When `minimumFractionDigits` or `maximumFractionDigits` is specified, values are truncated instead of rounded to provide more intuitive results for file sizes.\n\n```js\nimport prettyBytes from 'pretty-bytes';\n\n// Show the number with at least 3 fractional digits\nprettyBytes(1900, {minimumFractionDigits: 3});\n//=> '1.900 kB'\n\nprettyBytes(1900);\n//=> '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` nor `maximumFractionDigits` is set, the default behavior is to round to 3 significant digits.\n\nMust be an integer between 0 and 100. Throws a `TypeError` for invalid values.\n\nMust not be less than `minimumFractionDigits`, which throws a `RangeError` when both are set.\n\n> [!NOTE]\n> When `minimumFractionDigits` or `maximumFractionDigits` is specified, values are truncated instead of rounded to provide more intuitive results for file sizes.\n\n```js\nimport prettyBytes from 'pretty-bytes';\n\n// Show the number with at most 1 fractional digit\nprettyBytes(1920, {maximumFractionDigits: 1});\n//=> '1.9 kB'\n\nprettyBytes(1920);\n//=> '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//=> '1.92kB'\n\nprettyBytes(1920);\n//=> '1.92 kB'\n```\n\n##### nonBreakingSpace\n\nType: `boolean`\\\nDefault: `false`\n\nUse a non-breaking space instead of a regular space to prevent the unit from wrapping to a new line.\n\nHas no effect when `space` is `false`.\n\n```js\nimport prettyBytes from 'pretty-bytes';\n\nprettyBytes(1337, {nonBreakingSpace: true});\n//=> '1.34\\u00A0kB'\n\nprettyBytes(1337, {space: false, nonBreakingSpace: true});\n//=> '1.34kB'\n```\n\n##### fixedWidth\n\nType: `number`\\\nDefault: `undefined`\n\nPad the output to a fixed width by right-aligning it.\n\nUseful for creating aligned columns in tables or progress bars.\n\nIf the output is longer than the specified width, no padding is applied.\n\nMust be a non-negative integer. Throws a `TypeError` for invalid values.\n\n```js\nimport prettyBytes from 'pretty-bytes';\n\nprettyBytes(1337, {fixedWidth: 10});\n//=> '   1.34 kB'\n\nprettyBytes(100_000, {fixedWidth: 10});\n//=> '    100 kB'\n\n// Useful for progress bars and tables\n[1000, 10_000, 100_000].map(bytes => prettyBytes(bytes, {fixedWidth: 8}));\n//=> ['    1 kB', '   10 kB', '  100 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","publish_time":1790421288764,"_cnpm_publish_time":1790421288764,"dist-tags":{"latest":"7.2.0"}}