TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

JS Humanize (Give data a human touch)

40 pointsby mvrekicabout 13 years ago
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.

7 comments

callumjonesabout 13 years ago
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.
评论 #3845681 未加载
评论 #3845498 未加载
评论 #3845599 未加载
评论 #3845867 未加载
ctzabout 13 years ago
<p><pre><code> filesizeformat (1234567890 = 1.15 Gb) </code></pre> This should be either 9.20 Gb or 1.15 GB.
sirnabout 13 years ago
Nice idea, but seems to lack of any input escaping.<p><pre><code> =&#62; Humanize.truncatechars("&#60;script&#62;alert('yo');&#60;\/script&#62;", 30) "&#60;script&#62;alert('yo');&#60;/script&#62;" =&#62; Humanize.linebreaks("&#60;script&#62;alert('yo');&#60;\/script&#62;") "&#60;p&#62;&#60;script&#62;alert('yo');&#60;/script&#62;&#60;/p&#62;" </code></pre> Bug filed.
评论 #3846026 未加载
whalesaladabout 13 years ago
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: <a href="https://forrst.com/posts/JavaScript_Shorten_Function-1up" rel="nofollow">https://forrst.com/posts/JavaScript_Shorten_Function-1up</a>
chrisbroadfootabout 13 years ago
Two things:<p>1) Gb should be GiB<p>2) it would be lovely to see some internationalisation support.
chris_wotabout 13 years ago
This might need some internationalization support...
评论 #3847114 未加载
评论 #3846106 未加载
评论 #3846018 未加载
mahmudabout 13 years ago
All of them are built into Play Framework, fwiw.