Live data from Hacker News

JS Humanize (Give data a human touch)

github.com

1–10 of 25 posts

JS Humanize (Give data a human touch)

#1
If you are familiar with Django you are familiar with a nice set of template tags called "humanize". In essence it turns data such as "13 April 2012" into "2 days ago" or "1000000000" into "1.0 billion". JS Humanizer is a jQuery counterpart to the Django humanize template tags we wrote and thought that others might find it useful too.

JS Humanize (Give data a human touch)
github.com

Re: JS Humanize (Give data a human touch)

#3

Is it possible to have these in a stand alone library/namespace without the need for bringing the whole of jQuery with it? Not everyone uses jQuery in their JS application and it certainly would aid those who perform server-side JS.

IMO it's especially heinous because I didn't see a single piece of jQuery use in the code (I may have missed it, though). All they seem to be requiring jQuery for is to add to the $ namespace.

That pedantry aside, it seems like a decent enough chunk of code, and it's very easy to read. More libraries should be this clean.

Re: JS Humanize (Give data a human touch)

#4

Is it possible to have these in a stand alone library/namespace without the need for bringing the whole of jQuery with it? Not everyone uses jQuery in their JS application and it certainly would aid those who perform server-side JS.

This is perhaps an inelegant solution but i've found it useful sometimes, you can get standalone functions of most of these by using a JS port of PHP functions called phpjs (phpjs.org), while i understand PHP is as cool as toe fungus on HN right now, its a solution.

EDIT: Actually having now looked at the code, it seems a lot of it is specifically using the phpjs library.

Re: JS Humanize (Give data a human touch)

#5

Is it possible to have these in a stand alone library/namespace without the need for bringing the whole of jQuery with it? Not everyone uses jQuery in their JS application and it certainly would aid those who perform server-side JS.

I've removed the jQuery dependency and submitted a pull request (https://github.com/milanvrekic/JS-humanize/pull/1).

Re: JS Humanize (Give data a human touch)

#7

Is it possible to have these in a stand alone library/namespace without the need for bringing the whole of jQuery with it? Not everyone uses jQuery in their JS application and it certainly would aid those who perform server-side JS.

jQuery bit was originally intended to make it compatible with require.js loading; chetan51, Groxx - thanks for pointing it out. We removed that bit but we missed the dependancy, removed now thanks to chetan51

Re: JS Humanize (Give data a human touch)

#8
This is great! I love how it aligns with the Django templating system as well =) Although I do agree that this might be better off a something that is framework independent. A while ago I posted an example on Forrst of how you might write a simple and pure-js shorten function: https://forrst.com/posts/JavaScript_Shorten_Function-1up
Post reply on HN