{ "version": 3, "sources": ["src/app/_pipes/bytes.pipe.ts"], "sourcesContent": ["import { Pipe, PipeTransform } from '@angular/core';\r\n\r\n@Pipe({\r\n name: 'bytes',\r\n standalone: true\r\n})\r\nexport class BytesPipe implements PipeTransform {\r\n\r\n /**\r\n * Format bytes as human-readable text.\r\n *\r\n * @param bytes Number of bytes.\r\n * @param si True to use metric (SI) units, aka powers of 1000. False to use\r\n * binary (IEC), aka powers of 1024.\r\n * @param dp Number of decimal places to display.\r\n *\r\n * @return Formatted string.\r\n *\r\n * Credit: https://stackoverflow.com/questions/10420352/converting-file-size-in-bytes-to-human-readable-string\r\n */\r\n transform(bytes: number, si=true, dp=1): string {\r\n const thresh = si ? 1000 : 1024;\r\n\r\n if (Math.abs(bytes) < thresh) {\r\n return bytes + ' B';\r\n }\r\n\r\n const units = si\r\n ? ['kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']\r\n : ['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];\r\n let u = -1;\r\n const r = 10**dp;\r\n\r\n do {\r\n bytes /= thresh;\r\n ++u;\r\n } while (Math.round(Math.abs(bytes) * r) / r >= thresh && u < units.length - 1);\r\n\r\n const fixed = bytes.toFixed(dp);\r\n if ((fixed + '').endsWith('.0')) {\r\n return bytes.toFixed(0) + ' ' + units[u];\r\n }\r\n\r\n return fixed + ' ' + units[u];\r\n }\r\n\r\n}\r\n"], "mappings": "yCAMA,IAAaA,GAAS,IAAA,CAAhB,IAAOA,EAAP,MAAOA,CAAS,CAcpBC,UAAUC,EAAeC,EAAG,GAAMC,EAAG,EAAC,CACpC,IAAMC,EAASF,EAAK,IAAO,KAE3B,GAAIG,KAAKC,IAAIL,CAAK,EAAIG,EACpB,OAAOH,EAAQ,KAGjB,IAAMM,EAAQL,EACV,CAAC,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,IAAI,EAC/C,CAAC,MAAO,MAAO,MAAO,MAAO,MAAO,MAAO,MAAO,KAAK,EACvDM,EAAI,GACFC,EAAI,IAAIN,EAEd,GACEF,GAASG,EACT,EAAEI,QACKH,KAAKK,MAAML,KAAKC,IAAIL,CAAK,EAAIQ,CAAC,EAAIA,GAAKL,GAAUI,EAAID,EAAMI,OAAS,GAE7E,IAAMC,EAAQX,EAAMY,QAAQV,CAAE,EAC9B,OAAKS,EAAQ,IAAIE,SAAS,IAAI,EACrBb,EAAMY,QAAQ,CAAC,EAAI,IAAMN,EAAMC,CAAC,EAGlCI,EAAQ,IAAML,EAAMC,CAAC,CAC9B,yCAtCWT,EAAS,oCAATA,EAASgB,KAAA,GAAAC,WAAA,EAAA,CAAA,EAAhB,IAAOjB,EAAPkB,SAAOlB,CAAS,GAAA", "names": ["BytesPipe", "transform", "bytes", "si", "dp", "thresh", "Math", "abs", "units", "u", "r", "round", "length", "fixed", "toFixed", "endsWith", "pure", "standalone", "_BytesPipe"] }