hamro-nepali-patro
Version:
A modern React component library for Nepali (Bikram Sambat, BS) and Gregorian (AD) calendar date picking, conversion, and utilities. Includes a customizable datepicker, BS/AD conversion, and Nepali date functions.
1,450 lines (1,413 loc) • 328 kB
JavaScript
'use strict';
var React = require('react');
function _interopNamespaceDefault(e) {
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n.default = e;
return Object.freeze(n);
}
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
function _arrayLikeToArray(r, a) {
(null == a || a > r.length) && (a = r.length);
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
return n;
}
function _arrayWithHoles(r) {
if (Array.isArray(r)) return r;
}
function _assertThisInitialized(e) {
if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
return e;
}
function _callSuper(t, o, e) {
return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e));
}
function _classCallCheck(a, n) {
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
}
function _defineProperties(e, r) {
for (var t = 0; t < r.length; t++) {
var o = r[t];
o.enumerable = o.enumerable || false, o.configurable = true, "value" in o && (o.writable = true), Object.defineProperty(e, _toPropertyKey(o.key), o);
}
}
function _createClass(e, r, t) {
return r && _defineProperties(e.prototype, r), Object.defineProperty(e, "prototype", {
writable: false
}), e;
}
function _createForOfIteratorHelper(r, e) {
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
if (!t) {
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e) {
t && (r = t);
var n = 0,
F = function () {};
return {
s: F,
n: function () {
return n >= r.length ? {
done: true
} : {
done: false,
value: r[n++]
};
},
e: function (r) {
throw r;
},
f: F
};
}
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
var o,
a = true,
u = false;
return {
s: function () {
t = t.call(r);
},
n: function () {
var r = t.next();
return a = r.done, r;
},
e: function (r) {
u = true, o = r;
},
f: function () {
try {
a || null == t.return || t.return();
} finally {
if (u) throw o;
}
}
};
}
function _defineProperty(e, r, t) {
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
value: t,
enumerable: true,
configurable: true,
writable: true
}) : e[r] = t, e;
}
function _getPrototypeOf(t) {
return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
return t.__proto__ || Object.getPrototypeOf(t);
}, _getPrototypeOf(t);
}
function _inherits(t, e) {
if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function");
t.prototype = Object.create(e && e.prototype, {
constructor: {
value: t,
writable: true,
configurable: true
}
}), Object.defineProperty(t, "prototype", {
writable: false
}), e && _setPrototypeOf(t, e);
}
function _isNativeReflectConstruct() {
try {
var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
} catch (t) {}
return (_isNativeReflectConstruct = function () {
return !!t;
})();
}
function _iterableToArrayLimit(r, l) {
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
if (null != t) {
var e,
n,
i,
u,
a = [],
f = true,
o = false;
try {
if (i = (t = t.call(r)).next, 0 === l) ; else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
} catch (r) {
o = true, n = r;
} finally {
try {
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
} finally {
if (o) throw n;
}
}
return a;
}
}
function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function ownKeys(e, r) {
var t = Object.keys(e);
if (Object.getOwnPropertySymbols) {
var o = Object.getOwnPropertySymbols(e);
r && (o = o.filter(function (r) {
return Object.getOwnPropertyDescriptor(e, r).enumerable;
})), t.push.apply(t, o);
}
return t;
}
function _objectSpread2(e) {
for (var r = 1; r < arguments.length; r++) {
var t = null != arguments[r] ? arguments[r] : {};
r % 2 ? ownKeys(Object(t), true).forEach(function (r) {
_defineProperty(e, r, t[r]);
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
});
}
return e;
}
function _possibleConstructorReturn(t, e) {
if (e && ("object" == typeof e || "function" == typeof e)) return e;
if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined");
return _assertThisInitialized(t);
}
function _setPrototypeOf(t, e) {
return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
return t.__proto__ = e, t;
}, _setPrototypeOf(t, e);
}
function _slicedToArray(r, e) {
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
}
function _toPrimitive(t, r) {
if ("object" != typeof t || !t) return t;
var e = t[Symbol.toPrimitive];
if (void 0 !== e) {
var i = e.call(t, r);
if ("object" != typeof i) return i;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return (String )(t);
}
function _toPropertyKey(t) {
var i = _toPrimitive(t, "string");
return "symbol" == typeof i ? i : i + "";
}
function _typeof(o) {
"@babel/helpers - typeof";
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
return typeof o;
} : function (o) {
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
}, _typeof(o);
}
function _unsupportedIterableToArray(r, a) {
if (r) {
if ("string" == typeof r) return _arrayLikeToArray(r, a);
var t = {}.toString.call(r).slice(8, -1);
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
}
}
var _assign = function __assign() {
_assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
return t;
};
return _assign.apply(this, arguments);
};
function __rest(s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
}
return t;
}
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
var e = new Error(message);
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
};
function isInBetween(data, first, last) {
if (data >= first && data <= last && first < last) {
return true;
} else return false;
}
function getTotalDaysInAdMonth(year, month) {
return new Date(year, month, 0).getDate();
}
function parseDate$1(input, format) {
var _a, _b, _c;
format = ((_a = String(format)) === null || _a === void 0 ? void 0 : _a.toLocaleLowerCase()) || "yyyy-mm-dd"; // default format
var parts = input.match(/(\d+)/g);
if (parts) {
var i_1 = 0;
var fmt_1 = {};
format.replace(/(yyyy|dd|d|mm|m)/g, function (part) {
fmt_1[part] = i_1++;
return "";
});
var yearIndex = fmt_1["yyyy"];
var monthIndex = (_b = fmt_1["mm"]) !== null && _b !== void 0 ? _b : fmt_1["m"];
var dateIndex = (_c = fmt_1["dd"]) !== null && _c !== void 0 ? _c : fmt_1["d"];
if (yearIndex === undefined) {
throw new TypeError("Year isn't Provided in the given date input or the format doesn't contain correct combination of 'yyyy'. Please Acceptable formats are the pemutation of 'yyyy', 'mm' and 'dd' instead got ".concat(format, " "));
}
if (monthIndex === undefined) {
throw new TypeError("Month isn't Provided in the given date input or the format doesn't contain correct combination of 'mm' | 'm'. Please Acceptable formats are the pemutation of 'yyyy', 'mm' and 'dd' instead got ".concat(format, " "));
}
if (dateIndex === undefined) {
throw new TypeError("Date isn't Provided in the given date input or the format doesn't contain correct combination of 'dd' | 'd'. Please Acceptable formats are the pemutation of 'yyyy', 'mm' and 'dd' instead got ".concat(format, " "));
}
if (yearIndex !== undefined && monthIndex !== undefined && dateIndex !== undefined) {
var year = +parts[yearIndex];
var month = +parts[monthIndex];
var date = +parts[dateIndex];
return {
year: year,
month: month,
date: date
};
} else {
throw new Error("error");
}
} else {
throw new TypeError("Passed Input isn't a valid date. Please check again");
}
}
function format$1(dateObj, format) {
var _a;
format = ((_a = String(format)) === null || _a === void 0 ? void 0 : _a.toLocaleLowerCase()) || "yyyy-mm-dd"; // this is our default format
var str = {
yyyy: String(dateObj.year),
mm: String(dateObj.month).padStart(2, "0"),
m: String(dateObj.month),
dd: String(dateObj.date).padStart(2, "0"),
d: String(dateObj.date)
};
var formatted = format.replace(/(yyyy|dd|d|mm|m)/g, function (part) {
return str[part];
});
return formatted;
}
var lang = ["np", "rm", "en"],
variant = ["long", "short", "min"],
calendar = ["AD", "BS"],
np = {
dayName: {
full: ["आइतवार", "सोमवार", "मंगलवार", "बुधवार", "बिहिवार", "शुक्रवार", "शनिवार"],
short: ["आइ", "सोम", "मंगल", "बुध", "बिहि", "शुक्र", "शनि"],
min: ["आ", "सो", "मं", "बु", "बि", "शु", "श"]
},
monthName: {
full: ["बैशाख", "जेष्ठ", "आषाढ", "श्रावण", "भाद्र", "आश्विन", "कार्तिक", "मंसिर", "पौष", "माघ", "फाल्गुन", "चैत्र"],
short: ["बै", "जे", "आषा", "श्रा", "भा", "आश", "का", "मं", "पौ", "मा", "फा", "चै"],
min: ["बै", "जे", "आषा", "श्रा", "भा", "आश", "का", "मं", "पौ", "मा", "फा", "चै"]
}
},
rm = {
dayName: {
full: ["Aaitabaar", "Sombaar", "Mangalbaar", "Budhabaar", "Bihibaar", "Shukrabaar", "Shanibaar"],
short: ["Aaita", "Som", "Mangal", "Budha", "Bihi", "Shukra", "Shani"],
min: ["Aai", "So", "Man", "Bu", "Bi", "Shu", "Sha"] //TODO check
},
monthName: {
full: ["Baisakh", "Jestha", "Ashadh", "Shrawan", "Bhadra", "Ashwin", "Kartik", "Mangsir", "Paush", "Mangh", "Falgun", "Chaitra"],
short: ["Bai", "Je", "As", "Shra", "Bha", "Ash", "Kar", "Mang", "Pau", "Ma", "Fal", "Chai"],
min: ["Bai", "Je", "As", "Shra", "Bha", "Ash", "Kar", "Mang", "Pau", "Ma", "Fal", "Chai"]
}
},
en = {
dayName: {
full: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
short: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
min: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"]
},
monthName: {
full: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
short: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
min: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
}
},
npNumsArray = ["०", "१", "२", "३", "४", "५", "६", "७", "८", "९"],
nums = {
0: "०",
1: "१",
2: "२",
3: "३",
4: "४",
5: "५",
6: "६",
7: "७",
8: "८",
9: "९"
},
minBsYear = 1978,
maxBsYear = 2100,
minAdYear = 1921,
minAdMonth = 3,
minAdDate = 13,
maxAdYear = 2035,
daysInYear = 365,
minMonth = 1,
minDays = 1,
maxMonth = 12,
maxDays = 32,
base_ad = {
year: 1921,
month: 3,
day: 13,
dayOfWeek: 3
},
base_bs = {
year: 1978,
month: 1,
day: 1,
dayOfWeek: 3
},
calendar_data = {
1978: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30, 365],
1979: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30, 365],
1980: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31, 366],
1981: [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30, 365],
1982: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30, 365],
1983: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30, 365],
1984: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31, 366],
1985: [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30, 365],
1986: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30, 365],
1987: [31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30, 365],
1988: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31, 366],
1989: [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30, 365],
1990: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30, 365],
1991: [31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30, 365],
1992: [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31, 366],
1993: [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30, 365],
1994: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30, 365],
1995: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30, 365],
1996: [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31, 366],
1997: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30, 365],
1998: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30, 365],
1999: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31, 366],
2000: [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31, 365],
2001: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30, 365],
2002: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30, 365],
2003: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31, 366],
2004: [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31, 365],
2005: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30, 365],
2006: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30, 365],
2007: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31, 366],
2008: [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31, 365],
2009: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30, 365],
2010: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30, 365],
2011: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31, 366],
2012: [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30, 365],
2013: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30, 365],
2014: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30, 365],
2015: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31, 366],
2016: [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30, 365],
2017: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30, 365],
2018: [31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30, 365],
2019: [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31, 366],
2020: [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30, 365],
2021: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30, 365],
2022: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30, 365],
2023: [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31, 366],
2024: [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30, 365],
2025: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30, 365],
2026: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31, 366],
2027: [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31, 365],
2028: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30, 365],
2029: [31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30, 365],
2030: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31, 366],
2031: [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31, 365],
2032: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30, 365],
2033: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30, 365],
2034: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31, 366],
2035: [30, 32, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31, 365],
2036: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30, 365],
2037: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30, 365],
2038: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31, 366],
2039: [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30, 365],
2040: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30, 365],
2041: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30, 365],
2042: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31, 366],
2043: [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30, 365],
2044: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30, 365],
2045: [31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30, 365],
2046: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31, 366],
2047: [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30, 365],
2048: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30, 365],
2049: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30, 365],
2050: [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31, 366],
2051: [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30, 365],
2052: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30, 365],
2053: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30, 365],
2054: [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31, 366],
2055: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30, 365],
2056: [31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30, 365],
2057: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31, 366],
2058: [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31, 365],
2059: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30, 365],
2060: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30, 365],
2061: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31, 366],
2062: [30, 32, 31, 32, 31, 31, 29, 30, 29, 30, 29, 31, 365],
2063: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30, 365],
2064: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30, 365],
2065: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31, 366],
2066: [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31, 365],
2067: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30, 365],
2068: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30, 365],
2069: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31, 366],
2070: [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30, 365],
2071: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30, 365],
2072: [31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30, 365],
2073: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31, 366],
2074: [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30, 365],
2075: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30, 365],
2076: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30, 365],
2077: [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31, 366],
2078: [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30, 365],
2079: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30, 365],
2080: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30, 365],
2081: [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31, 366],
2082: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30, 365],
2083: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30, 365],
2084: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31, 366],
2085: [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31, 365],
2086: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30, 365],
2087: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30, 365],
2088: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31, 366],
2089: [30, 32, 31, 32, 31, 31, 29, 30, 29, 30, 29, 31, 365],
2090: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30, 365],
2091: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30, 365],
2092: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31, 366]
};
var BSdata = /*#__PURE__*/Object.freeze({
__proto__: null,
base_ad: base_ad,
base_bs: base_bs,
calendar: calendar,
calendar_data: calendar_data,
daysInYear: daysInYear,
en: en,
lang: lang,
maxAdYear: maxAdYear,
maxBsYear: maxBsYear,
maxDays: maxDays,
maxMonth: maxMonth,
minAdDate: minAdDate,
minAdMonth: minAdMonth,
minAdYear: minAdYear,
minBsYear: minBsYear,
minDays: minDays,
minMonth: minMonth,
np: np,
npNumsArray: npNumsArray,
nums: nums,
rm: rm,
variant: variant
});
var getTotalDaysInBsMonth = function getTotalDaysInBsMonth(year, month) {
try {
var allYears = Object.keys(calendar_data);
var monthIndex = +month - 1;
if (year && allYears.includes(year.toString()) && monthIndex <= 12) {
return calendar_data[year][monthIndex];
} else throw new RangeError("Expeceted first paramater as year within range ".concat(minBsYear, "-").concat(maxBsYear, " and second parameter as month within range 0-12. But got year as ").concat(year, " and month as ").concat(month, " in getNumberOfDaysInMonth function"));
} catch (err) {
console.log(err);
throw new Error("Error");
}
};
var isMonthValid = function isMonthValid(month, throwError) {
var m = Number(month);
var valid = m >= 1 && m <= 12;
if (!valid && throwError) {
throw new RangeError("Month must be between 1 and 12, got ".concat(month));
}
return valid;
};
function isDateValid(dateObj, minYear, maxYear, getTotalDays, throwError) {
var year = dateObj.year,
month = dateObj.month,
date = dateObj.date;
if (!isInBetween(year, minYear, maxYear)) {
throw new RangeError("Year must be between ".concat(minYear, " and ").concat(maxYear, ", got ").concat(year));
}
if (!isMonthValid(month, throwError)) return false;
var totalDays = getTotalDays(year, month);
if (date > totalDays) {
throw new RangeError("Date must be between 1 and ".concat(totalDays, " for year ").concat(year, ", month ").concat(month, ", got ").concat(date));
}
return true;
}
var isBsDateValid = function isBsDateValid(_a, throwError) {
var year = _a.year,
month = _a.month,
date = _a.date;
if (!isInBetween(year, minBsYear, maxBsYear)) {
throw new RangeError("Year must be between ".concat(minBsYear, " and ").concat(maxBsYear, ", got ").concat(year));
}
if (!isMonthValid(month, throwError)) return false;
var totalDays = getTotalDaysInBsMonth(year, month);
if (date > totalDays) {
throw new RangeError("Date must be between 1 and ".concat(totalDays, " for year ").concat(year, ", month ").concat(month, ", got ").concat(date));
}
return true;
};
var isAdDateValid = function isAdDateValid(dateObj, throwError) {
return isDateValid(dateObj, minAdYear, maxAdYear, getTotalDaysInAdMonth, throwError);
};
var isInValidRange = function isInValidRange(dateObj, calendarType, throwError) {
if (calendarType === "BS") {
return isBsDateValid(dateObj, throwError);
} else {
return isAdDateValid(dateObj, throwError);
}
};
function isDateValidWithFormat(input, format, throwError) {
var _a, _b, _c;
if (!format || !input) {
return false;
}
format = (_a = String(format)) === null || _a === void 0 ? void 0 : _a.toLocaleLowerCase(); // default format
var parts = input.match(/(\d+)/g);
if (parts) {
var i_1 = 0;
var fmt_1 = {};
format.replace(/(yyyy|dd|d|mm|m)/g, function (part) {
fmt_1[part] = i_1++;
return "";
});
var yearIndex = fmt_1["yyyy"];
var monthIndex = (_b = fmt_1["mm"]) !== null && _b !== void 0 ? _b : fmt_1["m"];
var dateIndex = (_c = fmt_1["dd"]) !== null && _c !== void 0 ? _c : fmt_1["d"];
if (yearIndex === undefined) {
return false;
}
if (monthIndex === undefined) {
return false;
}
if (dateIndex === undefined) {
return false;
}
var year = parts[yearIndex];
var month = parts[monthIndex];
var date = parts[dateIndex];
if (!year || !month || !date) {
return false;
}
return true;
} else {
return false;
}
}
var parseBsDate = parseDate$1;
var formatBsDate = format$1;
var dataType = ["np", "rm", "en"];
function getNames(type, lang, length) {
if (!["monthName", "dayName"].includes(type)) {
throw new Error("Type must be 'monthName' or 'dayName', got '".concat(type, "'"));
}
if (!["np", "rm", "en"].includes(lang)) {
throw new Error("Language must be 'np', 'rm', or 'en', got '".concat(lang, "'"));
}
if (length && !["full", "short", "min"].includes(length)) {
throw new Error("Length must be 'full', 'short', or 'min', got '".concat(length, "'"));
}
return length ? BSdata[lang][type][length] : BSdata[lang][type].full;
}
var getMonthNames = function getMonthNames(lang, length) {
if (lang === void 0) {
lang = "np";
}
var allMonths = getNames("monthName", lang, length);
return allMonths;
};
var getWeekNames = function getWeekNames(lang, length) {
if (lang === void 0) {
lang = "np";
}
var allMonths = getNames("dayName", lang, length);
if (Array.isArray(allMonths)) return allMonths;
return null;
};
function getValidYears(lang, calendarType) {
if (calendarType === "BS") {
if (dataType.includes(lang)) {
var allYears = Object.keys(calendar_data);
{
return allYears;
}
} else {
console.error("Expected paramters for getValidYears is one of the : ".concat(dataType));
var allYears = Object.keys(calendar_data);
return [];
}
} else {
var arr = [];
for (var i = minAdYear; i <= maxAdYear; i++) {
arr.push(i);
}
return arr;
}
}
var getNepaliNumber = function getNepaliNumber(n) {
if (isNaN(+n)) {
throw new TypeError("Expected Number instead got ".concat(_typeof(n), " value=").concat(n));
}
var nep = "";
var str = String(n);
for (var i = 0; i < str.length; i++) {
nep += npNumsArray[str[i]];
}
return nep;
};
var cache = {
_cumulativeTotal: null,
getCumulativeTotal: function getCumulativeTotal() {
if (this._cumulativeTotal) return this._cumulativeTotal;
var years = Object.keys(calendar_data);
var startingYear = +years[0];
var totalYears = years.length;
var obj = {};
for (var i = 0; i < totalYears; i++) {
var yearIndex = startingYear + i;
obj[yearIndex] = (i === 0 ? 0 : obj[yearIndex - 1]) + getYearCalendarData(yearIndex).slice(-1)[0];
}
this._cumulativeTotal = obj;
return obj;
}
};
var countBSDaysFromBaseDateUsingAdDate = function countBSDaysFromBaseDateUsingAdDate(year, month, day) {
var base_ad$1 = base_ad;
var dateObj = {
year: year,
month: month - 1,
day: day
};
var date1 = new Date(base_ad$1.year, base_ad$1.month, base_ad$1.day);
var date2 = new Date(dateObj.year, dateObj.month, dateObj.day);
var timeDiff = date2.getTime() - date1.getTime();
var dayCount = Math.ceil(timeDiff / (1000 * 3600 * 24));
return dayCount;
};
/**
* Returns the Index of week 0 for sunday and so on..
* @param {number} daysCount - No. of days from the base bs
*/
var getDayIndex = function getDayIndex(daysCount) {
return (daysCount % 7 + base_bs.dayOfWeek) % 7;
};
/**
* Safely get calendar data for a year as an array
* @param year - BS year
* @returns Array of days for each month in the year
*/
var getYearCalendarData = function getYearCalendarData(year) {
var yearData = calendar_data[year];
if (!Array.isArray(yearData)) {
throw new Error("Invalid calendar data for year ".concat(year, ". Expected array, got ").concat(_typeof(yearData)));
}
return yearData;
};
var ad2bs = function ad2bs(years, months, date) {
var base_bs$1 = base_bs;
var dayCount = countBSDaysFromBaseDateUsingAdDate(years, months, date);
var cumulativeData = cache.getCumulativeTotal();
var values = Object.values(cumulativeData);
var yearIndex = values.findIndex(function (value) {
return value >= dayCount;
});
var year = +base_bs$1.year + yearIndex;
var offsetDays = yearIndex === 0 ? dayCount : dayCount - cumulativeData[year - 1];
// Use the safe function to get year data
var yearData = getYearCalendarData(year);
var month = 0;
// Calculate which month the offsetDays falls into
while (month < 12 && yearData[month] <= offsetDays) {
offsetDays -= yearData[month];
month++;
}
// Handle edge case where month goes beyond 12
if (month === 12) {
month = 0;
year = year + 1;
// Get the next year's data safely
getYearCalendarData(year);
}
return {
year: year,
month: month + 1,
// one is added because month is 0 based
date: offsetDays + 1,
day: getDayIndex(dayCount)
};
};
var bs2ad = function bs2ad(year, month, day) {
var base_ad$1 = base_ad;
var cumulativeData = cache.getCumulativeTotal();
var prevMonthCumulativeTotal = 0;
var prevYearCumulativeTotal = cumulativeData[+year - 1] || 0;
for (var i = 0; i < +month - 1; i++) {
prevMonthCumulativeTotal += getYearCalendarData(+year)[i];
}
var countDays = prevYearCumulativeTotal + prevMonthCumulativeTotal + +day - 1;
var date1 = new Date(base_ad$1.year, base_ad$1.month, base_ad$1.day);
date1.setDate(date1.getDate() + countDays);
var ad = {
year: date1.getFullYear(),
month: date1.getMonth() + 1,
date: date1.getDate(),
day: date1.getDay()
};
return ad;
};
var getStartingDayOfBsMonth = function getStartingDayOfBsMonth(year, month) {
var monthIndex = month - 1;
var cumulativeData = cache.getCumulativeTotal();
var prevYearTotal = cumulativeData[year - 1] || 0;
var days = 0;
for (var i = 0; i < monthIndex; i++) {
days += getYearCalendarData(year)[i];
}
var daysCount = prevYearTotal + days;
return getDayIndex(daysCount);
};
var getBsRangeForAdCalendar = function getBsRangeForAdCalendar(year, month) {
var allNepaliMonth = getMonthNames("np", "short");
var bsfirst = ad2bs(year, month, 1);
var lastDate = getTotalDaysInAdMonth(year, month);
var bsLast = ad2bs(year, month, lastDate);
var firstMonth = allNepaliMonth[bsfirst.month - 1];
var lastMonth = allNepaliMonth[bsLast.month - 1];
return {
from: _assign(_assign({}, bsfirst), {
monthName: firstMonth
}),
to: _assign(_assign({}, bsLast), {
monthName: lastMonth
})
};
};
var getAdRangeForBsCalendar = function getAdRangeForBsCalendar(year, month) {
var allEnglishMonth = getMonthNames("en", "short");
var adfirst = bs2ad(year, month, 1);
var lastDate = getTotalDaysInBsMonth(year, month);
var adLast = bs2ad(year, month, lastDate);
var firstMonth = allEnglishMonth[adfirst.month - 1];
var lastMonth = allEnglishMonth[adLast.month - 1];
return {
from: _assign(_assign({}, adfirst), {
monthName: firstMonth
}),
to: _assign(_assign({}, adLast), {
monthName: lastMonth
})
};
};
//TODo Error
var getBsInfoOfoffsetDate = function getBsInfoOfoffsetDate(year, month, offset) {
var _a, _b;
var yearOffset = year + ((_a = offset === null || offset === void 0 ? void 0 : offset.year) !== null && _a !== void 0 ? _a : 0);
var monthOffset = month + ((_b = offset === null || offset === void 0 ? void 0 : offset.month) !== null && _b !== void 0 ? _b : 0);
var newMonth = monthOffset % 12 || 12;
var newYear = yearOffset + Math.floor(monthOffset / 12);
var newMonthIndex = newMonth - 1;
if (isInBetween(newYear, minBsYear, maxBsYear)) {
var totalDays = getYearCalendarData(newYear)[newMonthIndex];
return {
month: newMonth,
year: newYear,
totalDays: totalDays
};
} else throw new Error("Error");
};
var Header = function Header(_a) {
var year = _a.year,
month = _a.month,
changeYear = _a.changeYear,
changeMonth = _a.changeMonth,
isAD = _a.isAD,
showMonthDropdown = _a.showMonthDropdown,
showYearDropdown = _a.showYearDropdown,
showExtra = _a.showExtra;
// around difference of 57 years between AD and BS
var maxAD = 2035;
var maxBS = 2092;
var monthIndex = month - 1;
var allNepaliMonth = getMonthNames('np', 'full');
var allEnglishMonth = getMonthNames('en', 'full');
var allMonth = isAD ? allEnglishMonth : allNepaliMonth;
var currentMonthName = allMonth ? allMonth[monthIndex] : '';
var currentYear = isAD ? year : getNepaliNumber(year !== null && year !== void 0 ? year : 0);
var allYears = isAD ? getValidYears('en', 'AD') : getValidYears('en', 'BS');
var alternateCalendarTypeRange = isAD ? getBsRangeForAdCalendar(year, month) : getAdRangeForBsCalendar(year, month);
var from = alternateCalendarTypeRange.from,
to = alternateCalendarTypeRange.to;
var reachedMaxYear = isAD ? year >= maxAD : year >= maxBS;
return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
className: "month-header"
}, /*#__PURE__*/React.createElement("div", {
className: "left-actions"
}, /*#__PURE__*/React.createElement("button", {
style: {
border: 'none',
backgroundColor: 'inherit',
color: 'White'
},
title: "Previous Year",
onClick: function onClick() {
return changeYear(-1);
},
className: "prev-year hand-cursor"
}, "\u276E\u276E"), /*#__PURE__*/React.createElement("button", {
style: {
border: 'none',
backgroundColor: 'inherit',
color: 'White'
},
title: "Previous Month",
onClick: function onClick() {
return changeMonth(-1);
},
className: "prev-month hand-cursor"
}, "\u276E")), /*#__PURE__*/React.createElement("div", {
style: {
display: 'flex',
flexDirection: 'column',
gap: 0
}
}, /*#__PURE__*/React.createElement("div", {
className: "inline-dropdown-wrapper"
}, /*#__PURE__*/React.createElement("div", null, !showMonthDropdown ? (/*#__PURE__*/React.createElement("span", null, currentMonthName, " \xA0")) : (/*#__PURE__*/React.createElement("div", {
tabIndex: 0,
className: "inline-dropdown month-dropdown"
}, /*#__PURE__*/React.createElement("div", {
className: "value",
style: {
fontSize: 12,
padding: 0
}
}, currentMonthName), /*#__PURE__*/React.createElement("div", {
className: "inline-dropdown-container"
}, allMonth && allMonth.map(function (m, i) {
return /*#__PURE__*/React.createElement("div", {
key: m,
className: "inline-dropdown-item ".concat(i === monthIndex ? 'selected' : ''),
onClick: function onClick() {
var offset = i - monthIndex;
changeMonth(offset);
}
}, m);
}))))), /*#__PURE__*/React.createElement("div", {
key: "".concat(year, "--"),
tabIndex: 0,
className: "inline-dropdown"
}, !showYearDropdown ? (/*#__PURE__*/React.createElement("span", null, currentYear || 0, " \xA0")) : (/*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
className: "value",
style: {
padding: 0
}
}, currentYear || 0), /*#__PURE__*/React.createElement("div", {
className: "inline-dropdown-container"
}, allYears.map(function (m) {
return /*#__PURE__*/React.createElement("div", {
key: m,
className: "inline-dropdown-item ".concat(m === year ? 'selected' : ''),
onClick: function onClick() {
var offset = Number(m) - (year || 0);
changeYear(offset);
}
}, isAD ? m : getNepaliNumber(m));
})))))), showExtra && (/*#__PURE__*/React.createElement("div", {
className: "flex",
style: {
justifyContent: 'center'
}
}, /*#__PURE__*/React.createElement("div", {
style: {
fontSize: 12
}
}, from.monthName, "/", to.monthName, " \xA0"), /*#__PURE__*/React.createElement("div", {
key: "".concat(year, "--"),
tabIndex: 0,
className: "inline-dropdown",
style: {
fontSize: 12
}
}, from.year, from.year !== to.year ? "/".concat(String(to.year).slice(-2)) : '')))), /*#__PURE__*/React.createElement("div", {
className: "right-actions"
}, /*#__PURE__*/React.createElement("button", {
title: "Next Month",
style: {
border: 'none',
backgroundColor: 'inherit',
color: "".concat(reachedMaxYear && month >= 9 ? 'gray' : 'white')
},
disabled: reachedMaxYear && month >= 9,
onClick: function onClick() {
changeMonth(1);
},
className: "next-month hand-cursor"
}, "\u276F"), /*#__PURE__*/React.createElement("button", {
style: {
border: 'none',
backgroundColor: 'inherit',
color: "".concat(reachedMaxYear ? 'gray' : 'white')
},
onClick: function onClick() {
changeYear(1);
},
disabled: reachedMaxYear,
title: "Next Year",
className: "next-year hand-cursor"
}, "\u276F\u276F"))));
};
var formatDistanceLocale = {
lessThanXSeconds: {
one: "less than a second",
other: "less than {{count}} seconds"
},
xSeconds: {
one: "1 second",
other: "{{count}} seconds"
},
halfAMinute: "half a minute",
lessThanXMinutes: {
one: "less than a minute",
other: "less than {{count}} minutes"
},
xMinutes: {
one: "1 minute",
other: "{{count}} minutes"
},
aboutXHours: {
one: "about 1 hour",
other: "about {{count}} hours"
},
xHours: {
one: "1 hour",
other: "{{count}} hours"
},
xDays: {
one: "1 day",
other: "{{count}} days"
},
aboutXWeeks: {
one: "about 1 week",
other: "about {{count}} weeks"
},
xWeeks: {
one: "1 week",
other: "{{count}} weeks"
},
aboutXMonths: {
one: "about 1 month",
other: "about {{count}} months"
},
xMonths: {
one: "1 month",
other: "{{count}} months"
},
aboutXYears: {
one: "about 1 year",
other: "about {{count}} years"
},
xYears: {
one: "1 year",
other: "{{count}} years"
},
overXYears: {
one: "over 1 year",
other: "over {{count}} years"
},
almostXYears: {
one: "almost 1 year",
other: "almost {{count}} years"
}
};
var formatDistance = function formatDistance(token, count, options) {
var result;
var tokenValue = formatDistanceLocale[token];
if (typeof tokenValue === "string") {
result = tokenValue;
} else if (count === 1) {
result = tokenValue.one;
} else {
result = tokenValue.other.replace("{{count}}", count.toString());
}
if (options !== null && options !== void 0 && options.addSuffix) {
if (options.comparison && options.comparison > 0) {
return "in " + result;
} else {
return result + " ago";
}
}
return result;
};
function buildFormatLongFn(args) {
return function () {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
// TODO: Remove String()
var width = options.width ? String(options.width) : args.defaultWidth;
var format = args.formats[width] || args.formats[args.defaultWidth];
return format;
};
}
var dateFormats = {
full: "EEEE, MMMM do, y",
long: "MMMM do, y",
medium: "MMM d, y",
short: "MM/dd/yyyy"
};
var timeFormats = {
full: "h:mm:ss a zzzz",
long: "h:mm:ss a z",
medium: "h:mm:ss a",
short: "h:mm a"
};
var dateTimeFormats = {
full: "{{date}} 'at' {{time}}",
long: "{{date}} 'at' {{time}}",
medium: "{{date}}, {{time}}",
short: "{{date}}, {{time}}"
};
var formatLong = {
date: buildFormatLongFn({
formats: dateFormats,
defaultWidth: "full"
}),
time: buildFormatLongFn({
formats: timeFormats,
defaultWidth: "full"
}),
dateTime: buildFormatLongFn({
formats: dateTimeFormats,
defaultWidth: "full"
})
};
var formatRelativeLocale = {
lastWeek: "'last' eeee 'at' p",
yesterday: "'yesterday at' p",
today: "'today at' p",
tomorrow: "'tomorrow at' p",
nextWeek: "eeee 'at' p",
other: "P"
};
var formatRelative = function formatRelative(token, _date, _baseDate, _options) {
return formatRelativeLocale[token];
};
/**
* The localize function argument callback which allows to convert raw value to
* the actual type.
*
* @param value - The value to convert
*
* @returns The converted value
*/
/**
* The map of localized values for each width.
*/
/**
* The index type of the locale unit value. It types conversion of units of
* values that don't start at 0 (i.e. quarters).
*/
/**
* Converts the unit value to the tuple of values.
*/
/**
* The tuple of localized era values. The first element represents BC,
* the second element represents AD.
*/
/**
* The tuple of localized quarter values. The first element represents Q1.
*/
/**
* The tuple of localized day values. The first element represents Sunday.
*/
/**
* The tuple of localized month values. The first element represents January.
*/
function buildLocalizeFn(args) {
return function (value, options) {
var context = options !== null && options !== void 0 && options.context ? String(options.context) : "standalone";
var valuesArray;
if (context === "formatting" && args.formattingValues) {
var defaultWidth = args.defaultFormattingWidth || args.defaultWidth;
var width = options !== null && options !== void 0 && options.width ? String(options.width) : defaultWidth;
valuesArray = args.formattingValues[width] || args.formattingValues[defaultWidth];
} else {
var _defaultWidth = args.defaultWidth;
var _width = options !== null && options !== void 0 && options.width ? String(options.width) : args.defaultWidth;
valuesArray = args.values[_width] || args.values[_defaultWidth];
}
var index = args.argumentCallback ? args.argumentCallback(value) : value;
// @ts-expect-error - For some reason TypeScript just don't want to match it, no matter how hard we try. I challenge you to try to remove it!
return valuesArray[index];
};
}
var eraValues = {
narrow: ["B", "A"],
abbreviated: ["BC", "AD"],
wide: ["Before Christ", "Anno Domini"]
};
var quarterValues = {
narrow: ["1", "2", "3", "4"],
abbreviated: ["Q1", "Q2", "Q3", "Q4"],
wide: ["1st quarter", "2nd quarter", "3rd quarter", "4th quarter"]
};
// Note: in English, the names of days of the week and months are capitalized.
// If you are making a new locale based on this one, check if the same is true for the language you're working on.
// Generally, formatted dates should look like they are in the middle of a sentence,
// e.g. in Spanish language the weekdays and months should be in the lowercase.
var monthValues = {
narrow: ["J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"],
abbreviated: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
wide: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
};
var dayValues = {
narrow: ["S", "M", "T", "W", "T", "F", "S"],
short: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"],
abbreviated: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
wide: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
};
var dayPeriodValues = {
narrow: {
am: "a",
pm: "p",
midnight: "mi",
noon: "n",
morning: "morning",
afternoon: "afternoon",
evening: "evening",
night: "night"
},
abbreviated: {
am: "AM",
pm: "PM",
midnight: "midnight",
noon: "noon",
morning: "morning",
afternoon: "afternoon",
evening: "evening",
night: "night"
},
wide: {
am: "a.m.",
pm: "p.m.",
midnight: "midnight",
noon: "noon",
morning: "morning",
afternoon: "afternoon",
evening: "evening",
night: "night"
}
};
var formattingDayPeriodValues = {
narrow: {
am: "a",
pm: "p",
midnight: "mi",
noon: "n",
morning: "in the morning",
afternoon: "in the afternoon",
evening: "in the evening",
night: "at night"
},
abbreviated: {
am: "AM",
pm: "PM",
midnight: "midnight",
noon: "noon",
morning: "in the morning",
afternoon: "in the afternoon",
evening: "in the evening",
night: "at night"
},
wide: {
am: "a.m.",
pm: "p.m.",
midnight: "midnight",
noon: "noon",
morning: "in the morning",
afternoon: "in the afternoon",
evening: "in the evening",
night: "at night"
}
};
var ordinalNumber = function ordinalNumber(dirtyNumber, _options) {
var number = Number(dirtyNumber);
// If ordinal numbers depend on context, for example,
// if they are different for different grammatical genders,
// use `options.unit`.
//
// `unit` can be 'year', 'quarter', 'month', 'week', 'date', 'dayOfYear',
// 'day', 'hour', 'minute', 'second'.
var rem100 = number % 100;
if (rem100 > 20 || rem100 < 10) {
switch (rem100 % 10) {
case 1:
return number + "st";
case 2:
return number + "nd";
case 3:
return number + "rd";
}
}
return number + "th";
};
var localize = {
ordinalNumber: ordinalNumber,
era: buildLocalizeFn({
values: eraValues,
defaultWidth: "wide"
}),
quarter: buildLocalizeFn({
values: quarterValues,
defaultWidth: "wide",
argumentCallback: function argumentCallback(quarter) {
return quarter - 1;
}
}),
month: buildLocalizeFn({
values: monthValues,
defaultWidth: "wide"
}),
day: buildLocalizeFn({
values: dayValues,
defaultWidth: "wide"
}),
dayPeriod: buildLocalizeFn({
values: dayPeriodValues,
defaultWidth: "wide",
formattingValues: formattingDayPeriodValues,
defaultFormattingWidth: "wide"
})
};
function buildMatchFn(args) {
return function (string) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var width = options.width;
var matchPattern = width && args.matchPatterns[width] || args.matchPatterns[args.defaultMatchWidth];
var matchResult = string.match(matchPattern);
if (!matchResult) {
return null;
}
var matchedString = matchResult[0];
var parsePatterns = width && args.parsePatterns[width] || args.parsePatterns[args.defaultParseWidth];
var key = Array.isArray(parsePatterns) ? findIndex(parsePatterns, function (pattern) {
return pattern.test(matchedString);
}) :
// [TODO] -- I challenge you to fix the type
findKey(parsePatterns, function (pattern) {
return pattern.test(matchedString);
});
var value;
value = args.valueCallback ? args.valueCallback(key) : key;
value = options.valueCallback ?
// [TODO] -- I challenge you to fix the type
options.valueCallback(value) : value;
var rest = string.slice(matchedString.length);
return {
value: value,
rest: rest
};
};
}
function findKey(object, predicate) {
for (var key in object) {
if (Object.prototype.hasOwnProperty.call(object, key) && predicate(object[key])) {
return key;
}
}
return undefined;
}
function findIndex(array, predicate) {
for (var key = 0; key < array.length; key++) {
if (predicate(array[key])) {
return key;
}
}
return undefined;
}
function buildMatchPatternFn(args) {
return function (string) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var matchResult = string.match(args.matchPattern);
if (!matchResult) return null;
var matchedString = matchResult[0];
var parseResult = string.match(args.parsePattern);
if (!parseResult) return null;
var value = args.valueCallback ? args.valueCallback(parseResult[0]) : parseResult[0];
// [TODO] I challenge you to fix the type
value = options.valueCallback ? options.valueCallback(value) : value;
var rest = string.slice(matchedString.length);
return {
value: value,
rest: rest
};
};
}
var matchOrdinalNumberPattern = /^(\d+)(th|st|nd|rd)?/i;
var parseOrdinalNumberPattern = /\d+/i;
var matchEraPatterns = {
narrow: /^(b|a)/i,
abbreviated: /^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i,
wide: /^(before christ|before common era|anno domini|common era)/i
};
var parseEraPatterns = {
any: [/^b/i, /^(a|c)/i]
};
var matchQuarterPatterns = {
narrow: /^[1234]/i,
abbreviated: /^q[1234]/i,
wide: /^[1234](th|st|nd|rd)? quarter/i
};
var parseQuarterPatterns = {
any: [/1/i, /2/i, /3/i, /4/i]
};
var matchMonthPatterns = {
narrow: /^[jfmasond]/i,
abbreviated: /^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i,
wide: /^(january|february|march|april|may|june|july|august|september|october|november|december)/i
};
var parseMonthPatterns = {
narrow: [/^j/i, /^f/i, /^m/i, /^a/i, /^m/i, /^j/i, /^j/i, /^a/i, /^s/i, /^o/i, /^n/i, /^d/i],
any: [/^ja/i, /^f/i, /^mar/i, /^ap/i, /^may/i, /^jun/i, /^jul/i, /^au/i, /^s/i, /^o/i, /^n/i, /^d/i]
};
var matchDayPatterns = {
narrow: /^[smtwf]/i,
short: /^(su|mo|tu|we|th|fr|sa)/i,
abbreviated: /^(sun|mon|tue|wed|thu|fri|sat)/i,
wide: /^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i
};
var parseDayPatterns = {
narrow: [/^s/i, /^m/i, /^t/i, /^w/i, /^t/i, /^f/i, /^s/i],
any: [/^su/i, /^m/i, /^tu/i, /^w/i, /^th/i, /^f/i, /^sa/i]
};
var matchDayPeriodPatterns = {
narrow: /^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i,
any: /^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i
};
var parseDayPeriodPatterns = {
any: {
am: /^a/i,
pm: /^p/i,
midnight: /^mi/i,
noon: /^no/i,
morning: /morning/i,
afternoon: /afternoon/i,
evening: /evening/i,
night: /n