TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

JS Humanize (Give data a human touch)

40 点作者 mvrekic大约 13 年前
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 条评论

callumjones大约 13 年前
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 未加载
ctz大约 13 年前
<p><pre><code> filesizeformat (1234567890 = 1.15 Gb) </code></pre> This should be either 9.20 Gb or 1.15 GB.
sirn大约 13 年前
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 未加载
whalesalad大约 13 年前
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>
chrisbroadfoot大约 13 年前
Two things:<p>1) Gb should be GiB<p>2) it would be lovely to see some internationalisation support.
chris_wot大约 13 年前
This might need some internationalization support...
评论 #3847114 未加载
评论 #3846106 未加载
评论 #3846018 未加载
mahmud大约 13 年前
All of them are built into Play Framework, fwiw.