@webiny/validation 5.15.0-beta.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.
Files changed (84) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +409 -0
  3. package/index.d.ts +4 -0
  4. package/index.js +94 -0
  5. package/index.js.map +1 -0
  6. package/package.json +43 -0
  7. package/types.d.ts +27 -0
  8. package/types.js +6 -0
  9. package/types.js.map +1 -0
  10. package/validation.d.ts +62 -0
  11. package/validation.js +195 -0
  12. package/validation.js.map +1 -0
  13. package/validationError.d.ts +10 -0
  14. package/validationError.js +30 -0
  15. package/validationError.js.map +1 -0
  16. package/validators/creditCard.d.ts +15 -0
  17. package/validators/creditCard.js +70 -0
  18. package/validators/creditCard.js.map +1 -0
  19. package/validators/dateGte.d.ts +5 -0
  20. package/validators/dateGte.js +38 -0
  21. package/validators/dateGte.js.map +1 -0
  22. package/validators/dateLte.d.ts +5 -0
  23. package/validators/dateLte.js +38 -0
  24. package/validators/dateLte.js.map +1 -0
  25. package/validators/email.d.ts +15 -0
  26. package/validators/email.js +42 -0
  27. package/validators/email.js.map +1 -0
  28. package/validators/eq.d.ts +16 -0
  29. package/validators/eq.js +42 -0
  30. package/validators/eq.js.map +1 -0
  31. package/validators/gt.d.ts +16 -0
  32. package/validators/gt.js +39 -0
  33. package/validators/gt.js.map +1 -0
  34. package/validators/gte.d.ts +16 -0
  35. package/validators/gte.js +39 -0
  36. package/validators/gte.js.map +1 -0
  37. package/validators/in.d.ts +2 -0
  38. package/validators/in.js +28 -0
  39. package/validators/in.js.map +1 -0
  40. package/validators/integer.d.ts +2 -0
  41. package/validators/integer.js +27 -0
  42. package/validators/integer.js.map +1 -0
  43. package/validators/json.d.ts +2 -0
  44. package/validators/json.js +25 -0
  45. package/validators/json.js.map +1 -0
  46. package/validators/lt.d.ts +2 -0
  47. package/validators/lt.js +27 -0
  48. package/validators/lt.js.map +1 -0
  49. package/validators/lte.d.ts +2 -0
  50. package/validators/lte.js +27 -0
  51. package/validators/lte.js.map +1 -0
  52. package/validators/maxLength.d.ts +2 -0
  53. package/validators/maxLength.js +45 -0
  54. package/validators/maxLength.js.map +1 -0
  55. package/validators/minLength.d.ts +2 -0
  56. package/validators/minLength.js +45 -0
  57. package/validators/minLength.js.map +1 -0
  58. package/validators/number.d.ts +8 -0
  59. package/validators/number.js +35 -0
  60. package/validators/number.js.map +1 -0
  61. package/validators/numeric.d.ts +8 -0
  62. package/validators/numeric.js +38 -0
  63. package/validators/numeric.js.map +1 -0
  64. package/validators/password.d.ts +2 -0
  65. package/validators/password.js +27 -0
  66. package/validators/password.js.map +1 -0
  67. package/validators/phone.d.ts +2 -0
  68. package/validators/phone.js +27 -0
  69. package/validators/phone.js.map +1 -0
  70. package/validators/required.d.ts +2 -0
  71. package/validators/required.js +23 -0
  72. package/validators/required.js.map +1 -0
  73. package/validators/time/index.d.ts +6 -0
  74. package/validators/time/index.js +80 -0
  75. package/validators/time/index.js.map +1 -0
  76. package/validators/timeGte.d.ts +5 -0
  77. package/validators/timeGte.js +39 -0
  78. package/validators/timeGte.js.map +1 -0
  79. package/validators/timeLte.d.ts +5 -0
  80. package/validators/timeLte.js +39 -0
  81. package/validators/timeLte.js.map +1 -0
  82. package/validators/url.d.ts +2 -0
  83. package/validators/url.js +60 -0
  84. package/validators/url.js.map +1 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/validators/creditCard.ts"],"names":["value","length","ValidationError","test","nCheck","nDigit","bEven","replace","n","cDigit","charAt","parseInt"],"mappings":";;;;;;;;;AAAA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;eACgBA,KAAD,IAAsB;AACjC,MAAI,CAACA,KAAL,EAAY;AACR;AACH;;AACDA,EAAAA,KAAK,GAAGA,KAAK,GAAG,EAAhB;;AAEA,MAAIA,KAAK,CAACC,MAAN,GAAe,EAAnB,EAAuB;AACnB,UAAM,IAAIC,wBAAJ,CAAoB,+BAApB,CAAN;AACH;;AAED,MAAI,aAAaC,IAAb,CAAkBH,KAAlB,CAAJ,EAA8B;AAC1B,UAAM,IAAIE,wBAAJ,CAAoB,6BAApB,CAAN;AACH;;AAED,MAAIE,MAAM,GAAG,CAAb;AACA,MAAIC,MAAM,GAAG,CAAb;AACA,MAAIC,KAAK,GAAG,KAAZ;AAEAN,EAAAA,KAAK,GAAGA,KAAK,CAACO,OAAN,CAAc,IAAd,EAAoB,EAApB,CAAR;AACAP,EAAAA,KAAK,GAAGA,KAAK,CAACO,OAAN,CAAc,KAAd,EAAqB,EAArB,CAAR;;AAEA,OAAK,IAAIC,CAAC,GAAGR,KAAK,CAACC,MAAN,GAAe,CAA5B,EAA+BO,CAAC,IAAI,CAApC,EAAuCA,CAAC,EAAxC,EAA4C;AACxC,UAAMC,MAAM,GAAGT,KAAK,CAACU,MAAN,CAAaF,CAAb,CAAf;AACAH,IAAAA,MAAM,GAAGM,QAAQ,CAACF,MAAD,CAAjB;;AAEA,QAAIH,KAAJ,EAAW;AACPD,MAAAA,MAAM,IAAI,CAAV;;AACA,UAAIA,MAAM,GAAG,CAAb,EAAgB;AACZA,QAAAA,MAAM,IAAI,CAAV;AACH;AACJ;;AAEDD,IAAAA,MAAM,IAAIC,MAAV;AACAC,IAAAA,KAAK,GAAG,CAACA,KAAT;AACH;;AAED,MAAIF,MAAM,GAAG,EAAT,KAAgB,CAApB,EAAuB;AACnB;AACH;;AAED,QAAM,IAAIF,wBAAJ,CAAoB,6BAApB,CAAN;AACH,C","sourcesContent":["import ValidationError from \"./../validationError\";\n\n/**\n * @name creditCard\n * @description Credit card validator. This validator will check if the given value is a credit card number.\n * @param {any} value This is the value that will be validated.\n * @throws {ValidationError}\n * @example\n * import { validation } from '@webiny/validation';\n * validation.validate('notACreditCard', 'creditCard').then(() => {\n * // Valid\n * }).catch(e => {\n * // Invalid\n * });\n */\nexport default (value: any): void => {\n if (!value) {\n return;\n }\n value = value + \"\";\n\n if (value.length < 12) {\n throw new ValidationError(\"Credit card number too short.\");\n }\n\n if (/[^0-9-\\s]+/.test(value)) {\n throw new ValidationError(\"Credit card number invalid.\");\n }\n\n let nCheck = 0;\n let nDigit = 0;\n let bEven = false;\n\n value = value.replace(/ /g, \"\");\n value = value.replace(/\\D/g, \"\");\n\n for (let n = value.length - 1; n >= 0; n--) {\n const cDigit = value.charAt(n);\n nDigit = parseInt(cDigit);\n\n if (bEven) {\n nDigit *= 2;\n if (nDigit > 9) {\n nDigit -= 9;\n }\n }\n\n nCheck += nDigit;\n bEven = !bEven;\n }\n\n if (nCheck % 10 === 0) {\n return;\n }\n\n throw new ValidationError(\"Credit card number invalid.\");\n};\n"],"file":"creditCard.js"}
@@ -0,0 +1,5 @@
1
+ declare const _default: (value: string, params: string[]) => void;
2
+ /**
3
+ * Validates that given value is a greater or equal date to a gteValue
4
+ */
5
+ export default _default;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
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
+ * Validates that given value is a greater or equal date to a gteValue
14
+ */
15
+ var _default = (value, params) => {
16
+ if (!value) {
17
+ return;
18
+ } // we need to join because validation params are being split by :
19
+
20
+
21
+ const gteValue = params.join(":");
22
+
23
+ if (!gteValue) {
24
+ return;
25
+ }
26
+
27
+ const date = new Date(value);
28
+ const gteDate = new Date(gteValue);
29
+
30
+ if (date >= gteDate) {
31
+ return;
32
+ }
33
+
34
+ throw new _validationError.default(`Value needs to be greater than or equal to "${gteDate.toISOString()}".`);
35
+ };
36
+
37
+ exports.default = _default;
38
+ //# sourceMappingURL=dateGte.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/validators/dateGte.ts"],"names":["value","params","gteValue","join","date","Date","gteDate","ValidationError","toISOString"],"mappings":";;;;;;;;;AAAA;;AAEA;AACA;AACA;eACe,CAACA,KAAD,EAAgBC,MAAhB,KAAqC;AAChD,MAAI,CAACD,KAAL,EAAY;AACR;AACH,GAH+C,CAIhD;;;AACA,QAAME,QAAQ,GAAGD,MAAM,CAACE,IAAP,CAAY,GAAZ,CAAjB;;AACA,MAAI,CAACD,QAAL,EAAe;AACX;AACH;;AAED,QAAME,IAAI,GAAG,IAAIC,IAAJ,CAASL,KAAT,CAAb;AACA,QAAMM,OAAO,GAAG,IAAID,IAAJ,CAASH,QAAT,CAAhB;;AAEA,MAAIE,IAAI,IAAIE,OAAZ,EAAqB;AACjB;AACH;;AACD,QAAM,IAAIC,wBAAJ,CACD,+CAA8CD,OAAO,CAACE,WAAR,EAAsB,IADnE,CAAN;AAGH,C","sourcesContent":["import ValidationError from \"./../validationError\";\n\n/**\n * Validates that given value is a greater or equal date to a gteValue\n */\nexport default (value: string, params: string[]) => {\n if (!value) {\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 date = new Date(value);\n const gteDate = new Date(gteValue);\n\n if (date >= gteDate) {\n return;\n }\n throw new ValidationError(\n `Value needs to be greater than or equal to \"${gteDate.toISOString()}\".`\n );\n};\n"],"file":"dateGte.js"}
@@ -0,0 +1,5 @@
1
+ declare const _default: (value: string, params: string[]) => void;
2
+ /**
3
+ * Validates that given value is a lesser than or equal date to a lteValue
4
+ */
5
+ export default _default;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
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
+ * Validates that given value is a lesser than or equal date to a lteValue
14
+ */
15
+ var _default = (value, params) => {
16
+ if (!value) {
17
+ return;
18
+ } // we need to join because validation params are being split by :
19
+
20
+
21
+ const lteValue = params.join(":");
22
+
23
+ if (!lteValue) {
24
+ return;
25
+ }
26
+
27
+ const date = new Date(value);
28
+ const lteDate = new Date(lteValue);
29
+
30
+ if (date <= lteDate) {
31
+ return;
32
+ }
33
+
34
+ throw new _validationError.default(`Value needs to be lesser than or equal to "${lteDate.toISOString()}".`);
35
+ };
36
+
37
+ exports.default = _default;
38
+ //# sourceMappingURL=dateLte.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/validators/dateLte.ts"],"names":["value","params","lteValue","join","date","Date","lteDate","ValidationError","toISOString"],"mappings":";;;;;;;;;AAAA;;AAEA;AACA;AACA;eACe,CAACA,KAAD,EAAgBC,MAAhB,KAAqC;AAChD,MAAI,CAACD,KAAL,EAAY;AACR;AACH,GAH+C,CAIhD;;;AACA,QAAME,QAAQ,GAAGD,MAAM,CAACE,IAAP,CAAY,GAAZ,CAAjB;;AACA,MAAI,CAACD,QAAL,EAAe;AACX;AACH;;AAED,QAAME,IAAI,GAAG,IAAIC,IAAJ,CAASL,KAAT,CAAb;AACA,QAAMM,OAAO,GAAG,IAAID,IAAJ,CAASH,QAAT,CAAhB;;AAEA,MAAIE,IAAI,IAAIE,OAAZ,EAAqB;AACjB;AACH;;AACD,QAAM,IAAIC,wBAAJ,CACD,8CAA6CD,OAAO,CAACE,WAAR,EAAsB,IADlE,CAAN;AAGH,C","sourcesContent":["import ValidationError from \"./../validationError\";\n\n/**\n * Validates that given value is a lesser than or equal date to a lteValue\n */\nexport default (value: string, params: string[]) => {\n if (!value) {\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 date = new Date(value);\n const lteDate = new Date(lteValue);\n\n if (date <= lteDate) {\n return;\n }\n throw new ValidationError(\n `Value needs to be lesser than or equal to \"${lteDate.toISOString()}\".`\n );\n};\n"],"file":"dateLte.js"}
@@ -0,0 +1,15 @@
1
+ declare const _default: (value: any) => void;
2
+ /**
3
+ * @name email
4
+ * @description Email validator. This validator checks if the given value is a valid email address.
5
+ * @param {any} value This is the value that will be validated.
6
+ * @throws {ValidationError}
7
+ * @example
8
+ * import { validation } from '@webiny/validation';
9
+ * validation.validate('email@gmail.com', 'email').then(() => {
10
+ * // Valid
11
+ * }).catch(e => {
12
+ * // Invalid
13
+ * });
14
+ */
15
+ export default _default;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
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 email
14
+ * @description Email validator. This validator checks if the given value is a valid email address.
15
+ * @param {any} value This is the value that will be validated.
16
+ * @throws {ValidationError}
17
+ * @example
18
+ * import { validation } from '@webiny/validation';
19
+ * validation.validate('email@gmail.com', 'email').then(() => {
20
+ * // Valid
21
+ * }).catch(e => {
22
+ * // Invalid
23
+ * });
24
+ */
25
+ var _default = value => {
26
+ if (!value) {
27
+ return;
28
+ }
29
+
30
+ value = value + ""; // eslint-disable-next-line
31
+
32
+ const re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
33
+
34
+ if (!value || value.length && re.test(value)) {
35
+ return;
36
+ }
37
+
38
+ throw new _validationError.default("Value must be a valid e-mail address.");
39
+ };
40
+
41
+ exports.default = _default;
42
+ //# sourceMappingURL=email.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/validators/email.ts"],"names":["value","re","length","test","ValidationError"],"mappings":";;;;;;;;;AAAA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;eACgBA,KAAD,IAAsB;AACjC,MAAI,CAACA,KAAL,EAAY;AACR;AACH;;AACDA,EAAAA,KAAK,GAAGA,KAAK,GAAG,EAAhB,CAJiC,CAMjC;;AACA,QAAMC,EAAE,GACJ,sJADJ;;AAEA,MAAI,CAACD,KAAD,IAAWA,KAAK,CAACE,MAAN,IAAgBD,EAAE,CAACE,IAAH,CAAQH,KAAR,CAA/B,EAAgD;AAC5C;AACH;;AACD,QAAM,IAAII,wBAAJ,CAAoB,uCAApB,CAAN;AACH,C","sourcesContent":["import ValidationError from \"./../validationError\";\n\n/**\n * @name email\n * @description Email validator. This validator checks if the given value is a valid email address.\n * @param {any} value This is the value that will be validated.\n * @throws {ValidationError}\n * @example\n * import { validation } from '@webiny/validation';\n * validation.validate('email@gmail.com', 'email').then(() => {\n * // Valid\n * }).catch(e => {\n * // Invalid\n * });\n */\nexport default (value: any): void => {\n if (!value) {\n return;\n }\n value = value + \"\";\n\n // eslint-disable-next-line\n const re =\n /^(([^<>()[\\]\\\\.,;:\\s@\"]+(\\.[^<>()[\\]\\\\.,;:\\s@\"]+)*)|(\".+\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$/;\n if (!value || (value.length && re.test(value))) {\n return;\n }\n throw new ValidationError(\"Value must be a valid e-mail address.\");\n};\n"],"file":"email.js"}
@@ -0,0 +1,16 @@
1
+ declare const _default: (value: any, params: Array<string>) => void;
2
+ /**
3
+ * @name eq
4
+ * @description Equality validator. This validator checks if the given values are equal.
5
+ * @param {any} value This is the value that will be validated.
6
+ * @param {Array<string>} params This is the value to validate against. It is passed as a validator parameter: `eq:valueToCompareWith`
7
+ * @throws {ValidationError}
8
+ * @example
9
+ * import { validation } from '@webiny/validation';
10
+ * validation.validate('email@gmail.com', 'eq:another@gmail.com').then(() => {
11
+ * // Valid
12
+ * }).catch(e => {
13
+ * // Invalid
14
+ * });
15
+ */
16
+ export default _default;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
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 eq
14
+ * @description Equality validator. This validator checks if the given values are equal.
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: `eq:valueToCompareWith`
17
+ * @throws {ValidationError}
18
+ * @example
19
+ * import { validation } from '@webiny/validation';
20
+ * validation.validate('email@gmail.com', 'eq:another@gmail.com').then(() => {
21
+ * // Valid
22
+ * }).catch(e => {
23
+ * // Invalid
24
+ * });
25
+ */
26
+ var _default = (value, params) => {
27
+ if (!value) {
28
+ return;
29
+ }
30
+
31
+ value = value + ""; // Intentionally put '==' instead of '===' because passed parameter for this validator is always sent inside a string (eg. "eq:test").
32
+ // eslint-disable-next-line
33
+
34
+ if (value == params[0]) {
35
+ return;
36
+ }
37
+
38
+ throw new _validationError.default("Value must be equal to " + params[0] + ".");
39
+ };
40
+
41
+ exports.default = _default;
42
+ //# sourceMappingURL=eq.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/validators/eq.ts"],"names":["value","params","ValidationError"],"mappings":";;;;;;;;;AAAA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;eACe,CAACA,KAAD,EAAaC,MAAb,KAAuC;AAClD,MAAI,CAACD,KAAL,EAAY;AACR;AACH;;AACDA,EAAAA,KAAK,GAAGA,KAAK,GAAG,EAAhB,CAJkD,CAMlD;AACA;;AACA,MAAIA,KAAK,IAAIC,MAAM,CAAC,CAAD,CAAnB,EAAwB;AACpB;AACH;;AACD,QAAM,IAAIC,wBAAJ,CAAoB,4BAA4BD,MAAM,CAAC,CAAD,CAAlC,GAAwC,GAA5D,CAAN;AACH,C","sourcesContent":["import ValidationError from \"./../validationError\";\n\n/**\n * @name eq\n * @description Equality validator. This validator checks if the given values are equal.\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: `eq:valueToCompareWith`\n * @throws {ValidationError}\n * @example\n * import { validation } from '@webiny/validation';\n * validation.validate('email@gmail.com', 'eq:another@gmail.com').then(() => {\n * // Valid\n * }).catch(e => {\n * // Invalid\n * });\n */\nexport default (value: any, params: Array<string>) => {\n if (!value) {\n return;\n }\n value = value + \"\";\n\n // Intentionally put '==' instead of '===' because passed parameter for this validator is always sent inside a string (eg. \"eq:test\").\n // eslint-disable-next-line\n if (value == params[0]) {\n return;\n }\n throw new ValidationError(\"Value must be equal to \" + params[0] + \".\");\n};\n"],"file":"eq.js"}
@@ -0,0 +1,16 @@
1
+ declare const _default: (value: any, params: Array<string>) => void;
2
+ /**
3
+ * @name gt
4
+ * @description "Greater than" validator. This validator checks if the given values is greater than the `min` value.
5
+ * @param {any} value This is the value that will be validated.
6
+ * @param {Array<string>} params This is the value to validate against. It is passed as a validator parameter: `gt:valueToCompareAgainst`
7
+ * @throws {ValidationError}
8
+ * @example
9
+ * import { validation } from '@webiny/validation';
10
+ * validation.validate(10, 'gt:100').then(() => {
11
+ * // Valid
12
+ * }).catch(e => {
13
+ * // Invalid
14
+ * });
15
+ */
16
+ export default _default;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
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) {
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;
39
+ //# sourceMappingURL=gt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/validators/gt.ts"],"names":["value","params","parseFloat","ValidationError"],"mappings":";;;;;;;;;AAAA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;eACe,CAACA,KAAD,EAAaC,MAAb,KAAuC;AAClD,MAAI,CAACD,KAAL,EAAY;AACR;AACH;;AAED,MAAIE,UAAU,CAACF,KAAD,CAAV,GAAoBE,UAAU,CAACD,MAAM,CAAC,CAAD,CAAP,CAAlC,EAA+C;AAC3C;AACH;;AACD,QAAM,IAAIE,wBAAJ,CAAoB,oCAAoCF,MAAM,CAAC,CAAD,CAA1C,GAAgD,GAApE,CAAN;AACH,C","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: Array<string>) => {\n if (!value) {\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"],"file":"gt.js"}
@@ -0,0 +1,16 @@
1
+ declare const _default: (value: any, params: Array<string>) => void;
2
+ /**
3
+ * @name gte
4
+ * @description "Greater than or equals" validator. This validator checks if the given values is greater than or equal to the `min` value.
5
+ * @param {any} value This is the value that will be validated.
6
+ * @param {any} min This is the value to validate against. It is passed as a validator parameter: `gte:valueToCompareAgainst`
7
+ * @throws {ValidationError}
8
+ * @example
9
+ * import { validation } from '@webiny/validation';
10
+ * validation.validate(10, 'gte:100').then(() => {
11
+ * // Valid
12
+ * }).catch(e => {
13
+ * // Invalid
14
+ * });
15
+ */
16
+ export default _default;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
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) {
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;
39
+ //# sourceMappingURL=gte.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/validators/gte.ts"],"names":["value","params","parseFloat","ValidationError"],"mappings":";;;;;;;;;AAAA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;eACe,CAACA,KAAD,EAAaC,MAAb,KAAuC;AAClD,MAAI,CAACD,KAAL,EAAY;AACR;AACH;;AAED,MAAIE,UAAU,CAACF,KAAD,CAAV,IAAqBE,UAAU,CAACD,MAAM,CAAC,CAAD,CAAP,CAAnC,EAAgD;AAC5C;AACH;;AACD,QAAM,IAAIE,wBAAJ,CAAoB,gDAAgDF,MAAM,CAAC,CAAD,CAAtD,GAA4D,GAAhF,CAAN;AACH,C","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: Array<string>) => {\n if (!value) {\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"],"file":"gte.js"}
@@ -0,0 +1,2 @@
1
+ declare const _default: (value: any, params: string[]) => void;
2
+ export default _default;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
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) {
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;
28
+ //# sourceMappingURL=in.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/validators/in.ts"],"names":["value","params","includes","ValidationError","join"],"mappings":";;;;;;;;;AAAA;;AAEA;eACe,CAACA,KAAD,EAAaC,MAAb,KAAkC;AAC7C,MAAI,CAACD,KAAL,EAAY;AACR;AACH;;AACDA,EAAAA,KAAK,GAAGA,KAAK,GAAG,EAAhB;;AAEA,MAAIC,MAAM,CAACC,QAAP,CAAgBF,KAAhB,CAAJ,EAA4B;AACxB;AACH;;AAED,QAAM,IAAIG,wBAAJ,CAAoB,yCAAyCF,MAAM,CAACG,IAAP,CAAY,IAAZ,CAAzC,GAA6D,GAAjF,CAAN;AACH,C","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) {\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"],"file":"in.js"}
@@ -0,0 +1,2 @@
1
+ declare const _default: (value: any) => void;
2
+ export default _default;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
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;
27
+ //# sourceMappingURL=integer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/validators/integer.ts"],"names":["value","ValidationError"],"mappings":";;;;;;;;;;;AACA;;eAEgBA,KAAD,IAAgB;AAC3B,MAAI,CAACA,KAAL,EAAY;AACR;AACH;;AAED,MAAI,yBAAYA,KAAZ,CAAJ,EAAwB;AACpB;AACH;;AAED,QAAM,IAAIC,wBAAJ,CAAoB,+BAApB,CAAN;AACH,C","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"],"file":"integer.js"}
@@ -0,0 +1,2 @@
1
+ declare const _default: (value: any) => void;
2
+ export default _default;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
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;
25
+ //# sourceMappingURL=json.js.map