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

calendator

v2.1.0

Published

The Calendator will generate a calendar and cache it for any month and year OR date!

Downloads

13

Readme

The Calendator!

MIT License Version Travis Build Status Code Coverage

The Calendator will generate a calendar and cache it for any month and year OR date!

var calendator = new Calendator();
var may = Calendator.MAY;
var year2017 = 2017;
calendator.giveMeCalendarForMonthYear(may, year2017);
// => [
//      [null, 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, null, null, null]
//    ]

var may2017 = new Date(year2017, may, 1);
calendator.giveMeCalendarForDate(may2017);
// => [
//      [null, 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, null, null, null]
//    ]

Watch on GitHub Star on GitHub Tweet

Installation

npm install calendator or yarn add calendator.

Use with Node.js, Browserify, or webpack:

var Calendator = require('calendator');
var calendator = new Calendator();

The Calendator supports CommonJS, UMD, and browser (attaches itself to window.dv.Calendator).

License

MIT.

Usage

Basic Usage

See above.

Caching

The Calendator will only build a calendar once when you ask for a calendar, then it caches the calendar. When you ask for the same calendar next time, it will return the same exact calendar from it's cache.

Tips

The Calendator expects weekdays and months to start at 0. When using the Calendator, avoid specifying the weekday or the month in integer unless you're confident you can avoid the one-off bug. Instead, use the months and weekdays variable names attached to the Calendator:

// Weekdays
Calendator.SUN // => 0
Calendator.MON // => 1
Calendator.TUE // => 2
Calendator.WED // => 3
Calendator.THU // => 4
Calendator.FRI // => 5
Calendator.SAT // => 6

// Months
Calendator.JAN // => 0
Calendator.FEB // => 1
Calendator.MAR // => 2
Calendator.APR // => 3
Calendator.MAY // => 4
Calendator.JUN // => 5
Calendator.JUL // => 6
Calendator.AUG // => 7
Calendator.SEP // => 8
Calendator.OCT // => 9
Calendator.NOV // => 10
Calendator.DEC // => 11

If you already have an instance of Calendator, you can use .getMonths and .getWeekdays to get an object containing these variable names for weekdays and months:

var calendator = new Calendator();
calendator.getMonths()   // => {SUN: 0, MON: 1, ..., SAT:  6}
calendator.getWeekdays() // => {JAN: 0, FEB: 1, ..., DEC: 11}

Specifying the start weekday of every week

By default, the Calendator will always use Sunday as the starting weekday of every week. When you're constructing the Calendator, you can specify the starting weekday of every week:

var calendator = new Calendator(Calendator.MON);

The Calendator will now return all calendars with Monday as the first day of the week, which means that week[0] will be a Monday, week[1] will be a Tuesday, and etc.

Handling day creation yourself

By default, the Calendator will always return a number representing the day when it gives you a calendar. However, you can customize this day data by giving the Calendator a day creation handler during construction. Every time the Calendator creates a day, it will use your day creation handler to build the day data and pass it the following arguments: dayCreationHandler(year, month, day, weekday, currentWeekOfTheMonth)

NORMAL DEFAULT BEHAVIOR:

var may = Calendator.MAY;
var year2017 = 2017;

var calendator = new Calendator();
calendator.giveMeCalendarForMonthYear(may, year2017);
// => [
//      [null, 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, null, null, null]
//    ]

NOW, WITH THE dayCreationHandler:

function dayCreationHandler(year, month, day, weekday, currentWeekOfTheMonth) {
  var myCustomDayData = ...; // build your custom data according to your logic
  return myCustomDayData;    // return your custom data.

  // lets assume we returned this:
  // return {d: day, m: month};
}

// `null` defaults Calendator to Sunday as starting weekday
calendator = new Calendator(null, dayCreationHandler);
calendator.giveMeCalendarForMonthYear(may, year2017);
// => [
//      [
//        null,
//        {d: 1, m: 4},
//        {d: 2, m: 4},
//        {d: 3, m: 4},
//        {d: 4, m: 4},
//        {d: 5, m: 4},
//        {d: 6, m: 4}
//      ],
//      [
//        {d: 7, m: 4},
//        {d: 8, m: 4},
//        {d: 9, m: 4},
//        {d: 10, m: 4},
//        {d: 11, m: 4},
//        {d: 12, m: 4},
//        {d: 13, m: 4}
//      ],
//      [
//        {d: 14, m: 4},
//        {d: 15, m: 4},
//        {d: 16, m: 4},
//        {d: 17, m: 4},
//        {d: 18, m: 4},
//        {d: 19, m: 4},
//        {d: 20, m: 4}
//      ],
//      [
//        {d: 21, m: 4},
//        {d: 22, m: 4},
//        {d: 23, m: 4},
//        {d: 24, m: 4},
//        {d: 25, m: 4},
//        {d: 26, m: 4},
//        {d: 27, m: 4}
//      ],
//      [
//        {d: 28, m: 4},
//        {d: 29, m: 4},
//        {d: 30, m: 4},
//        {d: 31, m: 4},
//        null,
//        null,
//        null
//      ]
//    ]

Imagine all the possibilities that you can do with the Calendator! Ahhhh!

Calendator's API