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

@jpvmrcd/calendar

v0.1.2

Published

Lightweight JavaScript library for generating simple HTML table calendar.

Downloads

716

Readme

📅 Calendar

Coverage Status

A lightweight JavaScript library for generating simple HTML table calendar.

 

Usage

Using npm:

npm install @jpvmrcd/calendar --save
<div id="calendar"></div>
import { Calendar } from '@jpvmrcd/calendar';

const cal = new Calendar(document.getElementById('calendar'));
cal.render();

using CDN:

<div id="calendar"></div>

<script src="https://unpkg.com/@jpvmrcd/calendar/dist/calendar.min.js"></script>
var cal = new jpvmrcd.calendar.Calendar(document.getElementById('calendar'));
cal.render();

 

Methods

render(year?: number, month?: number): Date

Generates a calendar based on year and month arguments. If no arguments are passed, the calendar renders the current month and year.

Parameters

| Name | Type | Description | |-|-|-| | year | number | A number corresponding the year to be rendered. | | month | number | A zero based number corresponding the month to be rendered (zero is first month). |

 

Properties

| Name | Type | Description | |-|-|-| | options | calendarOptions | The rendering options for the calendar. | | month | number | The zero based month of the rendered calendar. | | year | number | The full year of the rendered calendar. | | element | HTMLElement | The parent HTML element of the calendar. |

 

Types

calendarOptions

| Name | Type | Description | |-|-|-| | dayNames | string[7] | Sets the days of the week. Should start from Sunday. | | startDay | string | Sets the start day of the week. The value for startDay should match one of the values defined in dayNames. Defaults to Sun. | | onCellAdded | (args: onCellAddedArgs) => void | Event triggered on every calendar cell added to the calendar. | | onDateClicked | (args: onDateClickedArgs) => void | Event triggered on every calendar date cell click. |

onCellAddedArgs

| Name | Type | Description | |-|-|-| | td | HTMLTableCellElement | Current td being rendered. | | dateISOString | string | ISO formatted date of the cell being rendered. |

onDateClickedArgs

| Name | Type | Description | |-|-|-| | event | Event | The Event triggered. | | dateISOString | string | ISO formatted date of cell clicked. |

 

Examples

Render calendar for the current month year.

const cal = new Calendar(document.getElementById('calendar'));
cal.render();

Calendar properties and render() return value

const cal = new Calendar(document.getElementById('calendar'));
const date = cal.render(2021, 0);

console.log(cal.month);
> 0

console.log(cal.year);
> 2021

console.log(cal.element);
> <div id="calendar">...</div>

Render calendar with custom option.dayNames

const cal = new Calendar(document.getElementById('calendar'));
cal.options.dayNames = ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'];
cal.render();

Render calendar with options.startDay

const cal = new Calendar(document.getElementById('calendar'));
cal.options.startDay = 'Mon';
cal.render();

Render calendar with option.dayNames and option.startDay

const cal = new Calendar(document.getElementById('calendar'));
cal.options.dayNames = ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'];
cal.options.startDay = 'Tu';
cal.render();

Change rendered calendar

const cal = new Calendar(document.getElementById('calendar'));
cal.render(2021, 0);

// renders calendar for December 2020
cal.render(cal.year, cal.month + 1);

// renders calendar for January 2021
cal.render(cal.year, cal.month - 1);

Render calendar with customized cells using options.onCellAdded

const cal = new Calendar(document.getElementById('calendar'));
cal.options.onCellAdded = (args: OnCellAddedArgs) => {
  args.td.innerHTML = `<div>${args.cellDate.getDate()}</div>`;
};
cal.render();

Render calendar with options.OnDateClicked

const cal = new Calendar(document.getElementById('calendar'));
cal.options.onDateClicked = (args: OnDateClickedArgs) => {
  console.log(args);
  // > {event: MouseEvent, dateISOString: "YYYY-MM-DD"}
};
cal.render();