
import { MeroDate } from "mero-nepali-utils";
const d = MeroDate("2024-04-13");
d.toBS(); // "2081-01-01"
d.format("YYYY MMMM DD"); // "2081 ΰ€¬ΰ₯ΰ€Άΰ€Ύΰ€ 01"
β‘ Fast, accurate Nepali date library for BS β AD conversion, formatting, and localization
Most Nepali date libraries are:
Mero Nepali Utils is different:
Unlike most libraries, this avoids iterative date calculations and uses precomputed offsets + binary search for speed and accuracy.
Handling Nepali dates in JavaScript has always been painful. This library was built to provide:
without hacks or inconsistencies.
npm install mero-nepali-utils
// GOOD
createdAt = "2024-04-13";
// Convert only in UI
MeroDate(createdAt).toBS();
import { MeroDate } from "mero-nepali-utils";
const date = MeroDate("2024-04-13");
// Convert
date.toBS(); // "2081-01-01"
// Format
date.format("YYYY MMMM DD", { locale: "np" });
// "2081 ΰ€¬ΰ₯ΰ€Άΰ€Ύΰ€ 01"
// Add / subtract
date.addDays(5).toBS();
// Relative
date.fromNow();
import { meroBs } from "mero-nepali-utils";
meroBs("2024-04-13");
// "2081-01-01"
import { meroAd } from "mero-nepali-utils";
meroAd("2081-01-01");
// "2024-04-13"
Supports customizable tokens like YYYY, YY, MMMM, MM, M, DD, D for flexible UI formatting.
const d = MeroDate("2024-04-13");
d.format("YYYY-MM-DD") // 2081-01-01
d.format("DD/MM/YYYY") // 01/01/2081
d.format("DD MMMM YYYY") // 01 ΰ€¬ΰ₯ΰ€Άΰ€Ύΰ€ 2081
MeroDate.locale("np");
d.format("MMMM"); // ΰ€¬ΰ₯ΰ€Άΰ€Ύΰ€
MeroDate.locale("en");
d.format("MMMM"); // Baishakh
import { toNepaliNumber, toEnglishNumber } from "mero-nepali-utils";
toNepaliNumber(123); // ΰ₯§ΰ₯¨ΰ₯©
toEnglishNumber("ΰ₯§ΰ₯¨ΰ₯©"); // 123
Inspired by modern libraries like dayjs.
const d = MeroDate("2024-01-01");
d.toBS(); // 2080-09-16
d.toAD(); // 2024-01-01
d.addDays(5).toAD(); // 2024-01-06
d.subtractDays(5).toAD(); // 2023-12-27
d.clone(); // new instance
d.valueOf(); // timestamp
//this will crash because React cannot render objects.
<p>{d.addDays(5)}</p>
// Correct Way
<p>{d.addDays(5).toBS()}</p>
<p>{d.format("DD MMM YYYY")}</p>
No setup needed β everything works out of the box.
d.diff("2024-01-01", "days"); // 4
d.diff("2024-01-01", "months"); // 0
d.isSame("2024-01-01"); // true
d.isSame("2024-01-01", "month"); // true
d.isBetween("2024-01-01", "2024-01-10"); // true
// inclusive
d.isBetween("2024-01-01", "2024-01-10", "[]");
-isToday()
MeroDate().isToday(); // true
d.fromNow(); // "5 days ago"
d.toNow(); // "in 5 days"
d.from("2024-01-01");
-startOf / endOf
d.startOf("month").toBS(); // start of month
d.endOf("month").toBS(); // end of month
d.startOf("year").toBS();
d.endOf("year").toBS();
import { isRoundTripValid } from "mero-nepali-utils";
isRoundTripValid("2081-01-01"); //true
| Feature | Mero Nepali Utils | Others |
|---|---|---|
| Speed | β‘ O(log n) | β Linear |
| Accuracy | β Verified | β οΈ Drift |
| API | π§ Modern | β Outdated |
| Size | πͺΆ Small | β οΈ Bigger |
| TypeScript | β Full | β οΈ Partial |
const myPlugin = (cls) => {
cls.prototype.hello = function () {
return "Hello";
};
};
MeroDate.extend(myPlugin);
MeroDate().hello(); // Hello
JavaScript's native Date does not support Bikram Sambat (BS).
This library provides:
π All with accurate calendar data
Running in real-world Nepali applications
Actively maintained and production-ready.
nepali date, nepali date converter, bikram sambat, bs to ad converter, ad to bs converter, nepali calendar js, nepali date javascript, nepali date npm, nepali date library, bs calendar conversion, nepali localization, devanagari numbers, nepali number converter, nepali date formatter
MIT Β© Sakar Khadka