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

@invilite/date

v1.1.1

Published

Extends native JavaScript Date object by adding new methods.

Downloads

1

Readme

@invilite/date

Codacy Badge Maintainability Test Coverage Known Vulnerabilities Version License

Unit tests

Extends native Date object by adding new methods.

Highlights

  • No overriding built-in methods
  • No dependencies
  • Focus on high performance
  • TypeScript type definitions included

Install

This is a Node.js module available through the npm registry.

Using npm:

$ npm install @invilite/date

Using bower:

$ bower install @invilite/date

Using yarn:

$ yarn add @invilite/date

Usage

import "@invilite/date";

const date = new Date();

// Outputs: 2022-04-08 14:30:00.0
console.log(date.format("YY-MM-D HH:mm:ss.S"));

Methods

format()

Return the formatted date string in the given format, optionally converts to different timezone.

Syntax

format(format: string, locales?: string | string[], timezoneName?: string): string;

Example

const date = new Date();
const formattedDate = date.format("YY-MM-D HH:mm:ss.S");
const date = new Date("2022-04-18 15:30:00 +01:00");

// Convert time to Tokyo timezone
const formattedTime = date.format("YY-MM-D HH:mm:ss.S", "en-US", "Asia/Tokyo");

Accepted patterns:

| Pattern | Description | Example | |:-------:|----------------------------------------------------------|:----------:| | Y | A two digit representation of a year | 22 | | YY | A full numeric representation of a year | 2022 | | M | Numeric representation of a month, without leading zeros | 3 | | MM | Numeric representation of a month, with leading zeros | 03 | | B | Full month name | January | | b | Short month name | Jan | | D | Day of the month without leading zeros | 9 | | DD | Day of the month, 2 digits with leading zeros | 09 | | w | Numeric representation of the day of the week | 05 | | W | Week of the year | 28 | | H | 24-hour format of an hour without leading zeros | 17 | | HH | 24-hour format of an hour with leading zeros | 17 | | h | 12-hour format of an hour without leading zeros | 9 | | hh | 12-hour format of an hour with leading zeros | 09 | | m | Minutes without leading zeros | 5 | | mm | Minutes with leading zeros | 05 | | s | Seconds without leading zeros | 0 | | ss | Seconds with leading zeros | 00 | | S | Milliseconds without leading zeros | 34 | | SS | Milliseconds with leading zeros | 034 | | a | Lowercase Ante meridiem and Post meridiem | am | | A | Uppercase Ante meridiem and Post meridiem | AM | | z | Timezone offset in minutes | -120 | | Z | Timezone offset in standard format | +02:00 | | X | Unit timestamp (in seconds) | 1659306131 |

toUnixTimestamp()

Get the seconds timestamp of the given date.

Syntax

toUnixTimestamp(): number;

Example

const date = new Date();
const timestamp = date.toUnixTimestamp();

addSeconds()

Add the specified number of seconds to the given date. Returns current object with the seconds added.

Syntax

addSeconds(seconds: number): Date;

Example

const date = new Date();
date.addSeconds(600);

diffFrom()

Get number of seconds, that represents time difference between two dates.

Syntax

diffFrom(date: Date | string = new Date()): number;

Example

const date = new Date("2022-04-18 15:50:40");
const futureDate = new Date("2022-04-18 14:30:00");

console.log(date.diffFrom(futureDate));
// Outputs: 4840

textDiffFrom()

Get formatted string (in English), that represents time difference between two dates.

Syntax

textDiffFrom(date: Date): string;

Example

const date = new Date("2022-04-18 15:50:40");
const futureDate = new Date("2022-04-18 14:30:00");

console.log(date.textDiffFrom(futureDate));
// Outputs: '1 hour, 20 minutes, 40 seconds'

Browser support

TBD

License

Library is licensed under a GNU General Public License v3.0