vest 4.0.0 → 4.0.2-dev-72921c

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.
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('n4s')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'n4s'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.schema = {}, global.n4s));
5
- }(this, (function (exports, n4s) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
+ typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.schema = {}));
5
+ }(this, (function (exports) { 'use strict';
6
6
 
7
7
  function mapFirst(array, callback) {
8
8
  var broke = false;
@@ -19,10 +19,325 @@
19
19
  }
20
20
  }
21
21
 
22
+ var assign = Object.assign;
23
+
22
24
  function isFunction(value) {
23
25
  return typeof value === 'function';
24
26
  }
25
27
 
28
+ function bindNot(fn) {
29
+ return function () {
30
+ var args = [];
31
+ for (var _i = 0; _i < arguments.length; _i++) {
32
+ args[_i] = arguments[_i];
33
+ }
34
+ return !fn.apply(void 0, args);
35
+ };
36
+ }
37
+
38
+ function isNull(value) {
39
+ return value === null;
40
+ }
41
+ var isNotNull = bindNot(isNull);
42
+
43
+ function isUndefined(value) {
44
+ return value === undefined;
45
+ }
46
+ var isNotUndefined = bindNot(isUndefined);
47
+
48
+ function isNullish(value) {
49
+ return isNull(value) || isUndefined(value);
50
+ }
51
+ var isNotNullish = bindNot(isNullish);
52
+
53
+ function isStringValue(v) {
54
+ return String(v) === v;
55
+ }
56
+
57
+ function endsWith(value, arg1) {
58
+ return isStringValue(value) && isStringValue(arg1) && value.endsWith(arg1);
59
+ }
60
+ var doesNotEndWith = bindNot(endsWith);
61
+
62
+ function equals(value, arg1) {
63
+ return value === arg1;
64
+ }
65
+ var notEquals = bindNot(equals);
66
+
67
+ function isNumeric(value) {
68
+ var str = String(value);
69
+ var num = Number(value);
70
+ var result = !isNaN(parseFloat(str)) && !isNaN(Number(value)) && isFinite(num);
71
+ return Boolean(result);
72
+ }
73
+ var isNotNumeric = bindNot(isNumeric);
74
+
75
+ function greaterThan(value, gt) {
76
+ return isNumeric(value) && isNumeric(gt) && Number(value) > Number(gt);
77
+ }
78
+
79
+ function greaterThanOrEquals(value, gte) {
80
+ return isNumeric(value) && isNumeric(gte) && Number(value) >= Number(gte);
81
+ }
82
+
83
+ // The module is named "isArrayValue" since it
84
+ // is conflicting with a nested npm dependency.
85
+ // We may need to revisit this in the future.
86
+ function isArray(value) {
87
+ return Boolean(Array.isArray(value));
88
+ }
89
+ var isNotArray = bindNot(isArray);
90
+
91
+ function inside(value, arg1) {
92
+ if (isArray(arg1)) {
93
+ return arg1.indexOf(value) !== -1;
94
+ }
95
+ // both value and arg1 are strings
96
+ if (isStringValue(arg1) && isStringValue(value)) {
97
+ return arg1.indexOf(value) !== -1;
98
+ }
99
+ return false;
100
+ }
101
+ var notInside = bindNot(inside);
102
+
103
+ function lessThanOrEquals(value, lte) {
104
+ return isNumeric(value) && isNumeric(lte) && Number(value) <= Number(lte);
105
+ }
106
+
107
+ function isBetween(value, min, max) {
108
+ return greaterThanOrEquals(value, min) && lessThanOrEquals(value, max);
109
+ }
110
+ var isNotBetween = bindNot(isBetween);
111
+
112
+ function isBlank(value) {
113
+ return isNullish(value) || (isStringValue(value) && !value.trim());
114
+ }
115
+ var isNotBlank = bindNot(isBlank);
116
+
117
+ function isBoolean(value) {
118
+ return !!value === value;
119
+ }
120
+
121
+ var isNotBoolean = bindNot(isBoolean);
122
+
123
+ /**
124
+ * A safe hasOwnProperty access
125
+ */
126
+ function hasOwnProperty(obj, key) {
127
+ return Object.prototype.hasOwnProperty.call(obj, key);
128
+ }
129
+
130
+ function isNumber(value) {
131
+ return Boolean(typeof value === 'number');
132
+ }
133
+ var isNotNumber = bindNot(isNumber);
134
+
135
+ function lengthEquals(value, arg1) {
136
+ return value.length === Number(arg1);
137
+ }
138
+ var lengthNotEquals = bindNot(lengthEquals);
139
+
140
+ function isEmpty(value) {
141
+ if (!value) {
142
+ return true;
143
+ }
144
+ else if (isNumber(value)) {
145
+ return value === 0;
146
+ }
147
+ else if (hasOwnProperty(value, 'length')) {
148
+ return lengthEquals(value, 0);
149
+ }
150
+ else if (typeof value === 'object') {
151
+ return lengthEquals(Object.keys(value), 0);
152
+ }
153
+ return true;
154
+ }
155
+ var isNotEmpty = bindNot(isEmpty);
156
+
157
+ /**
158
+ * Validates that a given value is an even number
159
+ */
160
+ var isEven = function (value) {
161
+ if (isNumeric(value)) {
162
+ return value % 2 === 0;
163
+ }
164
+ return false;
165
+ };
166
+
167
+ function isNaN$1(value) {
168
+ return Number.isNaN(value);
169
+ }
170
+ var isNotNaN = bindNot(isNaN$1);
171
+
172
+ function isNegative(value) {
173
+ if (isNumeric(value)) {
174
+ return Number(value) < 0;
175
+ }
176
+ return false;
177
+ }
178
+ var isPositive = bindNot(isNegative);
179
+
180
+ /**
181
+ * Validates that a given value is an odd number
182
+ */
183
+ var isOdd = function (value) {
184
+ if (isNumeric(value)) {
185
+ return value % 2 !== 0;
186
+ }
187
+ return false;
188
+ };
189
+
190
+ var isNotString = bindNot(isStringValue);
191
+
192
+ function isTruthy(value) {
193
+ return !!value;
194
+ }
195
+ var isFalsy = bindNot(isTruthy);
196
+
197
+ function isValueOf(value, objectToCheck) {
198
+ if (isNullish(objectToCheck)) {
199
+ return false;
200
+ }
201
+ for (var key in objectToCheck) {
202
+ if (objectToCheck[key] === value) {
203
+ return true;
204
+ }
205
+ }
206
+ return false;
207
+ }
208
+ var isNotValueOf = bindNot(isValueOf);
209
+
210
+ function lessThan(value, lt) {
211
+ return isNumeric(value) && isNumeric(lt) && Number(value) < Number(lt);
212
+ }
213
+
214
+ function longerThan(value, arg1) {
215
+ return value.length > Number(arg1);
216
+ }
217
+
218
+ function longerThanOrEquals(value, arg1) {
219
+ return value.length >= Number(arg1);
220
+ }
221
+
222
+ function matches(value, regex) {
223
+ if (regex instanceof RegExp) {
224
+ return regex.test(value);
225
+ }
226
+ else if (isStringValue(regex)) {
227
+ return new RegExp(regex).test(value);
228
+ }
229
+ else {
230
+ return false;
231
+ }
232
+ }
233
+ var notMatches = bindNot(matches);
234
+
235
+ function numberEquals(value, eq) {
236
+ return isNumeric(value) && isNumeric(eq) && Number(value) === Number(eq);
237
+ }
238
+ var numberNotEquals = bindNot(numberEquals);
239
+
240
+ function condition(value, callback) {
241
+ try {
242
+ return callback(value);
243
+ }
244
+ catch (_a) {
245
+ return false;
246
+ }
247
+ }
248
+
249
+ function shorterThan(value, arg1) {
250
+ return value.length < Number(arg1);
251
+ }
252
+
253
+ function shorterThanOrEquals(value, arg1) {
254
+ return value.length <= Number(arg1);
255
+ }
256
+
257
+ function startsWith(value, arg1) {
258
+ return isStringValue(value) && isStringValue(arg1) && value.startsWith(arg1);
259
+ }
260
+ var doesNotStartWith = bindNot(startsWith);
261
+
262
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, max-lines-per-function
263
+ function rules() {
264
+ return {
265
+ condition: condition,
266
+ doesNotEndWith: doesNotEndWith,
267
+ doesNotStartWith: doesNotStartWith,
268
+ endsWith: endsWith,
269
+ equals: equals,
270
+ greaterThan: greaterThan,
271
+ greaterThanOrEquals: greaterThanOrEquals,
272
+ gt: greaterThan,
273
+ gte: greaterThanOrEquals,
274
+ inside: inside,
275
+ isArray: isArray,
276
+ isBetween: isBetween,
277
+ isBlank: isBlank,
278
+ isBoolean: isBoolean,
279
+ isEmpty: isEmpty,
280
+ isEven: isEven,
281
+ isFalsy: isFalsy,
282
+ isNaN: isNaN$1,
283
+ isNegative: isNegative,
284
+ isNotArray: isNotArray,
285
+ isNotBetween: isNotBetween,
286
+ isNotBlank: isNotBlank,
287
+ isNotBoolean: isNotBoolean,
288
+ isNotEmpty: isNotEmpty,
289
+ isNotNaN: isNotNaN,
290
+ isNotNull: isNotNull,
291
+ isNotNullish: isNotNullish,
292
+ isNotNumber: isNotNumber,
293
+ isNotNumeric: isNotNumeric,
294
+ isNotString: isNotString,
295
+ isNotUndefined: isNotUndefined,
296
+ isNotValueOf: isNotValueOf,
297
+ isNull: isNull,
298
+ isNullish: isNullish,
299
+ isNumber: isNumber,
300
+ isNumeric: isNumeric,
301
+ isOdd: isOdd,
302
+ isPositive: isPositive,
303
+ isString: isStringValue,
304
+ isTruthy: isTruthy,
305
+ isUndefined: isUndefined,
306
+ isValueOf: isValueOf,
307
+ lengthEquals: lengthEquals,
308
+ lengthNotEquals: lengthNotEquals,
309
+ lessThan: lessThan,
310
+ lessThanOrEquals: lessThanOrEquals,
311
+ longerThan: longerThan,
312
+ longerThanOrEquals: longerThanOrEquals,
313
+ lt: lessThan,
314
+ lte: lessThanOrEquals,
315
+ matches: matches,
316
+ notEquals: notEquals,
317
+ notInside: notInside,
318
+ notMatches: notMatches,
319
+ numberEquals: numberEquals,
320
+ numberNotEquals: numberNotEquals,
321
+ shorterThan: shorterThan,
322
+ shorterThanOrEquals: shorterThanOrEquals,
323
+ startsWith: startsWith
324
+ };
325
+ }
326
+
327
+ var baseRules = rules();
328
+ function getRule(ruleName) {
329
+ return baseRules[ruleName];
330
+ }
331
+
332
+ function eachEnforceRule(action) {
333
+ for (var ruleName in baseRules) {
334
+ var ruleFn = getRule(ruleName);
335
+ if (isFunction(ruleFn)) {
336
+ action(ruleName, ruleFn);
337
+ }
338
+ }
339
+ }
340
+
26
341
  function optionalFunctionValue(value) {
27
342
  var args = [];
28
343
  for (var _i = 1; _i < arguments.length; _i++) {
@@ -36,6 +351,128 @@
36
351
  return (_a = optionalFunctionValue(callback)) !== null && _a !== void 0 ? _a : defaultValue;
37
352
  }
38
353
 
354
+ /**
355
+ * Throws a timed out error.
356
+ */
357
+ function throwError(devMessage, productionMessage) {
358
+ throw new Error(devMessage );
359
+ }
360
+
361
+ // eslint-disable-next-line max-lines-per-function
362
+ function createContext(init) {
363
+ var storage = { ancestry: [] };
364
+ return {
365
+ bind: bind,
366
+ run: run,
367
+ use: use,
368
+ useX: useX
369
+ };
370
+ function useX(errorMessage) {
371
+ var _a;
372
+ return ((_a = storage.ctx) !== null && _a !== void 0 ? _a : throwError(defaultTo(errorMessage, 'Context was used after it was closed')));
373
+ }
374
+ function run(ctxRef, fn) {
375
+ var _a;
376
+ var parentContext = use();
377
+ var out = assign({}, parentContext ? parentContext : {}, (_a = optionalFunctionValue(init, ctxRef, parentContext)) !== null && _a !== void 0 ? _a : ctxRef);
378
+ var ctx = set(Object.freeze(out));
379
+ storage.ancestry.unshift(ctx);
380
+ var res = fn(ctx);
381
+ clear();
382
+ return res;
383
+ }
384
+ function bind(ctxRef, fn) {
385
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
386
+ // @ts-ignore - this one's pretty hard to get right
387
+ var returnedFn = function () {
388
+ var runTimeArgs = [];
389
+ for (var _i = 0; _i < arguments.length; _i++) {
390
+ runTimeArgs[_i] = arguments[_i];
391
+ }
392
+ return run(ctxRef, function () {
393
+ return fn.apply(void 0, runTimeArgs);
394
+ });
395
+ };
396
+ return returnedFn;
397
+ }
398
+ function use() {
399
+ return storage.ctx;
400
+ }
401
+ function set(value) {
402
+ return (storage.ctx = value);
403
+ }
404
+ function clear() {
405
+ var _a;
406
+ storage.ancestry.shift();
407
+ set((_a = storage.ancestry[0]) !== null && _a !== void 0 ? _a : null);
408
+ }
409
+ }
410
+
411
+ var ctx = createContext(function (ctxRef, parentContext) {
412
+ var base = {
413
+ value: ctxRef.value,
414
+ meta: ctxRef.meta || {}
415
+ };
416
+ if (!parentContext) {
417
+ return assign(base, {
418
+ parent: emptyParent
419
+ });
420
+ }
421
+ else if (ctxRef.set) {
422
+ return assign(base, {
423
+ parent: function () { return stripContext(parentContext); }
424
+ });
425
+ }
426
+ return parentContext;
427
+ });
428
+ function stripContext(ctx) {
429
+ if (!ctx) {
430
+ return ctx;
431
+ }
432
+ return {
433
+ value: ctx.value,
434
+ meta: ctx.meta,
435
+ parent: ctx.parent
436
+ };
437
+ }
438
+ function emptyParent() {
439
+ return null;
440
+ }
441
+
442
+ /*! *****************************************************************************
443
+ Copyright (c) Microsoft Corporation.
444
+
445
+ Permission to use, copy, modify, and/or distribute this software for any
446
+ purpose with or without fee is hereby granted.
447
+
448
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
449
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
450
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
451
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
452
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
453
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
454
+ PERFORMANCE OF THIS SOFTWARE.
455
+ ***************************************************************************** */
456
+
457
+ function __spreadArray(to, from, pack) {
458
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
459
+ if (ar || !(i in from)) {
460
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
461
+ ar[i] = from[i];
462
+ }
463
+ }
464
+ return to.concat(ar || Array.prototype.slice.call(from));
465
+ }
466
+
467
+ function isProxySupported() {
468
+ try {
469
+ return isFunction(Proxy);
470
+ }
471
+ catch (_a) {
472
+ return false;
473
+ }
474
+ }
475
+
39
476
  function ruleReturn(pass, message) {
40
477
  var output = { pass: pass };
41
478
  if (message) {
@@ -53,6 +490,182 @@
53
490
  return defaultTo(callback, passing());
54
491
  }
55
492
 
493
+ /**
494
+ * Transform the result of a rule into a standard format
495
+ */
496
+ function transformResult(result, ruleName, value) {
497
+ var args = [];
498
+ for (var _i = 3; _i < arguments.length; _i++) {
499
+ args[_i - 3] = arguments[_i];
500
+ }
501
+ validateResult(result);
502
+ // if result is boolean
503
+ if (isBoolean(result)) {
504
+ return ruleReturn(result);
505
+ }
506
+ else {
507
+ return ruleReturn(result.pass, optionalFunctionValue.apply(void 0, __spreadArray([result.message, ruleName, value], args)));
508
+ }
509
+ }
510
+ function validateResult(result) {
511
+ // if result is boolean, or if result.pass is boolean
512
+ if (isBoolean(result) || (result && isBoolean(result.pass))) {
513
+ return;
514
+ }
515
+ throwError('Incorrect return value for rule: ' + JSON.stringify(result));
516
+ }
517
+
518
+ function enforceEager(value) {
519
+ var target = {};
520
+ if (!isProxySupported()) {
521
+ eachEnforceRule(function (ruleName, ruleFn) {
522
+ target[ruleName] = genRuleCall(target, ruleFn, ruleName);
523
+ });
524
+ return target;
525
+ }
526
+ var proxy = new Proxy(target, {
527
+ get: function (_, ruleName) {
528
+ var rule = getRule(ruleName);
529
+ if (rule) {
530
+ return genRuleCall(proxy, rule, ruleName);
531
+ }
532
+ }
533
+ });
534
+ return proxy;
535
+ function genRuleCall(target, rule, ruleName) {
536
+ return function ruleCall() {
537
+ var args = [];
538
+ for (var _i = 0; _i < arguments.length; _i++) {
539
+ args[_i] = arguments[_i];
540
+ }
541
+ var transformedResult = transformResult.apply(void 0, __spreadArray([ctx.run({ value: value }, function () { return rule.apply(void 0, __spreadArray([value], args)); }),
542
+ ruleName,
543
+ value], args));
544
+ if (!transformedResult.pass) {
545
+ if (isEmpty(transformedResult.message)) {
546
+ throwError("enforce/" + ruleName + " failed with " + JSON.stringify(value));
547
+ }
548
+ else {
549
+ // Explicitly throw a string so that vest.test can pick it up as the validation error message
550
+ throw transformedResult.message;
551
+ }
552
+ }
553
+ return target;
554
+ };
555
+ }
556
+ }
557
+
558
+ // eslint-disable-next-line max-lines-per-function
559
+ function genEnforceLazy(key) {
560
+ var registeredRules = [];
561
+ var lazyMessage;
562
+ return addLazyRule(key);
563
+ // eslint-disable-next-line max-lines-per-function
564
+ function addLazyRule(ruleName) {
565
+ // eslint-disable-next-line max-lines-per-function
566
+ return function () {
567
+ var args = [];
568
+ for (var _i = 0; _i < arguments.length; _i++) {
569
+ args[_i] = arguments[_i];
570
+ }
571
+ var rule = getRule(ruleName);
572
+ registeredRules.push(function (value) {
573
+ return transformResult.apply(void 0, __spreadArray([rule.apply(void 0, __spreadArray([value], args)), ruleName, value], args));
574
+ });
575
+ var proxy = {
576
+ run: function (value) {
577
+ return defaultToPassing(mapFirst(registeredRules, function (rule, breakout) {
578
+ var _a;
579
+ var res = ctx.run({ value: value }, function () { return rule(value); });
580
+ if (!res.pass) {
581
+ breakout(ruleReturn(!!res.pass, (_a = optionalFunctionValue(lazyMessage, value, res.message)) !== null && _a !== void 0 ? _a : res.message));
582
+ }
583
+ }));
584
+ },
585
+ test: function (value) { return proxy.run(value).pass; },
586
+ message: function (message) {
587
+ if (message) {
588
+ lazyMessage = message;
589
+ }
590
+ return proxy;
591
+ }
592
+ };
593
+ if (!isProxySupported()) {
594
+ eachEnforceRule(function (ruleName) {
595
+ proxy[ruleName] = addLazyRule(ruleName);
596
+ });
597
+ return proxy;
598
+ }
599
+ // reassigning the proxy here is not pretty
600
+ // but it's a cleaner way of getting `run` and `test` for free
601
+ proxy = new Proxy(proxy, {
602
+ get: function (target, key) {
603
+ if (getRule(key)) {
604
+ return addLazyRule(key);
605
+ }
606
+ return target[key]; // already has `run` and `test` on it
607
+ }
608
+ });
609
+ return proxy;
610
+ };
611
+ }
612
+ }
613
+
614
+ /**
615
+ * Enforce is quite complicated, I want to explain it in detail.
616
+ * It is dynamic in nature, so a lot of proxy objects are involved.
617
+ *
618
+ * Enforce has two main interfaces
619
+ * 1. eager
620
+ * 2. lazy
621
+ *
622
+ * The eager interface is the most commonly used, and the easier to understand.
623
+ * It throws an error when a rule is not satisfied.
624
+ * The eager interface is declared in enforceEager.ts and it is quite simple to understand.
625
+ * enforce is called with a value, and the return value is a proxy object that points back to all the rules.
626
+ * When a rule is called, the value is mapped as its first argument, and if the rule passes, the same
627
+ * proxy object is returned. Otherwise, an error is thrown.
628
+ *
629
+ * The lazy interface works quite differently. It is declared in genEnforceLazy.ts.
630
+ * Rather than calling enforce directly, the lazy interface has all the rules as "methods" (only by proxy).
631
+ * Calling the first function in the chain will initialize an array of calls. It stores the different rule calls
632
+ * and the parameters passed to them. None of the rules are called yet.
633
+ * The rules are only invoked in sequence once either of these chained functions are called:
634
+ * 1. test(value)
635
+ * 2. run(value)
636
+ *
637
+ * Calling run or test will call all the rules in sequence, with the difference that test will only return a boolean value,
638
+ * while run will return an object with the validation result and an optional message created by the rule.
639
+ */
640
+ function genEnforce() {
641
+ var target = {
642
+ context: function () { return ctx.useX(); },
643
+ extend: function (customRules) {
644
+ assign(baseRules, customRules);
645
+ }
646
+ };
647
+ if (!isProxySupported()) {
648
+ eachEnforceRule(function (ruleName) {
649
+ // Only on the first rule access - start the chain of calls
650
+ target[ruleName] = genEnforceLazy(ruleName);
651
+ });
652
+ return assign(enforceEager, target);
653
+ }
654
+ return new Proxy(assign(enforceEager, target), {
655
+ get: function (target, key) {
656
+ if (key in target) {
657
+ return target[key];
658
+ }
659
+ if (!getRule(key)) {
660
+ return;
661
+ }
662
+ // Only on the first rule access - start the chain of calls
663
+ return genEnforceLazy(key);
664
+ }
665
+ });
666
+ }
667
+ var enforce = genEnforce();
668
+
56
669
  function runLazyRule(lazyRule, currentValue) {
57
670
  try {
58
671
  return lazyRule.run(currentValue);
@@ -64,7 +677,7 @@
64
677
 
65
678
  function isArrayOf(inputArray, currentRule) {
66
679
  return defaultToPassing(mapFirst(inputArray, function (currentValue, breakout, index) {
67
- var res = n4s.ctx.run({ value: currentValue, set: true, meta: { index: index } }, function () { return runLazyRule(currentRule, currentValue); });
680
+ var res = ctx.run({ value: currentValue, set: true, meta: { index: index } }, function () { return runLazyRule(currentRule, currentValue); });
68
681
  if (!res.pass) {
69
682
  breakout(res);
70
683
  }
@@ -75,7 +688,7 @@
75
688
  var _loop_1 = function (key) {
76
689
  var currentValue = inputObject[key];
77
690
  var currentRule = shapeObject[key];
78
- var res = n4s.ctx.run({ value: currentValue, set: true, meta: { key: key } }, function () {
691
+ var res = ctx.run({ value: currentValue, set: true, meta: { key: key } }, function () {
79
692
  return runLazyRule(currentRule, currentValue);
80
693
  });
81
694
  if (!res.pass) {
@@ -90,18 +703,6 @@
90
703
  return passing();
91
704
  }
92
705
 
93
- function isNull(value) {
94
- return value === null;
95
- }
96
-
97
- function isUndefined(value) {
98
- return value === undefined;
99
- }
100
-
101
- function isNullish(value) {
102
- return isNull(value) || isUndefined(value);
103
- }
104
-
105
706
  function optional(value, ruleChain) {
106
707
  if (isNullish(value)) {
107
708
  return passing();
@@ -109,13 +710,6 @@
109
710
  return runLazyRule(ruleChain, value);
110
711
  }
111
712
 
112
- /**
113
- * A safe hasOwnProperty access
114
- */
115
- function hasOwnProperty(obj, key) {
116
- return Object.prototype.hasOwnProperty.call(obj, key);
117
- }
118
-
119
713
  function shape(inputObject, shapeObject) {
120
714
  var baseRes = loose(inputObject, shapeObject);
121
715
  if (!baseRes.pass) {
@@ -134,12 +728,12 @@
134
728
  function partial(shapeObject) {
135
729
  var output = {};
136
730
  for (var key in shapeObject) {
137
- output[key] = n4s.enforce.optional(shapeObject[key]);
731
+ output[key] = enforce.optional(shapeObject[key]);
138
732
  }
139
733
  return output;
140
734
  }
141
735
 
142
- n4s.enforce.extend({ isArrayOf: isArrayOf, loose: loose, optional: optional, shape: shape });
736
+ enforce.extend({ isArrayOf: isArrayOf, loose: loose, optional: optional, shape: shape });
143
737
 
144
738
  exports.partial = partial;
145
739