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names":[],"sources":["src/components/util/format-bytes/sc-format-bytes.css?tag=sc-format-bytes&encapsulation=shadow","src/components/util/format-bytes/sc-format-bytes.tsx"],"sourcesContent":[":host {\n display: inline-block;\n}\n","import { Component, Prop } from '@stencil/core';\n\n@Component({\n tag: 'sc-format-bytes',\n styleUrl: 'sc-format-bytes.css',\n shadow: true,\n})\nexport class ScFormatBytes {\n /** The locale to use when formatting the number. */\n @Prop() locale: string;\n\n /** The number to format in bytes. */\n @Prop() value: number = 0;\n\n /** The unit to display. */\n @Prop() unit: 'byte' | 'bit' = 'byte';\n\n /** Determines how to display the result, e.g. \"100 bytes\", \"100 b\", or \"100b\". */\n @Prop() display: 'long' | 'short' | 'narrow' = 'short';\n\n render() {\n if (isNaN(this.value)) {\n return '';\n }\n\n const bitPrefixes = ['', 'kilo', 'mega', 'giga', 'tera']; // petabit isn't a supported unit\n const bytePrefixes = ['', 'kilo', 'mega', 'giga', 'tera', 'peta'];\n const prefix = this.unit === 'bit' ? bitPrefixes : bytePrefixes;\n const index = Math.max(0, Math.min(Math.floor(Math.log10(this.value) / 3), prefix.length - 1));\n const unit = prefix[index] + this.unit;\n const valueToFormat = parseFloat((this.value / Math.pow(1000, index)).toPrecision(3));\n\n return new Intl.NumberFormat(this.locale, { style: 'unit', unit, unitDisplay: this.display } as any).format(valueToFormat);\n }\n}\n"],"version":3}