diff options
author | Kat Marchán <kzm@sykosomatic.org> | 2018-03-15 12:05:34 +0300 |
---|---|---|
committer | Rebecca Turner <me@re-becca.org> | 2018-03-23 12:08:56 +0300 |
commit | 23b4a4fac0fbfe8e03e2f65d9f674f163643d15d (patch) | |
tree | cd7290f516591bed2f611541e739d4461210e42e /node_modules/byte-size | |
parent | 9a5807c4f813c49b854170b6111c099b3054faa2 (diff) |
byte-size@4.0.2
PR-URL: https://github.com/npm/npm/pull/19910
Credit: @zkat
Reviewed-By: @iarna
Diffstat (limited to 'node_modules/byte-size')
-rw-r--r-- | node_modules/byte-size/LICENSE | 21 | ||||
-rw-r--r-- | node_modules/byte-size/README.hbs | 12 | ||||
-rw-r--r-- | node_modules/byte-size/README.md | 105 | ||||
-rw-r--r-- | node_modules/byte-size/index.js | 144 | ||||
-rw-r--r-- | node_modules/byte-size/package.json | 74 |
5 files changed, 356 insertions, 0 deletions
diff --git a/node_modules/byte-size/LICENSE b/node_modules/byte-size/LICENSE new file mode 100644 index 000000000..94d0234e5 --- /dev/null +++ b/node_modules/byte-size/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2014-17 Lloyd Brookes <75pound@gmail.com> + +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: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +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. diff --git a/node_modules/byte-size/README.hbs b/node_modules/byte-size/README.hbs new file mode 100644 index 000000000..3077e5e0c --- /dev/null +++ b/node_modules/byte-size/README.hbs @@ -0,0 +1,12 @@ +[![view on npm](https://img.shields.io/npm/v/byte-size.svg)](https://www.npmjs.org/package/byte-size) +[![npm module downloads](https://img.shields.io/npm/dt/byte-size.svg)](https://www.npmjs.org/package/byte-size) +[![Build Status](https://travis-ci.org/75lb/byte-size.svg?branch=master)](https://travis-ci.org/75lb/byte-size) +[![Coverage Status](https://coveralls.io/repos/github/75lb/byte-size/badge.svg?branch=master)](https://coveralls.io/github/75lb/byte-size?branch=master) +[![Dependency Status](https://david-dm.org/75lb/byte-size.svg)](https://david-dm.org/75lb/byte-size) +[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](https://github.com/feross/standard) + +{{>main}} + +* * * + +© 2014-17 Lloyd Brookes \<75pound@gmail.com\>. Documented by [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown). diff --git a/node_modules/byte-size/README.md b/node_modules/byte-size/README.md new file mode 100644 index 000000000..0b749e171 --- /dev/null +++ b/node_modules/byte-size/README.md @@ -0,0 +1,105 @@ +[![view on npm](https://img.shields.io/npm/v/byte-size.svg)](https://www.npmjs.org/package/byte-size) +[![npm module downloads](https://img.shields.io/npm/dt/byte-size.svg)](https://www.npmjs.org/package/byte-size) +[![Build Status](https://travis-ci.org/75lb/byte-size.svg?branch=master)](https://travis-ci.org/75lb/byte-size) +[![Coverage Status](https://coveralls.io/repos/github/75lb/byte-size/badge.svg?branch=master)](https://coveralls.io/github/75lb/byte-size?branch=master) +[![Dependency Status](https://david-dm.org/75lb/byte-size.svg)](https://david-dm.org/75lb/byte-size) +[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](https://github.com/feross/standard) + +<a name="module_byte-size"></a> + +## byte-size +Convert a bytes value to a more human-readable format. Choose between [metric or IEC units](https://en.wikipedia.org/wiki/Gigabyte), summarised below. + +Value | Metric +----- | ------------- +1000 | kB kilobyte +1000^2 | MB megabyte +1000^3 | GB gigabyte +1000^4 | TB terabyte +1000^5 | PB petabyte +1000^6 | EB exabyte +1000^7 | ZB zettabyte +1000^8 | YB yottabyte + +Value | IEC +----- | ------------ +1024 | KiB kibibyte +1024^2 | MiB mebibyte +1024^3 | GiB gibibyte +1024^4 | TiB tebibyte +1024^5 | PiB pebibyte +1024^6 | EiB exbibyte +1024^7 | ZiB zebibyte +1024^8 | YiB yobibyte + +Value | Metric (octet) +----- | ------------- +1000 | ko kilooctet +1000^2 | Mo megaoctet +1000^3 | Go gigaoctet +1000^4 | To teraoctet +1000^5 | Po petaoctet +1000^6 | Eo exaoctet +1000^7 | Zo zettaoctet +1000^8 | Yo yottaoctet + +Value | IEC (octet) +----- | ------------ +1024 | Kio kilooctet +1024^2 | Mio mebioctet +1024^3 | Gio gibioctet +1024^4 | Tio tebioctet +1024^5 | Pio pebioctet +1024^6 | Eio exbioctet +1024^7 | Zio zebioctet +1024^8 | Yio yobioctet + +**Example** +```js +const byteSize = require('byte-size') +``` +<a name="exp_module_byte-size--byteSize"></a> + +### byteSize(bytes, [options]) ⇒ <code>Object</code> ⏏ +**Kind**: Exported function + +| Param | Type | Default | Description | +| --- | --- | --- | --- | +| bytes | <code>number</code> | | the bytes value to convert. | +| [options] | <code>object</code> | | optional config. | +| [options.precision] | <code>number</code> | <code>1</code> | number of decimal places. | +| [options.units] | <code>string</code> | <code>"metric"</code> | select `'metric'`, `'iec'`, `'metric_octet'` or `'iec_octet'` units. | + +**Example** +```js +> const byteSize = require('byte-size') + +> byteSize(1580) +{ value: '1.6', unit: 'kB' } + +> byteSize(1580, { units: 'iec' }) +{ value: '1.5', unit: 'KiB' } + +> byteSize(1580, { units: 'iec', precision: 3 }) +{ value: '1.543', unit: 'KiB' } + +> byteSize(1580, { units: 'iec', precision: 0 }) +{ value: '2', unit: 'KiB' } + +> byteSize(1580, { units: 'metric_octet' }) +{ value: '1.6', unit: 'ko' } + +> byteSize(1580, { units: 'iec_octet' }) +{ value: '1.5', unit: 'Kio' } + +> byteSize(1580, { units: 'iec_octet' }).toString() +'1.5 Kio' + +> const { value, unit } = byteSize(1580, { units: 'iec_octet' }) +> `${value} ${unit}` +'1.5 Kio' +``` + +* * * + +© 2014-17 Lloyd Brookes \<75pound@gmail.com\>. Documented by [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown). diff --git a/node_modules/byte-size/index.js b/node_modules/byte-size/index.js new file mode 100644 index 000000000..c192e9520 --- /dev/null +++ b/node_modules/byte-size/index.js @@ -0,0 +1,144 @@ +'use strict' + +/** + * Convert a bytes value to a more human-readable format. Choose between [metric or IEC units](https://en.wikipedia.org/wiki/Gigabyte), summarised below. + * + * Value | Metric + * ----- | ------------- + * 1000 | kB kilobyte + * 1000^2 | MB megabyte + * 1000^3 | GB gigabyte + * 1000^4 | TB terabyte + * 1000^5 | PB petabyte + * 1000^6 | EB exabyte + * 1000^7 | ZB zettabyte + * 1000^8 | YB yottabyte + * + * Value | IEC + * ----- | ------------ + * 1024 | KiB kibibyte + * 1024^2 | MiB mebibyte + * 1024^3 | GiB gibibyte + * 1024^4 | TiB tebibyte + * 1024^5 | PiB pebibyte + * 1024^6 | EiB exbibyte + * 1024^7 | ZiB zebibyte + * 1024^8 | YiB yobibyte + * + * Value | Metric (octet) + * ----- | ------------- + * 1000 | ko kilooctet + * 1000^2 | Mo megaoctet + * 1000^3 | Go gigaoctet + * 1000^4 | To teraoctet + * 1000^5 | Po petaoctet + * 1000^6 | Eo exaoctet + * 1000^7 | Zo zettaoctet + * 1000^8 | Yo yottaoctet + * + * Value | IEC (octet) + * ----- | ------------ + * 1024 | Kio kilooctet + * 1024^2 | Mio mebioctet + * 1024^3 | Gio gibioctet + * 1024^4 | Tio tebioctet + * 1024^5 | Pio pebioctet + * 1024^6 | Eio exbioctet + * 1024^7 | Zio zebioctet + * 1024^8 | Yio yobioctet + * + * @module byte-size + * @example + * ```js + * const byteSize = require('byte-size') + * ``` + */ +module.exports = byteSize + +class ByteSize { + constructor (bytes, options) { + options = options || {} + options.units = options.units || 'metric' + options.precision = typeof options.precision === 'undefined' ? 1 : options.precision + + var table = [ + { expFrom: 0, expTo: 1, metric: 'B', iec: 'B', metric_octet: 'o', iec_octet: 'o' }, + { expFrom: 1, expTo: 2, metric: 'kB', iec: 'KiB', metric_octet: 'ko', iec_octet: 'Kio' }, + { expFrom: 2, expTo: 3, metric: 'MB', iec: 'MiB', metric_octet: 'Mo', iec_octet: 'Mio' }, + { expFrom: 3, expTo: 4, metric: 'GB', iec: 'GiB', metric_octet: 'Go', iec_octet: 'Gio' }, + { expFrom: 4, expTo: 5, metric: 'TB', iec: 'TiB', metric_octet: 'To', iec_octet: 'Tio' }, + { expFrom: 5, expTo: 6, metric: 'PB', iec: 'PiB', metric_octet: 'Po', iec_octet: 'Pio' }, + { expFrom: 6, expTo: 7, metric: 'EB', iec: 'EiB', metric_octet: 'Eo', iec_octet: 'Eio' }, + { expFrom: 7, expTo: 8, metric: 'ZB', iec: 'ZiB', metric_octet: 'Zo', iec_octet: 'Zio' }, + { expFrom: 8, expTo: 9, metric: 'YB', iec: 'YiB', metric_octet: 'Yo', iec_octet: 'Yio' } + ] + + var base = options.units === 'metric' || options.units === 'metric_octet' ? 1000 : 1024 + + for (var i = 0; i < table.length; i++) { + var lower = Math.pow(base, table[i].expFrom) + var upper = Math.pow(base, table[i].expTo) + if (bytes >= lower && bytes < upper) { + var units = table[i][options.units] + if (i === 0) { + this.value = String(bytes) + this.unit = units + return //{ value: String(bytes), unit: units } + } else { + this.value = (bytes / lower).toFixed(options.precision) + this.unit = units + return //{ value: (bytes / lower).toFixed(options.precision), unit: units } + } + } + } + + // return { value: String(bytes), unit: '' } + this.value = String(bytes) + this.unit = '' + } + + toString () { + return `${this.value} ${this.unit}`.trim() + } +} + +/** + * @param {number} - the bytes value to convert. + * @param [options] {object} - optional config. + * @param [options.precision=1] {number} - number of decimal places. + * @param [options.units=metric] {string} - select `'metric'`, `'iec'`, `'metric_octet'` or `'iec_octet'` units. + * @returns {{ value: string, unit: string}} + * @alias module:byte-size + * @example + * ```js + * > const byteSize = require('byte-size') + * + * > byteSize(1580) + * { value: '1.6', unit: 'kB' } + * + * > byteSize(1580, { units: 'iec' }) + * { value: '1.5', unit: 'KiB' } + * + * > byteSize(1580, { units: 'iec', precision: 3 }) + * { value: '1.543', unit: 'KiB' } + * + * > byteSize(1580, { units: 'iec', precision: 0 }) + * { value: '2', unit: 'KiB' } + * + * > byteSize(1580, { units: 'metric_octet' }) + * { value: '1.6', unit: 'ko' } + * + * > byteSize(1580, { units: 'iec_octet' }) + * { value: '1.5', unit: 'Kio' } + * + * > byteSize(1580, { units: 'iec_octet' }).toString() + * '1.5 Kio' + * + * > const { value, unit } = byteSize(1580, { units: 'iec_octet' }) + * > `${value} ${unit}` + * '1.5 Kio' + * ``` + */ +function byteSize (bytes, options) { + return new ByteSize(bytes, options) +} diff --git a/node_modules/byte-size/package.json b/node_modules/byte-size/package.json new file mode 100644 index 000000000..1c2d306de --- /dev/null +++ b/node_modules/byte-size/package.json @@ -0,0 +1,74 @@ +{ + "_from": "byte-size", + "_id": "byte-size@4.0.2", + "_inBundle": false, + "_integrity": "sha512-UGCQ0L1CO27M/9DOjS9ygrXz7CwHc3uVbNc1xbOGVL8RQO/8rJYCZclylAMcq4jQ0laO1izyomNZe1MFZsatlw==", + "_location": "/byte-size", + "_phantomChildren": {}, + "_requested": { + "type": "tag", + "registry": true, + "raw": "byte-size", + "name": "byte-size", + "escapedName": "byte-size", + "rawSpec": "", + "saveSpec": null, + "fetchSpec": "latest" + }, + "_requiredBy": [ + "#USER", + "/" + ], + "_resolved": "https://registry.npmjs.org/byte-size/-/byte-size-4.0.2.tgz", + "_shasum": "e8ddbf7161913965c6af5b236a4bed8896bdc83e", + "_spec": "byte-size", + "_where": "/Users/zkat/Documents/code/npm", + "author": { + "name": "Lloyd Brookes", + "email": "75pound@gmail.com" + }, + "bugs": { + "url": "https://github.com/75lb/byte-size/issues" + }, + "bundleDependencies": false, + "contributors": [ + { + "name": "Raul Perez", + "email": "repejota@gmail.com", + "url": "http://repejota.com" + } + ], + "deprecated": false, + "description": "Convert a bytes (and octets) value to a more human-readable format. Choose between metric or IEC units.", + "devDependencies": { + "coveralls": "^2.13.1", + "jsdoc-to-markdown": "^3.0.0", + "test-runner": "^0.4.0" + }, + "files": [ + "index.js" + ], + "homepage": "https://github.com/75lb/byte-size#readme", + "keywords": [ + "convert", + "bytes", + "octet", + "size", + "human", + "readable", + "metric", + "IEC" + ], + "license": "MIT", + "name": "byte-size", + "repository": { + "type": "git", + "url": "git+https://github.com/75lb/byte-size.git" + }, + "scripts": { + "cover": "istanbul cover ./node_modules/.bin/test-runner test.js && cat coverage/lcov.info | ./node_modules/.bin/coveralls", + "docs": "jsdoc2md -t README.hbs index.js > README.md; echo", + "test": "test-runner test.js" + }, + "version": "4.0.2" +} |