@availity/yup 5.1.2 → 5.1.3
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/CHANGELOG.md +51 -0
- package/dist/index.d.mts +116 -0
- package/dist/index.d.ts +8 -8
- package/dist/index.js +55 -6
- package/dist/index.mjs +46 -5
- package/package.json +5 -5
- package/project.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,57 @@
|
|
|
2
2
|
|
|
3
3
|
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
4
|
|
|
5
|
+
## [5.1.3](https://github.com/Availity/sdk-js/compare/@availity/yup@5.1.2...@availity/yup@5.1.3) (2023-08-23)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
# 1.0.0 (2023-08-23)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
* add browser field for output ([0ce7170](https://github.com/Availity/sdk-js/commit/0ce717075a82675b8707e4db0cc07cd4af370f3d))
|
|
15
|
+
* **yup:** avDate fix for edge case invalid date length ([55f8b78](https://github.com/Availity/sdk-js/commit/55f8b781595a1f5aa610d63da53c4ffe3c7710e4))
|
|
16
|
+
* **yup:** avDate fix handles undefined correctly now ([85d25b7](https://github.com/Availity/sdk-js/commit/85d25b751b340273de8396abc310e5a27934376c))
|
|
17
|
+
* **yup:** avDate.typeError should not display for empty fields ([8bf47fb](https://github.com/Availity/sdk-js/commit/8bf47fb3a64f5b956b8ce0d4b27dbac46e08c864))
|
|
18
|
+
* **yup:** conditional logic fix ([3679957](https://github.com/Availity/sdk-js/commit/36799574f86674e1a41228c10bfba8d303958e02))
|
|
19
|
+
* **yup:** fix issue with exports not being found if yup and @availity/yup not imported in right order ([fa24f1d](https://github.com/Availity/sdk-js/commit/fa24f1d6f43bcf1371ca7b0613cacc2f3a0d3b01))
|
|
20
|
+
* **yup:** fixed bug in daterange causing to validate improperly ([5e90f3e](https://github.com/Availity/sdk-js/commit/5e90f3e8cd25c8aaebfbbf4b03868c3f1e77ecbe))
|
|
21
|
+
* **yup:** fixes duplicate name key preventing some validation tests for running, changes wording of validation messages ([ef144eb](https://github.com/Availity/sdk-js/commit/ef144eb972f821dc2c180ee74e7f9b5a0ae019bc))
|
|
22
|
+
* **yup:** fixes start date before end date logic ([6cc0ff7](https://github.com/Availity/sdk-js/commit/6cc0ff736358bc5aaf738a84d8abb258e85f57f4))
|
|
23
|
+
* **yup:** fixes type resolution bug where internal yup.date was no longer being overridden ([01ba375](https://github.com/Availity/sdk-js/commit/01ba3752455b98ebd701d5cfddeb4ab79af3c1a3))
|
|
24
|
+
* **yup:** fixes unhandled error for when value === undefined in avDate().between() validation ([d779f59](https://github.com/Availity/sdk-js/commit/d779f591cadeba3184faec13034e7b12a66d697a))
|
|
25
|
+
* **yup:** package change for major version update ([9ad040f](https://github.com/Availity/sdk-js/commit/9ad040ff7a4f7cbe7d5fdd37932d953287db805c)), closes [/github.com/jquense/yup/blob/375f1b9ed41f5043e123ea87a01a2dfe333c3927/CHANGELOG.md#0320-2020-12-03](https://github.com//github.com/jquense/yup/blob/375f1b9ed41f5043e123ea87a01a2dfe333c3927/CHANGELOG.md/issues/0320-2020-12-03)
|
|
26
|
+
* **yup:** refactor typeError, use _typeCheck ([24cea5e](https://github.com/Availity/sdk-js/commit/24cea5e2140d72ecec169dfde9fd94eb18956e66))
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
* build!: switch from lerna to nx and compile to esm with tsup ([c586085](https://github.com/Availity/sdk-js/commit/c5860856ca96b743a0653d335ea00f0889132f7f))
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
### Features
|
|
33
|
+
|
|
34
|
+
* add npi method ([b1ac1a2](https://github.com/Availity/sdk-js/commit/b1ac1a258b32a74d7cce409304660a08089ddc46))
|
|
35
|
+
* **yup:** add phone validation schema ([98c3e29](https://github.com/Availity/sdk-js/commit/98c3e2968efe5f852872fda72839bda28dc7e38c))
|
|
36
|
+
* **yup:** add type definitions for phone schema ([319ca88](https://github.com/Availity/sdk-js/commit/319ca884a9fdd400c3983f751199263487dda8f6))
|
|
37
|
+
* **yup:** added yup validation library methods ([690f0c7](https://github.com/Availity/sdk-js/commit/690f0c7940748025a0d2c935fd4b8cbf81b29c28))
|
|
38
|
+
* **yup:** allow custom type error message for dateRange ([cc36cde](https://github.com/Availity/sdk-js/commit/cc36cde7d403f9787343fcecbf1d0fd9d8ac6bf7))
|
|
39
|
+
* **yup:** convert to ts and fix undefined class property ([f5a3a4f](https://github.com/Availity/sdk-js/commit/f5a3a4f944a0ae281e0eaabf3b6a38659a2acc71))
|
|
40
|
+
* **yup:** support inclusivity option ([94b1283](https://github.com/Availity/sdk-js/commit/94b1283c29e00f0db49ea58ae62d1cf16beef678))
|
|
41
|
+
* **yup:** switch to lodash from merge-options-es5 ([06456c9](https://github.com/Availity/sdk-js/commit/06456c90ac6ef7523c4ed0d2e4dc9af8c4a6dee5))
|
|
42
|
+
* **yup:** unit test for inclusivity ([25bf64b](https://github.com/Availity/sdk-js/commit/25bf64bd1fbd9b03ff609d8b8614ce40b7a4f4be))
|
|
43
|
+
* **yup:** update how accepted formats are handled for dates ([91006e5](https://github.com/Availity/sdk-js/commit/91006e564766e2bb66cdabc24dd2cdd69bc8b150))
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
### BREAKING CHANGES
|
|
47
|
+
|
|
48
|
+
* Drop Internet Explorer support
|
|
49
|
+
* **yup:** the version of yup this package requires contains breaking changes from 0.32.0 onward
|
|
50
|
+
* **yup:** avDate and dateRange should now be imported directly from @availity/yup, eliminating the need for a 'magic' import from moment.js that depends on import order
|
|
51
|
+
* **yup:** Fixes TypeError: Cannot set property date of #<Object> by renaming 'date' and 'DateSchema' to 'avDa
|
|
52
|
+
te' and 'AvDateSchema'.
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
5
56
|
## [5.1.2](https://github.com/Availity/sdk-js/compare/@availity/yup@5.1.1...@availity/yup@5.1.2) (2022-06-15)
|
|
6
57
|
|
|
7
58
|
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
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 MomentDateSchema extends MixedSchema<Moment> {
|
|
10
|
+
_validFormats: string[];
|
|
11
|
+
constructor({ format, typeError }?: Options$1);
|
|
12
|
+
_typeCheck(value: unknown): value is Moment;
|
|
13
|
+
/**
|
|
14
|
+
* Validate if the date is on or after a specified min
|
|
15
|
+
*/
|
|
16
|
+
min(min: string, message?: string): this;
|
|
17
|
+
/**
|
|
18
|
+
* Validate if the date is on or before a specified max
|
|
19
|
+
*/
|
|
20
|
+
max(max: string, message?: string): this;
|
|
21
|
+
/**
|
|
22
|
+
* Validate if the date is between a specified min or max
|
|
23
|
+
*
|
|
24
|
+
* For Inlcusivity: `[]` === include & `()` === exclude
|
|
25
|
+
*/
|
|
26
|
+
between(min: string, max: string, message?: string, inclusivity?: Inclusivity): this;
|
|
27
|
+
/**
|
|
28
|
+
* Set if the field is required and add a custom message
|
|
29
|
+
*/
|
|
30
|
+
isRequired(isRequired?: boolean, message?: string): this;
|
|
31
|
+
}
|
|
32
|
+
type Inclusivity = '()' | '[)' | '(]' | '[]';
|
|
33
|
+
type Options$1 = {
|
|
34
|
+
format?: string | string[];
|
|
35
|
+
typeError?: string;
|
|
36
|
+
};
|
|
37
|
+
declare const avDate: (options?: Options$1) => MomentDateSchema;
|
|
38
|
+
|
|
39
|
+
declare class DateRangeSchema extends MixedSchema<DateRange> {
|
|
40
|
+
startKey: string;
|
|
41
|
+
endKey: string;
|
|
42
|
+
format: string;
|
|
43
|
+
constructor(options?: Options);
|
|
44
|
+
/**
|
|
45
|
+
* Convert the string to a moment object
|
|
46
|
+
*/
|
|
47
|
+
getValidDate(value: string | Date | Moment): moment.Moment;
|
|
48
|
+
/**
|
|
49
|
+
* Validate based on min and max distance between dates
|
|
50
|
+
*/
|
|
51
|
+
distance({ min: { value: minValue, units: minUnits, errorMessage: minErrorMessage }, max: { value: maxValue, units: maxUnits, errorMessage: maxErrorMessage }, }?: DistanceOptions): this;
|
|
52
|
+
/**
|
|
53
|
+
* Validate start date is after given min
|
|
54
|
+
*/
|
|
55
|
+
min(min: string, message?: string): this;
|
|
56
|
+
/**
|
|
57
|
+
* Validate end date is before given max
|
|
58
|
+
*/
|
|
59
|
+
max(max: string, message?: string): this;
|
|
60
|
+
/**
|
|
61
|
+
* Validate dates are between the set min and max
|
|
62
|
+
*/
|
|
63
|
+
between(min: string, max: string, message?: string): this;
|
|
64
|
+
/**
|
|
65
|
+
* Set the field to be required or not
|
|
66
|
+
*/
|
|
67
|
+
isRequired(isRequired?: boolean, msg?: string): this;
|
|
68
|
+
typeError({ message }: {
|
|
69
|
+
message: string;
|
|
70
|
+
}): this;
|
|
71
|
+
_typeCheck(range?: {
|
|
72
|
+
startDate?: Moment;
|
|
73
|
+
endDate?: Moment;
|
|
74
|
+
}): range is DateRange;
|
|
75
|
+
}
|
|
76
|
+
type Options = {
|
|
77
|
+
startKey?: string;
|
|
78
|
+
endKey?: string;
|
|
79
|
+
format?: string;
|
|
80
|
+
};
|
|
81
|
+
type DateRange = {
|
|
82
|
+
startDate?: Moment;
|
|
83
|
+
endDate?: Moment;
|
|
84
|
+
supportedFormats?: string[];
|
|
85
|
+
};
|
|
86
|
+
type DistanceValue = {
|
|
87
|
+
value: number;
|
|
88
|
+
units?: unitOfTime.DurationConstructor;
|
|
89
|
+
errorMessage?: string;
|
|
90
|
+
};
|
|
91
|
+
type DistanceOptions = {
|
|
92
|
+
min?: DistanceValue;
|
|
93
|
+
max?: DistanceValue;
|
|
94
|
+
};
|
|
95
|
+
declare const dateRange: (opts?: Options) => DateRangeSchema;
|
|
96
|
+
|
|
97
|
+
declare module 'yup' {
|
|
98
|
+
interface StringSchema<TType extends Maybe<string> = string | undefined, TContext extends AnyObject = AnyObject, TOut extends TType = TType> extends BaseSchema<TType, TContext, TOut> {
|
|
99
|
+
isRequired(required?: boolean, errorMessage?: string): StringSchema<TType, TContext>;
|
|
100
|
+
npi(errorMessage?: string): StringSchema<TType, TContext>;
|
|
101
|
+
phone(errorMessage?: string): StringSchema<TType, TContext>;
|
|
102
|
+
}
|
|
103
|
+
interface NumberSchema<TType extends Maybe<number> = number | undefined, TContext extends AnyObject = AnyObject, TOut extends TType = TType> extends BaseSchema<TType, TContext, TOut> {
|
|
104
|
+
isRequired(required?: boolean, errorMessage?: string): NumberSchema<TType, TContext, TOut>;
|
|
105
|
+
npi(errorMessage?: string): NumberSchema<TType, TContext, TOut>;
|
|
106
|
+
phone(errorMessage?: string): NumberSchema<TType, TContext, TOut>;
|
|
107
|
+
}
|
|
108
|
+
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> {
|
|
109
|
+
isRequired(required?: boolean, errorMessage?: string): ArraySchema<T, C, TIn, TOut>;
|
|
110
|
+
}
|
|
111
|
+
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> {
|
|
112
|
+
isRequired(required?: boolean, errorMessage?: string): ObjectSchema<TShape, TContext, TIn, TOut>;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export { avDate, dateRange };
|
package/dist/index.d.ts
CHANGED
|
@@ -29,12 +29,12 @@ declare class MomentDateSchema extends MixedSchema<Moment> {
|
|
|
29
29
|
*/
|
|
30
30
|
isRequired(isRequired?: boolean, message?: string): this;
|
|
31
31
|
}
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
type Inclusivity = '()' | '[)' | '(]' | '[]';
|
|
33
|
+
type Options$1 = {
|
|
34
34
|
format?: string | string[];
|
|
35
35
|
typeError?: string;
|
|
36
36
|
};
|
|
37
|
-
declare const avDate: (options?: Options$1
|
|
37
|
+
declare const avDate: (options?: Options$1) => MomentDateSchema;
|
|
38
38
|
|
|
39
39
|
declare class DateRangeSchema extends MixedSchema<DateRange> {
|
|
40
40
|
startKey: string;
|
|
@@ -73,26 +73,26 @@ declare class DateRangeSchema extends MixedSchema<DateRange> {
|
|
|
73
73
|
endDate?: Moment;
|
|
74
74
|
}): range is DateRange;
|
|
75
75
|
}
|
|
76
|
-
|
|
76
|
+
type Options = {
|
|
77
77
|
startKey?: string;
|
|
78
78
|
endKey?: string;
|
|
79
79
|
format?: string;
|
|
80
80
|
};
|
|
81
|
-
|
|
81
|
+
type DateRange = {
|
|
82
82
|
startDate?: Moment;
|
|
83
83
|
endDate?: Moment;
|
|
84
84
|
supportedFormats?: string[];
|
|
85
85
|
};
|
|
86
|
-
|
|
86
|
+
type DistanceValue = {
|
|
87
87
|
value: number;
|
|
88
88
|
units?: unitOfTime.DurationConstructor;
|
|
89
89
|
errorMessage?: string;
|
|
90
90
|
};
|
|
91
|
-
|
|
91
|
+
type DistanceOptions = {
|
|
92
92
|
min?: DistanceValue;
|
|
93
93
|
max?: DistanceValue;
|
|
94
94
|
};
|
|
95
|
-
declare const dateRange: (opts?: Options
|
|
95
|
+
declare const dateRange: (opts?: Options) => DateRangeSchema;
|
|
96
96
|
|
|
97
97
|
declare module 'yup' {
|
|
98
98
|
interface StringSchema<TType extends Maybe<string> = string | undefined, TContext extends AnyObject = AnyObject, TOut extends TType = TType> extends BaseSchema<TType, TContext, TOut> {
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -16,7 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
17
|
}
|
|
17
18
|
return to;
|
|
18
19
|
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
20
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
29
|
|
|
22
30
|
// src/index.ts
|
|
@@ -47,9 +55,13 @@ var MomentDateSchema = class extends import_yup.MixedSchema {
|
|
|
47
55
|
});
|
|
48
56
|
});
|
|
49
57
|
}
|
|
58
|
+
// Check if the date is a valid moment object or an empty string
|
|
50
59
|
_typeCheck(value) {
|
|
51
60
|
return import_moment.default.isMoment(value) && (value.isValid() || value._i === "");
|
|
52
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Validate if the date is on or after a specified min
|
|
64
|
+
*/
|
|
53
65
|
min(min, message) {
|
|
54
66
|
return this.test({
|
|
55
67
|
message: ({ min: minDate }) => message || `Date must be ${minDate} or later.`,
|
|
@@ -64,6 +76,9 @@ var MomentDateSchema = class extends import_yup.MixedSchema {
|
|
|
64
76
|
}
|
|
65
77
|
});
|
|
66
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Validate if the date is on or before a specified max
|
|
81
|
+
*/
|
|
67
82
|
max(max, message) {
|
|
68
83
|
return this.test({
|
|
69
84
|
message: ({ max: maxDate }) => message || `Date must be ${maxDate} or earlier.`,
|
|
@@ -78,6 +93,11 @@ var MomentDateSchema = class extends import_yup.MixedSchema {
|
|
|
78
93
|
}
|
|
79
94
|
});
|
|
80
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Validate if the date is between a specified min or max
|
|
98
|
+
*
|
|
99
|
+
* For Inlcusivity: `[]` === include & `()` === exclude
|
|
100
|
+
*/
|
|
81
101
|
between(min, max, message, inclusivity = "()") {
|
|
82
102
|
return this.test({
|
|
83
103
|
name: "between",
|
|
@@ -92,6 +112,9 @@ var MomentDateSchema = class extends import_yup.MixedSchema {
|
|
|
92
112
|
}
|
|
93
113
|
});
|
|
94
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* Set if the field is required and add a custom message
|
|
117
|
+
*/
|
|
95
118
|
isRequired(isRequired2 = true, message) {
|
|
96
119
|
return this.test({
|
|
97
120
|
name: "isRequired",
|
|
@@ -140,9 +163,15 @@ var DateRangeSchema = class extends import_yup2.MixedSchema {
|
|
|
140
163
|
});
|
|
141
164
|
});
|
|
142
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* Convert the string to a moment object
|
|
168
|
+
*/
|
|
143
169
|
getValidDate(value) {
|
|
144
170
|
return (0, import_moment2.default)(value, [this.format, ...formats], true);
|
|
145
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* Validate based on min and max distance between dates
|
|
174
|
+
*/
|
|
146
175
|
distance({
|
|
147
176
|
min: { value: minValue, units: minUnits = "day", errorMessage: minErrorMessage } = { value: 0 },
|
|
148
177
|
max: { value: maxValue, units: maxUnits = "day", errorMessage: maxErrorMessage } = { value: 0 }
|
|
@@ -154,18 +183,29 @@ var DateRangeSchema = class extends import_yup2.MixedSchema {
|
|
|
154
183
|
if (!minValue && !maxValue || !startDate || !endDate)
|
|
155
184
|
return true;
|
|
156
185
|
if (maxValue && endDate.isAfter(startDate.add(maxValue, maxUnits), "day")) {
|
|
157
|
-
return new import_yup2.ValidationError(
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
186
|
+
return new import_yup2.ValidationError(
|
|
187
|
+
maxErrorMessage || `The end date must be within ${maxValue} ${maxUnits}${maxValue > 1 ? "s" : ""} of the start date`,
|
|
188
|
+
{
|
|
189
|
+
startDate,
|
|
190
|
+
endDate
|
|
191
|
+
},
|
|
192
|
+
this.path
|
|
193
|
+
);
|
|
161
194
|
}
|
|
162
195
|
if (minValue && endDate.isBefore(startDate.add(minValue, minUnits), "day")) {
|
|
163
|
-
return new import_yup2.ValidationError(
|
|
196
|
+
return new import_yup2.ValidationError(
|
|
197
|
+
minErrorMessage || `The end date must be greater than ${minValue} ${minUnits}${minValue > 1 ? "s" : ""} of the start date`,
|
|
198
|
+
{ startDate, endDate },
|
|
199
|
+
this.path
|
|
200
|
+
);
|
|
164
201
|
}
|
|
165
202
|
return true;
|
|
166
203
|
}
|
|
167
204
|
});
|
|
168
205
|
}
|
|
206
|
+
/**
|
|
207
|
+
* Validate start date is after given min
|
|
208
|
+
*/
|
|
169
209
|
min(min, message) {
|
|
170
210
|
return this.test({
|
|
171
211
|
message: message || (({ min: min2 }) => `Date Range must start on or after ${min2}`),
|
|
@@ -180,6 +220,9 @@ var DateRangeSchema = class extends import_yup2.MixedSchema {
|
|
|
180
220
|
}
|
|
181
221
|
});
|
|
182
222
|
}
|
|
223
|
+
/**
|
|
224
|
+
* Validate end date is before given max
|
|
225
|
+
*/
|
|
183
226
|
max(max, message) {
|
|
184
227
|
return this.test({
|
|
185
228
|
message: message || (({ max: max2 }) => `Date Range must end on or before ${max2}`),
|
|
@@ -194,6 +237,9 @@ var DateRangeSchema = class extends import_yup2.MixedSchema {
|
|
|
194
237
|
}
|
|
195
238
|
});
|
|
196
239
|
}
|
|
240
|
+
/**
|
|
241
|
+
* Validate dates are between the set min and max
|
|
242
|
+
*/
|
|
197
243
|
between(min, max, message) {
|
|
198
244
|
return this.test({
|
|
199
245
|
message: message || (({ min: min2, max: max2 }) => `Date Range must be between ${min2} and ${max2}`),
|
|
@@ -209,6 +255,9 @@ var DateRangeSchema = class extends import_yup2.MixedSchema {
|
|
|
209
255
|
}
|
|
210
256
|
});
|
|
211
257
|
}
|
|
258
|
+
/**
|
|
259
|
+
* Set the field to be required or not
|
|
260
|
+
*/
|
|
212
261
|
isRequired(isRequired2 = true, msg) {
|
|
213
262
|
return this.test({
|
|
214
263
|
name: "isRequired",
|
package/dist/index.mjs
CHANGED
|
@@ -20,9 +20,13 @@ var MomentDateSchema = class extends MixedSchema {
|
|
|
20
20
|
});
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
|
+
// Check if the date is a valid moment object or an empty string
|
|
23
24
|
_typeCheck(value) {
|
|
24
25
|
return moment.isMoment(value) && (value.isValid() || value._i === "");
|
|
25
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Validate if the date is on or after a specified min
|
|
29
|
+
*/
|
|
26
30
|
min(min, message) {
|
|
27
31
|
return this.test({
|
|
28
32
|
message: ({ min: minDate }) => message || `Date must be ${minDate} or later.`,
|
|
@@ -37,6 +41,9 @@ var MomentDateSchema = class extends MixedSchema {
|
|
|
37
41
|
}
|
|
38
42
|
});
|
|
39
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Validate if the date is on or before a specified max
|
|
46
|
+
*/
|
|
40
47
|
max(max, message) {
|
|
41
48
|
return this.test({
|
|
42
49
|
message: ({ max: maxDate }) => message || `Date must be ${maxDate} or earlier.`,
|
|
@@ -51,6 +58,11 @@ var MomentDateSchema = class extends MixedSchema {
|
|
|
51
58
|
}
|
|
52
59
|
});
|
|
53
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Validate if the date is between a specified min or max
|
|
63
|
+
*
|
|
64
|
+
* For Inlcusivity: `[]` === include & `()` === exclude
|
|
65
|
+
*/
|
|
54
66
|
between(min, max, message, inclusivity = "()") {
|
|
55
67
|
return this.test({
|
|
56
68
|
name: "between",
|
|
@@ -65,6 +77,9 @@ var MomentDateSchema = class extends MixedSchema {
|
|
|
65
77
|
}
|
|
66
78
|
});
|
|
67
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* Set if the field is required and add a custom message
|
|
82
|
+
*/
|
|
68
83
|
isRequired(isRequired2 = true, message) {
|
|
69
84
|
return this.test({
|
|
70
85
|
name: "isRequired",
|
|
@@ -113,9 +128,15 @@ var DateRangeSchema = class extends MixedSchema2 {
|
|
|
113
128
|
});
|
|
114
129
|
});
|
|
115
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Convert the string to a moment object
|
|
133
|
+
*/
|
|
116
134
|
getValidDate(value) {
|
|
117
135
|
return moment2(value, [this.format, ...formats], true);
|
|
118
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* Validate based on min and max distance between dates
|
|
139
|
+
*/
|
|
119
140
|
distance({
|
|
120
141
|
min: { value: minValue, units: minUnits = "day", errorMessage: minErrorMessage } = { value: 0 },
|
|
121
142
|
max: { value: maxValue, units: maxUnits = "day", errorMessage: maxErrorMessage } = { value: 0 }
|
|
@@ -127,18 +148,29 @@ var DateRangeSchema = class extends MixedSchema2 {
|
|
|
127
148
|
if (!minValue && !maxValue || !startDate || !endDate)
|
|
128
149
|
return true;
|
|
129
150
|
if (maxValue && endDate.isAfter(startDate.add(maxValue, maxUnits), "day")) {
|
|
130
|
-
return new ValidationError(
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
151
|
+
return new ValidationError(
|
|
152
|
+
maxErrorMessage || `The end date must be within ${maxValue} ${maxUnits}${maxValue > 1 ? "s" : ""} of the start date`,
|
|
153
|
+
{
|
|
154
|
+
startDate,
|
|
155
|
+
endDate
|
|
156
|
+
},
|
|
157
|
+
this.path
|
|
158
|
+
);
|
|
134
159
|
}
|
|
135
160
|
if (minValue && endDate.isBefore(startDate.add(minValue, minUnits), "day")) {
|
|
136
|
-
return new ValidationError(
|
|
161
|
+
return new ValidationError(
|
|
162
|
+
minErrorMessage || `The end date must be greater than ${minValue} ${minUnits}${minValue > 1 ? "s" : ""} of the start date`,
|
|
163
|
+
{ startDate, endDate },
|
|
164
|
+
this.path
|
|
165
|
+
);
|
|
137
166
|
}
|
|
138
167
|
return true;
|
|
139
168
|
}
|
|
140
169
|
});
|
|
141
170
|
}
|
|
171
|
+
/**
|
|
172
|
+
* Validate start date is after given min
|
|
173
|
+
*/
|
|
142
174
|
min(min, message) {
|
|
143
175
|
return this.test({
|
|
144
176
|
message: message || (({ min: min2 }) => `Date Range must start on or after ${min2}`),
|
|
@@ -153,6 +185,9 @@ var DateRangeSchema = class extends MixedSchema2 {
|
|
|
153
185
|
}
|
|
154
186
|
});
|
|
155
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* Validate end date is before given max
|
|
190
|
+
*/
|
|
156
191
|
max(max, message) {
|
|
157
192
|
return this.test({
|
|
158
193
|
message: message || (({ max: max2 }) => `Date Range must end on or before ${max2}`),
|
|
@@ -167,6 +202,9 @@ var DateRangeSchema = class extends MixedSchema2 {
|
|
|
167
202
|
}
|
|
168
203
|
});
|
|
169
204
|
}
|
|
205
|
+
/**
|
|
206
|
+
* Validate dates are between the set min and max
|
|
207
|
+
*/
|
|
170
208
|
between(min, max, message) {
|
|
171
209
|
return this.test({
|
|
172
210
|
message: message || (({ min: min2, max: max2 }) => `Date Range must be between ${min2} and ${max2}`),
|
|
@@ -182,6 +220,9 @@ var DateRangeSchema = class extends MixedSchema2 {
|
|
|
182
220
|
}
|
|
183
221
|
});
|
|
184
222
|
}
|
|
223
|
+
/**
|
|
224
|
+
* Set the field to be required or not
|
|
225
|
+
*/
|
|
185
226
|
isRequired(isRequired2 = true, msg) {
|
|
186
227
|
return this.test({
|
|
187
228
|
name: "isRequired",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@availity/yup",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.3",
|
|
4
4
|
"description": "Additional methods for yup validation library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"yup",
|
|
@@ -33,12 +33,12 @@
|
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"lodash": "^4.17.21",
|
|
36
|
-
"yup": "^0.32.
|
|
36
|
+
"yup": "^0.32.11"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"moment": "^2.
|
|
40
|
-
"tsup": "^
|
|
41
|
-
"typescript": "^
|
|
39
|
+
"moment": "^2.29.4",
|
|
40
|
+
"tsup": "^7.2.0",
|
|
41
|
+
"typescript": "^5.1.6"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"moment": "^2.24.0"
|
package/project.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"projectType": "library",
|
|
4
4
|
"targets": {
|
|
5
5
|
"test": {
|
|
6
|
-
"executor": "@
|
|
6
|
+
"executor": "@nx/jest:jest",
|
|
7
7
|
"outputs": ["coverage/yup"],
|
|
8
8
|
"options": {
|
|
9
9
|
"jestConfig": "packages/yup/jest.config.js",
|
|
@@ -14,13 +14,13 @@
|
|
|
14
14
|
"executor": "@jscutlery/semver:version",
|
|
15
15
|
"options": {
|
|
16
16
|
"preset": "angular",
|
|
17
|
-
"commitMessageFormat": "chore(
|
|
18
|
-
"tagPrefix": "@availity
|
|
17
|
+
"commitMessageFormat": "chore({projectName}): release version ${version} [skip ci]",
|
|
18
|
+
"tagPrefix": "@availity/{projectName}@",
|
|
19
19
|
"baseBranch": "master"
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
22
|
"lint": {
|
|
23
|
-
"executor": "@
|
|
23
|
+
"executor": "@nx/linter:eslint",
|
|
24
24
|
"options": {
|
|
25
25
|
"eslintConfig": ".eslintrc.yaml",
|
|
26
26
|
"lintFilePatterns": ["packages/yup/**/*.{js,ts}"],
|