@availity/yup 4.1.0 → 4.1.1-alpha.2
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/lib/dateRange.js +14 -24
- package/package.json +2 -2
- package/src/dateRange.js +16 -21
- package/types/date.d.ts +15 -17
- package/types/dateRange.d.ts +31 -33
- package/types/index.d.ts +10 -7
package/lib/dateRange.js
CHANGED
|
@@ -13,8 +13,6 @@ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/cl
|
|
|
13
13
|
|
|
14
14
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
15
15
|
|
|
16
|
-
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
17
|
-
|
|
18
16
|
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
19
17
|
|
|
20
18
|
var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
|
|
@@ -29,11 +27,11 @@ var _merge2 = _interopRequireDefault(require("lodash/merge"));
|
|
|
29
27
|
|
|
30
28
|
var defaultOptions = {
|
|
31
29
|
startKey: 'startDate',
|
|
32
|
-
endKey: 'endDate'
|
|
33
|
-
format: 'MM/DD/YYYY'
|
|
30
|
+
endKey: 'endDate'
|
|
34
31
|
};
|
|
35
32
|
var defaultValue = {};
|
|
36
|
-
var
|
|
33
|
+
var displayFormat = 'MM/DD/YYYY';
|
|
34
|
+
var formats = [displayFormat, 'YYYY-MM-DD', 'MMDDYYYY', 'YYYYMMDD'];
|
|
37
35
|
|
|
38
36
|
var DateRangeSchema = /*#__PURE__*/function (_MixedSchema) {
|
|
39
37
|
(0, _inherits2["default"])(DateRangeSchema, _MixedSchema);
|
|
@@ -50,13 +48,10 @@ var DateRangeSchema = /*#__PURE__*/function (_MixedSchema) {
|
|
|
50
48
|
|
|
51
49
|
var _merge = (0, _merge2["default"])({}, defaultOptions, options),
|
|
52
50
|
startKey = _merge.startKey,
|
|
53
|
-
endKey = _merge.endKey
|
|
54
|
-
format = _merge.format;
|
|
51
|
+
endKey = _merge.endKey;
|
|
55
52
|
|
|
56
53
|
_this.startKey = startKey;
|
|
57
|
-
_this.endKey = endKey;
|
|
58
|
-
_this.format = format;
|
|
59
|
-
_this.getValidDate = _this.getValidDate.bind((0, _assertThisInitialized2["default"])(_this));
|
|
54
|
+
_this.endKey = endKey; // this.format = format;
|
|
60
55
|
|
|
61
56
|
_this.withMutation(function (schema) {
|
|
62
57
|
schema.transform(function mutate(value) {
|
|
@@ -86,7 +81,7 @@ var DateRangeSchema = /*#__PURE__*/function (_MixedSchema) {
|
|
|
86
81
|
(0, _createClass2["default"])(DateRangeSchema, [{
|
|
87
82
|
key: "getValidDate",
|
|
88
83
|
value: function getValidDate(value) {
|
|
89
|
-
return (0, _moment["default"])(value,
|
|
84
|
+
return (0, _moment["default"])(value, formats, true);
|
|
90
85
|
}
|
|
91
86
|
}, {
|
|
92
87
|
key: "distance",
|
|
@@ -136,10 +131,10 @@ var DateRangeSchema = /*#__PURE__*/function (_MixedSchema) {
|
|
|
136
131
|
}, {
|
|
137
132
|
key: "min",
|
|
138
133
|
value: function min(_min, message) {
|
|
139
|
-
|
|
134
|
+
// it works for date, but not daterange. maybe that can tell us more about what is going on
|
|
140
135
|
var minDate = this.getValidDate(_min);
|
|
141
136
|
return this.test({
|
|
142
|
-
message: message || "Date Range must start on or after ".concat(minDate.format(
|
|
137
|
+
message: message || "Date Range must start on or after ".concat(minDate.format(displayFormat)),
|
|
143
138
|
name: 'min',
|
|
144
139
|
exclusive: true,
|
|
145
140
|
params: {
|
|
@@ -149,21 +144,17 @@ var DateRangeSchema = /*#__PURE__*/function (_MixedSchema) {
|
|
|
149
144
|
var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultValue,
|
|
150
145
|
startDate = _ref3.startDate;
|
|
151
146
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
return minDate.isValid() && minDate.isSameOrBefore(startDate);
|
|
147
|
+
// is minDate valid and is it before the given date
|
|
148
|
+
return !startDate || !_min ? true : minDate.isValid() && minDate.isSameOrBefore(startDate);
|
|
157
149
|
}
|
|
158
150
|
});
|
|
159
151
|
}
|
|
160
152
|
}, {
|
|
161
153
|
key: "max",
|
|
162
154
|
value: function max(_max, message) {
|
|
163
|
-
var format = this.format;
|
|
164
155
|
var maxDate = this.getValidDate(_max);
|
|
165
156
|
return this.test({
|
|
166
|
-
message: message || "Date Range must end on or before ".concat(maxDate.format(
|
|
157
|
+
message: message || "Date Range must end on or before ".concat(maxDate.format(displayFormat)),
|
|
167
158
|
name: 'max',
|
|
168
159
|
exclusive: true,
|
|
169
160
|
params: {
|
|
@@ -173,19 +164,18 @@ var DateRangeSchema = /*#__PURE__*/function (_MixedSchema) {
|
|
|
173
164
|
var _ref4 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultValue,
|
|
174
165
|
endDate = _ref4.endDate;
|
|
175
166
|
|
|
176
|
-
|
|
177
|
-
return maxDate.isValid() && maxDate.isSameOrAfter(endDate);
|
|
167
|
+
// is maxDate valid and is it after the given date
|
|
168
|
+
return !endDate || !_max ? true : maxDate.isValid() && maxDate.isSameOrAfter(endDate);
|
|
178
169
|
}
|
|
179
170
|
});
|
|
180
171
|
}
|
|
181
172
|
}, {
|
|
182
173
|
key: "between",
|
|
183
174
|
value: function between(min, max, message) {
|
|
184
|
-
var format = this.format;
|
|
185
175
|
var minDate = this.getValidDate(min);
|
|
186
176
|
var maxDate = this.getValidDate(max);
|
|
187
177
|
return this.test({
|
|
188
|
-
message: message || "Date Range must be between ".concat(minDate.format(
|
|
178
|
+
message: message || "Date Range must be between ".concat(minDate.format(displayFormat), " and ").concat(maxDate.format(displayFormat)),
|
|
189
179
|
name: 'between',
|
|
190
180
|
exclusive: true,
|
|
191
181
|
params: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@availity/yup",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.1-alpha.2+3679957",
|
|
4
4
|
"description": "Additional Methods for Yup validation library",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "src/index.js",
|
|
@@ -27,5 +27,5 @@
|
|
|
27
27
|
"moment": "^2.24.0",
|
|
28
28
|
"yup": "^0.32.9"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "36799574f86674e1a41228c10bfba8d303958e02"
|
|
31
31
|
}
|
package/src/dateRange.js
CHANGED
|
@@ -6,12 +6,13 @@ import merge from 'lodash/merge';
|
|
|
6
6
|
const defaultOptions = {
|
|
7
7
|
startKey: 'startDate',
|
|
8
8
|
endKey: 'endDate',
|
|
9
|
-
format: 'MM/DD/YYYY',
|
|
10
9
|
};
|
|
11
10
|
|
|
12
11
|
const defaultValue = {};
|
|
13
12
|
|
|
14
|
-
const
|
|
13
|
+
const displayFormat = 'MM/DD/YYYY';
|
|
14
|
+
|
|
15
|
+
const formats = [displayFormat, 'YYYY-MM-DD', 'MMDDYYYY', 'YYYYMMDD'];
|
|
15
16
|
|
|
16
17
|
export default class DateRangeSchema extends MixedSchema {
|
|
17
18
|
constructor(options) {
|
|
@@ -19,12 +20,11 @@ export default class DateRangeSchema extends MixedSchema {
|
|
|
19
20
|
type: 'dateRange',
|
|
20
21
|
});
|
|
21
22
|
|
|
22
|
-
const { startKey, endKey
|
|
23
|
+
const { startKey, endKey } = merge({}, defaultOptions, options);
|
|
23
24
|
|
|
24
25
|
this.startKey = startKey;
|
|
25
26
|
this.endKey = endKey;
|
|
26
|
-
this.format = format;
|
|
27
|
-
this.getValidDate = this.getValidDate.bind(this);
|
|
27
|
+
// this.format = format;
|
|
28
28
|
|
|
29
29
|
this.withMutation((schema) => {
|
|
30
30
|
schema.transform(function mutate(value) {
|
|
@@ -46,7 +46,7 @@ export default class DateRangeSchema extends MixedSchema {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
getValidDate(value) {
|
|
49
|
-
return moment(value,
|
|
49
|
+
return moment(value, formats, true);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
distance({
|
|
@@ -85,48 +85,43 @@ export default class DateRangeSchema extends MixedSchema {
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
min(min, message) {
|
|
88
|
-
|
|
89
|
-
|
|
88
|
+
// it works for date, but not daterange. maybe that can tell us more about what is going on
|
|
90
89
|
const minDate = this.getValidDate(min);
|
|
90
|
+
|
|
91
91
|
return this.test({
|
|
92
|
-
message: message || `Date Range must start on or after ${minDate.format(
|
|
92
|
+
message: message || `Date Range must start on or after ${minDate.format(displayFormat)}`,
|
|
93
93
|
name: 'min',
|
|
94
94
|
exclusive: true,
|
|
95
95
|
params: { min },
|
|
96
96
|
test({ startDate } = defaultValue) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
return minDate.isValid() && minDate.isSameOrBefore(startDate);
|
|
97
|
+
// is minDate valid and is it before the given date
|
|
98
|
+
return !startDate || !min ? true : minDate.isValid() && minDate.isSameOrBefore(startDate);
|
|
101
99
|
},
|
|
102
100
|
});
|
|
103
101
|
}
|
|
104
102
|
|
|
105
103
|
max(max, message) {
|
|
106
|
-
const { format } = this;
|
|
107
|
-
|
|
108
104
|
const maxDate = this.getValidDate(max);
|
|
109
105
|
|
|
110
106
|
return this.test({
|
|
111
|
-
message: message || `Date Range must end on or before ${maxDate.format(
|
|
107
|
+
message: message || `Date Range must end on or before ${maxDate.format(displayFormat)}`,
|
|
112
108
|
name: 'max',
|
|
113
109
|
exclusive: true,
|
|
114
110
|
params: { max },
|
|
115
111
|
test({ endDate } = defaultValue) {
|
|
116
|
-
|
|
117
|
-
return maxDate.isValid() && maxDate.isSameOrAfter(endDate);
|
|
112
|
+
// is maxDate valid and is it after the given date
|
|
113
|
+
return !endDate || !max ? true : maxDate.isValid() && maxDate.isSameOrAfter(endDate);
|
|
118
114
|
},
|
|
119
115
|
});
|
|
120
116
|
}
|
|
121
117
|
|
|
122
118
|
between(min, max, message) {
|
|
123
|
-
const { format } = this;
|
|
124
|
-
|
|
125
119
|
const minDate = this.getValidDate(min);
|
|
126
120
|
const maxDate = this.getValidDate(max);
|
|
127
121
|
|
|
128
122
|
return this.test({
|
|
129
|
-
message:
|
|
123
|
+
message:
|
|
124
|
+
message || `Date Range must be between ${minDate.format(displayFormat)} and ${maxDate.format(displayFormat)}`,
|
|
130
125
|
name: 'between',
|
|
131
126
|
exclusive: true,
|
|
132
127
|
params: { min, max },
|
package/types/date.d.ts
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { MixedSchema } from 'yup';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
interface AvDateSchema<T extends string | null | undefined = string> extends MixedSchema<T> {
|
|
9
|
-
min(date: string, errorMessage?: string): DateRangeSchema<T>;
|
|
10
|
-
max(date: string, errorMessage?: string): DateRangeSchema<T>;
|
|
11
|
-
between(minDate: string, maxDate: string, errorMessage?: string): AvDateSchema<T>;
|
|
12
|
-
isRequired(required?: boolean, errorMessage?: string): AvDateSchema<T>;
|
|
13
|
-
}
|
|
3
|
+
interface DateOpts {
|
|
4
|
+
format?: string | 'MM/DD/YYYY';
|
|
5
|
+
}
|
|
14
6
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
7
|
+
interface AvDateSchema<T extends string | null | undefined = string> extends MixedSchema<T> {
|
|
8
|
+
min(date: string, errorMessage?: string): DateRangeSchema<T>;
|
|
9
|
+
max(date: string, errorMessage?: string): DateRangeSchema<T>;
|
|
10
|
+
between(minDate: string, maxDate: string, errorMessage?: string): AvDateSchema<T>;
|
|
11
|
+
isRequired(required?: boolean, errorMessage?: string): AvDateSchema<T>;
|
|
12
|
+
}
|
|
19
13
|
|
|
20
|
-
|
|
14
|
+
export interface AvDateSchemaConstructor {
|
|
15
|
+
(opts?: DateOpts): AvDateSchema;
|
|
16
|
+
new (opts?: DateOpts): AvDateSchema;
|
|
21
17
|
}
|
|
18
|
+
|
|
19
|
+
export const avDate: AvDateSchemaConstructor;
|
package/types/dateRange.d.ts
CHANGED
|
@@ -1,40 +1,38 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { MixedSchema } from 'yup';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
};
|
|
3
|
+
type DateRangeObject = {
|
|
4
|
+
startDate: string;
|
|
5
|
+
endDate: string;
|
|
6
|
+
};
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
type DistanceValue = {
|
|
16
|
-
value: number;
|
|
17
|
-
units?: string;
|
|
18
|
-
errorMessage?: string;
|
|
19
|
-
};
|
|
8
|
+
interface DateRangeOpts {
|
|
9
|
+
startKey?: string | 'startDate';
|
|
10
|
+
endKey?: string | 'endKey';
|
|
11
|
+
format?: string | 'MM/DD/YYYY';
|
|
12
|
+
}
|
|
20
13
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
14
|
+
type DistanceValue = {
|
|
15
|
+
value: number;
|
|
16
|
+
units?: string;
|
|
17
|
+
errorMessage?: string;
|
|
18
|
+
};
|
|
25
19
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
isRequired(required?: boolean, errorMessage?: string): DateRangeSchema<T>;
|
|
31
|
-
distance(distanceOpts: DistanceOpts): DateRangeSchema<T>;
|
|
32
|
-
}
|
|
20
|
+
type DistanceOpts = {
|
|
21
|
+
min?: DistanceValue;
|
|
22
|
+
max?: DistanceValue;
|
|
23
|
+
};
|
|
33
24
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
25
|
+
interface DateRangeSchema<T extends DateRangeObject | null | undefined = DateRangeObject> extends MixedSchema<T> {
|
|
26
|
+
min(date: string, errorMessage?: string): DateRangeSchema<T>;
|
|
27
|
+
max(date: string, errorMessage?: string): DateRangeSchema<T>;
|
|
28
|
+
between(minDate: string, maxDate: string, errorMessage?: string): DateRangeSchema<T>;
|
|
29
|
+
isRequired(required?: boolean, errorMessage?: string): DateRangeSchema<T>;
|
|
30
|
+
distance(distanceOpts: DistanceOpts): DateRangeSchema<T>;
|
|
31
|
+
}
|
|
38
32
|
|
|
39
|
-
|
|
33
|
+
export interface DateRangeSchemaConstructor {
|
|
34
|
+
(opts?: DateRangeOpts): DateRangeSchema;
|
|
35
|
+
new (opts?: DateRangeOpts): DateRangeSchema;
|
|
40
36
|
}
|
|
37
|
+
|
|
38
|
+
export const dateRange: DateRangeSchemaConstructor;
|
package/types/index.d.ts
CHANGED
|
@@ -1,25 +1,28 @@
|
|
|
1
1
|
import * as yup from 'yup';
|
|
2
|
-
|
|
3
|
-
import './
|
|
2
|
+
|
|
3
|
+
import { dateRange } from './dateRange';
|
|
4
|
+
import { avDate } from './date';
|
|
5
|
+
|
|
6
|
+
export { avDate, dateRange };
|
|
4
7
|
|
|
5
8
|
declare module 'yup' {
|
|
6
|
-
interface StringSchema<T extends string | null | undefined = string> extends
|
|
9
|
+
interface StringSchema<T extends string | null | undefined = string> extends yup.StringSchema<T> {
|
|
7
10
|
isRequired(required?: boolean, errorMessage?: string): StringSchema<T>;
|
|
8
11
|
npi(errorMessage?: string): StringSchema<T>;
|
|
9
12
|
phone(errorMessage?: string): StringSchema<T>;
|
|
10
13
|
}
|
|
11
14
|
|
|
12
|
-
interface ArraySchema<T> extends
|
|
15
|
+
interface ArraySchema<T> extends yup.ArraySchema<T[]> {
|
|
13
16
|
isRequired(required?: boolean, errorMessage?: string): ArraySchema<T>;
|
|
14
17
|
}
|
|
15
18
|
|
|
16
|
-
interface NumberSchema<T extends number | null | undefined = number> extends
|
|
19
|
+
interface NumberSchema<T extends number | null | undefined = number> extends yup.NumberSchema<T> {
|
|
17
20
|
isRequired(required?: boolean, errorMessage?: string): NumberSchema<T>;
|
|
18
21
|
npi(errorMessage?: string): NumberSchema<T>;
|
|
19
22
|
phone(errorMessage?: string): NumberSchema<T>;
|
|
20
23
|
}
|
|
21
24
|
|
|
22
|
-
interface ObjectSchema<
|
|
23
|
-
isRequired(required?: boolean, errorMessage?: string): ObjectSchema<
|
|
25
|
+
interface ObjectSchema<TShape extends Record<string, any>> extends yup.ObjectSchema<TShape> {
|
|
26
|
+
isRequired(required?: boolean, errorMessage?: string): ObjectSchema<TShape>;
|
|
24
27
|
}
|
|
25
28
|
}
|