@tma.js/transformers 1.1.0 → 1.1.2

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.
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import { eitherFnToSimple as l } from "@tma.js/toolkit";
2
- import { transform as c, parse as A, pipe as p, string as n, union as B, instance as F, looseObject as h, optional as i, number as S, boolean as g, integer as I, date as J, record as N, check as O, is as U, unknown as z } from "valibot";
3
- function E(t, r, e, o, a, s, d, L, C) {
1
+ import { throwifyFpFn as g } from "@tma.js/toolkit";
2
+ import { pipe as c, string as n, check as S, transform as p, union as A, instance as D, parse as L, looseObject as l, optional as i, number as w, boolean as m, integer as N, date as O, record as I, is as U, unknown as z } from "valibot";
3
+ function E(t, r, e, u, a, s, o, R, J) {
4
4
  switch (arguments.length) {
5
5
  case 1:
6
6
  return t;
@@ -9,17 +9,17 @@ function E(t, r, e, o, a, s, d, L, C) {
9
9
  case 3:
10
10
  return e(r(t));
11
11
  case 4:
12
- return o(e(r(t)));
12
+ return u(e(r(t)));
13
13
  case 5:
14
- return a(o(e(r(t))));
14
+ return a(u(e(r(t))));
15
15
  case 6:
16
- return s(a(o(e(r(t)))));
16
+ return s(a(u(e(r(t)))));
17
17
  case 7:
18
- return d(s(a(o(e(r(t))))));
18
+ return o(s(a(u(e(r(t))))));
19
19
  case 8:
20
- return L(d(s(a(o(e(r(t)))))));
20
+ return R(o(s(a(u(e(r(t)))))));
21
21
  case 9:
22
- return C(L(d(s(a(o(e(r(t))))))));
22
+ return J(R(o(s(a(u(e(r(t))))))));
23
23
  default: {
24
24
  for (var y = arguments[0], _ = 1; _ < arguments.length; _++)
25
25
  y = arguments[_](y);
@@ -29,48 +29,70 @@ function E(t, r, e, o, a, s, d, L, C) {
29
29
  }
30
30
  var V = function(t) {
31
31
  return t._tag === "Left";
32
- }, x = function(t) {
32
+ }, q = function(t) {
33
33
  return { _tag: "Left", left: t };
34
- }, j = function(t) {
34
+ }, v = function(t) {
35
35
  return { _tag: "Right", right: t };
36
- }, D = x, u = j, q = function(t) {
36
+ }, Q = q, f = v, x = function(t) {
37
37
  return function(r) {
38
- return M(r) ? r : u(t(r.right));
38
+ return j(r) ? r : f(t(r.right));
39
39
  };
40
- }, M = V, P = function(t, r) {
40
+ }, j = V, G = function(t, r) {
41
41
  try {
42
- return u(t());
42
+ return f(t());
43
43
  } catch (e) {
44
- return D(r(e));
44
+ return Q(r(e));
45
45
  }
46
46
  };
47
- function H(t) {
48
- return c((r) => {
49
- const e = {};
50
- return new URLSearchParams(r).forEach((o, a) => {
51
- const s = e[a];
52
- Array.isArray(s) ? s.push(o) : s === void 0 ? e[a] = o : e[a] = [s, o];
53
- }), A(t, e);
54
- });
47
+ function M(t) {
48
+ const r = (e) => {
49
+ const u = {};
50
+ return new URLSearchParams(e).forEach((a, s) => {
51
+ const o = u[s];
52
+ Array.isArray(o) ? o.push(a) : o === void 0 ? u[s] = a : u[s] = [o, a];
53
+ }), L(t, u);
54
+ };
55
+ return c(
56
+ A([n(), D(URLSearchParams)]),
57
+ S((e) => {
58
+ try {
59
+ return r(e), !0;
60
+ } catch {
61
+ return !1;
62
+ }
63
+ }, "The value doesn't match required schema"),
64
+ p(r)
65
+ );
55
66
  }
56
- function K() {
57
- return c(JSON.parse);
67
+ function H(t) {
68
+ return c(
69
+ n(),
70
+ S((r) => {
71
+ try {
72
+ return JSON.parse(r), !0;
73
+ } catch {
74
+ return !1;
75
+ }
76
+ }, "Input is not a valid JSON value"),
77
+ p(JSON.parse),
78
+ t
79
+ );
58
80
  }
59
- function f(t) {
60
- return p(n(), K(), t);
81
+ function h(t) {
82
+ return c(n(), H(t));
61
83
  }
62
- function Q(t) {
63
- return p(
64
- B([n(), F(URLSearchParams)]),
65
- H(t)
84
+ function W(t) {
85
+ return c(
86
+ A([n(), D(URLSearchParams)]),
87
+ M(t)
66
88
  );
67
89
  }
68
- function m(t) {
90
+ function d(t) {
69
91
  return (r) => t.test(r);
70
92
  }
71
- const X = m(/^#[\da-f]{3}$/i), Y = m(/^#[\da-f]{4}$/i), Z = m(/^#[\da-f]{6}$/i), k = m(/^#[\da-f]{8}$/i);
72
- function v(t) {
73
- return [Z, k, X, Y].some((r) => r(t));
93
+ const K = d(/^#[\da-f]{3}$/i), X = d(/^#[\da-f]{4}$/i), Y = d(/^#[\da-f]{6}$/i), Z = d(/^#[\da-f]{8}$/i);
94
+ function k(t) {
95
+ return [Y, Z, K, X].some((r) => r(t));
74
96
  }
75
97
  function $(t) {
76
98
  let r = "#";
@@ -78,48 +100,48 @@ function $(t) {
78
100
  r += t[1 + e].repeat(2);
79
101
  return r;
80
102
  }
81
- function G(t) {
103
+ function b(t) {
82
104
  const r = t.replace(/\s/g, "").toLowerCase();
83
105
  if (/^#[\da-f]{3}$/i.test(r))
84
- return u($(r.toLowerCase() + "f"));
106
+ return f($(r.toLowerCase() + "f"));
85
107
  if (/^#[\da-f]{4}$/i.test(r))
86
- return u($(r.toLowerCase()));
108
+ return f($(r.toLowerCase()));
87
109
  if (/^#[\da-f]{6}$/i.test(r))
88
- return u(r.toLowerCase() + "ff");
110
+ return f(r.toLowerCase() + "ff");
89
111
  if (/^#[\da-f]{8}$/i.test(r))
90
- return u(r.toLowerCase());
112
+ return f(r.toLowerCase());
91
113
  const e = r.match(/^rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)$/) || r.match(/^rgba\((\d{1,3}),(\d{1,3}),(\d{1,3}),(\d{1,3})\)$/);
92
- return e ? u(
114
+ return e ? f(
93
115
  e.slice(1).reduce(
94
- (o, a) => o + parseInt(a, 10).toString(16).padStart(2, "0"),
116
+ (u, a) => u + parseInt(a, 10).toString(16).padStart(2, "0"),
95
117
  "#"
96
118
  ).padEnd(9, "f")
97
- ) : D(new Error(`Value "${t}" does not satisfy any of known RGB formats.`));
119
+ ) : Q(new Error(`Value "${t}" does not satisfy any of known RGB formats.`));
98
120
  }
99
121
  function tt(t) {
100
122
  return E(
101
- G(t),
102
- q((r) => r.slice(0, 7))
123
+ b(t),
124
+ x((r) => r.slice(0, 7))
103
125
  );
104
126
  }
105
- const ct = l(tt), pt = l(G);
127
+ const ct = g(tt), ft = g(b);
106
128
  function rt() {
107
- return h({
108
- id: S(),
129
+ return l({
130
+ id: w(),
109
131
  photo_url: i(n()),
110
132
  type: n(),
111
133
  title: n(),
112
134
  username: i(n())
113
135
  });
114
136
  }
115
- function w() {
116
- return h({
117
- added_to_attachment_menu: i(g()),
118
- allows_write_to_pm: i(g()),
137
+ function P() {
138
+ return l({
139
+ added_to_attachment_menu: i(m()),
140
+ allows_write_to_pm: i(m()),
119
141
  first_name: n(),
120
- id: S(),
121
- is_bot: i(g()),
122
- is_premium: i(g()),
142
+ id: w(),
143
+ is_bot: i(m()),
144
+ is_premium: i(m()),
123
145
  last_name: i(n()),
124
146
  language_code: i(n()),
125
147
  photo_url: i(n()),
@@ -127,120 +149,120 @@ function w() {
127
149
  });
128
150
  }
129
151
  function et() {
130
- return h({
131
- auth_date: p(
152
+ return l({
153
+ auth_date: c(
132
154
  n(),
133
- c((t) => new Date(Number(t) * 1e3)),
134
- J()
155
+ p((t) => new Date(Number(t) * 1e3)),
156
+ O()
135
157
  ),
136
- can_send_after: i(p(n(), c(Number), I())),
137
- chat: i(f(rt())),
158
+ can_send_after: i(c(n(), p(Number), N())),
159
+ chat: i(h(rt())),
138
160
  chat_type: i(n()),
139
161
  chat_instance: i(n()),
140
162
  hash: n(),
141
163
  query_id: i(n()),
142
- receiver: i(f(w())),
164
+ receiver: i(h(P())),
143
165
  start_param: i(n()),
144
166
  signature: n(),
145
- user: i(f(w()))
167
+ user: i(h(P()))
146
168
  });
147
169
  }
148
- function W() {
149
- return Q(et());
170
+ function F() {
171
+ return W(et());
150
172
  }
151
- function R() {
152
- return N(
173
+ function B() {
174
+ return I(
153
175
  n(),
154
- p(
155
- B([n(), S()]),
156
- c((t) => typeof t == "number" ? `#${(t & 16777215).toString(16).padStart(6, "0")}` : t),
157
- O(v)
176
+ c(
177
+ A([n(), w()]),
178
+ p((t) => typeof t == "number" ? `#${(t & 16777215).toString(16).padStart(6, "0")}` : t),
179
+ S(k)
158
180
  )
159
181
  );
160
182
  }
161
183
  function nt() {
162
- const t = i(p(n(), c((r) => r === "1")));
163
- return h({
184
+ const t = i(c(n(), p((r) => r === "1")));
185
+ return l({
164
186
  tgWebAppBotInline: t,
165
- tgWebAppData: i(W()),
166
- tgWebAppDefaultColors: i(f(R())),
187
+ tgWebAppData: i(F()),
188
+ tgWebAppDefaultColors: i(h(B())),
167
189
  tgWebAppFullscreen: t,
168
190
  tgWebAppPlatform: n(),
169
191
  tgWebAppShowSettings: t,
170
192
  tgWebAppStartParam: i(n()),
171
- tgWebAppThemeParams: f(R()),
193
+ tgWebAppThemeParams: h(B()),
172
194
  tgWebAppVersion: n()
173
195
  });
174
196
  }
175
- function b() {
176
- return Q(nt());
197
+ function T() {
198
+ return W(nt());
177
199
  }
178
- function ft(t) {
200
+ function pt(t) {
179
201
  try {
180
- return U(b(), t);
202
+ return U(T(), t);
181
203
  } catch {
182
204
  return !1;
183
205
  }
184
206
  }
185
207
  function ht() {
186
- return h({
208
+ return l({
187
209
  eventType: n(),
188
210
  eventData: i(z())
189
211
  });
190
212
  }
191
213
  function at(t) {
192
- return P(
193
- () => A(W(), t),
214
+ return G(
215
+ () => L(F(), t),
194
216
  (r) => r
195
217
  );
196
218
  }
197
219
  function it(t) {
198
- return P(
199
- () => A(b(), t),
220
+ return G(
221
+ () => L(T(), t),
200
222
  (r) => r
201
223
  );
202
224
  }
203
- const gt = l(at), lt = l(it);
204
- function T(t, r) {
205
- return r || (r = (e, o) => JSON.stringify(o)), new URLSearchParams(
206
- Object.entries(t).reduce((e, [o, a]) => (Array.isArray(a) ? e.push(...a.map((s) => [o, String(s)])) : a != null && e.push([
207
- o,
208
- a instanceof Date ? (a.getTime() / 1e3 | 0).toString() : typeof a == "string" || typeof a == "number" ? String(a) : typeof a == "boolean" ? a ? "1" : "0" : r(o, a)
225
+ const lt = g(at), mt = g(it);
226
+ function C(t, r) {
227
+ return r || (r = (e, u) => JSON.stringify(u)), new URLSearchParams(
228
+ Object.entries(t).reduce((e, [u, a]) => (Array.isArray(a) ? e.push(...a.map((s) => [u, String(s)])) : a != null && e.push([
229
+ u,
230
+ a instanceof Date ? (a.getTime() / 1e3 | 0).toString() : typeof a == "string" || typeof a == "number" ? String(a) : typeof a == "boolean" ? a ? "1" : "0" : r(u, a)
209
231
  ]), e), [])
210
232
  ).toString();
211
233
  }
212
- function ot(t) {
213
- return T(t);
234
+ function ut(t) {
235
+ return C(t);
214
236
  }
215
- function mt(t) {
216
- return T(t, (r, e) => r === "tgWebAppData" ? ot(e) : JSON.stringify(e));
237
+ function gt(t) {
238
+ return C(t, (r, e) => r === "tgWebAppData" ? ut(e) : JSON.stringify(e));
217
239
  }
218
240
  export {
219
241
  et as initData,
220
242
  rt as initDataChat,
221
- W as initDataQuery,
222
- w as initDataUser,
223
- v as isAnyRGB,
224
- ft as isLaunchParamsQuery,
225
- Z as isRGB,
226
- k as isRGBA,
227
- Y as isRGBAShort,
228
- X as isRGBShort,
243
+ F as initDataQuery,
244
+ P as initDataUser,
245
+ k as isAnyRGB,
246
+ pt as isLaunchParamsQuery,
247
+ Y as isRGB,
248
+ Z as isRGBA,
249
+ X as isRGBAShort,
250
+ K as isRGBShort,
229
251
  nt as launchParams,
230
- b as launchParamsQuery,
252
+ T as launchParamsQuery,
231
253
  ht as miniAppsMessage,
232
- gt as parseInitDataQuery,
254
+ lt as parseInitDataQuery,
233
255
  at as parseInitDataQueryFp,
234
- lt as parseLaunchParamsQuery,
256
+ mt as parseLaunchParamsQuery,
235
257
  it as parseLaunchParamsQueryFp,
236
- f as pipeJsonToSchema,
237
- Q as pipeQueryToSchema,
238
- ot as serializeInitDataQuery,
239
- mt as serializeLaunchParamsQuery,
240
- R as themeParams,
258
+ h as pipeJsonToSchema,
259
+ W as pipeQueryToSchema,
260
+ ut as serializeInitDataQuery,
261
+ gt as serializeLaunchParamsQuery,
262
+ B as themeParams,
241
263
  ct as toRGB,
242
264
  tt as toRGBFp,
243
- pt as toRGBFull,
244
- G as toRGBFullFp
265
+ ft as toRGBFull,
266
+ b as toRGBFullFp
245
267
  };
246
268
  //# sourceMappingURL=index.js.map