mero-nepali-utils - v1.0.5
    Preparing search index...

    mero-nepali-utils - v1.0.5

    πŸ‡³πŸ‡΅ Mero Nepali Utils

    Mero Nepali Utils Preview

    npm version npm downloads Bundle Size License: MIT CI

    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:

    • ❌ Slow (linear search)
    • ❌ Inaccurate (date drift)
    • ❌ Hard to use

    Mero Nepali Utils is different:

    • ⚑ O(log n) conversion (faster than most libraries)
    • 🎯 Accurate BS data (2000–2090)
    • 🧠 Modern API (like dayjs)
    • πŸ”’ Built-in Nepali number conversion
    • 🌐 Localization support (NP / EN)
    • 🧠 TypeScript-first (fully typed)
    • πŸͺΆ < 5KB gzipped
    • πŸ“¦ Tree-shakable

    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:

    • accurate conversion
    • clean developer experience
    • modern API

    without hacks or inconsistencies.


    npm install mero-nepali-utils
    
    // GOOD 
    createdAt = "2024-04-13";
    // Convert only in UI
    MeroDate(createdAt).toBS();
    • Causes bugs
    • Hard to integrate with APIs
    • Not standard
    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.

    • diff()
    d.diff("2024-01-01", "days"); // 4
    d.diff("2024-01-01", "months"); // 0
    • isSame()
    d.isSame("2024-01-01"); // true
    d.isSame("2024-01-01", "month"); // true
    • isBetween()
    d.isBetween("2024-01-01", "2024-01-10"); // true

    // inclusive
    d.isBetween("2024-01-01", "2024-01-10", "[]");

    -isToday()

    MeroDate().isToday(); // true
    
    • Relative Time
    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
    • No Drift
    • No Mutation
    • Fully deterministic
    • Uses precomputed BS calendar data
    • Converts using day offsets (no loops)
    • Binary search for fast lookup πŸ‘‰ Result:
    • Fast
    • Accurate
    • Predictable
    • BS: 2000 β†’ 2090
    • AD: 1943 β†’ 2033
    • πŸ‡³πŸ‡΅ Nepali SaaS apps
    • πŸ“Š Dashboards
    • 🧾 Billing Systems
    • 🧾 Invoice systems
    • 🏦 Fintech apps
    • πŸ“… Date pickers
    • 🌐 Localization
    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:

    • BS ↔ AD conversion
    • Nepali month names
    • Nepali number formatting

    πŸ‘‰ 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