chronos-date 1.1.2 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,31 +1,178 @@
1
- # Chronos Date
1
+ # [Chronos Date](https://chronos.nazmul-nhb.dev/)
2
2
 
3
- > A comprehensive date and time library for any JavaScript and TypeScript environment.
3
+ > A lightweight, immutable, and plugin-based date-time manipulation library for JavaScript and TypeScript.
4
4
 
5
- ## Install
5
+ [![Chronos Date](https://raw.githubusercontent.com/nazmul-nhb/chronos-date/refs/heads/main/chronos.png)](https://chronos.nazmul-nhb.dev/)
6
6
 
7
- ### NPM
7
+ <p>
8
+ <!-- Package Info -->
9
+ <a href="https://www.npmjs.com/package/chronos-date" aria-label="NPM Downloads">
10
+ <img src="https://img.shields.io/npm/dm/chronos-date.svg?label=DOWNLOADS&style=flat&color=red&logo=npm" alt="Downloads" />
11
+ </a>
12
+ <a href="https://www.npmjs.com/package/chronos-date" aria-label="Latest Version">
13
+ <img src="https://img.shields.io/npm/v/chronos-date.svg?label=NPM&style=flat&color=teal&logo=npm" alt="Latest Version" />
14
+ </a>
15
+ <a href="https://bundlejs.com/?q=chronos-date" aria-label="Bundle Size">
16
+ <img src="https://img.shields.io/bundlejs/size/chronos-date?label=Bundle%20Size&style=flat&color=blue&logo=npm" alt="Bundle Size" />
17
+ </a>
8
18
 
9
- ```bash
10
- npm i chronos-date
11
- ```
19
+ <!-- Project Metadata -->
20
+ <a href="https://github.com/nazmul-nhb/chronos-date" aria-label="TypeScript">
21
+ <img src="https://img.shields.io/badge/BUILT%20with-TypeScript-3178C6?style=flat&logo=typescript&logoColor=blue" alt="Built with TypeScript" />
22
+ </a>
23
+ <a href="https://github.com/nazmul-nhb/chronos-date/actions" aria-label="Build Status">
24
+ <img src="https://img.shields.io/github/actions/workflow/status/nazmul-nhb/chronos-date/publish.yml?label=BUILD%20%26%20PUBLISH&style=flat&logo=github" alt="Build Status" />
25
+ </a>
26
+ <a href="https://github.com/nazmul-nhb/chronos-date" aria-label="Project Status">
27
+ <img src="https://img.shields.io/badge/STATUS-maintained-brightgreen?style=flat&logo=git" alt="Maintained" />
28
+ </a>
29
+ <a href="https://github.com/nazmul-nhb/chronos-date/commits/main" aria-label="Last Commit">
30
+ <img src="https://img.shields.io/github/last-commit/nazmul-nhb/chronos-date?style=flat&label=LAST%20COMMIT&logo=git" alt="Last Commit" />
31
+ </a>
32
+
33
+ <!-- GitHub Meta -->
34
+ <a href="https://github.com/nazmul-nhb/chronos-date/stargazers" aria-label="GitHub Stars">
35
+ <img src="https://img.shields.io/github/stars/nazmul-nhb/chronos-date?style=flat&label=STARS&logo=github" alt="GitHub stars" />
36
+ </a>
37
+ <a href="https://github.com/nazmul-nhb/chronos-date/issues" aria-label="Open Issues">
38
+ <img src="https://img.shields.io/github/issues/nazmul-nhb/chronos-date?style=flat&label=ISSUES&logo=github" alt="Open Issues" />
39
+ </a>
40
+ <a href="https://github.com/nazmul-nhb/chronos-date/pulls" aria-label="Open Pull Requests">
41
+ <img src="https://img.shields.io/github/issues-pr/nazmul-nhb/chronos-date?style=flat&label=PRs&logo=github" alt="Pull Requests" />
42
+ </a>
43
+
44
+ <!-- License Info -->
45
+ <a href="https://www.npmjs.com/package/chronos-date" aria-label="License">
46
+ <img src="https://img.shields.io/npm/l/chronos-date.svg?label=LICENSE&style=flat&color=orange&logo=open-source-initiative" alt="License" />
47
+ </a>
48
+ </p>
49
+
50
+ ## Why Chronos?
51
+
52
+ In ancient Greek mythology, **Chronos** is the primordial embodiment of time — not merely tracking moments, but **defining their very existence**. Like its mythological namesake, the `Chronos` class offers **precise, immutable, and expressive control** over time within your application.
53
+
54
+ Designed to go beyond the native `Date` object, it empowers you to manipulate, format, compare, and traverse time with **clarity, reliability, and confidence** — all while staying _immutable_ and _framework-agnostic_.
12
55
 
13
- ### PNPM
56
+ ## Key Features
14
57
 
15
- ```bash
58
+ - **Immutability:** Every modification returns a new `Chronos` instance. Your original dates remain intact.
59
+ - **Rich API:** From formatting to comparison, calculation, and detailed part extraction.
60
+ - **Plugin System:** Extend core capabilities seamlessly using `Chronos.use(plugin)`. Over a dozen official plugins exist for advanced operations like business hours, seasons, zodiacs, relative times, and more.
61
+ - **Time Zone Support:** Advanced formatting and tracking of UTC offsets and Native time zone properties.
62
+ - **Date Utilities:** Extra utilities, type guards, types and constants for light weight date operations without the need of core class.
63
+ - **Comprehensive TypeScript IntelliSense:** Built with first-class TypeScript types and granular tracking for strict date formatting tokens.
64
+ - **Cross-environment compatibility:** Works anywhere JS runs (Node.js, Browser, Deno, Bun).
65
+
66
+ ---
67
+
68
+ ## Installation
69
+
70
+ ```sh
71
+ npm install chronos-date
72
+ # or
73
+ yarn add chronos-date
74
+ # or
16
75
  pnpm add chronos-date
17
76
  ```
18
77
 
19
- ### YARN
78
+ ---
20
79
 
21
- ```bash
22
- yarn add chronos-date
80
+ ## Quick Start
81
+
82
+ ```ts
83
+ import { Chronos, chronos } from 'chronos-date';
84
+
85
+ // Using the constructor
86
+ const now = new Chronos();
87
+ console.log(now.format('dd, mmm DD, YYYY'));
88
+
89
+ // Using the function wrapper
90
+ const tomorrow = chronos().addDays(1);
91
+ console.log(tomorrow.formatStrict('YYYY-MM-DD'));
92
+
93
+ // Calculate differences
94
+ const eventDate = new Chronos('2025-12-31');
95
+ console.log(now.diff(eventDate, 'day')); // Days until event
23
96
  ```
24
97
 
25
98
  ---
26
99
 
27
- ## Features
100
+ ## Modular Imports
101
+
102
+ You can import specific submodules for better tree-shaking:
103
+
104
+ ```ts
105
+ // Guards
106
+ import { isValidDateInput } from "chronos-date/guards";
107
+
108
+ // Utility functions
109
+ import { formatDate } from "chronos-date/utils";
110
+
111
+ // Type definitions
112
+ import type { ChronosInput } from "chronos-date/types";
113
+
114
+ // Constants
115
+ import { MONTHS } from "chronos-date/constants";
116
+
117
+ // Plugins (imported individually)
118
+ import { timeZonePlugin } from "chronos-date/plugins/timeZonePlugin";
119
+ import { seasonPlugin } from "chronos-date/plugins/seasonPlugin";
120
+ ```
121
+
122
+ ---
123
+
124
+ ## Documentation
125
+
126
+ For full documentation, API reference, and interactive playgrounds, visit the [**Documentation Site**](https://chronos.nazmul-nhb.dev/).
127
+
128
+ ---
129
+
130
+ ## 🔗 Related Packages
131
+
132
+ <div style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}>
133
+ <a target="_blank" href="https://www.npmjs.com/package/nhb-toolbox">
134
+ <img src="https://img.shields.io/badge/NHB_Toolbox-nhb--toolbox-steelblue" alt="nhb-toolbox" />
135
+ </a>
136
+ </div>
137
+
138
+ <div style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}>
139
+ <a target="_blank" href="https://www.npmjs.com/package/bn-calendar">
140
+ <img src="https://img.shields.io/badge/Bangla_Calendar-bn--calendar-red" alt="bn-calendar" />
141
+ </a>
142
+ </div>
143
+
144
+ <div style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}>
145
+ <a target="_blank" href="https://www.npmjs.com/package/nhb-hooks">
146
+ <img src="https://img.shields.io/badge/React_Hooks-nhb--hooks-blue" alt="nhb-hooks" />
147
+ </a>
148
+ </div>
149
+
150
+ <div style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}>
151
+ <a target="_blank" href="https://www.npmjs.com/package/locality-idb">
152
+ <img src="https://img.shields.io/badge/IndexedDB_ORM-locality--idb-darkviolet" alt="locality-idb" />
153
+ </a>
154
+ </div>
155
+
156
+ <div style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}>
157
+ <a target="_blank" href="https://www.npmjs.com/package/nhb-scripts">
158
+ <img src="https://img.shields.io/badge/Development_Scripts-nhb--scripts-red" alt="nhb-scripts" />
159
+ </a>
160
+ </div>
161
+
162
+ <div style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}>
163
+ <a target="_blank" href="https://www.npmjs.com/package/nhb-express">
164
+ <img src="https://img.shields.io/badge/Express_Server_Scaffolder-nhb--express-orange" alt="nhb-express" />
165
+ </a>
166
+ </div>
167
+
168
+ <div style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}>
169
+ <a target="_blank" href="https://www.npmjs.com/package/nhb-anagram-generator">
170
+ <img src="https://img.shields.io/badge/Anagram_Generator-nhb--anagram--generator-teal" alt="nhb-anagram-generator" />
171
+ </a>
172
+ </div>
173
+
174
+ ---
175
+
176
+ ## License
28
177
 
29
- >[!INFO]
30
- >
31
- > Full Docs Coming Soon...
178
+ This project is licensed under the [Apache License 2.0](LICENSE).
@@ -71,11 +71,16 @@ const timeZonePlugin = ($Chronos) => {
71
71
  }
72
72
  return tzIds;
73
73
  }, /* @__PURE__ */ new Map()));
74
+ const _buildTzNameAbbrMap = () => {
75
+ const result = [];
76
+ for (const [tzAbbr, { offset, tzName }] of Object.entries(require_timezone.TIME_ZONES)) result.unshift([offset, {
77
+ tzAbbr,
78
+ tzName
79
+ }]);
80
+ return result;
81
+ };
74
82
  /** Cache to store time zone name and abbreviation against UTC offset from {@link TIME_ZONES} */
75
- const TZ_NAME_ABBR_MAP = new Map(Object.entries(require_timezone.TIME_ZONES).map(([tzAbbr, { offset, tzName }]) => [offset, {
76
- tzAbbr,
77
- tzName
78
- }]));
83
+ const TZ_NAME_ABBR_MAP = new Map(_buildTzNameAbbrMap());
79
84
  /** Get time zone identifier from {@link TZ_ID_MAP} using UTC offset */
80
85
  const _getTimeZoneId = (utc) => {
81
86
  const tzIds = TZ_ID_MAP.get(utc);
@@ -132,8 +137,8 @@ const timeZonePlugin = ($Chronos) => {
132
137
  if (!utc && tracker && _isValidTzAbbr(tracker)) return tracker;
133
138
  if (require_guards.isValidUTCOffset(tzMapKey)) {
134
139
  if (TZ_ABBR_CACHE.has(tzMapKey)) return TZ_ABBR_CACHE.get(tzMapKey);
135
- if (TZ_NAME_ABBR_MAP.has(tzMapKey)) return TZ_NAME_ABBR_MAP.get(tzMapKey)?.tzAbbr;
136
140
  const tzName = _resolveTzName(tzMapKey);
141
+ if (!tzName && TZ_NAME_ABBR_MAP.has(tzMapKey)) return TZ_NAME_ABBR_MAP.get(tzMapKey)?.tzAbbr;
137
142
  if (tzName) {
138
143
  const tzAbbr = _abbreviate(tzName);
139
144
  TZ_ABBR_CACHE.set(tzMapKey, tzAbbr);
@@ -141,9 +146,10 @@ const timeZonePlugin = ($Chronos) => {
141
146
  }
142
147
  }
143
148
  const zone = _getTimeZoneName(tzMapKey, $Date(this)) ?? UTC;
144
- if (TZ_ABBR_CACHE.has(`name-${zone}`)) return TZ_ABBR_CACHE.get(zone);
149
+ const fallbackKey = `name-${zone}`;
150
+ if (TZ_ABBR_CACHE.has(fallbackKey)) return TZ_ABBR_CACHE.get(fallbackKey);
145
151
  const customAbbr = require_guards.isValidUTCOffset(zone) ? zone : _abbreviate(zone);
146
- TZ_ABBR_CACHE.set(`name-${zone}`, customAbbr);
152
+ TZ_ABBR_CACHE.set(fallbackKey, customAbbr);
147
153
  return customAbbr;
148
154
  };
149
155
  $Chronos.prototype.getTimeZoneNameAbbr = function(utc) {
@@ -70,11 +70,16 @@ const timeZonePlugin = ($Chronos) => {
70
70
  }
71
71
  return tzIds;
72
72
  }, /* @__PURE__ */ new Map()));
73
+ const _buildTzNameAbbrMap = () => {
74
+ const result = [];
75
+ for (const [tzAbbr, { offset, tzName }] of Object.entries(TIME_ZONES)) result.unshift([offset, {
76
+ tzAbbr,
77
+ tzName
78
+ }]);
79
+ return result;
80
+ };
73
81
  /** Cache to store time zone name and abbreviation against UTC offset from {@link TIME_ZONES} */
74
- const TZ_NAME_ABBR_MAP = new Map(Object.entries(TIME_ZONES).map(([tzAbbr, { offset, tzName }]) => [offset, {
75
- tzAbbr,
76
- tzName
77
- }]));
82
+ const TZ_NAME_ABBR_MAP = new Map(_buildTzNameAbbrMap());
78
83
  /** Get time zone identifier from {@link TZ_ID_MAP} using UTC offset */
79
84
  const _getTimeZoneId = (utc) => {
80
85
  const tzIds = TZ_ID_MAP.get(utc);
@@ -131,8 +136,8 @@ const timeZonePlugin = ($Chronos) => {
131
136
  if (!utc && tracker && _isValidTzAbbr(tracker)) return tracker;
132
137
  if (isValidUTCOffset(tzMapKey)) {
133
138
  if (TZ_ABBR_CACHE.has(tzMapKey)) return TZ_ABBR_CACHE.get(tzMapKey);
134
- if (TZ_NAME_ABBR_MAP.has(tzMapKey)) return TZ_NAME_ABBR_MAP.get(tzMapKey)?.tzAbbr;
135
139
  const tzName = _resolveTzName(tzMapKey);
140
+ if (!tzName && TZ_NAME_ABBR_MAP.has(tzMapKey)) return TZ_NAME_ABBR_MAP.get(tzMapKey)?.tzAbbr;
136
141
  if (tzName) {
137
142
  const tzAbbr = _abbreviate(tzName);
138
143
  TZ_ABBR_CACHE.set(tzMapKey, tzAbbr);
@@ -140,9 +145,10 @@ const timeZonePlugin = ($Chronos) => {
140
145
  }
141
146
  }
142
147
  const zone = _getTimeZoneName(tzMapKey, $Date(this)) ?? UTC;
143
- if (TZ_ABBR_CACHE.has(`name-${zone}`)) return TZ_ABBR_CACHE.get(zone);
148
+ const fallbackKey = `name-${zone}`;
149
+ if (TZ_ABBR_CACHE.has(fallbackKey)) return TZ_ABBR_CACHE.get(fallbackKey);
144
150
  const customAbbr = isValidUTCOffset(zone) ? zone : _abbreviate(zone);
145
- TZ_ABBR_CACHE.set(`name-${zone}`, customAbbr);
151
+ TZ_ABBR_CACHE.set(fallbackKey, customAbbr);
146
152
  return customAbbr;
147
153
  };
148
154
  $Chronos.prototype.getTimeZoneNameAbbr = function(utc) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "chronos-date",
3
- "version": "1.1.2",
4
- "description": "Flexible date-time library for any JavaScript and TypeScript environment.",
3
+ "version": "1.2.1",
4
+ "description": "A lightweight, immutable, and plugin-based date-time manipulation library for JavaScript and TypeScript.",
5
5
  "main": "./dist/index.cjs",
6
6
  "type": "module",
7
7
  "sideEffects": false,
@@ -32,7 +32,7 @@
32
32
  "type": "git",
33
33
  "url": "git+https://github.com/nazmul-nhb/chronos-date.git"
34
34
  },
35
- "homepage": "https://github.com/nazmul-nhb/chronos-date#readme",
35
+ "homepage": "https://chronos.nazmul-nhb.dev",
36
36
  "author": {
37
37
  "name": "Nazmul Hassan",
38
38
  "email": "nazmulnhb@gmail.com",
@@ -57,7 +57,7 @@
57
57
  "license": "Apache-2.0",
58
58
  "devDependencies": {
59
59
  "@biomejs/biome": "^2.4.15",
60
- "@types/node": "^25.7.0",
60
+ "@types/node": "^25.8.0",
61
61
  "husky": "^9.1.7",
62
62
  "lint-staged": "^17.0.4",
63
63
  "nhb-scripts": "^1.9.2",
@@ -154,7 +154,7 @@
154
154
  "scripts": {
155
155
  "build": "tsdown",
156
156
  "dev:pkg": "tsdown --watch",
157
- "dev:docs": "pnpm --filter chronos-date-docs dev",
157
+ "dev": "pnpm --filter chronos-date-docs dev",
158
158
  "build:docs": "pnpm --filter chronos-date-docs build",
159
159
  "typecheck": "tsc --noEmit",
160
160
  "commit": "nhb-commit",