Skip to content

Instantly share code, notes, and snippets.

@vbilopav
Created September 16, 2026 12:07
Show Gist options
  • Select an option

  • Save vbilopav/9ae744082cbee9cd2e7277dd10e36a17 to your computer and use it in GitHub Desktop.

Select an option

Save vbilopav/9ae744082cbee9cd2e7277dd10e36a17 to your computer and use it in GitHub Desktop.
// @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