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

month-class

v1.0.1

Published

Month class, manages information of the month from a given date

Downloads

14

Readme

🗓️ Month class

The Month class manages the information of a month from given date, such as number of weeks, number of work days, number of weekend.

Installation

First install Node.js. Then:

npm install month-class

Importing

// Using Node.js `require()`
const Month = require('month-class');

// Using ES6 imports
import Month from 'month-class';
<!-- From CDN -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/month.bundle.js" crossorigin="anonymous"></script>

Live demo

Vanilla javascript: here

Overview

Create instance

const Month = require('month-class');

const month = new Month();

// It is equivalent
const month = new Month({
  current: new Date(),
  weekend: 0,
  datebook: [],
});

Select weekends

See documentation for more details.

const month = new Month({
  current: new Date(),
  weekend: 14, // Sunday is the only weekend
});

// It is equivalent
const month = new Month({
  current: new Date(),
  weekend: '0000001', // Sunday is the only weekend
});

Concepts

Activity

Information about a scheduled activity.

An Object containing the properties date, title, description, type and holiday.

Important! All properties are required, date is a string with ISO format (ISO 8601).

const Month = require('month-class');

const activity = {
  date: '2021-01-11', // before current day
  title: 'Send final sales report',
  description: "Don't forget to attach graphics",
  type: 'task', // Allowed values: 'task', 'event', 'appointment', 'meeting'.
  holiday: false,
};

const month = new Month({
  current: new Date(2021, 0, 15),
  datebook: [activity],
});

Datebook

The datebook is a collection of activities, those that do not correspond to the month will be omitted, leaving only those of the month indicated in current.

const Month = require('month-class');

const date = new Date(2021, 0, 15);
const datebook = [{
  date: '2021-01-11',
  title: 'Send final sales report',
  description: "Don't forget to attach graphics",
  type: 'task',
  holiday: false,
},{
  date: new Date(2021, 0, 10).toISOString(),
  title: 'Meeting with managers',
  description: "In the cafe in the square, 11:30 a.m.",
  type: 'meeting',
  holiday: false,
},{
  date: '2021-02-11', // Will be omitted
  title: 'Send product catalog',
  description: "Don't forget to attach photos",
  type: 'task',
  holiday: false,
}];

const month = new Month({
  current: date,
  datebook,
});

// or
const month = new Month({ current: date });

month.addDatebook(datebook);

Workdays

The workdays are: workdays = month days - nonworkdays

The non-workdays are: nonworkdays = weekdays + holidays

const Month = require('month-class');

const date = new Date(2021, 0, 15); // 31 days
const datebook = [{
  date: new Date(2021, 0, 11).toISOString(),
  title: 'Meeting with managers',
  description: "In the cafe in the square, 11:30 a.m.",
  type: 'meeting',
  holiday: true, // One holiday
}];

const weekend = '0000001' // Sunday is weekend

const month = new Month({ current: date, datebook });

//    [        2021-01-15        ]
//    [ S,  M,  T,  W,  T,  F,  S]
// 01 [                     1,  2]
// 02 [ 3,  4,  5,  6,  7,  8,  9]
// 03 [10, 11, 12, 13, 14, 15, 16]
// 04 [17, 18, 19, 20, 21, 22, 23]
// 05 [24, 25, 26, 27, 28, 29, 30]
// 06 [31                        ]

//    WEEKENDS     [3, 10, 17, 24, 31] =  5
//    HOLIDAYS                    [11] =  1
// NONWORKDAYS [3, 10, 11, 17, 24, 31] =  6

//       TOTAL [1, 2, 3, 4, 5,..., 31] = 31
//    WORKDAYS [1, 2, 4, 5, 6,..., 30] = 31 - 6 = 25

Basics of the Month

Month.prototype.days

const Month = require('month-class');

// or const month = new Month();
const month = new Month({
  current: new Date(2021, 0, 15), // Friday, January 15 2021
  weekend: '0000011', // Weekend days: Saturday Sunday
  datebook: [{
    date: '2021-01-11',
    title: 'Send final sales report',
    description: "Don't forget to attach graphics",
    type: 'task', // Allowed values: 'task', 'event', 'appointment', 'meeting'.
    holiday: false,
  },{
    date: '2021-08-14', // The date does not correspond to the indicated month, Will be omitted.
    title: 'See Final space season finale',
    description: "Don't forget to order pizza",
    type: 'event',
    holiday: false,
  },{
    date: '2021-01-26',
    title: 'Pay the credit card',
    description: 'Amount 345.50',
    type: 'task',
    holiday: false,
  },{
    date: '2021-01-19',
    title: 'Meeting with investors',
    description: 'Send quote before',
    type: 'task',
    holiday: true, // One less work-day
  }],
});

// Array with information of the month
const { days } = month;

console.log(days.length); // Expected value 31
console.log(days[10]);
/*
{
  day: 11,
  date: [ 2021, 0, 11 ],
  weekday: 1,
  type: 'elapsed',
  week: 3,
  workday: 7,
  isWorkday: true,
  isWeekend: false,
  scheduled: { tasks: 1, events: 0, appointments: 0, meetings: 0, total: 1 }
}
*/

console.log(days[18]);
/*
{
  day: 19,
  date: [ 2021, 0, 19 ],
  weekday: 2,
  type: 'remaining',
  week: 4,
  workday: 12,
  isWorkday: false,
  isWeekend: false,
  scheduled: { tasks: 0, events: 0, appointments: 0, meetings: 1, total: 1 }
}
*/

Month.prototype.planner

const Month = require('month-class');

// or const month = new Month();
const month = new Month({
  current: new Date(2021, 0, 15), // Friday, January 15 2021
  weekend: '0000011', // Weekend days: Saturday Sunday
  datebook: [{
    date: '2021-01-11',
    title: 'Send final sales report',
    description: "Don't forget to attach graphics",
    type: 'task', // Allowed values: 'task', 'event', 'appointment', 'meeting'.
    holiday: false,
  },{
    date: '2021-08-14', // The date does not correspond to the indicated month, Will be omitted.
    title: 'Rick and morty season finale',
    description: "Don't forget to order pizza",
    type: 'event',
    holiday: false,
  },{
    date: '2021-01-26',
    title: 'Pay the credit card',
    description: 'Amount 345.50',
    type: 'task',
    holiday: false,
  },{
    date: '2021-01-19',
    title: 'Meeting with investors',
    description: 'Send quote before',
    type: 'task',
    holiday: true, // One less work-day
  }],
});

// Object with scheduled activities, organized by type
const { planner } = month;

console.log(planner);
/*
{
  tasks: [...],         3 elements
  events: [...],        1 element
  appointments: [...],  0 elements
  meetings: [...],      0 elements
}
*/

console.log(planner.events);

/*
[
  {
    date: '2021-08-14',
    title: 'Rick and morty season finale',
    description: "Don't forget to order pizza",
    type: 'event',
    holiday: false,
  },
]
*/

API Docs

Find the API docs here

TODO

  • 🔳 Live demo browser
  • 🔳 Create react provider.