@axium/core 0.21.1 → 0.22.0

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/dist/format.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export declare function formatDateRange(date: Date): string;
2
- export declare function formatBytes(bytes: number): string;
2
+ export declare function formatBytes(bytes: bigint): string;
3
3
  declare const _default: {
4
4
  dateRange: typeof formatDateRange;
5
5
  bytes: typeof formatBytes;
package/dist/format.js CHANGED
@@ -7,8 +7,8 @@ export function formatDateRange(date) {
7
7
  }
8
8
  export function formatBytes(bytes) {
9
9
  const units = ['B', 'KB', 'MB', 'GB', 'TB'];
10
- const i = bytes == 0 ? 0 : Math.floor(Math.log10(bytes) / 3);
11
- const value = bytes == 0 ? 0 : bytes / Math.pow(1000, i);
10
+ const i = bytes == 0n ? 0 : Math.floor((bytes.toString(10).length - 1) / 3);
11
+ const value = Number(bytes == 0n ? 0n : bytes / 1000n ** BigInt(i));
12
12
  return `${Number.isInteger(value) ? value : value.toFixed(2)} ${units[i]}`;
13
13
  }
14
14
  export default {
package/dist/parse.d.ts CHANGED
@@ -1 +1 @@
1
- export declare function parseByteSize(input: string): number | null;
1
+ export declare function parseByteSize(input: string): bigint | null;
package/dist/parse.js CHANGED
@@ -4,16 +4,14 @@ export function parseByteSize(input) {
4
4
  const match = byteSizePattern.exec(input.trim());
5
5
  if (!match)
6
6
  return null;
7
- const size = parseFloat(match.groups.size);
8
- if (!Number.isFinite(size))
9
- return null;
7
+ const size = BigInt(match.groups.size);
10
8
  let unit = match.groups.unit.toUpperCase();
11
9
  if (unit.at(-1) == 'B')
12
10
  unit = unit.slice(0, -1);
13
11
  if (unit.at(-1) == 'I')
14
12
  unit = unit.slice(0, -1);
15
- const unitIndex = units.indexOf(unit);
16
- if (unitIndex === -1)
13
+ const unitIndex = BigInt(units.indexOf(unit));
14
+ if (unitIndex === -1n)
17
15
  return null;
18
- return Math.round(size * Math.pow(1024, unitIndex));
16
+ return size * 1024n ** unitIndex;
19
17
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axium/core",
3
- "version": "0.21.1",
3
+ "version": "0.22.0",
4
4
  "author": "James Prevett <axium@jamespre.dev>",
5
5
  "funding": {
6
6
  "type": "individual",