typetify 2.0.0 → 2.1.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.
Files changed (47) hide show
  1. package/dist/chunk-7G4ZSMQX.js +470 -0
  2. package/dist/chunk-7G4ZSMQX.js.map +1 -0
  3. package/dist/chunk-CWHYQWNU.mjs +224 -0
  4. package/dist/chunk-CWHYQWNU.mjs.map +1 -0
  5. package/dist/{chunk-JAOGY4JO.mjs → chunk-FEX5C4OH.mjs} +2 -2
  6. package/dist/chunk-FEX5C4OH.mjs.map +1 -0
  7. package/dist/chunk-FN553YPU.js +441 -0
  8. package/dist/chunk-FN553YPU.js.map +1 -0
  9. package/dist/chunk-FT2EK4AM.mjs +420 -0
  10. package/dist/chunk-FT2EK4AM.mjs.map +1 -0
  11. package/dist/chunk-N6IUADIP.mjs +414 -0
  12. package/dist/chunk-N6IUADIP.mjs.map +1 -0
  13. package/dist/chunk-OKB3MS5F.js +547 -0
  14. package/dist/chunk-OKB3MS5F.js.map +1 -0
  15. package/dist/chunk-POD52NJ3.mjs +526 -0
  16. package/dist/chunk-POD52NJ3.mjs.map +1 -0
  17. package/dist/{chunk-SIA5BSVY.js → chunk-S535LAXW.js} +2 -2
  18. package/dist/chunk-S535LAXW.js.map +1 -0
  19. package/dist/chunk-X55EORNF.js +259 -0
  20. package/dist/chunk-X55EORNF.js.map +1 -0
  21. package/dist/index.d.mts +143 -24
  22. package/dist/index.d.ts +143 -24
  23. package/dist/index.js +17 -8
  24. package/dist/index.js.map +1 -1
  25. package/dist/index.mjs +10 -1
  26. package/dist/index.mjs.map +1 -1
  27. package/dist/iterator/index.js +77 -514
  28. package/dist/iterator/index.js.map +1 -1
  29. package/dist/iterator/index.mjs +1 -499
  30. package/dist/iterator/index.mjs.map +1 -1
  31. package/dist/logic/index.js +193 -408
  32. package/dist/logic/index.js.map +1 -1
  33. package/dist/logic/index.mjs +1 -364
  34. package/dist/logic/index.mjs.map +1 -1
  35. package/dist/narrowing/index.js +133 -212
  36. package/dist/narrowing/index.js.map +1 -1
  37. package/dist/narrowing/index.mjs +1 -183
  38. package/dist/narrowing/index.mjs.map +1 -1
  39. package/dist/schema/index.js +102 -402
  40. package/dist/schema/index.js.map +1 -1
  41. package/dist/schema/index.mjs +2 -381
  42. package/dist/schema/index.mjs.map +1 -1
  43. package/dist/typed/index.js +47 -47
  44. package/dist/typed/index.mjs +1 -1
  45. package/package.json +1 -1
  46. package/dist/chunk-JAOGY4JO.mjs.map +0 -1
  47. package/dist/chunk-SIA5BSVY.js.map +0 -1
@@ -1,416 +1,201 @@
1
1
  'use strict';
2
2
 
3
+ var chunk7G4ZSMQX_js = require('../chunk-7G4ZSMQX.js');
3
4
  require('../chunk-PZ5AY32C.js');
4
5
 
5
- // src/logic/when.ts
6
- function when(condition, fn) {
7
- if (condition) {
8
- return fn();
9
- }
10
- return void 0;
11
- }
12
- function whenValue(condition, value) {
13
- return condition ? value : void 0;
14
- }
15
6
 
16
- // src/logic/unless.ts
17
- function unless(condition, fn) {
18
- if (!condition) {
19
- return fn();
20
- }
21
- return void 0;
22
- }
23
- function unlessValue(condition, value) {
24
- return !condition ? value : void 0;
25
- }
26
7
 
27
- // src/logic/ifElse.ts
28
- function ifElse(condition, whenTrue, whenFalse) {
29
- return condition ? whenTrue : whenFalse;
30
- }
31
- function ifElseLazy(condition, whenTrue, whenFalse) {
32
- return condition ? whenTrue() : whenFalse();
33
- }
34
-
35
- // src/logic/cond.ts
36
- function cond(...pairs) {
37
- for (const [condition, value] of pairs) {
38
- if (condition) {
39
- return value;
40
- }
41
- }
42
- return void 0;
43
- }
44
- function condLazy(...pairs) {
45
- for (const [condition, fn] of pairs) {
46
- if (condition) {
47
- return fn();
48
- }
49
- }
50
- return void 0;
51
- }
52
- function condBy(value, ...pairs) {
53
- for (const [predicate, result] of pairs) {
54
- if (predicate(value)) {
55
- return result;
56
- }
57
- }
58
- return void 0;
59
- }
60
-
61
- // src/logic/match.ts
62
- function matchValue(value, cases) {
63
- return cases[value];
64
- }
65
- function matchWithDefault(value, cases, defaultValue) {
66
- const result = cases[value];
67
- return result !== void 0 ? result : defaultValue;
68
- }
69
- function matchLazy(value, cases) {
70
- return cases[value]();
71
- }
72
- function matchType(value, matchers) {
73
- for (const [guard, handler] of matchers) {
74
- if (guard(value)) {
75
- return handler(value);
76
- }
77
- }
78
- return void 0;
79
- }
80
-
81
- // src/logic/and.ts
82
- function and(...values) {
83
- if (values.length === 0) return void 0;
84
- for (let i = 0; i < values.length - 1; i++) {
85
- const value = values[i];
86
- if (!value) return value;
87
- }
88
- const last = values[values.length - 1];
89
- return typeof last === "function" ? last() : last;
90
- }
91
- function allTrue(...values) {
92
- return values.every(Boolean);
93
- }
94
- function andThen(conditions, fn) {
95
- return conditions.every(Boolean) ? fn() : void 0;
96
- }
97
-
98
- // src/logic/or.ts
99
- function or(...values) {
100
- if (values.length === 0) return void 0;
101
- for (const value of values) {
102
- if (value) return value;
103
- }
104
- return values[values.length - 1];
105
- }
106
- function anyTrue(...values) {
107
- return values.some(Boolean);
108
- }
109
- function orThen(conditions, fn) {
110
- return conditions.some(Boolean) ? fn() : void 0;
111
- }
112
-
113
- // src/logic/not.ts
114
- function not(value) {
115
- return !value;
116
- }
117
- function notFn(predicate) {
118
- return (...args) => !predicate(...args);
119
- }
120
-
121
- // src/logic/coalesce.ts
122
- function coalesce(...values) {
123
- for (const value of values) {
124
- if (value !== null && value !== void 0) {
125
- return value;
126
- }
127
- }
128
- return void 0;
129
- }
130
- function coalesceLazy(...fns) {
131
- for (const fn of fns) {
132
- const value = fn();
133
- if (value !== null && value !== void 0) {
134
- return value;
135
- }
136
- }
137
- return void 0;
138
- }
139
-
140
- // src/logic/defaultTo.ts
141
- function defaultTo(value, defaultValue) {
142
- return value ?? defaultValue;
143
- }
144
- function defaultToLazy(value, getDefault) {
145
- return value ?? getDefault();
146
- }
147
- function defaultToIf(value, predicate, defaultValue) {
148
- return predicate(value) ? value : defaultValue;
149
- }
150
- function defaultToIfEmpty(value, defaultValue) {
151
- if (value === null || value === void 0) return defaultValue;
152
- if (value === "") return defaultValue;
153
- if (Array.isArray(value) && value.length === 0) return defaultValue;
154
- if (typeof value === "object" && Object.keys(value).length === 0) return defaultValue;
155
- return value;
156
- }
157
-
158
- // src/logic/firstTruthy.ts
159
- function firstTruthy(values) {
160
- for (const value of values) {
161
- if (value) return value;
162
- }
163
- return void 0;
164
- }
165
- function firstWhere(values, predicate) {
166
- for (const value of values) {
167
- if (predicate(value)) return value;
168
- }
169
- return void 0;
170
- }
171
- function firstDefined(values) {
172
- for (const value of values) {
173
- if (value !== null && value !== void 0) return value;
174
- }
175
- return void 0;
176
- }
177
-
178
- // src/logic/allTruthy.ts
179
- function allTruthy(values) {
180
- return values.every(Boolean);
181
- }
182
- function allWhere(values, predicate) {
183
- return values.every(predicate);
184
- }
185
- function allDefined(values) {
186
- return values.every((v) => v !== null && v !== void 0);
187
- }
188
-
189
- // src/logic/get.ts
190
- function get(obj, ...path) {
191
- let current = obj;
192
- for (const key of path) {
193
- if (current === null || current === void 0) {
194
- return void 0;
195
- }
196
- current = current[key];
197
- }
198
- return current;
199
- }
200
- function getTyped(obj, path) {
201
- return get(obj, ...path);
202
- }
203
- function getPath(obj, path) {
204
- const keys = path.split(".").map((k) => {
205
- const num = Number(k);
206
- return Number.isNaN(num) ? k : num;
207
- });
208
- return get(obj, ...keys);
209
- }
210
-
211
- // src/logic/getOr.ts
212
- function getOr(obj, defaultValue, ...path) {
213
- let current = obj;
214
- for (const key of path) {
215
- if (current === null || current === void 0) {
216
- return defaultValue;
217
- }
218
- current = current[key];
219
- }
220
- return current ?? defaultValue;
221
- }
222
- function getPathOr(obj, defaultValue, path) {
223
- const keys = path.split(".").map((k) => {
224
- const num = Number(k);
225
- return Number.isNaN(num) ? k : num;
226
- });
227
- return getOr(obj, defaultValue, ...keys);
228
- }
229
- function getOrLazy(obj, getDefault, ...path) {
230
- let current = obj;
231
- for (const key of path) {
232
- if (current === null || current === void 0) {
233
- return getDefault();
234
- }
235
- current = current[key];
236
- }
237
- return current !== null && current !== void 0 ? current : getDefault();
238
- }
239
-
240
- // src/logic/tryGet.ts
241
- function tryGet(fn) {
242
- try {
243
- return fn();
244
- } catch {
245
- return void 0;
246
- }
247
- }
248
- function tryGetOr(fn, defaultValue) {
249
- try {
250
- return fn();
251
- } catch {
252
- return defaultValue;
253
- }
254
- }
255
- function tryGetResult(fn) {
256
- try {
257
- return { ok: true, value: fn() };
258
- } catch (error) {
259
- return { ok: false, error };
260
- }
261
- }
262
-
263
- // src/logic/safe.ts
264
- function safe(obj) {
265
- const handler = {
266
- get(target, prop) {
267
- if (target === null || target === void 0) {
268
- return createNullProxy();
269
- }
270
- const value = target[prop];
271
- if (value === null || value === void 0) {
272
- return createNullProxy();
273
- }
274
- if (typeof value === "object") {
275
- return new Proxy(value, handler);
276
- }
277
- return value;
278
- }
279
- };
280
- if (obj === null || obj === void 0) {
281
- return createNullProxy();
282
- }
283
- return new Proxy(obj, handler);
284
- }
285
- function createNullProxy() {
286
- const handler = {
287
- get() {
288
- return createNullProxy();
289
- }
290
- };
291
- return new Proxy({}, handler);
292
- }
293
- function unwrap(value) {
294
- if (value === null || value === void 0) return void 0;
295
- if (typeof value === "object" && Object.keys(value).length === 0) {
296
- return void 0;
297
- }
298
- return value;
299
- }
300
-
301
- // src/logic/chain.ts
302
- function chain(value) {
303
- return {
304
- map(fn) {
305
- if (value === null || value === void 0) {
306
- return chain(void 0);
307
- }
308
- return chain(fn(value));
309
- },
310
- flatMap(fn) {
311
- if (value === null || value === void 0) {
312
- return chain(void 0);
313
- }
314
- return fn(value);
315
- },
316
- filter(predicate) {
317
- if (value === null || value === void 0) {
318
- return chain(void 0);
319
- }
320
- return predicate(value) ? chain(value) : chain(void 0);
321
- },
322
- tap(fn) {
323
- if (value !== null && value !== void 0) {
324
- fn(value);
325
- }
326
- return chain(value);
327
- },
328
- value() {
329
- return value ?? void 0;
330
- },
331
- valueOr(defaultValue) {
332
- return value ?? defaultValue;
333
- },
334
- valueOrThrow(message) {
335
- if (value === null || value === void 0) {
336
- throw new Error(message ?? "Value is null or undefined");
337
- }
338
- return value;
339
- }
340
- };
341
- }
342
-
343
- // src/logic/optional.ts
344
- function optional(value, fn) {
345
- if (value === null || value === void 0) {
346
- return void 0;
347
- }
348
- return fn(value);
349
- }
350
- function optionalOr(value, fn, defaultValue) {
351
- if (value === null || value === void 0) {
352
- return defaultValue;
353
- }
354
- return fn(value);
355
- }
356
- function optionalChain(value, ...fns) {
357
- let current = value;
358
- for (const fn of fns) {
359
- if (current === null || current === void 0) {
360
- return void 0;
361
- }
362
- current = fn(current);
363
- }
364
- return current ?? void 0;
365
- }
366
-
367
- exports.allDefined = allDefined;
368
- exports.allTrue = allTrue;
369
- exports.allTruthy = allTruthy;
370
- exports.allWhere = allWhere;
371
- exports.and = and;
372
- exports.andThen = andThen;
373
- exports.anyTrue = anyTrue;
374
- exports.chain = chain;
375
- exports.coalesce = coalesce;
376
- exports.coalesceLazy = coalesceLazy;
377
- exports.cond = cond;
378
- exports.condBy = condBy;
379
- exports.condLazy = condLazy;
380
- exports.defaultTo = defaultTo;
381
- exports.defaultToIf = defaultToIf;
382
- exports.defaultToIfEmpty = defaultToIfEmpty;
383
- exports.defaultToLazy = defaultToLazy;
384
- exports.firstDefined = firstDefined;
385
- exports.firstTruthy = firstTruthy;
386
- exports.firstWhere = firstWhere;
387
- exports.get = get;
388
- exports.getOr = getOr;
389
- exports.getOrLazy = getOrLazy;
390
- exports.getPath = getPath;
391
- exports.getPathOr = getPathOr;
392
- exports.getTyped = getTyped;
393
- exports.ifElse = ifElse;
394
- exports.ifElseLazy = ifElseLazy;
395
- exports.matchLazy = matchLazy;
396
- exports.matchType = matchType;
397
- exports.matchValue = matchValue;
398
- exports.matchWithDefault = matchWithDefault;
399
- exports.not = not;
400
- exports.notFn = notFn;
401
- exports.optional = optional;
402
- exports.optionalChain = optionalChain;
403
- exports.optionalOr = optionalOr;
404
- exports.or = or;
405
- exports.orThen = orThen;
406
- exports.safe = safe;
407
- exports.tryGet = tryGet;
408
- exports.tryGetOr = tryGetOr;
409
- exports.tryGetResult = tryGetResult;
410
- exports.unless = unless;
411
- exports.unlessValue = unlessValue;
412
- exports.unwrap = unwrap;
413
- exports.when = when;
414
- exports.whenValue = whenValue;
8
+ Object.defineProperty(exports, "allDefined", {
9
+ enumerable: true,
10
+ get: function () { return chunk7G4ZSMQX_js.allDefined; }
11
+ });
12
+ Object.defineProperty(exports, "allTrue", {
13
+ enumerable: true,
14
+ get: function () { return chunk7G4ZSMQX_js.allTrue; }
15
+ });
16
+ Object.defineProperty(exports, "allTruthy", {
17
+ enumerable: true,
18
+ get: function () { return chunk7G4ZSMQX_js.allTruthy; }
19
+ });
20
+ Object.defineProperty(exports, "allWhere", {
21
+ enumerable: true,
22
+ get: function () { return chunk7G4ZSMQX_js.allWhere; }
23
+ });
24
+ Object.defineProperty(exports, "and", {
25
+ enumerable: true,
26
+ get: function () { return chunk7G4ZSMQX_js.and; }
27
+ });
28
+ Object.defineProperty(exports, "andThen", {
29
+ enumerable: true,
30
+ get: function () { return chunk7G4ZSMQX_js.andThen; }
31
+ });
32
+ Object.defineProperty(exports, "anyTrue", {
33
+ enumerable: true,
34
+ get: function () { return chunk7G4ZSMQX_js.anyTrue; }
35
+ });
36
+ Object.defineProperty(exports, "chain", {
37
+ enumerable: true,
38
+ get: function () { return chunk7G4ZSMQX_js.chain; }
39
+ });
40
+ Object.defineProperty(exports, "coalesce", {
41
+ enumerable: true,
42
+ get: function () { return chunk7G4ZSMQX_js.coalesce; }
43
+ });
44
+ Object.defineProperty(exports, "coalesceLazy", {
45
+ enumerable: true,
46
+ get: function () { return chunk7G4ZSMQX_js.coalesceLazy; }
47
+ });
48
+ Object.defineProperty(exports, "cond", {
49
+ enumerable: true,
50
+ get: function () { return chunk7G4ZSMQX_js.cond; }
51
+ });
52
+ Object.defineProperty(exports, "condBy", {
53
+ enumerable: true,
54
+ get: function () { return chunk7G4ZSMQX_js.condBy; }
55
+ });
56
+ Object.defineProperty(exports, "condLazy", {
57
+ enumerable: true,
58
+ get: function () { return chunk7G4ZSMQX_js.condLazy; }
59
+ });
60
+ Object.defineProperty(exports, "defaultTo", {
61
+ enumerable: true,
62
+ get: function () { return chunk7G4ZSMQX_js.defaultTo; }
63
+ });
64
+ Object.defineProperty(exports, "defaultToIf", {
65
+ enumerable: true,
66
+ get: function () { return chunk7G4ZSMQX_js.defaultToIf; }
67
+ });
68
+ Object.defineProperty(exports, "defaultToIfEmpty", {
69
+ enumerable: true,
70
+ get: function () { return chunk7G4ZSMQX_js.defaultToIfEmpty; }
71
+ });
72
+ Object.defineProperty(exports, "defaultToLazy", {
73
+ enumerable: true,
74
+ get: function () { return chunk7G4ZSMQX_js.defaultToLazy; }
75
+ });
76
+ Object.defineProperty(exports, "firstDefined", {
77
+ enumerable: true,
78
+ get: function () { return chunk7G4ZSMQX_js.firstDefined; }
79
+ });
80
+ Object.defineProperty(exports, "firstTruthy", {
81
+ enumerable: true,
82
+ get: function () { return chunk7G4ZSMQX_js.firstTruthy; }
83
+ });
84
+ Object.defineProperty(exports, "firstWhere", {
85
+ enumerable: true,
86
+ get: function () { return chunk7G4ZSMQX_js.firstWhere; }
87
+ });
88
+ Object.defineProperty(exports, "get", {
89
+ enumerable: true,
90
+ get: function () { return chunk7G4ZSMQX_js.get; }
91
+ });
92
+ Object.defineProperty(exports, "getOr", {
93
+ enumerable: true,
94
+ get: function () { return chunk7G4ZSMQX_js.getOr; }
95
+ });
96
+ Object.defineProperty(exports, "getOrLazy", {
97
+ enumerable: true,
98
+ get: function () { return chunk7G4ZSMQX_js.getOrLazy; }
99
+ });
100
+ Object.defineProperty(exports, "getPath", {
101
+ enumerable: true,
102
+ get: function () { return chunk7G4ZSMQX_js.getPath; }
103
+ });
104
+ Object.defineProperty(exports, "getPathOr", {
105
+ enumerable: true,
106
+ get: function () { return chunk7G4ZSMQX_js.getPathOr; }
107
+ });
108
+ Object.defineProperty(exports, "getTyped", {
109
+ enumerable: true,
110
+ get: function () { return chunk7G4ZSMQX_js.getTyped; }
111
+ });
112
+ Object.defineProperty(exports, "ifElse", {
113
+ enumerable: true,
114
+ get: function () { return chunk7G4ZSMQX_js.ifElse; }
115
+ });
116
+ Object.defineProperty(exports, "ifElseLazy", {
117
+ enumerable: true,
118
+ get: function () { return chunk7G4ZSMQX_js.ifElseLazy; }
119
+ });
120
+ Object.defineProperty(exports, "matchLazy", {
121
+ enumerable: true,
122
+ get: function () { return chunk7G4ZSMQX_js.matchLazy; }
123
+ });
124
+ Object.defineProperty(exports, "matchType", {
125
+ enumerable: true,
126
+ get: function () { return chunk7G4ZSMQX_js.matchType; }
127
+ });
128
+ Object.defineProperty(exports, "matchValue", {
129
+ enumerable: true,
130
+ get: function () { return chunk7G4ZSMQX_js.matchValue; }
131
+ });
132
+ Object.defineProperty(exports, "matchWithDefault", {
133
+ enumerable: true,
134
+ get: function () { return chunk7G4ZSMQX_js.matchWithDefault; }
135
+ });
136
+ Object.defineProperty(exports, "not", {
137
+ enumerable: true,
138
+ get: function () { return chunk7G4ZSMQX_js.not; }
139
+ });
140
+ Object.defineProperty(exports, "notFn", {
141
+ enumerable: true,
142
+ get: function () { return chunk7G4ZSMQX_js.notFn; }
143
+ });
144
+ Object.defineProperty(exports, "optional", {
145
+ enumerable: true,
146
+ get: function () { return chunk7G4ZSMQX_js.optional; }
147
+ });
148
+ Object.defineProperty(exports, "optionalChain", {
149
+ enumerable: true,
150
+ get: function () { return chunk7G4ZSMQX_js.optionalChain; }
151
+ });
152
+ Object.defineProperty(exports, "optionalOr", {
153
+ enumerable: true,
154
+ get: function () { return chunk7G4ZSMQX_js.optionalOr; }
155
+ });
156
+ Object.defineProperty(exports, "or", {
157
+ enumerable: true,
158
+ get: function () { return chunk7G4ZSMQX_js.or; }
159
+ });
160
+ Object.defineProperty(exports, "orThen", {
161
+ enumerable: true,
162
+ get: function () { return chunk7G4ZSMQX_js.orThen; }
163
+ });
164
+ Object.defineProperty(exports, "safe", {
165
+ enumerable: true,
166
+ get: function () { return chunk7G4ZSMQX_js.safe; }
167
+ });
168
+ Object.defineProperty(exports, "tryGet", {
169
+ enumerable: true,
170
+ get: function () { return chunk7G4ZSMQX_js.tryGet; }
171
+ });
172
+ Object.defineProperty(exports, "tryGetOr", {
173
+ enumerable: true,
174
+ get: function () { return chunk7G4ZSMQX_js.tryGetOr; }
175
+ });
176
+ Object.defineProperty(exports, "tryGetResult", {
177
+ enumerable: true,
178
+ get: function () { return chunk7G4ZSMQX_js.tryGetResult; }
179
+ });
180
+ Object.defineProperty(exports, "unless", {
181
+ enumerable: true,
182
+ get: function () { return chunk7G4ZSMQX_js.unless; }
183
+ });
184
+ Object.defineProperty(exports, "unlessValue", {
185
+ enumerable: true,
186
+ get: function () { return chunk7G4ZSMQX_js.unlessValue; }
187
+ });
188
+ Object.defineProperty(exports, "unwrap", {
189
+ enumerable: true,
190
+ get: function () { return chunk7G4ZSMQX_js.unwrap; }
191
+ });
192
+ Object.defineProperty(exports, "when", {
193
+ enumerable: true,
194
+ get: function () { return chunk7G4ZSMQX_js.when; }
195
+ });
196
+ Object.defineProperty(exports, "whenValue", {
197
+ enumerable: true,
198
+ get: function () { return chunk7G4ZSMQX_js.whenValue; }
199
+ });
415
200
  //# sourceMappingURL=index.js.map
416
201
  //# sourceMappingURL=index.js.map