{"_id":"byte-size@9.0.2","bugs":{"url":"https://github.com/75lb/byte-size/issues"},"dist":{"shasum":"97b2225c8db5fa54b658985d3896b1e020cba019","tarball":"http://registry-npm.ywwl.com/byte-size/download/byte-size-9.0.2.tgz","fileCount":7,"integrity":"sha512-awINQonvLawPPCIWKIoYwPlUJc2ysiRsYIIJfJoIyWMbqdceKHhhZsT3226exJYoDqpuI6sInkEo1B5Rrjbs+g==","signatures":[{"sig":"MEUCIHy5B/DyTscFggeYyEp1iBNtjyn4Fngz/VMvneEC0aM6AiEA0Vm5w8Zo69II91qMLqGB00aen7BxwkyHMqdj//+C3zk=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCGbvMGs2mnGlJvufvfU1VU3Tzeqe/7CIkkmESWBeUelgIgNa7NpI6q4ghYZTRIMa1zzXBfoUPlYR2OiAiHEnNgXu4="}],"unpackedSize":33543,"size":6018,"noattachment":false,"key":"/byte-size/-/byte-size-9.0.2.tgz"},"name":"byte-size","type":"module","author":{"name":"Lloyd Brookes","email":"opensource@75lb.com"},"engines":{"node":">=12.17"},"exports":{"import":"./index.js","require":"./dist/index.cjs"},"gitHead":"2e391037902390845aa75c2a6fd43d9011c6e38b","license":"MIT","scripts":{"dist":"75lb-nature cjs-build index.js","docs":"75lb-nature jsdoc2md -t README.hbs index.js > README.md","test":"npm run dist && npm run test:ci","test:ci":"75lb-nature test-runner test*.js"},"version":"9.0.2","_npmUser":{"name":"75lb","email":"opensource@75lb.com"},"homepage":"https://github.com/75lb/byte-size#readme","keywords":["convert","bytes","octet","size","human","readable","metric","IEC"],"standard":{"ignore":["dist"]},"repository":{"url":"git+https://github.com/75lb/byte-size.git","type":"git"},"_npmVersion":"12.0.2","description":"Convert a bytes or octets value (e.g. 34565346) to a human-readable string ('34.6 MB'). Choose between metric or IEC units.","directories":{},"maintainers":[{"name":"75lb","email":"opensource@75lb.com"}],"_nodeVersion":"26.9.0","contributors":[{"url":"http://repejota.com","name":"Raul Perez","email":"repejota@gmail.com"}],"_hasShrinkwrap":false,"devDependencies":{},"peerDependencies":{"@75lb/nature":"latest"},"peerDependenciesMeta":{"@75lb/nature":{"optional":true}},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/byte-size_9.0.2_1792074330799_0.26833748733437424"},"readme":"[![view on npm](https://badgen.net/npm/v/byte-size)](https://www.npmjs.org/package/byte-size)\n[![npm module downloads](https://badgen.net/npm/dt/byte-size)](https://www.npmjs.org/package/byte-size)\n[![Gihub repo dependents](https://badgen.net/github/dependents-repo/75lb/byte-size)](https://github.com/75lb/byte-size/network/dependents?dependent_type=REPOSITORY)\n[![Gihub package dependents](https://badgen.net/github/dependents-pkg/75lb/byte-size)](https://github.com/75lb/byte-size/network/dependents?dependent_type=PACKAGE)\n[![Node.js CI](https://github.com/75lb/byte-size/actions/workflows/node.js.yml/badge.svg)](https://github.com/75lb/byte-size/actions/workflows/node.js.yml)\n\n***Upgraders, please check the [release notes](https://github.com/75lb/byte-size/releases).***\n\n# byte-size\n\nAn isomorphic, load-anywhere function to convert a bytes value (e.g. `3456`) to a human-readable string (`'3.5 kB'`). Choose between [metric or IEC units](https://en.wikipedia.org/wiki/Gigabyte) (summarised below) or specify your own custom units.\n\nValue  | Metric        | Metric (octet) |\n-----  | ------------- | -------------- |\n1000   | kB  kilobyte  | ko  kilooctet  |\n1000^2 | MB  megabyte  | Mo  megaoctet  |\n1000^3 | GB  gigabyte  | Go  gigaoctet  |\n1000^4 | TB  terabyte  | To  teraoctet  |\n1000^5 | PB  petabyte  | Po  petaoctet  |\n1000^6 | EB  exabyte   | Eo  exaoctet   |\n1000^7 | ZB  zettabyte | Zo  zettaoctet |\n1000^8 | YB  yottabyte | Yo  yottaoctet |\n\nValue  | IEC          | IEC (octet)   |\n------ | ------------ | ------------- |\n1024   | KiB kibibyte | Kio kibioctet |\n1024^2 | MiB mebibyte | Mio mebioctet |\n1024^3 | GiB gibibyte | Gio gibioctet |\n1024^4 | TiB tebibyte | Tio tebioctet |\n1024^5 | PiB pebibyte | Pio pebioctet |\n1024^6 | EiB exbibyte | Eio exbioctet |\n1024^7 | ZiB zebibyte | Zio zebioctet |\n1024^8 | YiB yobibyte | Yio yobioctet |\n\n## Synopsis\n\nBy default, `byteSize` converts the input number to a human readable string with metric units and a precision of 1.\n\n```js\n> const byteSize = require('byte-size')\n\n> byteSize(1580)\n{ value: '1.6', unit: 'kB', long: 'kilobytes' }\n```\n\nThe object returned by `byteSize` defines a `toString` method therefore can be used directly in string context.\n\n```js\n> `Filesize: ${byteSize(12400)}`\n'Filesize: 12.4 kB'\n```\n\nOverride the default `toString` behaviour by setting [`options.toStringFn`](#bytesizebytes-options--object-).\n\n```js\n> function toStringFn () {\n  return `**${this.value}${this.unit}**`\n}\n\n> `Filesize: ${byteSize(12400, { toStringFn })}`\n'Filesize: **12.4kB**'\n```\n\nBeside the default of `metric`, there are three other built-in units available: `metric_octet`, `iec` and `iec_octet`.\n\n```js\n> byteSize(1580, { units: 'iec' })\n{ value: '1.5', unit: 'KiB', long: 'kibibytes' }\n\n> byteSize(1580, { units: 'iec_octet' })\n{ value: '1.5', unit: 'Kio', long: 'kibioctets' }\n\n> byteSize(1580, { units: 'metric_octet' })\n{ value: '1.6', unit: 'ko', long: 'kilooctets' }\n```\n\nYou can adjust the `precision`.\n\n```js\n> byteSize(1580, { units: 'iec', precision: 3 })\n{ value: '1.543', unit: 'KiB', long: 'kibibytes' }\n\n> byteSize(1580, { units: 'iec', precision: 0 })\n{ value: '2', unit: 'KiB', long: 'kibibytes' }\n```\n\nDefine custom units by passing an object containing one or more additional conversion tables to `options.customUnits`. In `options.units`, specify the name of a property from the `customUnits` object.\n\n```js\n> const customUnits = {\n  simple: [\n    { from: 0   , to: 1e3 , unit: ''  },\n    { from: 1e3 , to: 1e6 , unit: 'K', long: 'thousand' },\n    { from: 1e6 , to: 1e9 , unit: 'Mn', long: 'million' },\n    { from: 1e9 , to: 1e12, unit: 'Bn', long: 'billion' }\n  ]\n}\n\n> const { value, unit } = byteSize(10000, { customUnits, units: 'simple' })\n\n> `${value}${unit}`\n'10.0K'\n```\n\nOverride the built-in defaults for the duration of the process by passing an options object to `byteSize.defaultOptions()`. This results in cleaner code in cases where `byteSize` is used often with the same options.\n\n```js\n> byteSize.defaultOptions({\n  units: 'simple',\n  precision: 2,\n  customUnits: {\n    simple: [\n      { from: 0, to: 1e3, unit: '' },\n      { from: 1e3, to: 1e6, unit: 'k' },\n      { from: 1e6, to: 1e9, unit: 'm' },\n      { from: 1e9, to: 1e12, unit: 'bn' },\n    ]\n  },\n  toStringFn: function () {\n    return this.value + this.unit\n  }\n})\n\n> [2400, 16400, 3991200].map(byteSize).join(', ')\n'2.40k, 16.40k, 3.99m'\n```\n\n<a name=\"module_byte-size\"></a>\n\n## byte-size\n\n* [byte-size](#module_byte-size)\n    * [byteSize(bytes, [options])](#exp_module_byte-size--byteSize) ⇒ <code>object</code> ⏏\n        * [.defaultOptions(options)](#module_byte-size--byteSize.defaultOptions)\n\n<a name=\"exp_module_byte-size--byteSize\"></a>\n\n### byteSize(bytes, [options]) ⇒ <code>object</code> ⏏\nReturns an object with the spec `{ value: string, unit: string, long: string }`. The returned object defines a `toString` method meaning it can be used in any string context.\n\n**Kind**: Exported function  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| bytes | <code>number</code> | The bytes value to convert. |\n| [options] | <code>object</code> | Optional config. |\n| [options.precision] | <code>number</code> | Number of decimal places. Defaults to `1`. |\n| [options.units] | <code>string</code> | Specify `'metric'`, `'iec'`, `'metric_octet'`, `'iec_octet'` or the name of a property from the custom units table in `options.customUnits`. Defaults to `metric`. |\n| [options.customUnits] | <code>object</code> | An object containing one or more custom unit lookup tables. |\n| [options.toStringFn] | <code>function</code> | A `toString` function to override the default. |\n| [options.locale] | <code>string</code> \\| <code>Array.&lt;string&gt;</code> | *Node >=13 or modern browser only - on earlier platforms this option is ignored*. The locale to use for number formatting (e.g. `'de-DE'`). Defaults to your system locale. Passed directed into [Intl.NumberFormat()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat). |\n\n<a name=\"module_byte-size--byteSize.defaultOptions\"></a>\n\n#### byteSize.defaultOptions(options)\nSet the default `byteSize` options for the duration of the process.\n\n**Kind**: static method of [<code>byteSize</code>](#exp_module_byte-size--byteSize)  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| options | <code>object</code> | A `byteSize` options object. |\n\n\n## Load anywhere\n\nThis library is compatible with Node.js, the Web and any style of module loader. It can be loaded anywhere, natively without transpilation.\n\nNode.js (CommonJS):\n\n```js\nconst byteSize = require('byte-size')\n```\n\nNode.js (ECMAScript Module):\n\n```js\nimport byteSize from 'byte-size'\n```\n\nWithin a modern browser ECMAScript Module:\n\n```js\nimport byteSize from './node_modules/byte-size/index.js'\n```\n\nBrowser global (adds `window.byteSize`):\n\n```html\n<script src=\"./node_modules/byte-size/dist/index.js\"></script>\n```\n\n* * *\n\n&copy; 2014-26 [Lloyd Brookes](https://github.com/75lb) \\<opensource@75lb.com\\>.\n","publish_time":1792074330911,"_cnpm_publish_time":1792074330911,"dist-tags":{"latest":"9.0.2"}}