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

showtimeago

v3.3.13

Published

Show Time Ago is a utility that allows you to see how long ago a date was.

Downloads

20

Readme

Show Time Ago Utility

GPLv3 License Test showTimeAgo Utility PRs Welcome

Developed by Jackie Santana

This an Open Source utility project. I welcome any & all contributions via the development branch only.

What is Show Time Ago?

Show Time Ago is a utility that allows you to see how long ago a date was. Just add in your ISO date: showTimeAgo("2022-06-20T13:42:29-05:00") and this utility will dynamically update the time with the suffix 'ago'. ex: 2 minutes ago 1 hour ago.. 2 days ago.. 1 month ago.. 1 year ago..

List of time suffixes:
  • minutes, hours, days, weeks, months, years 'ago..'
Default: showTimeago updates on page reload

dynamically update time without page reload? code examples shown below

Installation

To install this utility, you need to install the following dependencies:

npm i showtimeago or npm install showtimeago


Usage

Import

  • ES6: import showTimeAgo from 'showtimeago'
  • commonJS: const showTimeAgo = require('showtimeago')

ex:

//vanilla javascript
showTimeAgo("2022-06-20T13:42:29-05:00")

//in react
{showTimeAgo('2022-07-02T23:12:01.449Z')}

console.log(showTimeAgo('2022-07-02T23:12:01.449Z'))

This utility only takes in a newDate() format time, for example: new Date().toISOString() outputs: 2022-07-02T23:12:01.449Z ISO date format

CDN:

  • https://cdn.jsdelivr.net/npm/showtimeago/index.js
  • https://unpkg.com/browse/showtimeago/index.js

This essentially a common Js module so ignore error: Uncaught ReferenceError: module is not defined at showTimeAgo.js:115:1 via client side.

CDN Set up:

<script crossorigin type="text/javascript" src="https://unpkg.com/browse/showtimeago/index.js"></script>

const showTimeAgo = showtimeago

console.log(showTimeAgo(new Date()))

Yarn: https://yarnpkg.com/package/showtimeago yarn add showtimeago


By default showTimeAgo only updates on page reload

How to show showTimeAgo updated time without a page reload ?

Vanilla Javascript Example:

const showTimeAgo = require('showtimeago');

 let showPastTime = showTimeAgo('2022-07-02T23:12:01.449Z')
 const showTimeAgoToBrowser = document.querySelector('div')
 showTimeAgoToBrowser.innerHTML = `${showPastTime}`;

setInterval(() => {
    showPastTime = showTimeAgo('2022-07-02T23:12:01.449Z')
    showTimeAgoToBrowser.innerHTML = `${showPastTime}`;

    // 600000 = 1 minute in ms
}, 60000)

clearInterval(showPastTime)

React Example:

import * as React from "react";
import showTimeAgo from "showtimeago";

export default function App() {
  const [showPastTime, setPastTime] = React.useState(null);

  React.useEffect(() => {
    setPastTime(showTimeAgo('2022-07-02T23:12:01.449Z'));

    const timer = window.setInterval(() => {
      setPastTime(showTimeAgo('2022-07-02T23:12:01.449Z'));

      // 600000 = 1 minute in ms
    }, 60000);

    return () => window.clearInterval(timer);
  }, [showPastTime]);

  return <div>User Posted Comment { showPastTime }</div>;
}

With the code above ShowTimeAgo will dynamically change per minute without a page reload

Contributing


  1. Fork it (https://github.com/yourname/yourproject/fork)
  2. Create your feature branch (git checkout -b feature/fooBar)
  3. Commit your changes (git commit -am 'Add some fooBar')
  4. Push to the branch (git push origin feature/fooBar)
  5. Create a new Pull Request