


// -------------------------------------------------------------------
// Dependencies

// Import

// Built-in

// Mine
const MIN = 60
const HOUR = MIN * 60
const DAY = HOUR * 24
const WEEK = DAY * 7
const MONTH = DAY * 30
const YEAR = DAY * 365




// -------------------------------------------------------------------
// Properties


const pluralize = (time, label) => `${time} ${label}${(time >= 1) ? 's' : ''}`



// -------------------------------------------------------------------
// Exports

export const timeAgo = dte => {
  if(!(dte instanceof Date)) dte = new Date(dte)
  const ago = (Date.now() - dte.getTime()) / 1000
  // ~~ Bitwise Operation : Make int positive
  if (ago < MIN) {
    return pluralize(~~(ago), ' sec')
  } else if (ago < HOUR) {
    return pluralize(~~(ago / MIN), ' min')
  } else if (ago < DAY) {
    return pluralize(~~(ago / HOUR), ' hour')
  } else if (ago < WEEK) {
    return pluralize(~~(ago / DAY), ' day')
  } else if (ago < MONTH) {
    return pluralize(~~(ago / WEEK), ' week')
  } else {
    return pluralize(~~(ago / YEAR), ' year')
  }
}
@@ -243,16 +243,55 @@
  * 365%0A%0A
+const UNITS = %5B'B', 'kB', 'Mb', 'Gb'%5D;%0A
 %0A%0A%0A// --
@@ -1121,8 +1121,595 @@
 ')%0A  %7D%0A%7D
+%0A%0A%0Aexport const sizeHuman = size =%3E %7B%0A  // Ref : https://github.com/sindresorhus/pretty-bytes%0A  size = Number.parseFloat(size)%0A  if (!Number.isFinite(size)) %0A%09%09throw new TypeError(%60Expected a finite number, got $%7Btypeof size%7D: $%7Bsize%7D%60)%0A%0A%09const neg = size %3C 0;%0A%0A%09if (neg) %0A%09%09size = -size;%0A%09%0A%09if (size %3C 1) %0A%09%09return (neg ? '-' : '') + size + ' B';%0A%09%0A%09const exponent = Math.min(Math.floor(Math.log10(size) / 3), UNITS.length - 1);%0A%09const sizeStr = Number((size / Math.pow(1000, exponent)).toPrecision(3));%0A%09const unit = UNITS%5Bexponent%5D;%0A%0A%09return (neg ? '-' : '') + sizeStr + ' ' + unit;%0A%7D

Add filter to convert byte to human readable