n4s 3.1.0 → 4.0.0-dev-e266d9

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 (63) hide show
  1. package/CHANGELOG.md +129 -0
  2. package/LICENSE +1 -2
  3. package/README.md +2 -5
  4. package/compose/package.json +7 -0
  5. package/compounds/package.json +7 -0
  6. package/dist/cjs/compose.development.js +139 -0
  7. package/dist/cjs/compose.js +7 -0
  8. package/dist/cjs/compose.production.js +1 -0
  9. package/dist/cjs/compounds.development.js +132 -0
  10. package/dist/cjs/compounds.js +7 -0
  11. package/dist/cjs/compounds.production.js +1 -0
  12. package/dist/cjs/n4s.development.js +602 -0
  13. package/dist/cjs/n4s.js +7 -0
  14. package/dist/cjs/n4s.production.js +1 -0
  15. package/dist/cjs/package.json +1 -0
  16. package/dist/cjs/schema.development.js +144 -0
  17. package/dist/cjs/schema.js +7 -0
  18. package/dist/cjs/schema.production.js +1 -0
  19. package/dist/es/compose.development.js +137 -0
  20. package/dist/es/compose.production.js +1 -0
  21. package/dist/es/compounds.development.js +130 -0
  22. package/dist/es/compounds.production.js +1 -0
  23. package/dist/es/n4s.development.js +597 -0
  24. package/dist/es/n4s.production.js +1 -0
  25. package/dist/es/package.json +1 -0
  26. package/dist/es/schema.development.js +140 -0
  27. package/dist/es/schema.production.js +1 -0
  28. package/dist/umd/compose.development.js +143 -0
  29. package/dist/umd/compose.production.js +1 -0
  30. package/dist/umd/compounds.development.js +136 -0
  31. package/dist/umd/compounds.production.js +1 -0
  32. package/dist/umd/n4s.development.js +606 -0
  33. package/dist/umd/n4s.production.js +1 -0
  34. package/dist/umd/schema.development.js +148 -0
  35. package/dist/umd/schema.production.js +1 -0
  36. package/docs/README.md +2 -5
  37. package/docs/_sidebar.md +0 -1
  38. package/docs/external.md +1 -28
  39. package/package.json +129 -53
  40. package/schema/package.json +7 -0
  41. package/tsconfig.json +8 -0
  42. package/types/compose.d.ts +134 -0
  43. package/types/compounds.d.ts +146 -0
  44. package/types/n4s.d.ts +167 -0
  45. package/types/schema.d.ts +151 -0
  46. package/config/jest/jest.setup.js +0 -14
  47. package/config/rollup/enforce.js +0 -8
  48. package/config/rollup/rollup.config.js +0 -3
  49. package/docs/compound.md +0 -187
  50. package/docs/custom.md +0 -52
  51. package/docs/template.md +0 -53
  52. package/esm/n4s.es.development.js +0 -1142
  53. package/esm/n4s.es.production.js +0 -1142
  54. package/esm/n4s.es.production.min.js +0 -1
  55. package/esm/package.json +0 -1
  56. package/jest.config.js +0 -3
  57. package/n4s.cjs.development.js +0 -1144
  58. package/n4s.cjs.production.js +0 -1144
  59. package/n4s.cjs.production.min.js +0 -1
  60. package/n4s.js +0 -7
  61. package/n4s.umd.development.js +0 -1231
  62. package/n4s.umd.production.js +0 -1231
  63. package/n4s.umd.production.min.js +0 -1
@@ -0,0 +1,597 @@
1
+ import { createContext } from 'context';
2
+
3
+ var assign = Object.assign;
4
+
5
+ function isFunction(value) {
6
+ return typeof value === 'function';
7
+ }
8
+
9
+ function bindNot(fn) {
10
+ return function () {
11
+ var args = [];
12
+ for (var _i = 0; _i < arguments.length; _i++) {
13
+ args[_i] = arguments[_i];
14
+ }
15
+ return !fn.apply(void 0, args);
16
+ };
17
+ }
18
+
19
+ function isNull(value) {
20
+ return value === null;
21
+ }
22
+ var isNotNull = bindNot(isNull);
23
+
24
+ function isUndefined(value) {
25
+ return value === undefined;
26
+ }
27
+ var isNotUndefined = bindNot(isUndefined);
28
+
29
+ function isNullish(value) {
30
+ return isNull(value) || isUndefined(value);
31
+ }
32
+ var isNotNullish = bindNot(isNullish);
33
+
34
+ function isStringValue(v) {
35
+ return String(v) === v;
36
+ }
37
+
38
+ function endsWith(value, arg1) {
39
+ return isStringValue(value) && isStringValue(arg1) && value.endsWith(arg1);
40
+ }
41
+ var doesNotEndWith = bindNot(endsWith);
42
+
43
+ function equals(value, arg1) {
44
+ return value === arg1;
45
+ }
46
+ var notEquals = bindNot(equals);
47
+
48
+ function isNumeric(value) {
49
+ var str = String(value);
50
+ var num = Number(value);
51
+ var result = !isNaN(parseFloat(str)) && !isNaN(Number(value)) && isFinite(num);
52
+ return Boolean(result);
53
+ }
54
+ var isNotNumeric = bindNot(isNumeric);
55
+
56
+ function greaterThan(value, gt) {
57
+ return isNumeric(value) && isNumeric(gt) && Number(value) > Number(gt);
58
+ }
59
+
60
+ function greaterThanOrEquals(value, gte) {
61
+ return isNumeric(value) && isNumeric(gte) && Number(value) >= Number(gte);
62
+ }
63
+
64
+ // The module is named "isArrayValue" since it
65
+ // is conflicting with a nested npm dependency.
66
+ // We may need to revisit this in the future.
67
+ function isArray(value) {
68
+ return Boolean(Array.isArray(value));
69
+ }
70
+ var isNotArray = bindNot(isArray);
71
+
72
+ function inside(value, arg1) {
73
+ if (isArray(arg1)) {
74
+ return arg1.indexOf(value) !== -1;
75
+ }
76
+ // both value and arg1 are strings
77
+ if (isStringValue(arg1) && isStringValue(value)) {
78
+ return arg1.indexOf(value) !== -1;
79
+ }
80
+ return false;
81
+ }
82
+ var notInside = bindNot(inside);
83
+
84
+ function lessThanOrEquals(value, lte) {
85
+ return isNumeric(value) && isNumeric(lte) && Number(value) <= Number(lte);
86
+ }
87
+
88
+ function isBetween(value, min, max) {
89
+ return greaterThanOrEquals(value, min) && lessThanOrEquals(value, max);
90
+ }
91
+ var isNotBetween = bindNot(isBetween);
92
+
93
+ function isBlank(value) {
94
+ return isNullish(value) || (isStringValue(value) && !value.trim());
95
+ }
96
+ var isNotBlank = bindNot(isBlank);
97
+
98
+ function isBoolean(value) {
99
+ return !!value === value;
100
+ }
101
+
102
+ var isNotBoolean = bindNot(isBoolean);
103
+
104
+ /**
105
+ * A safe hasOwnProperty access
106
+ */
107
+ function hasOwnProperty(obj, key) {
108
+ return Object.prototype.hasOwnProperty.call(obj, key);
109
+ }
110
+
111
+ function isNumber(value) {
112
+ return Boolean(typeof value === 'number');
113
+ }
114
+ var isNotNumber = bindNot(isNumber);
115
+
116
+ function lengthEquals(value, arg1) {
117
+ return value.length === Number(arg1);
118
+ }
119
+ var lengthNotEquals = bindNot(lengthEquals);
120
+
121
+ function isEmpty(value) {
122
+ if (!value) {
123
+ return true;
124
+ }
125
+ else if (isNumber(value)) {
126
+ return value === 0;
127
+ }
128
+ else if (hasOwnProperty(value, 'length')) {
129
+ return lengthEquals(value, 0);
130
+ }
131
+ else if (typeof value === 'object') {
132
+ return lengthEquals(Object.keys(value), 0);
133
+ }
134
+ return true;
135
+ }
136
+ var isNotEmpty = bindNot(isEmpty);
137
+
138
+ /**
139
+ * Validates that a given value is an even number
140
+ */
141
+ var isEven = function (value) {
142
+ if (isNumeric(value)) {
143
+ return value % 2 === 0;
144
+ }
145
+ return false;
146
+ };
147
+
148
+ function isNaN$1(value) {
149
+ return Number.isNaN(value);
150
+ }
151
+ var isNotNaN = bindNot(isNaN$1);
152
+
153
+ function isNegative(value) {
154
+ if (isNumeric(value)) {
155
+ return Number(value) < 0;
156
+ }
157
+ return false;
158
+ }
159
+ var isPositive = bindNot(isNegative);
160
+
161
+ /**
162
+ * Validates that a given value is an odd number
163
+ */
164
+ var isOdd = function (value) {
165
+ if (isNumeric(value)) {
166
+ return value % 2 !== 0;
167
+ }
168
+ return false;
169
+ };
170
+
171
+ var isNotString = bindNot(isStringValue);
172
+
173
+ function isTruthy(value) {
174
+ return !!value;
175
+ }
176
+ var isFalsy = bindNot(isTruthy);
177
+
178
+ function lessThan(value, lt) {
179
+ return isNumeric(value) && isNumeric(lt) && Number(value) < Number(lt);
180
+ }
181
+
182
+ function longerThan(value, arg1) {
183
+ return value.length > Number(arg1);
184
+ }
185
+
186
+ function longerThanOrEquals(value, arg1) {
187
+ return value.length >= Number(arg1);
188
+ }
189
+
190
+ function matches(value, regex) {
191
+ if (regex instanceof RegExp) {
192
+ return regex.test(value);
193
+ }
194
+ else if (isStringValue(regex)) {
195
+ return new RegExp(regex).test(value);
196
+ }
197
+ else {
198
+ return false;
199
+ }
200
+ }
201
+ var notMatches = bindNot(matches);
202
+
203
+ function numberEquals(value, eq) {
204
+ return isNumeric(value) && isNumeric(eq) && Number(value) === Number(eq);
205
+ }
206
+ var numberNotEquals = bindNot(numberEquals);
207
+
208
+ function condition(value, callback) {
209
+ try {
210
+ return callback(value);
211
+ }
212
+ catch (_a) {
213
+ return false;
214
+ }
215
+ }
216
+
217
+ function shorterThan(value, arg1) {
218
+ return value.length < Number(arg1);
219
+ }
220
+
221
+ function shorterThanOrEquals(value, arg1) {
222
+ return value.length <= Number(arg1);
223
+ }
224
+
225
+ function startsWith(value, arg1) {
226
+ return isStringValue(value) && isStringValue(arg1) && value.startsWith(arg1);
227
+ }
228
+ var doesNotStartWith = bindNot(startsWith);
229
+
230
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, max-lines-per-function
231
+ function rules() {
232
+ return {
233
+ condition: condition,
234
+ doesNotEndWith: doesNotEndWith,
235
+ doesNotStartWith: doesNotStartWith,
236
+ endsWith: endsWith,
237
+ equals: equals,
238
+ greaterThan: greaterThan,
239
+ greaterThanOrEquals: greaterThanOrEquals,
240
+ gt: greaterThan,
241
+ gte: greaterThanOrEquals,
242
+ inside: inside,
243
+ isArray: isArray,
244
+ isBetween: isBetween,
245
+ isBlank: isBlank,
246
+ isBoolean: isBoolean,
247
+ isEmpty: isEmpty,
248
+ isEven: isEven,
249
+ isFalsy: isFalsy,
250
+ isNaN: isNaN$1,
251
+ isNegative: isNegative,
252
+ isNotArray: isNotArray,
253
+ isNotBetween: isNotBetween,
254
+ isNotBlank: isNotBlank,
255
+ isNotBoolean: isNotBoolean,
256
+ isNotEmpty: isNotEmpty,
257
+ isNotNaN: isNotNaN,
258
+ isNotNull: isNotNull,
259
+ isNotNullish: isNotNullish,
260
+ isNotNumber: isNotNumber,
261
+ isNotNumeric: isNotNumeric,
262
+ isNotString: isNotString,
263
+ isNotUndefined: isNotUndefined,
264
+ isNull: isNull,
265
+ isNullish: isNullish,
266
+ isNumber: isNumber,
267
+ isNumeric: isNumeric,
268
+ isOdd: isOdd,
269
+ isPositive: isPositive,
270
+ isString: isStringValue,
271
+ isTruthy: isTruthy,
272
+ isUndefined: isUndefined,
273
+ lengthEquals: lengthEquals,
274
+ lengthNotEquals: lengthNotEquals,
275
+ lessThan: lessThan,
276
+ lessThanOrEquals: lessThanOrEquals,
277
+ longerThan: longerThan,
278
+ longerThanOrEquals: longerThanOrEquals,
279
+ lt: lessThan,
280
+ lte: lessThanOrEquals,
281
+ matches: matches,
282
+ notEquals: notEquals,
283
+ notInside: notInside,
284
+ notMatches: notMatches,
285
+ numberEquals: numberEquals,
286
+ numberNotEquals: numberNotEquals,
287
+ shorterThan: shorterThan,
288
+ shorterThanOrEquals: shorterThanOrEquals,
289
+ startsWith: startsWith
290
+ };
291
+ }
292
+
293
+ var baseRules = rules();
294
+ function getRule(ruleName) {
295
+ return baseRules[ruleName];
296
+ }
297
+
298
+ function eachEnforceRule(action) {
299
+ for (var ruleName in baseRules) {
300
+ var ruleFn = getRule(ruleName);
301
+ if (isFunction(ruleFn)) {
302
+ action(ruleName, ruleFn);
303
+ }
304
+ }
305
+ }
306
+
307
+ var ctx = createContext(function (ctxRef, parentContext) {
308
+ var base = {
309
+ value: ctxRef.value,
310
+ meta: ctxRef.meta || {}
311
+ };
312
+ if (!parentContext) {
313
+ return assign(base, {
314
+ parent: emptyParent
315
+ });
316
+ }
317
+ else if (ctxRef.set) {
318
+ return assign(base, {
319
+ parent: function () { return stripContext(parentContext); }
320
+ });
321
+ }
322
+ return parentContext;
323
+ });
324
+ function stripContext(ctx) {
325
+ if (!ctx) {
326
+ return ctx;
327
+ }
328
+ return {
329
+ value: ctx.value,
330
+ meta: ctx.meta,
331
+ parent: ctx.parent
332
+ };
333
+ }
334
+ function emptyParent() {
335
+ return null;
336
+ }
337
+
338
+ /*! *****************************************************************************
339
+ Copyright (c) Microsoft Corporation.
340
+
341
+ Permission to use, copy, modify, and/or distribute this software for any
342
+ purpose with or without fee is hereby granted.
343
+
344
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
345
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
346
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
347
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
348
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
349
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
350
+ PERFORMANCE OF THIS SOFTWARE.
351
+ ***************************************************************************** */
352
+
353
+ function __spreadArray(to, from, pack) {
354
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
355
+ if (ar || !(i in from)) {
356
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
357
+ ar[i] = from[i];
358
+ }
359
+ }
360
+ return to.concat(ar || from);
361
+ }
362
+
363
+ function optionalFunctionValue(value) {
364
+ var args = [];
365
+ for (var _i = 1; _i < arguments.length; _i++) {
366
+ args[_i - 1] = arguments[_i];
367
+ }
368
+ return isFunction(value) ? value.apply(void 0, args) : value;
369
+ }
370
+
371
+ function defaultTo(callback, defaultValue) {
372
+ var _a;
373
+ return (_a = optionalFunctionValue(callback)) !== null && _a !== void 0 ? _a : defaultValue;
374
+ }
375
+
376
+ /**
377
+ * Throws a timed out error.
378
+ */
379
+ function throwError(devMessage, productionMessage) {
380
+ throw new Error(devMessage );
381
+ }
382
+
383
+ function isProxySupported() {
384
+ try {
385
+ return isFunction(Proxy);
386
+ }
387
+ catch (_a) {
388
+ return false;
389
+ }
390
+ }
391
+
392
+ function ruleReturn(pass, message) {
393
+ var output = { pass: pass };
394
+ if (message) {
395
+ output.message = message;
396
+ }
397
+ return output;
398
+ }
399
+ function passing() {
400
+ return ruleReturn(true);
401
+ }
402
+ function defaultToPassing(callback) {
403
+ return defaultTo(callback, passing());
404
+ }
405
+
406
+ /**
407
+ * Transform the result of a rule into a standard format
408
+ */
409
+ function transformResult(result, ruleName, value) {
410
+ var args = [];
411
+ for (var _i = 3; _i < arguments.length; _i++) {
412
+ args[_i - 3] = arguments[_i];
413
+ }
414
+ validateResult(result);
415
+ // if result is boolean
416
+ if (isBoolean(result)) {
417
+ return ruleReturn(result);
418
+ }
419
+ else {
420
+ return ruleReturn(result.pass, optionalFunctionValue.apply(void 0, __spreadArray([result.message, ruleName, value], args)));
421
+ }
422
+ }
423
+ function validateResult(result) {
424
+ // if result is boolean, or if result.pass is boolean
425
+ if (isBoolean(result) || (result && isBoolean(result.pass))) {
426
+ return;
427
+ }
428
+ throwError('Incorrect return value for rule: ' + JSON.stringify(result));
429
+ }
430
+
431
+ function enforceEager(value) {
432
+ var target = {};
433
+ if (!isProxySupported()) {
434
+ eachEnforceRule(function (ruleName, ruleFn) {
435
+ target[ruleName] = genRuleCall(target, ruleFn, ruleName);
436
+ });
437
+ return target;
438
+ }
439
+ var proxy = new Proxy(target, {
440
+ get: function (_, ruleName) {
441
+ var rule = getRule(ruleName);
442
+ if (rule) {
443
+ return genRuleCall(proxy, rule, ruleName);
444
+ }
445
+ }
446
+ });
447
+ return proxy;
448
+ function genRuleCall(target, rule, ruleName) {
449
+ return function ruleCall() {
450
+ var args = [];
451
+ for (var _i = 0; _i < arguments.length; _i++) {
452
+ args[_i] = arguments[_i];
453
+ }
454
+ var transformedResult = transformResult.apply(void 0, __spreadArray([ctx.run({ value: value }, function () { return rule.apply(void 0, __spreadArray([value], args)); }),
455
+ ruleName,
456
+ value], args));
457
+ if (!transformedResult.pass) {
458
+ if (isEmpty(transformedResult.message)) {
459
+ throwError("enforce/" + ruleName + " failed with " + JSON.stringify(value));
460
+ }
461
+ else {
462
+ // Explicitly throw a string so that vest.test can pick it up as the validation error message
463
+ throw transformedResult.message;
464
+ }
465
+ }
466
+ return target;
467
+ };
468
+ }
469
+ }
470
+
471
+ function mapFirst(array, callback) {
472
+ var broke = false;
473
+ var breakoutValue = null;
474
+ for (var i = 0; i < array.length; i++) {
475
+ callback(array[i], breakout, i);
476
+ if (broke) {
477
+ return breakoutValue;
478
+ }
479
+ }
480
+ function breakout(value) {
481
+ broke = true;
482
+ breakoutValue = value;
483
+ }
484
+ }
485
+
486
+ // eslint-disable-next-line max-lines-per-function
487
+ function genEnforceLazy(key) {
488
+ var registeredRules = [];
489
+ var lazyMessage;
490
+ return addLazyRule(key);
491
+ // eslint-disable-next-line max-lines-per-function
492
+ function addLazyRule(ruleName) {
493
+ // eslint-disable-next-line max-lines-per-function
494
+ return function () {
495
+ var args = [];
496
+ for (var _i = 0; _i < arguments.length; _i++) {
497
+ args[_i] = arguments[_i];
498
+ }
499
+ var rule = getRule(ruleName);
500
+ registeredRules.push(function (value) {
501
+ return transformResult.apply(void 0, __spreadArray([rule.apply(void 0, __spreadArray([value], args)), ruleName, value], args));
502
+ });
503
+ var proxy = {
504
+ run: function (value) {
505
+ return defaultToPassing(mapFirst(registeredRules, function (rule, breakout) {
506
+ var _a;
507
+ var res = ctx.run({ value: value }, function () { return rule(value); });
508
+ if (!res.pass) {
509
+ breakout(ruleReturn(!!res.pass, (_a = optionalFunctionValue(lazyMessage, value, res.message)) !== null && _a !== void 0 ? _a : res.message));
510
+ }
511
+ }));
512
+ },
513
+ test: function (value) { return proxy.run(value).pass; },
514
+ message: function (message) {
515
+ if (message) {
516
+ lazyMessage = message;
517
+ }
518
+ return proxy;
519
+ }
520
+ };
521
+ if (!isProxySupported()) {
522
+ eachEnforceRule(function (ruleName) {
523
+ proxy[ruleName] = addLazyRule(ruleName);
524
+ });
525
+ return proxy;
526
+ }
527
+ // reassigning the proxy here is not pretty
528
+ // but it's a cleaner way of getting `run` and `test` for free
529
+ proxy = new Proxy(proxy, {
530
+ get: function (target, key) {
531
+ if (getRule(key)) {
532
+ return addLazyRule(key);
533
+ }
534
+ return target[key]; // already has `run` and `test` on it
535
+ }
536
+ });
537
+ return proxy;
538
+ };
539
+ }
540
+ }
541
+
542
+ /**
543
+ * Enforce is quite complicated, I want to explain it in detail.
544
+ * It is dynamic in nature, so a lot of proxy objects are involved.
545
+ *
546
+ * Enforce has two main interfaces
547
+ * 1. eager
548
+ * 2. lazy
549
+ *
550
+ * The eager interface is the most commonly used, and the easier to understand.
551
+ * It throws an error when a rule is not satisfied.
552
+ * The eager interface is declared in enforceEager.ts and it is quite simple to understand.
553
+ * enforce is called with a value, and the return value is a proxy object that points back to all the rules.
554
+ * When a rule is called, the value is mapped as its first argument, and if the rule passes, the same
555
+ * proxy object is returned. Otherwise, an error is thrown.
556
+ *
557
+ * The lazy interface works quite differently. It is declared in genEnforceLazy.ts.
558
+ * Rather than calling enforce directly, the lazy interface has all the rules as "methods" (only by proxy).
559
+ * Calling the first function in the chain will initialize an array of calls. It stores the different rule calls
560
+ * and the parameters passed to them. None of the rules are called yet.
561
+ * The rules are only invoked in sequence once either of these chained functions are called:
562
+ * 1. test(value)
563
+ * 2. run(value)
564
+ *
565
+ * Calling run or test will call all the rules in sequence, with the difference that test will only return a boolean value,
566
+ * while run will return an object with the validation result and an optional message created by the rule.
567
+ */
568
+ function genEnforce() {
569
+ var target = {
570
+ context: function () { return ctx.useX(); },
571
+ extend: function (customRules) {
572
+ assign(baseRules, customRules);
573
+ }
574
+ };
575
+ if (!isProxySupported()) {
576
+ eachEnforceRule(function (ruleName) {
577
+ // Only on the first rule access - start the chain of calls
578
+ target[ruleName] = genEnforceLazy(ruleName);
579
+ });
580
+ return target;
581
+ }
582
+ return new Proxy(assign(enforceEager, target), {
583
+ get: function (target, key) {
584
+ if (key in target) {
585
+ return target[key];
586
+ }
587
+ if (!getRule(key)) {
588
+ return;
589
+ }
590
+ // Only on the first rule access - start the chain of calls
591
+ return genEnforceLazy(key);
592
+ }
593
+ });
594
+ }
595
+ var enforce = genEnforce();
596
+
597
+ export { ctx, enforce };
@@ -0,0 +1 @@
1
+ import{createContext as n}from"context";var r=Object.assign;function t(n){return"function"==typeof n}function e(n){return function(){for(var r=[],t=0;t<arguments.length;t++)r[t]=arguments[t];return!n.apply(void 0,r)}}function u(n){return null===n}var i=e(u);function o(n){return void 0===n}var a=e(o);function s(n){return null===n||o(n)}var f=e(s);function c(n){return String(n)===n}function l(n,r){return c(n)&&c(r)&&n.endsWith(r)}var v=e(l);function N(n,r){return n===r}var h=e(N);function m(n){var r=Number(n);return!(isNaN(parseFloat(String(n)))||isNaN(Number(n))||!isFinite(r))}var g=e(m);function p(n,r){return m(n)&&m(r)&&Number(n)>Number(r)}function y(n,r){return m(n)&&m(r)&&Number(n)>=Number(r)}function b(n){return!!Array.isArray(n)}var d=e(b);function E(n,r){return!!(b(r)||c(r)&&c(n))&&-1!==r.indexOf(n)}var x=e(E);function O(n,r){return m(n)&&m(r)&&Number(n)<=Number(r)}function q(n,r,t){return y(n,r)&&O(n,t)}var w=e(q);function T(n){return s(n)||c(n)&&!n.trim()}var S=e(T);function B(n){return!!n===n}var P=e(B);function W(n){return"number"==typeof n}var A=e(W);function j(n,r){return n.length===Number(r)}var k=e(j);function F(n){if(n){if(W(n))return 0===n;if(Object.prototype.hasOwnProperty.call(n,"length"))return j(n,0);if("object"==typeof n)return j(Object.keys(n),0)}return!0}var I=e(F);function J(n){return Number.isNaN(n)}var R=e(J);function U(n){return!!m(n)&&0>Number(n)}var M=e(U),X=e(c);function z(n){return!!n}var C=e(z);function D(n,r){return m(n)&&m(r)&&Number(n)<Number(r)}function G(n,r){return r instanceof RegExp?r.test(n):!!c(r)&&new RegExp(r).test(n)}var H=e(G);function K(n,r){return m(n)&&m(r)&&Number(n)===Number(r)}var L=e(K);function Q(n,r){return c(n)&&c(r)&&n.startsWith(r)}var V={condition:function(n,r){try{return r(n)}catch(n){return!1}},doesNotEndWith:v,doesNotStartWith:e(Q),endsWith:l,equals:N,greaterThan:p,greaterThanOrEquals:y,gt:p,gte:y,inside:E,isArray:b,isBetween:q,isBlank:T,isBoolean:B,isEmpty:F,isEven:function(n){return!!m(n)&&0==n%2},isFalsy:C,isNaN:J,isNegative:U,isNotArray:d,isNotBetween:w,isNotBlank:S,isNotBoolean:P,isNotEmpty:I,isNotNaN:R,isNotNull:i,isNotNullish:f,isNotNumber:A,isNotNumeric:g,isNotString:X,isNotUndefined:a,isNull:u,isNullish:s,isNumber:W,isNumeric:m,isOdd:function(n){return!!m(n)&&0!=n%2},isPositive:M,isString:c,isTruthy:z,isUndefined:o,lengthEquals:j,lengthNotEquals:k,lessThan:D,lessThanOrEquals:O,longerThan:function(n,r){return n.length>Number(r)},longerThanOrEquals:function(n,r){return n.length>=Number(r)},lt:D,lte:O,matches:G,notEquals:h,notInside:x,notMatches:H,numberEquals:K,numberNotEquals:L,shorterThan:function(n,r){return n.length<Number(r)},shorterThanOrEquals:function(n,r){return n.length<=Number(r)},startsWith:Q};function Y(n){for(var r in V){var e=V[r];t(e)&&n(r,e)}}var Z=n((function(n,t){var e={value:n.value,meta:n.meta||{}};return t?n.set?r(e,{parent:function(){return t?{value:t.value,meta:t.meta,parent:t.parent}:t}}):t:r(e,{parent:$})}));function $(){return null}function _(n,r,t){if(t||2===arguments.length)for(var e,u=0,i=r.length;u<i;u++)!e&&u in r||(e||(e=Array.prototype.slice.call(r,0,u)),e[u]=r[u]);return n.concat(e||r)}function nn(n){for(var r=[],e=1;e<arguments.length;e++)r[e-1]=arguments[e];return t(n)?n.apply(void 0,r):n}function rn(n,r){var t;return null!==(t=nn(n))&&void 0!==t?t:r}function tn(n,r){throw Error(rn(r,n))}function en(){try{return t(Proxy)}catch(n){return!1}}function un(n,r){return n={pass:n},r&&(n.message=r),n}function on(n,r,t){for(var e=[],u=3;u<arguments.length;u++)e[u-3]=arguments[u];return B(n)||n&&B(n.pass)||tn("Incorrect return value for rule: "+JSON.stringify(n)),B(n)?un(n):un(n.pass,nn.apply(void 0,_([n.message,r,t],e)))}function an(n){function r(r,t,e){return function(){for(var u=[],i=0;i<arguments.length;i++)u[i]=arguments[i];if(!(i=on.apply(void 0,_([Z.run({value:n},(function(){return t.apply(void 0,_([n],u))})),e,n],u))).pass){if(!F(i.message))throw i.message;tn("enforce/"+e+" failed with "+JSON.stringify(n))}return r}}var t={};if(!en())return Y((function(n,e){t[n]=r(t,e,n)})),t;var e=new Proxy(t,{get:function(n,t){if(n=V[t])return r(e,n,t)}});return e}function sn(n,r){function t(n){e=!0,u=n}for(var e=!1,u=null,i=0;i<n.length;i++)if(r(n[i],t,i),e)return u}function fn(n){var r,t=[];return function n(e){return function(){for(var u=[],i=0;i<arguments.length;i++)u[i]=arguments[i];var o=V[e];t.push((function(n){return on.apply(void 0,_([o.apply(void 0,_([n],u)),e,n],u))}));var a={run:function(n){return rn(sn(t,(function(t,e){var u,i=Z.run({value:n},(function(){return t(n)}));i.pass||e(un(!!i.pass,null!==(u=nn(r,n,i.message))&&void 0!==u?u:i.message))})),un(!0))},test:function(n){return a.run(n).pass},message:function(n){return n&&(r=n),a}};return en()?a=new Proxy(a,{get:function(r,t){return V[t]?n(t):r[t]}}):(Y((function(r){a[r]=n(r)})),a)}}(n)}var cn,ln=(cn={context:function(){return Z.useX()},extend:function(n){r(V,n)}},en()?new Proxy(r(an,cn),{get:function(n,r){return r in n?n[r]:V[r]?fn(r):void 0}}):(Y((function(n){cn[n]=fn(n)})),cn));export{Z as ctx,ln as enforce};
@@ -0,0 +1 @@
1
+ {"type":"module"}