vest 4.0.0-dev-366a8b → 4.0.0-dev-e266d9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/CHANGELOG.md +70 -49
  2. package/README.md +2 -112
  3. package/dist/cjs/classnames.development.js +3 -3
  4. package/dist/cjs/classnames.production.js +1 -1
  5. package/dist/cjs/compose.js +7 -0
  6. package/dist/cjs/compounds.js +7 -0
  7. package/dist/cjs/enforce/compose.development.js +139 -0
  8. package/dist/cjs/enforce/compose.production.js +1 -0
  9. package/dist/cjs/enforce/compounds.development.js +132 -0
  10. package/dist/cjs/enforce/compounds.production.js +1 -0
  11. package/dist/cjs/enforce/package.json +1 -0
  12. package/dist/cjs/enforce/schema.development.js +144 -0
  13. package/dist/cjs/enforce/schema.production.js +1 -0
  14. package/dist/cjs/promisify.development.js +1 -1
  15. package/dist/cjs/promisify.production.js +1 -1
  16. package/dist/cjs/schema.js +7 -0
  17. package/dist/cjs/vest.development.js +608 -1097
  18. package/dist/cjs/vest.production.js +1 -1
  19. package/dist/es/classnames.development.js +3 -3
  20. package/dist/es/classnames.production.js +1 -1
  21. package/dist/es/enforce/compose.development.js +137 -0
  22. package/dist/es/enforce/compose.production.js +1 -0
  23. package/dist/es/enforce/compounds.development.js +130 -0
  24. package/dist/es/enforce/compounds.production.js +1 -0
  25. package/dist/es/enforce/package.json +1 -0
  26. package/dist/es/enforce/schema.development.js +140 -0
  27. package/dist/es/enforce/schema.production.js +1 -0
  28. package/dist/es/promisify.development.js +1 -1
  29. package/dist/es/promisify.production.js +1 -1
  30. package/dist/es/vest.development.js +602 -1097
  31. package/dist/es/vest.production.js +1 -1
  32. package/dist/umd/classnames.development.js +3 -3
  33. package/dist/umd/classnames.production.js +1 -1
  34. package/dist/umd/enforce/compose.development.js +143 -0
  35. package/dist/umd/enforce/compose.production.js +1 -0
  36. package/dist/umd/enforce/compounds.development.js +136 -0
  37. package/dist/umd/enforce/compounds.production.js +1 -0
  38. package/dist/umd/enforce/schema.development.js +148 -0
  39. package/dist/umd/enforce/schema.production.js +1 -0
  40. package/dist/umd/promisify.development.js +1 -1
  41. package/dist/umd/promisify.production.js +1 -1
  42. package/dist/umd/vest.development.js +1693 -2185
  43. package/dist/umd/vest.production.js +1 -1
  44. package/enforce/compose/package.json +7 -0
  45. package/enforce/compounds/package.json +7 -0
  46. package/enforce/schema/package.json +7 -0
  47. package/package.json +107 -13
  48. package/testUtils/mockThrowError.ts +16 -0
  49. package/types/classnames.d.ts +2 -2
  50. package/types/enforce/compose.d.ts +134 -0
  51. package/types/enforce/compounds.d.ts +146 -0
  52. package/types/enforce/schema.d.ts +151 -0
  53. package/types/vest.d.ts +31 -196
  54. package/docs/.nojekyll +0 -0
  55. package/docs/README.md +0 -113
  56. package/docs/_assets/favicon.ico +0 -0
  57. package/docs/_assets/vest-logo.png +0 -0
  58. package/docs/_sidebar.md +0 -14
  59. package/docs/cross_field_validations.md +0 -33
  60. package/docs/enforce.md +0 -11
  61. package/docs/exclusion.md +0 -129
  62. package/docs/getting_started.md +0 -72
  63. package/docs/group.md +0 -142
  64. package/docs/index.html +0 -41
  65. package/docs/migration.md +0 -202
  66. package/docs/n4s/rules.md +0 -1282
  67. package/docs/node.md +0 -36
  68. package/docs/optional.md +0 -103
  69. package/docs/result.md +0 -249
  70. package/docs/state.md +0 -102
  71. package/docs/test.md +0 -172
  72. package/docs/utilities.md +0 -109
  73. package/docs/warn.md +0 -82
@@ -0,0 +1,144 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var n4s = require('n4s');
6
+
7
+ function mapFirst(array, callback) {
8
+ var broke = false;
9
+ var breakoutValue = null;
10
+ for (var i = 0; i < array.length; i++) {
11
+ callback(array[i], breakout, i);
12
+ if (broke) {
13
+ return breakoutValue;
14
+ }
15
+ }
16
+ function breakout(value) {
17
+ broke = true;
18
+ breakoutValue = value;
19
+ }
20
+ }
21
+
22
+ function isFunction(value) {
23
+ return typeof value === 'function';
24
+ }
25
+
26
+ function optionalFunctionValue(value) {
27
+ var args = [];
28
+ for (var _i = 1; _i < arguments.length; _i++) {
29
+ args[_i - 1] = arguments[_i];
30
+ }
31
+ return isFunction(value) ? value.apply(void 0, args) : value;
32
+ }
33
+
34
+ function defaultTo(callback, defaultValue) {
35
+ var _a;
36
+ return (_a = optionalFunctionValue(callback)) !== null && _a !== void 0 ? _a : defaultValue;
37
+ }
38
+
39
+ function ruleReturn(pass, message) {
40
+ var output = { pass: pass };
41
+ if (message) {
42
+ output.message = message;
43
+ }
44
+ return output;
45
+ }
46
+ function failing() {
47
+ return ruleReturn(false);
48
+ }
49
+ function passing() {
50
+ return ruleReturn(true);
51
+ }
52
+ function defaultToPassing(callback) {
53
+ return defaultTo(callback, passing());
54
+ }
55
+
56
+ function runLazyRule(lazyRule, currentValue) {
57
+ try {
58
+ return lazyRule.run(currentValue);
59
+ }
60
+ catch (_a) {
61
+ return failing();
62
+ }
63
+ }
64
+
65
+ function isArrayOf(inputArray, currentRule) {
66
+ 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); });
68
+ if (!res.pass) {
69
+ breakout(res);
70
+ }
71
+ }));
72
+ }
73
+
74
+ function loose(inputObject, shapeObject) {
75
+ var _loop_1 = function (key) {
76
+ var currentValue = inputObject[key];
77
+ var currentRule = shapeObject[key];
78
+ var res = n4s.ctx.run({ value: currentValue, set: true, meta: { key: key } }, function () {
79
+ return runLazyRule(currentRule, currentValue);
80
+ });
81
+ if (!res.pass) {
82
+ return { value: res };
83
+ }
84
+ };
85
+ for (var key in shapeObject) {
86
+ var state_1 = _loop_1(key);
87
+ if (typeof state_1 === "object")
88
+ return state_1.value;
89
+ }
90
+ return passing();
91
+ }
92
+
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
+ function optional(value, ruleChain) {
106
+ if (isNullish(value)) {
107
+ return passing();
108
+ }
109
+ return runLazyRule(ruleChain, value);
110
+ }
111
+
112
+ /**
113
+ * A safe hasOwnProperty access
114
+ */
115
+ function hasOwnProperty(obj, key) {
116
+ return Object.prototype.hasOwnProperty.call(obj, key);
117
+ }
118
+
119
+ function shape(inputObject, shapeObject) {
120
+ var baseRes = loose(inputObject, shapeObject);
121
+ if (!baseRes.pass) {
122
+ return baseRes;
123
+ }
124
+ for (var key in inputObject) {
125
+ if (!hasOwnProperty(shapeObject, key)) {
126
+ return failing();
127
+ }
128
+ }
129
+ return passing();
130
+ }
131
+
132
+ // Help needed improving the typings of this file.
133
+ // Ideally, we'd be able to extend IShapeObject, but that's not possible.
134
+ function partial(shapeObject) {
135
+ var output = {};
136
+ for (var key in shapeObject) {
137
+ output[key] = n4s.enforce.optional(shapeObject[key]);
138
+ }
139
+ return output;
140
+ }
141
+
142
+ n4s.enforce.extend({ isArrayOf: isArrayOf, loose: loose, optional: optional, shape: shape });
143
+
144
+ exports.partial = partial;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var n=require("n4s");function r(n){return"function"==typeof n}function t(n,t){var e;return null!==(e=function(n){for(var t=[],e=1;e<arguments.length;e++)t[e-1]=arguments[e];return r(n)?n.apply(void 0,t):n}(n))&&void 0!==e?e:t}function e(n,r){return n={pass:n},r&&(n.message=r),n}function u(){return e(!1)}function o(){return e(!0)}function i(n,r){try{return n.run(r)}catch(n){return u()}}function f(r,t){var e,u=function(e){var u=r[e],o=t[e];if(!(e=n.ctx.run({value:u,set:!0,meta:{key:e}},(function(){return i(o,u)}))).pass)return{value:e}};for(e in t){var f=u(e);if("object"==typeof f)return f.value}return o()}function c(n,r){return Object.prototype.hasOwnProperty.call(n,r)}n.enforce.extend({isArrayOf:function(r,e){return function(n){return t(n,o())}(function(n,r){function t(n){e=!0,u=n}for(var e=!1,u=null,o=0;o<n.length;o++)if(r(n[o],t,o),e)return u}(r,(function(r,t,u){(u=n.ctx.run({value:r,set:!0,meta:{index:u}},(function(){return i(e,r)}))).pass||t(u)})))},loose:f,optional:function(n,r){return function(n){return function(n){return null===n}(n)||function(n){return void 0===n}(n)}(n)?o():i(r,n)},shape:function(n,r){var t=f(n,r);if(!t.pass)return t;for(var e in n)if(!c(r,e))return u();return o()}}),exports.partial=function(r){var t,e={};for(t in r)e[t]=n.enforce.optional(r[t]);return e};
@@ -18,7 +18,7 @@ var promisify = function (validatorFn) {
18
18
  args[_i] = arguments[_i];
19
19
  }
20
20
  if (!isFunction(validatorFn)) {
21
- throwError('[vest/promisify]: Expected validatorFn to be a function.');
21
+ throwError('promisify: Expected validatorFn to be a function.');
22
22
  }
23
23
  return new Promise(function (resolve) { return validatorFn.apply(void 0, args).done(resolve); });
24
24
  };
@@ -1 +1 @@
1
- "use strict";function n(n){return"function"==typeof n}function r(r,t){var o;return null!==(o=function(r){for(var t=[],o=1;o<arguments.length;o++)t[o-1]=arguments[o];return n(r)?r.apply(void 0,t):r}(r))&&void 0!==o?o:t}function t(n,t){throw Error(r(t,n))}module.exports=function(r){return function(){for(var o=[],e=0;e<arguments.length;e++)o[e]=arguments[e];return n(r)||t("[vest/promisify]: Expected validatorFn to be a function."),new Promise((function(n){return r.apply(void 0,o).done(n)}))}};
1
+ "use strict";function n(n){return"function"==typeof n}function r(r,t){var o;return null!==(o=function(r){for(var t=[],o=1;o<arguments.length;o++)t[o-1]=arguments[o];return n(r)?r.apply(void 0,t):r}(r))&&void 0!==o?o:t}function t(n,t){throw Error(r(t,n))}module.exports=function(r){return function(){for(var o=[],e=0;e<arguments.length;e++)o[e]=arguments[e];return n(r)||t("promisify: Expected validatorFn to be a function."),new Promise((function(n){return r.apply(void 0,o).done(n)}))}};
@@ -0,0 +1,7 @@
1
+ 'use strict'
2
+
3
+ if (process.env.NODE_ENV === 'production') {
4
+ module.exports = require('./schema.production.js');
5
+ } else {
6
+ module.exports = require('./schema.development.js');
7
+ }