neramjs 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/CHANGELOG.md ADDED
@@ -0,0 +1,39 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0 — 2026-12-04
4
+
5
+ First release.
6
+
7
+ - Ships as ESM and CommonJS. `require('neramjs')` returns the `neram` function, as `require('dayjs')` does, and
8
+ `require('neramjs/recur')` shares its copy. TypeScript types cover both, plus script-tag builds (`window.neram`).
9
+
10
+ - Day.js-compatible, immutable API: parse, get/set, add/subtract, startOf/endOf, diff, comparisons.
11
+ - IANA time zones and fixed offsets with DST handling that follows Temporal's "compatible" rule.
12
+ - Every `Intl` locale for names, localized formats (`L`…`LLLL`), week start and weekend.
13
+ - Relative time (`from`, `fromNow`, `to`, `toNow`) and `calendar()`.
14
+ - `Duration`: ISO 8601 parse/format, arithmetic, `normalize`, `humanize`, `format`, `toLocaleString`.
15
+ - Custom-format parsing with strict mode; impossible dates are invalid.
16
+ - Business days with holidays and locale weekends.
17
+ - ISO and locale week numbers, quarters, day of year, `round`, `clamp`, `durationTo`.
18
+ - RFC 9557 strings (`…+05:30[Asia/Kolkata]`) and Temporal interop.
19
+ - Day.js-style plugins via `neram.extend`.
20
+ - Day.js-compatible `localeData`: `neram.localeData(locale?)` and `d.localeData()` with `months()`,
21
+ `monthsShort()`, `weekdays()`, `weekdaysShort()`, `weekdaysMin()` (pass a date for that date's name),
22
+ `firstDayOfWeek()`, `meridiem()`, `ordinal()` and `week()`.
23
+ - `neramjs/recur`: RFC 5545 recurrence rules (RRULE, RDATE, EXDATE, all-day events) and cron schedules
24
+ (5/6 fields, Quartz `L`/`W`/`#`), evaluated in any IANA zone with DST-safe wall-clock times. Query with
25
+ `between`, `after`, `before`, `take`, `instances` (start/end for calendar views), and choose the output
26
+ format: ISO, zoned ISO, local, epoch, Date, Neram or a database-ready record. Rules serialise to RFC 5545
27
+ text or JSON and load back unchanged.
28
+ - Same results on server and browser: week rules (first day, weekend, week numbers) come from a built-in
29
+ CLDR 48 table instead of `Intl.Locale#getWeekInfo`; Unicode spaces in localized output are normalized to
30
+ plain spaces (`neram.config({ normalizeSpaces })`); relative time, lists and durations fall back to English
31
+ where Intl lacks them; `neram.environment()` reports ICU/CLDR/tz versions and Intl features.
32
+ - Strict validation: impossible dates in objects and arrays, offsets beyond ±23:59 and empty zone names are rejected;
33
+ `range()`, business days, durations, rule options and query limits reject values that cannot work instead of
34
+ silently returning wrong results. Invalid durations (`isValid()`), symmetric rounding of fractional calendar
35
+ amounts, and `with()` swapping `count` and `until`.
36
+ - CI on Node 20.19, 22 and 24 (Linux, macOS, Windows), package checks against the packed tarball, coverage, and a
37
+ tag-driven release workflow publishing to npm with provenance.
38
+ - Zone names are always current IANA names: `Asia/Calcutta` (reported by V8 and ICU) becomes `Asia/Kolkata`,
39
+ `Europe/Kiev` becomes `Europe/Kyiv`, and so on, when the runtime knows the new name.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 neram contributors
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,122 @@
1
- # Temporary Holding Version
1
+ <p align="center">
2
+ <a href="https://varksh05.github.io/neramjs/">
3
+ <picture>
4
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/varksh05/neramjs/main/assets/logo-dark.svg">
5
+ <img src="https://raw.githubusercontent.com/varksh05/neramjs/main/assets/logo-light.svg" alt="neramjs logo: the Tamil letter நே with an orange dot" height="96">
6
+ </picture>
7
+ </a>
8
+ </p>
2
9
 
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.
10
+ <p align="center">Dates, time zones and recurring events for JavaScript. <b>One import.</b></p>
11
+
12
+ <p align="center">
13
+ <a href="https://github.com/varksh05/neramjs/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/varksh05/neramjs/ci.yml?branch=main&style=flat-square&label=tests" alt="Tests"></a>
14
+ <a href="https://varksh05.github.io/neramjs/"><img src="https://img.shields.io/badge/docs-varksh05.github.io%2Fneramjs-FF6A13?style=flat-square" alt="Docs"></a>
15
+ <a href="./LICENSE"><img src="https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square" alt="License"></a>
16
+ </p>
17
+
18
+ > neramjs is a date library for JavaScript and TypeScript with a small, chainable API, real time zones,
19
+ > every language, and calendar repeat rules that give the same answer on the server and in the browser.
20
+ > *neram (நேரம்) means "time" in Tamil.*
21
+
22
+ ```js
23
+ import { neram } from 'neramjs'
24
+
25
+ neram('2026-12-04T09:00:00Z').tz('Asia/Kolkata').format('dddd, D MMM YYYY h:mm A') // → 'Friday, 4 Dec 2026 2:30 PM'
26
+ ```
27
+
28
+ - 🕒 **Familiar, chainable API**, immutable values
29
+ - 🌍 **Real time zones**: every IANA zone, daylight saving handled the way Temporal does it
30
+ - 🌐 **Every language** the runtime knows, with no locale files to import
31
+ - 🔁 **Recurring events and cron**: RFC 5545 repeat rules (as in Google Calendar) and cron, in any zone
32
+ - 🤝 **Same answer on server and browser**, so what you store never depends on the runtime
33
+ - 📦 **Zero dependencies**, about 13 KB gzipped; ESM, CommonJS and a script tag, with TypeScript types
34
+
35
+ ---
36
+
37
+ ## Getting started
38
+
39
+ ### Documentation
40
+
41
+ Guides, the full API and a playground to run code in your browser are at
42
+ **[varksh05.github.io/neramjs](https://varksh05.github.io/neramjs/)**.
43
+ For AI agents, the docs are also available as plain text:
44
+ [llms.txt](https://varksh05.github.io/neramjs/llms.txt) and [llms-full.txt](https://varksh05.github.io/neramjs/llms-full.txt).
45
+
46
+ ### Installation
47
+
48
+ ```bash
49
+ npm i neramjs
50
+ ```
51
+
52
+ ```cjs
53
+ const neram = require('neramjs') // CommonJS works too
54
+ ```
55
+
56
+ ```html
57
+ <script src="https://unpkg.com/neramjs"></script> <!-- window.neram -->
58
+ ```
59
+
60
+ 📚 [Installation guide](https://varksh05.github.io/neramjs/docs/installation/)
61
+
62
+ ### API
63
+
64
+ Parse, show, change and compare dates. Time zones, relative time and locales are built in, with nothing to configure.
65
+
66
+ ```js
67
+ import { neram } from 'neramjs'
68
+
69
+ const d = neram.utc('2026-12-04 14:30')
70
+
71
+ d.add(1, 'month').startOf('month').format('YYYY-MM-DD') // → '2027-01-01'
72
+ d.isBefore('2027-01-01') // → true
73
+ d.subtract(3, 'hour').from(d) // → '3 hours ago'
74
+ d.locale('ta').format('dddd, D MMMM YYYY') // → 'வெள்ளி, 4 டிசம்பர் 2026'
75
+ ```
76
+
77
+ 📚 [API reference](https://varksh05.github.io/neramjs/docs/api/)
78
+
79
+ ### Time zones
80
+
81
+ Show a stored time in the user's zone, and save a time they picked in theirs.
82
+
83
+ ```js
84
+ import { neram } from 'neramjs'
85
+
86
+ neram('2026-12-04T09:00:00.000Z').tz('America/New_York').format('ddd, MMM D [at] h:mm A z') // → 'Fri, Dec 4 at 4:00 AM EST'
87
+ neram.tz('2026-12-04 18:30', 'Asia/Kolkata').toISOString() // → '2026-12-04T13:00:00.000Z'
88
+ ```
89
+
90
+ 📚 [Time zones](https://varksh05.github.io/neramjs/docs/time-zones/)
91
+
92
+ ### Recurring events and cron
93
+
94
+ ```js
95
+ import { rrule, cron } from 'neramjs/recur'
96
+
97
+ const standup = rrule({ freq: 'weekly', byDay: ['MO', 'WE', 'FR'], dtstart: '2026-12-07 09:00', tz: 'Asia/Kolkata' })
98
+ standup.take(2, { from: '2026-12-01', as: 'local' }) // → ['2026-12-07T09:00:00', '2026-12-09T09:00:00']
99
+
100
+ cron('0 9 * * MON-FRI', { tz: 'Asia/Kolkata' }).after('2026-12-04 10:00', { as: 'iso' }) // → '2026-12-07T03:30:00.000Z'
101
+ ```
102
+
103
+ 📚 [Recurring events](https://varksh05.github.io/neramjs/docs/recurrence/) ·
104
+ [Cron](https://varksh05.github.io/neramjs/docs/cron/) ·
105
+ [Storing rules in a database](https://varksh05.github.io/neramjs/docs/storing-rules/)
106
+
107
+ ### More
108
+
109
+ 📚 [Compared with other libraries](https://varksh05.github.io/neramjs/docs/comparison/) ·
110
+ [Performance](https://varksh05.github.io/neramjs/docs/performance/)
111
+
112
+ ## Playground
113
+
114
+ Try neramjs without installing it: **[open the playground](https://varksh05.github.io/neramjs/playground/)**.
115
+
116
+ ## Contributing
117
+
118
+ Bug reports and pull requests are welcome. See [CONTRIBUTING.md](./CONTRIBUTING.md) for running the tests and the docs site.
119
+
120
+ ## License
121
+
122
+ neramjs is licensed under the [MIT License](./LICENSE).
@@ -0,0 +1,25 @@
1
+ export declare function isLeapYear(y: number): boolean;
2
+ /**
3
+ * Calendar date for a day number (days since 1970-01-01, proleptic Gregorian), with no Date allocation.
4
+ * Howard Hinnant's civil_from_days. M is 0-11, dow 0 = Sunday.
5
+ */
6
+ export declare function civilFromDays(n: number): {
7
+ y: number;
8
+ M: number;
9
+ D: number;
10
+ dow: number;
11
+ };
12
+ export declare function daysInMonth(y: number, M: number): number;
13
+ export declare function daysInYear(y: number): number;
14
+ /** 1-based day of the year. */
15
+ export declare function dayOfYear(y: number, M: number, D: number): number;
16
+ export declare function weekdayOf(y: number, M: number, D: number): number;
17
+ /**
18
+ * Week number and week-year for any week rule.
19
+ * ISO 8601 is { firstDay: 1, minimalDays: 4 }; US is { firstDay: 0, minimalDays: 1 }.
20
+ */
21
+ export declare function weekOfYear(y: number, M: number, D: number, firstDay: number, minimalDays: number): {
22
+ week: number;
23
+ year: number;
24
+ };
25
+ export declare function weeksInYear(y: number, firstDay: number, minimalDays: number): number;
@@ -0,0 +1,59 @@
1
+ import { utcFromParts } from './zone.js';
2
+ export function isLeapYear(y) {
3
+ return (y % 4 === 0 && y % 100 !== 0) || y % 400 === 0;
4
+ }
5
+ /**
6
+ * Calendar date for a day number (days since 1970-01-01, proleptic Gregorian), with no Date allocation.
7
+ * Howard Hinnant's civil_from_days. M is 0-11, dow 0 = Sunday.
8
+ */
9
+ export function civilFromDays(n) {
10
+ const z = n + 719468;
11
+ const era = Math.floor(z / 146097);
12
+ const doe = z - era * 146097;
13
+ const yoe = Math.floor((doe - Math.floor(doe / 1460) + Math.floor(doe / 36524) - Math.floor(doe / 146096)) / 365);
14
+ const doy = doe - (365 * yoe + Math.floor(yoe / 4) - Math.floor(yoe / 100));
15
+ const mp = Math.floor((5 * doy + 2) / 153);
16
+ const D = doy - Math.floor((153 * mp + 2) / 5) + 1;
17
+ const M = mp < 10 ? mp + 2 : mp - 10;
18
+ return { y: yoe + era * 400 + (M <= 1 ? 1 : 0), M, D, dow: (((n % 7) + 7 + 4) % 7) };
19
+ }
20
+ const MONTH_DAYS = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
21
+ export function daysInMonth(y, M) {
22
+ return M === 1 && isLeapYear(y) ? 29 : MONTH_DAYS[M];
23
+ }
24
+ export function daysInYear(y) {
25
+ return isLeapYear(y) ? 366 : 365;
26
+ }
27
+ /** 1-based day of the year. */
28
+ export function dayOfYear(y, M, D) {
29
+ return Math.round((utcFromParts(y, M, D) - utcFromParts(y, 0, 1)) / 86400000) + 1;
30
+ }
31
+ export function weekdayOf(y, M, D) {
32
+ return new Date(utcFromParts(y, M, D)).getUTCDay();
33
+ }
34
+ /**
35
+ * Week number and week-year for any week rule.
36
+ * ISO 8601 is { firstDay: 1, minimalDays: 4 }; US is { firstDay: 0, minimalDays: 1 }.
37
+ */
38
+ export function weekOfYear(y, M, D, firstDay, minimalDays) {
39
+ const doy = dayOfYear(y, M, D);
40
+ const idx = (weekdayOf(y, M, D) - firstDay + 7) % 7;
41
+ const weekStart = doy - idx;
42
+ const jan1Idx = (weekdayOf(y, 0, 1) - firstDay + 7) % 7;
43
+ const week1Start = 7 - jan1Idx >= minimalDays ? 1 - jan1Idx : 8 - jan1Idx;
44
+ if (weekStart < week1Start)
45
+ return weekOfYear(y - 1, 11, 31, firstDay, minimalDays);
46
+ const daysInNextYear = weekStart + 6 - daysInYear(y);
47
+ if (daysInNextYear >= minimalDays)
48
+ return { week: 1, year: y + 1 };
49
+ return { week: Math.floor((weekStart - week1Start) / 7) + 1, year: y };
50
+ }
51
+ export function weeksInYear(y, firstDay, minimalDays) {
52
+ // The last week of the year is the week containing the last day that still belongs to it.
53
+ for (let d = 31; d > 24; d--) {
54
+ const w = weekOfYear(y, 11, d, firstDay, minimalDays);
55
+ if (w.year === y)
56
+ return w.week;
57
+ }
58
+ return 52;
59
+ }