aboutsummaryrefslogtreecommitdiff
path: root/node_modules/bytes
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2018-09-20 02:56:13 +0200
committerFlorian Dold <florian.dold@gmail.com>2018-09-20 02:56:13 +0200
commitbbff7403fbf46f9ad92240ac213df8d30ef31b64 (patch)
treec58400ec5124da1c7d56b01aea83309f80a56c3b /node_modules/bytes
parent003fb34971cf63466184351b4db5f7c67df4f444 (diff)
update packages
Diffstat (limited to 'node_modules/bytes')
-rw-r--r--node_modules/bytes/.npmignore1
-rw-r--r--node_modules/bytes/History.md68
-rw-r--r--node_modules/bytes/Makefile7
-rw-r--r--node_modules/bytes/Readme.md145
-rw-r--r--node_modules/bytes/component.json7
-rw-r--r--node_modules/bytes/index.js174
-rw-r--r--node_modules/bytes/package.json46
7 files changed, 351 insertions, 97 deletions
diff --git a/node_modules/bytes/.npmignore b/node_modules/bytes/.npmignore
deleted file mode 100644
index 9daeafb98..000000000
--- a/node_modules/bytes/.npmignore
+++ /dev/null
@@ -1 +0,0 @@
-test
diff --git a/node_modules/bytes/History.md b/node_modules/bytes/History.md
index b93e41fa0..13d463ab1 100644
--- a/node_modules/bytes/History.md
+++ b/node_modules/bytes/History.md
@@ -1,20 +1,82 @@
+3.0.0 / 2017-08-31
+==================
+
+ * Change "kB" to "KB" in format output
+ * Remove support for Node.js 0.6
+ * Remove support for ComponentJS
+
+2.5.0 / 2017-03-24
+==================
+
+ * Add option "unit"
+
+2.4.0 / 2016-06-01
+==================
+
+ * Add option "unitSeparator"
+
+2.3.0 / 2016-02-15
+==================
+
+ * Drop partial bytes on all parsed units
+ * Fix non-finite numbers to `.format` to return `null`
+ * Fix parsing byte string that looks like hex
+ * perf: hoist regular expressions
+
+2.2.0 / 2015-11-13
+==================
+
+ * add option "decimalPlaces"
+ * add option "fixedDecimals"
+
+2.1.0 / 2015-05-21
+==================
+
+ * add `.format` export
+ * add `.parse` export
+
+2.0.2 / 2015-05-20
+==================
+
+ * remove map recreation
+ * remove unnecessary object construction
+
+2.0.1 / 2015-05-07
+==================
+
+ * fix browserify require
+ * remove node.extend dependency
+
+2.0.0 / 2015-04-12
+==================
+
+ * add option "case"
+ * add option "thousandsSeparator"
+ * return "null" on invalid parse input
+ * support proper round-trip: bytes(bytes(num)) === num
+ * units no longer case sensitive when parsing
+
+1.0.0 / 2014-05-05
+==================
+
+ * add negative support. fixes #6
0.3.0 / 2014-03-19
==================
* added terabyte support
-0.2.1 / 2013-04-01
+0.2.1 / 2013-04-01
==================
* add .component
-0.2.0 / 2012-10-28
+0.2.0 / 2012-10-28
==================
* bytes(200).should.eql('200b')
-0.1.0 / 2012-07-04
+0.1.0 / 2012-07-04
==================
* add bytes to string conversion [yields]
diff --git a/node_modules/bytes/Makefile b/node_modules/bytes/Makefile
deleted file mode 100644
index 8e8640f2e..000000000
--- a/node_modules/bytes/Makefile
+++ /dev/null
@@ -1,7 +0,0 @@
-
-test:
- @./node_modules/.bin/mocha \
- --reporter spec \
- --require should
-
-.PHONY: test \ No newline at end of file
diff --git a/node_modules/bytes/Readme.md b/node_modules/bytes/Readme.md
index 5591b28fb..9b53745d1 100644
--- a/node_modules/bytes/Readme.md
+++ b/node_modules/bytes/Readme.md
@@ -1,54 +1,125 @@
-# node-bytes
+# Bytes utility
- Byte string parser / formatter.
+[![NPM Version][npm-image]][npm-url]
+[![NPM Downloads][downloads-image]][downloads-url]
+[![Build Status][travis-image]][travis-url]
+[![Test Coverage][coveralls-image]][coveralls-url]
-## Example:
+Utility to parse a string bytes (ex: `1TB`) to bytes (`1099511627776`) and vice-versa.
-```js
-bytes('1kb')
-// => 1024
+## Installation
-bytes('2mb')
-// => 2097152
+This is a [Node.js](https://nodejs.org/en/) module available through the
+[npm registry](https://www.npmjs.com/). Installation is done using the
+[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):
-bytes('1gb')
-// => 1073741824
+```bash
+$ npm install bytes
+```
-bytes(1073741824)
-// => 1gb
+## Usage
-bytes(1099511627776)
-// => 1tb
+```js
+var bytes = require('bytes');
```
-## Installation
+#### bytes.format(number value, [options]): string|null
+
+Format 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
+ rounded.
+
+**Arguments**
+
+| Name | Type | Description |
+|---------|----------|--------------------|
+| value | `number` | Value in bytes |
+| options | `Object` | Conversion options |
+
+**Options**
+
+| Property | Type | Description |
+|-------------------|--------|-----------------------------------------------------------------------------------------|
+| decimalPlaces | `number`|`null` | Maximum number of decimal places to include in output. Default value to `2`. |
+| fixedDecimals | `boolean`|`null` | Whether to always display the maximum number of decimal places. Default value to `false` |
+| thousandsSeparator | `string`|`null` | Example of values: `' '`, `','` and `.`... Default value to `''`. |
+| unit | `string`|`null` | The unit in which the result will be returned (B/KB/MB/GB/TB). Default value to `''` (which means auto detect). |
+| unitSeparator | `string`|`null` | Separator to use between number and unit. Default value to `''`. |
+
+**Returns**
+
+| Name | Type | Description |
+|---------|------------------|-------------------------------------------------|
+| results | `string`|`null` | Return null upon error. String value otherwise. |
+
+**Example**
+
+```js
+bytes(1024);
+// output: '1KB'
+
+bytes(1000);
+// output: '1000B'
+
+bytes(1000, {thousandsSeparator: ' '});
+// output: '1 000B'
+
+bytes(1024 * 1.7, {decimalPlaces: 0});
+// output: '2KB'
+
+bytes(1024, {unitSeparator: ' '});
+// output: '1 KB'
-```
-$ npm install bytes
-$ component install visionmedia/bytes.js
```
-## License
+#### bytes.parse(string|number value): number|null
+
+Parse the string value into an integer in bytes. If no unit is given, or `value`
+is a number, it is assumed the value is in bytes.
+
+Supported units and abbreviations are as follows and are case-insensitive:
+
+ * `b` for bytes
+ * `kb` for kilobytes
+ * `mb` for megabytes
+ * `gb` for gigabytes
+ * `tb` for terabytes
+
+The units are in powers of two, not ten. This means 1kb = 1024b according to this parser.
-(The MIT License)
+**Arguments**
-Copyright (c) 2012 TJ Holowaychuk &lt;tj@vision-media.ca&gt;
+| Name | Type | Description |
+|---------------|--------|--------------------|
+| value | `string`|`number` | String to parse, or number in bytes. |
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of this software and associated documentation files (the
-'Software'), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
+**Returns**
+
+| Name | Type | Description |
+|---------|-------------|-------------------------|
+| results | `number`|`null` | Return null upon error. Value in bytes otherwise. |
+
+**Example**
+
+```js
+bytes('1KB');
+// output: 1024
+
+bytes('1024');
+// output: 1024
+
+bytes(1024);
+// output: 1024
+```
+
+## License
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
+[MIT](LICENSE)
-THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
-CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+[downloads-image]: https://img.shields.io/npm/dm/bytes.svg
+[downloads-url]: https://npmjs.org/package/bytes
+[npm-image]: https://img.shields.io/npm/v/bytes.svg
+[npm-url]: https://npmjs.org/package/bytes
+[travis-image]: https://img.shields.io/travis/visionmedia/bytes.js/master.svg
+[travis-url]: https://travis-ci.org/visionmedia/bytes.js
+[coveralls-image]: https://img.shields.io/coveralls/visionmedia/bytes.js/master.svg
+[coveralls-url]: https://coveralls.io/r/visionmedia/bytes.js?branch=master
diff --git a/node_modules/bytes/component.json b/node_modules/bytes/component.json
deleted file mode 100644
index 2929c25d6..000000000
--- a/node_modules/bytes/component.json
+++ /dev/null
@@ -1,7 +0,0 @@
-{
- "name": "bytes",
- "description": "byte size string parser / serializer",
- "keywords": ["bytes", "utility"],
- "version": "0.2.1",
- "scripts": ["index.js"]
-}
diff --git a/node_modules/bytes/index.js b/node_modules/bytes/index.js
index 02bd98f0d..1e39afd1d 100644
--- a/node_modules/bytes/index.js
+++ b/node_modules/bytes/index.js
@@ -1,41 +1,159 @@
+/*!
+ * bytes
+ * Copyright(c) 2012-2014 TJ Holowaychuk
+ * Copyright(c) 2015 Jed Watson
+ * MIT Licensed
+ */
+
+'use strict';
/**
- * Parse byte `size` string.
- *
- * @param {String} size
- * @return {Number}
- * @api public
+ * Module exports.
+ * @public
+ */
+
+module.exports = bytes;
+module.exports.format = format;
+module.exports.parse = parse;
+
+/**
+ * Module variables.
+ * @private
*/
-module.exports = function(size) {
- if ('number' == typeof size) return convert(size);
- var parts = size.match(/^(\d+(?:\.\d+)?) *(kb|mb|gb|tb)$/)
- , n = parseFloat(parts[1])
- , type = parts[2];
+var formatThousandsRegExp = /\B(?=(\d{3})+(?!\d))/g;
- var map = {
- kb: 1 << 10
- , mb: 1 << 20
- , gb: 1 << 30
- , tb: ((1 << 30) * 1024)
- };
+var formatDecimalsRegExp = /(?:\.0*|(\.[^0]+)0+)$/;
- return map[type] * n;
+var map = {
+ b: 1,
+ kb: 1 << 10,
+ mb: 1 << 20,
+ gb: 1 << 30,
+ tb: ((1 << 30) * 1024)
};
+var parseRegExp = /^((-|\+)?(\d+(?:\.\d+)?)) *(kb|mb|gb|tb)$/i;
+
/**
- * convert bytes into string.
+ * Convert the given value in bytes into a string or parse to string to an integer in bytes.
+ *
+ * @param {string|number} value
+ * @param {{
+ * case: [string],
+ * decimalPlaces: [number]
+ * fixedDecimals: [boolean]
+ * thousandsSeparator: [string]
+ * unitSeparator: [string]
+ * }} [options] bytes options.
+ *
+ * @returns {string|number|null}
+ */
+
+function bytes(value, options) {
+ if (typeof value === 'string') {
+ return parse(value);
+ }
+
+ if (typeof value === 'number') {
+ return format(value, options);
+ }
+
+ return null;
+}
+
+/**
+ * Format 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 rounded.
+ *
+ * @param {number} value
+ * @param {object} [options]
+ * @param {number} [options.decimalPlaces=2]
+ * @param {number} [options.fixedDecimals=false]
+ * @param {string} [options.thousandsSeparator=]
+ * @param {string} [options.unit=]
+ * @param {string} [options.unitSeparator=]
*
- * @param {Number} b - bytes to convert
- * @return {String}
- * @api public
+ * @returns {string|null}
+ * @public
*/
-function convert (b) {
- var tb = ((1 << 30) * 1024), gb = 1 << 30, mb = 1 << 20, kb = 1 << 10;
- if (b >= tb) return (Math.round(b / tb * 100) / 100) + 'tb';
- if (b >= gb) return (Math.round(b / gb * 100) / 100) + 'gb';
- if (b >= mb) return (Math.round(b / mb * 100) / 100) + 'mb';
- if (b >= kb) return (Math.round(b / kb * 100) / 100) + 'kb';
- return b + 'b';
+function format(value, options) {
+ if (!Number.isFinite(value)) {
+ return null;
+ }
+
+ var mag = Math.abs(value);
+ var thousandsSeparator = (options && options.thousandsSeparator) || '';
+ var unitSeparator = (options && options.unitSeparator) || '';
+ var decimalPlaces = (options && options.decimalPlaces !== undefined) ? options.decimalPlaces : 2;
+ var fixedDecimals = Boolean(options && options.fixedDecimals);
+ var unit = (options && options.unit) || '';
+
+ if (!unit || !map[unit.toLowerCase()]) {
+ if (mag >= map.tb) {
+ unit = 'TB';
+ } else if (mag >= map.gb) {
+ unit = 'GB';
+ } else if (mag >= map.mb) {
+ unit = 'MB';
+ } else if (mag >= map.kb) {
+ unit = 'KB';
+ } else {
+ unit = 'B';
+ }
+ }
+
+ var val = value / map[unit.toLowerCase()];
+ var str = val.toFixed(decimalPlaces);
+
+ if (!fixedDecimals) {
+ str = str.replace(formatDecimalsRegExp, '$1');
+ }
+
+ if (thousandsSeparator) {
+ str = str.replace(formatThousandsRegExp, thousandsSeparator);
+ }
+
+ return str + unitSeparator + unit;
+}
+
+/**
+ * Parse the string value into an integer in bytes.
+ *
+ * If no unit is given, it is assumed the value is in bytes.
+ *
+ * @param {number|string} val
+ *
+ * @returns {number|null}
+ * @public
+ */
+
+function parse(val) {
+ if (typeof val === 'number' && !isNaN(val)) {
+ return val;
+ }
+
+ if (typeof val !== 'string') {
+ return null;
+ }
+
+ // Test if the string passed is valid
+ var results = parseRegExp.exec(val);
+ var floatValue;
+ var unit = 'b';
+
+ if (!results) {
+ // Nothing could be extracted from the given string
+ floatValue = parseInt(val, 10);
+ unit = 'b'
+ } else {
+ // Retrieve the value and the unit
+ floatValue = parseFloat(results[1]);
+ unit = results[4].toLowerCase();
+ }
+
+ return Math.floor(map[unit] * floatValue);
}
diff --git a/node_modules/bytes/package.json b/node_modules/bytes/package.json
index f2f854e35..219329659 100644
--- a/node_modules/bytes/package.json
+++ b/node_modules/bytes/package.json
@@ -1,21 +1,39 @@
{
"name": "bytes",
+ "description": "Utility to parse a string bytes to bytes and vice-versa",
+ "version": "3.0.0",
"author": "TJ Holowaychuk <tj@vision-media.ca> (http://tjholowaychuk.com)",
- "description": "byte size string parser / serializer",
- "repository": {
- "type": "git",
- "url": "https://github.com/visionmedia/bytes.js.git"
- },
- "version": "0.3.0",
- "main": "index.js",
- "dependencies": {},
+ "contributors": [
+ "Jed Watson <jed.watson@me.com>",
+ "Théo FIDRY <theo.fidry@gmail.com>"
+ ],
+ "license": "MIT",
+ "keywords": [
+ "byte",
+ "bytes",
+ "utility",
+ "parse",
+ "parser",
+ "convert",
+ "converter"
+ ],
+ "repository": "visionmedia/bytes.js",
"devDependencies": {
- "mocha": "*",
- "should": "*"
+ "mocha": "2.5.3",
+ "nyc": "10.3.2"
+ },
+ "files": [
+ "History.md",
+ "LICENSE",
+ "Readme.md",
+ "index.js"
+ ],
+ "engines": {
+ "node": ">= 0.8"
},
- "component": {
- "scripts": {
- "bytes/index.js": "index.js"
- }
+ "scripts": {
+ "test": "mocha --check-leaks --reporter spec",
+ "test-ci": "nyc --reporter=text npm test",
+ "test-cov": "nyc --reporter=html --reporter=text npm test"
}
}