Created
September 16, 2026 12:07
-
-
Save vbilopav/9ae744082cbee9cd2e7277dd10e36a17 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // @ts-check | |
| // @description A numeric column named *size or *bytes reads as KB, MB, GB | |
| // @color green | |
| // A NUMBER column whose name ends in size or bytes reads as a human size | |
| // (KB, MB, GB ...), right aligned. The match ANDs the name and a numeric | |
| // type, so a text column is left alone. Edit the pattern to your columns. | |
| /** @type {PlumeExtension} */ | |
| export default [ | |
| { | |
| match: { name: /(size|bytes)$/i, type: /^(smallint|integer|bigint|numeric|real|double)/ }, | |
| fn: (value) => { | |
| let n = Number(value) | |
| if (!Number.isFinite(n)) return value | |
| const units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'] | |
| let u = 0 | |
| while (n >= 1024 && u < units.length - 1) { n /= 1024; u++ } | |
| const text = (u === 0 ? n : n.toFixed(1)) + ' ' + units[u] | |
| return { value: text, align: 'right' } | |
| } | |
| } | |
| ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment