@nepdatejs/core 0.0.0-stage → 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Shishir Rai
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,136 @@
1
- # Temporary Holding Version
1
+ # @nepdatejs/core
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The Bikram Sambat (BS) ⇄ AD date engine: conversion, formatting, parsing, arithmetic, Nepal's fiscal year, and English/Nepali names. It depends on no package, and runs in Node (ESM and CJS), browsers and a plain `<script>` tag.
4
+
5
+ ```bash
6
+ npm install @nepdatejs/core
7
+ ```
8
+
9
+ ```ts
10
+ import { adDate, adToBs, bsDate, bsToAd, formatDate, toIsoDate } from '@nepdatejs/core';
11
+
12
+ const bs = adToBs(adDate(2026, 10, 18)); // { calendar: 'BS', year: 2083, month: 7, day: 1 }
13
+ formatDate(bs, 'long'); // "1 Kartik 2083"
14
+ formatDate(bs, 'full', 'ne'); // "आइतबार, १ कार्तिक २०८३"
15
+ toIsoDate(bsDate(2083, 6, 24)); // "2026-10-10"
16
+ ```
17
+
18
+ ## Dates
19
+
20
+ Dates are frozen plain objects, `{ calendar, year, month, day }`, typed as `AdDate` or `BsDate`. They serialise to JSON and compare by value. Functions that need one calendar take that type, so passing a BS date where an AD date is expected is a type error.
21
+
22
+ | Function | Does |
23
+ | -------------------------------------------- | --------------------------------------------------------------------- |
24
+ | `adDate(y, m, d)` / `bsDate(y, m, d)` | Create and validate. AD works for any year; BS only inside the table. |
25
+ | `createDate(calendar, y, m, d)` | Either calendar. |
26
+ | `isValidDate`, `daysInMonth`, `isAdLeapYear` | Checks. |
27
+ | `isAdDate`, `isBsDate`, `isCalendarDate` | Type guards for unknown input (e.g. JSON). |
28
+
29
+ Invalid dates throw `NepDateRangeError` with a `code`: `'INVALID_DATE'`, `'OUT_OF_TABLE'` or `'INVALID_ARGUMENT'`. Nothing is silently clamped.
30
+
31
+ ## Conversion
32
+
33
+ | Function | Does |
34
+ | --------------------------------------------------------------- | -------------------------------------------------------------------- |
35
+ | `adToBs(ad)`, `bsToAd(bs)`, `toCalendar(date, 'AD' \| 'BS')` | Convert. Throws `OUT_OF_TABLE` outside 1913-04-13 – 2043-04-13 AD. |
36
+ | `toIsoDate(date)` | The AD day as `"YYYY-MM-DD"`, ready to store or send. |
37
+ | `fromIsoDate(text)` | `"2026-10-18"` or a longer ISO timestamp → `AdDate`, or `null`. |
38
+ | `fromJsDate(date, timeZone?)` | The calendar day of a JS `Date` in a time zone (Nepal by default). |
39
+ | `fromIsoTimestamp(text, timeZone?)` | `"2026-04-13T20:00:00Z"` → `{ date, time: "01:45" }` in Nepal time. |
40
+ | `today(calendar?, timeZone?)` | Today in Nepal (configurable), not the device's zone. |
41
+ | `minDate(calendar)`, `maxDate(calendar)`, `isConvertible(date)` | The range that can be converted. |
42
+ | `toEpoch(date)`, `fromEpoch(day, calendar)` | Whole days since 1970-01-01, the only thing the two calendars share. |
43
+
44
+ ## Arithmetic and comparison
45
+
46
+ These work in the date's own calendar, and compare across calendars.
47
+
48
+ - `addDays`, `addMonths`, `addYears`: the day is capped to the target month.
49
+ - `startOfMonth`, `endOfMonth`, `startOfWeek`, `endOfWeek`, `startOfYear`, `endOfYear`.
50
+ - `differenceInDays`, `eachDayOfInterval`, `eachDayOfMonth`.
51
+ - `compareDates`, `isSameDay`, `isSameMonth`, `isSameYear`, `isBefore`, `isAfter`, `isWithin`, `clampDate`.
52
+ - `dayOfWeek`, `isWeekend`.
53
+
54
+ ## Formatting and parsing
55
+
56
+ ```ts
57
+ formatDate(date, 'iso'); // 2083-07-01
58
+ formatDate(date, 'cbms'); // 2083.07.01
59
+ formatDate(date, 'short'); // 1 Kar 2083
60
+ formatDate(date, 'D, j M y \\Y'); // Sun, 1 Kar 83 Y
61
+ parseDate('2083/7/1', 'BS'); // year first only (or compact '20830701'); ASCII or Devanagari digits; null if invalid
62
+ parseDateStrict('17 July 2025', 'BS'); // throws with a reason
63
+ ```
64
+
65
+ | Token | Output |
66
+ | ----- | ---------------- |
67
+ | `Y` | 2083 |
68
+ | `y` | 83 |
69
+ | `m` | 07 |
70
+ | `n` | 7 |
71
+ | `d` | 01 |
72
+ | `j` | 1 |
73
+ | `F` | month name |
74
+ | `M` | short month name |
75
+ | `l` | weekday |
76
+ | `D` | short weekday |
77
+
78
+ Put a backslash before a letter to print it as is. Digits follow the locale.
79
+
80
+ ## Fiscal year
81
+
82
+ Nepal's fiscal year runs from 1 Shrawan to the end of Asar.
83
+
84
+ ```ts
85
+ fiscalYear(date).label; // "2083/84"
86
+ formatFiscalYear(fiscalYear(date), 'cbms'); // "2083.084"
87
+ parseFiscalYear('२०८३/८४'); // FiscalYear | null
88
+ isInFiscalYear(date, fiscalYearRange(2083));
89
+ ```
90
+
91
+ ## Time
92
+
93
+ ```ts
94
+ parseTime('2:30 pm'); // { hour: 14, minute: 30 }; also "14:30", "1430", "२:३० अपराह्न"
95
+ formatTime(timeOfDay(14, 30), { hour12: true, locale: 'ne' }); // "२:३० अपराह्न"
96
+ toIsoDateTime(bsDate(2083, 7, 1), timeOfDay(14, 30)); // "2026-10-18T14:30:00+05:45" (Nepal by default)
97
+ fromIsoDateTime('2026-10-18T09:00:00Z'); // { date: 2026-10-18 AD, time: 14:45 } in Nepal time
98
+ now(); // { date, time } in the configured zone
99
+ ```
100
+
101
+ ## Locales and config
102
+
103
+ ```ts
104
+ import { configure, getLocale, monthNames, registerLocale } from '@nepdatejs/core';
105
+
106
+ configure({
107
+ timeZone: 'Asia/Kathmandu',
108
+ weekStartsOn: 0,
109
+ weekendDays: [6],
110
+ defaultLocale: 'ne',
111
+ });
112
+ monthNames('BS', 'ne'); // ['बैशाख', 'जेठ', …]
113
+ registerLocale('xx', { ...getLocale('en'), digits: [/* ten digits */] });
114
+ ```
115
+
116
+ ## The BS table
117
+
118
+ BS month lengths come from a table keyed by BS year (1970–2099), verified through 2083. The table holds no AD dates, so fixing one BS year never changes any AD result, or any BS date before that year.
119
+
120
+ ```ts
121
+ isProjected(bsDate(2084, 1, 1)); // true: after the last verified year
122
+ patchBsYear(2090, [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30]); // correct one year
123
+ setBsData(table); // replace the whole table (validated)
124
+ import { BS_DATA } from '@nepdatejs/core/data'; // the raw bundled table
125
+ ```
126
+
127
+ ## In a `<script>` tag
128
+
129
+ ```html
130
+ <script src="https://unpkg.com/@nepdatejs/core"></script>
131
+ <script>
132
+ NepDate.formatDate(NepDate.today('BS'), 'long');
133
+ </script>
134
+ ```
135
+
136
+ MIT © Shishir Rai
package/dist/data.cjs ADDED
@@ -0,0 +1,3 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_years = require("./years-J6lZENDt.cjs");
3
+ exports.BS_DATA = require_years.BS_DATA;
@@ -0,0 +1,16 @@
1
+ //#region src/bs/data/years.d.ts
2
+ /** The bundled Bikram Sambat table: month lengths keyed by BS year, no AD dates. */
3
+ interface GeneratedBsData {
4
+ /** The BS year of the first row. */
5
+ readonly firstYear: number;
6
+ /** Days since 1970-01-01 of 1 Baisakh of `firstYear`. */
7
+ readonly epochStart: number;
8
+ /** Years after this one are projections, not yet checked against a published calendar. */
9
+ readonly verifiedThrough: number;
10
+ /** Twelve month lengths (Baisakh..Chaitra) per year, starting at `firstYear`. */
11
+ readonly years: readonly (readonly number[])[];
12
+ }
13
+ export declare const BS_DATA: GeneratedBsData;
14
+ //#endregion
15
+ export type { GeneratedBsData };
16
+ //# sourceMappingURL=data.d.cts.map
package/dist/data.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ //#region src/bs/data/years.d.ts
2
+ /** The bundled Bikram Sambat table: month lengths keyed by BS year, no AD dates. */
3
+ interface GeneratedBsData {
4
+ /** The BS year of the first row. */
5
+ readonly firstYear: number;
6
+ /** Days since 1970-01-01 of 1 Baisakh of `firstYear`. */
7
+ readonly epochStart: number;
8
+ /** Years after this one are projections, not yet checked against a published calendar. */
9
+ readonly verifiedThrough: number;
10
+ /** Twelve month lengths (Baisakh..Chaitra) per year, starting at `firstYear`. */
11
+ readonly years: readonly (readonly number[])[];
12
+ }
13
+ export declare const BS_DATA: GeneratedBsData;
14
+ //#endregion
15
+ export type { GeneratedBsData };
16
+ //# sourceMappingURL=data.d.ts.map
package/dist/data.js ADDED
@@ -0,0 +1 @@
1
+ export { t as BS_DATA } from "./years-CabTFbN9.js";