n4s 5.0.0 → 5.0.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.
Files changed (70) hide show
  1. package/README.md +2 -0
  2. package/date/package.json +9 -0
  3. package/dist/cjs/compose.development.js +9 -13
  4. package/dist/cjs/compose.js +0 -1
  5. package/dist/cjs/compose.production.js +1 -1
  6. package/dist/cjs/compounds.development.js +16 -32
  7. package/dist/cjs/compounds.js +0 -1
  8. package/dist/cjs/compounds.production.js +1 -1
  9. package/dist/cjs/date.development.js +186 -0
  10. package/dist/cjs/date.js +6 -0
  11. package/dist/cjs/date.production.js +1 -0
  12. package/dist/cjs/email.development.js +363 -0
  13. package/dist/cjs/email.js +6 -0
  14. package/dist/cjs/email.production.js +1 -0
  15. package/dist/cjs/isURL.development.js +353 -0
  16. package/dist/cjs/isURL.js +6 -0
  17. package/dist/cjs/isURL.production.js +1 -0
  18. package/dist/cjs/n4s.development.js +134 -213
  19. package/dist/cjs/n4s.js +0 -1
  20. package/dist/cjs/n4s.production.js +1 -1
  21. package/dist/cjs/schema.development.js +13 -22
  22. package/dist/cjs/schema.js +0 -1
  23. package/dist/cjs/schema.production.js +1 -1
  24. package/dist/es/compose.development.js +11 -15
  25. package/dist/es/compose.production.js +1 -1
  26. package/dist/es/compounds.development.js +16 -32
  27. package/dist/es/compounds.production.js +1 -1
  28. package/dist/es/date.development.js +184 -0
  29. package/dist/es/date.production.js +1 -0
  30. package/dist/es/email.development.js +361 -0
  31. package/dist/es/email.production.js +1 -0
  32. package/dist/es/isURL.development.js +351 -0
  33. package/dist/es/isURL.production.js +1 -0
  34. package/dist/es/n4s.development.js +155 -232
  35. package/dist/es/n4s.production.js +1 -1
  36. package/dist/es/schema.development.js +13 -20
  37. package/dist/es/schema.production.js +1 -1
  38. package/dist/umd/compose.development.js +12 -16
  39. package/dist/umd/compose.production.js +1 -1
  40. package/dist/umd/compounds.development.js +19 -35
  41. package/dist/umd/compounds.production.js +1 -1
  42. package/dist/umd/date.development.js +190 -0
  43. package/dist/umd/date.production.js +1 -0
  44. package/dist/umd/email.development.js +367 -0
  45. package/dist/umd/email.production.js +1 -0
  46. package/dist/umd/isURL.development.js +357 -0
  47. package/dist/umd/isURL.production.js +1 -0
  48. package/dist/umd/n4s.development.js +137 -216
  49. package/dist/umd/n4s.production.js +1 -1
  50. package/dist/umd/schema.development.js +16 -25
  51. package/dist/umd/schema.production.js +1 -1
  52. package/email/package.json +9 -0
  53. package/isURL/package.json +9 -0
  54. package/package.json +159 -55
  55. package/testUtils/TEnforceMock.ts +3 -0
  56. package/types/compose.d.ts +22 -23
  57. package/types/compose.d.ts.map +1 -0
  58. package/types/compounds.d.ts +22 -24
  59. package/types/compounds.d.ts.map +1 -0
  60. package/types/date.d.ts +18 -0
  61. package/types/date.d.ts.map +1 -0
  62. package/types/email.d.ts +12 -0
  63. package/types/email.d.ts.map +1 -0
  64. package/types/isURL.d.ts +12 -0
  65. package/types/isURL.d.ts.map +1 -0
  66. package/types/n4s.d.ts +30 -27
  67. package/types/n4s.d.ts.map +1 -0
  68. package/types/schema.d.ts +22 -23
  69. package/types/schema.d.ts.map +1 -0
  70. package/tsconfig.json +0 -8
@@ -1,18 +1,46 @@
1
1
  (function (global, factory) {
2
2
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vest-utils'), require('context')) :
3
3
  typeof define === 'function' && define.amd ? define(['exports', 'vest-utils', 'context'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.n4s = {}, global['vest-utils'], global.context));
5
- }(this, (function (exports, vestUtils, context) { 'use strict';
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.n4s = {}, global["vest-utils"], global.context));
5
+ })(this, (function (exports, vestUtils, context) { 'use strict';
6
+
7
+ const ctx = context.createCascade((ctxRef, parentContext) => {
8
+ const base = {
9
+ value: ctxRef.value,
10
+ meta: ctxRef.meta || {},
11
+ };
12
+ if (!parentContext) {
13
+ return vestUtils.assign(base, {
14
+ parent: emptyParent,
15
+ });
16
+ }
17
+ else if (ctxRef.set) {
18
+ return vestUtils.assign(base, {
19
+ parent: () => stripContext(parentContext),
20
+ });
21
+ }
22
+ return parentContext;
23
+ });
24
+ function stripContext(ctx) {
25
+ return {
26
+ value: ctx.value,
27
+ meta: ctx.meta,
28
+ parent: ctx.parent,
29
+ };
30
+ }
31
+ function emptyParent() {
32
+ return null;
33
+ }
6
34
 
7
35
  function endsWith(value, arg1) {
8
36
  return vestUtils.isStringValue(value) && vestUtils.isStringValue(arg1) && value.endsWith(arg1);
9
37
  }
10
- var doesNotEndWith = vestUtils.bindNot(endsWith);
38
+ const doesNotEndWith = vestUtils.bindNot(endsWith);
11
39
 
12
40
  function equals(value, arg1) {
13
41
  return value === arg1;
14
42
  }
15
- var notEquals = vestUtils.bindNot(equals);
43
+ const notEquals = vestUtils.bindNot(equals);
16
44
 
17
45
  function greaterThanOrEquals(value, gte) {
18
46
  return vestUtils.numberEquals(value, gte) || vestUtils.greaterThan(value, gte);
@@ -28,7 +56,7 @@
28
56
  }
29
57
  return false;
30
58
  }
31
- var notInside = vestUtils.bindNot(inside);
59
+ const notInside = vestUtils.bindNot(inside);
32
60
 
33
61
  function lessThan(value, lt) {
34
62
  return vestUtils.isNumeric(value) && vestUtils.isNumeric(lt) && Number(value) < Number(lt);
@@ -41,19 +69,19 @@
41
69
  function isBetween(value, min, max) {
42
70
  return greaterThanOrEquals(value, min) && lessThanOrEquals(value, max);
43
71
  }
44
- var isNotBetween = vestUtils.bindNot(isBetween);
72
+ const isNotBetween = vestUtils.bindNot(isBetween);
45
73
 
46
74
  function isBlank(value) {
47
75
  return vestUtils.isNullish(value) || (vestUtils.isStringValue(value) && !value.trim());
48
76
  }
49
- var isNotBlank = vestUtils.bindNot(isBlank);
77
+ const isNotBlank = vestUtils.bindNot(isBlank);
50
78
 
51
- var isNotBoolean = vestUtils.bindNot(vestUtils.isBoolean);
79
+ const isNotBoolean = vestUtils.bindNot(vestUtils.isBoolean);
52
80
 
53
81
  /**
54
82
  * Validates that a given value is an even number
55
83
  */
56
- var isEven = function (value) {
84
+ const isEven = (value) => {
57
85
  if (vestUtils.isNumeric(value)) {
58
86
  return value % 2 === 0;
59
87
  }
@@ -63,12 +91,12 @@
63
91
  function isKeyOf(key, obj) {
64
92
  return key in obj;
65
93
  }
66
- var isNotKeyOf = vestUtils.bindNot(isKeyOf);
94
+ const isNotKeyOf = vestUtils.bindNot(isKeyOf);
67
95
 
68
96
  function isNaN(value) {
69
97
  return Number.isNaN(value);
70
98
  }
71
- var isNotNaN = vestUtils.bindNot(isNaN);
99
+ const isNotNaN = vestUtils.bindNot(isNaN);
72
100
 
73
101
  function isNegative(value) {
74
102
  return lessThan(value, 0);
@@ -77,37 +105,37 @@
77
105
  function isNumber(value) {
78
106
  return Boolean(typeof value === 'number');
79
107
  }
80
- var isNotNumber = vestUtils.bindNot(isNumber);
108
+ const isNotNumber = vestUtils.bindNot(isNumber);
81
109
 
82
110
  /**
83
111
  * Validates that a given value is an odd number
84
112
  */
85
- var isOdd = function (value) {
113
+ const isOdd = (value) => {
86
114
  if (vestUtils.isNumeric(value)) {
87
115
  return value % 2 !== 0;
88
116
  }
89
117
  return false;
90
118
  };
91
119
 
92
- var isNotString = vestUtils.bindNot(vestUtils.isStringValue);
120
+ const isNotString = vestUtils.bindNot(vestUtils.isStringValue);
93
121
 
94
122
  function isTruthy(value) {
95
123
  return !!value;
96
124
  }
97
- var isFalsy = vestUtils.bindNot(isTruthy);
125
+ const isFalsy = vestUtils.bindNot(isTruthy);
98
126
 
99
127
  function isValueOf(value, objectToCheck) {
100
128
  if (vestUtils.isNullish(objectToCheck)) {
101
129
  return false;
102
130
  }
103
- for (var key in objectToCheck) {
131
+ for (const key in objectToCheck) {
104
132
  if (objectToCheck[key] === value) {
105
133
  return true;
106
134
  }
107
135
  }
108
136
  return false;
109
137
  }
110
- var isNotValueOf = vestUtils.bindNot(isValueOf);
138
+ const isNotValueOf = vestUtils.bindNot(isValueOf);
111
139
 
112
140
  function longerThanOrEquals(value, arg1) {
113
141
  return greaterThanOrEquals(value.length, arg1);
@@ -120,11 +148,9 @@
120
148
  else if (vestUtils.isStringValue(regex)) {
121
149
  return new RegExp(regex).test(value);
122
150
  }
123
- else {
124
- return false;
125
- }
151
+ return false;
126
152
  }
127
- var notMatches = vestUtils.bindNot(matches);
153
+ const notMatches = vestUtils.bindNot(matches);
128
154
 
129
155
  function condition(value, callback) {
130
156
  try {
@@ -146,156 +172,82 @@
146
172
  function startsWith(value, arg1) {
147
173
  return vestUtils.isStringValue(value) && vestUtils.isStringValue(arg1) && value.startsWith(arg1);
148
174
  }
149
- var doesNotStartWith = vestUtils.bindNot(startsWith);
175
+ const doesNotStartWith = vestUtils.bindNot(startsWith);
150
176
 
151
177
  // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, max-lines-per-function
152
178
  function rules() {
153
179
  return {
154
- condition: condition,
155
- doesNotEndWith: doesNotEndWith,
156
- doesNotStartWith: doesNotStartWith,
157
- endsWith: endsWith,
158
- equals: equals,
180
+ condition,
181
+ doesNotEndWith,
182
+ doesNotStartWith,
183
+ endsWith,
184
+ equals,
159
185
  greaterThan: vestUtils.greaterThan,
160
- greaterThanOrEquals: greaterThanOrEquals,
186
+ greaterThanOrEquals,
161
187
  gt: vestUtils.greaterThan,
162
188
  gte: greaterThanOrEquals,
163
- inside: inside,
189
+ inside,
164
190
  isArray: vestUtils.isArray,
165
- isBetween: isBetween,
166
- isBlank: isBlank,
191
+ isBetween,
192
+ isBlank,
167
193
  isBoolean: vestUtils.isBoolean,
168
194
  isEmpty: vestUtils.isEmpty,
169
- isEven: isEven,
170
- isFalsy: isFalsy,
171
- isKeyOf: isKeyOf,
172
- isNaN: isNaN,
173
- isNegative: isNegative,
195
+ isEven,
196
+ isFalsy,
197
+ isKeyOf,
198
+ isNaN,
199
+ isNegative,
174
200
  isNotArray: vestUtils.isNotArray,
175
- isNotBetween: isNotBetween,
176
- isNotBlank: isNotBlank,
177
- isNotBoolean: isNotBoolean,
201
+ isNotBetween,
202
+ isNotBlank,
203
+ isNotBoolean,
178
204
  isNotEmpty: vestUtils.isNotEmpty,
179
- isNotKeyOf: isNotKeyOf,
180
- isNotNaN: isNotNaN,
205
+ isNotKeyOf,
206
+ isNotNaN,
181
207
  isNotNull: vestUtils.isNotNull,
182
208
  isNotNullish: vestUtils.isNotNullish,
183
- isNotNumber: isNotNumber,
209
+ isNotNumber,
184
210
  isNotNumeric: vestUtils.isNotNumeric,
185
- isNotString: isNotString,
211
+ isNotString,
186
212
  isNotUndefined: vestUtils.isNotUndefined,
187
- isNotValueOf: isNotValueOf,
213
+ isNotValueOf,
188
214
  isNull: vestUtils.isNull,
189
215
  isNullish: vestUtils.isNullish,
190
- isNumber: isNumber,
216
+ isNumber,
191
217
  isNumeric: vestUtils.isNumeric,
192
- isOdd: isOdd,
218
+ isOdd,
193
219
  isPositive: vestUtils.isPositive,
194
220
  isString: vestUtils.isStringValue,
195
- isTruthy: isTruthy,
221
+ isTruthy,
196
222
  isUndefined: vestUtils.isUndefined,
197
- isValueOf: isValueOf,
223
+ isValueOf,
198
224
  lengthEquals: vestUtils.lengthEquals,
199
225
  lengthNotEquals: vestUtils.lengthNotEquals,
200
- lessThan: lessThan,
201
- lessThanOrEquals: lessThanOrEquals,
226
+ lessThan,
227
+ lessThanOrEquals,
202
228
  longerThan: vestUtils.longerThan,
203
- longerThanOrEquals: longerThanOrEquals,
229
+ longerThanOrEquals,
204
230
  lt: lessThan,
205
231
  lte: lessThanOrEquals,
206
- matches: matches,
207
- notEquals: notEquals,
208
- notInside: notInside,
209
- notMatches: notMatches,
232
+ matches,
233
+ notEquals,
234
+ notInside,
235
+ notMatches,
210
236
  numberEquals: vestUtils.numberEquals,
211
237
  numberNotEquals: vestUtils.numberNotEquals,
212
- shorterThan: shorterThan,
213
- shorterThanOrEquals: shorterThanOrEquals,
214
- startsWith: startsWith
238
+ shorterThan,
239
+ shorterThanOrEquals,
240
+ startsWith,
215
241
  };
216
242
  }
217
243
 
218
- var baseRules = rules();
244
+ const baseRules = rules();
219
245
  function getRule(ruleName) {
220
246
  return baseRules[ruleName];
221
247
  }
222
248
 
223
- function eachEnforceRule(action) {
224
- for (var ruleName in baseRules) {
225
- var ruleFn = getRule(ruleName);
226
- if (vestUtils.isFunction(ruleFn)) {
227
- action(ruleName, ruleFn);
228
- }
229
- }
230
- }
231
-
232
- var ctx = context.createCascade(function (ctxRef, parentContext) {
233
- var base = {
234
- value: ctxRef.value,
235
- meta: ctxRef.meta || {}
236
- };
237
- if (!parentContext) {
238
- return vestUtils.assign(base, {
239
- parent: emptyParent
240
- });
241
- }
242
- else if (ctxRef.set) {
243
- return vestUtils.assign(base, {
244
- parent: function () { return stripContext(parentContext); }
245
- });
246
- }
247
- return parentContext;
248
- });
249
- function stripContext(ctx) {
250
- if (!ctx) {
251
- return ctx;
252
- }
253
- return {
254
- value: ctx.value,
255
- meta: ctx.meta,
256
- parent: ctx.parent
257
- };
258
- }
259
- function emptyParent() {
260
- return null;
261
- }
262
-
263
- /******************************************************************************
264
- Copyright (c) Microsoft Corporation.
265
-
266
- Permission to use, copy, modify, and/or distribute this software for any
267
- purpose with or without fee is hereby granted.
268
-
269
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
270
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
271
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
272
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
273
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
274
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
275
- PERFORMANCE OF THIS SOFTWARE.
276
- ***************************************************************************** */
277
-
278
- function __spreadArray(to, from, pack) {
279
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
280
- if (ar || !(i in from)) {
281
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
282
- ar[i] = from[i];
283
- }
284
- }
285
- return to.concat(ar || Array.prototype.slice.call(from));
286
- }
287
-
288
- function isProxySupported() {
289
- try {
290
- return vestUtils.isFunction(Proxy);
291
- }
292
- catch (_a) {
293
- return false;
294
- }
295
- }
296
-
297
249
  function ruleReturn(pass, message) {
298
- var output = { pass: pass };
250
+ const output = { pass };
299
251
  if (message) {
300
252
  output.message = message;
301
253
  }
@@ -311,124 +263,106 @@
311
263
  /**
312
264
  * Transform the result of a rule into a standard format
313
265
  */
314
- function transformResult(result, ruleName, value) {
315
- var args = [];
316
- for (var _i = 3; _i < arguments.length; _i++) {
317
- args[_i - 3] = arguments[_i];
318
- }
266
+ function transformResult(result, ruleName, value, ...args) {
319
267
  validateResult(result);
320
268
  // if result is boolean
321
269
  if (vestUtils.isBoolean(result)) {
322
270
  return ruleReturn(result);
323
271
  }
324
- else {
325
- return ruleReturn(result.pass, vestUtils.optionalFunctionValue.apply(void 0, __spreadArray([result.message, ruleName, value], args, false)));
326
- }
272
+ return ruleReturn(result.pass, vestUtils.optionalFunctionValue(result.message, ruleName, value, ...args));
327
273
  }
328
274
  function validateResult(result) {
329
275
  // if result is boolean, or if result.pass is boolean
330
276
  vestUtils.invariant(vestUtils.isBoolean(result) || (result && vestUtils.isBoolean(result.pass)), 'Incorrect return value for rule: ' + JSON.stringify(result));
331
277
  }
332
278
 
279
+ // eslint-disable-next-line max-lines-per-function
333
280
  function enforceEager(value) {
334
- var target = {};
335
- // This condition is for when we don't have proxy support (ES5).
336
- // In this case, we need to manually assign the rules to the target object on runtime.
337
- // The follow up proxy block is used in case we do have proxy support, and we can assign each rule upon invocation.
338
- if (!isProxySupported()) {
339
- // We iterate over each of the rules, and add them to the target object being return by enforce
340
- eachEnforceRule(function (ruleName, ruleFn) {
341
- // We then wrap the rule with `genRuleCall` that adds the base enforce behavior
342
- target[ruleName] = genRuleCall(target, ruleFn, ruleName);
343
- });
344
- return target;
345
- }
281
+ const target = {
282
+ message,
283
+ };
284
+ let customMessage = undefined;
346
285
  // We create a proxy intercepting access to the target object (which is empty).
347
- var proxy = new Proxy(target, {
348
- get: function (_, ruleName) {
286
+ const proxy = new Proxy(target, {
287
+ get: (_, key) => {
349
288
  // On property access, we identify if it is a rule or not.
350
- var rule = getRule(ruleName);
289
+ const rule = getRule(key);
351
290
  // If it is a rule, we wrap it with `genRuleCall` that adds the base enforce behavior
352
291
  if (rule) {
353
- return genRuleCall(proxy, rule, ruleName);
292
+ return genRuleCall(proxy, rule, key);
354
293
  }
355
- }
294
+ return target[key];
295
+ },
356
296
  });
357
297
  return proxy;
358
298
  // This function is used to wrap a rule with the base enforce behavior
359
299
  // It takes the target object, the rule function, and the rule name
360
300
  // It then returns the rule, in a manner that can be used by enforce
361
301
  function genRuleCall(target, rule, ruleName) {
362
- return function ruleCall() {
363
- var args = [];
364
- for (var _i = 0; _i < arguments.length; _i++) {
365
- args[_i] = arguments[_i];
366
- }
302
+ return function ruleCall(...args) {
367
303
  // Order of operation:
368
304
  // 1. Create a context with the value being enforced
369
305
  // 2. Call the rule within the context, and pass over the arguments passed to it
370
306
  // 3. Transform the result to the correct output format
371
- var transformedResult = ctx.run({ value: value }, function () {
372
- return transformResult.apply(void 0, __spreadArray([rule.apply(void 0, __spreadArray([value], args, false)), ruleName, value], args, false));
307
+ const transformedResult = ctx.run({ value }, () => {
308
+ return transformResult(rule(value, ...args), ruleName, value, ...args);
373
309
  });
310
+ function enforceMessage() {
311
+ if (!vestUtils.isNullish(customMessage))
312
+ return vestUtils.StringObject(customMessage);
313
+ if (vestUtils.isNullish(transformedResult.message)) {
314
+ return `enforce/${ruleName} failed with ${JSON.stringify(value)}`;
315
+ }
316
+ return vestUtils.StringObject(transformedResult.message);
317
+ }
374
318
  // On rule failure (the result is false), we either throw an error
375
319
  // or throw a string value if the rule has a message defined in it.
376
- vestUtils.invariant(transformedResult.pass, vestUtils.isNullish(transformedResult.message)
377
- ? "enforce/".concat(ruleName, " failed with ").concat(JSON.stringify(value))
378
- : vestUtils.StringObject(transformedResult.message));
320
+ vestUtils.invariant(transformedResult.pass, enforceMessage());
379
321
  return target;
380
322
  };
381
323
  }
324
+ function message(input) {
325
+ customMessage = input;
326
+ return proxy;
327
+ }
382
328
  }
383
329
 
384
330
  // eslint-disable-next-line max-lines-per-function
385
331
  function genEnforceLazy(key) {
386
- var registeredRules = [];
387
- var lazyMessage;
332
+ const registeredRules = [];
333
+ let lazyMessage;
388
334
  return addLazyRule(key);
389
335
  // eslint-disable-next-line max-lines-per-function
390
336
  function addLazyRule(ruleName) {
391
337
  // eslint-disable-next-line max-lines-per-function
392
- return function () {
393
- var args = [];
394
- for (var _i = 0; _i < arguments.length; _i++) {
395
- args[_i] = arguments[_i];
396
- }
397
- var rule = getRule(ruleName);
398
- registeredRules.push(function (value) {
399
- return transformResult.apply(void 0, __spreadArray([rule.apply(void 0, __spreadArray([value], args, false)), ruleName, value], args, false));
400
- });
401
- var proxy = {
402
- run: function (value) {
403
- return defaultToPassing(vestUtils.mapFirst(registeredRules, function (rule, breakout) {
338
+ return (...args) => {
339
+ const rule = getRule(ruleName);
340
+ registeredRules.push((value) => transformResult(rule(value, ...args), ruleName, value, ...args));
341
+ let proxy = {
342
+ run: (value) => {
343
+ return defaultToPassing(vestUtils.mapFirst(registeredRules, (rule, breakout) => {
404
344
  var _a;
405
- var res = ctx.run({ value: value }, function () { return rule(value); });
345
+ const res = ctx.run({ value }, () => rule(value));
406
346
  breakout(!res.pass, ruleReturn(!!res.pass, (_a = vestUtils.optionalFunctionValue(lazyMessage, value, res.message)) !== null && _a !== void 0 ? _a : res.message));
407
347
  }));
408
348
  },
409
- test: function (value) { return proxy.run(value).pass; },
410
- message: function (message) {
349
+ test: (value) => proxy.run(value).pass,
350
+ message: (message) => {
411
351
  if (message) {
412
352
  lazyMessage = message;
413
353
  }
414
354
  return proxy;
415
- }
355
+ },
416
356
  };
417
- if (!isProxySupported()) {
418
- eachEnforceRule(function (ruleName) {
419
- proxy[ruleName] = addLazyRule(ruleName);
420
- });
421
- return proxy;
422
- }
423
357
  // reassigning the proxy here is not pretty
424
358
  // but it's a cleaner way of getting `run` and `test` for free
425
359
  proxy = new Proxy(proxy, {
426
- get: function (target, key) {
360
+ get: (target, key) => {
427
361
  if (getRule(key)) {
428
362
  return addLazyRule(key);
429
363
  }
430
364
  return target[key]; // already has `run` and `test` on it
431
- }
365
+ },
432
366
  });
433
367
  return proxy;
434
368
  };
@@ -462,16 +396,14 @@
462
396
  * while run will return an object with the validation result and an optional message created by the rule.
463
397
  */
464
398
  function genEnforce() {
465
- var target = {
466
- context: function () { return ctx.useX(); },
467
- extend: function (customRules) {
399
+ const target = {
400
+ context: () => ctx.useX(),
401
+ extend: (customRules) => {
468
402
  vestUtils.assign(baseRules, customRules);
469
- handleNoProxy(); // TODO: REMOVE when we stop supporting ES5
470
- }
403
+ },
471
404
  };
472
- handleNoProxy();
473
405
  return new Proxy(vestUtils.assign(enforceEager, target), {
474
- get: function (target, key) {
406
+ get: (target, key) => {
475
407
  if (key in target) {
476
408
  return target[key];
477
409
  }
@@ -480,23 +412,12 @@
480
412
  }
481
413
  // Only on the first rule access - start the chain of calls
482
414
  return genEnforceLazy(key);
483
- }
415
+ },
484
416
  });
485
- function handleNoProxy() {
486
- if (!isProxySupported()) {
487
- eachEnforceRule(function (ruleName) {
488
- // Only on the first rule access - start the chain of calls
489
- target[ruleName] = genEnforceLazy(ruleName);
490
- });
491
- return vestUtils.assign(enforceEager, target);
492
- }
493
- }
494
417
  }
495
- var enforce = genEnforce();
418
+ const enforce = genEnforce();
496
419
 
497
420
  exports.ctx = ctx;
498
421
  exports.enforce = enforce;
499
422
 
500
- Object.defineProperty(exports, '__esModule', { value: true });
501
-
502
- })));
423
+ }));
@@ -1 +1 @@
1
- "use strict";!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vest-utils"),require("context")):"function"==typeof define&&define.amd?define(["exports","vest-utils","context"],t):t((n="undefined"!=typeof globalThis?globalThis:n||self).n4s={},n["vest-utils"],n.context)}(this,(function(n,t,e){function i(n,e){return t.isStringValue(n)&&t.isStringValue(e)&&n.endsWith(e)}function r(n,t){return n===t}function u(n,e){return t.numberEquals(n,e)||t.greaterThan(n,e)}function s(n,e){return!!(t.isArray(e)||t.isStringValue(e)&&t.isStringValue(n))&&-1!==e.indexOf(n)}function o(n,e){return t.isNumeric(n)&&t.isNumeric(e)&&Number(n)<Number(e)}function a(n,e){return t.numberEquals(n,e)||o(n,e)}function l(n,t,e){return u(n,t)&&a(n,e)}function c(n){return t.isNullish(n)||t.isStringValue(n)&&!n.trim()}function f(n,t){return n in t}function N(n){return Number.isNaN(n)}function g(n){return"number"==typeof n}function d(n){return!!n}function h(n,e){if(t.isNullish(e))return!1;for(var i in e)if(e[i]===n)return!0;return!1}function p(n,e){return e instanceof RegExp?e.test(n):!!t.isStringValue(e)&&new RegExp(e).test(n)}function m(n,e){return t.isStringValue(n)&&t.isStringValue(e)&&n.startsWith(e)}function v(n){for(var e in K){var i=K[e];t.isFunction(i)&&n(e,i)}}function y(){return null}function b(n,t,e){if(e||2===arguments.length)for(var i,r=0,u=t.length;r<u;r++)!i&&r in t||(i||(i=Array.prototype.slice.call(t,0,r)),i[r]=t[r]);return n.concat(i||Array.prototype.slice.call(t))}function E(){try{return t.isFunction(Proxy)}catch(n){return!1}}function q(n,t){return n={pass:n},t&&(n.message=t),n}function x(n,e,i){for(var r=[],u=3;u<arguments.length;u++)r[u-3]=arguments[u];return t.invariant(t.isBoolean(n)||n&&t.isBoolean(n.pass),"Incorrect return value for rule: "+JSON.stringify(n)),t.isBoolean(n)?q(n):q(n.pass,t.optionalFunctionValue.apply(void 0,b([n.message,e,i],r,!1)))}function S(n){function e(e,i,r){return function(){for(var u=[],s=0;s<arguments.length;s++)u[s]=arguments[s];return s=M.run({value:n},(function(){return x.apply(void 0,b([i.apply(void 0,b([n],u,!1)),r,n],u,!1))})),t.invariant(s.pass,t.isNullish(s.message)?"enforce/".concat(r," failed with ").concat(JSON.stringify(n)):t.StringObject(s.message)),e}}var i={};if(!E())return v((function(n,t){i[n]=e(i,t,n)})),i;var r=new Proxy(i,{get:function(n,t){if(n=K[t])return e(r,n,t)}});return r}function T(n){var e,i=[];return function n(r){return function(){for(var u=[],s=0;s<arguments.length;s++)u[s]=arguments[s];var o=K[r];i.push((function(n){return x.apply(void 0,b([o.apply(void 0,b([n],u,!1)),r,n],u,!1))}));var a={run:function(n){return t.defaultTo(t.mapFirst(i,(function(i,r){var u,s=M.run({value:n},(function(){return i(n)}));r(!s.pass,q(!!s.pass,null!==(u=t.optionalFunctionValue(e,n,s.message))&&void 0!==u?u:s.message))})),q(!0))},test:function(n){return a.run(n).pass},message:function(n){return n&&(e=n),a}};return E()?a=new Proxy(a,{get:function(t,e){return K[e]?n(e):t[e]}}):(v((function(t){a[t]=n(t)})),a)}}(n)}var O=t.bindNot(i),V=t.bindNot(r),B=t.bindNot(s),w=t.bindNot(l),A=t.bindNot(c),P=t.bindNot(t.isBoolean),F=t.bindNot(f),W=t.bindNot(N),U=t.bindNot(g),j=t.bindNot(t.isStringValue),k=t.bindNot(d),I=t.bindNot(h),J=t.bindNot(p),K={condition:function(n,t){try{return t(n)}catch(n){return!1}},doesNotEndWith:O,doesNotStartWith:t.bindNot(m),endsWith:i,equals:r,greaterThan:t.greaterThan,greaterThanOrEquals:u,gt:t.greaterThan,gte:u,inside:s,isArray:t.isArray,isBetween:l,isBlank:c,isBoolean:t.isBoolean,isEmpty:t.isEmpty,isEven:function(n){return!!t.isNumeric(n)&&0==n%2},isFalsy:k,isKeyOf:f,isNaN:N,isNegative:function(n){return o(n,0)},isNotArray:t.isNotArray,isNotBetween:w,isNotBlank:A,isNotBoolean:P,isNotEmpty:t.isNotEmpty,isNotKeyOf:F,isNotNaN:W,isNotNull:t.isNotNull,isNotNullish:t.isNotNullish,isNotNumber:U,isNotNumeric:t.isNotNumeric,isNotString:j,isNotUndefined:t.isNotUndefined,isNotValueOf:I,isNull:t.isNull,isNullish:t.isNullish,isNumber:g,isNumeric:t.isNumeric,isOdd:function(n){return!!t.isNumeric(n)&&0!=n%2},isPositive:t.isPositive,isString:t.isStringValue,isTruthy:d,isUndefined:t.isUndefined,isValueOf:h,lengthEquals:t.lengthEquals,lengthNotEquals:t.lengthNotEquals,lessThan:o,lessThanOrEquals:a,longerThan:t.longerThan,longerThanOrEquals:function(n,t){return u(n.length,t)},lt:o,lte:a,matches:p,notEquals:V,notInside:B,notMatches:J,numberEquals:t.numberEquals,numberNotEquals:t.numberNotEquals,shorterThan:function(n,t){return o(n.length,t)},shorterThanOrEquals:function(n,t){return a(n.length,t)},startsWith:m},M=e.createCascade((function(n,e){var i={value:n.value,meta:n.meta||{}};return e?n.set?t.assign(i,{parent:function(){return e?{value:e.value,meta:e.meta,parent:e.parent}:e}}):e:t.assign(i,{parent:y})}));e=function(){function n(){if(!E())return v((function(n){e[n]=T(n)})),t.assign(S,e)}var e={context:function(){return M.useX()},extend:function(e){t.assign(K,e),n()}};return n(),new Proxy(t.assign(S,e),{get:function(n,t){return t in n?n[t]:K[t]?T(t):void 0}})}(),n.ctx=M,n.enforce=e,Object.defineProperty(n,"__esModule",{value:!0})}));
1
+ !function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vest-utils"),require("context")):"function"==typeof define&&define.amd?define(["exports","vest-utils","context"],t):t((n="undefined"!=typeof globalThis?globalThis:n||self).n4s={},n["vest-utils"],n.context)}(this,(function(n,t,e){"use strict";const i=e.createCascade(((n,e)=>{const i={value:n.value,meta:n.meta||{}};return e?n.set?t.assign(i,{parent:()=>function(n){return{value:n.value,meta:n.meta,parent:n.parent}}(e)}):e:t.assign(i,{parent:s})}));function s(){return null}function r(n,e){return t.isStringValue(n)&&t.isStringValue(e)&&n.endsWith(e)}const u=t.bindNot(r);function o(n,t){return n===t}const a=t.bindNot(o);function l(n,e){return t.numberEquals(n,e)||t.greaterThan(n,e)}function c(n,e){return(t.isArray(e)||!(!t.isStringValue(e)||!t.isStringValue(n)))&&-1!==e.indexOf(n)}const N=t.bindNot(c);function f(n,e){return t.isNumeric(n)&&t.isNumeric(e)&&Number(n)<Number(e)}function g(n,e){return t.numberEquals(n,e)||f(n,e)}function d(n,t,e){return l(n,t)&&g(n,e)}const h=t.bindNot(d);function m(n){return t.isNullish(n)||t.isStringValue(n)&&!n.trim()}const b=t.bindNot(m),p=t.bindNot(t.isBoolean),y=n=>!!t.isNumeric(n)&&n%2==0;function E(n,t){return n in t}const v=t.bindNot(E);function q(n){return Number.isNaN(n)}const S=t.bindNot(q);function T(n){return f(n,0)}function x(n){return Boolean("number"==typeof n)}const O=t.bindNot(x),V=n=>!!t.isNumeric(n)&&n%2!=0,B=t.bindNot(t.isStringValue);function w(n){return!!n}const W=t.bindNot(w);function A(n,e){if(t.isNullish(e))return!1;for(const t in e)if(e[t]===n)return!0;return!1}const P=t.bindNot(A);function F(n,t){return l(n.length,t)}function U(n,e){return e instanceof RegExp?e.test(n):!!t.isStringValue(e)&&new RegExp(e).test(n)}const j=t.bindNot(U);function k(n,t){try{return t(n)}catch(n){return!1}}function I(n,t){return f(n.length,t)}function J(n,t){return g(n.length,t)}function K(n,e){return t.isStringValue(n)&&t.isStringValue(e)&&n.startsWith(e)}const R=t.bindNot(K);const $={condition:k,doesNotEndWith:u,doesNotStartWith:R,endsWith:r,equals:o,greaterThan:t.greaterThan,greaterThanOrEquals:l,gt:t.greaterThan,gte:l,inside:c,isArray:t.isArray,isBetween:d,isBlank:m,isBoolean:t.isBoolean,isEmpty:t.isEmpty,isEven:y,isFalsy:W,isKeyOf:E,isNaN:q,isNegative:T,isNotArray:t.isNotArray,isNotBetween:h,isNotBlank:b,isNotBoolean:p,isNotEmpty:t.isNotEmpty,isNotKeyOf:v,isNotNaN:S,isNotNull:t.isNotNull,isNotNullish:t.isNotNullish,isNotNumber:O,isNotNumeric:t.isNotNumeric,isNotString:B,isNotUndefined:t.isNotUndefined,isNotValueOf:P,isNull:t.isNull,isNullish:t.isNullish,isNumber:x,isNumeric:t.isNumeric,isOdd:V,isPositive:t.isPositive,isString:t.isStringValue,isTruthy:w,isUndefined:t.isUndefined,isValueOf:A,lengthEquals:t.lengthEquals,lengthNotEquals:t.lengthNotEquals,lessThan:f,lessThanOrEquals:g,longerThan:t.longerThan,longerThanOrEquals:F,lt:f,lte:g,matches:U,notEquals:a,notInside:N,notMatches:j,numberEquals:t.numberEquals,numberNotEquals:t.numberNotEquals,shorterThan:I,shorterThanOrEquals:J,startsWith:K};function C(n){return $[n]}function M(n,t){const e={pass:n};return t&&(e.message=t),e}function X(n){return t.defaultTo(n,M(!0))}function z(n,e,i,...s){return function(n){t.invariant(t.isBoolean(n)||n&&t.isBoolean(n.pass),"Incorrect return value for rule: "+JSON.stringify(n))}(n),t.isBoolean(n)?M(n):M(n.pass,t.optionalFunctionValue(n.message,e,i,...s))}function D(n){const e={message:function(n){return s=n,r}};let s;const r=new Proxy(e,{get:(u,o)=>{const a=C(o);return a?function(e,r,u){return function(...o){const a=i.run({value:n},(()=>z(r(n,...o),u,n,...o)));function l(){return t.isNullish(s)?t.isNullish(a.message)?`enforce/${u} failed with ${JSON.stringify(n)}`:t.StringObject(a.message):t.StringObject(s)}return t.invariant(a.pass,l()),e}}(r,a,o):e[o]}});return r}const G=function(){const n={context:()=>i.useX(),extend:n=>{t.assign($,n)}};return new Proxy(t.assign(D,n),{get:(n,e)=>e in n?n[e]:C(e)?function(n){const e=[];let s;return function n(r){return(...u)=>{const o=C(r);e.push((n=>z(o(n,...u),r,n,...u)));let a={run:n=>X(t.mapFirst(e,((e,r)=>{var u;const o=i.run({value:n},(()=>e(n)));r(!o.pass,M(!!o.pass,null!==(u=t.optionalFunctionValue(s,n,o.message))&&void 0!==u?u:o.message))}))),test:n=>a.run(n).pass,message:n=>(n&&(s=n),a)};return a=new Proxy(a,{get:(t,e)=>C(e)?n(e):t[e]}),a}}(n)}(e):void 0})}();n.ctx=i,n.enforce=G}));