bytes-formatter 21.6.15 → 21.6.17

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.
Files changed (3) hide show
  1. package/README.md +1 -1
  2. package/index.js +7 -1
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Bytes Formatter [![Tweet](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/intent/tweet?text=Bytes%20formatter%20module.&url=https://github.com/vpodk/bytes-formatter&via=GitHub&hashtags=JavaScript,ECMAScript,ES6)
2
2
 
3
- [![Build Status](https://github.com/vpodk/bytes-formatter/actions/workflows/npm-publish.yml/badge.svg)](https://github.com/vpodk/bytes-formatter/actions/workflows/npm-publish.yml) [![License](https://img.shields.io/:license-apache-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0.html) [![NPM version](https://img.shields.io/npm/v/bytes-formatter.svg?style=flat)](https://npmjs.org/package/bytes-formatter) [![NPM downloads](https://img.shields.io/npm/dm/bytes-formatter.svg?style=flat)](https://npmjs.org/package/bytes-formatter)
3
+ [![Build Status](https://github.com/vpodk/bytes-formatter/actions/workflows/npm-publish.yml/badge.svg)](https://github.com/vpodk/bytes-formatter/actions/workflows/npm-publish.yml) [![License](https://img.shields.io/:license-apache-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0.html) [![NPM version](https://img.shields.io/npm/v/bytes-formatter.svg?style=flat)](https://npmjs.org/package/bytes-formatter) [![NPM downloads](https://img.shields.io/npm/dm/bytes-formatter.svg?style=flat)](https://npmjs.org/package/bytes-formatter) ![npms.io](https://img.shields.io/npms-io/maintenance-score/bytes-formatter)
4
4
 
5
5
  Bytes formatter module provides a function to format byte values into human-readable strings with appropriate units (bytes, KB, MB, GB, TB, PB).
6
6
 
package/index.js CHANGED
@@ -20,9 +20,15 @@ const FORMATS = ["bytes", "KB", "MB", "GB", "TB", "PB"];
20
20
  * @example
21
21
  * import {formatBytes} from 'bytes-formatter';
22
22
  * formatBytes(1024);
23
- * //> 1.0 Kb
23
+ * //> 1.00 KB
24
24
  */
25
25
  export const formatBytes = (bytes) => {
26
+ // Handle non-number and non-finite values
27
+ if (typeof bytes !== 'number' || !Number.isFinite(bytes)) return 'NaN';
28
+
29
+ // Handle negative values
30
+ if (bytes < 0) return "-" + formatBytes(-bytes);
31
+
26
32
  let i = 0;
27
33
 
28
34
  while (1023 < bytes) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bytes-formatter",
3
3
  "type": "module",
4
- "version": "21.6.15",
4
+ "version": "21.6.17",
5
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
6
  "homepage": "https://vpodk.com/bytes-formatter/",
7
7
  "repository": {