@anoki/fse-ui
Version:
FSE UI components library
208 lines (207 loc) • 5.05 kB
JavaScript
import { InvalidArgumentError as a } from "./index.es237.js";
import y from "./index.es4.js";
import { isoWeekdayToLocal as w, dayOfWeek as h } from "./index.es235.js";
function c(e) {
return typeof e > "u";
}
function L(e) {
return typeof e == "number";
}
function I(e) {
return typeof e == "number" && e % 1 === 0;
}
function g(e) {
return typeof e == "string";
}
function A(e) {
return Object.prototype.toString.call(e) === "[object Date]";
}
function b() {
try {
return typeof Intl < "u" && !!Intl.RelativeTimeFormat;
} catch {
return !1;
}
}
function v() {
try {
return typeof Intl < "u" && !!Intl.Locale && ("weekInfo" in Intl.Locale.prototype || "getWeekInfo" in Intl.Locale.prototype);
} catch {
return !1;
}
}
function C(e) {
return Array.isArray(e) ? e : [e];
}
function W(e, n, t) {
if (e.length !== 0)
return e.reduce((r, o) => {
const u = [n(o), o];
return r && t(r[0], u[0]) === r[0] ? r : u;
}, null)[1];
}
function M(e, n) {
return n.reduce((t, r) => (t[r] = e[r], t), {});
}
function O(e, n) {
return Object.prototype.hasOwnProperty.call(e, n);
}
function Y(e) {
if (e == null)
return null;
if (typeof e != "object")
throw new a("Week settings must be an object");
if (!f(e.firstDay, 1, 7) || !f(e.minimalDays, 1, 7) || !Array.isArray(e.weekend) || e.weekend.some((n) => !f(n, 1, 7)))
throw new a("Invalid week settings");
return {
firstDay: e.firstDay,
minimalDays: e.minimalDays,
weekend: Array.from(e.weekend)
};
}
function f(e, n, t) {
return I(e) && e >= n && e <= t;
}
function k(e, n) {
return e - n * Math.floor(e / n);
}
function i(e, n = 2) {
const t = e < 0;
let r;
return t ? r = "-" + ("" + -e).padStart(n, "0") : r = ("" + e).padStart(n, "0"), r;
}
function F(e) {
if (!(c(e) || e === null || e === ""))
return parseInt(e, 10);
}
function z(e) {
if (!(c(e) || e === null || e === ""))
return parseFloat(e);
}
function P(e) {
if (!(c(e) || e === null || e === "")) {
const n = parseFloat("0." + e) * 1e3;
return Math.floor(n);
}
}
function R(e, n, t = !1) {
const r = 10 ** n;
return (t ? Math.trunc : Math.round)(e * r) / r;
}
function d(e) {
return e % 4 === 0 && (e % 100 !== 0 || e % 400 === 0);
}
function N(e) {
return d(e) ? 366 : 365;
}
function U(e, n) {
const t = k(n - 1, 12) + 1, r = e + (n - t) / 12;
return t === 2 ? d(r) ? 29 : 28 : [31, null, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][t - 1];
}
function B(e) {
let n = Date.UTC(
e.year,
e.month - 1,
e.day,
e.hour,
e.minute,
e.second,
e.millisecond
);
return e.year < 100 && e.year >= 0 && (n = new Date(n), n.setUTCFullYear(e.year, e.month - 1, e.day)), +n;
}
function s(e, n, t) {
return -w(h(e, 1, n), t) + n - 1;
}
function E(e, n = 4, t = 1) {
const r = s(e, n, t), o = s(e + 1, n, t);
return (N(e) - r + o) / 7;
}
function V(e) {
return e > 99 ? e : e > y.twoDigitCutoffYear ? 1900 + e : 2e3 + e;
}
function Z(e, n, t, r = null) {
const o = new Date(e), u = {
hourCycle: "h23",
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit"
};
r && (u.timeZone = r);
const m = { timeZoneName: n, ...u }, l = new Intl.DateTimeFormat(t, m).formatToParts(o).find((p) => p.type.toLowerCase() === "timezonename");
return l ? l.value : null;
}
function H(e, n) {
let t = parseInt(e, 10);
Number.isNaN(t) && (t = 0);
const r = parseInt(n, 10) || 0, o = t < 0 || Object.is(t, -0) ? -r : r;
return t * 60 + o;
}
function $(e) {
const n = Number(e);
if (typeof e == "boolean" || e === "" || Number.isNaN(n))
throw new a(`Invalid unit value ${e}`);
return n;
}
function q(e, n) {
const t = {};
for (const r in e)
if (O(e, r)) {
const o = e[r];
if (o == null) continue;
t[n(r)] = $(o);
}
return t;
}
function x(e, n) {
const t = Math.trunc(Math.abs(e / 60)), r = Math.trunc(Math.abs(e % 60)), o = e >= 0 ? "+" : "-";
switch (n) {
case "short":
return `${o}${i(t, 2)}:${i(r, 2)}`;
case "narrow":
return `${o}${t}${r > 0 ? `:${r}` : ""}`;
case "techie":
return `${o}${i(t, 2)}${i(r, 2)}`;
default:
throw new RangeError(`Value format ${n} is out of range for property format`);
}
}
function G(e) {
return M(e, ["hour", "minute", "second", "millisecond"]);
}
export {
$ as asNumber,
W as bestBy,
U as daysInMonth,
N as daysInYear,
k as floorMod,
x as formatOffset,
v as hasLocaleWeekInfo,
O as hasOwnProperty,
b as hasRelative,
f as integerBetween,
A as isDate,
I as isInteger,
d as isLeapYear,
L as isNumber,
g as isString,
c as isUndefined,
C as maybeArray,
q as normalizeObject,
B as objToLocalTS,
i as padStart,
z as parseFloating,
F as parseInteger,
P as parseMillis,
Z as parseZoneInfo,
M as pick,
R as roundTo,
H as signedOffset,
G as timeObject,
V as untruncateYear,
Y as validateWeekSettings,
E as weeksInWeekYear
};
//# sourceMappingURL=index.es231.js.map