namirasoft-core 1.4.80 → 1.4.81
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/ByteOperation.d.ts +12 -0
- package/dist/ByteOperation.js +57 -0
- package/dist/ByteOperation.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/ByteOperation.ts +58 -0
- package/src/index.ts +1 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare enum ByteUnit {
|
|
2
|
+
B = "B",
|
|
3
|
+
KB = "KB",
|
|
4
|
+
MB = "MB",
|
|
5
|
+
GB = "GB",
|
|
6
|
+
TB = "TB",
|
|
7
|
+
PB = "PB"
|
|
8
|
+
}
|
|
9
|
+
export declare class ByteOperation {
|
|
10
|
+
static format(value: number, unit: ByteUnit): string;
|
|
11
|
+
static convert(value: number, from: ByteUnit, to: ByteUnit): number;
|
|
12
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ByteOperation = exports.ByteUnit = void 0;
|
|
4
|
+
var ByteUnit;
|
|
5
|
+
(function (ByteUnit) {
|
|
6
|
+
ByteUnit["B"] = "B";
|
|
7
|
+
ByteUnit["KB"] = "KB";
|
|
8
|
+
ByteUnit["MB"] = "MB";
|
|
9
|
+
ByteUnit["GB"] = "GB";
|
|
10
|
+
ByteUnit["TB"] = "TB";
|
|
11
|
+
ByteUnit["PB"] = "PB";
|
|
12
|
+
})(ByteUnit || (exports.ByteUnit = ByteUnit = {}));
|
|
13
|
+
;
|
|
14
|
+
const SIGN_TO_NUMBER = {
|
|
15
|
+
[ByteUnit.B]: 0,
|
|
16
|
+
[ByteUnit.KB]: 1,
|
|
17
|
+
[ByteUnit.MB]: 2,
|
|
18
|
+
[ByteUnit.GB]: 3,
|
|
19
|
+
[ByteUnit.TB]: 4,
|
|
20
|
+
[ByteUnit.PB]: 5,
|
|
21
|
+
};
|
|
22
|
+
const NUMBER_TO_SIGN = {
|
|
23
|
+
0: ByteUnit.B,
|
|
24
|
+
1: ByteUnit.KB,
|
|
25
|
+
2: ByteUnit.MB,
|
|
26
|
+
3: ByteUnit.GB,
|
|
27
|
+
4: ByteUnit.TB,
|
|
28
|
+
5: ByteUnit.PB,
|
|
29
|
+
};
|
|
30
|
+
class ByteOperation {
|
|
31
|
+
static format(value, unit) {
|
|
32
|
+
let KILO = 1024;
|
|
33
|
+
let bytes = this.convert(value, unit, ByteUnit.B);
|
|
34
|
+
if (!bytes || bytes < 1)
|
|
35
|
+
return "0B";
|
|
36
|
+
let index = 0;
|
|
37
|
+
while (bytes >= KILO && NUMBER_TO_SIGN[index] != null) {
|
|
38
|
+
bytes /= KILO;
|
|
39
|
+
index++;
|
|
40
|
+
}
|
|
41
|
+
function formatNumber(value) {
|
|
42
|
+
if (value != Math.round(value)) {
|
|
43
|
+
if (value < 1)
|
|
44
|
+
return value.toFixed(2);
|
|
45
|
+
if (value < 100)
|
|
46
|
+
return value.toFixed(1);
|
|
47
|
+
}
|
|
48
|
+
return value.toFixed(0);
|
|
49
|
+
}
|
|
50
|
+
return `${formatNumber(bytes)}${NUMBER_TO_SIGN[index]}`;
|
|
51
|
+
}
|
|
52
|
+
static convert(value, from, to) {
|
|
53
|
+
return value * (Math.pow(2, (10 * (SIGN_TO_NUMBER[from] - SIGN_TO_NUMBER[to]))));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.ByteOperation = ByteOperation;
|
|
57
|
+
//# sourceMappingURL=ByteOperation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ByteOperation.js","sourceRoot":"","sources":["../src/ByteOperation.ts"],"names":[],"mappings":";;;AAAA,IAAY,QAQX;AARD,WAAY,QAAQ;IAEhB,mBAAO,CAAA;IACP,qBAAS,CAAA;IACT,qBAAS,CAAA;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K,CAAC,KAAK,CAAC,EAC9B,CAAC;gBACG,IAAI,KAAK,GAAG,CAAC;oBAAE,OAAO,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;gBACvC,IAAI,KAAK,GAAG,GAAG;oBAAE,OAAO,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YAC7C,CAAC;YACD,OAAO,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QAC5B,CAAC;QACD,OAAO,GAAG,YAAY,CAAC,KAAK,CAAC,GAAG,cAAc,CAAC,KAAK,CAAC,EAAE,CAAC;IAC5D,CAAC;IACD,MAAM,CAAC,OAAO,CAAC,KAAa,EAAE,IAAc,EAAE,EAAY;QAEtD,OAAO,KAAK,GAAG,CAAC,SAAA,CAAC,EAAI,CAAC,EAAE,GAAG,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA,CAAC,CAAC;IAC7E,CAAC;CACJ;AA9BD,sCA8BC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export * from "./BaseMetaDatabase";
|
|
|
4
4
|
export * from "./BaseMetaTable";
|
|
5
5
|
export * from "./BaseServer";
|
|
6
6
|
export * from "./BaseUUID";
|
|
7
|
+
export * from "./ByteOperation";
|
|
7
8
|
export * from "./CacheService";
|
|
8
9
|
export * from "./ConsoleOperation";
|
|
9
10
|
export * from "./CookieService";
|
package/dist/index.js
CHANGED
|
@@ -20,6 +20,7 @@ __exportStar(require("./BaseMetaDatabase"), exports);
|
|
|
20
20
|
__exportStar(require("./BaseMetaTable"), exports);
|
|
21
21
|
__exportStar(require("./BaseServer"), exports);
|
|
22
22
|
__exportStar(require("./BaseUUID"), exports);
|
|
23
|
+
__exportStar(require("./ByteOperation"), exports);
|
|
23
24
|
__exportStar(require("./CacheService"), exports);
|
|
24
25
|
__exportStar(require("./ConsoleOperation"), exports);
|
|
25
26
|
__exportStar(require("./CookieService"), exports);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,mDAAiC;AACjC,qDAAmC;AACnC,kDAAgC;AAChC,+CAA6B;AAC7B,6CAA2B;AAC3B,iDAA+B;AAC/B,qDAAmC;AACnC,kDAAgC;AAChC,8CAA4B;AAC5B,mDAAiC;AACjC,4CAA0B;AAC1B,qDAAmC;AACnC,sDAAoC;AACpC,wDAAsC;AACtC,+CAA6B;AAC7B,mDAAiC;AACjC,kDAAgC;AAChC,+CAA6B;AAC7B,yDAAuC;AACvC,uDAAqC;AACrC,iDAA+B;AAC/B,kDAAgC;AAChC,8CAA4B;AAC5B,+CAA6B;AAC7B,6CAA2B;AAC3B,mDAAiC;AACjC,qDAAmC;AACnC,kDAAgC;AAChC,4DAA0C;AAC1C,yDAAuC;AACvC,oDAAkC;AAClC,qDAAmC;AACnC,kDAAgC;AAChC,mDAAiC;AACjC,oDAAkC;AAClC,mDAAiC;AACjC,mDAAiC;AACjC,oDAAkC;AAClC,6CAA2B;AAC3B,oDAAkC;AAClC,kDAAgC;AAChC,sDAAoC;AACpC,qDAAmC;AACnC,iDAA+B;AAC/B,qDAAmC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,mDAAiC;AACjC,qDAAmC;AACnC,kDAAgC;AAChC,+CAA6B;AAC7B,6CAA2B;AAC3B,kDAAgC;AAChC,iDAA+B;AAC/B,qDAAmC;AACnC,kDAAgC;AAChC,8CAA4B;AAC5B,mDAAiC;AACjC,4CAA0B;AAC1B,qDAAmC;AACnC,sDAAoC;AACpC,wDAAsC;AACtC,+CAA6B;AAC7B,mDAAiC;AACjC,kDAAgC;AAChC,+CAA6B;AAC7B,yDAAuC;AACvC,uDAAqC;AACrC,iDAA+B;AAC/B,kDAAgC;AAChC,8CAA4B;AAC5B,+CAA6B;AAC7B,6CAA2B;AAC3B,mDAAiC;AACjC,qDAAmC;AACnC,kDAAgC;AAChC,4DAA0C;AAC1C,yDAAuC;AACvC,oDAAkC;AAClC,qDAAmC;AACnC,kDAAgC;AAChC,mDAAiC;AACjC,oDAAkC;AAClC,mDAAiC;AACjC,mDAAiC;AACjC,oDAAkC;AAClC,6CAA2B;AAC3B,oDAAkC;AAClC,kDAAgC;AAChC,sDAAoC;AACpC,qDAAmC;AACnC,iDAA+B;AAC/B,qDAAmC"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export enum ByteUnit
|
|
2
|
+
{
|
|
3
|
+
B = "B",
|
|
4
|
+
KB = "KB",
|
|
5
|
+
MB = "MB",
|
|
6
|
+
GB = "GB",
|
|
7
|
+
TB = "TB",
|
|
8
|
+
PB = "PB",
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const SIGN_TO_NUMBER: Record<ByteUnit, number> = {
|
|
12
|
+
[ByteUnit.B]: 0,
|
|
13
|
+
[ByteUnit.KB]: 1,
|
|
14
|
+
[ByteUnit.MB]: 2,
|
|
15
|
+
[ByteUnit.GB]: 3,
|
|
16
|
+
[ByteUnit.TB]: 4,
|
|
17
|
+
[ByteUnit.PB]: 5,
|
|
18
|
+
};
|
|
19
|
+
const NUMBER_TO_SIGN: Record<number, ByteUnit> = {
|
|
20
|
+
0: ByteUnit.B,
|
|
21
|
+
1: ByteUnit.KB,
|
|
22
|
+
2: ByteUnit.MB,
|
|
23
|
+
3: ByteUnit.GB,
|
|
24
|
+
4: ByteUnit.TB,
|
|
25
|
+
5: ByteUnit.PB,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export class ByteOperation
|
|
29
|
+
{
|
|
30
|
+
static format(value: number, unit: ByteUnit)
|
|
31
|
+
{
|
|
32
|
+
let KILO = 1024;
|
|
33
|
+
let bytes = this.convert(value, unit, ByteUnit.B);
|
|
34
|
+
if (!bytes || bytes < 1) return "0B";
|
|
35
|
+
|
|
36
|
+
let index = 0;
|
|
37
|
+
while (bytes >= KILO && NUMBER_TO_SIGN[index] != null)
|
|
38
|
+
{
|
|
39
|
+
bytes /= KILO;
|
|
40
|
+
index++;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function formatNumber(value: number): string
|
|
44
|
+
{
|
|
45
|
+
if (value != Math.round(value))
|
|
46
|
+
{
|
|
47
|
+
if (value < 1) return value.toFixed(2);
|
|
48
|
+
if (value < 100) return value.toFixed(1);
|
|
49
|
+
}
|
|
50
|
+
return value.toFixed(0);
|
|
51
|
+
}
|
|
52
|
+
return `${formatNumber(bytes)}${NUMBER_TO_SIGN[index]}`;
|
|
53
|
+
}
|
|
54
|
+
static convert(value: number, from: ByteUnit, to: ByteUnit)
|
|
55
|
+
{
|
|
56
|
+
return value * (2 ** (10 * (SIGN_TO_NUMBER[from] - SIGN_TO_NUMBER[to])));
|
|
57
|
+
}
|
|
58
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -4,6 +4,7 @@ export * from "./BaseMetaDatabase";
|
|
|
4
4
|
export * from "./BaseMetaTable";
|
|
5
5
|
export * from "./BaseServer";
|
|
6
6
|
export * from "./BaseUUID";
|
|
7
|
+
export * from "./ByteOperation";
|
|
7
8
|
export * from "./CacheService";
|
|
8
9
|
export * from "./ConsoleOperation";
|
|
9
10
|
export * from "./CookieService";
|