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

@eartharoid/dtf

v2.0.1

Published

A simple date and time formatter.

Downloads

626

Readme

dtf

GitHub Workflow Status

Simple and somewhat-localised timestamp formatting.

Note that in some cases, especially if you want to use standard formats and in other locales, it may be better to use the built-in Date or Intl functions.

Installation

Install with npm/pnpm/yarn:

npm i @eartharoid/dtf

Usage

const DTF = require('@eartharoid/dtf');
const dtf = new DTF();

// a new `Date` will be created
const timestamp = dtf.fill('DD/MM/YYYY HH:mm:ss');
console.log(timestamp); // => `13/07/2021 14:44:51`

// custom `Date` and use UTC time
const timestamp = dtf.fill('DD/MM/YYYY HH:mm:ss', new Date(), true);
console.log(timestamp); // => `13/07/2021 13:44:51`

See DTF#fill.

Placeholders

|Placeholder|Description|Example| |-|-|-| |YYYY|The full year number|2021| |YY|The short year number|21| |MMMM|The full month name|July| |MMM|The short month name|Jul| |MM|The zero-padded month number|07| |M|The non-padded month number|7| |DDDD|The full day name|Tuesday| |DDD|The short day name|Tue| |DD|The zero-padded date number|13| |D_|The date followed by its ordinal suffix|13th| |D|The non-padded date number|13| |HH|The zero-padded 24h hour number|14| |hh|The zero-padded 12h hour number|02| |h|The non-padded 12h hour number|2| |mm|The zero-padded minute number|18| |m|The non-padded minute number|18| |ss|The zero-padded second number|09| |s|The non-padded second number|9| |SSS|The zero-padded millisecond number|638| |AMPM|AM or PM|PM|

API

new DTF(locale?)

Create a new DTF instance.

  • locale? - the locale of this DTF instance (default is 'en')

DTF#locale

The locale of this DTF instance.

DTF#fill(format?, date?, utc?)

Fill a given or the default timestamp format using the current date or the Date provided.

  • format? - the placeholder string (default is 'HH:mm:ss')
  • date? - the Date object used to fill the placeholders (defaults to a new Date object)
  • utc? - use UTC time? (default is false)

DTF#AMPM(date?, utc?)

Returns 'AM' or 'PM' based on the time

  • date? - the date to use (defaults to a new Date object)
  • utc? - use UTC time? (default is false)

DTF#suffix(number)

Appends st, nd, rd, or th to the given number for an English locale. I don't know what it does for other locales.

  • number - the number to append the ordinal suffix to

DTF#convert24To12(h)

Converts a 24h number to 12h.

  • h - the 24h number

Support

Discord support server

Donate

ko-fi

or sponsor me.

License

MIT license.

© 2021 Isaac Saunders