aboutsummaryrefslogtreecommitdiff
path: root/node_modules/pretty-bytes
diff options
context:
space:
mode:
authorruki <waruqi@gmail.com>2018-11-08 00:38:48 +0800
committerruki <waruqi@gmail.com>2018-11-07 21:53:09 +0800
commit26105034da4fcce7ac883c899d781f016559310d (patch)
treec459a5dc4e3aa0972d9919033ece511ce76dd129 /node_modules/pretty-bytes
parent2c77f00f1a7ecb6c8192f9c16d3b2001b254a107 (diff)
downloadxmake-docs-26105034da4fcce7ac883c899d781f016559310d.tar.gz
xmake-docs-26105034da4fcce7ac883c899d781f016559310d.zip
switch to vuepress
Diffstat (limited to 'node_modules/pretty-bytes')
-rw-r--r--node_modules/pretty-bytes/index.js24
-rw-r--r--node_modules/pretty-bytes/license21
-rw-r--r--node_modules/pretty-bytes/package.json38
-rw-r--r--node_modules/pretty-bytes/readme.md40
4 files changed, 123 insertions, 0 deletions
diff --git a/node_modules/pretty-bytes/index.js b/node_modules/pretty-bytes/index.js
new file mode 100644
index 00000000..cdcec7e6
--- /dev/null
+++ b/node_modules/pretty-bytes/index.js
@@ -0,0 +1,24 @@
+'use strict';
+const UNITS = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
+
+module.exports = num => {
+ if (!Number.isFinite(num)) {
+ throw new TypeError(`Expected a finite number, got ${typeof num}: ${num}`);
+ }
+
+ const neg = num < 0;
+
+ if (neg) {
+ num = -num;
+ }
+
+ if (num < 1) {
+ return (neg ? '-' : '') + num + ' B';
+ }
+
+ const exponent = Math.min(Math.floor(Math.log(num) / Math.log(1000)), UNITS.length - 1);
+ const numStr = Number((num / Math.pow(1000, exponent)).toPrecision(3));
+ const unit = UNITS[exponent];
+
+ return (neg ? '-' : '') + numStr + ' ' + unit;
+};
diff --git a/node_modules/pretty-bytes/license b/node_modules/pretty-bytes/license
new file mode 100644
index 00000000..654d0bfe
--- /dev/null
+++ b/node_modules/pretty-bytes/license
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.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/pretty-bytes/package.json b/node_modules/pretty-bytes/package.json
new file mode 100644
index 00000000..e6b450ea
--- /dev/null
+++ b/node_modules/pretty-bytes/package.json
@@ -0,0 +1,38 @@
+{
+ "name": "pretty-bytes",
+ "version": "4.0.2",
+ "description": "Convert bytes to a human readable string: 1337 → 1.34 kB",
+ "license": "MIT",
+ "repository": "sindresorhus/pretty-bytes",
+ "author": {
+ "name": "Sindre Sorhus",
+ "email": "sindresorhus@gmail.com",
+ "url": "sindresorhus.com"
+ },
+ "engines": {
+ "node": ">=4"
+ },
+ "scripts": {
+ "test": "xo && ava"
+ },
+ "files": [
+ "index.js"
+ ],
+ "keywords": [
+ "pretty",
+ "bytes",
+ "byte",
+ "filesize",
+ "size",
+ "file",
+ "human",
+ "humanized",
+ "readable",
+ "si",
+ "data"
+ ],
+ "devDependencies": {
+ "ava": "*",
+ "xo": "*"
+ }
+}
diff --git a/node_modules/pretty-bytes/readme.md b/node_modules/pretty-bytes/readme.md
new file mode 100644
index 00000000..9bcf73a3
--- /dev/null
+++ b/node_modules/pretty-bytes/readme.md
@@ -0,0 +1,40 @@
+# pretty-bytes [![Build Status](https://travis-ci.org/sindresorhus/pretty-bytes.svg?branch=master)](https://travis-ci.org/sindresorhus/pretty-bytes)
+
+> Convert bytes to a human readable string: `1337` → `1.34 kB`
+
+Useful for displaying file sizes for humans.
+
+-
+
+*Note that it uses base-10 (e.g. kilobyte).
+[Read about the difference between kilobyte and kibibyte.](http://pacoup.com/2009/05/26/kb-kb-kib-whats-up-with-that/)*
+
+
+## Install
+
+```
+$ npm install --save pretty-bytes
+```
+
+
+## Usage
+
+```js
+const prettyBytes = require('pretty-bytes');
+
+prettyBytes(1337);
+//=> '1.34 kB'
+
+prettyBytes(100);
+//=> '100 B'
+```
+
+
+## Related
+
+- [pretty-bytes-cli](https://github.com/sindresorhus/pretty-bytes-cli) - CLI for this module
+
+
+## License
+
+MIT © [Sindre Sorhus](https://sindresorhus.com)