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

eg-datetime-helper

v1.0.1

Published

A helpful library for date and time operations

Downloads

5

Readme

eg-datetime-helper

A lightweight JavaScript library to simplify date and time handling.

Link to NPM package

https://www.npmjs.com/package/eg-datetime-helper

Installation

You can install eg-datetime-helper using npm:

npm install eg-datetime-helper

Usage

Import the D`` class from eg-datetime-helper`` and create an instance to easily work with dates and times.

import { D } from 'eg-datetime-helper';

const d = new D(2023, 7, 21, 15, 30, 0);

console.log(d.year);        // 2023
console.log(d.month);       // August
console.log(d.date);        // 21
console.log(d.format());    // "2023 August 21"
console.log(d.when());      // "2 days from now"

Features

  • Get various date and time components such as year, month, day, hours, minutes, and seconds.
  • Format dates using customizable masks (e.g., "Y-M-D h:I:S" or "y/m/d").
  • Get human-readable time difference with the when() method (e.g., "2 days from now").

API

Class: D The D class class provides various methods and properties to work with dates and times.

Constructor Create a new instance of the D class:

const d = new D(year, month, day, hours, minutes, seconds);
  • year (optional): Year value (default: current year).
  • month (optional): Month value (0-based index, default: current month).
  • day (optional): Day value (default: current day).
  • hours (optional): Hours value (default: 0).
  • minutes (optional): Minutes value (default: 0).
  • seconds (optional): Seconds value (default: 0).

Properties

  • year: Full year (4 digits).
  • yr: Short year (2 digits).
  • month: Full month name (e.g., "January").
  • mon: Short month name (e.g., "Jan").
  • day: Full day name (e.g., "Monday").
  • dy: Short day name (e.g., "Mon").
  • date: Day of the month (1-31).
  • hours: Hour value (0-23).
  • mins: Minute value (0-59).
  • secs: Second value (0-59).

Methods

  • format(mask): Format the date using the provided mask. Available mask characters:
    • Y: Full year (4 digits).
    • y: Short year (2 digits).
    • M: Full month name.
    • m: Short month name.
    • D: Zero-padded day of the month.
    • d: Day of the month.
    • #: Suffixed day of the month (e.g., "1st", "2nd").
    • H: Zero-padded hour (24-hour format).
    • h: Hour (24-hour format).
    • I: Zero-padded minute.
    • i: Minute.
    • S: Zero-padded second.
    • s: Second.
  • when(): Get a human-readable time difference between the current date and the instance date. Returns values like "3 days from now" or "1 year 2 months ago".