npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

time-ago.js

v1.0.0

Published

A simple library to used to format datetime

Downloads

43

Readme

A simple library to used to format datetime

提取自 Vidahouse 社区中的格式化时间的插件,功能单一,并没有做绑定dom定时刷新的功能。 在社区项目中 数据库返回的是 评论对象、文章对象。其中发表时间为一个Unix时间戳。 有些地方将使用timeago处理过的时间通过 pug渲染。 另外一些地方则通过 React.js 或者 Vue.js 进行绑定。 由于本方法其实很简单,核心不超过20行。 所以只实现一个纯函数,绑定等操作自己进行即可。

刚刚
1分钟前
23分钟前
1天前
2天前
28天前
5月前
4年前

Install

通过npm安装

npm install timeago.js

或者使用 script 引入

<script src="dist/time-ago.min.js" type="text/javascript"></script>

可以使用ES6的 import 引入

import timeago from 'timeago.js';

使用

timeago(Date.now())  // =>  '刚刚'
timeago(Date.now(), 'en')  // =>  'just now'

// Unix 时间戳 (s)
timeago(1462377600)  // =>  '1年前'

// JavaScript 时间戳 (ms)
timeago(1462377600000)  // =>  '1年前'

致谢

在此,我情不自禁,想背诵一段《共产党宣言》: 一个幽灵,共产主义的幽灵,在欧洲徘徊。旧欧洲的一切势力,教皇和沙皇、梅特涅和基佐、法国的激进党人和德国的警察,都为驱除这个幽灵而结成了神圣同盟。