vest 4.0.1 → 4.0.2-dev-6e9534

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