n4s 3.0.0 → 4.0.0-dev-1aae50

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