n4s 4.3.6 → 4.3.8-dev-9c596e

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