@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/dist/index.mjs ADDED
@@ -0,0 +1,325 @@
1
+ // src/index.ts
2
+ import { addMethod, array, number, object, string } from "yup";
3
+
4
+ // src/date.ts
5
+ import { MixedSchema } from "yup";
6
+ import moment from "moment";
7
+ var formats = ["YYYY-MM-DD", "MMDDYYYY", "YYYYMMDD", "MM-DD-YYYY"];
8
+ var AvDateSchema = class extends MixedSchema {
9
+ constructor({ format = "MM/DD/YYYY" } = {}) {
10
+ super({
11
+ type: "avDate"
12
+ });
13
+ this.format = format;
14
+ this.withMutation((schema) => {
15
+ if (!schema.tests.some((test) => {
16
+ var _a;
17
+ return ((_a = test == null ? void 0 : test.OPTIONS) == null ? void 0 : _a.name) === "typeError";
18
+ })) {
19
+ super.typeError("Date is invalid.");
20
+ }
21
+ schema.transform(function mutate(value) {
22
+ return schema.getValidDate(value);
23
+ });
24
+ });
25
+ }
26
+ _typeCheck(value) {
27
+ return value.isValid() || value._i === "";
28
+ }
29
+ getValidDate(value) {
30
+ return moment(value, [this.format, ...formats], true);
31
+ }
32
+ min(min, message) {
33
+ const minDate = this.getValidDate(min);
34
+ return this.test({
35
+ message: message || `Date must be ${minDate.format(this.format)} or later.`,
36
+ name: "min",
37
+ exclusive: true,
38
+ params: { min },
39
+ test(value) {
40
+ if (!min || !minDate.isValid()) {
41
+ return true;
42
+ }
43
+ return value === null || minDate.isSameOrBefore(value);
44
+ }
45
+ });
46
+ }
47
+ max(max, message) {
48
+ const maxDate = this.getValidDate(max);
49
+ return this.test({
50
+ message: message || `Date must be ${maxDate.format(this.format)} or earlier.`,
51
+ name: "max",
52
+ exclusive: true,
53
+ params: { max },
54
+ test(value) {
55
+ if (!max || !maxDate.isValid()) {
56
+ return true;
57
+ }
58
+ return value === null || maxDate.isSameOrAfter(value);
59
+ }
60
+ });
61
+ }
62
+ isRequired(isRequired2 = true, msg) {
63
+ return this.test({
64
+ name: "isRequired",
65
+ exclusive: true,
66
+ message: msg || "This field is required.",
67
+ test(value) {
68
+ if (!isRequired2) {
69
+ return true;
70
+ }
71
+ return value !== void 0;
72
+ }
73
+ });
74
+ }
75
+ between(min, max, msg, inclusivity = "()") {
76
+ const minDate = this.getValidDate(min);
77
+ const maxDate = this.getValidDate(max);
78
+ return this.test({
79
+ name: "between",
80
+ exclusive: true,
81
+ message: msg || `Date must be between ${minDate.format(this.format)} and ${maxDate.format(this.format)}.`,
82
+ test(value) {
83
+ if (!value || !min || !max || !minDate.isValid() || !maxDate.isValid()) {
84
+ return true;
85
+ }
86
+ return value.isBetween(minDate, maxDate, void 0, inclusivity);
87
+ }
88
+ });
89
+ }
90
+ };
91
+ var avDate = (opts) => new AvDateSchema(opts);
92
+
93
+ // src/dateRange.ts
94
+ import { MixedSchema as MixedSchema2, ValidationError } from "yup";
95
+ import moment2 from "moment";
96
+ import get from "lodash/get";
97
+ import merge from "lodash/merge";
98
+ var defaultOptions = {
99
+ startKey: "startDate",
100
+ endKey: "endDate",
101
+ format: "MM/DD/YYYY"
102
+ };
103
+ var formats2 = ["YYYY-MM-DD", "MMDDYYYY", "YYYYMMDD"];
104
+ var DateRangeSchema = class extends MixedSchema2 {
105
+ constructor(options) {
106
+ super({
107
+ type: "dateRange"
108
+ });
109
+ const { startKey, endKey, format } = merge({}, defaultOptions, options);
110
+ this.startKey = startKey;
111
+ this.endKey = endKey;
112
+ this.format = format;
113
+ this.withMutation((schema) => {
114
+ schema.transform(function mutate(value) {
115
+ const start = get(value, startKey);
116
+ const end = get(value, endKey);
117
+ return {
118
+ startDate: start ? schema.getValidDate(start) : start,
119
+ endDate: end ? schema.getValidDate(end) : end,
120
+ supportedFormats: [schema.format, ...formats2]
121
+ };
122
+ });
123
+ });
124
+ }
125
+ getValidDate(value) {
126
+ return moment2(value, [this.format, ...formats2], true);
127
+ }
128
+ distance({
129
+ min: { value: minValue, units: minUnits = "day", errorMessage: minErrorMessage } = { value: 0 },
130
+ max: { value: maxValue, units: maxUnits = "day", errorMessage: maxErrorMessage } = { value: 0 }
131
+ } = {}) {
132
+ return this.test({
133
+ name: "distance",
134
+ exclusive: true,
135
+ test({ endDate, startDate } = {}) {
136
+ if (!minValue && !maxValue || !startDate || !endDate)
137
+ return true;
138
+ if (maxValue && endDate.isAfter(startDate.add(maxValue, maxUnits), "day")) {
139
+ return new ValidationError(maxErrorMessage || `The end date must be within ${maxValue} ${maxUnits}${maxValue > 1 ? "s" : ""} of the start date`, {
140
+ startDate,
141
+ endDate
142
+ }, this.path);
143
+ }
144
+ if (minValue && endDate.isBefore(startDate.add(minValue, minUnits), "day")) {
145
+ return new ValidationError(minErrorMessage || `The end date must be greater than ${minValue} ${minUnits}${minValue > 1 ? "s" : ""} of the start date`, { startDate, endDate }, this.path);
146
+ }
147
+ return true;
148
+ }
149
+ });
150
+ }
151
+ min(min, message) {
152
+ return this.test({
153
+ message: message || (({ min: min2 }) => `Date Range must start on or after ${min2}`),
154
+ name: "min",
155
+ exclusive: true,
156
+ params: { min },
157
+ test({ startDate, supportedFormats } = {}) {
158
+ if (!startDate || !min)
159
+ return true;
160
+ const minDate = moment2(min, supportedFormats, true);
161
+ return minDate.isValid() && minDate.isSameOrBefore(startDate);
162
+ }
163
+ });
164
+ }
165
+ max(max, message) {
166
+ return this.test({
167
+ message: message || (({ max: max2 }) => `Date Range must end on or before ${max2}`),
168
+ name: "max",
169
+ exclusive: true,
170
+ params: { max },
171
+ test({ endDate, supportedFormats } = {}) {
172
+ if (!endDate || !max)
173
+ return true;
174
+ const maxDate = moment2(max, supportedFormats, true);
175
+ return maxDate.isValid() && maxDate.isSameOrAfter(endDate);
176
+ }
177
+ });
178
+ }
179
+ between(min, max, message) {
180
+ return this.test({
181
+ message: message || (({ min: min2, max: max2 }) => `Date Range must be between ${min2} and ${max2}`),
182
+ name: "between",
183
+ exclusive: true,
184
+ params: { min, max },
185
+ test({ startDate, endDate, supportedFormats } = {}) {
186
+ if (!startDate || !endDate || !min || !max)
187
+ return true;
188
+ const minDate = moment2(min, supportedFormats, true);
189
+ const maxDate = moment2(max, supportedFormats, true);
190
+ return maxDate.isValid() && minDate.isValid() && maxDate.isSameOrAfter(endDate) && minDate.isSameOrBefore(startDate);
191
+ }
192
+ });
193
+ }
194
+ isRequired(isRequired2 = true, msg) {
195
+ return this.test({
196
+ name: "isRequired",
197
+ exclusive: true,
198
+ message: msg || "This field is required.",
199
+ test({ startDate, endDate } = {}) {
200
+ return !isRequired2 || !!(startDate && endDate);
201
+ }
202
+ });
203
+ }
204
+ typeError({ message }) {
205
+ return this.test({
206
+ name: "typeError",
207
+ exclusive: true,
208
+ test({ startDate, endDate } = {}) {
209
+ const errors = [];
210
+ if ((!startDate || !endDate) && (startDate || endDate)) {
211
+ errors.push(message || "Start and End Date are required.");
212
+ }
213
+ if (startDate && endDate && !startDate.isSameOrBefore(endDate)) {
214
+ errors.push("Start date must come before end date.");
215
+ }
216
+ if (startDate && !startDate.isValid()) {
217
+ errors.push("Start Date is invalid.");
218
+ }
219
+ if (endDate && !endDate.isValid()) {
220
+ errors.push("End Date is invalid.");
221
+ }
222
+ return errors.length > 0 ? new ValidationError(errors, { startDate, endDate }, this.path) : true;
223
+ }
224
+ });
225
+ }
226
+ _typeCheck(range = {}) {
227
+ const { startDate, endDate } = range;
228
+ return !!startDate && !!endDate && startDate.isValid() && endDate.isValid();
229
+ }
230
+ };
231
+ var dateRange = (opts) => new DateRangeSchema(opts);
232
+
233
+ // src/isRequired.ts
234
+ function isRequired(isRequired2 = true, msg) {
235
+ return this.test({
236
+ name: "isRequired",
237
+ exclusive: true,
238
+ message: msg || "This field is required.",
239
+ test(value) {
240
+ if (isRequired2) {
241
+ if (this.schema.type === "array") {
242
+ return Array.isArray(value) ? value.length > 0 : value !== void 0;
243
+ }
244
+ if (this.schema.type === "string") {
245
+ return value !== void 0 && value !== "";
246
+ }
247
+ return value !== void 0;
248
+ }
249
+ return true;
250
+ }
251
+ });
252
+ }
253
+ var isRequired_default = isRequired;
254
+
255
+ // src/npi.ts
256
+ var INTEGER_REGEX = /^\d*$/;
257
+ function npi(msg) {
258
+ return this.test({
259
+ name: "npi",
260
+ exclusive: true,
261
+ message: msg || "This field is invalid.",
262
+ test(value) {
263
+ if (!value)
264
+ return true;
265
+ value += "";
266
+ if (!INTEGER_REGEX.test(value) || value.length !== 10) {
267
+ return false;
268
+ }
269
+ const firstDigit = value.charAt(0);
270
+ if (["1", "2", "3", "4"].indexOf(firstDigit) < 0) {
271
+ return false;
272
+ }
273
+ const digit = Number.parseInt(value.charAt(9), 10);
274
+ value = value.substring(0, 9);
275
+ value = `80840${value}`;
276
+ let alternate = true;
277
+ let total = 0;
278
+ for (let i = value.length; i > 0; i--) {
279
+ let next = Number.parseInt(value.charAt(i - 1), 10);
280
+ if (alternate) {
281
+ next *= 2;
282
+ if (next > 9) {
283
+ next = next % 10 + 1;
284
+ }
285
+ }
286
+ total += next;
287
+ alternate = !alternate;
288
+ }
289
+ const roundUp = Math.ceil(total / 10) * 10;
290
+ const calculatedCheck = roundUp - total;
291
+ return calculatedCheck === digit;
292
+ }
293
+ });
294
+ }
295
+ var npi_default = npi;
296
+
297
+ // src/phone.ts
298
+ var NANP_REGEXP = /^(\+?1[\s.-]?)?\(?[2-9]\d{2}[\s).-]?\s?[2-9]\d{2}[\s.-]?\d{4}$/;
299
+ function phone(msg) {
300
+ return this.test({
301
+ name: "phone",
302
+ exclusive: true,
303
+ message: msg || "This field is invalid",
304
+ test(value) {
305
+ if (!value)
306
+ return true;
307
+ return NANP_REGEXP.test(value);
308
+ }
309
+ });
310
+ }
311
+ var phone_default = phone;
312
+
313
+ // src/index.ts
314
+ addMethod(array, "isRequired", isRequired_default);
315
+ addMethod(number, "isRequired", isRequired_default);
316
+ addMethod(object, "isRequired", isRequired_default);
317
+ addMethod(string, "isRequired", isRequired_default);
318
+ addMethod(number, "npi", npi_default);
319
+ addMethod(string, "npi", npi_default);
320
+ addMethod(number, "phone", phone_default);
321
+ addMethod(string, "phone", phone_default);
322
+ export {
323
+ avDate,
324
+ dateRange
325
+ };
package/jest.config.js ADDED
@@ -0,0 +1,11 @@
1
+ module.exports = {
2
+ displayName: 'yup',
3
+ preset: '../../jest.preset.js',
4
+ globals: {
5
+ 'ts-jest': {
6
+ tsconfig: '<rootDir>/tsconfig.spec.json',
7
+ },
8
+ },
9
+ coverageDirectory: '../../coverage/yup',
10
+ coverageReporters: ['json'],
11
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@availity/yup",
3
- "version": "4.2.0",
3
+ "version": "5.0.0",
4
4
  "description": "Additional methods for yup validation library",
5
5
  "keywords": [
6
6
  "yup",
@@ -18,31 +18,31 @@
18
18
  },
19
19
  "license": "MIT",
20
20
  "author": "Kyle Gray <kyle.gray@availity.com>",
21
- "main": "lib/index.js",
22
- "module": "dist/index.js",
23
- "types": "dist/index.d.ts",
21
+ "main": "./dist/index.js",
22
+ "module": "./dist/index.mjs",
23
+ "types": "./dist/index.d.ts",
24
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"
25
+ "build": "tsup src/index.ts --format esm,cjs --dts",
26
+ "dev": "tsup src/index.ts --format esm,cjs --watch --dts",
27
+ "lint": "eslint src",
28
+ "lint:fix": "eslint src --fix",
29
+ "clean": "rm -rf node_modules && rm -rf dist",
30
+ "bundlesize": "bundlesize",
31
+ "publish": "yarn npm publish --tolerate-republish --access public"
30
32
  },
31
33
  "dependencies": {
32
- "@babel/runtime": "^7.16.5",
33
- "core-js": "^3.12.1",
34
- "lodash": "^4.17.21"
34
+ "lodash": "^4.17.21",
35
+ "yup": "^0.32.0"
35
36
  },
36
37
  "devDependencies": {
37
38
  "moment": "^2.24.0",
38
- "yup": "^0.32.9"
39
+ "tsup": "^5.10.1",
40
+ "typescript": "^4.5.3"
39
41
  },
40
42
  "peerDependencies": {
41
- "moment": "^2.24.0",
42
- "yup": "^0.32.9"
43
+ "moment": "^2.24.0"
43
44
  },
44
45
  "publishConfig": {
45
46
  "access": "public"
46
- },
47
- "gitHead": "1c3e8c8045b16fc5111f941d863600f0a97cdbff"
48
- }
47
+ }
48
+ }
package/project.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "root": "packages/yup",
3
+ "projectType": "library",
4
+ "targets": {
5
+ "test": {
6
+ "executor": "@nrwl/jest:jest",
7
+ "outputs": ["coverage/yup"],
8
+ "options": {
9
+ "jestConfig": "packages/yup/jest.config.js",
10
+ "passWithNoTests": true
11
+ }
12
+ },
13
+ "version": {
14
+ "executor": "@jscutlery/semver:version",
15
+ "options": {
16
+ "preset": "angular",
17
+ "commitMessageFormat": "chore(${projectName}): release version ${version} [skip ci]",
18
+ "tagPrefix": "@availity/${projectName}@",
19
+ "baseBranch": "master"
20
+ }
21
+ }
22
+ }
23
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "include": ["."],
4
+ "exclude": ["dist", "build", "node_modules"]
5
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "../../dist/out-tsc",
5
+ "module": "commonjs",
6
+ "types": ["jest", "node"],
7
+ "allowJs": true
8
+ },
9
+ "include": ["**/*.test.ts", "**/*.spec.ts", "**/*.d.ts"]
10
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2016-present Availity, LLC
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
package/dist/date.d.ts DELETED
@@ -1,23 +0,0 @@
1
- import { MixedSchema } from 'yup';
2
- import moment, { Moment } from 'moment';
3
- export default class AvDateSchema extends MixedSchema<Moment> {
4
- format: string;
5
- constructor({ format }?: Options);
6
- _typeCheck(value: Moment & {
7
- _i: string;
8
- }): value is Moment & {
9
- _i: string;
10
- };
11
- getValidDate(value: string | Date | Moment): moment.Moment;
12
- min(min: string, message?: string): this;
13
- max(max: string, message?: string): this;
14
- isRequired(isRequired?: boolean, msg?: string): this;
15
- between(min: string, max: string, msg?: string, inclusivity?: Inclusivity): this;
16
- }
17
- export declare type Inclusivity = '()' | '[)' | '(]' | '[]';
18
- declare type Options = {
19
- format?: string;
20
- };
21
- export declare const avDate: (opts?: Options | undefined) => AvDateSchema;
22
- export {};
23
- //# sourceMappingURL=date.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../src/date.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,KAAK,CAAC;AAClC,OAAO,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAIxC,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,WAAW,CAAC,MAAM,CAAC;IAC3D,MAAM,EAAE,MAAM,CAAC;gBAEH,EAAE,MAAqB,EAAE,GAAE,OAAY;IAiBnD,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,GAAG,KAAK,IAAI,MAAM,GAAG;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE;IAQ5E,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM;IAI1C,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM;IAiBjC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM;IAiBjC,UAAU,CAAC,UAAU,UAAO,EAAE,GAAG,CAAC,EAAE,MAAM;IAe1C,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,WAAW,GAAE,WAAkB;CAmBhF;AAED,oBAAY,WAAW,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AACpD,aAAK,OAAO,GAAG;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAEnC,eAAO,MAAM,MAAM,kCAAqB,YAAsC,CAAC"}
package/dist/date.js DELETED
@@ -1,123 +0,0 @@
1
- var __extends = (this && this.__extends) || (function () {
2
- var extendStatics = function (d, b) {
3
- extendStatics = Object.setPrototypeOf ||
4
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
- return extendStatics(d, b);
7
- };
8
- return function (d, b) {
9
- if (typeof b !== "function" && b !== null)
10
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
- extendStatics(d, b);
12
- function __() { this.constructor = d; }
13
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
- };
15
- })();
16
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
17
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
18
- if (ar || !(i in from)) {
19
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
20
- ar[i] = from[i];
21
- }
22
- }
23
- return to.concat(ar || Array.prototype.slice.call(from));
24
- };
25
- /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
26
- import { MixedSchema } from 'yup';
27
- import moment from 'moment';
28
- var formats = ['YYYY-MM-DD', 'MMDDYYYY', 'YYYYMMDD', 'MM-DD-YYYY'];
29
- var AvDateSchema = /** @class */ (function (_super) {
30
- __extends(AvDateSchema, _super);
31
- function AvDateSchema(_a) {
32
- var _b = _a === void 0 ? {} : _a, _c = _b.format, format = _c === void 0 ? 'MM/DD/YYYY' : _c;
33
- var _this = _super.call(this, {
34
- type: 'avDate',
35
- }) || this;
36
- _this.format = format;
37
- _this.withMutation(function (schema) {
38
- if (!schema.tests.some(function (test) { var _a; return ((_a = test === null || test === void 0 ? void 0 : test.OPTIONS) === null || _a === void 0 ? void 0 : _a.name) === 'typeError'; })) {
39
- _super.prototype.typeError.call(_this, 'Date is invalid.');
40
- }
41
- schema.transform(function mutate(value) {
42
- return schema.getValidDate(value);
43
- });
44
- });
45
- return _this;
46
- }
47
- AvDateSchema.prototype._typeCheck = function (value) {
48
- // So as long as the passed in value is defined, moment._i will contain a string value to validate.
49
- // If user enters a date and then removes it, should not show a typeError
50
- // Note: this does not prevent other tests, like isRequired, from showing messages
51
- // If user has touched a required field, required error message should still show
52
- return value.isValid() || value._i === '';
53
- };
54
- AvDateSchema.prototype.getValidDate = function (value) {
55
- return moment(value, __spreadArray([this.format], formats, true), true);
56
- };
57
- AvDateSchema.prototype.min = function (min, message) {
58
- var minDate = this.getValidDate(min);
59
- return this.test({
60
- message: message || "Date must be " + minDate.format(this.format) + " or later.",
61
- name: 'min',
62
- exclusive: true,
63
- params: { min: min },
64
- test: function (value) {
65
- if (!min || !minDate.isValid()) {
66
- return true;
67
- }
68
- return value === null || minDate.isSameOrBefore(value);
69
- },
70
- });
71
- };
72
- AvDateSchema.prototype.max = function (max, message) {
73
- var maxDate = this.getValidDate(max);
74
- return this.test({
75
- message: message || "Date must be " + maxDate.format(this.format) + " or earlier.",
76
- name: 'max',
77
- exclusive: true,
78
- params: { max: max },
79
- test: function (value) {
80
- if (!max || !maxDate.isValid()) {
81
- return true;
82
- }
83
- return value === null || maxDate.isSameOrAfter(value);
84
- },
85
- });
86
- };
87
- AvDateSchema.prototype.isRequired = function (isRequired, msg) {
88
- if (isRequired === void 0) { isRequired = true; }
89
- return this.test({
90
- name: 'isRequired',
91
- exclusive: true,
92
- message: msg || 'This field is required.',
93
- test: function (value) {
94
- if (!isRequired) {
95
- return true;
96
- }
97
- return value !== undefined;
98
- },
99
- });
100
- };
101
- AvDateSchema.prototype.between = function (min, max, msg, inclusivity) {
102
- if (inclusivity === void 0) { inclusivity = '()'; }
103
- var minDate = this.getValidDate(min);
104
- var maxDate = this.getValidDate(max);
105
- // Can't use arrow function because we rely on 'this' referencing yup's internals
106
- return this.test({
107
- name: 'between',
108
- exclusive: true,
109
- // NOTE: Intentional use of single quotes - yup will handle the string interpolation
110
- message: msg || "Date must be between " + minDate.format(this.format) + " and " + maxDate.format(this.format) + ".",
111
- test: function (value) {
112
- if (!value || !min || !max || !minDate.isValid() || !maxDate.isValid()) {
113
- return true;
114
- }
115
- return value.isBetween(minDate, maxDate, undefined, inclusivity);
116
- },
117
- });
118
- };
119
- return AvDateSchema;
120
- }(MixedSchema));
121
- export default AvDateSchema;
122
- export var avDate = function (opts) { return new AvDateSchema(opts); };
123
- //# sourceMappingURL=date.js.map
package/dist/date.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"date.js","sourceRoot":"","sources":["../src/date.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,sEAAsE;A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';
3
- export default class DateRangeSchema extends MixedSchema<DateRange> {
4
- startKey: string;
5
- endKey: string;
6
- format: string;
7
- constructor(options?: Options);
8
- getValidDate(value: string | Date | Moment): moment.Moment;
9
- distance({ min: { value: minValue, units: minUnits, errorMessage: minErrorMessage }, max: { value: maxValue, units: maxUnits, errorMessage: maxErrorMessage }, }?: DistanceOptions): this;
10
- min(min: string, message?: string): this;
11
- max(max: string, message?: string): this;
12
- between(min: string, max: string, message?: string): this;
13
- isRequired(isRequired?: boolean, msg?: string): this;
14
- typeError({ message }: {
15
- message: string;
16
- }): this;
17
- _typeCheck(range?: {
18
- startDate?: Moment;
19
- endDate?: Moment;
20
- }): range is DateRange;
21
- }
22
- declare type Options = {
23
- startKey?: string;
24
- endKey?: string;
25
- format?: string;
26
- };
27
- declare type DateRange = {
28
- startDate?: Moment;
29
- endDate?: Moment;
30
- supportedFormats?: string[];
31
- };
32
- declare type DistanceValue = {
33
- value: number;
34
- units?: unitOfTime.DurationConstructor;
35
- errorMessage?: string;
36
- };
37
- declare type DistanceOptions = {
38
- min?: DistanceValue;
39
- max?: DistanceValue;
40
- };
41
- export declare const dateRange: (opts?: Options | undefined) => DateRangeSchema;
42
- export {};
43
- //# sourceMappingURL=dateRange.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dateRange.d.ts","sourceRoot":"","sources":["../src/dateRange.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAmB,MAAM,KAAK,CAAC;AACnD,OAAO,MAAM,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAYpD,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,WAAW,CAAC,SAAS,CAAC;IACjE,QAAQ,EAAE,MAAM,CAAC;IAEjB,MAAM,EAAE,MAAM,CAAC;IAEf,MAAM,EAAE,MAAM,CAAC;gBAEH,OAAO,CAAC,EAAE,OAAO;IA2B7B,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAA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