@naturalcycles/js-lib 15.28.0 → 15.29.1
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/browser/topbar.js +2 -2
- package/dist/unit/size.util.d.ts +2 -0
- package/dist/unit/size.util.js +51 -21
- package/package.json +1 -2
- package/src/browser/topbar.ts +2 -2
- package/src/unit/size.util.ts +33 -14
- package/cfg/frontend/tsconfig.json +0 -70
package/dist/browser/topbar.js
CHANGED
|
@@ -36,7 +36,7 @@ const repaint = () => {
|
|
|
36
36
|
ctx.shadowColor = options.shadowColor;
|
|
37
37
|
const lineGradient = ctx.createLinearGradient(0, 0, canvas.width, 0);
|
|
38
38
|
for (const stop in options.barColors) {
|
|
39
|
-
// @ts-
|
|
39
|
+
// @ts-expect-error
|
|
40
40
|
lineGradient.addColorStop(stop, options.barColors[stop]);
|
|
41
41
|
}
|
|
42
42
|
ctx.lineWidth = options.barThickness;
|
|
@@ -61,7 +61,7 @@ export const topbar = {
|
|
|
61
61
|
config(opts) {
|
|
62
62
|
for (const key in opts) {
|
|
63
63
|
if (options.hasOwnProperty(key)) {
|
|
64
|
-
// @ts-
|
|
64
|
+
// @ts-expect-error
|
|
65
65
|
options[key] = opts[key];
|
|
66
66
|
}
|
|
67
67
|
}
|
package/dist/unit/size.util.d.ts
CHANGED
|
@@ -9,5 +9,7 @@ export declare function _hb(b?: number): string;
|
|
|
9
9
|
* hc stands for "human count", similar to "human bytes" `_hb` function.
|
|
10
10
|
* Helpful to print big numbers, as it adds `K` (kilo), `M` (mega), etc to make
|
|
11
11
|
* them more readable.
|
|
12
|
+
*
|
|
13
|
+
* Implementation rule of thumb: aim to have up to 3 significant digits, cut the rest.
|
|
12
14
|
*/
|
|
13
15
|
export declare function _hc(c?: number): string;
|
package/dist/unit/size.util.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
+
const kb = 1024;
|
|
2
|
+
const mb = 1024 ** 2;
|
|
3
|
+
const gb = 1024 ** 3;
|
|
4
|
+
const tb = 1024 ** 4;
|
|
1
5
|
export function _gb(b) {
|
|
2
|
-
return Math.round(b /
|
|
6
|
+
return Math.round(b / gb);
|
|
3
7
|
}
|
|
4
8
|
export function _mb(b) {
|
|
5
|
-
return Math.round(b /
|
|
9
|
+
return Math.round(b / mb);
|
|
6
10
|
}
|
|
7
11
|
export function _kb(b) {
|
|
8
|
-
return Math.round(b /
|
|
12
|
+
return Math.round(b / kb);
|
|
9
13
|
}
|
|
10
14
|
/**
|
|
11
15
|
* Byte size to Human byte size string
|
|
@@ -13,35 +17,61 @@ export function _kb(b) {
|
|
|
13
17
|
export function _hb(b = 0) {
|
|
14
18
|
if (b < 100)
|
|
15
19
|
return `${Math.round(b)} byte(s)`;
|
|
16
|
-
if (b <
|
|
17
|
-
return `${(b /
|
|
18
|
-
if (b <
|
|
19
|
-
return `${
|
|
20
|
-
if (b <
|
|
21
|
-
return `${Math.round(b /
|
|
22
|
-
if (b <
|
|
23
|
-
return `${(b /
|
|
24
|
-
if (b <
|
|
25
|
-
return `${
|
|
26
|
-
if (b <
|
|
27
|
-
return `${(b /
|
|
28
|
-
|
|
20
|
+
if (b < 10 ** 4)
|
|
21
|
+
return `${(b / kb).toFixed(2)} Kb`;
|
|
22
|
+
if (b < 10 ** 5)
|
|
23
|
+
return `${(b / kb).toFixed(1)} Kb`;
|
|
24
|
+
if (b < 10 ** 6)
|
|
25
|
+
return `${Math.round(b / kb)} Kb`;
|
|
26
|
+
if (b < 10 ** 7)
|
|
27
|
+
return `${(b / mb).toFixed(2)} Mb`;
|
|
28
|
+
if (b < 10 ** 8)
|
|
29
|
+
return `${(b / mb).toFixed(1)} Mb`;
|
|
30
|
+
if (b < 10 ** 9)
|
|
31
|
+
return `${Math.round(b / mb)} Mb`;
|
|
32
|
+
if (b < 10 ** 10)
|
|
33
|
+
return `${(b / gb).toFixed(2)} Gb`;
|
|
34
|
+
if (b < 10 ** 11)
|
|
35
|
+
return `${(b / gb).toFixed(1)} Gb`;
|
|
36
|
+
if (b < 10 ** 12)
|
|
37
|
+
return `${Math.round(b / gb)} Gb`;
|
|
38
|
+
if (b < 10 ** 13)
|
|
39
|
+
return `${(b / tb).toFixed(2)} Tb`;
|
|
40
|
+
if (b < 10 ** 14)
|
|
41
|
+
return `${(b / tb).toFixed(1)} Tb`;
|
|
42
|
+
return `${Math.round(b / tb)} Tb`;
|
|
29
43
|
}
|
|
30
44
|
/**
|
|
31
45
|
* hc stands for "human count", similar to "human bytes" `_hb` function.
|
|
32
46
|
* Helpful to print big numbers, as it adds `K` (kilo), `M` (mega), etc to make
|
|
33
47
|
* them more readable.
|
|
48
|
+
*
|
|
49
|
+
* Implementation rule of thumb: aim to have up to 3 significant digits, cut the rest.
|
|
34
50
|
*/
|
|
35
51
|
export function _hc(c = 0) {
|
|
36
|
-
if (c < 10 **
|
|
52
|
+
if (c < 10 ** 3)
|
|
37
53
|
return String(Math.round(c));
|
|
54
|
+
if (c < 10 ** 4)
|
|
55
|
+
return (c / 10 ** 3).toFixed(2) + ' K';
|
|
56
|
+
if (c < 10 ** 5)
|
|
57
|
+
return (c / 10 ** 3).toFixed(1) + ' K';
|
|
38
58
|
if (c < 10 ** 6)
|
|
39
59
|
return Math.round(c / 10 ** 3) + ' K';
|
|
60
|
+
if (c < 10 ** 7)
|
|
61
|
+
return (c / 10 ** 6).toFixed(2) + ' M';
|
|
62
|
+
if (c < 10 ** 8)
|
|
63
|
+
return (c / 10 ** 6).toFixed(1) + ' M';
|
|
40
64
|
if (c < 10 ** 9)
|
|
41
|
-
return Math.round(c / 10 ** 6) + ' M';
|
|
65
|
+
return Math.round(c / 10 ** 6) + ' M';
|
|
66
|
+
if (c < 10 ** 10)
|
|
67
|
+
return (c / 10 ** 9).toFixed(2) + ' B';
|
|
68
|
+
if (c < 10 ** 11)
|
|
69
|
+
return (c / 10 ** 9).toFixed(1) + ' B';
|
|
42
70
|
if (c < 10 ** 12)
|
|
43
|
-
return Math.round(c / 10 ** 9) + ' B';
|
|
44
|
-
if (c < 10 **
|
|
45
|
-
return
|
|
71
|
+
return Math.round(c / 10 ** 9) + ' B';
|
|
72
|
+
if (c < 10 ** 13)
|
|
73
|
+
return (c / 10 ** 12).toFixed(2) + ' T';
|
|
74
|
+
if (c < 10 ** 14)
|
|
75
|
+
return (c / 10 ** 12).toFixed(1) + ' T';
|
|
46
76
|
return Math.round(c / 10 ** 12) + ' T';
|
|
47
77
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/js-lib",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "15.
|
|
4
|
+
"version": "15.29.1",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"tslib": "^2",
|
|
7
7
|
"zod": "^4"
|
|
@@ -16,7 +16,6 @@
|
|
|
16
16
|
},
|
|
17
17
|
"exports": {
|
|
18
18
|
".": "./dist/index.js",
|
|
19
|
-
"./cfg/frontend/tsconfig.json": "./cfg/frontend/tsconfig.json",
|
|
20
19
|
"./array": "./dist/array/index.js",
|
|
21
20
|
"./array/*.js": "./dist/array/*.js",
|
|
22
21
|
"./browser": "./dist/browser/index.js",
|
package/src/browser/topbar.ts
CHANGED
|
@@ -57,7 +57,7 @@ const repaint = () => {
|
|
|
57
57
|
|
|
58
58
|
const lineGradient = ctx.createLinearGradient(0, 0, canvas.width, 0)
|
|
59
59
|
for (const stop in options.barColors) {
|
|
60
|
-
// @ts-
|
|
60
|
+
// @ts-expect-error
|
|
61
61
|
lineGradient.addColorStop(stop, options.barColors[stop])
|
|
62
62
|
}
|
|
63
63
|
ctx.lineWidth = options.barThickness
|
|
@@ -83,7 +83,7 @@ export const topbar = {
|
|
|
83
83
|
config(opts: TopBarOptions) {
|
|
84
84
|
for (const key in opts) {
|
|
85
85
|
if (options.hasOwnProperty(key)) {
|
|
86
|
-
// @ts-
|
|
86
|
+
// @ts-expect-error
|
|
87
87
|
options[key] = opts[key]
|
|
88
88
|
}
|
|
89
89
|
}
|
package/src/unit/size.util.ts
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
|
+
const kb = 1024
|
|
2
|
+
const mb = 1024 ** 2
|
|
3
|
+
const gb = 1024 ** 3
|
|
4
|
+
const tb = 1024 ** 4
|
|
5
|
+
|
|
1
6
|
export function _gb(b: number): number {
|
|
2
|
-
return Math.round(b /
|
|
7
|
+
return Math.round(b / gb)
|
|
3
8
|
}
|
|
4
9
|
|
|
5
10
|
export function _mb(b: number): number {
|
|
6
|
-
return Math.round(b /
|
|
11
|
+
return Math.round(b / mb)
|
|
7
12
|
}
|
|
8
13
|
|
|
9
14
|
export function _kb(b: number): number {
|
|
10
|
-
return Math.round(b /
|
|
15
|
+
return Math.round(b / kb)
|
|
11
16
|
}
|
|
12
17
|
|
|
13
18
|
/**
|
|
@@ -15,25 +20,39 @@ export function _kb(b: number): number {
|
|
|
15
20
|
*/
|
|
16
21
|
export function _hb(b = 0): string {
|
|
17
22
|
if (b < 100) return `${Math.round(b)} byte(s)`
|
|
18
|
-
if (b <
|
|
19
|
-
if (b <
|
|
20
|
-
if (b <
|
|
21
|
-
if (b <
|
|
22
|
-
if (b <
|
|
23
|
-
if (b <
|
|
24
|
-
return `${
|
|
23
|
+
if (b < 10 ** 4) return `${(b / kb).toFixed(2)} Kb`
|
|
24
|
+
if (b < 10 ** 5) return `${(b / kb).toFixed(1)} Kb`
|
|
25
|
+
if (b < 10 ** 6) return `${Math.round(b / kb)} Kb`
|
|
26
|
+
if (b < 10 ** 7) return `${(b / mb).toFixed(2)} Mb`
|
|
27
|
+
if (b < 10 ** 8) return `${(b / mb).toFixed(1)} Mb`
|
|
28
|
+
if (b < 10 ** 9) return `${Math.round(b / mb)} Mb`
|
|
29
|
+
if (b < 10 ** 10) return `${(b / gb).toFixed(2)} Gb`
|
|
30
|
+
if (b < 10 ** 11) return `${(b / gb).toFixed(1)} Gb`
|
|
31
|
+
if (b < 10 ** 12) return `${Math.round(b / gb)} Gb`
|
|
32
|
+
if (b < 10 ** 13) return `${(b / tb).toFixed(2)} Tb`
|
|
33
|
+
if (b < 10 ** 14) return `${(b / tb).toFixed(1)} Tb`
|
|
34
|
+
return `${Math.round(b / tb)} Tb`
|
|
25
35
|
}
|
|
26
36
|
|
|
27
37
|
/**
|
|
28
38
|
* hc stands for "human count", similar to "human bytes" `_hb` function.
|
|
29
39
|
* Helpful to print big numbers, as it adds `K` (kilo), `M` (mega), etc to make
|
|
30
40
|
* them more readable.
|
|
41
|
+
*
|
|
42
|
+
* Implementation rule of thumb: aim to have up to 3 significant digits, cut the rest.
|
|
31
43
|
*/
|
|
32
44
|
export function _hc(c = 0): string {
|
|
33
|
-
if (c < 10 **
|
|
45
|
+
if (c < 10 ** 3) return String(Math.round(c))
|
|
46
|
+
if (c < 10 ** 4) return (c / 10 ** 3).toFixed(2) + ' K'
|
|
47
|
+
if (c < 10 ** 5) return (c / 10 ** 3).toFixed(1) + ' K'
|
|
34
48
|
if (c < 10 ** 6) return Math.round(c / 10 ** 3) + ' K'
|
|
35
|
-
if (c < 10 **
|
|
36
|
-
if (c < 10 **
|
|
37
|
-
if (c < 10 **
|
|
49
|
+
if (c < 10 ** 7) return (c / 10 ** 6).toFixed(2) + ' M'
|
|
50
|
+
if (c < 10 ** 8) return (c / 10 ** 6).toFixed(1) + ' M'
|
|
51
|
+
if (c < 10 ** 9) return Math.round(c / 10 ** 6) + ' M'
|
|
52
|
+
if (c < 10 ** 10) return (c / 10 ** 9).toFixed(2) + ' B'
|
|
53
|
+
if (c < 10 ** 11) return (c / 10 ** 9).toFixed(1) + ' B'
|
|
54
|
+
if (c < 10 ** 12) return Math.round(c / 10 ** 9) + ' B'
|
|
55
|
+
if (c < 10 ** 13) return (c / 10 ** 12).toFixed(2) + ' T'
|
|
56
|
+
if (c < 10 ** 14) return (c / 10 ** 12).toFixed(1) + ' T'
|
|
38
57
|
return Math.round(c / 10 ** 12) + ' T'
|
|
39
58
|
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// @naturalcycles/js-lib/cfg/frontend/tsconfig.json
|
|
3
|
-
//
|
|
4
|
-
// Shared tsconfig for Frontend applications
|
|
5
|
-
//
|
|
6
|
-
{
|
|
7
|
-
"compilerOptions": {
|
|
8
|
-
// Target/module
|
|
9
|
-
"target": "es2023", // es2023+ browsers, adjust to your requirements!
|
|
10
|
-
"lib": ["esnext", "dom", "dom.iterable"],
|
|
11
|
-
"module": "esnext",
|
|
12
|
-
"moduleResolution": "bundler",
|
|
13
|
-
"moduleDetection": "force",
|
|
14
|
-
// specifying these explicitly for better IDE compatibility (but they're on by default with module=nodenext)
|
|
15
|
-
"esModuleInterop": true,
|
|
16
|
-
"allowSyntheticDefaultImports": true,
|
|
17
|
-
// Faster compilation in general
|
|
18
|
-
// Support for external compilers (e.g esbuild)
|
|
19
|
-
// Speedup in Jest by using "isolatedModules" in 'ts-jest' config
|
|
20
|
-
"isolatedModules": true,
|
|
21
|
-
|
|
22
|
-
// Emit
|
|
23
|
-
"sourceMap": false,
|
|
24
|
-
"declaration": false,
|
|
25
|
-
// Otherwise since es2022 it defaults to true
|
|
26
|
-
// and starts to produce different/unexpected behavior
|
|
27
|
-
// https://angular.schule/blog/2022-11-use-define-for-class-fields
|
|
28
|
-
"useDefineForClassFields": true,
|
|
29
|
-
"importHelpers": true,
|
|
30
|
-
|
|
31
|
-
// Strictness
|
|
32
|
-
"strict": true,
|
|
33
|
-
"noFallthroughCasesInSwitch": true,
|
|
34
|
-
"forceConsistentCasingInFileNames": true,
|
|
35
|
-
"resolveJsonModule": true,
|
|
36
|
-
"suppressImplicitAnyIndexErrors": false,
|
|
37
|
-
"noUncheckedIndexedAccess": true,
|
|
38
|
-
"noUncheckedSideEffectImports": true,
|
|
39
|
-
"noPropertyAccessFromIndexSignature": true,
|
|
40
|
-
"noImplicitOverride": true,
|
|
41
|
-
|
|
42
|
-
// Enabled should be faster, but will catch less errors
|
|
43
|
-
// "skipLibCheck": true,
|
|
44
|
-
|
|
45
|
-
// Disabled because of https://github.com/Microsoft/TypeScript/issues/29172
|
|
46
|
-
// Need to be specified in the project tsconfig
|
|
47
|
-
// "outDir": "dist",
|
|
48
|
-
// "rootDir": "./src",
|
|
49
|
-
// "baseUrl": "./",
|
|
50
|
-
// "paths": {
|
|
51
|
-
// "@src/*": ["src/*"]
|
|
52
|
-
// },
|
|
53
|
-
// "typeRoots": [
|
|
54
|
-
// "node_modules/@types",
|
|
55
|
-
// "src/@types"
|
|
56
|
-
// ],
|
|
57
|
-
|
|
58
|
-
// Other
|
|
59
|
-
"incremental": true,
|
|
60
|
-
"tsBuildInfoFile": "${configDir}/node_modules/.cache/src.tsbuildinfo",
|
|
61
|
-
"jsx": "preserve",
|
|
62
|
-
"pretty": true,
|
|
63
|
-
"newLine": "lf",
|
|
64
|
-
"experimentalDecorators": true
|
|
65
|
-
// "emitDecoratorMetadata": true // use if needed
|
|
66
|
-
}
|
|
67
|
-
// Need to be specified in the project tsconfig
|
|
68
|
-
// "include": ["src"],
|
|
69
|
-
// "exclude": ["**/__exclude", "**/@linked"]
|
|
70
|
-
}
|