@webiny/validation 0.0.0-ee-vpcs.549378cf03

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.
Files changed (87) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +409 -0
  3. package/index.d.ts +4 -0
  4. package/index.js +96 -0
  5. package/index.js.map +1 -0
  6. package/package.json +45 -0
  7. package/types.d.ts +30 -0
  8. package/types.js +5 -0
  9. package/types.js.map +1 -0
  10. package/validation.d.ts +62 -0
  11. package/validation.js +199 -0
  12. package/validation.js.map +1 -0
  13. package/validationError.d.ts +10 -0
  14. package/validationError.js +29 -0
  15. package/validationError.js.map +1 -0
  16. package/validators/creditCard.d.ts +15 -0
  17. package/validators/creditCard.js +69 -0
  18. package/validators/creditCard.js.map +1 -0
  19. package/validators/dateGte.d.ts +5 -0
  20. package/validators/dateGte.js +37 -0
  21. package/validators/dateGte.js.map +1 -0
  22. package/validators/dateLte.d.ts +5 -0
  23. package/validators/dateLte.js +37 -0
  24. package/validators/dateLte.js.map +1 -0
  25. package/validators/email.d.ts +15 -0
  26. package/validators/email.js +41 -0
  27. package/validators/email.js.map +1 -0
  28. package/validators/eq.d.ts +16 -0
  29. package/validators/eq.js +41 -0
  30. package/validators/eq.js.map +1 -0
  31. package/validators/gt.d.ts +16 -0
  32. package/validators/gt.js +38 -0
  33. package/validators/gt.js.map +1 -0
  34. package/validators/gte.d.ts +16 -0
  35. package/validators/gte.js +38 -0
  36. package/validators/gte.js.map +1 -0
  37. package/validators/in.d.ts +2 -0
  38. package/validators/in.js +27 -0
  39. package/validators/in.js.map +1 -0
  40. package/validators/integer.d.ts +2 -0
  41. package/validators/integer.js +26 -0
  42. package/validators/integer.js.map +1 -0
  43. package/validators/json.d.ts +2 -0
  44. package/validators/json.js +24 -0
  45. package/validators/json.js.map +1 -0
  46. package/validators/lt.d.ts +2 -0
  47. package/validators/lt.js +26 -0
  48. package/validators/lt.js.map +1 -0
  49. package/validators/lte.d.ts +2 -0
  50. package/validators/lte.js +26 -0
  51. package/validators/lte.js.map +1 -0
  52. package/validators/maxLength.d.ts +2 -0
  53. package/validators/maxLength.js +44 -0
  54. package/validators/maxLength.js.map +1 -0
  55. package/validators/minLength.d.ts +2 -0
  56. package/validators/minLength.js +44 -0
  57. package/validators/minLength.js.map +1 -0
  58. package/validators/number.d.ts +8 -0
  59. package/validators/number.js +34 -0
  60. package/validators/number.js.map +1 -0
  61. package/validators/numeric.d.ts +8 -0
  62. package/validators/numeric.js +42 -0
  63. package/validators/numeric.js.map +1 -0
  64. package/validators/password.d.ts +2 -0
  65. package/validators/password.js +26 -0
  66. package/validators/password.js.map +1 -0
  67. package/validators/phone.d.ts +2 -0
  68. package/validators/phone.js +26 -0
  69. package/validators/phone.js.map +1 -0
  70. package/validators/required.d.ts +2 -0
  71. package/validators/required.js +22 -0
  72. package/validators/required.js.map +1 -0
  73. package/validators/slug.d.ts +2 -0
  74. package/validators/slug.js +26 -0
  75. package/validators/slug.js.map +1 -0
  76. package/validators/time/index.d.ts +6 -0
  77. package/validators/time/index.js +79 -0
  78. package/validators/time/index.js.map +1 -0
  79. package/validators/timeGte.d.ts +5 -0
  80. package/validators/timeGte.js +38 -0
  81. package/validators/timeGte.js.map +1 -0
  82. package/validators/timeLte.d.ts +5 -0
  83. package/validators/timeLte.js +38 -0
  84. package/validators/timeLte.js.map +1 -0
  85. package/validators/url.d.ts +2 -0
  86. package/validators/url.js +59 -0
  87. package/validators/url.js.map +1 -0
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @name gt
3
+ * @description "Greater than" validator. This validator checks if the given values is greater than the `min` value.
4
+ * @param {any} value This is the value that will be validated.
5
+ * @param {Array<string>} params This is the value to validate against. It is passed as a validator parameter: `gt:valueToCompareAgainst`
6
+ * @throws {ValidationError}
7
+ * @example
8
+ * import { validation } from '@webiny/validation';
9
+ * validation.validate(10, 'gt:100').then(() => {
10
+ * // Valid
11
+ * }).catch(e => {
12
+ * // Invalid
13
+ * });
14
+ */
15
+ declare const _default: (value: any, params?: string[]) => void;
16
+ export default _default;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+
10
+ var _validationError = _interopRequireDefault(require("../validationError"));
11
+
12
+ /**
13
+ * @name gt
14
+ * @description "Greater than" validator. This validator checks if the given values is greater than the `min` value.
15
+ * @param {any} value This is the value that will be validated.
16
+ * @param {Array<string>} params This is the value to validate against. It is passed as a validator parameter: `gt:valueToCompareAgainst`
17
+ * @throws {ValidationError}
18
+ * @example
19
+ * import { validation } from '@webiny/validation';
20
+ * validation.validate(10, 'gt:100').then(() => {
21
+ * // Valid
22
+ * }).catch(e => {
23
+ * // Invalid
24
+ * });
25
+ */
26
+ var _default = (value, params) => {
27
+ if (!value || !params) {
28
+ return;
29
+ }
30
+
31
+ if (parseFloat(value) > parseFloat(params[0])) {
32
+ return;
33
+ }
34
+
35
+ throw new _validationError.default("Value needs to be greater than " + params[0] + ".");
36
+ };
37
+
38
+ exports.default = _default;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["value","params","parseFloat","ValidationError"],"sources":["gt.ts"],"sourcesContent":["import ValidationError from \"~/validationError\";\n\n/**\n * @name gt\n * @description \"Greater than\" validator. This validator checks if the given values is greater than the `min` value.\n * @param {any} value This is the value that will be validated.\n * @param {Array<string>} params This is the value to validate against. It is passed as a validator parameter: `gt:valueToCompareAgainst`\n * @throws {ValidationError}\n * @example\n * import { validation } from '@webiny/validation';\n * validation.validate(10, 'gt:100').then(() => {\n * // Valid\n * }).catch(e => {\n * // Invalid\n * });\n */\nexport default (value: any, params?: string[]) => {\n if (!value || !params) {\n return;\n }\n\n if (parseFloat(value) > parseFloat(params[0])) {\n return;\n }\n throw new ValidationError(\"Value needs to be greater than \" + params[0] + \".\");\n};\n"],"mappings":";;;;;;;;;AAAA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;eACe,CAACA,KAAD,EAAaC,MAAb,KAAmC;EAC9C,IAAI,CAACD,KAAD,IAAU,CAACC,MAAf,EAAuB;IACnB;EACH;;EAED,IAAIC,UAAU,CAACF,KAAD,CAAV,GAAoBE,UAAU,CAACD,MAAM,CAAC,CAAD,CAAP,CAAlC,EAA+C;IAC3C;EACH;;EACD,MAAM,IAAIE,wBAAJ,CAAoB,oCAAoCF,MAAM,CAAC,CAAD,CAA1C,GAAgD,GAApE,CAAN;AACH,C"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @name gte
3
+ * @description "Greater than or equals" validator. This validator checks if the given values is greater than or equal to the `min` value.
4
+ * @param {any} value This is the value that will be validated.
5
+ * @param {any} min This is the value to validate against. It is passed as a validator parameter: `gte:valueToCompareAgainst`
6
+ * @throws {ValidationError}
7
+ * @example
8
+ * import { validation } from '@webiny/validation';
9
+ * validation.validate(10, 'gte:100').then(() => {
10
+ * // Valid
11
+ * }).catch(e => {
12
+ * // Invalid
13
+ * });
14
+ */
15
+ declare const _default: (value: any, params?: string[]) => void;
16
+ export default _default;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+
10
+ var _validationError = _interopRequireDefault(require("../validationError"));
11
+
12
+ /**
13
+ * @name gte
14
+ * @description "Greater than or equals" validator. This validator checks if the given values is greater than or equal to the `min` value.
15
+ * @param {any} value This is the value that will be validated.
16
+ * @param {any} min This is the value to validate against. It is passed as a validator parameter: `gte:valueToCompareAgainst`
17
+ * @throws {ValidationError}
18
+ * @example
19
+ * import { validation } from '@webiny/validation';
20
+ * validation.validate(10, 'gte:100').then(() => {
21
+ * // Valid
22
+ * }).catch(e => {
23
+ * // Invalid
24
+ * });
25
+ */
26
+ var _default = (value, params) => {
27
+ if (!value || !params) {
28
+ return;
29
+ }
30
+
31
+ if (parseFloat(value) >= parseFloat(params[0])) {
32
+ return;
33
+ }
34
+
35
+ throw new _validationError.default("Value needs to be greater than or equal to " + params[0] + ".");
36
+ };
37
+
38
+ exports.default = _default;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["value","params","parseFloat","ValidationError"],"sources":["gte.ts"],"sourcesContent":["import ValidationError from \"~/validationError\";\n\n/**\n * @name gte\n * @description \"Greater than or equals\" validator. This validator checks if the given values is greater than or equal to the `min` value.\n * @param {any} value This is the value that will be validated.\n * @param {any} min This is the value to validate against. It is passed as a validator parameter: `gte:valueToCompareAgainst`\n * @throws {ValidationError}\n * @example\n * import { validation } from '@webiny/validation';\n * validation.validate(10, 'gte:100').then(() => {\n * // Valid\n * }).catch(e => {\n * // Invalid\n * });\n */\nexport default (value: any, params?: string[]) => {\n if (!value || !params) {\n return;\n }\n\n if (parseFloat(value) >= parseFloat(params[0])) {\n return;\n }\n throw new ValidationError(\"Value needs to be greater than or equal to \" + params[0] + \".\");\n};\n"],"mappings":";;;;;;;;;AAAA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;eACe,CAACA,KAAD,EAAaC,MAAb,KAAmC;EAC9C,IAAI,CAACD,KAAD,IAAU,CAACC,MAAf,EAAuB;IACnB;EACH;;EAED,IAAIC,UAAU,CAACF,KAAD,CAAV,IAAqBE,UAAU,CAACD,MAAM,CAAC,CAAD,CAAP,CAAnC,EAAgD;IAC5C;EACH;;EACD,MAAM,IAAIE,wBAAJ,CAAoB,gDAAgDF,MAAM,CAAC,CAAD,CAAtD,GAA4D,GAAhF,CAAN;AACH,C"}
@@ -0,0 +1,2 @@
1
+ declare const _default: (value: any, params?: string[]) => void;
2
+ export default _default;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+
10
+ var _validationError = _interopRequireDefault(require("../validationError"));
11
+
12
+ // In array validator. This validator checks if the given value is allowed to.
13
+ var _default = (value, params) => {
14
+ if (!value || !params) {
15
+ return;
16
+ }
17
+
18
+ value = value + "";
19
+
20
+ if (params.includes(value)) {
21
+ return;
22
+ }
23
+
24
+ throw new _validationError.default("Value must be one of the following: " + params.join(", ") + ".");
25
+ };
26
+
27
+ exports.default = _default;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["value","params","includes","ValidationError","join"],"sources":["in.ts"],"sourcesContent":["import ValidationError from \"~/validationError\";\n\n// In array validator. This validator checks if the given value is allowed to.\nexport default (value: any, params?: string[]) => {\n if (!value || !params) {\n return;\n }\n value = value + \"\";\n\n if (params.includes(value)) {\n return;\n }\n\n throw new ValidationError(\"Value must be one of the following: \" + params.join(\", \") + \".\");\n};\n"],"mappings":";;;;;;;;;AAAA;;AAEA;eACe,CAACA,KAAD,EAAaC,MAAb,KAAmC;EAC9C,IAAI,CAACD,KAAD,IAAU,CAACC,MAAf,EAAuB;IACnB;EACH;;EACDD,KAAK,GAAGA,KAAK,GAAG,EAAhB;;EAEA,IAAIC,MAAM,CAACC,QAAP,CAAgBF,KAAhB,CAAJ,EAA4B;IACxB;EACH;;EAED,MAAM,IAAIG,wBAAJ,CAAoB,yCAAyCF,MAAM,CAACG,IAAP,CAAY,IAAZ,CAAzC,GAA6D,GAAjF,CAAN;AACH,C"}
@@ -0,0 +1,2 @@
1
+ declare const _default: (value: any) => void;
2
+ export default _default;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+
10
+ var _isInteger2 = _interopRequireDefault(require("lodash/isInteger"));
11
+
12
+ var _validationError = _interopRequireDefault(require("../validationError"));
13
+
14
+ var _default = value => {
15
+ if (!value) {
16
+ return;
17
+ }
18
+
19
+ if ((0, _isInteger2.default)(value)) {
20
+ return;
21
+ }
22
+
23
+ throw new _validationError.default("Value needs to be an integer.");
24
+ };
25
+
26
+ exports.default = _default;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["value","ValidationError"],"sources":["integer.ts"],"sourcesContent":["import _ from \"lodash\";\nimport ValidationError from \"~/validationError\";\n\nexport default (value: any) => {\n if (!value) {\n return;\n }\n\n if (_.isInteger(value)) {\n return;\n }\n\n throw new ValidationError(\"Value needs to be an integer.\");\n};\n"],"mappings":";;;;;;;;;;;AACA;;eAEgBA,KAAD,IAAgB;EAC3B,IAAI,CAACA,KAAL,EAAY;IACR;EACH;;EAED,IAAI,yBAAYA,KAAZ,CAAJ,EAAwB;IACpB;EACH;;EAED,MAAM,IAAIC,wBAAJ,CAAoB,+BAApB,CAAN;AACH,C"}
@@ -0,0 +1,2 @@
1
+ declare const _default: (value: any) => void;
2
+ export default _default;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+
10
+ var _validationError = _interopRequireDefault(require("../validationError"));
11
+
12
+ var _default = value => {
13
+ if (!value) {
14
+ return;
15
+ }
16
+
17
+ try {
18
+ JSON.parse(value);
19
+ } catch (e) {
20
+ throw new _validationError.default("Value needs to be a valid JSON.");
21
+ }
22
+ };
23
+
24
+ exports.default = _default;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["value","JSON","parse","e","ValidationError"],"sources":["json.ts"],"sourcesContent":["import ValidationError from \"~/validationError\";\n\nexport default (value: any) => {\n if (!value) {\n return;\n }\n\n try {\n JSON.parse(value);\n } catch (e) {\n throw new ValidationError(\"Value needs to be a valid JSON.\");\n }\n};\n"],"mappings":";;;;;;;;;AAAA;;eAEgBA,KAAD,IAAgB;EAC3B,IAAI,CAACA,KAAL,EAAY;IACR;EACH;;EAED,IAAI;IACAC,IAAI,CAACC,KAAL,CAAWF,KAAX;EACH,CAFD,CAEE,OAAOG,CAAP,EAAU;IACR,MAAM,IAAIC,wBAAJ,CAAoB,iCAApB,CAAN;EACH;AACJ,C"}
@@ -0,0 +1,2 @@
1
+ declare const _default: (value: any, params?: string[]) => void;
2
+ export default _default;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+
10
+ var _validationError = _interopRequireDefault(require("../validationError"));
11
+
12
+ var _default = (value, params) => {
13
+ if (!value || !params) {
14
+ return;
15
+ }
16
+
17
+ value = value + "";
18
+
19
+ if (parseFloat(value) < parseFloat(params[0])) {
20
+ return;
21
+ }
22
+
23
+ throw new _validationError.default("Value needs to be less than " + params[0] + ".");
24
+ };
25
+
26
+ exports.default = _default;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["value","params","parseFloat","ValidationError"],"sources":["lt.ts"],"sourcesContent":["import ValidationError from \"~/validationError\";\n\nexport default (value: any, params?: string[]) => {\n if (!value || !params) {\n return;\n }\n value = value + \"\";\n\n if (parseFloat(value) < parseFloat(params[0])) {\n return;\n }\n\n throw new ValidationError(\"Value needs to be less than \" + params[0] + \".\");\n};\n"],"mappings":";;;;;;;;;AAAA;;eAEe,CAACA,KAAD,EAAaC,MAAb,KAAmC;EAC9C,IAAI,CAACD,KAAD,IAAU,CAACC,MAAf,EAAuB;IACnB;EACH;;EACDD,KAAK,GAAGA,KAAK,GAAG,EAAhB;;EAEA,IAAIE,UAAU,CAACF,KAAD,CAAV,GAAoBE,UAAU,CAACD,MAAM,CAAC,CAAD,CAAP,CAAlC,EAA+C;IAC3C;EACH;;EAED,MAAM,IAAIE,wBAAJ,CAAoB,iCAAiCF,MAAM,CAAC,CAAD,CAAvC,GAA6C,GAAjE,CAAN;AACH,C"}
@@ -0,0 +1,2 @@
1
+ declare const _default: (value: any, params?: string[]) => void;
2
+ export default _default;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+
10
+ var _validationError = _interopRequireDefault(require("../validationError"));
11
+
12
+ var _default = (value, params) => {
13
+ if (!value || !params) {
14
+ return;
15
+ }
16
+
17
+ value = value + "";
18
+
19
+ if (parseFloat(value) <= parseFloat(params[0])) {
20
+ return;
21
+ }
22
+
23
+ throw new _validationError.default("Value needs to be less than or equal to " + params[0] + ".");
24
+ };
25
+
26
+ exports.default = _default;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["value","params","parseFloat","ValidationError"],"sources":["lte.ts"],"sourcesContent":["import ValidationError from \"~/validationError\";\n\nexport default (value: any, params?: string[]) => {\n if (!value || !params) {\n return;\n }\n value = value + \"\";\n\n if (parseFloat(value) <= parseFloat(params[0])) {\n return;\n }\n\n throw new ValidationError(\"Value needs to be less than or equal to \" + params[0] + \".\");\n};\n"],"mappings":";;;;;;;;;AAAA;;eAEe,CAACA,KAAD,EAAaC,MAAb,KAAmC;EAC9C,IAAI,CAACD,KAAD,IAAU,CAACC,MAAf,EAAuB;IACnB;EACH;;EACDD,KAAK,GAAGA,KAAK,GAAG,EAAhB;;EAEA,IAAIE,UAAU,CAACF,KAAD,CAAV,IAAqBE,UAAU,CAACD,MAAM,CAAC,CAAD,CAAP,CAAnC,EAAgD;IAC5C;EACH;;EAED,MAAM,IAAIE,wBAAJ,CAAoB,6CAA6CF,MAAM,CAAC,CAAD,CAAnD,GAAyD,GAA7E,CAAN;AACH,C"}
@@ -0,0 +1,2 @@
1
+ declare const _default: (value: any, params?: string[]) => void;
2
+ export default _default;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+
10
+ var _isString2 = _interopRequireDefault(require("lodash/isString"));
11
+
12
+ var _keys2 = _interopRequireDefault(require("lodash/keys"));
13
+
14
+ var _isObject2 = _interopRequireDefault(require("lodash/isObject"));
15
+
16
+ var _has2 = _interopRequireDefault(require("lodash/has"));
17
+
18
+ var _validationError = _interopRequireDefault(require("../validationError"));
19
+
20
+ var _default = (value, params) => {
21
+ if (!value || !params) {
22
+ return;
23
+ }
24
+
25
+ let lengthOfValue = null;
26
+
27
+ if ((0, _has2.default)(value, "length")) {
28
+ lengthOfValue = value.length;
29
+ } else if ((0, _isObject2.default)(value)) {
30
+ lengthOfValue = (0, _keys2.default)(value).length;
31
+ }
32
+
33
+ if (lengthOfValue === null || lengthOfValue <= params[0]) {
34
+ return;
35
+ }
36
+
37
+ if ((0, _isString2.default)(value)) {
38
+ throw new _validationError.default("Value requires " + params[0] + " characters at most.");
39
+ }
40
+
41
+ throw new _validationError.default("Value requires " + params[0] + " items at most.");
42
+ };
43
+
44
+ exports.default = _default;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["value","params","lengthOfValue","length","ValidationError"],"sources":["maxLength.ts"],"sourcesContent":["import _ from \"lodash\";\nimport ValidationError from \"~/validationError\";\n\nexport default (value: any, params?: string[]) => {\n if (!value || !params) {\n return;\n }\n\n let lengthOfValue = null;\n if (_.has(value, \"length\")) {\n lengthOfValue = value.length;\n } else if (_.isObject(value)) {\n lengthOfValue = _.keys(value).length;\n }\n\n if (lengthOfValue === null || lengthOfValue <= params[0]) {\n return;\n }\n\n if (_.isString(value)) {\n throw new ValidationError(\"Value requires \" + params[0] + \" characters at most.\");\n }\n throw new ValidationError(\"Value requires \" + params[0] + \" items at most.\");\n};\n"],"mappings":";;;;;;;;;;;;;;;;;AACA;;eAEe,CAACA,KAAD,EAAaC,MAAb,KAAmC;EAC9C,IAAI,CAACD,KAAD,IAAU,CAACC,MAAf,EAAuB;IACnB;EACH;;EAED,IAAIC,aAAa,GAAG,IAApB;;EACA,IAAI,mBAAMF,KAAN,EAAa,QAAb,CAAJ,EAA4B;IACxBE,aAAa,GAAGF,KAAK,CAACG,MAAtB;EACH,CAFD,MAEO,IAAI,wBAAWH,KAAX,CAAJ,EAAuB;IAC1BE,aAAa,GAAG,oBAAOF,KAAP,EAAcG,MAA9B;EACH;;EAED,IAAID,aAAa,KAAK,IAAlB,IAA0BA,aAAa,IAAID,MAAM,CAAC,CAAD,CAArD,EAA0D;IACtD;EACH;;EAED,IAAI,wBAAWD,KAAX,CAAJ,EAAuB;IACnB,MAAM,IAAII,wBAAJ,CAAoB,oBAAoBH,MAAM,CAAC,CAAD,CAA1B,GAAgC,sBAApD,CAAN;EACH;;EACD,MAAM,IAAIG,wBAAJ,CAAoB,oBAAoBH,MAAM,CAAC,CAAD,CAA1B,GAAgC,iBAApD,CAAN;AACH,C"}
@@ -0,0 +1,2 @@
1
+ declare const _default: (value: any, params?: string[]) => void;
2
+ export default _default;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+
10
+ var _isString2 = _interopRequireDefault(require("lodash/isString"));
11
+
12
+ var _keys2 = _interopRequireDefault(require("lodash/keys"));
13
+
14
+ var _isObject2 = _interopRequireDefault(require("lodash/isObject"));
15
+
16
+ var _has2 = _interopRequireDefault(require("lodash/has"));
17
+
18
+ var _validationError = _interopRequireDefault(require("../validationError"));
19
+
20
+ var _default = (value, params) => {
21
+ if (!value || !params) {
22
+ return;
23
+ }
24
+
25
+ let lengthOfValue = null;
26
+
27
+ if ((0, _has2.default)(value, "length")) {
28
+ lengthOfValue = value.length;
29
+ } else if ((0, _isObject2.default)(value)) {
30
+ lengthOfValue = (0, _keys2.default)(value).length;
31
+ }
32
+
33
+ if (lengthOfValue === null || lengthOfValue >= params[0]) {
34
+ return;
35
+ }
36
+
37
+ if ((0, _isString2.default)(value)) {
38
+ throw new _validationError.default("Value requires at least " + params[0] + " characters.");
39
+ }
40
+
41
+ throw new _validationError.default("Value requires at least " + params[0] + " items.");
42
+ };
43
+
44
+ exports.default = _default;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["value","params","lengthOfValue","length","ValidationError"],"sources":["minLength.ts"],"sourcesContent":["import _ from \"lodash\";\nimport ValidationError from \"~/validationError\";\n\nexport default (value: any, params?: string[]) => {\n if (!value || !params) {\n return;\n }\n\n let lengthOfValue = null;\n if (_.has(value, \"length\")) {\n lengthOfValue = value.length;\n } else if (_.isObject(value)) {\n lengthOfValue = _.keys(value).length;\n }\n\n if (lengthOfValue === null || lengthOfValue >= params[0]) {\n return;\n }\n\n if (_.isString(value)) {\n throw new ValidationError(\"Value requires at least \" + params[0] + \" characters.\");\n }\n throw new ValidationError(\"Value requires at least \" + params[0] + \" items.\");\n};\n"],"mappings":";;;;;;;;;;;;;;;;;AACA;;eAEe,CAACA,KAAD,EAAaC,MAAb,KAAmC;EAC9C,IAAI,CAACD,KAAD,IAAU,CAACC,MAAf,EAAuB;IACnB;EACH;;EAED,IAAIC,aAAa,GAAG,IAApB;;EACA,IAAI,mBAAMF,KAAN,EAAa,QAAb,CAAJ,EAA4B;IACxBE,aAAa,GAAGF,KAAK,CAACG,MAAtB;EACH,CAFD,MAEO,IAAI,wBAAWH,KAAX,CAAJ,EAAuB;IAC1BE,aAAa,GAAG,oBAAOF,KAAP,EAAcG,MAA9B;EACH;;EAED,IAAID,aAAa,KAAK,IAAlB,IAA0BA,aAAa,IAAID,MAAM,CAAC,CAAD,CAArD,EAA0D;IACtD;EACH;;EAED,IAAI,wBAAWD,KAAX,CAAJ,EAAuB;IACnB,MAAM,IAAII,wBAAJ,CAAoB,6BAA6BH,MAAM,CAAC,CAAD,CAAnC,GAAyC,cAA7D,CAAN;EACH;;EACD,MAAM,IAAIG,wBAAJ,CAAoB,6BAA6BH,MAAM,CAAC,CAAD,CAAnC,GAAyC,SAA7D,CAAN;AACH,C"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @function number
3
+ * @description This validator checks of the given value is a number
4
+ * @param {any} value
5
+ * @return {boolean}
6
+ */
7
+ declare const _default: (value: any) => void;
8
+ export default _default;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+
10
+ var _isNumber2 = _interopRequireDefault(require("lodash/isNumber"));
11
+
12
+ var _isNaN2 = _interopRequireDefault(require("lodash/isNaN"));
13
+
14
+ var _validationError = _interopRequireDefault(require("../validationError"));
15
+
16
+ /**
17
+ * @function number
18
+ * @description This validator checks of the given value is a number
19
+ * @param {any} value
20
+ * @return {boolean}
21
+ */
22
+ var _default = value => {
23
+ if (!value && !(0, _isNaN2.default)(value)) {
24
+ return;
25
+ }
26
+
27
+ if ((0, _isNumber2.default)(value) && !(0, _isNaN2.default)(value)) {
28
+ return;
29
+ }
30
+
31
+ throw new _validationError.default("Value needs to be a number.");
32
+ };
33
+
34
+ exports.default = _default;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["value","ValidationError"],"sources":["number.ts"],"sourcesContent":["import _ from \"lodash\";\nimport ValidationError from \"~/validationError\";\n\n/**\n * @function number\n * @description This validator checks of the given value is a number\n * @param {any} value\n * @return {boolean}\n */\nexport default (value: any) => {\n if (!value && !_.isNaN(value)) {\n return;\n }\n\n if (_.isNumber(value) && !_.isNaN(value)) {\n return;\n }\n\n throw new ValidationError(\"Value needs to be a number.\");\n};\n"],"mappings":";;;;;;;;;;;;;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;eACgBA,KAAD,IAAgB;EAC3B,IAAI,CAACA,KAAD,IAAU,CAAC,qBAAQA,KAAR,CAAf,EAA+B;IAC3B;EACH;;EAED,IAAI,wBAAWA,KAAX,KAAqB,CAAC,qBAAQA,KAAR,CAA1B,EAA0C;IACtC;EACH;;EAED,MAAM,IAAIC,wBAAJ,CAAoB,6BAApB,CAAN;AACH,C"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @function number
3
+ * @description This validator checks if the given value is numeric
4
+ * @param {any} value
5
+ * @return {boolean}
6
+ */
7
+ declare const _default: (value: any) => void;
8
+ export default _default;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+
10
+ var _validationError = _interopRequireDefault(require("../validationError"));
11
+
12
+ var _isnumeric = _interopRequireDefault(require("isnumeric"));
13
+
14
+ /**
15
+ * Package isnumeric does not have types so we ignore it.
16
+ */
17
+ // @ts-ignore
18
+
19
+ /**
20
+ * @function number
21
+ * @description This validator checks if the given value is numeric
22
+ * @param {any} value
23
+ * @return {boolean}
24
+ */
25
+ var _default = value => {
26
+ // Eliminate edge cases
27
+ if (typeof value === "undefined" || value === 0 || value === "0") {
28
+ return;
29
+ }
30
+
31
+ if (!value && !isNaN(value)) {
32
+ return;
33
+ }
34
+
35
+ if ((0, _isnumeric.default)(value)) {
36
+ return;
37
+ }
38
+
39
+ throw new _validationError.default("Value needs to be numeric.");
40
+ };
41
+
42
+ exports.default = _default;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["value","isNaN","isNumeric","ValidationError"],"sources":["numeric.ts"],"sourcesContent":["import ValidationError from \"~/validationError\";\n/**\n * Package isnumeric does not have types so we ignore it.\n */\n// @ts-ignore\nimport isNumeric from \"isnumeric\";\n\n/**\n * @function number\n * @description This validator checks if the given value is numeric\n * @param {any} value\n * @return {boolean}\n */\nexport default (value: any) => {\n // Eliminate edge cases\n if (typeof value === \"undefined\" || value === 0 || value === \"0\") {\n return;\n }\n\n if (!value && !isNaN(value)) {\n return;\n }\n\n if (isNumeric(value)) {\n return;\n }\n\n throw new ValidationError(\"Value needs to be numeric.\");\n};\n"],"mappings":";;;;;;;;;AAAA;;AAKA;;AAJA;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;eACgBA,KAAD,IAAgB;EAC3B;EACA,IAAI,OAAOA,KAAP,KAAiB,WAAjB,IAAgCA,KAAK,KAAK,CAA1C,IAA+CA,KAAK,KAAK,GAA7D,EAAkE;IAC9D;EACH;;EAED,IAAI,CAACA,KAAD,IAAU,CAACC,KAAK,CAACD,KAAD,CAApB,EAA6B;IACzB;EACH;;EAED,IAAI,IAAAE,kBAAA,EAAUF,KAAV,CAAJ,EAAsB;IAClB;EACH;;EAED,MAAM,IAAIG,wBAAJ,CAAoB,4BAApB,CAAN;AACH,C"}
@@ -0,0 +1,2 @@
1
+ declare const _default: (value: any, params?: string[]) => void;
2
+ export default _default;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+
10
+ var _validationError = _interopRequireDefault(require("../validationError"));
11
+
12
+ var _default = (value, params) => {
13
+ if (!value) {
14
+ return;
15
+ }
16
+
17
+ value = value + "";
18
+ const length = params ? params[0] || 6 : 6;
19
+ const test = value.match(new RegExp(`^.{${length},}$`));
20
+
21
+ if (test === null) {
22
+ throw new _validationError.default(`Password must contain at least ${length} characters`);
23
+ }
24
+ };
25
+
26
+ exports.default = _default;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["value","params","length","test","match","RegExp","ValidationError"],"sources":["password.ts"],"sourcesContent":["import ValidationError from \"~/validationError\";\n\nexport default (value: any, params?: string[]) => {\n if (!value) {\n return;\n }\n value = value + \"\";\n\n const length = params ? params[0] || 6 : 6;\n const test = value.match(new RegExp(`^.{${length},}$`));\n if (test === null) {\n throw new ValidationError(`Password must contain at least ${length} characters`);\n }\n};\n"],"mappings":";;;;;;;;;AAAA;;eAEe,CAACA,KAAD,EAAaC,MAAb,KAAmC;EAC9C,IAAI,CAACD,KAAL,EAAY;IACR;EACH;;EACDA,KAAK,GAAGA,KAAK,GAAG,EAAhB;EAEA,MAAME,MAAM,GAAGD,MAAM,GAAGA,MAAM,CAAC,CAAD,CAAN,IAAa,CAAhB,GAAoB,CAAzC;EACA,MAAME,IAAI,GAAGH,KAAK,CAACI,KAAN,CAAY,IAAIC,MAAJ,CAAY,MAAKH,MAAO,KAAxB,CAAZ,CAAb;;EACA,IAAIC,IAAI,KAAK,IAAb,EAAmB;IACf,MAAM,IAAIG,wBAAJ,CAAqB,kCAAiCJ,MAAO,aAA7D,CAAN;EACH;AACJ,C"}
@@ -0,0 +1,2 @@
1
+ declare const _default: (value: any) => void;
2
+ export default _default;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+
10
+ var _validationError = _interopRequireDefault(require("../validationError"));
11
+
12
+ var _default = value => {
13
+ if (!value) {
14
+ return;
15
+ }
16
+
17
+ value = value + "";
18
+
19
+ if (value.match(/^[-+0-9()/\s]+$/)) {
20
+ return;
21
+ }
22
+
23
+ throw new _validationError.default("Value must be a valid phone number.");
24
+ };
25
+
26
+ exports.default = _default;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["value","match","ValidationError"],"sources":["phone.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(/^[-+0-9()/\\s]+$/)) {\n return;\n }\n throw new ValidationError(\"Value must be a valid phone number.\");\n};\n"],"mappings":";;;;;;;;;AAAA;;eAEgBA,KAAD,IAAgB;EAC3B,IAAI,CAACA,KAAL,EAAY;IACR;EACH;;EACDA,KAAK,GAAGA,KAAK,GAAG,EAAhB;;EAEA,IAAIA,KAAK,CAACC,KAAN,CAAY,iBAAZ,CAAJ,EAAoC;IAChC;EACH;;EACD,MAAM,IAAIC,wBAAJ,CAAoB,qCAApB,CAAN;AACH,C"}
@@ -0,0 +1,2 @@
1
+ declare const _default: (value: any) => void;
2
+ export default _default;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+
10
+ var _validationError = _interopRequireDefault(require("../validationError"));
11
+
12
+ const throwError = () => {
13
+ throw new _validationError.default("Value is required.");
14
+ };
15
+
16
+ var _default = value => {
17
+ if (value === "" || value === null || value === undefined) {
18
+ throwError();
19
+ }
20
+ };
21
+
22
+ exports.default = _default;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["throwError","ValidationError","value","undefined"],"sources":["required.ts"],"sourcesContent":["import ValidationError from \"~/validationError\";\n\nconst throwError = () => {\n throw new ValidationError(\"Value is required.\");\n};\n\nexport default (value: any) => {\n if (value === \"\" || value === null || value === undefined) {\n throwError();\n }\n};\n"],"mappings":";;;;;;;;;AAAA;;AAEA,MAAMA,UAAU,GAAG,MAAM;EACrB,MAAM,IAAIC,wBAAJ,CAAoB,oBAApB,CAAN;AACH,CAFD;;eAIgBC,KAAD,IAAgB;EAC3B,IAAIA,KAAK,KAAK,EAAV,IAAgBA,KAAK,KAAK,IAA1B,IAAkCA,KAAK,KAAKC,SAAhD,EAA2D;IACvDH,UAAU;EACb;AACJ,C"}
@@ -0,0 +1,2 @@
1
+ declare const _default: (value: any) => void;
2
+ export default _default;