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

timerizer

v1.0.0

Published

ActiveSupport time stuff in JS

Downloads

3

Readme

TimerizerJS

A neat little utility for working with relative times in JavaScript.

(2).days.ago(); // Sat Jan 03 2015 18:00:00 GMT+0000 (GMT)

Neat.

I stole the name from Timerizer, which is written in Ruby and based on Ruby on Rails' ActiveSupport, which is also what this was based on.

Installation

Either download the repo and just include timerizr.js or build/timerizer.min.js into your project (using AMD, CommonJS or just good old globals), or install through npm using npm install timerizer.

Usage

There are two main ways to call Timerizer; you can either use the Timerizer constructor function, or you can call one of the time methods directly on number objects.

Timerizer(4).weeks.ago();

// Or you can call it directly on numbers
(4).weeks.ago();

This does involve adding a load of properties to Number.prototype—if this concerns you, there will be a way to disable that behaviour soon.

Time methods

Time methods are the ones you call on the number, and are specifying the type of interval of time.

The available time methods are seconds, minutes, hours, days, weeks, and fortnights. There are also singular versions of all those methods.

(4).seconds.ago();
(10).hours.ago();
(1).fortnight.ago();

Calculation methods

(I don't like this name. Feel free to suggest better.)

The calculation methods are four methods used to get the actual Date object.

In the past

We've met one of these already, the .ago() method. The following will return a Date object for four hours ago:

(4).hours.ago();

Pretty simple. You can also give it an argument containing a time to generate the Date from: e.g., you can specify that you want the time two hours before a given time. That doesn't make much sense as the ago method, so there is an until method aliased to ago:

(4).hours.until(myTime);

In the future

The two methods for getting times in the future are called fromNow and since, and they behave in pretty much the same way that the methods for getting times in the past do.

(4).hours.fromNow();
(4).hours.since(myTime);

Developing

If you want to contribute (thank you!), you'll need to clone the repository and install the dependencies using npm install. Run the tests before sending a pull request (npm test), and try to avoid sending a pull request from the master branch.

License

This library is released under an MIT license.