@arthurzakharov/ui-kit 2.9.0 → 2.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,14 @@
1
+ function f(r, t, s) {
2
+ if (r == null)
3
+ return [];
4
+ if (r instanceof EventTarget)
5
+ return [r];
6
+ if (typeof r == "string") {
7
+ const o = document.querySelectorAll(r);
8
+ return o ? Array.from(o) : [];
9
+ }
10
+ return Array.from(r).filter((n) => n != null);
11
+ }
12
+ export {
13
+ f as r
14
+ };
@@ -1,5 +1,5 @@
1
1
  import { Base } from '../types';
2
- import { SyntheticEvent } from 'react';
2
+ import { MouseEvent, SyntheticEvent } from 'react';
3
3
  /**
4
4
  * Type guard: checks whether value is a string
5
5
  */
@@ -44,4 +44,45 @@ export declare const convertToEuro: (num: number, options?: {
44
44
  * Falsy values (`null`, `undefined`, `false`, `0`, `0n`, `''`) are skipped.
45
45
  */
46
46
  export declare const clsx: (...inputs: ClsxClassValue[]) => string;
47
+ export declare const removeSlashAtEnd: (url: string | null) => string;
48
+ export declare const convertDateFormat: (dateString: string) => string;
49
+ export declare const sortSearchParams: (params: URLSearchParams) => URLSearchParams;
50
+ export declare const formatNumber: (num: number) => string;
51
+ export declare const getSalutationLabel: (salutation: string, withCase?: boolean) => string;
52
+ export declare const getSettlementPercent: (totalDebtNumber: number, settlementFeeNumber: number) => string;
53
+ export declare const fakeAwait: (time?: number | string) => Promise<void>;
54
+ export declare const isLeapYear: (year: number) => boolean;
55
+ export declare const convertToDateNumber: (num: string) => string;
56
+ export declare const isValidDate: (date: string) => boolean;
57
+ export declare const isValidBirthDate: (date: string) => boolean;
58
+ export declare const isValidHouseNumber: (houseNumber: string) => boolean;
59
+ export declare const blurAfterClick: (e: MouseEvent<HTMLElement>, cb: () => void) => void;
60
+ export declare const getPath: (path: string, baseUrl: string) => string;
61
+ export declare const publicSrcPath: (path: string, baseUrl: string) => string;
62
+ export declare const searchParams: (search: string) => URLSearchParams;
63
+ export declare const defaultTo: <A, B = NonNullable<A>>(a: A | null | undefined, b?: B) => A | B;
64
+ export declare const getSecretFromUrlParams: (search: string) => string;
65
+ export declare function getKeysFromUrlParams(keys: string, search: string): string;
66
+ export declare function getKeysFromUrlParams(keys: string[], search: string): string[];
67
+ export declare const deleteUrlParameters: (href: string, ...keys: string[]) => string;
68
+ export declare function getTimeStamp(date?: Date): string;
69
+ export declare function isWithinTimeStamps(from: string, to: string): boolean;
70
+ export declare const last: <T>(arr: T[]) => T;
71
+ export declare const formatEuroAmount: (amount: number) => string;
72
+ export declare const birthDateToGerman: (value: string) => string;
73
+ export declare const once: <T>(factory: () => T) => (() => T);
74
+ export declare const toGermanDate: (value: string) => string;
75
+ export declare const stripRequestName: (name: string) => string;
76
+ export declare function removeLastNumberSuffix(str: string): [string, number];
77
+ export declare function updateLastPathSubdirectory(url: string, update: string): string;
78
+ type GetFirstDayOfNextMonthOptions = {
79
+ format: 'us-kebab' | 'german-month';
80
+ firstDayOfNextMonth: boolean;
81
+ daysFromNow: number;
82
+ };
83
+ export declare function getDate(date: Date, options?: Partial<GetFirstDayOfNextMonthOptions>): string;
84
+ export declare const trimAllStringKeys: <T extends Record<string, unknown>>(record: T) => T;
85
+ export declare function formatDate(date: string): string;
86
+ export declare function pickValues<T extends Record<string, unknown>>(record: T): Partial<T> | null;
87
+ export declare const getFromJson: <T>(jsonString: string, pathToKey: string, fallbackValue: T) => T;
47
88
  export {};
@@ -1,49 +1,237 @@
1
- function o(t) {
1
+ function $(t, e, r) {
2
+ return e <= t && t < r;
3
+ }
4
+ function S(t) {
5
+ return t == null;
6
+ }
7
+ function b(t) {
2
8
  return typeof t == "string";
3
9
  }
4
- function e(t) {
5
- const r = /<\/?[a-z][\s\S]*>/i, n = /&(?:[a-z][a-z0-9]+|#\d+|#x[\da-f]+);/i;
6
- return r.test(t) || n.test(t);
10
+ function D(t) {
11
+ const e = /<\/?[a-z][\s\S]*>/i, r = /&(?:[a-z][a-z0-9]+|#\d+|#x[\da-f]+);/i;
12
+ return e.test(t) || r.test(t);
7
13
  }
8
- function u(t) {
9
- return o(t) && e(t);
14
+ function P(t) {
15
+ return b(t) && D(t);
10
16
  }
11
- const c = (t, r) => (n) => {
12
- r?.prevent && n.preventDefault(), r?.stop && n.stopPropagation(), r?.blur && n.currentTarget.blur(), r?.withEvent ? t(n) : t();
17
+ const E = (t, e) => (r) => {
18
+ e?.prevent && r.preventDefault(), e?.stop && r.stopPropagation(), e?.blur && r.currentTarget.blur(), e?.withEvent ? t(r) : t();
13
19
  };
14
- function f(t, r, n) {
15
- return t[r] ? t[r] : n;
20
+ function x(t, e, r) {
21
+ return t[e] ? t[e] : r;
16
22
  }
17
- const p = (t, r) => new Intl.NumberFormat("de-DE", {
23
+ const j = (t, e) => new Intl.NumberFormat("de-DE", {
18
24
  style: "currency",
19
25
  currency: "EUR",
20
- minimumFractionDigits: r?.skipZeroCents && t % 1 === 0 ? 0 : 2,
21
- maximumFractionDigits: r?.skipZeroCents && t % 1 === 0 ? 0 : 2
22
- }).format(t), s = (...t) => {
23
- const r = [];
24
- for (const n of t)
25
- if (n) {
26
- if (typeof n == "string" || typeof n == "number" || typeof n == "bigint") {
27
- r.push(String(n));
26
+ minimumFractionDigits: e?.skipZeroCents && t % 1 === 0 ? 0 : 2,
27
+ maximumFractionDigits: e?.skipZeroCents && t % 1 === 0 ? 0 : 2
28
+ }).format(t), N = (...t) => {
29
+ const e = [];
30
+ for (const r of t)
31
+ if (r) {
32
+ if (typeof r == "string" || typeof r == "number" || typeof r == "bigint") {
33
+ e.push(String(r));
28
34
  continue;
29
35
  }
30
- if (Array.isArray(n)) {
31
- const i = s(...n);
32
- i && r.push(i);
36
+ if (Array.isArray(r)) {
37
+ const n = N(...r);
38
+ n && e.push(n);
33
39
  continue;
34
40
  }
35
- if (typeof n == "object")
36
- for (const i in n)
37
- n[i] && r.push(i);
41
+ if (typeof r == "object")
42
+ for (const n in r)
43
+ r[n] && e.push(n);
44
+ }
45
+ return e.join(" ");
46
+ }, v = (t) => typeof t != "string" ? "" : t.replace(/\/$/, ""), R = (t) => {
47
+ const e = t.split("/");
48
+ return e[2] + "-" + e[1] + "-" + e[0];
49
+ }, w = (t) => {
50
+ const e = Array.from(t.entries());
51
+ return e.sort(([r], [n]) => r === "secret" ? -1 : n === "secret" ? 1 : r === "page" ? -1 : n === "page" ? 1 : 0), new URLSearchParams(e);
52
+ }, F = (t) => parseFloat(String(t)).toFixed().replace(".", ","), H = (t, e = !0) => {
53
+ const r = [
54
+ { value: "male", label: "Herr" },
55
+ { value: "female", label: "Frau" },
56
+ { value: "partner", label: "Eheleute" },
57
+ { value: "Herr", label: "Herr" },
58
+ { value: "Frau", label: "Frau" },
59
+ { value: "Divers", label: "Divers" }
60
+ ].find((n) => n.value === t)?.label || "";
61
+ return (t === "male" || t === "Herr") && e ? "Herrn" : r;
62
+ }, O = (t, e) => t > 0 ? String(F(e / t * 100)) : "0,00", Y = async (t) => {
63
+ const e = typeof t == "string" ? Number(t) : t;
64
+ return await new Promise((r) => {
65
+ setTimeout(() => {
66
+ r();
67
+ }, e || 500);
68
+ });
69
+ }, T = (t) => t % 4 === 0 && t % 100 !== 0 || t % 400 === 0, l = (t) => parseInt(t).toString().length !== t.length ? "" : t.length === 1 ? `0${t}` : t, M = (t) => {
70
+ const [e, r, n] = t.split("/"), s = parseInt(e, 10), o = parseInt(r, 10), a = parseInt(n, 10);
71
+ if (Number.isNaN(s) || Number.isNaN(o) || Number.isNaN(a) || t.length !== 10 || o > 12 || s > 31)
72
+ return !1;
73
+ if (o === 2 && s > 28)
74
+ if (s === 29) {
75
+ if (!T(a))
76
+ return !1;
77
+ } else
78
+ return !1;
79
+ else if (s > 30 && (o === 4 || o === 6 || o === 9 || o === 11))
80
+ return !1;
81
+ return !0;
82
+ }, z = (t) => {
83
+ if (/^\s*(3[01]|[12][0-9]|0?[1-9])\/(1[012]|0?[1-9])\/((?:19|20)\d{2})\s*$/g.test(t) && M(t)) {
84
+ const [r, n, s] = t.split("/"), o = /* @__PURE__ */ new Date(), a = String(o.getFullYear() - 18), i = l(String(o.getMonth() + 1)), c = l(`${o.getDate()}`), u = /* @__PURE__ */ new Date(`${s}-${n}-${r}T00:00:00`), f = /* @__PURE__ */ new Date(`${a}-${i}-${c}T00:00:00`);
85
+ return u <= f;
86
+ }
87
+ return !1;
88
+ }, L = (t) => $(t.length, 1, 20), I = (t, e) => {
89
+ t.currentTarget.blur(), e();
90
+ }, U = (t, e) => e === "/" ? e + t + "/" : e + "/" + t + "/", C = (t, e) => "/" + [e !== "/" ? e : "", t].join("*").replace(/\//g, "*").split("*").filter(Boolean).join("/"), h = (t) => new URLSearchParams(t), A = (t, e) => t == null || Object.is(t, NaN) ? e : t, B = (t) => A(h(t).get("secret"), "");
91
+ function G(t, e, r = "") {
92
+ const n = h(e), s = (o) => n.get(o)?.trim() || r;
93
+ return Array.isArray(t) ? t.map((o) => s(o)) : s(t);
94
+ }
95
+ const J = (t, ...e) => {
96
+ const r = new URL(t), n = new URLSearchParams(r.search);
97
+ return e.forEach((s) => n.delete(s)), `${r.origin}${r.pathname}?${w(n).toString()}${r.hash}`;
98
+ };
99
+ function V(t = /* @__PURE__ */ new Date()) {
100
+ const e = t.getTimezoneOffset(), r = e > 0 ? "-" : "+", n = (y) => String(Math.floor(Math.abs(y))).padStart(2, "0"), s = t.getFullYear(), o = n(t.getMonth() + 1), a = n(t.getDate()), i = n(t.getHours()), c = n(t.getMinutes()), u = n(t.getSeconds()), f = n(e / 60), p = n(e % 60), d = `${r}${f}:${p}`;
101
+ return `${s}-${o}-${a}T${i}:${c}:${u}${d}`;
102
+ }
103
+ function k(t, e) {
104
+ const r = (/* @__PURE__ */ new Date()).getTime(), n = new Date(t).getTime() || r, s = new Date(e).getTime() || r;
105
+ return r > n && r < s;
106
+ }
107
+ const K = (t) => t[t.length - 1], W = (t) => new Intl.NumberFormat("de-DE", { minimumFractionDigits: 2, maximumFractionDigits: 2 }).format(t), Z = (t) => {
108
+ if (!t) return "";
109
+ const e = t.split("/");
110
+ if (e.length !== 3 || !e.every((o) => /^\d+$/.test(o))) return "";
111
+ const [r, n, s] = e;
112
+ return `${r}.${n}.${s}`;
113
+ }, q = (t) => {
114
+ let e, r = !1;
115
+ return () => (r || (e = t(), r = !0), e);
116
+ }, _ = (t) => {
117
+ if (!t) return "";
118
+ if (/^\d{2}\.\d{2}\.\d{4}$/.test(t)) return t;
119
+ const e = t.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/);
120
+ if (e) {
121
+ const [, n, s, o] = e;
122
+ return `${n.padStart(2, "0")}.${s.padStart(2, "0")}.${o}`;
123
+ }
124
+ const r = t.match(/^(\d{4})-(\d{2})-(\d{2})/);
125
+ if (r) {
126
+ const [, n, s, o] = r;
127
+ return `${o}.${s}.${n}`;
128
+ }
129
+ return "";
130
+ }, Q = (t) => {
131
+ const e = t.match(new RegExp(/GET\/authenticate/)), r = t.match(new RegExp(/POST\/marketing\/case/));
132
+ return e ? e[0] : r ? r[0] : t;
133
+ };
134
+ function X(t) {
135
+ const e = t.match(/^(.*)_(\d+)$/);
136
+ return e ? [e[1], Number.parseInt(e[2])] : [t, -1];
137
+ }
138
+ function tt(t, e) {
139
+ const r = t.endsWith("/"), n = r ? t.slice(0, -1) : t;
140
+ if (!/^\/([^/]+\/)*[^/]+$/.test(n)) return t;
141
+ const s = n.split("/");
142
+ return s.length <= 2 ? t : (s[s.length - 1] = e, s.join("/") + (r ? "/" : ""));
143
+ }
144
+ function et(t, e) {
145
+ const r = t.getFullYear(), n = t.getMonth() + 1, s = t.getDate();
146
+ if (e?.daysFromNow) {
147
+ const o = new Date(t);
148
+ o.setDate(o.getDate() + e.daysFromNow);
149
+ const a = (o.getMonth() + 1).toString().padStart(2, "0"), i = o.getDate().toString().padStart(2, "0");
150
+ return e?.format === "german-month" ? `1.${Number(a)}.` : `${o.getFullYear()}-${a}-${i}`;
151
+ }
152
+ if (e?.firstDayOfNextMonth)
153
+ if (s >= 15) {
154
+ const o = new Date(r, n, 1), a = o.getFullYear(), i = (o.getMonth() + 1).toString().padStart(2, "0");
155
+ return e?.format === "german-month" ? `1.${Number(i)}.` : `${a}-${i}-01`;
156
+ } else {
157
+ const o = n.toString().padStart(2, "0");
158
+ return e?.format === "german-month" ? `15.${Number(o)}.` : `${r}-${o}-15`;
38
159
  }
39
- return r.join(" ");
160
+ return "";
161
+ }
162
+ const m = (t) => typeof t == "object" && t !== null && !Array.isArray(t), g = (t) => {
163
+ const e = {};
164
+ for (const [r, n] of Object.entries(t))
165
+ typeof n == "string" ? e[r] = n.trim() : Array.isArray(n) ? e[r] = n.map(
166
+ (s) => typeof s == "string" ? s.trim() : m(s) ? g(s) : s
167
+ ) : m(n) ? e[r] = g(n) : e[r] = n;
168
+ return e;
169
+ };
170
+ function rt(t) {
171
+ if (!t) return "";
172
+ const e = new Date(t);
173
+ if (isNaN(e.getTime())) return "";
174
+ const r = String(e.getDate()).padStart(2, "0"), n = String(e.getMonth() + 1).padStart(2, "0"), s = e.getFullYear();
175
+ return `${r}.${n}.${s}`;
176
+ }
177
+ function nt(t) {
178
+ const e = Object.entries(t).filter(([, r]) => S(r) ? !1 : typeof r == "string" ? r.trim() !== "" : !0);
179
+ return e.length ? Object.fromEntries(e) : null;
180
+ }
181
+ const st = (t, e, r) => {
182
+ try {
183
+ const n = JSON.parse(t);
184
+ if (!e) return n;
185
+ const s = e.split(".").reduce((o, a) => {
186
+ if (o && typeof o == "object" && a in o)
187
+ return o[a];
188
+ }, n);
189
+ return s === void 0 ? r : s;
190
+ } catch {
191
+ return r;
192
+ }
40
193
  };
41
194
  export {
42
- f as baseProps,
43
- s as clsx,
44
- e as containsHtml,
45
- p as convertToEuro,
46
- u as isHtmlString,
47
- o as isString,
48
- c as withControl
195
+ x as baseProps,
196
+ Z as birthDateToGerman,
197
+ I as blurAfterClick,
198
+ N as clsx,
199
+ D as containsHtml,
200
+ R as convertDateFormat,
201
+ l as convertToDateNumber,
202
+ j as convertToEuro,
203
+ A as defaultTo,
204
+ J as deleteUrlParameters,
205
+ Y as fakeAwait,
206
+ rt as formatDate,
207
+ W as formatEuroAmount,
208
+ F as formatNumber,
209
+ et as getDate,
210
+ st as getFromJson,
211
+ G as getKeysFromUrlParams,
212
+ U as getPath,
213
+ H as getSalutationLabel,
214
+ B as getSecretFromUrlParams,
215
+ O as getSettlementPercent,
216
+ V as getTimeStamp,
217
+ P as isHtmlString,
218
+ T as isLeapYear,
219
+ b as isString,
220
+ z as isValidBirthDate,
221
+ M as isValidDate,
222
+ L as isValidHouseNumber,
223
+ k as isWithinTimeStamps,
224
+ K as last,
225
+ q as once,
226
+ nt as pickValues,
227
+ C as publicSrcPath,
228
+ X as removeLastNumberSuffix,
229
+ v as removeSlashAtEnd,
230
+ h as searchParams,
231
+ w as sortSearchParams,
232
+ Q as stripRequestName,
233
+ _ as toGermanDate,
234
+ g as trimAllStringKeys,
235
+ tt as updateLastPathSubdirectory,
236
+ E as withControl
49
237
  };
@@ -1,10 +1,45 @@
1
- import { baseProps as r, clsx as i, containsHtml as n, convertToEuro as s, isHtmlString as l, isString as c, withControl as e } from "./functions.util.js";
1
+ import { baseProps as a, birthDateToGerman as r, blurAfterClick as o, clsx as m, containsHtml as i, convertDateFormat as s, convertToDateNumber as l, convertToEuro as n, defaultTo as u, deleteUrlParameters as c, fakeAwait as S, formatDate as g, formatEuroAmount as b, formatNumber as h, getDate as P, getFromJson as f, getKeysFromUrlParams as p, getPath as d, getSalutationLabel as D, getSecretFromUrlParams as T, getSettlementPercent as v, getTimeStamp as A, isHtmlString as N, isLeapYear as F, isString as L, isValidBirthDate as V, isValidDate as k, isValidHouseNumber as x, isWithinTimeStamps as y, last as E, once as H, pickValues as U, publicSrcPath as w, removeLastNumberSuffix as C, removeSlashAtEnd as G, searchParams as K, sortSearchParams as q, stripRequestName as B, toGermanDate as J, trimAllStringKeys as R, updateLastPathSubdirectory as W, withControl as Y } from "./functions.util.js";
2
2
  export {
3
- r as baseProps,
4
- i as clsx,
5
- n as containsHtml,
6
- s as convertToEuro,
7
- l as isHtmlString,
8
- c as isString,
9
- e as withControl
3
+ a as baseProps,
4
+ r as birthDateToGerman,
5
+ o as blurAfterClick,
6
+ m as clsx,
7
+ i as containsHtml,
8
+ s as convertDateFormat,
9
+ l as convertToDateNumber,
10
+ n as convertToEuro,
11
+ u as defaultTo,
12
+ c as deleteUrlParameters,
13
+ S as fakeAwait,
14
+ g as formatDate,
15
+ b as formatEuroAmount,
16
+ h as formatNumber,
17
+ P as getDate,
18
+ f as getFromJson,
19
+ p as getKeysFromUrlParams,
20
+ d as getPath,
21
+ D as getSalutationLabel,
22
+ T as getSecretFromUrlParams,
23
+ v as getSettlementPercent,
24
+ A as getTimeStamp,
25
+ N as isHtmlString,
26
+ F as isLeapYear,
27
+ L as isString,
28
+ V as isValidBirthDate,
29
+ k as isValidDate,
30
+ x as isValidHouseNumber,
31
+ y as isWithinTimeStamps,
32
+ E as last,
33
+ H as once,
34
+ U as pickValues,
35
+ w as publicSrcPath,
36
+ C as removeLastNumberSuffix,
37
+ G as removeSlashAtEnd,
38
+ K as searchParams,
39
+ q as sortSearchParams,
40
+ B as stripRequestName,
41
+ J as toGermanDate,
42
+ R as trimAllStringKeys,
43
+ W as updateLastPathSubdirectory,
44
+ Y as withControl
10
45
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@arthurzakharov/ui-kit",
3
3
  "private": false,
4
- "version": "2.9.0",
4
+ "version": "2.11.0",
5
5
  "type": "module",
6
6
  "main": "dist/main.js",
7
7
  "types": "dist/main.d.ts",
@@ -29,6 +29,7 @@
29
29
  "test-storybook:coverage": "vitest --project=storybook --coverage"
30
30
  },
31
31
  "peerDependencies": {
32
+ "es-toolkit": "^1.44.0",
32
33
  "lucide-react": "^0.562.0",
33
34
  "motion": "^12.26.1",
34
35
  "react": "^18.3.1",