UNPKG

@rishovt/angular-nepali-datepicker

Version:

A lightweight Angular wrapper and fully customizable, non-typeable Nepali datepicker component for Angular with support for Unicode-rendered Nepali dates, BS↔AD conversion, and flexible date formats. Ideal for forms requiring calendar-based input with nat

1 lines 49.1 kB
var NepaliFunctions = function () { "use strict"; var e = ["YYYY-MM-DD", "YYYY/MM/DD", "YYYY.MM.DD", "DD-MM-YYYY", "DD/MM/YYYY", "DD.MM.YYYY", "MM-DD-YYYY", "MM/DD/YYYY"], t = "==", n = "<", a = "<=", i = ">", r = ">=", s = "AD", o = "YYYY-MM-DD", h = "MM/DD/YYYY"; function u() { var e = [], t = { year: 2e3, month: 9, day: 17 }, n = { year: 1944, month: 1, day: 1 }; e[1970] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], e[1971] = [31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30], e[1972] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], e[1973] = [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31], e[1974] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], e[1975] = [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], e[1976] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], e[1977] = [30, 32, 31, 32, 31, 31, 29, 30, 29, 30, 29, 31], e[1978] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], e[1979] = [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], e[1980] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], e[1981] = [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30], e[1982] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], e[1983] = [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], e[1984] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], e[1985] = [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30], e[1986] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], e[1987] = [31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30], e[1988] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], e[1989] = [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30], e[1990] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], e[1991] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30], e[1992] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31], e[1993] = [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30], e[1994] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], e[1995] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30], e[1996] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31], e[1997] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], e[1998] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], e[1999] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], e[2e3] = [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31], e[2001] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], e[2002] = [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], e[2003] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], e[2004] = [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31], e[2005] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], e[2006] = [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], e[2007] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], e[2008] = [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31], e[2009] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], e[2010] = [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], e[2011] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], e[2012] = [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30], e[2013] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], e[2014] = [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], e[2015] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], e[2016] = [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30], e[2017] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], e[2018] = [31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30], e[2019] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31], e[2020] = [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30], e[2021] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], e[2022] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30], e[2023] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31], e[2024] = [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30], e[2025] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], e[2026] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], e[2027] = [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31], e[2028] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], e[2029] = [31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30], e[2030] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], e[2031] = [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31], e[2032] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], e[2033] = [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], e[2034] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], e[2035] = [30, 32, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31], e[2036] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], e[2037] = [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], e[2038] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], e[2039] = [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30], e[2040] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], e[2041] = [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], e[2042] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], e[2043] = [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30], e[2044] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], e[2045] = [31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30], e[2046] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], e[2047] = [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30], e[2048] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], e[2049] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30], e[2050] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31], e[2051] = [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30], e[2052] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], e[2053] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30], e[2054] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31], e[2055] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], e[2056] = [31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30], e[2057] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], e[2058] = [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31], e[2059] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], e[2060] = [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], e[2061] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], e[2062] = [30, 32, 31, 32, 31, 31, 29, 30, 29, 30, 29, 31], e[2063] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], e[2064] = [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], e[2065] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], e[2066] = [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31], e[2067] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], e[2068] = [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], e[2069] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], e[2070] = [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30], e[2071] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], e[2072] = [31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30], e[2073] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], e[2074] = [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30], e[2075] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], e[2076] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30], e[2077] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31], e[2078] = [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30], e[2079] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], e[2080] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30], e[2081] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31], e[2082] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], e[2083] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], e[2084] = [31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30], e[2085] = [31, 32, 31, 32, 30, 31, 30, 30, 29, 30, 30, 30], e[2086] = [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30], e[2087] = [31, 31, 32, 31, 31, 31, 30, 30, 29, 30, 30, 30], e[2088] = [30, 31, 32, 32, 30, 31, 30, 30, 29, 30, 30, 30], e[2089] = [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30], e[2090] = [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30], e[2091] = [31, 31, 32, 31, 31, 31, 30, 30, 29, 30, 30, 30], e[2092] = [30, 31, 32, 32, 31, 30, 30, 30, 29, 30, 30, 30], e[2093] = [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30], e[2094] = [31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30], e[2095] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 30, 30, 30], e[2096] = [30, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], e[2097] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30], e[2098] = [31, 31, 32, 31, 31, 31, 29, 30, 29, 30, 29, 31], e[2099] = [31, 31, 32, 31, 31, 31, 30, 29, 29, 30, 30, 30]; var a = { year: 1970, month: 1, day: 1 }, i = { year: 2099, month: 12, day: 30 }; function r(e) { var t = 0; return e.forEach((function (e) { t += e })), t } function s(e, t) { var n = Date.UTC(e.year, e.month - 1, e.day), a = Date.UTC(t.year, t.month - 1, t.day); return Math.abs((a - n) / 864e5) } function o(t, n) { var a = 0, i = 0; for (i = t.year; i <= n.year; i += 1)a += r(e[i]); for (i = 0; i < t.month; i += 1)a -= e[t.year][i]; for (a += e[t.year][11], i = n.month - 1; i < 12; i += 1)a -= e[n.year][i]; return a -= t.day + 1, a += n.day - 1 } function u(e, t) { var n = new Date(p(e, h)); return n.setDate(n.getDate() + t), { year: n.getFullYear(), month: n.getMonth() + 1, day: n.getDate() } } function d(t, n) { for (t.day += n; t.day > e[t.year][t.month - 1];)t.day -= e[t.year][t.month - 1], t.month += 1, t.month > 12 && (t.month = 1, t.year += 1); return { year: t.year, month: t.month, day: t.day } } return { minDate: function () { return a }, maxDate: function () { return i }, countAdDays: s, countBsDays: o, addBsDays: d, addAdDays: u, bs2ad: function (e) { var a = o(t, e); return u(n, a) }, ad2bs: function (e) { var a = s(n, e); return d(t, a) }, getDaysInMonth: function (t, n) { return e[t][n - 1] } } } function d(e, t, n) { var a, i = o; return n == s && (i = h, "[object Date]" === Object.prototype.toString.call(e) && (e = { year: (a = e).getFullYear(), month: a.getMonth() + 1, day: a.getDate() }, t = h)), function (e) { return "object" == typeof e && e.year && e.month && e.day }(e) || (e = D(e, t = l(t) ? t : i)), { dateObject: e, dateFormat: t } } function l(t) { return e.indexOf(t) > -1 } function c(e, t, n) { var a = d(e, t, s); if (e = a.dateObject, t = a.dateFormat, !e) return null; var i = (new u).ad2bs(e); return t ? (t = l(t) ? t : h, p(i, n = l(n) ? n : o)) : i } function m(e, t, n) { var a = d(e, t); if (e = a.dateObject, t = a.dateFormat, !e) return null; var i = (new u).bs2ad(e); return t ? (t = l(t) ? t : h, p(i, n = l(n) ? n : o)) : i } function p(t, n) { n = n && e.indexOf(n) > -1 ? n : o; let a = t.year, i = String(t.month).padStart(2, "0"), r = String(t.day).padStart(2, "0"); return n.replace("YYYY", a).replace("MM", i).replace("DD", r) } function D(e, t) { if (!e || !t) return null; var n = [], a = { year: null, month: null, day: null }; switch (t) { case "MM/DD/YYYY": 3 == (n = e.split("/")).length && (a = { year: Number(n[2]), month: Number(n[0]), day: Number(n[1]) }); break; case "MM-DD-YYYY": 3 == (n = e.split("-")).length && (a = { year: Number(n[2]), month: Number(n[0]), day: Number(n[1]) }); break; case "YYYY-MM-DD": 3 == (n = e.split("-")).length && (a = { year: Number(n[0]), month: Number(n[1]), day: Number(n[2]) }); break; case "YYYY/MM/DD": 3 == (n = e.split("/")).length && (a = { year: Number(n[0]), month: Number(n[1]), day: Number(n[2]) }); break; case "YYYY.MM.DD": 3 == (n = e.split(".")).length && (a = { year: Number(n[0]), month: Number(n[1]), day: Number(n[2]) }); break; case "DD-MM-YYYY": 3 == (n = e.split("-")).length && (a = { year: Number(n[2]), month: Number(n[1]), day: Number(n[0]) }); break; case "DD/MM/YYYY": 3 == (n = e.split("/")).length && (a = { year: Number(n[2]), month: Number(n[1]), day: Number(n[0]) }); break; case "DD.MM.YYYY": 3 == (n = e.split(".")).length && (a = { year: Number(n[2]), month: Number(n[1]), day: Number(n[0]) }) }return a?.year && a?.month && a?.day || (a = null), a } function y(e) { const t = { 0: "०", 1: "१", 2: "२", 3: "३", 4: "४", 5: "५", 6: "६", 7: "७", 8: "८", 9: "९" }; e = e.toString(); var n = "", a = 0; for (a = 0; a < e.length; a += 1)n += t[e[a]] || e[a]; return n } function f(e) { var t = new Date; t.setHours(t.getHours() + 5), t.setMinutes(t.getMinutes() + 45); var n = t.getUTCDate(), a = t.getUTCMonth() + 1, i = { year: t.getUTCFullYear(), month: a, day: n }; return e ? p(i, e = l(e) ? e : h) : i } function g(e) { return e = Number(e), isNaN(e) || e < 0 || e > 6 ? null : ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"][Number(e)] } function v() { return ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"] } function b() { return ["S", "M", "T", "W", "T", "F", "S"] } function Y() { return ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"] } function M(e, t, n, a) { var i = d(e, n); if (e = i.dateObject, n = i.dateFormat, !e) return null; if (!(t = d(t, n).dateObject)) return null; var r = null, s = null; switch (k(e) && k(t) ? (e = m(e), t = m(t), r = new Date(e.year, e.month - 1, e.day).getTime(), s = new Date(t.year, t.month - 1, t.day).getTime()) : (r = 1e4 * e.year + 100 * e.month + e.day, s = 1e4 * t.year + 100 * t.month + t.day), a) { case "==": return r == s; case ">": return r > s; case ">=": return r >= s; case "<": return r < s; case "<=": return r <= s } } function N(e) { var t = c(f()); return e ? p(t, e = l(e) ? e : o) : t } function F(e) { return e = Number(e), isNaN(e) || e < 0 || e > 6 ? null : ["आइतवार", "सोमवार", "मङ्गलवार", "बुधवार", "बिहिवार", "शुक्रवार", "शनिवार"][Number(e)] } function S() { return ["आ", "सो", "मं", "बु", "बि", "शु", "श"] } function T(e, t) { var n = new u, a = n.minDate(), i = n.maxDate(); return (e < a.year || e > i.year) && (t < a.month || t > a.month) ? 0 : n.getDaysInMonth(e, t) } function w() { return ["आइतवार", "सोमवार", "मङ्गलवार", "बुधवार", "बिहिवार", "शुक्रवार", "शनिवार"] } function C() { return ["Baisakh", "Jestha", "Ashar", "Shrawan", "Bhadra", "Ashoj", "Kartik", "Mangsir", "Poush", "Magh", "Falgun", "Chaitra"] } function E() { return ["बैशाख", "जेठ", "अषाढ", "श्रावण", "भाद्र", "आश्विन", "कार्तिक", "मङ्सिर", "पौष", "माघ", "फाल्गुन", "चैत्र"] } function k(e, t) { var n = d(e, t); if (e = n.dateObject, t = n.dateFormat, !e) return !1; var a = new u, i = a.minDate(), r = a.maxDate(), s = e.day + 100 * e.month + 1e4 * e.year, o = i.day + 100 * i.month + 1e4 * i.year; if (s > r.day + 100 * r.month + 1e4 * r.year || s < o) return !1; var h = T(e.year, e.month); return e.month > 0 && e.month <= 12 && e.day > 0 && e.day <= h } return { AvailableFormats: e, IsValidDateFormat: l, Get2DigitNo: function (e) { return String(e).padStart(2, "0") }, ParseDate: function (e) { var t = e.indexOf("/") > -1, n = e.indexOf("-") > -1, a = null; if (t) { var i = e.split("/"); 3 == i.length && ((a = s(i)).parsedFormat = a.parsedFormat.join("/")) } else if (n) { var r = e.split("-"); 3 == r.length && ((a = s(r)).parsedFormat = a.parsedFormat.join("-")) } function s(e) { var t = {}, n = [], a = []; e.forEach((function (e, t) { var n = parseInt(e), i = { index: t, value: n, year: !1, month: !1, day: !1 }; n > 0 && n > 999 ? i.year = !0 : n > 0 && n > 12 ? i.day = !0 : n > 0 && n <= 12 && (i.month = !0, i.day = !0), a.push(i) })); var i = a.filter((function (e) { return 1 == e.year }))[0]; if (i) { t.year = i.value, n[i.index] = "YYYY"; var r = a.filter((function (e) { return 1 == e.day })), s = a.filter((function (e) { return 1 == e.month })); 1 == s.length ? (t.month = s[0].value, n[s[0].index] = "MM", 1 == r.length ? (t.day = r[0].value, n[r[0].index] = "DD") : (r = r.find((function (e) { return !e.month })), t.day = r.value, n[r.index] = "DD")) : 2 == s.length && (t.day = s[0 == i.index ? 1 : 0].value, t.month = s[0 == i.index ? 0 : 1].value, n[s[0].index] = 0 == i.index ? "MM" : "DD", n[s[1].index] = 0 == i.index ? "DD" : "MM") } if (t?.year && t?.month && t?.day) { var o = T(t.year, t.month); t.day > o && (t = null, n = null) } else t = null, n = null; return { parsedDate: t, parsedFormat: n } } return a }, ConvertToDateObject: D, ConvertToDateFormat: p, AD2BS: c, BS2AD: m, ConvertToUnicode: y, ConvertToNumber: function (e) { const t = { "०": "0", "१": "1", "२": "2", "३": "3", "४": "4", "५": "5", "६": "6", "७": "7", "८": "8", "९": "9" }; e = e.toString(); for (var n = "", a = 0; a < e.length;)n += t[e[a]] || e[a], a++; return n }, NumberToWords: function (e, t) { if (e = e || 0, isNaN(e) || Math.floor(e).toString().length > 13) return null; var n = "", a = 0, i = e.toString(); if (i.indexOf(".") > -1) { var r = i.split("."); a = Number(r[1]) } var s = Math.floor(e % 100), o = null; e.toString().length > 2 && (o = e.toString().substring(e.toString().length - 3, e.toString().length - 2)); var h = Math.floor(e % 1e5); h = (h = h.toString()).substring(0, h.length - 3); var u = Math.floor(e % 1e7); u = (u = u.toString()).substring(0, u.length - 5); var d = Math.floor(e % 1e9); d = (d = d.toString()).substring(0, d.length - 7); var l = Math.floor(e % 1e11); l = (l = l.toString()).substring(0, l.length - 9); var c = Math.floor(e % 1e13); function m(e) { var t = { 0: "", 1: "One", 2: "Two", 3: "Three", 4: "Four", 5: "Five", 6: "Six", 7: "Seven", 8: "Eight", 9: "Nine", 10: "Ten", 11: "Eleven", 12: "Twelve", 13: "Thirteen", 14: "Fourteen", 15: "Fifteen", 16: "Sixteen", 17: "Seventeen", 18: "Eighteen", 19: "Nineteen", 20: "Twenty", 30: "Thirty", 40: "Forty", 50: "Fifty", 60: "Sixty", 70: "Seventy", 80: "Eighty", 90: "Ninety" }, n = (e = Number(e)).toString(); return e < 20 ? t[e] : t[10 * n[0]] + " " + t[n[1]] } for ((c = (c = c.toString()).substring(0, c.length - 11)) > 0 && (n += m(c) + " Kharab"), l > 0 && (n += " " + m(l) + " Arab"), d > 0 && (n += " " + m(d) + " Crore"), u > 0 && (n += " " + m(u) + " Lakh"), h > 0 && (n += " " + m(h) + " Thousand"), o > 0 && (n += " " + m(o) + " Hundred"), s > 0 && (n += " " + m(s)), "" != n.trim() && t && (n += " Rupees"), a > 0 && t && (n += " and " + m(a) + " Paisa"); n.indexOf(" ") > -1;)n = n.replace(" ", " "); return n.trim() }, NumberToWordsUnicode: function (e, t) { if (e = e || 0, isNaN(e) || Math.floor(e).toString().length > 13) return null; var n = ["सुन्य", "एक", "दुई", "तीन", "चार", "पाँच", "छ", "सात", "आठ", "नौ", "दस", "एघार", "बाह्र", "तेह्र", "चौध", "पन्ध्र", "सोह्र", "सत्र", "अठाह्र", "उन्नाइस", "बीस", "एकाइस", "बाइस", "तेइस", "चौबीस", "पचीस", "छब्बीस", "सत्ताइस", "अठ्ठाइस", "उनन्तीस", "तीस", "एकतीस", "बतीस", "तेतीस", "चौतीस", "पैतीस", "छतीस", "सरतीस", "अरतीस", "उननचालीस", "चालीस", "एकचालीस", "बयालिस", "तीरचालीस", "चौवालिस", "पैंतालिस", "छयालिस", "सरचालीस", "अरचालीस", "उननचास", "पचास", "एकाउन्न", "बाउन्न", "त्रिपन्न", "चौवन्न", "पच्पन्न", "छपन्न", "सन्ताउन्न", "अन्ठाउँन्न", "उनान्न्साठी ", "साठी", "एकसाठी", "बासाठी", "तीरसाठी", "चौंसाठी", "पैसाठी", "छैसठी", "सत्सठ्ठी", "अर्सठ्ठी", "उनन्सत्तरी", "सतरी", "एकहत्तर", "बहत्तर", "त्रिहत्तर", "चौहत्तर", "पचहत्तर", "छहत्तर", "सत्हत्तर", "अठ्हत्तर", "उनास्सी", "अस्सी", "एकासी", "बयासी", "त्रीयासी", "चौरासी", "पचासी", "छयासी", "सतासी", "अठासी", "उनान्नब्बे", "नब्बे", "एकान्नब्बे", "बयान्नब्बे", "त्रियान्नब्बे", "चौरान्नब्बे", "पंचान्नब्बे", "छयान्नब्बे", "सन्तान्‍नब्बे", "अन्ठान्नब्बे", "उनान्सय"], a = "", i = 0, r = ""; if (-1 != (e = e.toString()).indexOf(".")) { var s = e.split("."); e = s[0]; var o = (i = s[1]).substring(0, 2).toString(); 1 == o.length && (o = o.toString() + "0"), r = n[parseInt(o)].toString() + " पैसा" } if (!(e.length > 13)) { var h = Math.floor(e % 100), u = ""; e.toString().length > 2 && (u = e.toString().substring(e.toString().length - 3, e.toString().length - 2)); var d = Math.floor(e % 1e5); d = (d = d.toString()).substring(0, d.length - 3); var l = Math.floor(e % 1e7); l = (l = l.toString()).substring(0, l.length - 5); var c = Math.floor(e % 1e9); c = (c = c.toString()).substring(0, c.length - 7); var m = Math.floor(e % 1e11); m = (m = m.toString()).substring(0, m.length - 9); var p = Math.floor(e % 1e13); return (p = (p = p.toString()).substring(0, p.length - 11)) > 0 && (a += n[p] + " खरब"), m > 0 && (a += " " + n[m] + " अरब"), c > 0 && (a += " " + n[c] + " करोड"), l > 0 && (a += " " + n[l] + " लाख"), d > 0 && (a += " " + n[d] + " हजार"), u > 0 && (a += " " + n[u] + " सय"), h > 0 && (a += " " + n[h]), "" != a.trim() && t && (a += " रुपैंया"), i > 0 && t && (a += ("" != a.trim() ? " " : "") + r), a.trim() } alert("Number greater than kharab not supported") }, DefaultBsDateFormat: o, DefaultAdDateFormat: h, AD: { GetCurrentDate: f, GetCurrentYear: function () { var e = f(); return Number(e.year) }, GetCurrentMonth: function () { var e = f(); return Number(e.month) }, GetCurrentDay: function () { var e = f(); return Number(e.day) }, GetMonths: Y, GetMonth: function (e) { return e = Number(e), isNaN(e) || e < 0 || e > 11 ? null : ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"][e] }, GetDays: v, GetDay: g, GetDaysShort: b, GetDayShort: function (e) { return e = Number(e), isNaN(e) || e < 0 || e > 6 ? null : ["S", "M", "T", "W", "T", "F", "S"][Number(e)] }, GetDaysInMonth: function (e, t) { return new Date(e, t, 0).getDate() }, DatesDiff: function (e, t, n) { var a = d(e, n, s); return e = a.dateObject, n = a.dateFormat, e && (t = d(t, n, s).dateObject) ? (new u).countAdDays(e, t) : null }, AddDays: function (e, t, n) { var a = d(e, n, s); return e = a.dateObject, n = a.dateFormat, (e = new Date(e.year, e.month - 1, e.day)).setDate(e.getDate() + t), e = { year: e.getFullYear(), month: e.getMonth() + 1, day: e.getDate() }, n ? NepaliFunctions.ConvertToDateFormat(e, n) : e }, GetFullDate: function (e, t) { var n = d(e, t, s); return e = n.dateObject, t = n.dateFormat, e ? `${e.day} ${NepaliFunctions.AD.GetMonth(e.month - 1)} ${e.year}` : null }, GetFullDay: function (e, t) { var n = d(e, t, s); return e = n.dateObject, t = n.dateFormat, e ? g((e = new Date(e.year, e.month - 1, e.day)).getDay()) : null } }, BS: { ValidateDate: k, IsBetweenDates: function (e, t, n, a, i) { var r = d(e, a); if (e = r.dateObject, a = r.dateFormat, !e) return null; var s = d(t, a); if (t = s.dateObject, a = s.dateFormat, !t) return null; if (!(n = d(n, a).dateObject)) return null; if (!k(e) || !k(t) || !k(n)) return null; i = !0 === i; var o = m(e), u = m(t), l = m(n), c = new Date(p(o, h)), D = new Date(p(u, h)), y = new Date(p(l, h)), f = !1; return i ? c >= D && c <= y && (f = !0) : c > D && c < y && (f = !0), f }, GetCurrentDate: N, GetCurrentYear: function () { var e = N(); return Number(e.year) }, GetCurrentMonth: function () { var e = N(); return Number(e.month) }, GetCurrentDay: function () { var e = N(); return Number(e.day) }, GetMonths: C, GetMonth: function (e) { return e = Number(e), isNaN(e) || e < 0 || e > 11 ? null : ["Baisakh", "Jestha", "Ashar", "Shrawan", "Bhadra", "Ashoj", "Kartik", "Mangsir", "Poush", "Magh", "Falgun", "Chaitra"][e] }, GetMonthsInUnicode: E, GetMonthInUnicode: function (e) { return e = Number(e), isNaN(e) || e < 0 || e > 11 ? null : ["बैशाख", "जेठ", "अषाढ", "श्रावण", "भाद्र", "आश्विन", "कार्तिक", "मङ्सिर", "पौष", "माघ", "फाल्गुन", "चैत्र"][e] }, GetFullDate: function (e, t, n) { var a = d(e, n); if (e = a.dateObject, n = a.dateFormat, !e) return null; var i = [], r = ""; return t ? (i = ["बैशाख", "जेठ", "अषाढ", "श्रावण", "भाद्र", "आश्विन", "कार्तिक", "मङ्सिर", "पौष", "माघ", "फाल्गुन", "चैत्र"], r = `${y(e.day)} ${i[e.month - 1]} ${y(e.year)}`) : (i = ["Baisakh", "Jestha", "Ashar", "Shrawan", "Bhadra", "Ashoj", "Kartik", "Mangsir", "Poush", "Magh", "Falgun", "Chaitra"], r = `${e.day} ${i[e.month - 1]} ${e.year}`), r }, GetDaysUnicode: w, GetDayUnicode: F, GetDaysUnicodeShort: S, GetDayUnicodeShort: function (e) { return e = Number(e), isNaN(e) || e < 0 || e > 6 ? null : ["आ", "सो", "मं", "बु", "बि", "शु", "श"][Number(e)] }, GetFullDay: function (e, t) { var n = d(e, t); if (e = n.dateObject, t = n.dateFormat, !e) return null; var a = NepaliFunctions.BS2AD(e); return g((a = new Date(a.year, a.month - 1, a.day)).getDay()) }, GetFullDayInUnicode: function (e, t) { var n = d(e, t); if (e = n.dateObject, t = n.dateFormat, !e) return null; var a = NepaliFunctions.BS2AD(e); return F((a = new Date(a.year, a.month - 1, a.day)).getDay()) }, GetDaysInMonth: T, DatesDiff: function (e, t, n) { var a = d(e, n); return e = a.dateObject, n = a.dateFormat, e && (t = d(t, n).dateObject) ? !(!k(e) || !k(t)) && (e = m(e), t = m(t), (new u).countAdDays(e, t)) : null }, AddDays: function (e, t, n) { var a = d(e, n); if (e = a.dateObject, n = a.dateFormat, !e) return null; var i = NepaliFunctions.BS2AD(e); return (i = new Date(i.year, i.month - 1, i.day)).setDate(i.getDate() + t), i = { year: i.getFullYear(), month: i.getMonth() + 1, day: i.getDate() }, e = NepaliFunctions.AD2BS(i), n ? NepaliFunctions.ConvertToDateFormat(e, n) : e }, IsEqualTo: function (e, n, a) { return M(e, n, a, t) }, IsGreaterThan: function (e, t, n) { return M(e, t, n, i) }, IsLessThan: function (e, t, a) { return M(e, t, a, n) }, IsGreaterThanOrEqualTo: function (e, t, n) { return M(e, t, n, r) }, IsLessThanOrEqualTo: function (e, t, n) { return M(e, t, n, a) }, MinimumDate: function () { return (new u).minDate() }, MaximumDate: function () { return (new u).maxDate() } } } }(); "undefined" != typeof module && void 0 !== module.exports && (module.exports = NepaliFunctions); var NepaliDatePicker = function () { "use strict"; class e { constructor(e, t = {}) { if ("destroy" !== t) { if (this.inputElement = e, this.defaultDateFormat = "YYYY-MM-DD", this.isInputValue = !1, this.animations = ["fade", "slide"], this.range = [], this.options = Object.assign({ debug: !1, dateFormat: this.defaultDateFormat, minDate: NepaliFunctions.BS.MinimumDate(), maxDate: NepaliFunctions.BS.MaximumDate(), onSelect: null, onClose: null, multiple: !1, range: !1, animation: "fade", language: "nepali", disableDates: [], disableToday: !1, disableDaysBefore: 0, disableDaysAfter: 0, mode: "light", unicodeDate: !1, inline: !1, container: "body", miniEnglishDates: !1, value: null }, t), this.yearsPerPage = 12, this.currentBsDate = NepaliFunctions.BS.GetCurrentDate(), this.currentDate = {}, this.selectedDates = [], this.datePickerDiv = null, NepaliFunctions.IsValidDateFormat(this.options.dateFormat) || (this.options.dateFormat = this.defaultDateFormat), this.options.disableDates.length > 0 && (this.options.disableDates = this.options.disableDates.map((e => { if (NepaliFunctions.BS.ValidateDate(e)) return "object" == typeof e ? e : NepaliFunctions.ConvertToDateObject(e, this.options.dateFormat) })).filter((e => e))), this.options.disableDaysBefore > 0) { var n = NepaliFunctions.BS.AddDays(this.currentBsDate, -this.options.disableDaysBefore); NepaliFunctions.BS.IsGreaterThan(n, this.options.minDate) && (this.options.minDate = n) } if (this.options.disableDaysAfter > 0) { var a = NepaliFunctions.BS.AddDays(this.currentBsDate, this.options.disableDaysAfter); NepaliFunctions.BS.IsLessThan(a, this.options.maxDate) && (this.options.maxDate = a) } this.init() } else this.destroy(e) } cloneObject(e) { return JSON.parse(JSON.stringify(e)) } init() { if (this.options.inline) this.datePickerDiv = document.createElement("div"), this.datePickerDiv.className = `ndp-container ndp-${this.options.mode} ndp-inline`, this.datePickerDiv.setAttribute("role", "dialog"), this.datePickerDiv.setAttribute("aria-label", "Date Picker"), this.isInputValue = !0, this.currentDate = this.cloneObject(this.currentBsDate), this.currentYearView = this.currentDate.year, this.currentMonthView = this.currentDate.month, this.currentYearRange = this.calculateYearRange(this.currentDate.year), this.renderCalendar(), this.inputElement.appendChild(this.datePickerDiv); else { if (this.options.value) { this.inputElement.value = this.options.value; var e = [NepaliFunctions.ConvertToDateObject(this.options.value.trim(), this.options.dateFormat)]; this.options.value.indexOf(",") > -1 && (e = this.options.value.split(",").map((e => NepaliFunctions.ConvertToDateObject(e.trim(), this.options.dateFormat)))), this.options.value.indexOf(" - ") > -1 && (e = this.options.value.split("-").map((e => NepaliFunctions.ConvertToDateObject(e.trim(), this.options.dateFormat)))), this.selectedDates = e } this.handleFocusRef = this.handleFocus.bind(this), this.handleBlurRef = this.handleBlur.bind(this), this.handleMouseDownRef = this.handleMouseDown.bind(this), this.inputElement.addEventListener("focus", this.handleFocusRef), this.inputElement.addEventListener("blur", this.handleBlurRef), this.inputElement.setAttribute("aria-haspopup", "true"), this.inputElement.setAttribute("aria-expanded", "false"), document.addEventListener("mousedown", this.handleMouseDownRef), this.inputElement._ndpHandlers = { focus: this.handleFocusRef, blur: this.handleBlurRef, mousedown: this.handleMouseDownRef } } } handleFocus = e => this.showDatePicker(); handleBlur = e => { const t = document.activeElement; this.datePickerDiv && (this.datePickerDiv.contains(t) || t === this.inputElement) || this.hideDatePicker() }; handleMouseDown = e => { this.datePickerDiv && this.datePickerDiv.contains(e.target) && e.preventDefault() }; showDatePicker() { if (this.datePickerDiv) return; let e = this.inputElement.value; if (e) if (this.options.unicodeDate && (e = NepaliFunctions.ConvertToNumber(e)), this.options.multiple || this.options.range) { var t = ","; this.options.range && (t = " - "), this.selectedDates = e.split(t).map((e => NepaliFunctions.ConvertToDateObject(e.trim(), this.options.dateFormat))).filter((e => e)), this.selectedDates.length > 0 ? (this.currentDate = this.selectedDates[0], this.isInputValue = !0) : (this.currentDate = this.cloneObject(this.options.minDate), this.isInputValue = !1) } else { const t = NepaliFunctions.ConvertToDateObject(e, this.options.dateFormat); t ? (this.currentDate = t, this.isInputValue = !0) : (NepaliFunctions.BS.IsGreaterThan(this.currentBsDate, this.options.minDate) && NepaliFunctions.BS.IsLessThan(this.currentBsDate, this.options.maxDate) ? this.currentDate = this.cloneObject(this.currentBsDate) : this.currentDate = this.cloneObject(this.options.minDate), this.isInputValue = !1) } else this.currentDate = this.cloneObject(this.currentBsDate), this.isInputValue = !1; this.currentYearView = this.currentDate.year, this.currentMonthView = this.currentDate.month, this.currentYearRange = this.calculateYearRange(this.currentDate.year), this.datePickerDiv = document.createElement("div"), this.datePickerDiv.className = `ndp-container ndp-${this.options.mode}`, this.datePickerDiv.setAttribute("role", "dialog"), this.datePickerDiv.setAttribute("aria-label", "Date Picker"), "fade" === this.options.animation ? this.datePickerDiv.classList.add("fade") : "slide" === this.options.animation && this.datePickerDiv.classList.add("slide"), this.renderCalendar(), document.querySelector(this.options.container).appendChild(this.datePickerDiv), this.positionDatePicker(), setTimeout((() => { this.animations.indexOf(this.options.animation) > -1 && this.datePickerDiv.classList.add("in") }), 0) } hideDatePicker() { this.options.debug || this.datePickerDiv && (this.inputElement.setAttribute("aria-expanded", "false"), this.animations.indexOf(this.options.animation) > -1 ? (this.datePickerDiv.classList.remove("in"), setTimeout((() => { this.datePickerDiv.remove(), this.datePickerDiv = null, this.handleClose() }), 300)) : (this.datePickerDiv.remove(), this.datePickerDiv = null, this.handleClose())) } handleClose() { "function" == typeof this.options.onClose && (this.datePickerDiv || (this.inputElement.blur(), setTimeout((() => { this.options.onClose(this.selectedDates) }), 0))), this.inputElement.blur() } positionDatePicker() { var e = this.inputElement, t = this.getPosition(e), n = this.getSpaceAbove(t), a = this.getSpaceBelow(e, t), i = this.datePickerDiv, r = i.offsetHeight, s = t.y + e.offsetHeight + 2; a < r && a < n && (s = s - r - e.offsetHeight - 4), i.style.top = s + "px", i.style.left = t.x + "px" } getPosition(e) { if ("body" != this.options.container) { var t = e.getBoundingClientRect(); return { x: t.x, y: t.y } } var n = 0, a = 0; return { x: n += this.getOffsetLeft(e), y: a += this.getOffsetTop(e) } } getOffsetLeft(e) { for (var t = 0; e;)t += e.offsetLeft, e = e.offsetParent; return t += document.firstChild.offsetLeft || 0 } getOffsetTop(e) { for (var t = 0; e;)t += e.offsetTop, e = e.offsetParent; return t += document.firstChild.offsetTop || 0 } getSpaceAbove(e) { var t = window.pageYOffset || (document.documentElement || document.body.parentNode || document.body).scrollTop; return e.y - t } getSpaceBelow(e, t) { var n = window.pageYOffset || (document.documentElement || document.body.parentNode || document.body).scrollTop; return window.innerHeight - t.y - e.offsetHeight + n } renderCalendar() { this.datePickerDiv.innerHTML = ""; const e = this.createCalendarHeader(), t = this.createCalendarBody(); this.datePickerDiv.appendChild(e), this.datePickerDiv.appendChild(t) } getNavigationButton(e) { const t = document.createElement("a"); t.className = "ndc-nav-button", t.href = "javascript:void(0);"; const n = document.createElement("span"); return n.className = `ndc-chevron ndc-${e}`, t.appendChild(n), t } createCalendarHeader(e = "calendar") { const t = document.createElement("div"); t.className = "ndp-header", "year" !== e || this.currentYearRange || (this.currentYearRange = this.calculateYearRange(this.currentYearView)); const n = this.getNavigationButton("left"); let a = this.addMonth(this.currentYearView, this.currentMonthView, -1); "calendar" === e ? n.disabled = 100 * a.year + a.month < 100 * this.options.minDate.year + this.options.minDate.month : "month" === e ? n.disabled = this.currentYearView <= this.options.minDate.year : "year" === e && (n.disabled = this.currentYearRange.start <= this.options.minDate.year), n.disabled ? (n.classList.add("ndp-disabled"), n.setAttribute("aria-disabled", "true")) : n.addEventListener("click", (t => { if (n.disabled) return t.preventDefault(), void t.stopPropagation(); "calendar" === e ? this.changeMonth(-1) : "month" === e ? this.changeYear(-1) : "year" === e && this.changeYearGroup(-1) })); const i = document.createElement("a"); i.className = "ndp-header-link"; const r = document.createElement("span"); r.className = "ndp-header-display"; const s = document.createElement("span"); s.className = "ndp-header-display-english", s.innerHTML = this.getEnglishMonthYear(this.currentYearView, this.currentMonthView); let o = "english" == this.options.language ? NepaliFunctions.BS.GetMonth(this.currentMonthView - 1) : NepaliFunctions.BS.GetMonthInUnicode(this.currentMonthView - 1), h = "english" == this.options.language ? this.currentYearView : NepaliFunctions.ConvertToUnicode(this.currentYearView); if ("calendar" === e) r.innerHTML = `${o} ${h}`, i.addEventListener("click", (() => this.showMonthSelection(this.currentYearView))); else if ("month" === e) r.innerHTML = `${h}`, i.addEventListener("click", (() => this.showYearSelection())); else if ("year" === e) { this.currentYearRange || (this.currentYearRange = this.calculateYearRange(this.currentYearView)); let e = "english" == this.options.language ? this.currentYearRange.start : NepaliFunctions.ConvertToUnicode(this.currentYearRange.start), t = "english" == this.options.language ? this.currentYearRange.end : NepaliFunctions.ConvertToUnicode(this.currentYearRange.end); r.innerHTML = `${e} - ${t}`, i.addEventListener("click", (() => this.renderCalendar())) } i.appendChild(r), this.options.miniEnglishDates && "calendar" === e && i.appendChild(s); const u = this.getNavigationButton("right"); let d = this.addMonth(this.currentYearView, this.currentMonthView, 1); "calendar" === e ? u.disabled = 100 * d.year + d.month > 100 * this.options.maxDate.year + this.options.maxDate.month : "month" === e ? u.disabled = this.currentYearView >= this.options.maxDate.year : "year" === e && (u.disabled = this.currentYearRange.end >= this.options.maxDate.year), u.disabled ? (u.classList.add("ndp-disabled"), u.setAttribute("aria-disabled", "true")) : u.addEventListener("click", (t => { if (u.disabled) return t.preventDefault(), void t.stopPropagation(); "calendar" === e ? this.changeMonth(1) : "month" === e ? this.changeYear(1) : "year" === e && this.changeYearGroup(1) })); const l = document.createElement("button"); return l.className = "ndp-today-button", l.innerHTML = "Today", l.addEventListener("click", (() => this.goToToday())), t.appendChild(n), t.appendChild(i), t.appendChild(u), t } showYearSelection() { this.datePickerDiv.innerHTML = ""; const e = this.createCalendarHeader("year"), t = document.createElement("div"); t.className = "ndp-year-selection", this.currentYearRange = this.calculateYearRange(this.currentDate.year), this.renderYearButtons(t, this.currentYearRange.start, this.currentYearRange.end), this.datePickerDiv.appendChild(e), this.datePickerDiv.appendChild(t) } updateYearSelection(e) { e || ((e = document.createElement("div")).className = "ndp-year-selection", this.datePickerDiv.appendChild(e)), e.innerHTML = ""; let t = this.currentYearRange.start, n = this.currentYearRange.end; if (this.options.minDate) { const e = this.options.minDate.year; t < e && (t = e) } if (this.options.maxDate) { const e = this.options.maxDate.year; n > e && (n = e) } this.renderYearButtons(e, t, n) } showMonthSelection(e) { this.datePickerDiv.innerHTML = ""; const t = this.createCalendarHeader("month"), n = document.createElement("div"); n.className = "ndp-month-selection", ("english" == this.options.language ? NepaliFunctions.BS.GetMonths() : NepaliFunctions.BS.GetMonthsInUnicode()).forEach(((t, a) => { const i = document.createElement("a"); i.href = "javascript:void(0);", i.className = "ndp-month-button", i.textContent = t, a + 1 === this.currentBsDate.month && e === this.currentBsDate.year && i.classList.add("ndp-current"), this.isInputValue && a + 1 === this.currentDate.month && e === this.currentDate.year && i.classList.add("ndp-selected"), this.isMonthDisabled(e, a + 1) ? (i.classList.add("ndp-disabled"), i.setAttribute("aria-disabled", "true")) : i.addEventListener("click", (() => { this.currentMonthView = a + 1, this.renderCalendar() })), n.appendChild(i) })), this.datePickerDiv.appendChild(t), this.datePickerDiv.appendChild(n) } createCalendarBody() { const e = document.createElement("table"); e.className = "ndp-table"; const t = "english" == this.options.language ? NepaliFunctions.AD.GetDaysShort() : NepaliFunctions.BS.GetDaysUnicodeShort(), n = document.createElement("thead"), a = document.createElement("tr"); t.forEach((e => { const t = document.createElement("th"); t.innerHTML = e, a.appendChild(t) })), n.appendChild(a), e.appendChild(n); const i = document.createElement("tbody"), r = NepaliFunctions.BS.GetDaysInMonth(this.currentYearView, this.currentMonthView); let s = NepaliFunctions.BS.GetFullDay({ year: this.currentYearView, month: this.currentMonthView, day: 1 }), o = NepaliFunctions.AD.GetDays().indexOf(s), h = document.createElement("tr"); for (let e = 0; e < r + o; e++) { const t = document.createElement("td"); if (e > o - 1) { let n = e - o + 1; t.innerHTML = "english" == this.options.language ? n : NepaliFunctions.ConvertToUnicode(n), t.setAttribute("data-bs-day", n); var u = this.bsDate(this.currentYearView, this.currentMonthView, n); if (this.options.miniEnglishDates) { var d = NepaliFunctions.BS2AD(u), l = document.createElement("span"); l.classList.add("ndp-mini-english-date"), l.innerHTML = d.day, t.appendChild(l) } this.isToday(u) && t.classList.add("ndp-today"), this.isInputValue && this.isSelected(u) && t.classList.add("ndp-selected"), this.isInputValue && this.isInRange(u) && t.classList.add("ndp-range-hover"), this.isDisabled(u) ? (t.classList.add("ndp-disabled"), t.setAttribute("aria-disabled", "true")) : t.addEventListener("click", (e => { this.selectDate(e) })), t.addEventListener("mouseenter", (e => this.handleMouseEnter(e))) } h.appendChild(t), (e + 1) % 7 == 0 && (i.appendChild(h), h = document.createElement("tr")) } if (h.children.length > 0) { if (h.children.length < 7) for (let e = h.children.length; e < 7; e++) { const e = document.createElement("td"); h.appendChild(e) } i.appendChild(h) } return e.appendChild(i), e } handleMouseEnter(e) { this.options.range && 1 === this.selectedDates.length && this.highlightRange(this.selectedDates[0], this.bsDate(this.currentYearView, this.currentMonthView, parseInt(e.target.getAttribute("data-bs-day")))) } bsDate(e, t, n) { return { year: e, month: t, day: n } } isToday(e) { if (!e) return !1; const t = this.currentBsDate; return e.year === t.year && e.month === t.month && e.day === t.day } isInRange(e) { if (this.options.range && 2 === this.selectedDates.length) { const [t, n] = this.sortDates(this.selectedDates); return NepaliFunctions.BS.IsGreaterThan(e, t) && NepaliFunctions.BS.IsLessThan(e, n) } } isSelected(e) { return this.selectedDates.some((t => t.year === e.year && t.month === e.month && t.day === e.day)) } isDisabled(e) { if (!e) return !1; const t = this.options.minDate, n = this.options.maxDate; let a = !1; return this.options.disableDates.length > 0 && (a = this.options.disableDates.some((t => NepaliFunctions.BS.IsEqualTo(e, t)))), a || NepaliFunctions.BS.IsLessThan(e, t) || NepaliFunctions.BS.IsGreaterThan(e, n) || this.isToday(e) && this.options.disableToday } isMonthDisabled(e, t) { if (!e || !t) return !1; const n = this.options.minDate, a = this.options.maxDate, i = { year: e, month: t, day: 1 }, r = { year: e, month: t, day: NepaliFunctions.BS.GetDaysInMonth(e, t) }; return NepaliFunctions.BS.IsLessThan(r, n) || NepaliFunctions.BS.IsGreaterThan(i, a) } highlightRange(e, t) { const [n, a] = this.sortDates([e, t]); this.datePickerDiv.querySelectorAll("td[data-bs-day]").forEach((e => { const t = parseInt(e.getAttribute("data-bs-day")), i = this.bsDate(this.currentYearView, this.currentMonthView, t); (NepaliFunctions.BS.IsGreaterThan(i, n) || NepaliFunctions.BS.IsEqualTo(i, n)) && (NepaliFunctions.BS.IsLessThan(i, a) || NepaliFunctions.BS.IsEqualTo(i, a)) ? e.classList.add("ndp-range-hover") : e.classList.remove("ndp-range-hover") })) } changeMonth(e) { let t = this.addMonth(this.currentYearView, this.currentMonthView, e); this.currentYearView = t.year, this.currentMonthView = t.month, this.renderCalendar() } addMonth(e, t, n) { return (t += n) > 12 ? (t = 1, e += 1) : t < 1 && (t = 12, e -= 1), { year: e, month: t } } changeYear(e) { this.currentYearView += e, this.showMonthSelection(this.currentYearView) } changeYearGroup(e) { const t = this.currentYearRange.start + e * this.yearsPerPage; this.currentYearRange = this.calculateYearRange(t); const n = this.datePickerDiv.querySelector(".ndp-year-selection"); if (!n) return; const a = this.createCalendarHeader("year"); this.datePickerDiv.querySelector(".ndp-header").replaceWith(a), this.updateYearSelection(n) } selectDate(e) { var t = e.target; t.getAttribute("data-bs-day") || (t = t.parentElement); const n = { year: this.currentYearView, month: this.currentMonthView, day: parseInt(t.getAttribute("data-bs-day")) }; if (this.currentDate = n, this.options.range) 2 === this.selectedDates.length && this.clearSelectedRangeDates(), t.classList.add("ndp-selected"), this.selectedDates.push(this.currentDate), this.selectedDates = this.sortDates(this.selectedDates), 2 === this.selectedDates.length && this.hideDatePicker(); else if (this.options.multiple) { const e = this.selectedDates.findIndex((e => e.year === n.year && e.month === n.month && e.day === n.day)); -1 === e ? (this.selectedDates.push(this.currentDate), this.selectedDates = this.sortDates(this.selectedDates), t.classList.add("ndp-selected")) : (this.selectedDates.splice(e, 1), this.selectedDates = this.sortDates(this.selectedDates), t.classList.remove("ndp-selected")) } else this.options.inline ? (this.clearSelectedRangeDates(), this.selectedDates = [this.currentDate], t.classList.add("ndp-selected")) : (this.selectedDates = [this.currentDate], t.classList.add("ndp-selected"), this.hideDatePicker()); var a = ""; if (this.options.multiple ? a = ", " : this.options.range && (a = " - "), this.inputElement.value = this.selectedDates.map((e => { var t = NepaliFunctions.ConvertToDateFormat(e, this.options.dateFormat); return this.options.unicodeDate && (t = NepaliFunctions.ConvertToUnicode(t)), t })).join(a), "function" == typeof this.options.onSelect) { var i = this.selectedDates.map((e => ({ value: NepaliFunctions.ConvertToDateFormat(e, this.options.dateFormat), year: e.year, month: e.month, day: e.day }))); this.options.onSelect(this.options.multiple || this.options.range ? i : i[0]) } } clearSelectedRangeDates() { this.selectedDates = [], this.inputElement.value = ""; this.datePickerDiv.querySelectorAll("td[data-bs-day]").forEach((e => { e.classList.remove("ndp-selected", "ndp-range-hover") })) } sortDates(e) { return e.sort(((e, t) => NepaliFunctions.BS.IsLessThan(e, t) ? -1 : 1)) } goToToday() { this.currentDate = this.currentBsDate, this.currentYearView = this.currentDate.year, this.currentMonthView = this.currentDate.month, this.renderCalendar() } renderYearButtons(e, t, n) { for (let a = t; a <= n; a++) { const t = document.createElement("a"); t.href = "javascript:void(0);", t.className = "ndp-year-button", t.textContent = "english" == this.options.language ? a : NepaliFunctions.ConvertToUnicode(a), a === this.currentBsDate.year && t.classList.add("ndp-current"), this.isInputValue && a === this.currentDate.year && t.classList.add("ndp-selected"), t.addEventListener("click", (() => { this.currentYearView = a, this.showMonthSelection(a) })), e.appendChild(t) } } calculateYearRange(e) { const t = this.yearsPerPage; let n = NepaliFunctions.BS.MinimumDate().year, a = NepaliFunctions.BS.MaximumDate().year; return this.options.minDate && (n = this.options.minDate.year), this.options.maxDate && (a = this.options.maxDate.year), a - n < t || (n += Math.floor((e - n) / t) * t, a = n + t - 1, a > this.options.maxDate.year && (a = this.options.maxDate.year)), { start: n, end: a } } parseInputDate(e) { if (!e) return null; const t = this.options.dateFormat || "YYYY-MM-DD", n = e.match(/(\d+)/g); if (!n) return null; let a, i, r; if ("YYYY-MM-DD" === t) [a, i, r] = n.map(Number); else if ("MM/DD/YYYY" === t) [i, r, a] = n.map(Number); else { if ("DD/MM/YYYY" !== t) return null;[r, i, a] = n.map(Number) } const s = new Date(a, i - 1, r); return s.year === a && s.month === i - 1 && s.day === r ? s : null } getEnglishMonthYear(e, t) { const n = NepaliFunctions.BS2AD({ year: e, month: t, day: 1 }); var a = n.month; return a = 12 == a ? 0 : a, NepaliFunctions.AD.GetMonth(n.month - 1).substring(0, 3) + (0 == a ? " " + n.year : "") + " / " + NepaliFunctions.AD.GetMonth(a).substring(0, 3) + " " + (0 == a ? n.year + 1 : n.year) } destroy(e) { e && e._ndpHandlers && (e.removeEventListener("focus", e._ndpHandlers.focus), e.removeEventListener("blur", e._ndpHandlers.blur), document.removeEventListener("mousedown", e._ndpHandlers.mousedown), delete e._ndpHandlers), this.datePickerDiv && (this.datePickerDiv.remove(), this.datePickerDiv = null) } } HTMLElement.prototype.NepaliDatePicker = function (t) { return new e(this, t) }, HTMLCollection.prototype.NepaliDatePicker = function (e) { Array.from(this).forEach((t => { t.NepaliDatePicker(e) })) } }(); "undefined" != typeof module && void 0 !== module.exports && (module.exports = NepaliDatePicker);