Module: common/human

Utitities for working with human friendly I/O.
Source:

Members

(static, constant) GB :number

Type:
  • number
Source:

(static, constant) KB :number

Type:
  • number
Source:

(static, constant) MB :number

Type:
  • number
Source:

(static, constant) PB :number

Type:
  • number
Source:

(static, constant) TB :number

Type:
  • number
Source:

Methods

(static) bytes(b, unit) → {string}

Formats the amount of bytes in a human friendly format. unit may be supplied to indicate b is not in bytes, but in something like kilobytes (KB) or megabytes (MB)
Parameters:
Name Type Description
b number The number of bytes in units 'unit'.
unit number The number of bytes per unit.
Source:
Returns:
Type
string
Examples
// returns "1 KB"
bytes(1234)
// returns "5 GB"
bytes(5321, MB)

(static) diffDate(milliseconds) → {string}

Returns the difference between the current time and 's' as a string in a human friendly format. If 's' is a number it is assumed to contain the time in milliseconds otherwise it is assumed to contain a time string parsable by Date.parse(). For example, a difference of 123 seconds between 's' and the current time would return "2m".
Parameters:
Name Type Description
milliseconds Object The time in milliseconds or a time string.
Source:
Returns:
Type
string

(static) localeTime(date) → {string}

localeTime formats the provided Date object in locale time and appends the timezone to the end.
Parameters:
Name Type Description
date Date
Source:
Returns:
Type
string

(static) pad(num, size) → {string}

Left pad a number with 0's.
Parameters:
Name Type Description
num number The number to pad.
size number The number of digits to pad out to.
Source:
Returns:
Type
string

(static) strDuration(seconds) → {string}

Returns a human-readable format of the given duration in seconds. For example, 'strDuration(123)' would return "2m 3s". Negative seconds is treated the same as positive seconds.
Parameters:
Name Type Description
seconds number The duration.
Source:
Returns:
Type
string