@oeos-components/utils 0.0.6 → 0.0.8

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 CHANGED
@@ -644,37 +644,38 @@ function toFixed(value, options = {}) {
644
644
  }
645
645
  return `${prefix}${res}${finalUnit}${suffix}`;
646
646
  }
647
- function formatBytes(bytes, { toFixed: toFixed2 = 2, thousands = true } = {}) {
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(toFixed2) + " B";
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(toFixed2) + " " + sizes[i];
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
- function formatBytesConvert(oBytes, { thounsand = false, toFixed: toFixed2 = 0 } = {}) {
666
+ function formatBytesConvert(oBytes, { thounsands = false, digit = 0 } = {}) {
667
+ let bytes = oBytes;
666
668
  if (isStringNumber(oBytes) || isNumber(oBytes) || getType(oBytes) !== "string") {
667
- return oBytes;
669
+ return parseDigitThounsands(oBytes);
668
670
  }
669
671
  if (!oBytes) {
670
- return oBytes;
672
+ return parseDigitThounsands(oBytes);
671
673
  }
672
674
  const regex = /^\d{1,3}(,\d{3})*(\.\d+)?[a-zA-Z ]*$/;
673
- let bytes = oBytes;
674
675
  if (regex.test(oBytes)) {
675
676
  bytes = oBytes.replace(/,/g, "");
676
677
  if (isStringNumber(bytes) || isNumber(bytes) || getType(bytes) !== "string") {
677
- return bytes;
678
+ return parseDigitThounsands(bytes);
678
679
  }
679
680
  }
680
681
  const bytesRegex = /^(\d+(?:\.\d+)?)\s*([BKMGTPEZY]?B|Byte)$/i;
@@ -703,14 +704,17 @@ function formatBytesConvert(oBytes, { thounsand = false, toFixed: toFixed2 = 0 }
703
704
  );
704
705
  return;
705
706
  }
706
- let finalRes = size * units[unit];
707
- if (toFixed2) {
708
- finalRes = Number(finalRes).toFixed(toFixed2);
709
- }
710
- if (thounsand) {
711
- finalRes = formatThousands(finalRes);
707
+ function parseDigitThounsands(val) {
708
+ let finalRes = val;
709
+ if (digit) {
710
+ finalRes = Number(finalRes).toFixed(digit);
711
+ }
712
+ if (thounsands) {
713
+ finalRes = formatThousands(finalRes);
714
+ }
715
+ return finalRes;
712
716
  }
713
- return finalRes;
717
+ return parseDigitThounsands(size * units[unit]);
714
718
  }
715
719
  function throttle(fn, delay = 1e3) {
716
720
  let last = 0;
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as element_plus from 'element-plus';
2
- import { ElMessageOptions } from 'element-plus';
2
+ import { MessageOptions } from 'element-plus';
3
3
  import { Ref } from '@vue/reactivity';
4
4
 
5
5
  /**
@@ -61,7 +61,7 @@ declare const isNumber: (val: any) => val is number;
61
61
  type MessageType = 'success' | 'info' | 'error' | 'warning';
62
62
  type ShortType = 's' | 'i' | 'e' | 'w';
63
63
  type ToastType = MessageType | ShortType;
64
- type ToastOptions = Partial<ElMessageOptions> & {
64
+ type ToastOptions = Partial<MessageOptions> & {
65
65
  closeAll?: boolean;
66
66
  };
67
67
  declare function $toast(message: string | ToastOptions, type?: ToastType | ToastOptions, otherParams?: ToastOptions): void;
@@ -280,9 +280,11 @@ 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, { toFixed, thousands }?: {
284
- toFixed?: number | undefined;
285
- thousands?: boolean | undefined;
283
+ declare function formatBytes(bytes: any, options?: {
284
+ digit?: number;
285
+ thousands?: boolean;
286
+ prefix?: string;
287
+ suffix?: string;
286
288
  }): any;
287
289
  /**
288
290
  * 字节转数字
@@ -294,9 +296,9 @@ declare function formatBytes(bytes: any, { toFixed, thousands }?: {
294
296
  * formatBytesConvert('1,234 GB', {thousand: true}) 1,324,997,410,816
295
297
  * formatBytesConvert('1,234 GB', {toFixed: 2}) 1324997410816.00
296
298
  */
297
- declare function formatBytesConvert(oBytes: any, { thounsand, toFixed }?: {
298
- thounsand?: boolean | undefined;
299
- toFixed?: number | undefined;
299
+ declare function formatBytesConvert(oBytes: any, { thounsands, digit }?: {
300
+ thounsands?: boolean | undefined;
301
+ digit?: number | undefined;
300
302
  }): any;
301
303
  declare function throttle(fn: any, delay?: number): () => void;
302
304
  /**
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as element_plus from 'element-plus';
2
- import { ElMessageOptions } from 'element-plus';
2
+ import { MessageOptions } from 'element-plus';
3
3
  import { Ref } from '@vue/reactivity';
4
4
 
5
5
  /**
@@ -61,7 +61,7 @@ declare const isNumber: (val: any) => val is number;
61
61
  type MessageType = 'success' | 'info' | 'error' | 'warning';
62
62
  type ShortType = 's' | 'i' | 'e' | 'w';
63
63
  type ToastType = MessageType | ShortType;
64
- type ToastOptions = Partial<ElMessageOptions> & {
64
+ type ToastOptions = Partial<MessageOptions> & {
65
65
  closeAll?: boolean;
66
66
  };
67
67
  declare function $toast(message: string | ToastOptions, type?: ToastType | ToastOptions, otherParams?: ToastOptions): void;
@@ -280,9 +280,11 @@ 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, { toFixed, thousands }?: {
284
- toFixed?: number | undefined;
285
- thousands?: boolean | undefined;
283
+ declare function formatBytes(bytes: any, options?: {
284
+ digit?: number;
285
+ thousands?: boolean;
286
+ prefix?: string;
287
+ suffix?: string;
286
288
  }): any;
287
289
  /**
288
290
  * 字节转数字
@@ -294,9 +296,9 @@ declare function formatBytes(bytes: any, { toFixed, thousands }?: {
294
296
  * formatBytesConvert('1,234 GB', {thousand: true}) 1,324,997,410,816
295
297
  * formatBytesConvert('1,234 GB', {toFixed: 2}) 1324997410816.00
296
298
  */
297
- declare function formatBytesConvert(oBytes: any, { thounsand, toFixed }?: {
298
- thounsand?: boolean | undefined;
299
- toFixed?: number | undefined;
299
+ declare function formatBytesConvert(oBytes: any, { thounsands, digit }?: {
300
+ thounsands?: boolean | undefined;
301
+ digit?: number | undefined;
300
302
  }): any;
301
303
  declare function throttle(fn: any, delay?: number): () => void;
302
304
  /**
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as element_plus from 'element-plus';
2
- import { ElMessageOptions } from 'element-plus';
2
+ import { MessageOptions } from 'element-plus';
3
3
  import { Ref } from '@vue/reactivity';
4
4
 
5
5
  /**
@@ -61,7 +61,7 @@ declare const isNumber: (val: any) => val is number;
61
61
  type MessageType = 'success' | 'info' | 'error' | 'warning';
62
62
  type ShortType = 's' | 'i' | 'e' | 'w';
63
63
  type ToastType = MessageType | ShortType;
64
- type ToastOptions = Partial<ElMessageOptions> & {
64
+ type ToastOptions = Partial<MessageOptions> & {
65
65
  closeAll?: boolean;
66
66
  };
67
67
  declare function $toast(message: string | ToastOptions, type?: ToastType | ToastOptions, otherParams?: ToastOptions): void;
@@ -280,9 +280,11 @@ 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, { toFixed, thousands }?: {
284
- toFixed?: number | undefined;
285
- thousands?: boolean | undefined;
283
+ declare function formatBytes(bytes: any, options?: {
284
+ digit?: number;
285
+ thousands?: boolean;
286
+ prefix?: string;
287
+ suffix?: string;
286
288
  }): any;
287
289
  /**
288
290
  * 字节转数字
@@ -294,9 +296,9 @@ declare function formatBytes(bytes: any, { toFixed, thousands }?: {
294
296
  * formatBytesConvert('1,234 GB', {thousand: true}) 1,324,997,410,816
295
297
  * formatBytesConvert('1,234 GB', {toFixed: 2}) 1324997410816.00
296
298
  */
297
- declare function formatBytesConvert(oBytes: any, { thounsand, toFixed }?: {
298
- thounsand?: boolean | undefined;
299
- toFixed?: number | undefined;
299
+ declare function formatBytesConvert(oBytes: any, { thounsands, digit }?: {
300
+ thounsands?: boolean | undefined;
301
+ digit?: number | undefined;
300
302
  }): any;
301
303
  declare function throttle(fn: any, delay?: number): () => void;
302
304
  /**
package/dist/index.mjs CHANGED
@@ -641,37 +641,38 @@ function toFixed(value, options = {}) {
641
641
  }
642
642
  return `${prefix}${res}${finalUnit}${suffix}`;
643
643
  }
644
- function formatBytes(bytes, { toFixed: toFixed2 = 2, thousands = true } = {}) {
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(toFixed2) + " B";
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(toFixed2) + " " + sizes[i];
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
- function formatBytesConvert(oBytes, { thounsand = false, toFixed: toFixed2 = 0 } = {}) {
663
+ function formatBytesConvert(oBytes, { thounsands = false, digit = 0 } = {}) {
664
+ let bytes = oBytes;
663
665
  if (isStringNumber(oBytes) || isNumber(oBytes) || getType(oBytes) !== "string") {
664
- return oBytes;
666
+ return parseDigitThounsands(oBytes);
665
667
  }
666
668
  if (!oBytes) {
667
- return oBytes;
669
+ return parseDigitThounsands(oBytes);
668
670
  }
669
671
  const regex = /^\d{1,3}(,\d{3})*(\.\d+)?[a-zA-Z ]*$/;
670
- let bytes = oBytes;
671
672
  if (regex.test(oBytes)) {
672
673
  bytes = oBytes.replace(/,/g, "");
673
674
  if (isStringNumber(bytes) || isNumber(bytes) || getType(bytes) !== "string") {
674
- return bytes;
675
+ return parseDigitThounsands(bytes);
675
676
  }
676
677
  }
677
678
  const bytesRegex = /^(\d+(?:\.\d+)?)\s*([BKMGTPEZY]?B|Byte)$/i;
@@ -700,14 +701,17 @@ function formatBytesConvert(oBytes, { thounsand = false, toFixed: toFixed2 = 0 }
700
701
  );
701
702
  return;
702
703
  }
703
- let finalRes = size * units[unit];
704
- if (toFixed2) {
705
- finalRes = Number(finalRes).toFixed(toFixed2);
706
- }
707
- if (thounsand) {
708
- finalRes = formatThousands(finalRes);
704
+ function parseDigitThounsands(val) {
705
+ let finalRes = val;
706
+ if (digit) {
707
+ finalRes = Number(finalRes).toFixed(digit);
708
+ }
709
+ if (thounsands) {
710
+ finalRes = formatThousands(finalRes);
711
+ }
712
+ return finalRes;
709
713
  }
710
- return finalRes;
714
+ return parseDigitThounsands(size * units[unit]);
711
715
  }
712
716
  function throttle(fn, delay = 1e3) {
713
717
  let last = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oeos-components/utils",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "description": "utils of oeos-components",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",