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

calendarize

v1.1.1

Published

A tiny (202B) utility to generate calendar views

Downloads

18,361

Readme

calendarize build status codecov

A tiny (202B) utility to generate calendar views.

This function (optionally) accepts a date in exchange for a calendar view of that date's month.

The output contains no labels! This is ideal for calendar generator because it allows the developer to easily customize their labels, including full i18n/internationalization support! (Demo)

Additionally, this module is delivered as:

Install

$ npm install --save calendarize

Usage

via Date Instance

import calendarize from 'calendarize';

// Week = [Sun, Mon, Tue, Wed, Thu, Fri, Sat]
const view = calendarize(new Date('2019-12-20'));
//=> [
//=>   [ 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, 31,  0,  0,  0,  0],
//=> ]

via Date String

import calendarize from 'calendarize';

// Week = [Sun, Mon, Tue, Wed, Thu, Fri, Sat]
const view = calendarize('Nov 01, 2019');
//=> [
//=>   [ 0,  0,  0,  0,  0,  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],
//=> ]

with Weeks starting on Monday

Note: Uses the offset parameter.

import calendarize from 'calendarize';

// Week = [Mon, Tue, Wed, Thu, Fri, Sat, Sun]
const view = calendarize('Nov 01, 2019', 1);
//=> [
//=>   [ 0,  0,  0,  0,  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,  0],
//=> ]

API

calendarize(date?, offset?)

Returns: Array<Week>

An Array of Week Arrays is returned.

Each Week is an Array of 7 numbers, wherein each index is the Day of the week and each value is the numerical date. The index is forwarded from Date.getDay, which means that index: 0 is Sunday.

Important: A value of zero (0) represents a date that exists beyond the current month view.

date

Type: string | number | Date Default: new Date() – aka, today

The date you want to process.

Important: Your string|number value will be cast to a Date object, which means Node.js may apply incorrect timezone!

offset

Type: number Default: 0

A positive or negative day offset to modify which day of the week the calendar should start. This offset is relative to Sunday – so, by default, an offset of 0 will mean that your Weeks will start on Sundays.

Note: Some parts of the globe expect calendars to start on Sunday, Saturday, or Monday: see map

Example Offsets

  • Monday: 1
  • Tuesday: 2
  • ...
  • Friday: 5 or -2
  • Saturday: 6 or -1

If you use offset: 1, this means you want the Weeks to start on Monday. In turn, the 0th value of each Week array will be Monday's date.

// The first week of Jan 2020:

// start = Sunday (default)
calendarize('Jan 01, 2020');
// =>    [[0, 0, 0, 1, 2, 3, 4], ...]
// (days: [S, M, T, W, T, F, S])

// start = Monday (offset: 1)
calendarize('Jan 01, 2020', 1);
// =>    [[0, 0, 1, 2, 3, 4, 5], ...]
// (days: [M, T, W, T, F, S, S])

License

MIT © Luke Edwards