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