@availity/yup 3.2.1 → 4.2.0

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.
package/dist/npi.js ADDED
@@ -0,0 +1,43 @@
1
+ var INTEGER_REGEX = /^\d*$/;
2
+ function npi(msg) {
3
+ return this.test({
4
+ name: 'npi',
5
+ exclusive: true,
6
+ message: msg || 'This field is invalid.',
7
+ test: function (value) {
8
+ if (!value)
9
+ return true;
10
+ value += '';
11
+ // is it a number and 10 digits long
12
+ if (!INTEGER_REGEX.test(value) || value.length !== 10) {
13
+ return false;
14
+ }
15
+ // is the first digit 1-4
16
+ var firstDigit = value.charAt(0);
17
+ if (['1', '2', '3', '4'].indexOf(firstDigit) < 0) {
18
+ return false;
19
+ }
20
+ var digit = Number.parseInt(value.charAt(9), 10);
21
+ value = value.substring(0, 9);
22
+ value = "80840" + value;
23
+ var alternate = true;
24
+ var total = 0;
25
+ for (var i = value.length; i > 0; i--) {
26
+ var next = Number.parseInt(value.charAt(i - 1), 10);
27
+ if (alternate) {
28
+ next *= 2;
29
+ if (next > 9) {
30
+ next = (next % 10) + 1;
31
+ }
32
+ }
33
+ total += next;
34
+ alternate = !alternate;
35
+ }
36
+ var roundUp = Math.ceil(total / 10) * 10;
37
+ var calculatedCheck = roundUp - total;
38
+ return calculatedCheck === digit;
39
+ },
40
+ });
41
+ }
42
+ export default npi;
43
+ //# sourceMappingURL=npi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"npi.js","sourceRoot":"","sources":["../src/npi.ts"],"names":[],"mappings":"AAEA,IAAM,aAAa,GAAG,OAAO,CAAC;AAE9B,SAAS,GAAG,CAA0C,GAAY;IAChE,OAAO,IAAI,CAAC,IAAI,CAAC;QACf,IAAI,EAAE,KAAK;QACX,SAAS,EAAE,IAAI;QACf,OAAO,EAAE,GAAG,IAAI,wBAAwB;QACxC,IAAI,YAAC,KAAK;YACR,IAAI,CAAC,KAAK;gBAAE,OAAO,IAAI,CAAC;YAExB,KAAK,IAAI,EAAE,CAAC;YAEZ,oCAAoC;YACpC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,EAAE,EAAE;gBACrD,OAAO,KAAK,CAAC;aACd;YAED,yBAAyB;YACzB,IAAM,UAAU,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YACnC,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;gBAChD,OAAO,KAAK,CAAC;aACd;YAED,IAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YACnD,KAAK,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YAC9B,KAAK,GAAG,UAAQ,KAAO,CAAC;YAExB,IAAI,SAAS,GAAG,IAAI,CAAC;YACrB,IAAI,KAAK,GAAG,CAAC,CAAC;YAEd,KAAK,IAAI,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE;gBACrC,IAAI,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;gBACpD,IAAI,SAAS,EAAE;oBACb,IAAI,IAAI,CAAC,CAAC;oBACV,IAAI,IAAI,GAAG,CAAC,EAAE;wBACZ,IAAI,GAAG,CAAC,IAAI,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC;qBACxB;iBACF;gBACD,KAAK,IAAI,IAAI,CAAC;gBACd,SAAS,GAAG,CAAC,SAAS,CAAC;aACxB;YAED,IAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC;YAC3C,IAAM,eAAe,GAAG,OAAO,GAAG,KAAK,CAAC;YAExC,OAAO,eAAe,KAAK,KAAK,CAAC;QACnC,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAED,eAAe,GAAG,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { BaseSchema } from 'yup';
2
+ declare function phone<Schema extends BaseSchema>(this: Schema, msg: string): Schema;
3
+ export default phone;
4
+ //# sourceMappingURL=phone.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"phone.d.ts","sourceRoot":"","sources":["../src/phone.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AAIjC,iBAAS,KAAK,CAAC,MAAM,SAAS,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAW3E;AAED,eAAe,KAAK,CAAC"}
package/dist/phone.js ADDED
@@ -0,0 +1,15 @@
1
+ var NANP_REGEXP = /^(\+?1[\s.-]?)?\(?[2-9]\d{2}[\s).-]?\s?[2-9]\d{2}[\s.-]?\d{4}$/;
2
+ function phone(msg) {
3
+ return this.test({
4
+ name: 'phone',
5
+ exclusive: true,
6
+ message: msg || 'This field is invalid',
7
+ test: function (value) {
8
+ if (!value)
9
+ return true;
10
+ return NANP_REGEXP.test(value);
11
+ },
12
+ });
13
+ }
14
+ export default phone;
15
+ //# sourceMappingURL=phone.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"phone.js","sourceRoot":"","sources":["../src/phone.ts"],"names":[],"mappings":"AAEA,IAAM,WAAW,GAAG,gEAAgE,CAAC;AAErF,SAAS,KAAK,CAA0C,GAAW;IACjE,OAAO,IAAI,CAAC,IAAI,CAAC;QACf,IAAI,EAAE,OAAO;QACb,SAAS,EAAE,IAAI;QACf,OAAO,EAAE,GAAG,IAAI,uBAAuB;QACvC,IAAI,YAAC,KAAK;YACR,IAAI,CAAC,KAAK;gBAAE,OAAO,IAAI,CAAC;YAExB,OAAO,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACjC,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAED,eAAe,KAAK,CAAC"}
package/lib/date.js CHANGED
@@ -5,12 +5,24 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports["default"] = void 0;
8
+ exports["default"] = exports.avDate = void 0;
9
+
10
+ require("core-js/modules/es.object.to-string.js");
11
+
12
+ require("core-js/modules/esnext.async-iterator.some.js");
13
+
14
+ require("core-js/modules/esnext.iterator.constructor.js");
15
+
16
+ require("core-js/modules/esnext.iterator.some.js");
9
17
 
10
18
  require("core-js/modules/es.function.name.js");
11
19
 
12
20
  require("core-js/modules/es.array.concat.js");
13
21
 
22
+ require("core-js/modules/es.regexp.exec.js");
23
+
24
+ require("core-js/modules/es.regexp.test.js");
25
+
14
26
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
15
27
 
16
28
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
@@ -29,9 +41,7 @@ var _yup = require("yup");
29
41
 
30
42
  var _moment = _interopRequireDefault(require("moment"));
31
43
 
32
- var defaultOpts = {
33
- format: 'MM/DD/YYYY'
34
- };
44
+ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
35
45
  var formats = ['YYYY-MM-DD', 'MMDDYYYY', 'YYYYMMDD', 'MM-DD-YYYY'];
36
46
 
37
47
  var AvDateSchema = /*#__PURE__*/function (_MixedSchema) {
@@ -42,7 +52,7 @@ var AvDateSchema = /*#__PURE__*/function (_MixedSchema) {
42
52
  function AvDateSchema() {
43
53
  var _thisSuper, _this;
44
54
 
45
- var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultOpts,
55
+ var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
46
56
  _ref$format = _ref.format,
47
57
  format = _ref$format === void 0 ? 'MM/DD/YYYY' : _ref$format;
48
58
 
@@ -50,8 +60,8 @@ var AvDateSchema = /*#__PURE__*/function (_MixedSchema) {
50
60
  _this = _super.call(this, {
51
61
  type: 'avDate'
52
62
  });
63
+ _this.format = void 0;
53
64
  _this.format = format;
54
- _this.getValidDate = _this.getValidDate.bind((0, _assertThisInitialized2["default"])(_this));
55
65
 
56
66
  _this.withMutation(function (schema) {
57
67
  if (!schema.tests.some(function (test) {
@@ -100,7 +110,7 @@ var AvDateSchema = /*#__PURE__*/function (_MixedSchema) {
100
110
  return true;
101
111
  }
102
112
 
103
- return value === null || minDate.isSameOrBefore(value, 'MM/DD/YYYY');
113
+ return value === null || minDate.isSameOrBefore(value);
104
114
  }
105
115
  });
106
116
  }
@@ -169,4 +179,10 @@ var AvDateSchema = /*#__PURE__*/function (_MixedSchema) {
169
179
  return AvDateSchema;
170
180
  }(_yup.MixedSchema);
171
181
 
172
- exports["default"] = AvDateSchema;
182
+ exports["default"] = AvDateSchema;
183
+
184
+ var avDate = function avDate(opts) {
185
+ return new AvDateSchema(opts);
186
+ };
187
+
188
+ exports.avDate = avDate;
package/lib/dateRange.js CHANGED
@@ -5,16 +5,18 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports["default"] = void 0;
8
+ exports["default"] = exports.dateRange = void 0;
9
9
 
10
10
  require("core-js/modules/es.array.concat.js");
11
11
 
12
+ require("core-js/modules/es.regexp.exec.js");
13
+
14
+ require("core-js/modules/es.regexp.test.js");
15
+
12
16
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
13
17
 
14
18
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
15
19
 
16
- var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
17
-
18
20
  var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
19
21
 
20
22
  var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
@@ -27,12 +29,12 @@ var _get = _interopRequireDefault(require("lodash/get"));
27
29
 
28
30
  var _merge2 = _interopRequireDefault(require("lodash/merge"));
29
31
 
32
+ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
30
33
  var defaultOptions = {
31
34
  startKey: 'startDate',
32
35
  endKey: 'endDate',
33
36
  format: 'MM/DD/YYYY'
34
37
  };
35
- var defaultValue = {};
36
38
  var formats = ['YYYY-MM-DD', 'MMDDYYYY', 'YYYYMMDD'];
37
39
 
38
40
  var DateRangeSchema = /*#__PURE__*/function (_MixedSchema) {
@@ -47,41 +49,35 @@ var DateRangeSchema = /*#__PURE__*/function (_MixedSchema) {
47
49
  _this = _super.call(this, {
48
50
  type: 'dateRange'
49
51
  });
52
+ _this.startKey = void 0;
53
+ _this.endKey = void 0;
54
+ _this.format = void 0;
50
55
 
51
56
  var _merge = (0, _merge2["default"])({}, defaultOptions, options),
52
57
  startKey = _merge.startKey,
53
58
  endKey = _merge.endKey,
54
- format = _merge.format;
59
+ format = _merge.format; // Assign them here so we can use in schema.transform
60
+
55
61
 
56
62
  _this.startKey = startKey;
57
63
  _this.endKey = endKey;
58
64
  _this.format = format;
59
- _this.getValidDate = _this.getValidDate.bind((0, _assertThisInitialized2["default"])(_this));
60
65
 
61
66
  _this.withMutation(function (schema) {
62
67
  schema.transform(function mutate(value) {
63
68
  var start = (0, _get["default"])(value, startKey);
64
69
  var end = (0, _get["default"])(value, endKey);
65
- var startDate;
66
- var endDate;
67
-
68
- if (start) {
69
- startDate = schema.getValidDate(start);
70
- }
71
-
72
- if (end) {
73
- endDate = schema.getValidDate(end);
74
- }
75
-
76
70
  return {
77
- startDate: startDate,
78
- endDate: endDate
71
+ startDate: start ? schema.getValidDate(start) : start,
72
+ endDate: end ? schema.getValidDate(end) : end,
73
+ supportedFormats: [schema.format].concat(formats)
79
74
  };
80
75
  });
81
76
  });
82
77
 
83
78
  return _this;
84
- }
79
+ } // Convert the string to a moment object
80
+
85
81
 
86
82
  (0, _createClass2["default"])(DateRangeSchema, [{
87
83
  key: "getValidDate",
@@ -91,16 +87,20 @@ var DateRangeSchema = /*#__PURE__*/function (_MixedSchema) {
91
87
  }, {
92
88
  key: "distance",
93
89
  value: function distance() {
94
- var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultValue,
90
+ var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
95
91
  _ref$min = _ref.min;
96
92
 
97
- _ref$min = _ref$min === void 0 ? {} : _ref$min;
93
+ _ref$min = _ref$min === void 0 ? {
94
+ value: 0
95
+ } : _ref$min;
98
96
  var minValue = _ref$min.value,
99
97
  _ref$min$units = _ref$min.units,
100
98
  minUnits = _ref$min$units === void 0 ? 'day' : _ref$min$units,
101
99
  minErrorMessage = _ref$min.errorMessage,
102
100
  _ref$max = _ref.max;
103
- _ref$max = _ref$max === void 0 ? {} : _ref$max;
101
+ _ref$max = _ref$max === void 0 ? {
102
+ value: 0
103
+ } : _ref$max;
104
104
  var maxValue = _ref$max.value,
105
105
  _ref$max$units = _ref$max.units,
106
106
  maxUnits = _ref$max$units === void 0 ? 'day' : _ref$max$units,
@@ -109,18 +109,20 @@ var DateRangeSchema = /*#__PURE__*/function (_MixedSchema) {
109
109
  name: 'distance',
110
110
  exclusive: true,
111
111
  test: function test() {
112
- var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultValue,
112
+ var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
113
113
  endDate = _ref2.endDate,
114
114
  startDate = _ref2.startDate;
115
115
 
116
- if (!minValue && !maxValue || !startDate || !endDate) return true;
116
+ // check if we have min or max set and if both dates are present
117
+ if (!minValue && !maxValue || !startDate || !endDate) return true; // if we have a max then check distance between end and start
117
118
 
118
119
  if (maxValue && endDate.isAfter(startDate.add(maxValue, maxUnits), 'day')) {
119
120
  return new _yup.ValidationError(maxErrorMessage || "The end date must be within ".concat(maxValue, " ").concat(maxUnits).concat(maxValue > 1 ? 's' : '', " of the start date"), {
120
121
  startDate: startDate,
121
122
  endDate: endDate
122
123
  }, this.path);
123
- }
124
+ } // if we have a min the check distance between end and start
125
+
124
126
 
125
127
  if (minValue && endDate.isBefore(startDate.add(minValue, minUnits), 'day')) {
126
128
  return new _yup.ValidationError(minErrorMessage || "The end date must be greater than ".concat(minValue, " ").concat(minUnits).concat(minValue > 1 ? 's' : '', " of the start date"), {
@@ -136,23 +138,27 @@ var DateRangeSchema = /*#__PURE__*/function (_MixedSchema) {
136
138
  }, {
137
139
  key: "min",
138
140
  value: function min(_min, message) {
139
- var format = this.format;
140
- var minDate = this.getValidDate(_min);
141
+ // it works for date, but not daterange. maybe that can tell us more about what is going on
142
+ // const minDate = this.getValidDate(min);
141
143
  return this.test({
142
- message: message || "Date Range must start on or after ".concat(minDate.format(format)),
144
+ message: message || function (_ref3) {
145
+ var min = _ref3.min;
146
+ return "Date Range must start on or after ".concat(min);
147
+ },
143
148
  name: 'min',
144
149
  exclusive: true,
145
150
  params: {
146
151
  min: _min
147
152
  },
148
153
  test: function test() {
149
- var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultValue,
150
- startDate = _ref3.startDate;
154
+ var _ref4 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
155
+ startDate = _ref4.startDate,
156
+ supportedFormats = _ref4.supportedFormats;
151
157
 
152
- if (!startDate || !_min) {
153
- return true;
154
- }
158
+ // return true when no startDate or min set
159
+ if (!startDate || !_min) return true; // otherwise check if min is correct format and is after given startDate
155
160
 
161
+ var minDate = (0, _moment["default"])(_min, supportedFormats, true);
156
162
  return minDate.isValid() && minDate.isSameOrBefore(startDate);
157
163
  }
158
164
  });
@@ -160,20 +166,26 @@ var DateRangeSchema = /*#__PURE__*/function (_MixedSchema) {
160
166
  }, {
161
167
  key: "max",
162
168
  value: function max(_max, message) {
163
- var format = this.format;
164
- var maxDate = this.getValidDate(_max);
169
+ // const maxDate = this.getValidDate(max);
165
170
  return this.test({
166
- message: message || "Date Range must end on or before ".concat(maxDate.format(format)),
171
+ message: message || function (_ref5) {
172
+ var max = _ref5.max;
173
+ return "Date Range must end on or before ".concat(max);
174
+ },
167
175
  name: 'max',
168
176
  exclusive: true,
169
177
  params: {
170
178
  max: _max
171
179
  },
172
180
  test: function test() {
173
- var _ref4 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultValue,
174
- endDate = _ref4.endDate;
181
+ var _ref6 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
182
+ endDate = _ref6.endDate,
183
+ supportedFormats = _ref6.supportedFormats;
184
+
185
+ // return true when no endDate given or max set
186
+ if (!endDate || !_max) return true; // otherwise check if max is correct format and is after given endDate
175
187
 
176
- if (!endDate || !_max) return true;
188
+ var maxDate = (0, _moment["default"])(_max, supportedFormats, true);
177
189
  return maxDate.isValid() && maxDate.isSameOrAfter(endDate);
178
190
  }
179
191
  });
@@ -181,11 +193,14 @@ var DateRangeSchema = /*#__PURE__*/function (_MixedSchema) {
181
193
  }, {
182
194
  key: "between",
183
195
  value: function between(min, max, message) {
184
- var format = this.format;
185
- var minDate = this.getValidDate(min);
186
- var maxDate = this.getValidDate(max);
196
+ // const minDate = this.getValidDate(min);
197
+ // const maxDate = this.getValidDate(max);
187
198
  return this.test({
188
- message: message || "Date Range must be between ".concat(minDate.format(format), " and ").concat(maxDate.format(format)),
199
+ message: message || function (_ref7) {
200
+ var min = _ref7.min,
201
+ max = _ref7.max;
202
+ return "Date Range must be between ".concat(min, " and ").concat(max);
203
+ },
189
204
  name: 'between',
190
205
  exclusive: true,
191
206
  params: {
@@ -193,11 +208,14 @@ var DateRangeSchema = /*#__PURE__*/function (_MixedSchema) {
193
208
  max: max
194
209
  },
195
210
  test: function test() {
196
- var _ref5 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultValue,
197
- startDate = _ref5.startDate,
198
- endDate = _ref5.endDate;
211
+ var _ref8 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
212
+ startDate = _ref8.startDate,
213
+ endDate = _ref8.endDate,
214
+ supportedFormats = _ref8.supportedFormats;
199
215
 
200
216
  if (!startDate || !endDate || !min || !max) return true;
217
+ var minDate = (0, _moment["default"])(min, supportedFormats, true);
218
+ var maxDate = (0, _moment["default"])(max, supportedFormats, true);
201
219
  return maxDate.isValid() && minDate.isValid() && maxDate.isSameOrAfter(endDate) && minDate.isSameOrBefore(startDate);
202
220
  }
203
221
  });
@@ -213,29 +231,33 @@ var DateRangeSchema = /*#__PURE__*/function (_MixedSchema) {
213
231
  exclusive: true,
214
232
  message: msg || 'This field is required.',
215
233
  test: function test() {
216
- var _ref6 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultValue,
217
- startDate = _ref6.startDate,
218
- endDate = _ref6.endDate;
234
+ var _ref9 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
235
+ startDate = _ref9.startDate,
236
+ endDate = _ref9.endDate;
219
237
 
220
- return !_isRequired || startDate && endDate;
238
+ return !_isRequired || !!(startDate && endDate);
221
239
  }
222
240
  });
223
241
  }
224
242
  }, {
225
243
  key: "typeError",
226
- value: function typeError() {
244
+ value: function typeError(_ref10) {
245
+ var message = _ref10.message;
227
246
  return this.test({
228
247
  name: 'typeError',
229
248
  exclusive: true,
230
249
  test: function test() {
231
- var _ref7 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultValue,
232
- startDate = _ref7.startDate,
233
- endDate = _ref7.endDate;
250
+ var _ref11 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
251
+ startDate = _ref11.startDate,
252
+ endDate = _ref11.endDate;
234
253
 
254
+ // Set to `any` to pass to ValidationErrors. Docs state string[] is accepted,
255
+ // but types do not allow string[]
256
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
235
257
  var errors = [];
236
258
 
237
259
  if ((!startDate || !endDate) && (startDate || endDate)) {
238
- errors.push('Start and End Date are required.');
260
+ errors.push(message || 'Start and End Date are required.');
239
261
  }
240
262
 
241
263
  if (startDate && endDate && !startDate.isSameOrBefore(endDate)) {
@@ -260,14 +282,19 @@ var DateRangeSchema = /*#__PURE__*/function (_MixedSchema) {
260
282
  }, {
261
283
  key: "_typeCheck",
262
284
  value: function _typeCheck() {
263
- var _ref8 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultValue,
264
- startDate = _ref8.startDate,
265
- endDate = _ref8.endDate;
266
-
267
- return startDate && endDate && startDate.isValid() && endDate.isValid();
285
+ var range = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
286
+ var startDate = range.startDate,
287
+ endDate = range.endDate;
288
+ return !!startDate && !!endDate && startDate.isValid() && endDate.isValid();
268
289
  }
269
290
  }]);
270
291
  return DateRangeSchema;
271
292
  }(_yup.MixedSchema);
272
293
 
273
- exports["default"] = DateRangeSchema;
294
+ exports["default"] = DateRangeSchema;
295
+
296
+ var dateRange = function dateRange(opts) {
297
+ return new DateRangeSchema(opts);
298
+ };
299
+
300
+ exports.dateRange = dateRange;
package/lib/index.js CHANGED
@@ -5,13 +5,24 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.dateRange = exports.avDate = void 0;
8
+ Object.defineProperty(exports, "avDate", {
9
+ enumerable: true,
10
+ get: function get() {
11
+ return _date.avDate;
12
+ }
13
+ });
14
+ Object.defineProperty(exports, "dateRange", {
15
+ enumerable: true,
16
+ get: function get() {
17
+ return _dateRange.dateRange;
18
+ }
19
+ });
9
20
 
10
21
  var _yup = require("yup");
11
22
 
12
- var _date = _interopRequireDefault(require("./date"));
23
+ var _date = require("./date");
13
24
 
14
- var _dateRange = _interopRequireDefault(require("./dateRange"));
25
+ var _dateRange = require("./dateRange");
15
26
 
16
27
  var _isRequired = _interopRequireDefault(require("./isRequired"));
17
28
 
@@ -19,17 +30,6 @@ var _npi = _interopRequireDefault(require("./npi"));
19
30
 
20
31
  var _phone = _interopRequireDefault(require("./phone"));
21
32
 
22
- var avDate = function avDate(opts) {
23
- return new _date["default"](opts);
24
- };
25
-
26
- exports.avDate = avDate;
27
-
28
- var dateRange = function dateRange(opts) {
29
- return new _dateRange["default"](opts);
30
- };
31
-
32
- exports.dateRange = dateRange;
33
33
  (0, _yup.addMethod)(_yup.array, 'isRequired', _isRequired["default"]);
34
34
  (0, _yup.addMethod)(_yup.number, 'isRequired', _isRequired["default"]);
35
35
  (0, _yup.addMethod)(_yup.object, 'isRequired', _isRequired["default"]);
@@ -37,4 +37,4 @@ exports.dateRange = dateRange;
37
37
  (0, _yup.addMethod)(_yup.number, 'npi', _npi["default"]);
38
38
  (0, _yup.addMethod)(_yup.string, 'npi', _npi["default"]);
39
39
  (0, _yup.addMethod)(_yup.number, 'phone', _phone["default"]);
40
- (0, _yup.addMethod)(_yup.string, 'phone', _phone["default"]);
40
+ (0, _yup.addMethod)(_yup.string, 'phone', _phone["default"]); // Add definitions to yup
package/lib/isRequired.js CHANGED
@@ -1,10 +1,14 @@
1
1
  "use strict";
2
2
 
3
+ require("core-js/modules/es.regexp.exec");
4
+
3
5
  Object.defineProperty(exports, "__esModule", {
4
6
  value: true
5
7
  });
6
8
  exports["default"] = void 0;
7
9
 
10
+ require("core-js/modules/es.regexp.test.js");
11
+
8
12
  function isRequired() {
9
13
  var isRequired = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
10
14
  var msg = arguments.length > 1 ? arguments[1] : undefined;
@@ -14,16 +18,17 @@ function isRequired() {
14
18
  message: msg || 'This field is required.',
15
19
  test: function test(value) {
16
20
  if (isRequired) {
17
- if (typeof value === 'number') {
18
- return value !== undefined;
21
+ // array and string have custom logic
22
+ if (this.schema.type === 'array') {
23
+ return Array.isArray(value) ? value.length > 0 : value !== undefined;
19
24
  }
20
25
 
21
- if (Array.isArray(value)) {
22
- return value.length > 0;
23
- } // String ( If you want to check for null add nullable )
26
+ if (this.schema.type === 'string') {
27
+ return value !== undefined && value !== '';
28
+ } // default logic for all other types
24
29
 
25
30
 
26
- return value !== undefined && value !== '';
31
+ return value !== undefined;
27
32
  }
28
33
 
29
34
  return true;
package/lib/npi.js CHANGED
@@ -1,12 +1,16 @@
1
1
  "use strict";
2
2
 
3
- require("core-js/modules/es.number.parse-int");
3
+ require("core-js/modules/es.regexp.exec");
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
8
  exports["default"] = void 0;
9
9
 
10
+ require("core-js/modules/es.regexp.test.js");
11
+
12
+ require("core-js/modules/es.number.parse-int.js");
13
+
10
14
  require("core-js/modules/es.number.constructor.js");
11
15
 
12
16
  var INTEGER_REGEX = /^\d*$/;
@@ -18,11 +22,12 @@ function npi(msg) {
18
22
  message: msg || 'This field is invalid.',
19
23
  test: function test(value) {
20
24
  if (!value) return true;
21
- value += '';
25
+ value += ''; // is it a number and 10 digits long
22
26
 
23
27
  if (!INTEGER_REGEX.test(value) || value.length !== 10) {
24
28
  return false;
25
- }
29
+ } // is the first digit 1-4
30
+
26
31
 
27
32
  var firstDigit = value.charAt(0);
28
33
 
package/lib/phone.js CHANGED
@@ -1,9 +1,14 @@
1
1
  "use strict";
2
2
 
3
+ require("core-js/modules/es.regexp.exec");
4
+
3
5
  Object.defineProperty(exports, "__esModule", {
4
6
  value: true
5
7
  });
6
8
  exports["default"] = void 0;
9
+
10
+ require("core-js/modules/es.regexp.test.js");
11
+
7
12
  var NANP_REGEXP = /^(\+?1[\s.-]?)?\(?[2-9]\d{2}[\s).-]?\s?[2-9]\d{2}[\s.-]?\d{4}$/;
8
13
 
9
14
  function phone(msg) {
package/package.json CHANGED
@@ -1,21 +1,35 @@
1
1
  {
2
2
  "name": "@availity/yup",
3
- "version": "3.2.1",
4
- "description": "Additional Methods for Yup validation library",
5
- "main": "lib/index.js",
6
- "module": "src/index.js",
7
- "types": "types/index.d.ts",
3
+ "version": "4.2.0",
4
+ "description": "Additional methods for yup validation library",
8
5
  "keywords": [
9
6
  "yup",
10
- "availity"
7
+ "availity",
8
+ "validation"
11
9
  ],
12
- "author": "Kyle Gray <kyle.gray@availity.com>",
10
+ "homepage": "https://availity.github.io/sdk-js/resources/yup",
11
+ "bugs": {
12
+ "url": "https://github.com/Availity/sdk-js/issues"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/Availity/sdk-js.git",
17
+ "directory": "packages/yup"
18
+ },
13
19
  "license": "MIT",
14
- "publishConfig": {
15
- "access": "public"
20
+ "author": "Kyle Gray <kyle.gray@availity.com>",
21
+ "main": "lib/index.js",
22
+ "module": "dist/index.js",
23
+ "types": "dist/index.d.ts",
24
+ "scripts": {
25
+ "build": "yarn clean && yarn transpile && yarn compile",
26
+ "clean": "rimraf ./lib ./dist",
27
+ "compile": "tsc -p tsconfig.build.json",
28
+ "compile:types": "tsc -p tsconfig.build.json --emitDeclarationOnly",
29
+ "transpile": "babel --root-mode upward src -d lib --extensions .ts --ignore **/*.test.ts"
16
30
  },
17
31
  "dependencies": {
18
- "@babel/runtime": "^7.10.2",
32
+ "@babel/runtime": "^7.16.5",
19
33
  "core-js": "^3.12.1",
20
34
  "lodash": "^4.17.21"
21
35
  },
@@ -27,5 +41,8 @@
27
41
  "moment": "^2.24.0",
28
42
  "yup": "^0.32.9"
29
43
  },
30
- "gitHead": "19644de90a510481a5086fcf737d43491061690b"
44
+ "publishConfig": {
45
+ "access": "public"
46
+ },
47
+ "gitHead": "1c3e8c8045b16fc5111f941d863600f0a97cdbff"
31
48
  }