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

use-custom-dates

v1.0.3

Published

This npm package, named 'use-custom-dates', provides a utility function called useCustomDates that generates a customizable date range based on the current date. The function returns an object containing information about the current date, the previous ye

Downloads

2

Readme

use-custom-dates

JavaScript PRs Welcome Version License Downloads Contributors GitHub Issues

This npm package, named "use-custom-dates", provides a utility function called useCustomDates that generates a customizable date range based on the current date. The function returns an object containing information about the current date, the previous year's date, and an array representing the labels for the last 7 days, including the day of the month and the corresponding month name.

Key Features

  • Dynamic calculation of the current date, including day of the week, month, year, and leap year status.
  • Generation of a date range for the last 7 days, with customizable labels based on the day of the month and the corresponding month name.
  • Consideration of month lengths and leap years in the date calculations.

Installation

npm install use-custom-dates

Usage

const useCustomDates = require("use-custom-dates")

// Get date-related information
const dateInfo = await useCustomDates()

// Access properties from the returned object
console.log(dateInfo)

####Output

{
  current: {
    todayDate: '07',
    weekDay: 'Sunday',
    month: '01',
    year: 2024,
    date: '07/01/2024',
    monthName: 'January',
    monthLength: 31,
    isLeapYear: true
  },
  previous: { year: 2023, month: 12, monthLength: 31, monthName: 'December' },
  allMonths: [
    { month: 'January', shortName: 'Jan', numOfDays: 31, weeks: 5 },
    { month: 'February', shortName: 'Feb', numOfDays: 29, weeks: 4 },
    { month: 'March', shortName: 'Mar', numOfDays: 31, weeks: 5 },
    { month: 'April', shortName: 'Apr', numOfDays: 30, weeks: 5 },
    { month: 'May', shortName: 'May', numOfDays: 31, weeks: 5 },
    { month: 'June', shortName: 'Jun', numOfDays: 30, weeks: 5 },
    { month: 'July', shortName: 'Jul', numOfDays: 31, weeks: 5 },
    { month: 'August', shortName: 'Aug', numOfDays: 31, weeks: 5 },
    { month: 'September', shortName: 'Sep', numOfDays: 30, weeks: 5 },
    { month: 'October', shortName: 'Oct', numOfDays: 31, weeks: 5 },
    { month: 'November', shortName: 'Nov', numOfDays: 30, weeks: 5 },
    { month: 'December', shortName: 'Dec', numOfDays: 31, weeks: 5 }
  ],
  last7days: {
    from_date: 1,
    to_date: 7,
    L7D: [
        { label: '1 January' },
        { label: '2 January' },
        { label: '3 January' },
        { label: '4 January' },
        { label: '5 January' },
        { label: '6 January' },
        { label: '7 January' }
    ]
  }
}

Returned Object Properties

current

  • todayDate: Day of the month with leading zero.
  • weekDay: Day of the week (e.g., "Monday").
  • month: Month with leading zero.
  • year: Current year.
  • date: Full date string in UK format.
  • monthName: Full name of the current month.
  • monthLength: Number of days in the current month.
  • isLeapYear: Leap year status for the current year.

previous

  • year: Previous year.
  • month: Previous month with leading zero.
  • monthLength: Number of days in the previous month.
  • monthName: Full name of the previous month.

allMonths: Array containing information about all months.

last7days

  • from_date: Start date of the last 7 days' range.
  • to_date: End date of the last 7 days' range.
  • L7D: Array of objects representing the last 7 days' date range labels. Each object has a label property containing the day of the month and the corresponding month name.

Examples

// Example 1: Accessing current date information
console.log(dateInfo.current.todayDate)
console.log(dateInfo.current.weekDay)

// Example 2: Accessing last 7 days' date range labels
console.log(dateInfo.last7days.L7D)

License

This project is licensed under the ISC License - see the LICENSE.md file for details.

Author

Suraj Aswal

Repository

GitHub Repository