@taybart/corvid 0.1.0 → 0.1.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/index.d.ts +1 -0
- package/dist/index.js +59 -14
- package/package.json +1 -1
- package/dist/crypto.d.ts +0 -8
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -20,6 +20,12 @@ var __webpack_require__ = {};
|
|
|
20
20
|
});
|
|
21
21
|
};
|
|
22
22
|
})();
|
|
23
|
+
var strings_namespaceObject = {};
|
|
24
|
+
__webpack_require__.r(strings_namespaceObject);
|
|
25
|
+
__webpack_require__.d(strings_namespaceObject, {
|
|
26
|
+
bytesToHuman: ()=>bytesToHuman,
|
|
27
|
+
toKebab: ()=>toKebab
|
|
28
|
+
});
|
|
23
29
|
var dom_namespaceObject = {};
|
|
24
30
|
__webpack_require__.r(dom_namespaceObject);
|
|
25
31
|
__webpack_require__.d(dom_namespaceObject, {
|
|
@@ -51,6 +57,48 @@ __webpack_require__.d(local_storage_namespaceObject, {
|
|
|
51
57
|
listen: ()=>listen,
|
|
52
58
|
set: ()=>set
|
|
53
59
|
});
|
|
60
|
+
function bytesToHuman(bytes, options = {}) {
|
|
61
|
+
const { useSI = false, decimals = 2, includeUnits = true, targetUnit = null } = options;
|
|
62
|
+
const unit = useSI ? 1000 : 1024;
|
|
63
|
+
const units = useSI ? [
|
|
64
|
+
'B',
|
|
65
|
+
'kB',
|
|
66
|
+
'MB',
|
|
67
|
+
'GB',
|
|
68
|
+
'TB',
|
|
69
|
+
'PB',
|
|
70
|
+
'EB',
|
|
71
|
+
'ZB',
|
|
72
|
+
'YB'
|
|
73
|
+
] : [
|
|
74
|
+
'B',
|
|
75
|
+
'KiB',
|
|
76
|
+
'MiB',
|
|
77
|
+
'GiB',
|
|
78
|
+
'TiB',
|
|
79
|
+
'PiB',
|
|
80
|
+
'EiB',
|
|
81
|
+
'ZiB',
|
|
82
|
+
'YiB'
|
|
83
|
+
];
|
|
84
|
+
if (null === targetUnit) {
|
|
85
|
+
let val = parseInt(bytes, 10);
|
|
86
|
+
if (Math.abs(val) < unit) return `${bytes} B`;
|
|
87
|
+
let u = 0;
|
|
88
|
+
while(Math.abs(val) >= unit && u < units.length - 1){
|
|
89
|
+
val /= unit;
|
|
90
|
+
u++;
|
|
91
|
+
}
|
|
92
|
+
if (includeUnits) return `${val.toFixed(decimals)} ${units[u]}`;
|
|
93
|
+
return `${val.toFixed(decimals)}`;
|
|
94
|
+
}
|
|
95
|
+
const targetUnitIndex = units.indexOf(targetUnit);
|
|
96
|
+
if (-1 === targetUnitIndex) throw new Error(`Invalid unit: ${targetUnit}. Valid units are: ${units.join(', ')}`);
|
|
97
|
+
let val = parseInt(bytes, 10);
|
|
98
|
+
for(let i = 0; i < targetUnitIndex; i++)val /= unit;
|
|
99
|
+
if (includeUnits) return `${val.toFixed(decimals)} ${targetUnit}`;
|
|
100
|
+
return `${val.toFixed(decimals)}`;
|
|
101
|
+
}
|
|
54
102
|
function toKebab(str) {
|
|
55
103
|
return str.replace(/[A-Z]+(?![a-z])|[A-Z]/g, (s, ofs)=>(ofs ? '-' : '') + s.toLowerCase());
|
|
56
104
|
}
|
|
@@ -129,19 +177,16 @@ class logger {
|
|
|
129
177
|
_define_property(this, "prefix", void 0);
|
|
130
178
|
this.level = level;
|
|
131
179
|
this.prefix = prefix ? `(${prefix}):` : ':';
|
|
132
|
-
if (-1 === this.level)
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
];
|
|
141
|
-
|
|
142
|
-
this[methodName] = ()=>{};
|
|
143
|
-
});
|
|
144
|
-
}
|
|
180
|
+
if (-1 === this.level) [
|
|
181
|
+
'error',
|
|
182
|
+
'warn',
|
|
183
|
+
'info',
|
|
184
|
+
'debug',
|
|
185
|
+
'trace',
|
|
186
|
+
'log'
|
|
187
|
+
].forEach((methodName)=>{
|
|
188
|
+
this[methodName] = ()=>{};
|
|
189
|
+
});
|
|
145
190
|
}
|
|
146
191
|
}
|
|
147
192
|
function dom_define_property(obj, key, value) {
|
|
@@ -510,4 +555,4 @@ function listen(key, cb) {
|
|
|
510
555
|
}
|
|
511
556
|
});
|
|
512
557
|
}
|
|
513
|
-
export { clipboard, dom_namespaceObject as dom, genID, utils_logLevel as logLevel, logger, local_storage_namespaceObject as ls, network_namespaceObject as network, style_namespaceObject as style };
|
|
558
|
+
export { clipboard, dom_namespaceObject as dom, genID, utils_logLevel as logLevel, logger, local_storage_namespaceObject as ls, network_namespaceObject as network, strings_namespaceObject as strings, style_namespaceObject as style };
|
package/package.json
CHANGED