@oeos-components/utils 0.0.6 → 0.0.7
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.cjs +5 -4
- package/dist/index.d.cts +6 -4
- package/dist/index.d.mts +6 -4
- package/dist/index.d.ts +6 -4
- package/dist/index.mjs +5 -4
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -644,23 +644,24 @@ function toFixed(value, options = {}) {
|
|
|
644
644
|
}
|
|
645
645
|
return `${prefix}${res}${finalUnit}${suffix}`;
|
|
646
646
|
}
|
|
647
|
-
function formatBytes(bytes,
|
|
647
|
+
function formatBytes(bytes, options = {}) {
|
|
648
|
+
let { digit = 2, thousands = true, prefix = "", suffix = "" } = options;
|
|
648
649
|
if (isStringNumber(bytes) || isNumber(bytes)) {
|
|
649
650
|
bytes = Number(bytes);
|
|
650
651
|
} else {
|
|
651
652
|
return bytes;
|
|
652
653
|
}
|
|
653
654
|
if (bytes <= 0) {
|
|
654
|
-
return bytes.toFixed(
|
|
655
|
+
return bytes.toFixed(digit) + " B";
|
|
655
656
|
}
|
|
656
657
|
const k = 1024;
|
|
657
658
|
const sizes = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
|
|
658
659
|
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
659
|
-
let res = (bytes / Math.pow(k, i)).toFixed(
|
|
660
|
+
let res = (bytes / Math.pow(k, i)).toFixed(digit) + " " + sizes[i];
|
|
660
661
|
if (thousands) {
|
|
661
662
|
res = formatThousands(res);
|
|
662
663
|
}
|
|
663
|
-
return res
|
|
664
|
+
return `${prefix}${res}${suffix}`;
|
|
664
665
|
}
|
|
665
666
|
function formatBytesConvert(oBytes, { thounsand = false, toFixed: toFixed2 = 0 } = {}) {
|
|
666
667
|
if (isStringNumber(oBytes) || isNumber(oBytes) || getType(oBytes) !== "string") {
|
package/dist/index.d.cts
CHANGED
|
@@ -280,10 +280,12 @@ declare function toFixed(value: any, options?: {
|
|
|
280
280
|
* proxy.formatBytes(536870912) // 512MB
|
|
281
281
|
* proxy.formatBytes(536870912) // 512MB
|
|
282
282
|
*/
|
|
283
|
-
declare function formatBytes(bytes: any,
|
|
284
|
-
|
|
285
|
-
thousands?: boolean
|
|
286
|
-
|
|
283
|
+
declare function formatBytes(bytes: any, options?: {
|
|
284
|
+
digit?: number;
|
|
285
|
+
thousands?: boolean;
|
|
286
|
+
prefix?: string;
|
|
287
|
+
suffix?: string;
|
|
288
|
+
} | number): any;
|
|
287
289
|
/**
|
|
288
290
|
* 字节转数字
|
|
289
291
|
* @param oBytes
|
package/dist/index.d.mts
CHANGED
|
@@ -280,10 +280,12 @@ declare function toFixed(value: any, options?: {
|
|
|
280
280
|
* proxy.formatBytes(536870912) // 512MB
|
|
281
281
|
* proxy.formatBytes(536870912) // 512MB
|
|
282
282
|
*/
|
|
283
|
-
declare function formatBytes(bytes: any,
|
|
284
|
-
|
|
285
|
-
thousands?: boolean
|
|
286
|
-
|
|
283
|
+
declare function formatBytes(bytes: any, options?: {
|
|
284
|
+
digit?: number;
|
|
285
|
+
thousands?: boolean;
|
|
286
|
+
prefix?: string;
|
|
287
|
+
suffix?: string;
|
|
288
|
+
} | number): any;
|
|
287
289
|
/**
|
|
288
290
|
* 字节转数字
|
|
289
291
|
* @param oBytes
|
package/dist/index.d.ts
CHANGED
|
@@ -280,10 +280,12 @@ declare function toFixed(value: any, options?: {
|
|
|
280
280
|
* proxy.formatBytes(536870912) // 512MB
|
|
281
281
|
* proxy.formatBytes(536870912) // 512MB
|
|
282
282
|
*/
|
|
283
|
-
declare function formatBytes(bytes: any,
|
|
284
|
-
|
|
285
|
-
thousands?: boolean
|
|
286
|
-
|
|
283
|
+
declare function formatBytes(bytes: any, options?: {
|
|
284
|
+
digit?: number;
|
|
285
|
+
thousands?: boolean;
|
|
286
|
+
prefix?: string;
|
|
287
|
+
suffix?: string;
|
|
288
|
+
} | number): any;
|
|
287
289
|
/**
|
|
288
290
|
* 字节转数字
|
|
289
291
|
* @param oBytes
|
package/dist/index.mjs
CHANGED
|
@@ -641,23 +641,24 @@ function toFixed(value, options = {}) {
|
|
|
641
641
|
}
|
|
642
642
|
return `${prefix}${res}${finalUnit}${suffix}`;
|
|
643
643
|
}
|
|
644
|
-
function formatBytes(bytes,
|
|
644
|
+
function formatBytes(bytes, options = {}) {
|
|
645
|
+
let { digit = 2, thousands = true, prefix = "", suffix = "" } = options;
|
|
645
646
|
if (isStringNumber(bytes) || isNumber(bytes)) {
|
|
646
647
|
bytes = Number(bytes);
|
|
647
648
|
} else {
|
|
648
649
|
return bytes;
|
|
649
650
|
}
|
|
650
651
|
if (bytes <= 0) {
|
|
651
|
-
return bytes.toFixed(
|
|
652
|
+
return bytes.toFixed(digit) + " B";
|
|
652
653
|
}
|
|
653
654
|
const k = 1024;
|
|
654
655
|
const sizes = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
|
|
655
656
|
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
656
|
-
let res = (bytes / Math.pow(k, i)).toFixed(
|
|
657
|
+
let res = (bytes / Math.pow(k, i)).toFixed(digit) + " " + sizes[i];
|
|
657
658
|
if (thousands) {
|
|
658
659
|
res = formatThousands(res);
|
|
659
660
|
}
|
|
660
|
-
return res
|
|
661
|
+
return `${prefix}${res}${suffix}`;
|
|
661
662
|
}
|
|
662
663
|
function formatBytesConvert(oBytes, { thounsand = false, toFixed: toFixed2 = 0 } = {}) {
|
|
663
664
|
if (isStringNumber(oBytes) || isNumber(oBytes) || getType(oBytes) !== "string") {
|