bytes-formatter 21.6.12 → 21.6.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -8
- package/index.js +6 -10
- package/package.json +13 -9
package/README.md
CHANGED
|
@@ -1,23 +1,30 @@
|
|
|
1
|
-
# Bytes Formatter [](https://twitter.com/intent/tweet?text=Bytes%20formatter%20module
|
|
2
|
-
[](https://github.com/Datamart/bytes-formatter/actions/workflows/npm-publish.yml) [](https://www.apache.org/licenses/LICENSE-2.0.html) [](https://npmjs.org/package/bytes-formatter) [](https://glize.js.org) [](https://npmjs.org/package/bytes-formatter)
|
|
1
|
+
# Bytes Formatter [](https://twitter.com/intent/tweet?text=Bytes%20formatter%20module.&url=https://github.com/vpodk/bytes-formatter&via=GitHub&hashtags=JavaScript,ECMAScript,ES6)
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
[](https://github.com/vpodk/bytes-formatter/actions/workflows/npm-publish.yml) [](https://www.apache.org/licenses/LICENSE-2.0.html) [](https://npmjs.org/package/bytes-formatter) [](https://npmjs.org/package/bytes-formatter)
|
|
4
|
+
|
|
5
|
+
Bytes formatter module provides a function to format byte values into human-readable strings with appropriate units (bytes, KB, MB, GB, TB, PB).
|
|
5
6
|
|
|
6
7
|
## Usage
|
|
7
8
|
|
|
8
9
|
```bash
|
|
9
|
-
npm install bytes-formatter
|
|
10
|
+
npm install bytes-formatter
|
|
11
|
+
# Or
|
|
12
|
+
yarn add bytes-formatter
|
|
10
13
|
```
|
|
11
14
|
|
|
12
15
|
```js
|
|
13
|
-
import { formatBytes } from
|
|
16
|
+
import { formatBytes } from "bytes-formatter";
|
|
14
17
|
|
|
15
18
|
/**
|
|
16
19
|
* Formats given <code>bytes</code> to human friendly format.
|
|
17
20
|
* @param {number} bytes The bytes to be formatted.
|
|
18
21
|
* @return {string} The formatted bytes as string.
|
|
19
22
|
*/
|
|
20
|
-
console.log(formatBytes(
|
|
23
|
+
console.log(formatBytes(1000)); // "1000 bytes"
|
|
24
|
+
console.log(formatBytes(1024)); // "1.00 KB"
|
|
25
|
+
console.log(formatBytes(1000000)); // "976.56 KB"
|
|
26
|
+
console.log(formatBytes(2000000)); // "1.91 MB"
|
|
27
|
+
console.log(formatBytes(2000000000)); // "1.86 GB"
|
|
28
|
+
console.log(formatBytes(2000000000000)); // "1.82 TB"
|
|
29
|
+
console.log(formatBytes(Number.MAX_SAFE_INTEGER)); // "8.00 PB"
|
|
21
30
|
```
|
|
22
|
-
|
|
23
|
-
For more information please visit [Glize project page](https://glize.js.org).
|
package/index.js
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @fileoverview Bytes formatter module
|
|
2
|
+
* @fileoverview Bytes formatter module
|
|
3
3
|
*
|
|
4
|
-
* @see https://google.github.io/styleguide/
|
|
5
|
-
* @see https://
|
|
6
|
-
* @see https://github.com/Datamart/Glize
|
|
4
|
+
* @see https://google.github.io/styleguide/jsguide.html
|
|
5
|
+
* @see https://google.github.io/styleguide/tsguide.html
|
|
7
6
|
* @module bytes-formatter
|
|
8
7
|
*/
|
|
9
8
|
|
|
10
|
-
|
|
11
9
|
/**
|
|
12
10
|
* @type {!Array<string>}
|
|
13
11
|
* @inner
|
|
14
12
|
*/
|
|
15
|
-
const FORMATS = [
|
|
16
|
-
|
|
13
|
+
const FORMATS = ["bytes", "KB", "MB", "GB", "TB", "PB"];
|
|
14
|
+
|
|
17
15
|
/**
|
|
18
16
|
* Formats given <code>bytes</code> to human friendly format.
|
|
19
17
|
* @param {number} bytes The bytes to be formatted.
|
|
@@ -32,7 +30,5 @@ export const formatBytes = (bytes) => {
|
|
|
32
30
|
++i;
|
|
33
31
|
}
|
|
34
32
|
|
|
35
|
-
return (i ? bytes.toFixed(2) : bytes) +
|
|
33
|
+
return (i ? bytes.toFixed(2) : bytes) + " " + FORMATS[i];
|
|
36
34
|
};
|
|
37
|
-
|
|
38
|
-
|
package/package.json
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bytes-formatter",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "21.6.
|
|
5
|
-
"description": "Bytes formatter module
|
|
6
|
-
"homepage": "https://
|
|
7
|
-
"repository":
|
|
4
|
+
"version": "21.6.15",
|
|
5
|
+
"description": "Bytes formatter module provides a function to format byte values into human-readable strings with appropriate units (bytes, KB, MB, GB, TB, PB).",
|
|
6
|
+
"homepage": "https://vpodk.com/bytes-formatter/",
|
|
7
|
+
"repository": {
|
|
8
|
+
"url": "git+https://github.com/vpodk/bytes-formatter.git"
|
|
9
|
+
},
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/vpodk/bytes-formatter/issues"
|
|
12
|
+
},
|
|
13
|
+
"funding": {
|
|
14
|
+
"url": "https://github.com/sponsors/vpodk"
|
|
15
|
+
},
|
|
8
16
|
"license": "Apache-2.0",
|
|
9
17
|
"main": "./index.js",
|
|
10
18
|
"exports": "./index.js",
|
|
@@ -12,12 +20,9 @@
|
|
|
12
20
|
"scripts": {
|
|
13
21
|
"test": "node ./index.tests.js"
|
|
14
22
|
},
|
|
15
|
-
"bugs": {
|
|
16
|
-
"url": "https://github.com/Datamart/bytes-formatter/issues"
|
|
17
|
-
},
|
|
18
23
|
"author": {
|
|
19
24
|
"name": "Valentin Podkamennyi",
|
|
20
|
-
"email": "
|
|
25
|
+
"email": "vpodk@users.noreply.github.com",
|
|
21
26
|
"url": "https://vpodk.com/"
|
|
22
27
|
},
|
|
23
28
|
"keywords": [
|
|
@@ -25,7 +30,6 @@
|
|
|
25
30
|
"byte-formatter",
|
|
26
31
|
"format-bytes",
|
|
27
32
|
"formatBytes",
|
|
28
|
-
"glize",
|
|
29
33
|
"filesize",
|
|
30
34
|
"pretty-bytes"
|
|
31
35
|
]
|