@webiny/validation 5.35.0-beta.0 → 5.35.0-beta.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/index.js +0 -27
- package/index.js.map +1 -1
- package/package.json +4 -4
- package/validation.js +7 -44
- package/validation.js.map +1 -1
- package/validationError.js +0 -5
- package/validationError.js.map +1 -1
- package/validators/creditCard.js +0 -14
- package/validators/creditCard.js.map +1 -1
- package/validators/dateGte.js +2 -11
- package/validators/dateGte.js.map +1 -1
- package/validators/dateLte.js +2 -11
- package/validators/dateLte.js.map +1 -1
- package/validators/email.js +2 -8
- package/validators/email.js.map +1 -1
- package/validators/eq.js +2 -7
- package/validators/eq.js.map +1 -1
- package/validators/gt.js +0 -6
- package/validators/gt.js.map +1 -1
- package/validators/gte.js +0 -6
- package/validators/gte.js.map +1 -1
- package/validators/in.js +0 -7
- package/validators/in.js.map +1 -1
- package/validators/integer.js +0 -7
- package/validators/integer.js.map +1 -1
- package/validators/json.js +0 -5
- package/validators/json.js.map +1 -1
- package/validators/lt.js +0 -7
- package/validators/lt.js.map +1 -1
- package/validators/lte.js +0 -7
- package/validators/lte.js.map +1 -1
- package/validators/maxLength.js +0 -13
- package/validators/maxLength.js.map +1 -1
- package/validators/minLength.js +0 -13
- package/validators/minLength.js.map +1 -1
- package/validators/number.js +0 -8
- package/validators/number.js.map +1 -1
- package/validators/numeric.js +0 -9
- package/validators/numeric.js.map +1 -1
- package/validators/password.js +0 -6
- package/validators/password.js.map +1 -1
- package/validators/phone.js +0 -7
- package/validators/phone.js.map +1 -1
- package/validators/required.js +0 -5
- package/validators/required.js.map +1 -1
- package/validators/slug.js +0 -7
- package/validators/slug.js.map +1 -1
- package/validators/time/index.js +0 -13
- package/validators/time/index.js.map +1 -1
- package/validators/timeGte.js +2 -12
- package/validators/timeGte.js.map +1 -1
- package/validators/timeLte.js +2 -12
- package/validators/timeLte.js.map +1 -1
- package/validators/url.js +8 -16
- package/validators/url.js.map +1 -1
package/validators/slug.js
CHANGED
|
@@ -1,26 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = void 0;
|
|
9
|
-
|
|
10
8
|
var _validationError = _interopRequireDefault(require("../validationError"));
|
|
11
|
-
|
|
12
9
|
var _default = value => {
|
|
13
10
|
if (!value) {
|
|
14
11
|
return;
|
|
15
12
|
}
|
|
16
|
-
|
|
17
13
|
value = value + "";
|
|
18
|
-
|
|
19
14
|
if (value.match(/^[a-z0-9]+(-[a-z0-9]+)*$/) && value.length <= 100) {
|
|
20
15
|
return;
|
|
21
16
|
}
|
|
22
|
-
|
|
23
17
|
throw new _validationError.default("Slug must consist of only 'a-z', '0-9' and '-' and be max 100 characters long (for example: 'some-slug' or 'some-slug-2')");
|
|
24
18
|
};
|
|
25
|
-
|
|
26
19
|
exports.default = _default;
|
package/validators/slug.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["value","match","length","ValidationError"],"sources":["slug.ts"],"sourcesContent":["import ValidationError from \"~/validationError\";\n\nexport default (value: any) => {\n if (!value) {\n return;\n }\n value = value + \"\";\n\n if (value.match(/^[a-z0-9]+(-[a-z0-9]+)*$/) && value.length <= 100) {\n return;\n }\n\n throw new ValidationError(\n \"Slug must consist of only 'a-z', '0-9' and '-' and be max 100 characters long (for example: 'some-slug' or 'some-slug-2')\"\n );\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["value","match","length","ValidationError"],"sources":["slug.ts"],"sourcesContent":["import ValidationError from \"~/validationError\";\n\nexport default (value: any) => {\n if (!value) {\n return;\n }\n value = value + \"\";\n\n if (value.match(/^[a-z0-9]+(-[a-z0-9]+)*$/) && value.length <= 100) {\n return;\n }\n\n throw new ValidationError(\n \"Slug must consist of only 'a-z', '0-9' and '-' and be max 100 characters long (for example: 'some-slug' or 'some-slug-2')\"\n );\n};\n"],"mappings":";;;;;;;AAAA;AAAgD,eAEhCA,KAAU,IAAK;EAC3B,IAAI,CAACA,KAAK,EAAE;IACR;EACJ;EACAA,KAAK,GAAGA,KAAK,GAAG,EAAE;EAElB,IAAIA,KAAK,CAACC,KAAK,CAAC,0BAA0B,CAAC,IAAID,KAAK,CAACE,MAAM,IAAI,GAAG,EAAE;IAChE;EACJ;EAEA,MAAM,IAAIC,wBAAe,CACrB,2HAA2H,CAC9H;AACL,CAAC;AAAA"}
|
package/validators/time/index.js
CHANGED
|
@@ -1,23 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.compareTime = void 0;
|
|
9
|
-
|
|
10
8
|
var _validationError = _interopRequireDefault(require("../../validationError"));
|
|
11
|
-
|
|
12
9
|
const parseTime = value => {
|
|
13
10
|
const parsed = value.split(":").map(Number);
|
|
14
|
-
|
|
15
11
|
if (parsed.length < 2) {
|
|
16
12
|
throw new _validationError.default(`Value "${value}" does not look like time.`);
|
|
17
13
|
}
|
|
18
|
-
|
|
19
14
|
const [hours, minutes, seconds = 0] = parsed;
|
|
20
|
-
|
|
21
15
|
if (hours >= 24) {
|
|
22
16
|
throw new _validationError.default(`There cannot be more than 24 hours. Value parsed is "${value}".`);
|
|
23
17
|
} else if (hours < 0) {
|
|
@@ -31,7 +25,6 @@ const parseTime = value => {
|
|
|
31
25
|
} else if (seconds < 0) {
|
|
32
26
|
throw new _validationError.default(`Seconds cannot go into negative. Value parsed is "${value}".`);
|
|
33
27
|
}
|
|
34
|
-
|
|
35
28
|
return {
|
|
36
29
|
hours,
|
|
37
30
|
minutes,
|
|
@@ -43,8 +36,6 @@ const parseTime = value => {
|
|
|
43
36
|
* returns 0 if they are equal
|
|
44
37
|
* returns -1 if compareTo is greater than time
|
|
45
38
|
*/
|
|
46
|
-
|
|
47
|
-
|
|
48
39
|
const compareTime = (time, compareTo) => {
|
|
49
40
|
const {
|
|
50
41
|
hours: timeHours,
|
|
@@ -56,11 +47,9 @@ const compareTime = (time, compareTo) => {
|
|
|
56
47
|
minutes: compareToMinutes,
|
|
57
48
|
seconds: compareToSeconds
|
|
58
49
|
} = parseTime(compareTo);
|
|
59
|
-
|
|
60
50
|
if (timeHours > compareToHours) {
|
|
61
51
|
return 1;
|
|
62
52
|
}
|
|
63
|
-
|
|
64
53
|
if (timeHours === compareToHours) {
|
|
65
54
|
if (timeMinutes > compareToMinutes) {
|
|
66
55
|
return 1;
|
|
@@ -72,8 +61,6 @@ const compareTime = (time, compareTo) => {
|
|
|
72
61
|
}
|
|
73
62
|
}
|
|
74
63
|
}
|
|
75
|
-
|
|
76
64
|
return -1;
|
|
77
65
|
};
|
|
78
|
-
|
|
79
66
|
exports.compareTime = compareTime;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["parseTime","value","parsed","split","map","Number","length","ValidationError","hours","minutes","seconds","compareTime","time","compareTo","timeHours","timeMinutes","timeSeconds","compareToHours","compareToMinutes","compareToSeconds"],"sources":["index.ts"],"sourcesContent":["import ValidationError from \"~/validationError\";\n\ninterface ParsedTimeResult {\n hours: number;\n minutes: number;\n seconds: number;\n}\nconst parseTime = (value: string): ParsedTimeResult => {\n const parsed = value.split(\":\").map(Number);\n if (parsed.length < 2) {\n throw new ValidationError(`Value \"${value}\" does not look like time.`);\n }\n const [hours, minutes, seconds = 0] = parsed;\n if (hours >= 24) {\n throw new ValidationError(\n `There cannot be more than 24 hours. Value parsed is \"${value}\".`\n );\n } else if (hours < 0) {\n throw new ValidationError(`Hours cannot go into negative. Value parsed is \"${value}\".`);\n } else if (minutes >= 60) {\n throw new ValidationError(\n `There cannot be more than 59 minutes. Value parsed is \"${value}\".`\n );\n } else if (minutes < 0) {\n throw new ValidationError(`Minutes cannot go into negative. Value parsed is \"${value}\".`);\n } else if (seconds >= 60) {\n throw new ValidationError(\n `There cannot be more than 59 seconds. Value parsed is \"${value}\".`\n );\n } else if (seconds < 0) {\n throw new ValidationError(`Seconds cannot go into negative. Value parsed is \"${value}\".`);\n }\n return {\n hours,\n minutes,\n seconds\n };\n};\n/**\n * returns 1 if time is greater than compareTo\n * returns 0 if they are equal\n * returns -1 if compareTo is greater than time\n */\nexport const compareTime = (time: string, compareTo: string): number => {\n const { hours: timeHours, minutes: timeMinutes, seconds: timeSeconds } = parseTime(time);\n const {\n hours: compareToHours,\n minutes: compareToMinutes,\n seconds: compareToSeconds\n } = parseTime(compareTo);\n if (timeHours > compareToHours) {\n return 1;\n }\n if (timeHours === compareToHours) {\n if (timeMinutes > compareToMinutes) {\n return 1;\n } else if (timeMinutes === compareToMinutes) {\n if (timeSeconds > compareToSeconds) {\n return 1;\n } else if (timeSeconds === compareToSeconds) {\n return 0;\n }\n }\n }\n return -1;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["parseTime","value","parsed","split","map","Number","length","ValidationError","hours","minutes","seconds","compareTime","time","compareTo","timeHours","timeMinutes","timeSeconds","compareToHours","compareToMinutes","compareToSeconds"],"sources":["index.ts"],"sourcesContent":["import ValidationError from \"~/validationError\";\n\ninterface ParsedTimeResult {\n hours: number;\n minutes: number;\n seconds: number;\n}\nconst parseTime = (value: string): ParsedTimeResult => {\n const parsed = value.split(\":\").map(Number);\n if (parsed.length < 2) {\n throw new ValidationError(`Value \"${value}\" does not look like time.`);\n }\n const [hours, minutes, seconds = 0] = parsed;\n if (hours >= 24) {\n throw new ValidationError(\n `There cannot be more than 24 hours. Value parsed is \"${value}\".`\n );\n } else if (hours < 0) {\n throw new ValidationError(`Hours cannot go into negative. Value parsed is \"${value}\".`);\n } else if (minutes >= 60) {\n throw new ValidationError(\n `There cannot be more than 59 minutes. Value parsed is \"${value}\".`\n );\n } else if (minutes < 0) {\n throw new ValidationError(`Minutes cannot go into negative. Value parsed is \"${value}\".`);\n } else if (seconds >= 60) {\n throw new ValidationError(\n `There cannot be more than 59 seconds. Value parsed is \"${value}\".`\n );\n } else if (seconds < 0) {\n throw new ValidationError(`Seconds cannot go into negative. Value parsed is \"${value}\".`);\n }\n return {\n hours,\n minutes,\n seconds\n };\n};\n/**\n * returns 1 if time is greater than compareTo\n * returns 0 if they are equal\n * returns -1 if compareTo is greater than time\n */\nexport const compareTime = (time: string, compareTo: string): number => {\n const { hours: timeHours, minutes: timeMinutes, seconds: timeSeconds } = parseTime(time);\n const {\n hours: compareToHours,\n minutes: compareToMinutes,\n seconds: compareToSeconds\n } = parseTime(compareTo);\n if (timeHours > compareToHours) {\n return 1;\n }\n if (timeHours === compareToHours) {\n if (timeMinutes > compareToMinutes) {\n return 1;\n } else if (timeMinutes === compareToMinutes) {\n if (timeSeconds > compareToSeconds) {\n return 1;\n } else if (timeSeconds === compareToSeconds) {\n return 0;\n }\n }\n }\n return -1;\n};\n"],"mappings":";;;;;;;AAAA;AAOA,MAAMA,SAAS,GAAIC,KAAa,IAAuB;EACnD,MAAMC,MAAM,GAAGD,KAAK,CAACE,KAAK,CAAC,GAAG,CAAC,CAACC,GAAG,CAACC,MAAM,CAAC;EAC3C,IAAIH,MAAM,CAACI,MAAM,GAAG,CAAC,EAAE;IACnB,MAAM,IAAIC,wBAAe,CAAE,UAASN,KAAM,4BAA2B,CAAC;EAC1E;EACA,MAAM,CAACO,KAAK,EAAEC,OAAO,EAAEC,OAAO,GAAG,CAAC,CAAC,GAAGR,MAAM;EAC5C,IAAIM,KAAK,IAAI,EAAE,EAAE;IACb,MAAM,IAAID,wBAAe,CACpB,wDAAuDN,KAAM,IAAG,CACpE;EACL,CAAC,MAAM,IAAIO,KAAK,GAAG,CAAC,EAAE;IAClB,MAAM,IAAID,wBAAe,CAAE,mDAAkDN,KAAM,IAAG,CAAC;EAC3F,CAAC,MA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AC"}
|
package/validators/timeGte.js
CHANGED
|
@@ -1,38 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = void 0;
|
|
9
|
-
|
|
10
8
|
var _validationError = _interopRequireDefault(require("../validationError"));
|
|
11
|
-
|
|
12
9
|
var _time = require("./time");
|
|
13
|
-
|
|
14
10
|
/**
|
|
15
11
|
* Validates that given value is a greater or equal to a gteValue
|
|
16
12
|
*/
|
|
17
13
|
var _default = (value, params) => {
|
|
18
14
|
if (!value || !params) {
|
|
19
15
|
return;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
}
|
|
17
|
+
// we need to join because validation params are being split by :
|
|
23
18
|
const gteValue = params.join(":");
|
|
24
|
-
|
|
25
19
|
if (!gteValue) {
|
|
26
20
|
return;
|
|
27
21
|
}
|
|
28
|
-
|
|
29
22
|
const compare = (0, _time.compareTime)(value, gteValue);
|
|
30
|
-
|
|
31
23
|
if (compare >= 0) {
|
|
32
24
|
return;
|
|
33
25
|
}
|
|
34
|
-
|
|
35
26
|
throw new _validationError.default(`Value needs to be greater than or equal to "${gteValue}".`);
|
|
36
27
|
};
|
|
37
|
-
|
|
38
28
|
exports.default = _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["value","params","gteValue","join","compare","compareTime","ValidationError"],"sources":["timeGte.ts"],"sourcesContent":["import ValidationError from \"~/validationError\";\nimport { compareTime } from \"./time\";\n\n/**\n * Validates that given value is a greater or equal to a gteValue\n */\nexport default (value: string, params?: string[]) => {\n if (!value || !params) {\n return;\n }\n // we need to join because validation params are being split by :\n const gteValue = params.join(\":\");\n if (!gteValue) {\n return;\n }\n\n const compare = compareTime(value, gteValue);\n\n if (compare >= 0) {\n return;\n }\n throw new ValidationError(`Value needs to be greater than or equal to \"${gteValue}\".`);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["value","params","gteValue","join","compare","compareTime","ValidationError"],"sources":["timeGte.ts"],"sourcesContent":["import ValidationError from \"~/validationError\";\nimport { compareTime } from \"./time\";\n\n/**\n * Validates that given value is a greater or equal to a gteValue\n */\nexport default (value: string, params?: string[]) => {\n if (!value || !params) {\n return;\n }\n // we need to join because validation params are being split by :\n const gteValue = params.join(\":\");\n if (!gteValue) {\n return;\n }\n\n const compare = compareTime(value, gteValue);\n\n if (compare >= 0) {\n return;\n }\n throw new ValidationError(`Value needs to be greater than or equal to \"${gteValue}\".`);\n};\n"],"mappings":";;;;;;;AAAA;AACA;AAEA;AACA;AACA;AAFA,eAGe,CAACA,KAAa,EAAEC,MAAiB,KAAK;EACjD,IAAI,CAACD,KAAK,IAAI,CAACC,MAAM,EAAE;IACnB;EACJ;EACA;EACA,MAAMC,QAAQ,GAAGD,MAAM,CAACE,IAAI,CAAC,GAAG,CAAC;EACjC,IAAI,CAACD,QAAQ,EAAE;IACX;EACJ;EAEA,MAAME,OAAO,GAAG,IAAAC,iBAAW,EAACL,KAAK,EAAEE,QAAQ,CAAC;EAE5C,IAAIE,OAAO,IAAI,CAAC,EAAE;IACd;EACJ;EACA,MAAM,IAAIE,wBAAe,CAAE,+CAA8CJ,QAAS,IAAG,CAAC;AAC1F,CAAC;AAAA"}
|
package/validators/timeLte.js
CHANGED
|
@@ -1,38 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = void 0;
|
|
9
|
-
|
|
10
8
|
var _validationError = _interopRequireDefault(require("../validationError"));
|
|
11
|
-
|
|
12
9
|
var _time = require("./time");
|
|
13
|
-
|
|
14
10
|
/**
|
|
15
11
|
* Validates that given value is a leaser or equal to a lteValue
|
|
16
12
|
*/
|
|
17
13
|
var _default = (value, params) => {
|
|
18
14
|
if (!value || !params) {
|
|
19
15
|
return;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
}
|
|
17
|
+
// we need to join because validation params are being split by :
|
|
23
18
|
const lteValue = params.join(":");
|
|
24
|
-
|
|
25
19
|
if (!lteValue) {
|
|
26
20
|
return;
|
|
27
21
|
}
|
|
28
|
-
|
|
29
22
|
const compare = (0, _time.compareTime)(value, lteValue);
|
|
30
|
-
|
|
31
23
|
if (compare <= 0) {
|
|
32
24
|
return;
|
|
33
25
|
}
|
|
34
|
-
|
|
35
26
|
throw new _validationError.default(`Value needs to be lesser than or equal to "${lteValue}".`);
|
|
36
27
|
};
|
|
37
|
-
|
|
38
28
|
exports.default = _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["value","params","lteValue","join","compare","compareTime","ValidationError"],"sources":["timeLte.ts"],"sourcesContent":["import ValidationError from \"~/validationError\";\nimport { compareTime } from \"./time\";\n\n/**\n * Validates that given value is a leaser or equal to a lteValue\n */\nexport default (value: string, params?: string[]) => {\n if (!value || !params) {\n return;\n }\n // we need to join because validation params are being split by :\n const lteValue = params.join(\":\");\n if (!lteValue) {\n return;\n }\n\n const compare = compareTime(value, lteValue);\n if (compare <= 0) {\n return;\n }\n throw new ValidationError(`Value needs to be lesser than or equal to \"${lteValue}\".`);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["value","params","lteValue","join","compare","compareTime","ValidationError"],"sources":["timeLte.ts"],"sourcesContent":["import ValidationError from \"~/validationError\";\nimport { compareTime } from \"./time\";\n\n/**\n * Validates that given value is a leaser or equal to a lteValue\n */\nexport default (value: string, params?: string[]) => {\n if (!value || !params) {\n return;\n }\n // we need to join because validation params are being split by :\n const lteValue = params.join(\":\");\n if (!lteValue) {\n return;\n }\n\n const compare = compareTime(value, lteValue);\n if (compare <= 0) {\n return;\n }\n throw new ValidationError(`Value needs to be lesser than or equal to \"${lteValue}\".`);\n};\n"],"mappings":";;;;;;;AAAA;AACA;AAEA;AACA;AACA;AAFA,eAGe,CAACA,KAAa,EAAEC,MAAiB,KAAK;EACjD,IAAI,CAACD,KAAK,IAAI,CAACC,MAAM,EAAE;IACnB;EACJ;EACA;EACA,MAAMC,QAAQ,GAAGD,MAAM,CAACE,IAAI,CAAC,GAAG,CAAC;EACjC,IAAI,CAACD,QAAQ,EAAE;IACX;EACJ;EAEA,MAAME,OAAO,GAAG,IAAAC,iBAAW,EAACL,KAAK,EAAEE,QAAQ,CAAC;EAC5C,IAAIE,OAAO,IAAI,CAAC,EAAE;IACd;EACJ;EACA,MAAM,IAAIE,wBAAe,CAAE,8CAA6CJ,QAAS,IAAG,CAAC;AACzF,CAAC;AAAA"}
|
package/validators/url.js
CHANGED
|
@@ -1,59 +1,51 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = void 0;
|
|
9
|
-
|
|
10
8
|
var _validationError = _interopRequireDefault(require("../validationError"));
|
|
11
|
-
|
|
12
9
|
const regex = {
|
|
13
|
-
base: new RegExp(
|
|
10
|
+
base: new RegExp(
|
|
11
|
+
// eslint-disable-next-line
|
|
14
12
|
/^(https?:\/\/)((([a-z\d]([a-z\d-]*[a-z\d])*)\.)+[a-z]{2,}|((\d{1,3}\.){3}\d{1,3}))(\:\d+)?(\/[-a-z\d%_.~+]*)*(\?[;&a-z\d%_.~+=!-]*)?(\#[-a-z\d_]*)?$/i),
|
|
15
|
-
ip: new RegExp(
|
|
13
|
+
ip: new RegExp(
|
|
14
|
+
// eslint-disable-next-line
|
|
16
15
|
/^(https?:\/\/)(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/),
|
|
17
|
-
relative: new RegExp(
|
|
16
|
+
relative: new RegExp(
|
|
17
|
+
// eslint-disable-next-line
|
|
18
18
|
/^\/.*$/),
|
|
19
|
-
href: new RegExp(
|
|
19
|
+
href: new RegExp(
|
|
20
|
+
// eslint-disable-next-line
|
|
20
21
|
/^(#|mailto:|tel:)\S*$/)
|
|
21
22
|
};
|
|
22
|
-
|
|
23
23
|
var _default = (value, params) => {
|
|
24
24
|
if (!value || !params) {
|
|
25
25
|
return;
|
|
26
26
|
}
|
|
27
|
-
|
|
28
27
|
value = value + "";
|
|
29
|
-
|
|
30
28
|
if (value.startsWith("http://localhost") || value.startsWith("https://localhost")) {
|
|
31
29
|
value = value.replace("//localhost", "//localhost.com");
|
|
32
30
|
}
|
|
33
|
-
|
|
34
31
|
if (regex.base.test(value)) {
|
|
35
32
|
if (!params.includes("noIp")) {
|
|
36
33
|
return;
|
|
37
34
|
}
|
|
38
|
-
|
|
39
35
|
if (!regex.ip.test(value)) {
|
|
40
36
|
return;
|
|
41
37
|
}
|
|
42
38
|
}
|
|
43
|
-
|
|
44
39
|
if (params.includes("allowRelative")) {
|
|
45
40
|
if (regex.relative.test(value)) {
|
|
46
41
|
return;
|
|
47
42
|
}
|
|
48
43
|
}
|
|
49
|
-
|
|
50
44
|
if (params.includes("allowHref")) {
|
|
51
45
|
if (regex.href.test(value)) {
|
|
52
46
|
return;
|
|
53
47
|
}
|
|
54
48
|
}
|
|
55
|
-
|
|
56
49
|
throw new _validationError.default("Value must be a valid URL.");
|
|
57
50
|
};
|
|
58
|
-
|
|
59
51
|
exports.default = _default;
|
package/validators/url.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["regex","base","RegExp","ip","relative","href","value","params","startsWith","replace","test","includes","ValidationError"],"sources":["url.ts"],"sourcesContent":["import ValidationError from \"~/validationError\";\n\nconst regex = {\n base: new RegExp(\n // eslint-disable-next-line\n /^(https?:\\/\\/)((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|((\\d{1,3}\\.){3}\\d{1,3}))(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*(\\?[;&a-z\\d%_.~+=!-]*)?(\\#[-a-z\\d_]*)?$/i\n ),\n ip: new RegExp(\n // eslint-disable-next-line\n /^(https?:\\/\\/)(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/\n ),\n relative: new RegExp(\n // eslint-disable-next-line\n /^\\/.*$/\n ),\n href: new RegExp(\n // eslint-disable-next-line\n /^(#|mailto:|tel:)\\S*$/\n )\n};\n\nexport default (value: any, params?: string[]) => {\n if (!value || !params) {\n return;\n }\n value = value + \"\";\n\n if (value.startsWith(\"http://localhost\") || value.startsWith(\"https://localhost\")) {\n value = value.replace(\"//localhost\", \"//localhost.com\");\n }\n\n if (regex.base.test(value)) {\n if (!params.includes(\"noIp\")) {\n return;\n }\n\n if (!regex.ip.test(value)) {\n return;\n }\n }\n\n if (params.includes(\"allowRelative\")) {\n if (regex.relative.test(value)) {\n return;\n }\n }\n\n if (params.includes(\"allowHref\")) {\n if (regex.href.test(value)) {\n return;\n }\n }\n\n throw new ValidationError(\"Value must be a valid URL.\");\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["regex","base","RegExp","ip","relative","href","value","params","startsWith","replace","test","includes","ValidationError"],"sources":["url.ts"],"sourcesContent":["import ValidationError from \"~/validationError\";\n\nconst regex = {\n base: new RegExp(\n // eslint-disable-next-line\n /^(https?:\\/\\/)((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|((\\d{1,3}\\.){3}\\d{1,3}))(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*(\\?[;&a-z\\d%_.~+=!-]*)?(\\#[-a-z\\d_]*)?$/i\n ),\n ip: new RegExp(\n // eslint-disable-next-line\n /^(https?:\\/\\/)(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/\n ),\n relative: new RegExp(\n // eslint-disable-next-line\n /^\\/.*$/\n ),\n href: new RegExp(\n // eslint-disable-next-line\n /^(#|mailto:|tel:)\\S*$/\n )\n};\n\nexport default (value: any, params?: string[]) => {\n if (!value || !params) {\n return;\n }\n value = value + \"\";\n\n if (value.startsWith(\"http://localhost\") || value.startsWith(\"https://localhost\")) {\n value = value.replace(\"//localhost\", \"//localhost.com\");\n }\n\n if (regex.base.test(value)) {\n if (!params.includes(\"noIp\")) {\n return;\n }\n\n if (!regex.ip.test(value)) {\n return;\n }\n }\n\n if (params.includes(\"allowRelative\")) {\n if (regex.relative.test(value)) {\n return;\n }\n }\n\n if (params.includes(\"allowHref\")) {\n if (regex.href.test(value)) {\n return;\n }\n }\n\n throw new ValidationError(\"Value must be a valid URL.\");\n};\n"],"mappings":";;;;;;;AAAA;AAEA,MAAMA,KAAK,GAAG;EACVC,IAAI,EAAE,IAAIC,MAAM;EACZ;EACA,uJAAuJ,CAC1J;EACDC,EAAE,EAAE,IAAID,MAAM;EACV;EACA,+KAA+K,CAClL;EACDE,QAAQ,EAAE,IAAIF,MAAM;EAChB;EACA,QAAQ,CACX;EACDG,IAAI,EAAE,IAAIH,MAAM;EACZ;EACA,uBAAuB;AAE/B,CAAC;AAAC,eAEa,CAACI,KAAU,EAAEC,MAAiB,KAAK;EAC9C,IAAI,CAACD,KAAK,IAAI,CAACC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