{"name":"pretty-bytes","version":"7.1.2","keywords":["pretty","bytes","byte","filesize","size","file","human","humanized","readable","si","data","locale","localization","localized"],"author":{"url":"https://sindresorhus.com","name":"Sindre Sorhus","email":"sindresorhus@gmail.com"},"license":"MIT","_id":"pretty-bytes@7.1.2","maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"homepage":"https://github.com/sindresorhus/pretty-bytes#readme","bugs":{"url":"https://github.com/sindresorhus/pretty-bytes/issues"},"dist":{"shasum":"2ff7ecfe78c999a2edf5f20449b047b0583108d2","tarball":"http://registry-npm.ywwl.com/pretty-bytes/download/pretty-bytes-7.1.2.tgz","fileCount":5,"integrity":"sha512-spZIOSORH9joSPGN0L/tYfvINH+xbOpnI3kdcEkq0mzGMjFvDZzyRVbqEOV0wACF0gggdKE9RWO2mosGsBh/Rg==","signatures":[{"sig":"MEYCIQCAbgDig6ivH193SqBQYNPp2qGh+UI+wSPHtLH7bC1f/QIhALQuc9TEtco0OzMXnYIU4NAmh105EZ6bowHbvryq2FUl","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"sig":"MEYCIQDlwmo/UbzoEovp1CRUEqWab6BSZIs8B2XcTm/MCtWyjAIhAMkTRiNB7A9gpRBcru3OQGt8NBj96N1JTWWxP/XaeTMP","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":15939,"size":4686,"noattachment":false,"key":"/pretty-bytes/-/pretty-bytes-7.1.2.tgz"},"type":"module","types":"./index.d.ts","engines":{"node":">=20"},"exports":{"types":"./index.d.ts","default":"./index.js"},"funding":"https://github.com/sponsors/sindresorhus","gitHead":"deb9a2c6d2aaa2789e51411ebfcc7dd52446a2e9","scripts":{"test":"xo && ava && tsd"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"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":{},"sideEffects":false,"_nodeVersion":"22.23.1","_hasShrinkwrap":false,"devDependencies":{"xo":"^0.60.0","ava":"^6.2.0","tsd":"^0.32.0"},"_npmOperationalInternal":{"tmp":"tmp/pretty-bytes_7.1.2_1787931586568_0.4491140717801061","host":"s3://npm-registry-packages-npm-production"},"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\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##### 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\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\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##### 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":1787931586638,"_cnpm_publish_time":1787931586638,"dist-tags":{"latest":"7.2.0"}}