@availity/yup 4.2.0 → 5.0.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/.eslintrc.yml +2 -0
- package/CHANGELOG.md +14 -3
- package/dist/index.d.ts +68 -7
- package/dist/index.js +353 -16
- package/dist/index.mjs +325 -0
- package/jest.config.js +11 -0
- package/package.json +18 -18
- package/project.json +23 -0
- package/tsconfig.json +5 -0
- package/tsconfig.spec.json +10 -0
- package/LICENSE +0 -21
- package/dist/date.d.ts +0 -23
- package/dist/date.d.ts.map +0 -1
- package/dist/date.js +0 -123
- package/dist/date.js.map +0 -1
- package/dist/dateRange.d.ts +0 -43
- package/dist/dateRange.d.ts.map +0 -1
- package/dist/dateRange.js +0 -203
- package/dist/dateRange.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/isRequired.d.ts +0 -4
- package/dist/isRequired.d.ts.map +0 -1
- package/dist/isRequired.js +0 -24
- package/dist/isRequired.js.map +0 -1
- package/dist/npi.d.ts +0 -4
- package/dist/npi.d.ts.map +0 -1
- package/dist/npi.js +0 -43
- package/dist/npi.js.map +0 -1
- package/dist/phone.d.ts +0 -4
- package/dist/phone.d.ts.map +0 -1
- package/dist/phone.js +0 -15
- package/dist/phone.js.map +0 -1
- package/lib/date.js +0 -188
- package/lib/dateRange.js +0 -300
- package/lib/index.js +0 -40
- package/lib/isRequired.js +0 -40
- package/lib/npi.js +0 -67
- package/lib/phone.js +0 -27
- package/tsconfig.build.json +0 -8
package/lib/dateRange.js
DELETED
|
@@ -1,300 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports["default"] = exports.dateRange = void 0;
|
|
9
|
-
|
|
10
|
-
require("core-js/modules/es.array.concat.js");
|
|
11
|
-
|
|
12
|
-
require("core-js/modules/es.regexp.exec.js");
|
|
13
|
-
|
|
14
|
-
require("core-js/modules/es.regexp.test.js");
|
|
15
|
-
|
|
16
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
17
|
-
|
|
18
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
19
|
-
|
|
20
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
21
|
-
|
|
22
|
-
var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
|
|
23
|
-
|
|
24
|
-
var _yup = require("yup");
|
|
25
|
-
|
|
26
|
-
var _moment = _interopRequireDefault(require("moment"));
|
|
27
|
-
|
|
28
|
-
var _get = _interopRequireDefault(require("lodash/get"));
|
|
29
|
-
|
|
30
|
-
var _merge2 = _interopRequireDefault(require("lodash/merge"));
|
|
31
|
-
|
|
32
|
-
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
33
|
-
var defaultOptions = {
|
|
34
|
-
startKey: 'startDate',
|
|
35
|
-
endKey: 'endDate',
|
|
36
|
-
format: 'MM/DD/YYYY'
|
|
37
|
-
};
|
|
38
|
-
var formats = ['YYYY-MM-DD', 'MMDDYYYY', 'YYYYMMDD'];
|
|
39
|
-
|
|
40
|
-
var DateRangeSchema = /*#__PURE__*/function (_MixedSchema) {
|
|
41
|
-
(0, _inherits2["default"])(DateRangeSchema, _MixedSchema);
|
|
42
|
-
|
|
43
|
-
var _super = (0, _createSuper2["default"])(DateRangeSchema);
|
|
44
|
-
|
|
45
|
-
function DateRangeSchema(options) {
|
|
46
|
-
var _this;
|
|
47
|
-
|
|
48
|
-
(0, _classCallCheck2["default"])(this, DateRangeSchema);
|
|
49
|
-
_this = _super.call(this, {
|
|
50
|
-
type: 'dateRange'
|
|
51
|
-
});
|
|
52
|
-
_this.startKey = void 0;
|
|
53
|
-
_this.endKey = void 0;
|
|
54
|
-
_this.format = void 0;
|
|
55
|
-
|
|
56
|
-
var _merge = (0, _merge2["default"])({}, defaultOptions, options),
|
|
57
|
-
startKey = _merge.startKey,
|
|
58
|
-
endKey = _merge.endKey,
|
|
59
|
-
format = _merge.format; // Assign them here so we can use in schema.transform
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
_this.startKey = startKey;
|
|
63
|
-
_this.endKey = endKey;
|
|
64
|
-
_this.format = format;
|
|
65
|
-
|
|
66
|
-
_this.withMutation(function (schema) {
|
|
67
|
-
schema.transform(function mutate(value) {
|
|
68
|
-
var start = (0, _get["default"])(value, startKey);
|
|
69
|
-
var end = (0, _get["default"])(value, endKey);
|
|
70
|
-
return {
|
|
71
|
-
startDate: start ? schema.getValidDate(start) : start,
|
|
72
|
-
endDate: end ? schema.getValidDate(end) : end,
|
|
73
|
-
supportedFormats: [schema.format].concat(formats)
|
|
74
|
-
};
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
return _this;
|
|
79
|
-
} // Convert the string to a moment object
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
(0, _createClass2["default"])(DateRangeSchema, [{
|
|
83
|
-
key: "getValidDate",
|
|
84
|
-
value: function getValidDate(value) {
|
|
85
|
-
return (0, _moment["default"])(value, [this.format].concat(formats), true);
|
|
86
|
-
}
|
|
87
|
-
}, {
|
|
88
|
-
key: "distance",
|
|
89
|
-
value: function distance() {
|
|
90
|
-
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
91
|
-
_ref$min = _ref.min;
|
|
92
|
-
|
|
93
|
-
_ref$min = _ref$min === void 0 ? {
|
|
94
|
-
value: 0
|
|
95
|
-
} : _ref$min;
|
|
96
|
-
var minValue = _ref$min.value,
|
|
97
|
-
_ref$min$units = _ref$min.units,
|
|
98
|
-
minUnits = _ref$min$units === void 0 ? 'day' : _ref$min$units,
|
|
99
|
-
minErrorMessage = _ref$min.errorMessage,
|
|
100
|
-
_ref$max = _ref.max;
|
|
101
|
-
_ref$max = _ref$max === void 0 ? {
|
|
102
|
-
value: 0
|
|
103
|
-
} : _ref$max;
|
|
104
|
-
var maxValue = _ref$max.value,
|
|
105
|
-
_ref$max$units = _ref$max.units,
|
|
106
|
-
maxUnits = _ref$max$units === void 0 ? 'day' : _ref$max$units,
|
|
107
|
-
maxErrorMessage = _ref$max.errorMessage;
|
|
108
|
-
return this.test({
|
|
109
|
-
name: 'distance',
|
|
110
|
-
exclusive: true,
|
|
111
|
-
test: function test() {
|
|
112
|
-
var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
113
|
-
endDate = _ref2.endDate,
|
|
114
|
-
startDate = _ref2.startDate;
|
|
115
|
-
|
|
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
|
|
118
|
-
|
|
119
|
-
if (maxValue && endDate.isAfter(startDate.add(maxValue, maxUnits), 'day')) {
|
|
120
|
-
return new _yup.ValidationError(maxErrorMessage || "The end date must be within ".concat(maxValue, " ").concat(maxUnits).concat(maxValue > 1 ? 's' : '', " of the start date"), {
|
|
121
|
-
startDate: startDate,
|
|
122
|
-
endDate: endDate
|
|
123
|
-
}, this.path);
|
|
124
|
-
} // if we have a min the check distance between end and start
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
if (minValue && endDate.isBefore(startDate.add(minValue, minUnits), 'day')) {
|
|
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"), {
|
|
129
|
-
startDate: startDate,
|
|
130
|
-
endDate: endDate
|
|
131
|
-
}, this.path);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return true;
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
}, {
|
|
139
|
-
key: "min",
|
|
140
|
-
value: function min(_min, message) {
|
|
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);
|
|
143
|
-
return this.test({
|
|
144
|
-
message: message || function (_ref3) {
|
|
145
|
-
var min = _ref3.min;
|
|
146
|
-
return "Date Range must start on or after ".concat(min);
|
|
147
|
-
},
|
|
148
|
-
name: 'min',
|
|
149
|
-
exclusive: true,
|
|
150
|
-
params: {
|
|
151
|
-
min: _min
|
|
152
|
-
},
|
|
153
|
-
test: function test() {
|
|
154
|
-
var _ref4 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
155
|
-
startDate = _ref4.startDate,
|
|
156
|
-
supportedFormats = _ref4.supportedFormats;
|
|
157
|
-
|
|
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
|
|
160
|
-
|
|
161
|
-
var minDate = (0, _moment["default"])(_min, supportedFormats, true);
|
|
162
|
-
return minDate.isValid() && minDate.isSameOrBefore(startDate);
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
}, {
|
|
167
|
-
key: "max",
|
|
168
|
-
value: function max(_max, message) {
|
|
169
|
-
// const maxDate = this.getValidDate(max);
|
|
170
|
-
return this.test({
|
|
171
|
-
message: message || function (_ref5) {
|
|
172
|
-
var max = _ref5.max;
|
|
173
|
-
return "Date Range must end on or before ".concat(max);
|
|
174
|
-
},
|
|
175
|
-
name: 'max',
|
|
176
|
-
exclusive: true,
|
|
177
|
-
params: {
|
|
178
|
-
max: _max
|
|
179
|
-
},
|
|
180
|
-
test: function test() {
|
|
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
|
|
187
|
-
|
|
188
|
-
var maxDate = (0, _moment["default"])(_max, supportedFormats, true);
|
|
189
|
-
return maxDate.isValid() && maxDate.isSameOrAfter(endDate);
|
|
190
|
-
}
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
}, {
|
|
194
|
-
key: "between",
|
|
195
|
-
value: function between(min, max, message) {
|
|
196
|
-
// const minDate = this.getValidDate(min);
|
|
197
|
-
// const maxDate = this.getValidDate(max);
|
|
198
|
-
return this.test({
|
|
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
|
-
},
|
|
204
|
-
name: 'between',
|
|
205
|
-
exclusive: true,
|
|
206
|
-
params: {
|
|
207
|
-
min: min,
|
|
208
|
-
max: max
|
|
209
|
-
},
|
|
210
|
-
test: function test() {
|
|
211
|
-
var _ref8 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
212
|
-
startDate = _ref8.startDate,
|
|
213
|
-
endDate = _ref8.endDate,
|
|
214
|
-
supportedFormats = _ref8.supportedFormats;
|
|
215
|
-
|
|
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);
|
|
219
|
-
return maxDate.isValid() && minDate.isValid() && maxDate.isSameOrAfter(endDate) && minDate.isSameOrBefore(startDate);
|
|
220
|
-
}
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
}, {
|
|
224
|
-
key: "isRequired",
|
|
225
|
-
value: function isRequired() {
|
|
226
|
-
var _isRequired = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
227
|
-
|
|
228
|
-
var msg = arguments.length > 1 ? arguments[1] : undefined;
|
|
229
|
-
return this.test({
|
|
230
|
-
name: 'isRequired',
|
|
231
|
-
exclusive: true,
|
|
232
|
-
message: msg || 'This field is required.',
|
|
233
|
-
test: function test() {
|
|
234
|
-
var _ref9 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
235
|
-
startDate = _ref9.startDate,
|
|
236
|
-
endDate = _ref9.endDate;
|
|
237
|
-
|
|
238
|
-
return !_isRequired || !!(startDate && endDate);
|
|
239
|
-
}
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
}, {
|
|
243
|
-
key: "typeError",
|
|
244
|
-
value: function typeError(_ref10) {
|
|
245
|
-
var message = _ref10.message;
|
|
246
|
-
return this.test({
|
|
247
|
-
name: 'typeError',
|
|
248
|
-
exclusive: true,
|
|
249
|
-
test: function test() {
|
|
250
|
-
var _ref11 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
251
|
-
startDate = _ref11.startDate,
|
|
252
|
-
endDate = _ref11.endDate;
|
|
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
|
|
257
|
-
var errors = [];
|
|
258
|
-
|
|
259
|
-
if ((!startDate || !endDate) && (startDate || endDate)) {
|
|
260
|
-
errors.push(message || 'Start and End Date are required.');
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
if (startDate && endDate && !startDate.isSameOrBefore(endDate)) {
|
|
264
|
-
errors.push('Start date must come before end date.');
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
if (startDate && !startDate.isValid()) {
|
|
268
|
-
errors.push('Start Date is invalid.');
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
if (endDate && !endDate.isValid()) {
|
|
272
|
-
errors.push('End Date is invalid.');
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
return errors.length > 0 ? new _yup.ValidationError(errors, {
|
|
276
|
-
startDate: startDate,
|
|
277
|
-
endDate: endDate
|
|
278
|
-
}, this.path) : true;
|
|
279
|
-
}
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
}, {
|
|
283
|
-
key: "_typeCheck",
|
|
284
|
-
value: function _typeCheck() {
|
|
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();
|
|
289
|
-
}
|
|
290
|
-
}]);
|
|
291
|
-
return DateRangeSchema;
|
|
292
|
-
}(_yup.MixedSchema);
|
|
293
|
-
|
|
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
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
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
|
-
});
|
|
20
|
-
|
|
21
|
-
var _yup = require("yup");
|
|
22
|
-
|
|
23
|
-
var _date = require("./date");
|
|
24
|
-
|
|
25
|
-
var _dateRange = require("./dateRange");
|
|
26
|
-
|
|
27
|
-
var _isRequired = _interopRequireDefault(require("./isRequired"));
|
|
28
|
-
|
|
29
|
-
var _npi = _interopRequireDefault(require("./npi"));
|
|
30
|
-
|
|
31
|
-
var _phone = _interopRequireDefault(require("./phone"));
|
|
32
|
-
|
|
33
|
-
(0, _yup.addMethod)(_yup.array, 'isRequired', _isRequired["default"]);
|
|
34
|
-
(0, _yup.addMethod)(_yup.number, 'isRequired', _isRequired["default"]);
|
|
35
|
-
(0, _yup.addMethod)(_yup.object, 'isRequired', _isRequired["default"]);
|
|
36
|
-
(0, _yup.addMethod)(_yup.string, 'isRequired', _isRequired["default"]);
|
|
37
|
-
(0, _yup.addMethod)(_yup.number, 'npi', _npi["default"]);
|
|
38
|
-
(0, _yup.addMethod)(_yup.string, 'npi', _npi["default"]);
|
|
39
|
-
(0, _yup.addMethod)(_yup.number, 'phone', _phone["default"]);
|
|
40
|
-
(0, _yup.addMethod)(_yup.string, 'phone', _phone["default"]); // Add definitions to yup
|
package/lib/isRequired.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
require("core-js/modules/es.regexp.exec");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports["default"] = void 0;
|
|
9
|
-
|
|
10
|
-
require("core-js/modules/es.regexp.test.js");
|
|
11
|
-
|
|
12
|
-
function isRequired() {
|
|
13
|
-
var isRequired = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
14
|
-
var msg = arguments.length > 1 ? arguments[1] : undefined;
|
|
15
|
-
return this.test({
|
|
16
|
-
name: 'isRequired',
|
|
17
|
-
exclusive: true,
|
|
18
|
-
message: msg || 'This field is required.',
|
|
19
|
-
test: function test(value) {
|
|
20
|
-
if (isRequired) {
|
|
21
|
-
// array and string have custom logic
|
|
22
|
-
if (this.schema.type === 'array') {
|
|
23
|
-
return Array.isArray(value) ? value.length > 0 : value !== undefined;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (this.schema.type === 'string') {
|
|
27
|
-
return value !== undefined && value !== '';
|
|
28
|
-
} // default logic for all other types
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return value !== undefined;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return true;
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
var _default = isRequired;
|
|
40
|
-
exports["default"] = _default;
|
package/lib/npi.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
require("core-js/modules/es.regexp.exec");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports["default"] = void 0;
|
|
9
|
-
|
|
10
|
-
require("core-js/modules/es.regexp.test.js");
|
|
11
|
-
|
|
12
|
-
require("core-js/modules/es.number.parse-int.js");
|
|
13
|
-
|
|
14
|
-
require("core-js/modules/es.number.constructor.js");
|
|
15
|
-
|
|
16
|
-
var INTEGER_REGEX = /^\d*$/;
|
|
17
|
-
|
|
18
|
-
function npi(msg) {
|
|
19
|
-
return this.test({
|
|
20
|
-
name: 'npi',
|
|
21
|
-
exclusive: true,
|
|
22
|
-
message: msg || 'This field is invalid.',
|
|
23
|
-
test: function test(value) {
|
|
24
|
-
if (!value) return true;
|
|
25
|
-
value += ''; // is it a number and 10 digits long
|
|
26
|
-
|
|
27
|
-
if (!INTEGER_REGEX.test(value) || value.length !== 10) {
|
|
28
|
-
return false;
|
|
29
|
-
} // is the first digit 1-4
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
var firstDigit = value.charAt(0);
|
|
33
|
-
|
|
34
|
-
if (['1', '2', '3', '4'].indexOf(firstDigit) < 0) {
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
var digit = Number.parseInt(value.charAt(9), 10);
|
|
39
|
-
value = value.substring(0, 9);
|
|
40
|
-
value = "80840".concat(value);
|
|
41
|
-
var alternate = true;
|
|
42
|
-
var total = 0;
|
|
43
|
-
|
|
44
|
-
for (var i = value.length; i > 0; i--) {
|
|
45
|
-
var next = Number.parseInt(value.charAt(i - 1), 10);
|
|
46
|
-
|
|
47
|
-
if (alternate) {
|
|
48
|
-
next *= 2;
|
|
49
|
-
|
|
50
|
-
if (next > 9) {
|
|
51
|
-
next = next % 10 + 1;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
total += next;
|
|
56
|
-
alternate = !alternate;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
var roundUp = Math.ceil(total / 10) * 10;
|
|
60
|
-
var calculatedCheck = roundUp - total;
|
|
61
|
-
return calculatedCheck === digit;
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
var _default = npi;
|
|
67
|
-
exports["default"] = _default;
|
package/lib/phone.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
require("core-js/modules/es.regexp.exec");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports["default"] = void 0;
|
|
9
|
-
|
|
10
|
-
require("core-js/modules/es.regexp.test.js");
|
|
11
|
-
|
|
12
|
-
var NANP_REGEXP = /^(\+?1[\s.-]?)?\(?[2-9]\d{2}[\s).-]?\s?[2-9]\d{2}[\s.-]?\d{4}$/;
|
|
13
|
-
|
|
14
|
-
function phone(msg) {
|
|
15
|
-
return this.test({
|
|
16
|
-
name: 'phone',
|
|
17
|
-
exclusive: true,
|
|
18
|
-
message: msg || 'This field is invalid',
|
|
19
|
-
test: function test(value) {
|
|
20
|
-
if (!value) return true;
|
|
21
|
-
return NANP_REGEXP.test(value);
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
var _default = phone;
|
|
27
|
-
exports["default"] = _default;
|