{"name":"byte-size","author":{"name":"Lloyd Brookes","email":"75pound@gmail.com"},"version":"8.0.0","description":"Convert a bytes or octets value (e.g. 34565346) to a human-readable string ('34.6 MB'). Choose between metric or IEC units.","repository":{"type":"git","url":"git+https://github.com/75lb/byte-size.git"},"exports":{"import":"./index.mjs","require":"./dist/index.cjs"},"license":"MIT","engines":{"node":">=14"},"keywords":["convert","bytes","octet","size","human","readable","metric","IEC"],"scripts":{"test":"npm run dist && npm run test:esm && npm run test:web","test:esm":"test-runner --view.hide-skips test.mjs","test:web":"web-runner test.mjs","docs":"jsdoc2md -c jsdoc.conf -t README.hbs index.mjs > README.md","cover":"c8 npm test && c8 report --reporter=text-lcov | coveralls","dist":"rollup -c"},"devDependencies":{"@rollup/plugin-node-resolve":"^13.0.0","@test-runner/web":"^0.4.1","coveralls":"^3.1.1","isomorphic-assert":"^0.2.0","jsdoc-to-markdown":"^7.0.1","rollup":"^2.52.7","test-runner":"^0.9.6"},"standard":{"ignore":["dist"]},"contributors":[{"name":"Raul Perez","email":"repejota@gmail.com","url":"http://repejota.com"}],"gitHead":"712a890413f09a4170edf372d5a8173bfb413562","bugs":{"url":"https://github.com/75lb/byte-size/issues"},"homepage":"https://github.com/75lb/byte-size#readme","_id":"byte-size@8.0.0","_nodeVersion":"16.4.1","_npmVersion":"7.19.1","dist":{"integrity":"sha512-W9nozFNCma06nuwM+s/r3gP3sX3++QQm8qNQf3Gch2In1vZpDNpT3lEg73i18H1E9d0750/HXP52n/gbg8DNZw==","shasum":"2b3a1679b26326a15918a64c59bc35e56439cabd","tarball":"http://registry-npm.ywwl.com/byte-size/download/byte-size-8.0.0.tgz","fileCount":7,"unpackedSize":32123,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJg4bXFCRA9TVsSAnZWagAAtykP/0broPLb6QVsHF9jH+jN\nARJL8ruaGGtCqCJgMOOtF6uZ+P1yu7dHM7V5fZWXMtTWx2aYeqp3PGrFaKwc\nihU1k1Yqw8aEIgxFmOxKLir283BRj5xFGuXznS5VWc1FVPVZbkqr9/eePqaB\nkKLNpvobKyCLFPAAVx6ftnfpsqHkbvthSo1xCaLKTxF48ePgL5zdXZvxmnxC\nQnc4lsJ5aTva2jxk9K7DG8h0vntIOp6sb4yvMmd+r/6e2JMzBRu/o1drguFx\niH855he3a3FOyLyrBsw6RrGpjtE+vM2X4YF5Jncbp5Faha9N2cfNwT+/Dxmu\ni28eOn2KbyvOGWCI8ErmOSA5X5+EP7d816iRCZfmLu0YHrcM+JexOMuwXrGW\nzRo9P88KXBBsAonIbK8qFJdPSBTYr0uSZKnieCImJ8mlMiRCGsIwg175Jwo4\nqF73kbuUDDp79MVdxK61/zRT1BjPn4BB57/7irZ4iMcW97piadLGpUtN1QMP\nlRIIGT0gMULjuk0lZ7da+90P/L39wH5maYohOvsLJASlVOSRpQqcsKhie5RG\nrp4sUmWdMMv1fmJsUB+5B9mJgrRwPQdN/DPcImLfwkvhSoc7tRTQHEREtR4z\nKS/4XPFnfFTA8y8ldMgMfJ1LrX8R5vg3cuKv4rvjRmABjiMcEF2VEy+Nllpt\nS3f+\r\n=NsuE\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHUXVbERj7z/7CEkdh+ThGAncqkxnomrD9AdqBaREnDBAiEA3FSmqoFzziBLNaARtIOpAyfGsXBJI60TmJAOut2450I="}],"size":5905,"noattachment":false,"key":"/byte-size/-/byte-size-8.0.0.tgz"},"_npmUser":{"name":"75lb","email":"75pound@gmail.com"},"directories":{},"maintainers":[{"name":"75lb","email":"75pound@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/byte-size_8.0.0_1625404868885_0.7858206131589511"},"_hasShrinkwrap":false,"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[![Coverage Status](https://coveralls.io/repos/github/75lb/byte-size/badge.svg)](https://coveralls.io/github/75lb/byte-size)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](https://github.com/feross/standard)\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-23 [Lloyd Brookes](https://github.com/75lb) \\<75pound@gmail.com\\>.\n\nTested by [test-runner](https://github.com/test-runner-js/test-runner). Documented by [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown).\n","publish_time":1625404869018,"_cnpm_publish_time":1625404869018,"dist-tags":{"latest":"9.0.2"}}