use
Injects a plugin into the Chronos system.
use()
Injects a plugin into the Chronos system. This enables dynamic extension of the Chronos class at runtime by registering external functionality as methods on its prototype.
One-time Injection
A plugin is only injected once per runtime. Re-registering the same plugin has no effect.
Info
- Plugins should be injected before any instance creation.
- Internally,
Chronosmaintains a#pluginsset to prevent duplicate injections. - This system is ideal for modular features like
seasons,zodiac, ortimeZoneetc. support.
Signature
static use(plugin: ChronosPlugin): voidParameters
| Name | Type | Description |
|---|---|---|
| plugin | ChronosPlugin | A plugin function that receives the Chronos class constructor and augments it. |
Example
import { Chronos } from "chronos-date";
import { timeZonePlugin } from "chronos-date/plugins/timeZonePlugin";
Chronos.use(timeZonePlugin); // Injects timeZone() and other timezone specific methodsOnce injected, the plugin methods become available on all Chronos instances:
playground.ts
Alias
This method is also available as Chronos.register(). Both behave the same way.
Notes
- Using this (
use) method inReactprojects may trigger linter error like"React Hooks must be called in a React function component or a custom React Hook function." - To prevent this incorrect linter error in
Reactprojects, prefer usingregistermethod (alias ofusemethod).
Last updated: Thu, May 21, 2026 07:12:18AM (UTC)
