Skip to main content

Chronos Plugins

info

Chronos supports a powerful plugin system that allows developers to inject additional methods or utilities into the Chronos class without modifying its core. This enables clean separation of concerns, tree-shaking, modular feature design, and maintainability.


🧩 What Is a Plugin?​

A plugin is a function that takes the Chronos class constructor and augments itβ€”usually by adding prototype methods.

type ChronosPlugin = (ChronosClass: typeof Chronos) => void;

You can inject plugins via the static Chronos.use() method or its wrapper function:

Chronos.use(pluginName);

// or
chronos.use(pluginName)
tip
  • Each plugin is only applied once, even if use() is called multiple times with the same plugin.
  • If a plugin enables multiple methods, injecting once will enable all the methods by that particular plugin. See the list below

βœ… Using a Plugin​

To enable a plugin, use the static Chronos.use() method before creating instances:

import { Chronos, chronos } from 'nhb-toolbox';

// For importing a plugin from the package, plugin name and import path are same
import { pluginName } from 'nhb-toolbox/plugins/pluginName';

// Using the plugin
Chronos.use(pluginName);
// or
chronos.use(pluginName)

// Using the method enabled by that plugin
const c = new Chronos();
c.enabledMethod();

// or
chronos().enabledMethod()

πŸ“¦ Official Plugins​

Plugin NamesImports StatementsMethods Registered
relativeTimePlugin
getRelativeYear, getRelativeMonth, getRelativeWeek, getRelativeDay, getRelativeHour, getRelativeMinute, getRelativeSecond, getRelativeMilliSecond, compare, isToday, isTomorrow, isYesterday
timeZonePlugin
timeZone
fromNowPlugin
fromNow
businessPlugin
isWeekend, isWorkday, isBusinessHour, toAcademicYear, toFiscalQuarter
seasonPlugin
season
dayPartPlugin
getPartOfDay
zodiacPlugin
getZodiacSign
palindromePlugin
isPalindromeDate
(More coming soon)