Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

better-bytes

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

better-bytes - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

27

dist/index.js

@@ -39,2 +39,5 @@ var __defProp = Object.defineProperty;

}
if (typeof data === "number" && !Number.isFinite(data)) {
throw new Error("Data must be finite");
}
if (data < 0) {

@@ -48,13 +51,14 @@ throw new Error("Data must be greater than or equal to 0");

let value = data;
if (typeof value === "bigint") {
const bigIntBase = BigInt(base);
while (value >= bigIntBase && i < units.length - 1) {
value /= bigIntBase;
i++;
while (value >= base && i < units.length - 1) {
if (typeof value === "number" && value > Number.MAX_SAFE_INTEGER) {
value = BigInt(value);
} else if (typeof value === "bigint" && value <= BigInt(Number.MAX_SAFE_INTEGER)) {
value = Number(value);
}
} else {
while (value >= base && i < units.length - 1) {
if (typeof value === "bigint") {
value /= BigInt(base);
} else {
value /= base;
i++;
}
i++;
}

@@ -75,7 +79,7 @@ if (i === 0 || typeof value === "bigint") {

const unit = results?.[4]?.toLowerCase();
if (isNaN(floatValue) || floatValue < 0) {
if (!Number.isFinite(floatValue) || floatValue < 0) {
return null;
}
if (unit === "") {
return floatValue;
return Math.floor(floatValue);
}

@@ -109,2 +113,5 @@ let i = 0;

}
if (typeof result === "number") {
result = Math.floor(result);
}
return result;

@@ -111,0 +118,0 @@ }

{
"name": "better-bytes",
"version": "1.1.0",
"version": "1.2.0",
"description": "Better byte base conversion. Supports two base conversions: kilo binary byte (2^10) and kilobyte (10^3).\n更好的字节进制换算。支持 千位二进制字节(2^10) 和 千字节(10^3) 两种进制换算",

@@ -5,0 +5,0 @@ "author": "CaoMeiYouRen",

@@ -51,3 +51,3 @@ <h1 align="center">better-bytes </h1>

format(1073741824) // '1.00 GiB'
format(1125899906842624n) // '1 PiB'
format(1125899906842624n) // '1.00 PiB'

@@ -74,4 +74,4 @@ format(1572864, { standard: 'kilobinary' }) // '1.50 MiB'

parse('1.123456789012345KiB') // 1150.4197519486413
parse('1.123456789012345KB') // 1123.456789012345
parse('1.123456789012345GiB') // 1206302541
parse('1.123456789012345GB') // 1123456789

@@ -105,3 +105,3 @@ parse('9007199254740991YiB') // 10633823966279325802638835764831453184n

| decimal | `number`|`undefined` | Maximum number of decimal places to include in output. Default: `2`. 输出中包含的最大小数位数。默认值:`2`。 |
| standard | `kilobinary`|`kilo` | base. kilobinary = 2^10 ; kilo = 10^3. Default: `kilobinary`. 进制规范。千位二进制=2^10;千位=10^3。默认值:`kilobinary` |
| standard | `kilobinary`|`kilo` | base. kilobinary = 2^10 ; kilo = 10^3. Default: `kilobinary`. 进制规范。千位二进制=2^10;千位=10^3。默认值:`kilobinary` |
| unitSeparator | `string`|`undefined` | Separator to use between number and unit. Default: `' '`. 用于数字和单位之间的分隔符。默认值:`' '` |

@@ -132,3 +132,3 @@

| --------------- | ---------------------- | ------------------------------------------------------------ |
| forceKilobinary | `boolean`|`undefined` | If true, consider kilo as kilobinary, i.e. using 2 ^ 10 base. 如果为真,则将千位进制视为千位二进制,即使用2^10进制换算。 |
| forceKilobinary | `boolean`|`undefined` | If true, consider kilo as kilobinary, i.e. using 2 ^ 10 base. 如果为真,则将千位进制视为千位二进制,即使用 2^10 进制换算。 |

@@ -139,3 +139,3 @@ **Returns**

| ------- | ------------------------ | ------------------------------------------------------------ |
| results | `number`|`bigint`|`null` | Returns null on error. Otherwise, return the value of number or bigint in bytes. 出错时返回null。否则以字节为单位返回number或bigint的数值。 |
| results | `number`|`bigint`|`null` | Returns null on error. Otherwise, return the value of number or bigint in bytes. 出错时返回 null。否则以字节为单位返回 number 或 bigint 的数值。 |

@@ -142,0 +142,0 @@ ## 🛠️ Development/开发

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc