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

@craftykate/kates-dates

v1.3.0

Published

Kate's date package

Downloads

3

Readme

Kate's Dates

Lightweight helper functions for date objects in Javascript

Introduction

I can never remember how to figure out how many days in the month there are, or how to get the day of the week, or how to get the day of the month but pad it with zeros. So I made a lightweight package to do these for me that makes intuitive sense to me.

(This is a brand new package and I intend to add more functionality as I need it or think of it!)

Installation

  • Run npm i @craftykate/kates-dates in your consuming app to install

Usage

  • In the consuming file, import with import { KatesDates } from '@craftykate/kates-dates'
  • new KatesDates() takes three parameters:
    • Param 1 (required): Date object. (ex: new Date())
    • Param 2 (optional): Number - how many days away from the date you passed in. (ex: -3 would be three days earlier, 1 would be the day after)
    • Param 3 (optional): boolean - whether to set the time to 00:00:00
  • Set up a new instance of the class with:
    • Today: const d = new KatesDates(new Date())
    • Yesterday: const d = new KatesDates(new Date(), -1)
    • Tomorrow: const d = new KatesDates(new Date(), +1)
    • Today at midnight: const d = new KatesDates(new Date(), 0, true)

Available functions

  • Year
    • d.year(numDigits?: 2 | 4): yyyy (default) or yy
    • Examples:
      • d.year() or d.year(4) // 2023
      • d.year(2) // 23
  • Month in Letters
    • d.monthL(numLetters?: 1 | 3): January (default) or Jan or J
    • Examples:
      • d.monthL() // January
      • d.monthL(3) // Jan
      • d.monthL(1) // J
  • Month in Digits
    • d.monthD(minDigits?: 1 | 2)): 1-12 (default) or 01-12
    • Examples:
      • d.monthD() or d.monthD(1) // 1, 14 (no padding)
      • d.monthD(2) // 01, 14 (always two digits)
  • Month index
    • d.monthI(): 0-11
  • Month array
    • d.monthArray(): ['January', 'February'...]
  • Weekday in letters
    • d.weekdayL(numLetters?: 1 | 2 | 3): Sunday (default) or Sun or Su or S
    • Examples:
      • d.weekdayL() // Sunday
      • d.weekdayL(3) // Sun
      • d.weekdayL(2) // Su
      • d.weekdayL(1) // S
  • Weekday index
    • d.weekdayI(): // 0-6, 0 = Sunday
  • Weekday array
    • d.weekdayArray(): // ['Sunday', 'Monday', ...]
  • Date of the month
    • d.date(minDigits?: 1 | 2, isSuffix = false): 1-31 (default) or 01-31 or 1st-31st
    • Examples:
      • d.date() or d.date(1) // 1, 14 (no padding)
      • d.date(2) // 01, 14 (always two digits)
      • d.date(1, true) // 1st, 14th, 22nd (adds 'st', 'nd', 'rd' or 'th')
  • Time
    • Hour
      • d.hour(numDigits?: 1 | 2, isMilitary = false): 1-12 (default) or 01-12 or 0-23 or 00-23
      • Examples:
        • d.hour() or d.hour(1) // 1, 12 (no padding, up to 12)
        • d.hour(2) // 01, 12 (two digits, up to 12)
        • d.hour(1, true) // 0, 3, 23 (no padding, 0-23)
        • d.hour(2, true) // 00, 03, 23 (two digits, 00-23)
    • Minute
      • d.minute(): 00-59 (always two digits)
    • Second
      • d.second(): 00-59 (always two digits)
    • am / pm
      • d.ampm(numLetters?: 1 | 2, uppercase = false): am/pm (default) or a/p or AM/PM or A/P
      • Examples:
        • d.ampm() or d.ampm(2) // am, pm
        • d.ampm(1) // a, p
        • d.ampm(2, true) // AM, PM
        • d.ampm(1, true) // A, P
  • Number of days in month
    • d.daysInMonth(): 28 or 29 or 30 or 31
  • Days between
    • d.daysBetween(secondDate: Date): positive or negative number
    • Example:
      • d.daysBetween(new Date('01/01/2024')) // 199 - means 1/1/2024 is 199 days in the future as I'm writing this
      • d.daysBetween(new Date('01/01/2023')) // -166 - 1/1/2023 is 166 days in the past
  • Get date string for form date fields
    • d.fieldFormat(): yyyy-mm-dd
  • Get the entire date object
    • d.dateObj(): Date object
  • Help
    • Log out all functions available with examples using the date you have stored
    • d.help():

Examples:

const d = new KatesDates(new Date())

const wordyDate = `${d.weekdayL(3)}, ${d.monthL(3)} ${d.date(1, true)}, ${d.year()}`
console.log(wordyDate) // Fri, Jun 16th, 2023

const numberyDate =  `${d.monthD(2)}/${d.date(2)}/${d.year()}`
console.log(numberyDate) // 06/16/2023

const justTheTime = `${d.hour()}:${d.minute()}${d.ampm(1)}`
console.log(justTheTime) // 6:43p