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

class-scheduler

v1.2.1

Published

A zero dependency schedule manager for javascript apps

Downloads

16

Readme

Installation

  • Using npm
npm install class-scheduler
  • Using yarn
yarn add class-scheduler

Quick Start

Importing

  • TypeScript / JavaScript ES6+

    import { Schedule } from 'class-scheduler';
  • Common JS

    const { Schedule } = require('class-scheduler');

Usage

The calendar array

Create the calendar array in the following structure for each day in a week:

const calendar = [
  {
    day: 'Sunday',
    timeRange: [],
    classes: []
  },
  {
    day: 'Monday',
    timeRange: [
      { start: { hour: 12, minute: 30 }, end: { hour: 13, minute: 30 } },
      ...
    ],
    classes: ['Class 1', ...]
  }
  ...
];

The array must have a length of 7.

Initialize the Schedule object

const sch = new Schedule(calendar);

Get current class

const currentClass = sch.getCurrentClass();

Get upcoming classes

const nextClass = sch.getNextClass();
const laterClass = sch.getLaterClass();

Schema of the Calendar

Array<{
  day: 'Sunday' | 'Monday' | 'Tuesday' | 'Wednesday' | 'Thursday' | 'Friday' | 'Saturday';
  timeRange: Array<{
    start: {
      hour: number;
      minute: number;
    };
    end: {
      hour: number;
      minute: number;
    };
  }>;
  classes: Array<string>
}>;

See Quick Start Usage guide to get a grasp of the schema.

NOTE The package is not mature enough to check if the length of the timeRange[] comply with the length of classes[] or to check if the given time limit is valid or even the size of the entire array. Please make sure that you don't do anything wrong such things before reporting a bug.


Custom messages

Scheduler offers several options to customize the messages shown during break times, when there are no classes, when the classes are yet to start or when the all classes have ended already.

You can do that in one of the following ways:

1. Pass it using the constructor options parameter

constructor(calendar: Calendar, options?: object)

The options object contains the following properties:

| Property | Type | Default | Description | | ------------------ | ------ | ------------------ | ---------------------------------------------------------------------------- | | noScheduleMessage | string | 'No Schedule' | No schedule for the time being, default when other messages are not provided | | breakMessage | string | 'Break' | Break in-between two classes | | classesOverMessage | string | 'Classes are over' | Classes are over for today | | yetToBeginMessage | string | 'Yet to begin' | Today's classes are yet to begin |

2. Use methods to set specific messages

| Method name | Parameter type | Description | | --------------------- | -------------- | ---------------------------------------------------------------------------- | | setNoScheduleMessage | string | No schedule for the time being, default when other messages are not provided | | setBreakMessage | string | Break in-between two classes | | setClassesOverMessage | string | Classes are over for today | | setYetToStartMessage | string | Today's classes are yet to begin |


Methods

getClassTable

Arguments: None

Returns

All the classes of the week as array of array.

Type: Array<Array<string>>


getPeriodNumber

Get Period number corresponding to a given time.

Arguments

| Name | Type | isMandatory | Default | | ---- | ---- | ----------- | ------------ | | time | Date | false | current time |

Returns

The period number corresponding to the given time. 0 corresponds to 1st period of the day.

Type: number

Special values

| Value | Meaning | | ----- | ------------------------ | | -4 | Break | | -3 | No classes today | | -2 | Classes have ended | | -1 | Classes are yet to start |


getClasses

Get Classes of a given Date/ Day number. Day number 0 corresponds to Sunday.

Arguments

| Name | Type | isMandatory | Default | | ---- | ------------- | ----------- | ------------ | | date | Date / number | false | current date |

Returns

An array of all the classes in the given day.

Type: Array<string>


getClass

Get the Class corresponding to a given period and day.

Arguments

| Name | Type | isMandatory | Default | | ------ | ------------- | ----------- | -------------- | | period | number | false | current period | | date | Date / number | false | current date |

Returns

The Class corresponding to a given period and day.

Type: string

Quick hint

() -> currentPeriod

(n) -> today's nth period

(n, d) -> Day d's nth period


getClassByDay

Get the Class schedule corresponding to given days.

Arguments

| Name | Type | isMandatory | Default | | ---- | ---------- | ----------- | ------- | | date | ... string | true | not set |

Returns

An array of all the classes that matches the given days.

Type: Array<string>

Quick hint

For single day

getClassByDay('Monday')

For multiple days

getClassByDay('Monday' , 'Friday')


getCurrentClass

Get the class for current time.

Arguments [Options]

| Name | Type | isMandatory | Default | Description | | ---------------------- | ------- | ----------- | ------- | ------------------------------------------ | | {useMeaningfulMessage} | boolean | false | false | Toggle usage of custom No schedule message |

Returns

The current class.

Type: string


getNextClass

Get the next upcoming class.

Arguments [Options]

| Name | Type | isMandatory | Default | Description | | -------------- | ------- | ----------- | ------- | ----------------------- | | {allowNextDay} | boolean | false | false | Toggle next day look up |

Returns

The next upcoming class.

Type: string


getLaterClass

Get the class coming after the next class.

Arguments [Options]

| Name | Type | isMandatory | Default | Description | | -------------- | ------- | ----------- | ------- | ----------------------- | | {allowNextDay} | boolean | false | false | Toggle next day look up |

Returns

The class coming after the next class.

Type: string


Authors

Contributing

Refer the contributing guide here.

License

MIT License