Skip to main content

Chronos Wrapper Function

Overview​

info

Function wrapper around the Chronos class that provides identical functionality with a simpler interface. All Chronos features are available through this function.

Key Features​

  • Same functionality as new Chronos() but with function syntax
  • Full access to all Chronos instance methods
  • Inherits all static methods from Chronos class (chronos without call signature)
  • Supports all Chronos input types
  • Maintains identical type safety

🧩 Plugin System​

Chronos supports a modular plugin system that allows you to extend its capabilities without bloating the core. Plugin methods are not available by default—you must explicitly install them using the .use() static method.

How it works​

import { Chronos } from 'nhb-toolbox';
import { seasonPlugin } from 'nhb-toolbox/plugins/seasonPlugin';

chronos.use(seasonPlugin); // Register the plugin before using its methods

console.log(chronos().season()); // ✅ Safe to use after plugin registration
info

Each plugin enhances the Chronos prototype and becomes available globally after registration.

Usage​

Import​

import { chronos } from 'nhb-toolbox';

Basic Instantiation​

// Function style
const date = chronos('2023-12-31')

date.year // 2023
date.formatStrict() // Formatted date string

// Class style (equivalent)
const date = new Chronos('2023-12-31')

date.year // 2023
date.formatStrict() // Formatted date string

With Components​

const date = chronos(2023, 12, 31, 15, 30)

date.year // 2023
date.formatStrict() // Formatted date string

Available Methods​

The wrapper provides access to all Chronos methods through the returned instance:

Static Methods​

All Chronos static methods are available directly on the wrapper function:

import { Chronos } from 'nhb-toolbox';
import { timeZonePlugin } from 'nhb-toolbox/plugins/timeZonePlugin';

// Using wrapper function
chronos.parse('2023-12-31', 'YYYY-MM-DD')
chronos.use(timeZonePlugin)
chronos.today()
chronos.isLeapYear(2024)

// Using class (equivalent)
Chronos.parse('2023-12-31', 'YYYY-MM-DD')
Chronos.today()
Chronos.isLeapYear(2024)

Aliases​

The chronos function is also available under the following aliases:

  • chronosjs
  • chronosts
  • chronus
  • chronusjs
  • chronusts

These aliases exist to support flexible naming conventions and common user preferences.

Full Documentation​

For complete method documentation, see the Chronos class reference. All methods shown there are available through this wrapper.