@naturalcycles/js-lib 15.26.0 → 15.28.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.
@@ -55,7 +55,7 @@ export interface ErrorData {
55
55
  *
56
56
  * Sentry takes string[], but for convenience we allow to pass a singe string.
57
57
  */
58
- fingerprint?: string | string[];
58
+ fingerprint?: string;
59
59
  /**
60
60
  * Set when throwing an error from your backend code, to indicate desired http status code.
61
61
  * e.g throw new AppError('oj', { backendResponseStatusCode: 401 })
@@ -11,16 +11,20 @@ export function _kb(b) {
11
11
  * Byte size to Human byte size string
12
12
  */
13
13
  export function _hb(b = 0) {
14
- if (b < 1024)
14
+ if (b < 100)
15
15
  return `${Math.round(b)} byte(s)`;
16
- if (b < 1024 ** 2)
17
- return `${(b / 1024).toPrecision(3)} Kb`;
18
- if (b < 1024 ** 3)
19
- return `${(b / 1024 ** 2).toPrecision(3)} Mb`;
20
- if (b < 1024 ** 4)
21
- return `${(b / 1024 ** 3).toPrecision(3)} Gb`;
22
- if (b < 1024 ** 5)
23
- return `${(b / 1024 ** 4).toPrecision(3)} Tb`;
16
+ if (b < 1000)
17
+ return `${(b / 1024).toFixed(2)} Kb`;
18
+ if (b < 0.9 * 1024 ** 2)
19
+ return `${Math.round(b / 1024)} Kb`;
20
+ if (b < 0.9 * 1024 ** 3)
21
+ return `${Math.round(b / 1024 ** 2)} Mb`;
22
+ if (b < 0.09 * 1024 ** 4)
23
+ return `${(b / 1024 ** 3).toFixed(2)} Gb`;
24
+ if (b < 0.9 * 1024 ** 4)
25
+ return `${Math.round(b / 1024 ** 3)} Gb`;
26
+ if (b < 0.9 * 1024 ** 5)
27
+ return `${(b / 1024 ** 4).toFixed(2)} Tb`;
24
28
  return `${Math.round(b / 1024 ** 4)} Tb`;
25
29
  }
26
30
  /**
@@ -30,14 +34,14 @@ export function _hb(b = 0) {
30
34
  */
31
35
  export function _hc(c = 0) {
32
36
  if (c < 10 ** 4)
33
- return String(c);
37
+ return String(Math.round(c));
34
38
  if (c < 10 ** 6)
35
- return (c / 10 ** 3).toPrecision(3) + ' K';
39
+ return Math.round(c / 10 ** 3) + ' K';
36
40
  if (c < 10 ** 9)
37
- return (c / 10 ** 6).toPrecision(3) + ' M'; // million
41
+ return Math.round(c / 10 ** 6) + ' M'; // million
38
42
  if (c < 10 ** 12)
39
- return (c / 10 ** 9).toPrecision(3) + ' B'; // billion
43
+ return Math.round(c / 10 ** 9) + ' B'; // billion
40
44
  if (c < 10 ** 15)
41
- return (c / 10 ** 12).toPrecision(3) + ' T'; // trillion
45
+ return Math.round(c / 10 ** 12) + ' T'; // trillion
42
46
  return Math.round(c / 10 ** 12) + ' T';
43
47
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
3
  "type": "module",
4
- "version": "15.26.0",
4
+ "version": "15.28.0",
5
5
  "dependencies": {
6
6
  "tslib": "^2",
7
7
  "zod": "^4"
@@ -63,7 +63,7 @@ export interface ErrorData {
63
63
  *
64
64
  * Sentry takes string[], but for convenience we allow to pass a singe string.
65
65
  */
66
- fingerprint?: string | string[]
66
+ fingerprint?: string
67
67
 
68
68
  /**
69
69
  * Set when throwing an error from your backend code, to indicate desired http status code.
@@ -14,11 +14,13 @@ export function _kb(b: number): number {
14
14
  * Byte size to Human byte size string
15
15
  */
16
16
  export function _hb(b = 0): string {
17
- if (b < 1024) return `${Math.round(b)} byte(s)`
18
- if (b < 1024 ** 2) return `${(b / 1024).toPrecision(3)} Kb`
19
- if (b < 1024 ** 3) return `${(b / 1024 ** 2).toPrecision(3)} Mb`
20
- if (b < 1024 ** 4) return `${(b / 1024 ** 3).toPrecision(3)} Gb`
21
- if (b < 1024 ** 5) return `${(b / 1024 ** 4).toPrecision(3)} Tb`
17
+ if (b < 100) return `${Math.round(b)} byte(s)`
18
+ if (b < 1000) return `${(b / 1024).toFixed(2)} Kb`
19
+ if (b < 0.9 * 1024 ** 2) return `${Math.round(b / 1024)} Kb`
20
+ if (b < 0.9 * 1024 ** 3) return `${Math.round(b / 1024 ** 2)} Mb`
21
+ if (b < 0.09 * 1024 ** 4) return `${(b / 1024 ** 3).toFixed(2)} Gb`
22
+ if (b < 0.9 * 1024 ** 4) return `${Math.round(b / 1024 ** 3)} Gb`
23
+ if (b < 0.9 * 1024 ** 5) return `${(b / 1024 ** 4).toFixed(2)} Tb`
22
24
  return `${Math.round(b / 1024 ** 4)} Tb`
23
25
  }
24
26
 
@@ -28,10 +30,10 @@ export function _hb(b = 0): string {
28
30
  * them more readable.
29
31
  */
30
32
  export function _hc(c = 0): string {
31
- if (c < 10 ** 4) return String(c)
32
- if (c < 10 ** 6) return (c / 10 ** 3).toPrecision(3) + ' K'
33
- if (c < 10 ** 9) return (c / 10 ** 6).toPrecision(3) + ' M' // million
34
- if (c < 10 ** 12) return (c / 10 ** 9).toPrecision(3) + ' B' // billion
35
- if (c < 10 ** 15) return (c / 10 ** 12).toPrecision(3) + ' T' // trillion
33
+ if (c < 10 ** 4) return String(Math.round(c))
34
+ if (c < 10 ** 6) return Math.round(c / 10 ** 3) + ' K'
35
+ if (c < 10 ** 9) return Math.round(c / 10 ** 6) + ' M' // million
36
+ if (c < 10 ** 12) return Math.round(c / 10 ** 9) + ' B' // billion
37
+ if (c < 10 ** 15) return Math.round(c / 10 ** 12) + ' T' // trillion
36
38
  return Math.round(c / 10 ** 12) + ' T'
37
39
  }