@availity/yup 4.1.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 +30 -3
- package/README.md +9 -3
- package/dist/index.d.ts +88 -0
- package/dist/index.js +353 -0
- package/dist/index.mjs +325 -0
- package/jest.config.js +11 -0
- package/package.json +34 -17
- package/project.json +23 -0
- package/src/{date.js → date.ts} +18 -16
- package/src/dateRange.ts +215 -0
- package/src/index.ts +67 -0
- package/src/isRequired.ts +26 -0
- package/src/{npi.js → npi.ts} +5 -1
- package/src/{phone.js → phone.ts} +3 -1
- package/tsconfig.json +5 -0
- package/tsconfig.spec.json +10 -0
- package/LICENSE +0 -21
- package/lib/date.js +0 -172
- package/lib/dateRange.js +0 -274
- package/lib/index.js +0 -40
- package/lib/isRequired.js +0 -35
- package/lib/npi.js +0 -62
- package/lib/phone.js +0 -22
- package/src/dateRange.js +0 -184
- package/src/index.js +0 -20
- package/src/isRequired.js +0 -22
- package/types/date.d.ts +0 -21
- package/types/dateRange.d.ts +0 -40
- package/types/index.d.ts +0 -25
package/.eslintrc.yml
ADDED
package/CHANGELOG.md
CHANGED
|
@@ -1,7 +1,34 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
|
+
|
|
5
|
+
# [5.0.0](https://github.com/Availity/sdk-js/compare/@availity/yup@4.2.0...@availity/yup@5.0.0) (2022-04-28)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
* build!: switch from lerna to nx and compile to esm with tsup ([c586085](https://github.com/Availity/sdk-js/commit/c5860856ca96b743a0653d335ea00f0889132f7f))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### BREAKING CHANGES
|
|
12
|
+
|
|
13
|
+
* Drop Internet Explorer support
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# 4.2.0 (2021-12-21)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* **yup:** conditional logic fix ([3679957](https://github.com/Availity/sdk-js/commit/36799574f86674e1a41228c10bfba8d303958e02))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Features
|
|
26
|
+
|
|
27
|
+
* **yup:** convert to ts and fix undefined class property ([f5a3a4f](https://github.com/Availity/sdk-js/commit/f5a3a4f944a0ae281e0eaabf3b6a38659a2acc71))
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
2
31
|
|
|
3
|
-
All notable changes to this project will be documented in this file.
|
|
4
|
-
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
32
|
|
|
6
33
|
# 4.1.0 (2021-11-18)
|
|
7
34
|
|
package/README.md
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
# yup
|
|
1
|
+
# @availity/yup
|
|
2
2
|
|
|
3
|
-
> Method extensions for
|
|
3
|
+
> Method extensions for [yup](https://github.com/jquense/yup)
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/@availity/yup)
|
|
6
|
+
[](https://www.npmjs.com/package/@availity/yup)
|
|
7
|
+
[](https://github.com/Availity/sdk-js/blob/master/packages/yup/package.json)
|
|
6
8
|
|
|
7
9
|
## Install
|
|
8
10
|
|
|
@@ -18,4 +20,8 @@ npm install @availity/yup yup
|
|
|
18
20
|
yarn add @availity/yup yup
|
|
19
21
|
```
|
|
20
22
|
|
|
21
|
-
|
|
23
|
+
> You will need to also install [moment](https://www.npmjs.com/package/moment) if you plan on using the `date` or `dateRange` schemas
|
|
24
|
+
|
|
25
|
+
## Documentation
|
|
26
|
+
|
|
27
|
+
Check out more documentation at [availity.github.io](https://availity.github.io/sdk-js/resources/yup)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Maybe, AnyObject, Optionals } from 'yup/lib/types';
|
|
2
|
+
import BaseSchema, { AnySchema } from 'yup/lib/schema';
|
|
3
|
+
import { TypeOf, Asserts } from 'yup/lib/util/types';
|
|
4
|
+
import { ObjectShape, TypeOfShape, AssertsShape } from 'yup/lib/object';
|
|
5
|
+
import Lazy from 'yup/lib/Lazy';
|
|
6
|
+
import { MixedSchema } from 'yup';
|
|
7
|
+
import moment, { Moment, unitOfTime } from 'moment';
|
|
8
|
+
|
|
9
|
+
declare class AvDateSchema extends MixedSchema<Moment> {
|
|
10
|
+
format: string;
|
|
11
|
+
constructor({ format }?: Options$1);
|
|
12
|
+
_typeCheck(value: Moment & {
|
|
13
|
+
_i: string;
|
|
14
|
+
}): value is Moment & {
|
|
15
|
+
_i: string;
|
|
16
|
+
};
|
|
17
|
+
getValidDate(value: string | Date | Moment): moment.Moment;
|
|
18
|
+
min(min: string, message?: string): this;
|
|
19
|
+
max(max: string, message?: string): this;
|
|
20
|
+
isRequired(isRequired?: boolean, msg?: string): this;
|
|
21
|
+
between(min: string, max: string, msg?: string, inclusivity?: Inclusivity): this;
|
|
22
|
+
}
|
|
23
|
+
declare type Inclusivity = '()' | '[)' | '(]' | '[]';
|
|
24
|
+
declare type Options$1 = {
|
|
25
|
+
format?: string;
|
|
26
|
+
};
|
|
27
|
+
declare const avDate: (opts?: Options$1 | undefined) => AvDateSchema;
|
|
28
|
+
|
|
29
|
+
declare class DateRangeSchema extends MixedSchema<DateRange> {
|
|
30
|
+
startKey: string;
|
|
31
|
+
endKey: string;
|
|
32
|
+
format: string;
|
|
33
|
+
constructor(options?: Options);
|
|
34
|
+
getValidDate(value: string | Date | Moment): moment.Moment;
|
|
35
|
+
distance({ min: { value: minValue, units: minUnits, errorMessage: minErrorMessage }, max: { value: maxValue, units: maxUnits, errorMessage: maxErrorMessage }, }?: DistanceOptions): this;
|
|
36
|
+
min(min: string, message?: string): this;
|
|
37
|
+
max(max: string, message?: string): this;
|
|
38
|
+
between(min: string, max: string, message?: string): this;
|
|
39
|
+
isRequired(isRequired?: boolean, msg?: string): this;
|
|
40
|
+
typeError({ message }: {
|
|
41
|
+
message: string;
|
|
42
|
+
}): this;
|
|
43
|
+
_typeCheck(range?: {
|
|
44
|
+
startDate?: Moment;
|
|
45
|
+
endDate?: Moment;
|
|
46
|
+
}): range is DateRange;
|
|
47
|
+
}
|
|
48
|
+
declare type Options = {
|
|
49
|
+
startKey?: string;
|
|
50
|
+
endKey?: string;
|
|
51
|
+
format?: string;
|
|
52
|
+
};
|
|
53
|
+
declare type DateRange = {
|
|
54
|
+
startDate?: Moment;
|
|
55
|
+
endDate?: Moment;
|
|
56
|
+
supportedFormats?: string[];
|
|
57
|
+
};
|
|
58
|
+
declare type DistanceValue = {
|
|
59
|
+
value: number;
|
|
60
|
+
units?: unitOfTime.DurationConstructor;
|
|
61
|
+
errorMessage?: string;
|
|
62
|
+
};
|
|
63
|
+
declare type DistanceOptions = {
|
|
64
|
+
min?: DistanceValue;
|
|
65
|
+
max?: DistanceValue;
|
|
66
|
+
};
|
|
67
|
+
declare const dateRange: (opts?: Options | undefined) => DateRangeSchema;
|
|
68
|
+
|
|
69
|
+
declare module 'yup' {
|
|
70
|
+
interface StringSchema<TType extends Maybe<string> = string | undefined, TContext extends AnyObject = AnyObject, TOut extends TType = TType> extends BaseSchema<TType, TContext, TOut> {
|
|
71
|
+
isRequired(required?: boolean, errorMessage?: string): StringSchema<TType, TContext>;
|
|
72
|
+
npi(errorMessage?: string): StringSchema<TType, TContext>;
|
|
73
|
+
phone(errorMessage?: string): StringSchema<TType, TContext>;
|
|
74
|
+
}
|
|
75
|
+
interface NumberSchema<TType extends Maybe<number> = number | undefined, TContext extends AnyObject = AnyObject, TOut extends TType = TType> extends BaseSchema<TType, TContext, TOut> {
|
|
76
|
+
isRequired(required?: boolean, errorMessage?: string): NumberSchema<TType, TContext, TOut>;
|
|
77
|
+
npi(errorMessage?: string): NumberSchema<TType, TContext, TOut>;
|
|
78
|
+
phone(errorMessage?: string): NumberSchema<TType, TContext, TOut>;
|
|
79
|
+
}
|
|
80
|
+
interface ArraySchema<T extends AnySchema | Lazy<any, any>, C extends AnyObject = AnyObject, TIn extends Maybe<TypeOf<T>[]> = TypeOf<T>[] | undefined, TOut extends Maybe<Asserts<T>[]> = Asserts<T>[] | Optionals<TIn>> extends BaseSchema<TIn, C, TOut> {
|
|
81
|
+
isRequired(required?: boolean, errorMessage?: string): ArraySchema<T, C, TIn, TOut>;
|
|
82
|
+
}
|
|
83
|
+
interface ObjectSchema<TShape extends ObjectShape, TContext extends AnyObject = AnyObject, TIn extends Maybe<TypeOfShape<TShape>> = TypeOfShape<TShape>, TOut extends Maybe<AssertsShape<TShape>> = AssertsShape<TShape> | Optionals<TIn>> extends BaseSchema<TIn, TContext, TOut> {
|
|
84
|
+
isRequired(required?: boolean, errorMessage?: string): ObjectSchema<TShape, TContext, TIn, TOut>;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export { avDate, dateRange };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
|
|
22
|
+
// src/index.ts
|
|
23
|
+
var src_exports = {};
|
|
24
|
+
__export(src_exports, {
|
|
25
|
+
avDate: () => avDate,
|
|
26
|
+
dateRange: () => dateRange
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(src_exports);
|
|
29
|
+
var import_yup3 = require("yup");
|
|
30
|
+
|
|
31
|
+
// src/date.ts
|
|
32
|
+
var import_yup = require("yup");
|
|
33
|
+
var import_moment = __toESM(require("moment"));
|
|
34
|
+
var formats = ["YYYY-MM-DD", "MMDDYYYY", "YYYYMMDD", "MM-DD-YYYY"];
|
|
35
|
+
var AvDateSchema = class extends import_yup.MixedSchema {
|
|
36
|
+
constructor({ format = "MM/DD/YYYY" } = {}) {
|
|
37
|
+
super({
|
|
38
|
+
type: "avDate"
|
|
39
|
+
});
|
|
40
|
+
this.format = format;
|
|
41
|
+
this.withMutation((schema) => {
|
|
42
|
+
if (!schema.tests.some((test) => {
|
|
43
|
+
var _a;
|
|
44
|
+
return ((_a = test == null ? void 0 : test.OPTIONS) == null ? void 0 : _a.name) === "typeError";
|
|
45
|
+
})) {
|
|
46
|
+
super.typeError("Date is invalid.");
|
|
47
|
+
}
|
|
48
|
+
schema.transform(function mutate(value) {
|
|
49
|
+
return schema.getValidDate(value);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
_typeCheck(value) {
|
|
54
|
+
return value.isValid() || value._i === "";
|
|
55
|
+
}
|
|
56
|
+
getValidDate(value) {
|
|
57
|
+
return (0, import_moment.default)(value, [this.format, ...formats], true);
|
|
58
|
+
}
|
|
59
|
+
min(min, message) {
|
|
60
|
+
const minDate = this.getValidDate(min);
|
|
61
|
+
return this.test({
|
|
62
|
+
message: message || `Date must be ${minDate.format(this.format)} or later.`,
|
|
63
|
+
name: "min",
|
|
64
|
+
exclusive: true,
|
|
65
|
+
params: { min },
|
|
66
|
+
test(value) {
|
|
67
|
+
if (!min || !minDate.isValid()) {
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
return value === null || minDate.isSameOrBefore(value);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
max(max, message) {
|
|
75
|
+
const maxDate = this.getValidDate(max);
|
|
76
|
+
return this.test({
|
|
77
|
+
message: message || `Date must be ${maxDate.format(this.format)} or earlier.`,
|
|
78
|
+
name: "max",
|
|
79
|
+
exclusive: true,
|
|
80
|
+
params: { max },
|
|
81
|
+
test(value) {
|
|
82
|
+
if (!max || !maxDate.isValid()) {
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
return value === null || maxDate.isSameOrAfter(value);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
isRequired(isRequired2 = true, msg) {
|
|
90
|
+
return this.test({
|
|
91
|
+
name: "isRequired",
|
|
92
|
+
exclusive: true,
|
|
93
|
+
message: msg || "This field is required.",
|
|
94
|
+
test(value) {
|
|
95
|
+
if (!isRequired2) {
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
return value !== void 0;
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
between(min, max, msg, inclusivity = "()") {
|
|
103
|
+
const minDate = this.getValidDate(min);
|
|
104
|
+
const maxDate = this.getValidDate(max);
|
|
105
|
+
return this.test({
|
|
106
|
+
name: "between",
|
|
107
|
+
exclusive: true,
|
|
108
|
+
message: msg || `Date must be between ${minDate.format(this.format)} and ${maxDate.format(this.format)}.`,
|
|
109
|
+
test(value) {
|
|
110
|
+
if (!value || !min || !max || !minDate.isValid() || !maxDate.isValid()) {
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
return value.isBetween(minDate, maxDate, void 0, inclusivity);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
var avDate = (opts) => new AvDateSchema(opts);
|
|
119
|
+
|
|
120
|
+
// src/dateRange.ts
|
|
121
|
+
var import_yup2 = require("yup");
|
|
122
|
+
var import_moment2 = __toESM(require("moment"));
|
|
123
|
+
var import_get = __toESM(require("lodash/get"));
|
|
124
|
+
var import_merge = __toESM(require("lodash/merge"));
|
|
125
|
+
var defaultOptions = {
|
|
126
|
+
startKey: "startDate",
|
|
127
|
+
endKey: "endDate",
|
|
128
|
+
format: "MM/DD/YYYY"
|
|
129
|
+
};
|
|
130
|
+
var formats2 = ["YYYY-MM-DD", "MMDDYYYY", "YYYYMMDD"];
|
|
131
|
+
var DateRangeSchema = class extends import_yup2.MixedSchema {
|
|
132
|
+
constructor(options) {
|
|
133
|
+
super({
|
|
134
|
+
type: "dateRange"
|
|
135
|
+
});
|
|
136
|
+
const { startKey, endKey, format } = (0, import_merge.default)({}, defaultOptions, options);
|
|
137
|
+
this.startKey = startKey;
|
|
138
|
+
this.endKey = endKey;
|
|
139
|
+
this.format = format;
|
|
140
|
+
this.withMutation((schema) => {
|
|
141
|
+
schema.transform(function mutate(value) {
|
|
142
|
+
const start = (0, import_get.default)(value, startKey);
|
|
143
|
+
const end = (0, import_get.default)(value, endKey);
|
|
144
|
+
return {
|
|
145
|
+
startDate: start ? schema.getValidDate(start) : start,
|
|
146
|
+
endDate: end ? schema.getValidDate(end) : end,
|
|
147
|
+
supportedFormats: [schema.format, ...formats2]
|
|
148
|
+
};
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
getValidDate(value) {
|
|
153
|
+
return (0, import_moment2.default)(value, [this.format, ...formats2], true);
|
|
154
|
+
}
|
|
155
|
+
distance({
|
|
156
|
+
min: { value: minValue, units: minUnits = "day", errorMessage: minErrorMessage } = { value: 0 },
|
|
157
|
+
max: { value: maxValue, units: maxUnits = "day", errorMessage: maxErrorMessage } = { value: 0 }
|
|
158
|
+
} = {}) {
|
|
159
|
+
return this.test({
|
|
160
|
+
name: "distance",
|
|
161
|
+
exclusive: true,
|
|
162
|
+
test({ endDate, startDate } = {}) {
|
|
163
|
+
if (!minValue && !maxValue || !startDate || !endDate)
|
|
164
|
+
return true;
|
|
165
|
+
if (maxValue && endDate.isAfter(startDate.add(maxValue, maxUnits), "day")) {
|
|
166
|
+
return new import_yup2.ValidationError(maxErrorMessage || `The end date must be within ${maxValue} ${maxUnits}${maxValue > 1 ? "s" : ""} of the start date`, {
|
|
167
|
+
startDate,
|
|
168
|
+
endDate
|
|
169
|
+
}, this.path);
|
|
170
|
+
}
|
|
171
|
+
if (minValue && endDate.isBefore(startDate.add(minValue, minUnits), "day")) {
|
|
172
|
+
return new import_yup2.ValidationError(minErrorMessage || `The end date must be greater than ${minValue} ${minUnits}${minValue > 1 ? "s" : ""} of the start date`, { startDate, endDate }, this.path);
|
|
173
|
+
}
|
|
174
|
+
return true;
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
min(min, message) {
|
|
179
|
+
return this.test({
|
|
180
|
+
message: message || (({ min: min2 }) => `Date Range must start on or after ${min2}`),
|
|
181
|
+
name: "min",
|
|
182
|
+
exclusive: true,
|
|
183
|
+
params: { min },
|
|
184
|
+
test({ startDate, supportedFormats } = {}) {
|
|
185
|
+
if (!startDate || !min)
|
|
186
|
+
return true;
|
|
187
|
+
const minDate = (0, import_moment2.default)(min, supportedFormats, true);
|
|
188
|
+
return minDate.isValid() && minDate.isSameOrBefore(startDate);
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
max(max, message) {
|
|
193
|
+
return this.test({
|
|
194
|
+
message: message || (({ max: max2 }) => `Date Range must end on or before ${max2}`),
|
|
195
|
+
name: "max",
|
|
196
|
+
exclusive: true,
|
|
197
|
+
params: { max },
|
|
198
|
+
test({ endDate, supportedFormats } = {}) {
|
|
199
|
+
if (!endDate || !max)
|
|
200
|
+
return true;
|
|
201
|
+
const maxDate = (0, import_moment2.default)(max, supportedFormats, true);
|
|
202
|
+
return maxDate.isValid() && maxDate.isSameOrAfter(endDate);
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
between(min, max, message) {
|
|
207
|
+
return this.test({
|
|
208
|
+
message: message || (({ min: min2, max: max2 }) => `Date Range must be between ${min2} and ${max2}`),
|
|
209
|
+
name: "between",
|
|
210
|
+
exclusive: true,
|
|
211
|
+
params: { min, max },
|
|
212
|
+
test({ startDate, endDate, supportedFormats } = {}) {
|
|
213
|
+
if (!startDate || !endDate || !min || !max)
|
|
214
|
+
return true;
|
|
215
|
+
const minDate = (0, import_moment2.default)(min, supportedFormats, true);
|
|
216
|
+
const maxDate = (0, import_moment2.default)(max, supportedFormats, true);
|
|
217
|
+
return maxDate.isValid() && minDate.isValid() && maxDate.isSameOrAfter(endDate) && minDate.isSameOrBefore(startDate);
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
isRequired(isRequired2 = true, msg) {
|
|
222
|
+
return this.test({
|
|
223
|
+
name: "isRequired",
|
|
224
|
+
exclusive: true,
|
|
225
|
+
message: msg || "This field is required.",
|
|
226
|
+
test({ startDate, endDate } = {}) {
|
|
227
|
+
return !isRequired2 || !!(startDate && endDate);
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
typeError({ message }) {
|
|
232
|
+
return this.test({
|
|
233
|
+
name: "typeError",
|
|
234
|
+
exclusive: true,
|
|
235
|
+
test({ startDate, endDate } = {}) {
|
|
236
|
+
const errors = [];
|
|
237
|
+
if ((!startDate || !endDate) && (startDate || endDate)) {
|
|
238
|
+
errors.push(message || "Start and End Date are required.");
|
|
239
|
+
}
|
|
240
|
+
if (startDate && endDate && !startDate.isSameOrBefore(endDate)) {
|
|
241
|
+
errors.push("Start date must come before end date.");
|
|
242
|
+
}
|
|
243
|
+
if (startDate && !startDate.isValid()) {
|
|
244
|
+
errors.push("Start Date is invalid.");
|
|
245
|
+
}
|
|
246
|
+
if (endDate && !endDate.isValid()) {
|
|
247
|
+
errors.push("End Date is invalid.");
|
|
248
|
+
}
|
|
249
|
+
return errors.length > 0 ? new import_yup2.ValidationError(errors, { startDate, endDate }, this.path) : true;
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
_typeCheck(range = {}) {
|
|
254
|
+
const { startDate, endDate } = range;
|
|
255
|
+
return !!startDate && !!endDate && startDate.isValid() && endDate.isValid();
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
var dateRange = (opts) => new DateRangeSchema(opts);
|
|
259
|
+
|
|
260
|
+
// src/isRequired.ts
|
|
261
|
+
function isRequired(isRequired2 = true, msg) {
|
|
262
|
+
return this.test({
|
|
263
|
+
name: "isRequired",
|
|
264
|
+
exclusive: true,
|
|
265
|
+
message: msg || "This field is required.",
|
|
266
|
+
test(value) {
|
|
267
|
+
if (isRequired2) {
|
|
268
|
+
if (this.schema.type === "array") {
|
|
269
|
+
return Array.isArray(value) ? value.length > 0 : value !== void 0;
|
|
270
|
+
}
|
|
271
|
+
if (this.schema.type === "string") {
|
|
272
|
+
return value !== void 0 && value !== "";
|
|
273
|
+
}
|
|
274
|
+
return value !== void 0;
|
|
275
|
+
}
|
|
276
|
+
return true;
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
var isRequired_default = isRequired;
|
|
281
|
+
|
|
282
|
+
// src/npi.ts
|
|
283
|
+
var INTEGER_REGEX = /^\d*$/;
|
|
284
|
+
function npi(msg) {
|
|
285
|
+
return this.test({
|
|
286
|
+
name: "npi",
|
|
287
|
+
exclusive: true,
|
|
288
|
+
message: msg || "This field is invalid.",
|
|
289
|
+
test(value) {
|
|
290
|
+
if (!value)
|
|
291
|
+
return true;
|
|
292
|
+
value += "";
|
|
293
|
+
if (!INTEGER_REGEX.test(value) || value.length !== 10) {
|
|
294
|
+
return false;
|
|
295
|
+
}
|
|
296
|
+
const firstDigit = value.charAt(0);
|
|
297
|
+
if (["1", "2", "3", "4"].indexOf(firstDigit) < 0) {
|
|
298
|
+
return false;
|
|
299
|
+
}
|
|
300
|
+
const digit = Number.parseInt(value.charAt(9), 10);
|
|
301
|
+
value = value.substring(0, 9);
|
|
302
|
+
value = `80840${value}`;
|
|
303
|
+
let alternate = true;
|
|
304
|
+
let total = 0;
|
|
305
|
+
for (let i = value.length; i > 0; i--) {
|
|
306
|
+
let next = Number.parseInt(value.charAt(i - 1), 10);
|
|
307
|
+
if (alternate) {
|
|
308
|
+
next *= 2;
|
|
309
|
+
if (next > 9) {
|
|
310
|
+
next = next % 10 + 1;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
total += next;
|
|
314
|
+
alternate = !alternate;
|
|
315
|
+
}
|
|
316
|
+
const roundUp = Math.ceil(total / 10) * 10;
|
|
317
|
+
const calculatedCheck = roundUp - total;
|
|
318
|
+
return calculatedCheck === digit;
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
var npi_default = npi;
|
|
323
|
+
|
|
324
|
+
// src/phone.ts
|
|
325
|
+
var NANP_REGEXP = /^(\+?1[\s.-]?)?\(?[2-9]\d{2}[\s).-]?\s?[2-9]\d{2}[\s.-]?\d{4}$/;
|
|
326
|
+
function phone(msg) {
|
|
327
|
+
return this.test({
|
|
328
|
+
name: "phone",
|
|
329
|
+
exclusive: true,
|
|
330
|
+
message: msg || "This field is invalid",
|
|
331
|
+
test(value) {
|
|
332
|
+
if (!value)
|
|
333
|
+
return true;
|
|
334
|
+
return NANP_REGEXP.test(value);
|
|
335
|
+
}
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
var phone_default = phone;
|
|
339
|
+
|
|
340
|
+
// src/index.ts
|
|
341
|
+
(0, import_yup3.addMethod)(import_yup3.array, "isRequired", isRequired_default);
|
|
342
|
+
(0, import_yup3.addMethod)(import_yup3.number, "isRequired", isRequired_default);
|
|
343
|
+
(0, import_yup3.addMethod)(import_yup3.object, "isRequired", isRequired_default);
|
|
344
|
+
(0, import_yup3.addMethod)(import_yup3.string, "isRequired", isRequired_default);
|
|
345
|
+
(0, import_yup3.addMethod)(import_yup3.number, "npi", npi_default);
|
|
346
|
+
(0, import_yup3.addMethod)(import_yup3.string, "npi", npi_default);
|
|
347
|
+
(0, import_yup3.addMethod)(import_yup3.number, "phone", phone_default);
|
|
348
|
+
(0, import_yup3.addMethod)(import_yup3.string, "phone", phone_default);
|
|
349
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
350
|
+
0 && (module.exports = {
|
|
351
|
+
avDate,
|
|
352
|
+
dateRange
|
|
353
|
+
});
|