A JS library for adding a “human touch” to data.
JavaScript
Pull request Compare This branch is 23 commits ahead, 24 commits behind milanvrekic:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
LICENSE
README.md
humanize.js
humanize.min.js
tests.html

README.md

JS library useful for adding a “human touch” to data.

Functions available:

humanize.noConflict()

Give control of the "humanize" variable back to its previous owner. Returns a reference to the humanize object.

humanize.time()

Retrieves the current time in seconds

humanize.date(format [, timestamp / JS Date Object = new Date()])

This is a port of php.js date and behaves exactly like PHP's date

humanize.numberFormat(number [, decimals = 2, decPoint = '.', thousandsSep = ','])

Format a number to have decimal significant decimal places, using decPoint as the decimal separator, and thousandsSep as thousands separater

humanize.naturalDay(timestamp [, format = 'd.m.Y'])

Returns 'today', 'tomorrow' or 'yesterday', as appropriate, otherwise format the date using the passed format with humanize.date()

humanize.naturalDateTime(timestamp [, format = 'd.m.Y'])

Returns 'today', 'tomorrow' or 'yesterday', as appropriate WITH time

humanize.relativeTime(timestamp)

Returns a relative time to the current time, seconds as the most granular up to years to the least granular.

humanize.ordinal(integer)

Converts a number into its ordinal representation.

humanize.filesize(filesize [, kilo = 1024, decimals = 2, decPoint = '.', thousandsSep = ','])

Converts a byte count to a human readable value using kilo as the basis, and numberFormat formatting

humanize.linebreaks(string)

Converts a string's newlines into properly formatted html ie. one new line -> br, two new lines -> p, entire thing wrapped in p

humanize.nl2br(string)

Converts a string's newlines into br's

humanize.truncatechars(string, length)

Truncates a string to length-1 and appends '…'. If string is shorter than length, then no-op

humanize.truncatewords(string, numWords)

Truncates a string to only include the first numWords words and appends '…'. If string has fewer words than newWords, then no-op