chunk.L6IF2EAH.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import {
  2. e,
  3. h,
  4. n
  5. } from "./chunk.5PIDMFOE.js";
  6. import {
  7. __decorateClass
  8. } from "./chunk.IHGPZX35.js";
  9. // src/internal/number.ts
  10. function formatBytes(bytes, options) {
  11. options = Object.assign({
  12. unit: "bytes",
  13. locale: void 0
  14. }, options);
  15. const byteUnits = ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
  16. const bitUnits = ["b", "kbit", "Mbit", "Gbit", "Tbit", "Pbit", "Ebit", "Zbit", "Ybit"];
  17. const units = options.unit === "bytes" ? byteUnits : bitUnits;
  18. const isNegative = bytes < 0;
  19. bytes = Math.abs(bytes);
  20. if (bytes === 0)
  21. return "0 B";
  22. const i = Math.min(Math.floor(Math.log10(bytes) / 3), units.length - 1);
  23. const num = Number((bytes / Math.pow(1e3, i)).toPrecision(3));
  24. const numString = num.toLocaleString(options.locale);
  25. const prefix = isNegative ? "-" : "";
  26. return `${prefix}${numString} ${units[i]}`;
  27. }
  28. // src/components/format-bytes/format-bytes.ts
  29. var SlFormatBytes = class extends h {
  30. constructor() {
  31. super(...arguments);
  32. this.value = 0;
  33. this.unit = "bytes";
  34. }
  35. render() {
  36. return formatBytes(this.value, {
  37. unit: this.unit,
  38. locale: this.locale
  39. });
  40. }
  41. };
  42. __decorateClass([
  43. e({ type: Number })
  44. ], SlFormatBytes.prototype, "value", 2);
  45. __decorateClass([
  46. e()
  47. ], SlFormatBytes.prototype, "unit", 2);
  48. __decorateClass([
  49. e()
  50. ], SlFormatBytes.prototype, "locale", 2);
  51. SlFormatBytes = __decorateClass([
  52. n("sl-format-bytes")
  53. ], SlFormatBytes);
  54. var format_bytes_default = SlFormatBytes;
  55. export {
  56. format_bytes_default
  57. };