{"_id":"@arihantverma/bytes.js","name":"@arihantverma/bytes.js","dist-tags":{"latest":"3.1.2"},"versions":{"3.1.2":{"name":"@arihantverma/bytes.js","description":"Utility to parse a string bytes to bytes and vice-versa","version":"3.1.2","author":{"name":"TJ Holowaychuk","email":"tj@vision-media.ca","url":"http://tjholowaychuk.com"},"contributors":[{"name":"Jed Watson","email":"jed.watson@me.com"},{"name":"Théo FIDRY","email":"theo.fidry@gmail.com"},{"name":"Arihant Verma","email":"arihantverma1994@gmail.com,arihantverma@proton.me"}],"license":"MIT","keywords":["byte","bytes","utility","parse","parser","convert","converter"],"repository":{"type":"git","url":"git+https://github.com/arihantverma/bytes.js.git"},"devDependencies":{"eslint":"8.41.0","eslint-config-kentcdodds":"^20.5.0","eslint-plugin-markdown":"3.0.0","microbundle":"^0.15.1","mocha":"9.2.0","nyc":"15.1.0"},"engines":{"node":">= 0.8"},"scripts":{"lint":"eslint .","test":"mocha --check-leaks --reporter spec","test-ci":"nyc --reporter=lcov --reporter=text npm test","test-cov":"nyc --reporter=html --reporter=text npm test","build":"microbundle","publish":"npm run build && npm publish --access public"},"type":"module","source":"./index.js","main":"dist/index.cjs","umd:main":"dist/foo.umd.js","module":"dist/foo.js","exports":{"require":"./dist/foo.js","default":"./dist/foo.modern.mjs"},"gitHead":"9ddc13b6c66e0cb293616fba246e05db4b6cef4d","bugs":{"url":"https://github.com/arihantverma/bytes.js/issues"},"homepage":"https://github.com/arihantverma/bytes.js#readme","_id":"@arihantverma/bytes.js@3.1.2","_nodeVersion":"18.14.0","_npmVersion":"9.3.1","dist":{"integrity":"sha512-hFHh/4/ETQdN+EFl2Z9LKQmP9RvcQkyjtGvd4k/QdsTKE2cVtcZmGlOHjhrDB6wGVuyX7YG8FNZAS698zYVntQ==","shasum":"44056a703ce1fb94a778e0178193311890137ff2","tarball":"https://registry.npmjs.org/@arihantverma/bytes.js/-/bytes.js-3.1.2.tgz","fileCount":13,"unpackedSize":40070,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGQi+lENwjeFJJ1c6mO1vTNZmG1gKPMCT2aWP+smxxaRAiEArKcFHmoa9vt6UdlSUuCTYANDYpdaeBi1RSOLbWkITdc="}]},"_npmUser":{"name":"arihantverma","email":"arihantverma@proton.me"},"directories":{},"maintainers":[{"name":"arihantverma","email":"arihantverma@proton.me"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/bytes.js_3.1.2_1684779803647_0.2487328220183167"},"_hasShrinkwrap":false}},"time":{"created":"2023-05-22T18:23:23.581Z","3.1.2":"2023-05-22T18:23:23.827Z","modified":"2023-05-22T18:23:24.008Z"},"maintainers":[{"name":"arihantverma","email":"arihantverma@proton.me"}],"description":"Utility to parse a string bytes to bytes and vice-versa","homepage":"https://github.com/arihantverma/bytes.js#readme","keywords":["byte","bytes","utility","parse","parser","convert","converter"],"repository":{"type":"git","url":"git+https://github.com/arihantverma/bytes.js.git"},"contributors":[{"name":"Jed Watson","email":"jed.watson@me.com"},{"name":"Théo FIDRY","email":"theo.fidry@gmail.com"},{"name":"Arihant Verma","email":"arihantverma1994@gmail.com,arihantverma@proton.me"}],"author":{"name":"TJ Holowaychuk","email":"tj@vision-media.ca","url":"http://tjholowaychuk.com"},"bugs":{"url":"https://github.com/arihantverma/bytes.js/issues"},"license":"MIT","readme":"## Purpose of Existence Of This Fork\n\n1. The purpose of existence of this package/repo is to be able to be consumable as umd and esm modules, since the [author is not interested in suporting those environment](https://github.com/visionmedia/bytes.js/issues/64#issuecomment-1557245891), which is their humble choice.\n2. Intention of this package is to be in sync with the original repo and just give umd and esm modules as outputs along with the original cjs.\n\n> ⚠️ Only PRs related to being in sync with the original repo will be enterntained. If you want to make a functional change, please raise issues and PRs in the original repo.\n\n# Bytes utility\n\n[![NPM Version][npm-image]][npm-url]\n[![NPM Downloads][downloads-image]][downloads-url]\n[![Build Status][ci-image]][ci-url]\n[![Test Coverage][coveralls-image]][coveralls-url]\n\nUtility to parse a string bytes (ex: `1TB`) to bytes (`1099511627776`) and vice-versa.\n\n## Installation\n\nThis is a [Node.js](https://nodejs.org/en/) module available through the\n[npm registry](https://www.npmjs.com/). Installation is done using the\n[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):\n\n```bash\n$ npm install bytes\n```\n\n## Usage\n\n```js\nvar bytes = require(\"bytes\");\n```\n\n#### bytes(number ｜ string value, [options]): number ｜ string ｜ null\n\nDefault export function. Delegates to either `bytes.format` or `bytes.parse` based on the type of `value`.\n\n**Arguments**\n\n| Name    | Type               | Description                                     |\n| ------- | ------------------ | ----------------------------------------------- |\n| value   | `number`｜`string` | Number value to format or string value to parse |\n| options | `Object`           | Conversion options for `format`                 |\n\n**Returns**\n\n| Name    | Type                       | Description                                                                |\n| ------- | -------------------------- | -------------------------------------------------------------------------- |\n| results | `string`｜`number`｜`null` | Return null upon error. Numeric value in bytes, or string value otherwise. |\n\n**Example**\n\n```js\nbytes(1024);\n// output: '1KB'\n\nbytes(\"1KB\");\n// output: 1024\n```\n\n#### bytes.format(number value, [options]): string ｜ null\n\nFormat the given value in bytes into a string. If the value is negative, it is kept as such. If it is a float, it is\nrounded.\n\n**Arguments**\n\n| Name    | Type     | Description        |\n| ------- | -------- | ------------------ |\n| value   | `number` | Value in bytes     |\n| options | `Object` | Conversion options |\n\n**Options**\n\n| Property           | Type              | Description                                                                                                     |\n| ------------------ | ----------------- | --------------------------------------------------------------------------------------------------------------- |\n| decimalPlaces      | `number`｜`null`  | Maximum number of decimal places to include in output. Default value to `2`.                                    |\n| fixedDecimals      | `boolean`｜`null` | Whether to always display the maximum number of decimal places. Default value to `false`                        |\n| thousandsSeparator | `string`｜`null`  | Example of values: `' '`, `','` and `'.'`... Default value to `''`.                                             |\n| unit               | `string`｜`null`  | The unit in which the result will be returned (B/KB/MB/GB/TB). Default value to `''` (which means auto detect). |\n| unitSeparator      | `string`｜`null`  | Separator to use between number and unit. Default value to `''`.                                                |\n\n**Returns**\n\n| Name    | Type             | Description                                     |\n| ------- | ---------------- | ----------------------------------------------- |\n| results | `string`｜`null` | Return null upon error. String value otherwise. |\n\n**Example**\n\n```js\nbytes.format(1024);\n// output: '1KB'\n\nbytes.format(1000);\n// output: '1000B'\n\nbytes.format(1000, { thousandsSeparator: \" \" });\n// output: '1 000B'\n\nbytes.format(1024 * 1.7, { decimalPlaces: 0 });\n// output: '2KB'\n\nbytes.format(1024, { unitSeparator: \" \" });\n// output: '1 KB'\n```\n\n#### bytes.parse(string ｜ number value): number ｜ null\n\nParse the string value into an integer in bytes. If no unit is given, or `value`\nis a number, it is assumed the value is in bytes.\n\nSupported units and abbreviations are as follows and are case-insensitive:\n\n- `b` for bytes\n- `kb` for kilobytes\n- `mb` for megabytes\n- `gb` for gigabytes\n- `tb` for terabytes\n- `pb` for petabytes\n\nThe units are in powers of two, not ten. This means 1kb = 1024b according to this parser.\n\n**Arguments**\n\n| Name  | Type               | Description                          |\n| ----- | ------------------ | ------------------------------------ |\n| value | `string`｜`number` | String to parse, or number in bytes. |\n\n**Returns**\n\n| Name    | Type             | Description                                       |\n| ------- | ---------------- | ------------------------------------------------- |\n| results | `number`｜`null` | Return null upon error. Value in bytes otherwise. |\n\n**Example**\n\n```js\nbytes.parse(\"1KB\");\n// output: 1024\n\nbytes.parse(\"1024\");\n// output: 1024\n\nbytes.parse(1024);\n// output: 1024\n```\n\n## License\n\n[MIT](LICENSE)\n\n[ci-image]: https://badgen.net/github/checks/visionmedia/bytes.js/master?label=ci\n[ci-url]: https://github.com/visionmedia/bytes.js/actions?query=workflow%3Aci\n[coveralls-image]: https://badgen.net/coveralls/c/github/visionmedia/bytes.js/master\n[coveralls-url]: https://coveralls.io/r/visionmedia/bytes.js?branch=master\n[downloads-image]: https://badgen.net/npm/dm/bytes\n[downloads-url]: https://npmjs.org/package/bytes\n[npm-image]: https://badgen.net/npm/v/bytes\n[npm-url]: https://npmjs.org/package/bytes\n","readmeFilename":"README.md"}