TypeScript and JavaScript
Two npm packages, released together with the same version:
nepdate-core: dates, conversion, arithmetic, formatting and parsing. ESM only, types included, zero dependencies, no event data.nepdate-patro: tithi, public holidays and events from BS 2077-01-01 to 2084-08-20. It needsnepdate-coreas a peer dependency.
For a BS date picker in the browser, see Date picker: a third package,
nepdate-datepicker, built on the core.
Pure TypeScript, no WASM and no time zone guessing. Node 22.12.0 and later, Deno, Bun and current browsers.
Install
Section titled “Install”npm install nepdate-core@betapnpm add nepdate-core@betayarn add nepdate-core@betabun add nepdate-core@betaQuick start
Section titled “Quick start”import { NepaliDate } from "nepdate-core";
const republicDay = NepaliDate.of(2081, 2, 15);console.log(republicDay.toGregorian()); // { year: 2024, month: 5, day: 28 }console.log(republicDay.toJSON()); // "2081-02-15"console.log(republicDay.long({ weekday: true })); // "Tuesday, Jestha 15, 2081"import { NepaliDate } from "npm:nepdate-core@0.1.0-beta.1";
console.log(NepaliDate.of(2081, 2, 15).toJSON()); // "2081-02-15"<script type="module">import { NepaliDate } from "https://esm.sh/nepdate-core@0.1.0-beta.1";document.body.textContent = NepaliDate.of(2081, 2, 15).toJSON();</script>toJSON() is the interchange form, "YYYY-MM-DD". toString() is the display form,
"YYYY/MM/DD". Months are 1-based everywhere, unlike JavaScript’s Date.
Today, time zones and Temporal
Section titled “Today, time zones and Temporal”today(timeZone = "Asia/Kathmandu") reads the clock through Intl.DateTimeFormat with that zone,
so the machine’s own zone never changes the answer.
GregorianDate is structural: a Temporal.PlainDate satisfies it, so no Temporal dependency is
needed. fromJSDate and toJSDate take an explicit zone because a Date holds an instant, not a
calendar day.
import { NepaliDate } from "nepdate-core";
if (globalThis.Temporal !== undefined) { const date = NepaliDate.fromGregorian(Temporal.PlainDate.from("2024-07-30")); console.log(date.toJSON()); // "2081-04-15" console.log(Temporal.PlainDate.from(date.toGregorian()).toString()); // "2024-07-30"}Tithi, holidays and events
Section titled “Tithi, holidays and events”npm install nepdate-core@beta nepdate-patro@betaimport { NepaliDate } from "nepdate-core";import { info } from "nepdate-patro";
const day = info(NepaliDate.of(2081, 2, 15));console.log(day.isPublicHoliday); // trueconsole.log(day.tithi?.en); // "Panchami"console.log(day.events.map((event) => event.en)); // ["Republic Day"]info() never fails: a day without data returns the shared empty object (tithi: null,
isPublicHoliday: false, events: []). coverage() gives the range with any data and
publicHolidays() yields the holiday dates in ascending order.
Reference
Section titled “Reference”| Topic | Where |
|---|---|
| Every exported name | docs/API.md |
| Speed and bundle size, with the C# baseline | docs/benchmarks.md |
| What changed | CHANGELOG.md |
| Source | sanamhub/nepdate-typescript |
The converter on the home page runs nepdate-core in your browser.