@brightsoftware/date-np
Version:
Simple & minimal Nepali date picker that just works.
96 lines (95 loc) • 2.21 kB
JavaScript
import { NepaliDate as S } from "./NepaliDate.js";
import { CALENDAR as p } from "../data/locale.js";
function A(t) {
const r = t % 10, n = t % 100;
return r === 1 && n !== 11 ? t + "st" : r === 2 && n !== 12 ? t + "nd" : r === 3 && n !== 13 ? t + "rd" : t + "th";
}
function b(t) {
const r = {
January: "Jan",
February: "Feb",
// Note: fixing the typo in CALENDAR
March: "Mar",
April: "Apr",
May: "May",
June: "Jun",
July: "Jul",
August: "Aug",
September: "Sep",
October: "Oct",
// Note: fixing the typo in CALENDAR
November: "Nov",
December: "Dec"
};
return r[t] ? r[t] : {
Baishak: "Bais",
Jestha: "Jest",
Aashar: "Aash",
Sharawan: "Shra",
Bhadau: "Bhad",
Ashoj: "Asho",
Kartik: "Kart",
Mangshir: "Mang",
Poush: "Pous",
Magh: "Magh",
Falgun: "Falg",
Chaitra: "Chai"
}[t] || t.substring(0, 3);
}
function m(t) {
return t instanceof S;
}
function h(t, r) {
const n = m(t);
let s, o, a, c;
if (n) {
const e = t;
s = e.getFullYear(), o = e.getMonth(), a = e.getDate(), c = p.BS.months;
} else {
const e = t;
s = e.getFullYear(), o = e.getMonth(), a = e.getDate(), c = p.AD.months;
}
const M = {
yyyy: s.toString(),
yy: s.toString().slice(-2),
MMMM: c[o],
MMM: b(c[o]),
MM: (o + 1).toString().padStart(2, "0"),
// Convert to 1-based and pad
M: (o + 1).toString(),
// Convert to 1-based
dd: a.toString().padStart(2, "0"),
d: a.toString(),
do: A(a)
};
let i = r;
const u = Object.keys(M).sort((e, g) => g.length - e.length), l = {};
for (let e = 0; e < u.length; e++) {
const g = u[e], y = `__PLACEHOLDER_${e}__`;
l[y] = M[g];
const d = g.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), f = new RegExp(d, "g");
i = i.replace(f, y);
}
for (const e in l)
i = i.replace(new RegExp(e, "g"), l[e]);
return i;
}
function k(t) {
return h(t, "yyyy-MM-dd");
}
function F(t) {
return h(t, "MMMM do, yyyy");
}
function O(t) {
return h(t, "MM/dd/yyyy");
}
function v(t) {
return h(t, "MMM dd, yyyy");
}
export {
h as format,
k as formatISO,
F as formatLong,
v as formatMedium,
O as formatShort
};