{"id":16556324,"url":"https://github.com/miraclx/xbytes","last_synced_at":"2025-09-17T16:24:23.826Z","repository":{"id":34266521,"uuid":"174065132","full_name":"miraclx/xbytes","owner":"miraclx","description":"Parse bytes to human readable sizes (4747) → ('4.75 KB') and vice versa.","archived":false,"fork":false,"pushed_at":"2024-04-01T12:53:16.000Z","size":154,"stargazers_count":25,"open_issues_count":2,"forks_count":9,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-02T23:40:53.374Z","etag":null,"topics":["binary-bytes","bit","bits","byte","bytes","convert","converter","datasize","decimal-bytes","filesize","human","humanized","iec","iec-80000-13","parser","pretty","readable","size","utility","xbytes"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/miraclx.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-03-06T03:35:24.000Z","updated_at":"2024-09-05T11:06:36.000Z","dependencies_parsed_at":"2024-06-18T15:40:46.288Z","dependency_job_id":null,"html_url":"https://github.com/miraclx/xbytes","commit_stats":{"total_commits":114,"total_committers":6,"mean_commits":19.0,"dds":"0.052631578947368474","last_synced_commit":"75c28d785984220fe49dfff39d14179836c79da0"},"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miraclx%2Fxbytes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miraclx%2Fxbytes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miraclx%2Fxbytes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miraclx%2Fxbytes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/miraclx","download_url":"https://codeload.github.com/miraclx/xbytes/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253176439,"owners_count":21866141,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["binary-bytes","bit","bits","byte","bytes","convert","converter","datasize","decimal-bytes","filesize","human","humanized","iec","iec-80000-13","parser","pretty","readable","size","utility","xbytes"],"created_at":"2024-10-11T20:04:11.560Z","updated_at":"2025-09-17T16:24:18.768Z","avatar_url":"https://github.com/miraclx.png","language":"JavaScript","readme":"# ByteParser (xbytes)\n\n\u003e NodeJS Byte Parser\n\u003e Parse bytes to human readable sizes (4747) → ('4.75 KB') and vice versa.\n\n[![NPM Version][npm-image]][npm-url]\n[![NPM Downloads][downloads-image]][downloads-url]\n\n[![NPM][npm-image-url]][npm-url]\n\n## Installing\n\nVia [NPM][npm]:\n\n``` bash\nnpm install xbytes\n```\n\n## Usage\n\n``` javascript\n// Node CommonJS\nconst xbytes = require('xbytes');\n// Or Node ES6 Modules\nimport xbytes from 'xbytes';\n// Or TypeScript\nimport * as xbytes from 'xbytes';\n```\n\n``` html\n\u003c!-- Or in the Browser --\u003e\n\u003cscript src=\"xbytes/dist/index.js\"\u003e\u003c/script\u003e\n```\n\n## Examples\n\n``` javascript\nxbytes(4747); // '4.75 KB'\nxbytes(-3946); // '-3.95 KB'\nxbytes(34.724e+4); // '347.24 KB'\nxbytes(32000000000); // '32.00 GB'\nxbytes(21474836480, {iec: true}); // '20.00 GiB'\nxbytes.parseSize('10 GB'); // 10000000\nxbytes.parseSize('-50 GiB'); // -53687091200\n```\n\n\u003e *IEC Specification**\n\n``` javascript\nxbytes(5242880, {iec: true}); // '5 MiB'\n\nxbytes.parseSize('10 GiB'); // 10485760\n```\n\n## API\n\n### \u003ca id='fn:xbytes'\u003e\u003c/a\u003e xbytes(byte[, options])\n\n* `byte`: \u0026lt;[number][]\u0026gt;\n* `options`: \u0026lt;[ByteOptions](#byteoptions)\u0026gt;\n* Returns: \u0026lt;[ByteString](#bytestring)\u0026gt;\n\nParse `byte` to human readable size. If `byte` is not a number or an number-like string, return `null` appropriately.\n\n```javascript\nxbytes(2472946)\n// \u003c\u003c '2.47 MB'\nxbytes(49392123904, {iec: true})\n// \u003c\u003c '46.00 GiB'\n```\n\n### \u003ca id='fn:parsesize'\u003e\u003c/a\u003e xbytes.parseSize(str[, config])\n\n* `str`: \u0026lt;[ByteString](#bytestring)\u0026gt;\n* `config`: \u0026lt;[ParseOptions](#parseoptions)\u0026gt;\n* Returns: \u0026lt;[number][]\u0026gt;\n\nParse human readable size to bytes\n\n```javascript\nxbytes.parseSize('15.967 MB')\n// \u003c\u003c 15967000\nxbytes.parseSize('5.97 PiB')\n// \u003c\u003c 6721622443850465\n```\n\n### \u003ca id='fn:parse'\u003e\u003c/a\u003e xbytes.parse(size)\n\n* `str`: \u0026lt;[HybridByte](#hybridbyte)\u0026gt;\n* Returns: \u0026lt;[ByteUnitObject](#byteunitobject)\u0026gt;\n\nCreate a ByteUnitObject around the specified HybridByte\n\n```javascript\nxbytes.parse('10 MiB')\n// \u003c\u003c ByteUnitObject { bytes: 10485760 }\nxbytes.parse('10 MiB').add('20 MiB')\n// \u003c\u003c ByteUnitObject { bytes: 31457280 }\nxbytes.parse('10 MiB').add('20 MiB').toIECBytes()\n// \u003c\u003c '30.00 MiB'\n```\n\n### \u003ca id='fn:isbytes'\u003e\u003c/a\u003e xbytes.isBytes(str)\n\n* `str`: \u0026lt;[string][]\u0026gt;\n* Returns: \u0026lt;[boolean][]\u0026gt;\n\nCheck if the provided string is a [ByteString](#bytestring)\n\n``` javascript\nxbytes.isBytes('10 MiB')\n// \u003c\u003c true\nxbytes.isBytes('Hello')\n// \u003c\u003c false\nxbytes.isBytes('10 iB')\n// \u003c\u003c false\nxbytes.isBytes('10b')\n// \u003c\u003c true\n```\n\n### \u003ca id='fn:isunit'\u003e\u003c/a\u003e xbytes.isUnit(str)\n\n* `str`: \u0026lt;[UnitString](#unitstring)\u0026gt;\n* Returns: \u0026lt;[boolean][]\u0026gt;\n\nCheck if the provided string is an [UnitString](#unitstring)\n\n``` javascript\nxbytes.isUnit('GB')\n// \u003c\u003c true\nxbytes.isUnit('giB')\n// \u003c\u003c true\nxbytes.isUnit('iB')\n// \u003c\u003c false\nxbytes.isUnit('BB')\n// \u003c\u003c false\n```\n\n### \u003ca id='fn:isparsable'\u003e\u003c/a\u003e xbytes.isParsable(input)\n\n* `input`: \u0026lt;[HybridByte](#hybridbyte)\u0026gt;\n* Returns: \u0026lt;[boolean][]\u0026gt;\n\nCheck if the provided argument is parsable _i.e_ raw_bytes ([number]) or [ByteString](#bytestring).\n\n### \u003ca id='fn:relative'\u003e\u003c/a\u003e xbytes.relative(size[, options])\n\n* `size`: \u0026lt;[HybridByte](#hybridbyte)\u0026gt;\n* `options`: \u0026lt;[ByteOptions](#byteoptions)\u0026gt;\n* Returns: \u0026lt;[HybridByteRelations](#hybridbyterelations)\u0026gt;\n\n### \u003ca id='fn:relative:bits'\u003e\u003c/a\u003e xbytes.relative.bits(size[, options])\n\n* `size`: \u0026lt;[HybridByte](#hybridbyte)\u0026gt;\n* `options`: \u0026lt;[ByteOptions](#byteoptions)\u0026gt;\n* Returns: \u0026lt;[ByteString](#Bytestring)\u0026gt;\n\nShow the input size in relation to its `bit` format\n\n### \u003ca id='fn:relative:bytes'\u003e\u003c/a\u003e xbytes.relative.bytes(size[, options])\n\n* `size`: \u0026lt;[HybridByte](#hybridbyte)\u0026gt;\n* `options`: \u0026lt;[ByteOptions](#byteoptions)\u0026gt;\n* Returns: \u0026lt;[ByteString](#Bytestring)\u0026gt;\n\nShow the input size in relation to its `byte` format\n\n### \u003ca id='fn:relative:iecBits'\u003e\u003c/a\u003e xbytes.relative.iecBits(size[, options])\n\n* `size`: \u0026lt;[HybridByte](#hybridbyte)\u0026gt;\n* `options`: \u0026lt;[ByteOptions](#byteoptions)\u0026gt;\n* Returns: \u0026lt;[ByteString](#Bytestring)\u0026gt;\n\nShow the input size in relation to its `bit` format under `IEC Standards`\n\n### \u003ca id='fn:relative:iecBytes'\u003e\u003c/a\u003e xbytes.relative.iecBytes(size[, options])\n\n* `size`: \u0026lt;[HybridByte](#hybridbyte)\u0026gt;\n* `options`: \u0026lt;[ByteOptions](#byteoptions)\u0026gt;\n* Returns: \u0026lt;[ByteString](#Bytestring)\u0026gt;\n\nShow the input size in relation to its `bytes` format under `IEC Standards`\n\n### \u003ca id='fn:relative:size'\u003e\u003c/a\u003e xbytes.relative.size(size[, unit[, options]])\n\n* `size`: \u0026lt;[HybridByte](#hybridbyte)\u0026gt;\n* `unit`: \u0026lt;[UnitString](#unitstring)\u0026gt;\n* `options`: \u0026lt;[ByteOptions](#byteoptions)\u0026gt;\n* Returns: \u0026lt;[ByteString](#bytestring)\u0026gt;\n\n### \u003ca id='fn:parsestring'\u003e\u003c/a\u003e xbytes.parseString(str)\n\n* `str`: \u0026lt;[ByteString](#bytestring)\u0026gt;\n* Returns: \u0026lt;[ParsedByteString](#parsedbytestring)\u0026gt;\n\nParse a human readable byte into its components\n\n### \u003ca id='fn:parsebytes'\u003e\u003c/a\u003e xbytes.parseBytes(str, options)\n\n* `str`: \u0026lt;[HybridByte](#hybridbyte)\u0026gt;\n* `options`: \u0026lt;[ByteOptions](#byteoptions)\u0026gt;\n* Returns: \u0026lt;[ParsedBytes](#parsedbytes)\u0026gt;\n\nParse a human readable byte into its components.\nExtended from [parseString()](#parsestring), but with a few extra properties.\nAnd flexibility to use parse either an integer byte value or a `ByteString` resulting in the same object.\n\n### \u003ca id='fn:extractbytes'\u003e\u003c/a\u003e xbytes.extractBytes(str)\n\n* `str`: \u0026lt;[string][]\u0026gt;\n* Returns: \u0026lt;[ByteString](#bytestring)[]\u0026gt;\n\nExtract all [ByteString](#bytestring)s within a string into an array, alternative to `str.match(xbytes.byteFilter)`\n\n### \u003ca id='fn:createbyteparser'\u003e\u003c/a\u003e xbytes.createByteParser(config)\n\n* `config`: \u0026lt;[ByteOptions](#byteoptions)\u0026gt;\n* Returns: \u0026lt;[ByteParser](#byteparser)\u0026gt;\n\nConstruct a static [ByteParser](#byteparser) with predefined configurations\n\n### \u003ca id='fn:createsizeparser'\u003e\u003c/a\u003e xbytes.createSizeParser(config)\n\n* `config`: \u0026lt;[ParseOptions](#parseoptions)\u0026gt;\n* Returns: \u0026lt;[SizeParser](#sizeparser)\u0026gt;\n\nConstruct a static [SizeParser](#sizeparser) with predefined configurations\n\n### \u003ca id='fn:createrelativesizer'\u003e\u003c/a\u003e xbytes.createRelativeSizer(unit[, config])\n\n* `unit`: \u0026lt;[UnitString](#unitstring)\u0026gt;\n* `config`: \u0026lt;[ByteOptions](#byteoptions)\u0026gt;\n* Returns: \u0026lt;[RelativeSizer](#relativesizer)\u0026gt;\n\nCreate a [RelativeSizer](#relativesizer) for converting a hybrid byte into any set unit under predefined configuration\n\n### \u003ca id='unitmatcher'\u003e\u003c/a\u003e xbytes.unitMatcher: [`RegExp`][regexp]\n\nThe raw Regular expression used in scanning all string byte units.\n\n### \u003ca id='genericmatcher'\u003e\u003c/a\u003e xbytes.genericMatcher: [`RegExp`][regexp]\n\nThe raw regular expression used in scanning all byte containing strings.\n\n### \u003ca id='bytefilter'\u003e\u003c/a\u003e xbytes.byteFilter: [`RegExp`][regexp]\n\nAn regular expression extension of [`genericMatcher`](#genericmatcher) with the 'i' flag.\n\n### \u003ca id='globalbytefilter'\u003e\u003c/a\u003e xbytes.globalByteFilter: [`RegExp`][regexp]\n\nAn regular expression extension of [`genericMatcher`](#genericmatcher) with the 'gi' flags.\n\n### \u003ca id='unitstring'\u003e\u003c/a\u003e UnitString: [`String`][string]\n\n Supported Unit Strings\n\n | Index | Prefix |    Decimal Bits    | Binary Bits ([IEC][]) |    Decimal Bytes    | Binary Bytes ([IEC][]) |\n | :---: | :----: | :----------------: | :-------------------: | :-----------------: | :--------------------: |\n |   0   |   -    | **b (Bits)**       | **b (Bits)**          | **b (Bits)**        | **b (Bits)**           |\n |   0   |   -    | **B (Bytes)**      | **B (Bytes)**         | **B (Bytes)**       | **B (Bytes)**          |\n |   1   |   K    | **Kb (KiloBits)**  | **Kib (KiloBits)**    | **KB (KiloBytes)**  | **KiB (KibiBytes)**    |\n |   2   |   M    | **Mb (MegaBits)**  | **Mib (MebiBits)**    | **MB (MegaBytes)**  | **MiB (MebiBytes)**    |\n |   3   |   G    | **Gb (GigaBits)**  | **Gib (GibiBits)**    | **GB (GigaBytes)**  | **GiB (GibiBytes)**    |\n |   4   |   T    | **Tb (TeraBits)**  | **Tib (TebiBits)**    | **TB (TeraBytes)**  | **TiB (TebiBytes)**    |\n |   5   |   P    | **Pb (PetaBits)**  | **Pib (PebiBits)**    | **PB (PetaBytes)**  | **PiB (PebiBytes)**    |\n |   6   |   E    | **Eb (ExaBits)**   | **Eib (ExbiBits)**    | **EB (ExaBytes)**   | **EiB (ExbiBytes)**    |\n |   7   |   Z    | **Zb (ZettaBits)** | **Zib (ZebiBits)**    | **ZB (ZettaBytes)** | **ZiB (ZebiBytes)**    |\n |   8   |   Y    | **Yb (YottaBits)** | **Yib (YobiBits)**    | **YB (YottaBytes)** | **YiB (YobiBytes)**    |\n\n### \u003ca id='bytestring'\u003e\u003c/a\u003e ByteString: [`String`][string]\n\nA stringed byte representation. The result of a parsed byte value.\n\n* '5 MB'\n* '10 GiB'\n* '0.67 Tb'\n* '-50 KB'\n* '2e+15 KB'\n* '-9e-4 GB'\n\n### \u003ca id='hybridbyte'\u003e\u003c/a\u003e HybridByte: [`Number`][number]|[`ByteString`](#bytestring)\n\nUsed to identify a variable thats either a [ByteString](#bytestring) or a [number][]\n\n* '47 MiB'\n* '50kb'\n* 74753\n* '105'\n\n### \u003ca id='byteoptions'\u003e\u003c/a\u003e ByteOptions: [`Object`][object]\n\n* `iec`: \u0026lt;[boolean][]\u0026gt; Whether or not to parse under the [IEC standard][IEC] i.e in terms of 1024. **Default**: `true`\n* `bits`: \u0026lt;[boolean][]\u0026gt; Whether or not to convert inputed bytes to bits and parse in terms of bits [1 byte = 8 bits]. **Default**: `false`.\n* `fixed`: \u0026lt;[number][]\u0026gt; Number of digits to include after decimal point. **Default**: `2`.\n* `short`: \u0026lt;[boolean][]\u0026gt; Whether or not to shorten unit String [short: 'MB', long: 'MegaBytes']. **Default**: `true`.\n* `space`: \u0026lt;[boolean][]\u0026gt; Whether or not to include a white space inbetween value and unit. **Default**: `true`.\n* `sticky`: \u0026lt;[boolean][]\u0026gt; Whether or not to retain unit on max unit values. e.g `'1024.00 GiB'` instead of `'1.00 TiB'`. **Default**: `false`.\n* `prefixIndex`: \u0026lt;[number][]\u0026gt; The index of unit relativity [See [UnitString](#unitstring)].\n\n### \u003ca id='parseoptions'\u003e\u003c/a\u003e ParseOptions: [`Object`][object]\n\n* `iec`: \u0026lt;[boolean][]\u0026gt; Whether or not to enforce compliance to [IEC standard][IEC]s. **Default**: `true`.\n* `bits`: \u0026lt;[boolean][]\u0026gt; Whether or not to parse a lower case 'b' in bit format. **Default**: `true`.\n\n### \u003ca id='byteparser'\u003e\u003c/a\u003e ByteParser: [`Function`][function]\n\n* `size`: \u0026lt;[number][]\u0026gt;\n* Returns: \u0026lt;[ByteString](#bytestring)\u0026gt;\n\nByte parser with predefined configuration. Result of [`createByteParser`](#fn:createbyteparser).\n\n### \u003ca id='sizeparser'\u003e\u003c/a\u003e SizeParser: [`Function`][function]\n\n* `str`: \u0026lt;[ByteString](#bytestring)[]\u0026gt;\n* Returns: \u0026lt;[number][]\u0026gt;\n\n[ByteString](#bytestring) parser with predefined configuration. Result of [`createSizeParser`](#fn:createsizeparser).\n\n### \u003ca id='relativesizer'\u003e\u003c/a\u003e RelativeSizer: [`Function`][function]\n\n* `size`: \u0026lt;[HybridByte](#hybridbyte)\u0026gt;\n* Returns: \u0026lt;[ByteString](#bytestring)\u0026gt;\n\n[HybridByte](#hybridbyte) parser with predefined configuration. Result of [`createRelativeSizer`](#fn:createrelativesizer).\n\n### \u003ca id='parsedunit'\u003e\u003c/a\u003e ParsedUnit: [`Object`][object]\n\n* `iec`: \u0026lt;[boolean][]\u0026gt; Whether or not the byte is represented under the [IEC standard][IEC] i.e in terms of 1024.\n  * `true` in `'7 TiB'`\n  * `false` in `'3 TB'`\n* `type`: \u0026lt;[string][]\u0026gt; Whether the size is represented as bits(b) or bytes(B).\n  * `'b'` in `'499Yb'`\n  * `'B'` in `'7 MB'`\n* `bits`: \u0026lt;[boolean][]\u0026gt; Whether or not the size is specifically represented as a `bit`.\n  * `true` in `84 Yb`\n  * `false` in `278.58 KB`\n* `bytes`: \u0026lt;[boolean][]\u0026gt; Whether or not the size is specifically represented as a `byte`.\n  * `true` in `92 EB`\n  * `false` in `28 Mb`\n* `unit`: \u0026lt;[UnitString](#unitstring)\u0026gt; Re-parsed UnitString of `inputUnit`, fixing formatting.\n  * `'TB'` if `'TB'`\n  * `'Gib'` if `'gib'`\n* `inputUnit`: \u0026lt;[UnitString](#unitstring)\u0026gt; The unparsed String as was provided.\n  * `'47TB'` in `'47TB'`\n* `prefix`: \u0026lt;[string][]\u0026gt; The prefix of the size string.\n  * `'K'` in `'KB'`\n* `prefixIndex`: \u0026lt;[number][]\u0026gt; The index of the size unit [See [UnitString](#unitstring)].\n  * `3` in `'GB'`\n\n### \u003ca id='parsedbytestring'\u003e\u003c/a\u003e ParsedByteString \u003csub\u003e`extends`\u003c/sub\u003e [ParsedUnit](#parsedunit): [`Object`][object]\n\n* `input`: \u0026lt;[ByteString](#bytestring)\u0026gt; The unparsed String as was provided.\n  * `'47TB'` in `'47TB'`\n* `value`: \u0026lt;[number][]\u0026gt; The value for the size.\n  * `83` in `'83MB'`\n\n### \u003ca id='parsedbytes'\u003e\u003c/a\u003e ParsedBytes \u003csub\u003e`extends`\u003c/sub\u003e [ParsedByteString](#parsedbytestring): [`Object`][object]\n\n* `input`: \u0026lt;[HybridByte](#hybridbyte)\u0026gt; The unparsed String as was provided.\n  * `1024` in `1024`\n  * `'47TB'` in `'47TB'`\n* `size`: \u0026lt;[ByteString](#bytestring)\u0026gt; The value for the size.\n  * `83` in `'83MB'`\n* `bytes`: \u0026lt;[number][]\u0026gt; The value for the size.\n  * `10485760` from `'10 MiB'`\n\n### \u003ca id='byteunitobject'\u003e\u003c/a\u003e class ByteUnitObject\n\n* `bytes`: \u0026lt;[number][]\u0026gt; Internal byte value.\n\nWrap a HybridByte in a chainable, transformative object.\n\n```javascript\nnew ByteUnitObject('10 MiB')\n// \u003c\u003c ByteUnitObject { bytes: 10485760 }\nnew ByteUnitObject('10 MiB').add('20 MiB')\n// \u003c\u003c ByteUnitObject { bytes: 31457280 }\nnew ByteUnitObject('10 MiB').add('20 MiB').toIECBytes()\n// \u003c\u003c '30.00 MiB'\n```\n\n#### ByteUnitObject().add(bytes)\n\n* `bytes`: \u0026lt;[HybridByte](#hybridbyte)|[HybridByte](#hybridbyte)[]\u0026gt; Byte(s) to subract from the root byte.\n* Returns: \u0026lt;[ByteUnitObject](#byteunitobject)\u0026gt;\n\nAdd byte(s) to the internal bytes, resulting in a new [`ByteUnitObject`](#byteunitobject) object with the value\n\n#### ByteUnitObject().subtract(bytes)\n\n* `bytes`: \u0026lt;[HybridByte](#hybridbyte)|[HybridByte](#hybridbyte)[]\u0026gt; Subtract byte(s) from the internal bytes, resulting in a new ByteUnitObject object with the value.\n* Returns: \u0026lt;[ByteUnitObject](#byteunitobject)\u0026gt;\n\nSubtract byte(s) from the internal bytes, resulting in a new [`ByteUnitObject`](#byteunitobject) object with the value\n\n#### ByteUnitObject().multiply(bytes)\n\n* `bytes`: \u0026lt;[HybridByte](#hybridbyte)|[HybridByte](#hybridbyte)[]\u0026gt; Multiply byte(s) with the internal bytes, resulting in a new ByteUnitObject object with the value.\n* Returns: \u0026lt;[ByteUnitObject](#byteunitobject)\u0026gt;\n\nMultiply byte(s) with the internal bytes, resulting in a new [`ByteUnitObject`](#byteunitobject) object with the value\n\n#### ByteUnitObject().divide(bytes)\n\n* `bytes`: \u0026lt;[HybridByte](#hybridbyte)|[HybridByte](#hybridbyte)[]\u0026gt; Byte(s) to divide with.\n* Returns: \u0026lt;[ByteUnitObject](#byteunitobject)\u0026gt;\n\nDivide internal bytes by byte(s) specified, resulting in a new [`ByteUnitObject`](#byteunitobject) object with the value\n\n#### ByteUnitObject().convertTo(unit)\n\n* `unit`: \u0026lt;[UnitString](#unitstring)\u0026gt;\n* Returns: \u0026lt;[ByteString](#bytestring)\u0026gt;\n\nParse the internal byte into any unit, following the relativity.\n\n``` javascript\nnew ByteUnitObject('10 MiB')\n// \u003e\u003e ByteUnitObject { bytes: 10485760 }\nnew ByteUnitObject('10 MiB').convertTo('MB')\n// \u003e\u003e '10.49 MB'\nnew ByteUnitObject('10 MiB').add('50 MB').convertTo('KB')\n    '60485.76 KB'\n```\n\n#### ByteUnitObject().objectify(opts)\n\n* `opts`: \u0026lt;[ByteOptions](#byteoptions)\u0026gt;\n\nParse the internal bytes property to a byte object.\n\n#### ByteUnitObject().checkInternalByteVal(bytes)\n\nMethod to check integrity of internal bytes. Throw if there's an error somewhere.\n\n### \u003ca id='hybridbyterelations'\u003e\u003c/a\u003e HybridByteRelations: [`Object`][object]\n\n* `raw`:\u003ca id='hybridraw'\u003e\u003c/a\u003e \u0026lt;[HybridByte](#hybridbyte)\u0026gt; The unparsed data\n* `bits`: \u0026lt;[ByteString](#bytestring)\u0026gt; A relative bit parsing of the input [HybridByte](#hybridraw)\n* `size`: \u0026lt;[number][]\u0026gt; The numeric byte format of the input [HybridByte](#hybridraw)\n* `bytes`: \u0026lt;[ByteString](#bytestring)\u0026gt; A relative byte parsing of the input [HybridByte](#hybridraw)\n* `iecBits`: \u0026lt;[ByteString](#bytestring)\u0026gt; A relative bit parsing of the input [HybridByte](#hybridraw) under the IEC Specification\n* `parsed`: \u0026lt;[ByteString](#bytestring)\u0026gt; A relative bit parsing of the input [HybridByte](#hybridraw) under the IEC Specification\n* `iecBytes`: \u0026lt;[ByteString](#bytestring)\u0026gt; A relative byte parsing of the input [HybridByte](#hybridraw) under the IEC Specification\n\n## More Examples\n\nCheck out some examples in the `examples` folder\n\n``` javascript\n$ node examples/index.js 'Hey, its 6GB, but my 8 TB flash drive is better'\n┌─────────┬──────────┬───────────┬────────┬───────────┬────────────┬────────────┬─────────────┐\n│ (index) │  parsed  │   size    │  raw   │   bytes   │  iecBytes  │    bits    │   iecBits   │\n├─────────┼──────────┼───────────┼────────┼───────────┼────────────┼────────────┼─────────────┤\n│    0    │ [Object] │ '6.00 GB' │ '6GB'  │ '6.00 GB' │ '5.59 GiB' │ '48.00 Gb' │ '44.70 Gib' │\n│    1    │ [Object] │ '8.00 TB' │ '8 TB' │ '8.00 TB' │ '7.28 TiB' │ '64.00 Tb' │ '58.21 Tib' │\n└─────────┴──────────┴───────────┴────────┴───────────┴────────────┴────────────┴─────────────┘\n$ node examples/parse.js 'The 10GB file was downloaded in 50MB/s'\nThe 10737418240 file was downloaded in 52428800/s\n$ node examples/relative.js mb '10GiB, 1mb 6   gb'\n85899.35 Mb, 1.00 Mb 6000.00 Mb\n$ node examples/random.js 10 // Parse 10 random bytes\n[tabular data]\n$ node examples/extract.js 'Hey, its 6GB, but my 8 TB flash drive is better'\n┌─────────┬────────┬───────────────┐\n│ (index) │  size  │     bytes     │\n├─────────┼────────┼───────────────┤\n│    0    │ '6GB'  │  6000000000   │\n│    1    │ '8 TB' │ 8000000000000 │\n└─────────┴────────┴───────────────┘\n```\n\n## Features\n\n### Compatible with all versions of NodeJS (tested from v1.8.4)\n\n``` bash\n$ nvm exec v1.8.4 node -pe 'require(\".\")(3748587)'\n\"3.75 MB\"\n$ nvm exec v5.12.0 node -pe 'require(\".\").parseSize(\"476 TiB\")'\n523367534821376\n$ nvm exec v11.10.0 node -e '\n  let xbytes = require(\"./dist\");\n  let str = \"My 10GB drive transmits at 250MiB/sec\"\n  console.log(str.replace(xbytes.globalByteFilter, xbytes.relative.bits))\n'\n\"My 80.00 Gb drive transmits at 2.10 Gb/sec\"\n```\n\n### Decimal parsing\n\n``` javascript\nxbytes(524334545.847775856); // 524.33 MB\nxbytes.parseSize('665.284 TiB'); // 731487493773328.4\n\nxbytes(.24283884748955); // 0.24 B\nxbytes.parseSize('.295 MB'); // 295000\n```\n\n### Parse human readable sizes in binary ([IEC][]) format to bytes\n\n``` javascript\nxbytes.parseSize('1 MiB'); // 1048576\n```\n\n### Parse byte values to extended human readable sizes\n\n``` javascript\nxbytes(50000000, {short: false}); // '50.00 MegaBytes'\n```\n\n### Match or extract [ByteString](#bytestring)s in a string\n\n``` javascript\nlet data = 'My 16GB flash drive has a 4GB Zip Archive and a 5MB JavaScript file';\nxbytes.extractBytes(data);\n  //\u003e [ '16GB', '4GB', '5MB' ]\ndata.match(xbytes.globalByteFilter)\n  //\u003e [ '16GB', '4GB', '5MB' ]\ndata.replace(xbytes.globalByteFilter, xbytes.parseSize)\n  //\u003e 'My 16000000000 flash drive has a 4000000000 Zip Archive and a 5000000 JavaScript file'\ndata.replace(xbytes.globalByteFilter, xbytes.createSizeParser({ iec: false }))\n  //\u003e 'My 17179869184 flash drive has a 4294967296 Zip Archive and a 5242880 JavaScript file'\n```\n\n### Decimal and Binary Unit Relativity\n\n``` javascript\nimport { parseSize, relative } from 'xbytes';\n\nrelative('35 TiB').bits // '307.86 Tb'\nrelative('35 TiB').bytes // '38.48 TB'\nrelative('35 TiB').iecBits // '280.00 Tib'\nrelative('35 TiB').iecBytes // '35.00 TiB'\n\nparseSize(relative('35 TiB', {fixed: 20}).bits);\n  //\u003e 38482906972160\nparseSize(relative('35 TiB', {fixed: 20}).bytes);\n  //\u003e 38482906972160\nparseSize(relative('35 TiB', {fixed: 20}).iecBits);\n  //\u003e 38482906972160\nparseSize(relative('35 TiB', {fixed: 20}).iecBytes);\n  //\u003e 38482906972160\n```\n\n## Development\n\n### Building\n\nFeel free to clone, use in adherance to the [license](#license) and perhaps send pull requests\n\n``` bash\ngit clone https://github.com/miraclx/xbytes.git\ncd xbytes\nnpm install\n# hack on code\nnpm run build\nnpm test\n```\n\n### Testing\n\nTests are executed with [Jest][jest]. To use it, simple run `npm install`, it will install\nJest and its dependencies in your project's `node_modules` directory followed by `npm run build` and finally `npm test`.\n\nTo run the tests:\n\n```bash\nnpm install\nnpm run build\nnpm test\n```\n\n## License\n\n[Apache 2.0][license] © **Miraculous Owonubi** ([@miraclx][author-url]) \u0026lt;omiraculous@gmail.com\u0026gt;\n\n[IEC]: https://en.wikipedia.org/wiki/Units_of_information#Systematic_multiples 'International Electrotechnical Commission'\n[npm]:  https://github.com/npm/cli 'The Node Package Manager'\n[jest]:  https://github.com/facebook/jest 'Delightful JavaScript Testing'\n[license]:  LICENSE 'Apache 2.0 License'\n[author-url]: https://github.com/miraclx\n\n[npm-url]: https://npmjs.org/package/xbytes\n[npm-image]: https://badgen.net/npm/node/xbytes\n[npm-image-url]: https://nodei.co/npm/xbytes.png?stars\u0026downloads\n[downloads-url]: https://npmjs.org/package/xbytes\n[downloads-image]: https://badgen.net/npm/dm/xbytes\n\n[number]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type\n[object]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\n[regexp]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp\n[string]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\n[boolean]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type\n[function]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmiraclx%2Fxbytes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmiraclx%2Fxbytes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmiraclx%2Fxbytes/lists"}