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

kaalendar

v1.0.0

Published

A zero dependency package to manage calendar/datepicker creation and gestion with language support & utility methods

Downloads

3

Readme

About

The package

Kaalendar is a TypeScript library that works with 0 dependency. It was made for help to manage calendars generation/creation and datepickers.

Me

I had initially made this code for a personnel project that uses calendars but as a citation that I really like say:

"All we have to decide is what to do with the time that is given us." J. R. R. Tolkien

So that is why I decided to use mine to publish Kaalendarjs which is my first public package for the wonderful world of Open Source & JavaScript.

In the future

I will add more features to the package in the futur like:

  • The possibility to provide a public holiday list
  • The possibility to disable the weekend days
  • Add hours:
    • Add working hours
    • Splitting the day on working hours
  • Others ?

Installation

Installation from npm

See npm documentation on how to get started with npm.

npm install --save kaalendar

How to use it ?

Kaalendar

How to use the Kaalendar class ?

Instanciation

You can instanciate a new Kaalendar using its class:

Instanciation without any parameters:

import Kaalendar from 'kaalendar';

const kaalendar = new Kaalendar();

If you create the kaalendar like this, it will be instanciate with Date.now and use the current year and month as default.

Instanciation with parameters:

  1. The year
  2. The month
  3. The language
  4. An enum of the days of the week so you can start the week by the day of you choice (monday to sunday)
  5. An option object to provide optionnal parameters (available options are listed in the interface in Kaalendar file)
import Kaalendar from 'kaalendar';
import { DaysOfWeek } from 'kaalendar/utils/utils';

const kaalendar = new Kaalendar(2022, 7, 'en', DaysOfWeek.SUNDAY, {
  generateOnlyDaysOfCurrentMonth: false,
  generateASingleArray: false,
});

Methods

The kaalendar class provides a bunch of methods and features:

Navigation:

The class provides methods to navigate through the calendar

  • goToDate()

    params:

    1. year
    2. month

    👉 kaalendar.goToDate(2021, 3)

  • goToNextMonth() 👉 kaalendar.goToNextMonth()

  • goToPreviousMonth() 👉 kaalendar.goToPreviousMonth()

  • goToNextYear() 👉kaalendar.goToNextYear()

  • goToPreviousYear() 👉 kaalendar.goToPreviousYear()

Getter:

  • getNextMonth() 👉 kaalendar.getNextMonth()

  • getPreviousMonth() 👉 kaalendar.getPreviousMonth()

  • getMonth()

    params:

    1. month

    👉 kaalendar.getMonth(12)

Generation:

  • generateArray()

    Description:

    This method will return either a singleArray of days of the current month or a 2D array AND either the last days of the previous month + first days of the next month or not, depending on the options passed while instanciation:

    • generateASingleArray: boolean
    • generateOnlyDaysOfCurrentMonth: boolean

    👉 kaalendar.generateArray()

  • Iterator()

    You can use iterable features on your kaalendar object to get all month of the current year. This to avoid any memory leaks or useless memory requirement

    • Spread operator
    const months: Month[] = [...kaalendar];
    • for of loop
    for (const month of kaalendar) {
        // do some stuff...
    }

Month

How to use the Month class ?

Intanciation

In a "classic" usage of the package, you would not like to instanciate the Month class by your own since you can get the months from various methods.

But even if you need to, you do it like this:

Instanciation without any parameters:

import Month from 'kaalendar/lib/Month';

const month = new Month();

If you create the month like this, it will be instanciate with Date.now and use the current month as default.

Instanciation with parameters:

  1. The date
  2. The language
  3. An enum of the days of the week so you can start the week by the day of you choice (monday to sunday)
import Month from 'kaalendar/lib/Month';
import { DaysOfWeek } from 'kaalendar/utils/utils';

const dateOfYourChoice = new Date();

const month = new Month(dateOfYourChoice, 'en', DaysOfWeek.SUNDAY);

Methods

Getter:

  • getDay()

    params:

    1. day

    👉 month.getDay(31)

Generation:

  • Iterator()

    You can use iterable features on your month object to get all day of the current month. This to avoid any memory leaks or useless memory requirement

    • Spread operator
    const days: Day[] = [...month];
    • for of loop
    for (const day of month) {
        // do some stuff...
    }

Day

How to use the Day class ?

Intanciation

In a "classic" usage of the package, you would not like to instanciate the Day class by your own since you can get the days from various methods.

But even if you need to, you do it like this:

Instanciation without any parameters:

import Day from 'kaalendar/lib/Day';

const day = new Day();

If you create the day like this, it will be instanciate with Date.now and use the current day as default.

Instanciation with parameters:

  1. The date
  2. The language
  3. An enum of the days of the week so you can start the week by the day of you choice (monday to sunday)
  4. An option object to provide optionnal parameters (available options are listed in the interface in Day file)
import Day from 'kaalendar/lib/Day';
import { DaysOfWeek } from 'kaalendar/utils/utils';

const dateOfYourChoice = new Date();

const day = new Day(dateOfYourChoice, 'en', DaysOfWeek.SUNDAY, {
    activated: false,
});

Methods

The day class provides a bunch of methods and features:

Utilities

  • get isToday() 👉 day.isToday

  • isEqualTo()

    params:

    1. date

    👉 day.isEqualTo(date)

  • format()

    params:

    1. string

    👉 day.format(stringToFormat)

Data management

The class provides methods to manage the data of each day

  • resetDatas() 👉 day.resetDatas()

  • get data() 👉 day.data

  • set data(dataToAdd) 👉 day.data = {newData: 'some new data'}

  • getSpecificData()

    params:

    1. theKeyYouWantToGet

    👉 day.getSpecificData(theKeyYouWantToGet)

  • setSpecificData()

    params:

    1. theKeyYouWantToSet
    2. callback(data, keyFound)
day.setSpecificData('message', (data, found) => {
    if (found) // do some stuff
    else // do some stuff
})