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

date-matrix

v0.1.0

Published

Calendar date matrix generator

Downloads

330

Readme

Date Matrix

Calendar date matrix generator

Date matrix generator for NodeJS / browsers, written in Typescript.

This can be used to generate grids of days, representing a calendar month, by passing in any Date in the desired month.

Installation

Install by running npm install date-matrix --save.

Usage

Import createDateMatrix to create a date matrix object:

import { DateMatrix, createDateMatrix } from "date-matrix";

const dm: DateMatrix = createDateMatrix(new Date("2021-04-30"));
// {
//     weekdays: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
//     weeks: [
//         // ...
//     ]
// }

weeks is an array of weeks (rows), representing Monday-Sunday in a calendar grid (or Sunday-Saturday when using { firstDay: "sunday" }).

Each day object looks like the following:

{
    day: 30,
    date: Date(),
    type: "current"
}

To just render the days as-is, you could use a helper function like so:

function weeksToNumbers(weeks) {
    return weeks.map(week => week.map(item => item.day));
}

const dm: DateMatrix = createDateMatrix(new Date("2021-04-30"));
const matrix = weeksToNumbers(dm.weeks);
// [
//     [29, 30, 31, 1, 2, 3, 4],
//     [5, 6, 7, 8, 9, 10, 11],
//     [12, 13, 14, 15, 16, 17, 18],
//     [19, 20, 21, 22, 23, 24, 25],
//     [26, 27, 28, 29, 30, 1, 2]
// ]

createDateMatrix

The function takes two parameters:

createDateMatrix(date: Date, options?: DateMatrixOptions) => DateMatrix

| Parameter | Type | Required | Description | |-------------------|-------------------|-----------|---------------------------------------| | date | Date | Yes | The target date, with which to generate the date matrix from (using its month). | | options | DateMatrixOptions| No | Options for the matrix creation. |

With the options parameter supporting the following properties:

| Property | Default | Description | |-------------------|-------------------|---------------------------------------------------| | firstDay | monday | The first day of the week, either monday or sunday. | | locale | undefined | The locale to use for date handling, eg. en-GB. | | weekdayFormat | short | The Date function weekday format, either short or long. |