CoolFace
Apppublic

opusdev/vector-similarity-api

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes
Readme.md153 linesDownload Raw Back to bytes
1# Bytes utility2 3[![NPM Version][npm-image]][npm-url]4[![NPM Downloads][downloads-image]][downloads-url]5[![Build Status][ci-image]][ci-url]6[![Test Coverage][coveralls-image]][coveralls-url]7 8Utility to parse a string bytes (ex: `1TB`) to bytes (`1099511627776`) and vice-versa.9 10## Installation11 12This is a [Node.js](https://nodejs.org/en/) module available through the13[npm registry](https://www.npmjs.com/). Installation is done using the14[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):15 16```bash17$ npm install bytes18```19 20## Usage21 22```js23var bytes = require('bytes');24```25 26#### bytes(number|string value, [options]): number|string|null27 28Default export function. Delegates to either `bytes.format` or `bytes.parse` based on the type of `value`.29 30**Arguments**31 32| Name    | Type     | Description        |33|---------|----------|--------------------|34| value   | `number`|`string` | Number value to format or string value to parse |35| options | `Object` | Conversion options for `format` |36 37**Returns**38 39| Name    | Type             | Description                                     |40|---------|------------------|-------------------------------------------------|41| results | `string`|`number`|`null` | Return null upon error. Numeric value in bytes, or string value otherwise. |42 43**Example**44 45```js46bytes(1024);47// output: '1KB'48 49bytes('1KB');50// output: 102451```52 53#### bytes.format(number value, [options]): string|null54 55Format the given value in bytes into a string. If the value is negative, it is kept as such. If it is a float, it is56 rounded.57 58**Arguments**59 60| Name    | Type     | Description        |61|---------|----------|--------------------|62| value   | `number` | Value in bytes     |63| options | `Object` | Conversion options |64 65**Options**66 67| Property          | Type   | Description                                                                             |68|-------------------|--------|-----------------------------------------------------------------------------------------|69| decimalPlaces | `number`|`null` | Maximum number of decimal places to include in output. Default value to `2`. |70| fixedDecimals | `boolean`|`null` | Whether to always display the maximum number of decimal places. Default value to `false` |71| thousandsSeparator | `string`|`null` | Example of values: `' '`, `','` and `'.'`... Default value to `''`. |72| unit | `string`|`null` | The unit in which the result will be returned (B/KB/MB/GB/TB). Default value to `''` (which means auto detect). |73| unitSeparator | `string`|`null` | Separator to use between number and unit. Default value to `''`. |74 75**Returns**76 77| Name    | Type             | Description                                     |78|---------|------------------|-------------------------------------------------|79| results | `string`|`null` | Return null upon error. String value otherwise. |80 81**Example**82 83```js84bytes.format(1024);85// output: '1KB'86 87bytes.format(1000);88// output: '1000B'89 90bytes.format(1000, {thousandsSeparator: ' '});91// output: '1 000B'92 93bytes.format(1024 * 1.7, {decimalPlaces: 0});94// output: '2KB'95 96bytes.format(1024, {unitSeparator: ' '});97// output: '1 KB'98```99 100#### bytes.parse(string|number value): number|null101 102Parse the string value into an integer in bytes. If no unit is given, or `value`103is a number, it is assumed the value is in bytes.104 105Supported units and abbreviations are as follows and are case-insensitive:106 107  * `b` for bytes108  * `kb` for kilobytes109  * `mb` for megabytes110  * `gb` for gigabytes111  * `tb` for terabytes112  * `pb` for petabytes113 114The units are in powers of two, not ten. This means 1kb = 1024b according to this parser.115 116**Arguments**117 118| Name          | Type   | Description        |119|---------------|--------|--------------------|120| value   | `string`|`number` | String to parse, or number in bytes.   |121 122**Returns**123 124| Name    | Type        | Description             |125|---------|-------------|-------------------------|126| results | `number`|`null` | Return null upon error. Value in bytes otherwise. |127 128**Example**129 130```js131bytes.parse('1KB');132// output: 1024133 134bytes.parse('1024');135// output: 1024136 137bytes.parse(1024);138// output: 1024139```140 141## License142 143[MIT](LICENSE)144 145[ci-image]: https://badgen.net/github/checks/visionmedia/bytes.js/master?label=ci146[ci-url]: https://github.com/visionmedia/bytes.js/actions?query=workflow%3Aci147[coveralls-image]: https://badgen.net/coveralls/c/github/visionmedia/bytes.js/master148[coveralls-url]: https://coveralls.io/r/visionmedia/bytes.js?branch=master149[downloads-image]: https://badgen.net/npm/dm/bytes150[downloads-url]: https://npmjs.org/package/bytes151[npm-image]: https://badgen.net/npm/v/bytes152[npm-url]: https://npmjs.org/package/bytes153