{ "version": 3, "sources": ["src/app/_pipes/bytes.pipe.ts"], "sourcesContent": ["import { Pipe, PipeTransform } from '@angular/core';\n\n@Pipe({\n name: 'bytes',\n standalone: true\n})\nexport class BytesPipe implements PipeTransform {\n\n /**\n * Format bytes as human-readable text.\n *\n * @param bytes Number of bytes.\n * @param si True to use metric (SI) units, aka powers of 1000. False to use\n * binary (IEC), aka powers of 1024.\n * @param dp Number of decimal places to display.\n *\n * @return Formatted string.\n *\n * Credit: https://stackoverflow.com/questions/10420352/converting-file-size-in-bytes-to-human-readable-string\n */\n transform(bytes: number, si=true, dp=1): string {\n const thresh = si ? 1000 : 1024;\n\n if (Math.abs(bytes) < thresh) {\n return bytes + ' B';\n }\n\n const units = si\n ? ['kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']\n : ['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];\n let u = -1;\n const r = 10**dp;\n\n do {\n bytes /= thresh;\n ++u;\n } while (Math.round(Math.abs(bytes) * r) / r >= thresh && u < units.length - 1);\n\n const fixed = bytes.toFixed(dp);\n if ((fixed + '').endsWith('.0')) {\n return bytes.toFixed(0) + ' ' + units[u];\n }\n\n return fixed + ' ' + units[u];\n }\n\n}\n"], "mappings": "yCAMA,IAAaA,GAAS,IAAA,CAAhB,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,iDAtCWT,EAAS,CAAA,6CAATA,EAASgB,KAAA,GAAAC,WAAA,EAAA,CAAA,CAAA,SAATjB,CAAS,GAAA", "names": ["BytesPipe", "transform", "bytes", "si", "dp", "thresh", "Math", "abs", "units", "u", "r", "round", "length", "fixed", "toFixed", "endsWith", "pure", "standalone"] }