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

speed-date

v1.0.0

Published

Format dates super-efficiently

Downloads

4,378

Readme

speed-date

Travis Dependencies Join the chat at https://gitter.im/gosquared/speed-date

NPM

Format your dates really really fast

So you have a date object in JavaScript. And you want to turn it into a string. Perhaps you want to format it a particular way, say YYYY-MM-DD HH:mm:ss.

Speed-date is a super-fast date formatter optimized for formatting lots of dates with the same format.

Installation

npm install speed-date

Usage

var speedDate = require('speed-date');

var theDate = new Date(2006, 1, 3, 12, 34, 56);

var formatter = speedDate('YYYY-MM-DD HH:mm:ss');

formatter(theDate); // '2006-02-03 12:34:56'


// alternatively:
speedDate('YYYY-MM-DD HH:mm:ss', theDate); // '2006-02-03 12:34:56'

// alternatively alternatively:
// faster when repeated lots with the same format,
// useful as an alternative to keeping track of formatter as above
speedDate.cached('YYYY-MM-DD HH:mm:ss', theDate); // '2006-02-03 12:34:56'

Full API

speedDate(format[, date])

When called with just format, generates a formatter function that takes date objects.

When called with both format and date, creates a formatter function and applies it with the given date.

speedDate.cached(format[, date])

Behaves the same as speedDate, but the generated formatter function is stored and reused if the same format is used again. Only use this if you know you're only going to be using a few different possible formats (they're never cleaned up internally).

speedDate.UTC(format[, date])

Exactly the same as above, but always interprets the date as UTC. Obviousy, in this mode, Z and ZZ tokens will always be +00:00 and +0000 respectively. Similarly speedDate.UTC.cached(format[, date]).

But how fast is it actually?

Well, run npm run benchmark to find out for yourself how it stacks up against Moment for various formatting tokens. On the whole speed-date is ~15-20x faster than Moment with repeated use of the same formatter function. Check out benchmark results for an example run.

Is there any error handling or input validation?

Nope. None at all. In the interests of performance, speed-date assumes that you're always passing in valid Date objects and sane formatting strings. If you give it an invalid Date, it won't handle it nicely, like how Moment returns "Invalid date". It'll probably return something with NaN and undefined all over the place. If you give it something that isn't a Date object at all, there's no telling what it'll do. It might return complete garbage, it might throw an error, it might set fire to your dog. So be careful.