@webiny/validation 0.0.0-unstable.ecd8734205 → 0.0.0-unstable.f9f12f52a0

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 (59) hide show
  1. package/index.js +4 -30
  2. package/index.js.map +1 -1
  3. package/package.json +9 -18
  4. package/types.d.ts +6 -3
  5. package/types.js +3 -1
  6. package/types.js.map +1 -1
  7. package/validation.d.ts +1 -1
  8. package/validation.js +18 -55
  9. package/validation.js.map +1 -1
  10. package/validationError.js +2 -11
  11. package/validationError.js.map +1 -1
  12. package/validators/creditCard.js +2 -14
  13. package/validators/creditCard.js.map +1 -1
  14. package/validators/dateGte.js +4 -11
  15. package/validators/dateGte.js.map +1 -1
  16. package/validators/dateLte.js +4 -11
  17. package/validators/dateLte.js.map +1 -1
  18. package/validators/email.js +4 -8
  19. package/validators/email.js.map +1 -1
  20. package/validators/eq.js +4 -7
  21. package/validators/eq.js.map +1 -1
  22. package/validators/gt.js +4 -7
  23. package/validators/gt.js.map +1 -1
  24. package/validators/gte.js +4 -7
  25. package/validators/gte.js.map +1 -1
  26. package/validators/in.js +2 -7
  27. package/validators/in.js.map +1 -1
  28. package/validators/integer.js +4 -9
  29. package/validators/integer.js.map +1 -1
  30. package/validators/json.js +2 -5
  31. package/validators/json.js.map +1 -1
  32. package/validators/lt.js +3 -8
  33. package/validators/lt.js.map +1 -1
  34. package/validators/lte.js +3 -8
  35. package/validators/lte.js.map +1 -1
  36. package/validators/maxLength.js +10 -21
  37. package/validators/maxLength.js.map +1 -1
  38. package/validators/minLength.js +10 -21
  39. package/validators/minLength.js.map +1 -1
  40. package/validators/number.js +6 -12
  41. package/validators/number.js.map +1 -1
  42. package/validators/numeric.js +3 -10
  43. package/validators/numeric.js.map +1 -1
  44. package/validators/password.js +2 -6
  45. package/validators/password.js.map +1 -1
  46. package/validators/phone.js +2 -7
  47. package/validators/phone.js.map +1 -1
  48. package/validators/required.js +2 -5
  49. package/validators/required.js.map +1 -1
  50. package/validators/slug.js +4 -9
  51. package/validators/slug.js.map +1 -1
  52. package/validators/time/index.js +2 -13
  53. package/validators/time/index.js.map +1 -1
  54. package/validators/timeGte.js +4 -12
  55. package/validators/timeGte.js.map +1 -1
  56. package/validators/timeLte.js +4 -12
  57. package/validators/timeLte.js.map +1 -1
  58. package/validators/url.js +10 -16
  59. package/validators/url.js.map +1 -1
package/index.js CHANGED
@@ -1,7 +1,6 @@
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
  });
@@ -18,59 +17,32 @@ Object.defineProperty(exports, "ValidationError", {
18
17
  }
19
18
  });
20
19
  exports.validation = void 0;
21
-
22
20
  var _validation = _interopRequireDefault(require("./validation"));
23
-
24
21
  var _validationError = _interopRequireDefault(require("./validationError"));
25
-
26
22
  var _creditCard = _interopRequireDefault(require("./validators/creditCard"));
27
-
28
23
  var _email = _interopRequireDefault(require("./validators/email"));
29
-
30
24
  var _eq = _interopRequireDefault(require("./validators/eq"));
31
-
32
25
  var _gt = _interopRequireDefault(require("./validators/gt"));
33
-
34
26
  var _gte = _interopRequireDefault(require("./validators/gte"));
35
-
36
27
  var _in = _interopRequireDefault(require("./validators/in"));
37
-
38
28
  var _integer = _interopRequireDefault(require("./validators/integer"));
39
-
40
29
  var _json = _interopRequireDefault(require("./validators/json"));
41
-
42
30
  var _lt = _interopRequireDefault(require("./validators/lt"));
43
-
44
31
  var _lte = _interopRequireDefault(require("./validators/lte"));
45
-
46
32
  var _maxLength = _interopRequireDefault(require("./validators/maxLength"));
47
-
48
33
  var _minLength = _interopRequireDefault(require("./validators/minLength"));
49
-
50
34
  var _number = _interopRequireDefault(require("./validators/number"));
51
-
52
35
  var _numeric = _interopRequireDefault(require("./validators/numeric"));
53
-
54
36
  var _password = _interopRequireDefault(require("./validators/password"));
55
-
56
37
  var _phone = _interopRequireDefault(require("./validators/phone"));
57
-
58
38
  var _required = _interopRequireDefault(require("./validators/required"));
59
-
60
39
  var _url = _interopRequireDefault(require("./validators/url"));
61
-
62
40
  var _dateGte = _interopRequireDefault(require("./validators/dateGte"));
63
-
64
41
  var _dateLte = _interopRequireDefault(require("./validators/dateLte"));
65
-
66
42
  var _timeGte = _interopRequireDefault(require("./validators/timeGte"));
67
-
68
43
  var _timeLte = _interopRequireDefault(require("./validators/timeLte"));
69
-
70
44
  var _slug = _interopRequireDefault(require("./validators/slug"));
71
-
72
- const validation = new _validation.default();
73
- exports.validation = validation;
45
+ const validation = exports.validation = new _validation.default();
74
46
  validation.setValidator("creditCard", _creditCard.default);
75
47
  validation.setValidator("email", _email.default);
76
48
  validation.setValidator("eq", _eq.default);
@@ -93,4 +65,6 @@ validation.setValidator("dateGte", _dateGte.default);
93
65
  validation.setValidator("dateLte", _dateLte.default);
94
66
  validation.setValidator("timeGte", _timeGte.default);
95
67
  validation.setValidator("timeLte", _timeLte.default);
96
- validation.setValidator("slug", _slug.default);
68
+ validation.setValidator("slug", _slug.default);
69
+
70
+ //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["validation","Validation","setValidator","creditCard","email","eq","gt","gte","isIn","integer","json","lt","lte","maxLength","minLength","number","numeric","password","phone","required","url","dateGte","dateLte","timeGte","timeLte","slug"],"sources":["index.ts"],"sourcesContent":["import Validation from \"./validation\";\nimport ValidationError from \"./validationError\";\nimport creditCard from \"./validators/creditCard\";\nimport email from \"./validators/email\";\nimport eq from \"./validators/eq\";\nimport gt from \"./validators/gt\";\nimport gte from \"./validators/gte\";\nimport isIn from \"./validators/in\";\nimport integer from \"./validators/integer\";\nimport json from \"./validators/json\";\nimport lt from \"./validators/lt\";\nimport lte from \"./validators/lte\";\nimport maxLength from \"./validators/maxLength\";\nimport minLength from \"./validators/minLength\";\nimport number from \"./validators/number\";\nimport numeric from \"./validators/numeric\";\nimport password from \"./validators/password\";\nimport phone from \"./validators/phone\";\nimport required from \"./validators/required\";\nimport url from \"./validators/url\";\nimport dateGte from \"./validators/dateGte\";\nimport dateLte from \"./validators/dateLte\";\nimport timeGte from \"./validators/timeGte\";\nimport timeLte from \"./validators/timeLte\";\nimport slug from \"./validators/slug\";\n\nconst validation = new Validation();\nvalidation.setValidator(\"creditCard\", creditCard);\nvalidation.setValidator(\"email\", email);\nvalidation.setValidator(\"eq\", eq);\nvalidation.setValidator(\"gt\", gt);\nvalidation.setValidator(\"gte\", gte);\nvalidation.setValidator(\"in\", isIn);\nvalidation.setValidator(\"integer\", integer);\nvalidation.setValidator(\"json\", json);\nvalidation.setValidator(\"lt\", lt);\nvalidation.setValidator(\"lte\", lte);\nvalidation.setValidator(\"maxLength\", maxLength);\nvalidation.setValidator(\"minLength\", minLength);\nvalidation.setValidator(\"number\", number);\nvalidation.setValidator(\"numeric\", numeric);\nvalidation.setValidator(\"password\", password);\nvalidation.setValidator(\"phone\", phone);\nvalidation.setValidator(\"required\", required);\nvalidation.setValidator(\"url\", url);\nvalidation.setValidator(\"dateGte\", dateGte);\nvalidation.setValidator(\"dateLte\", dateLte);\nvalidation.setValidator(\"timeGte\", timeGte);\nvalidation.setValidator(\"timeLte\", timeLte);\nvalidation.setValidator(\"slug\", slug);\n\nexport { validation, Validation, ValidationError };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA,MAAMA,UAAU,GAAG,IAAIC,mBAAJ,EAAnB;;AACAD,UAAU,CAACE,YAAX,CAAwB,YAAxB,EAAsCC,mBAAtC;AACAH,UAAU,CAACE,YAAX,CAAwB,OAAxB,EAAiCE,cAAjC;AACAJ,UAAU,CAACE,YAAX,CAAwB,IAAxB,EAA8BG,WAA9B;AACAL,UAAU,CAACE,YAAX,CAAwB,IAAxB,EAA8BI,WAA9B;AACAN,UAAU,CAACE,YAAX,CAAwB,KAAxB,EAA+BK,YAA/B;AACAP,UAAU,CAACE,YAAX,CAAwB,IAAxB,EAA8BM,WAA9B;AACAR,UAAU,CAACE,YAAX,CAAwB,SAAxB,EAAmCO,gBAAnC;AACAT,UAAU,CAACE,YAAX,CAAwB,MAAxB,EAAgCQ,aAAhC;AACAV,UAAU,CAACE,YAAX,CAAwB,IAAxB,EAA8BS,WAA9B;AACAX,UAAU,CAACE,YAAX,CAAwB,KAAxB,EAA+BU,YAA/B;AACAZ,UAAU,CAACE,YAAX,CAAwB,WAAxB,EAAqCW,kBAArC;AACAb,UAAU,CAACE,YAAX,CAAwB,WAAxB,EAAqCY,kBAArC;AACAd,UAAU,CAACE,YAAX,CAAwB,QAAxB,EAAkCa,eAAlC;AACAf,UAAU,CAACE,YAAX,CAAwB,SAAxB,EAAmCc,gBAAnC;AACAhB,UAAU,CAACE,YAAX,CAAwB,UAAxB,EAAoCe,iBAApC;AACAjB,UAAU,CAACE,YAAX,CAAwB,OAAxB,EAAiCgB,cAAjC;AACAlB,UAAU,CAACE,YAAX,CAAwB,UAAxB,EAAoCiB,iBAApC;AACAnB,UAAU,CAACE,YAAX,CAAwB,KAAxB,EAA+BkB,YAA/B;AACApB,UAAU,CAACE,YAAX,CAAwB,SAAxB,EAAmCmB,gBAAnC;AACArB,UAAU,CAACE,YAAX,CAAwB,SAAxB,EAAmCoB,gBAAnC;AACAtB,UAAU,CAACE,YAAX,CAAwB,SAAxB,EAAmCqB,gBAAnC;AACAvB,UAAU,CAACE,YAAX,CAAwB,SAAxB,EAAmCsB,gBAAnC;AACAxB,UAAU,CAACE,YAAX,CAAwB,MAAxB,EAAgCuB,aAAhC"}
1
+ {"version":3,"names":["_validation","_interopRequireDefault","require","_validationError","_creditCard","_email","_eq","_gt","_gte","_in","_integer","_json","_lt","_lte","_maxLength","_minLength","_number","_numeric","_password","_phone","_required","_url","_dateGte","_dateLte","_timeGte","_timeLte","_slug","validation","exports","Validation","setValidator","creditCard","email","eq","gt","gte","isIn","integer","json","lt","lte","maxLength","minLength","number","numeric","password","phone","required","url","dateGte","dateLte","timeGte","timeLte","slug"],"sources":["index.ts"],"sourcesContent":["import Validation from \"./validation\";\nimport ValidationError from \"./validationError\";\nimport creditCard from \"./validators/creditCard\";\nimport email from \"./validators/email\";\nimport eq from \"./validators/eq\";\nimport gt from \"./validators/gt\";\nimport gte from \"./validators/gte\";\nimport isIn from \"./validators/in\";\nimport integer from \"./validators/integer\";\nimport json from \"./validators/json\";\nimport lt from \"./validators/lt\";\nimport lte from \"./validators/lte\";\nimport maxLength from \"./validators/maxLength\";\nimport minLength from \"./validators/minLength\";\nimport number from \"./validators/number\";\nimport numeric from \"./validators/numeric\";\nimport password from \"./validators/password\";\nimport phone from \"./validators/phone\";\nimport required from \"./validators/required\";\nimport url from \"./validators/url\";\nimport dateGte from \"./validators/dateGte\";\nimport dateLte from \"./validators/dateLte\";\nimport timeGte from \"./validators/timeGte\";\nimport timeLte from \"./validators/timeLte\";\nimport slug from \"./validators/slug\";\n\nconst validation = new Validation();\nvalidation.setValidator(\"creditCard\", creditCard);\nvalidation.setValidator(\"email\", email);\nvalidation.setValidator(\"eq\", eq);\nvalidation.setValidator(\"gt\", gt);\nvalidation.setValidator(\"gte\", gte);\nvalidation.setValidator(\"in\", isIn);\nvalidation.setValidator(\"integer\", integer);\nvalidation.setValidator(\"json\", json);\nvalidation.setValidator(\"lt\", lt);\nvalidation.setValidator(\"lte\", lte);\nvalidation.setValidator(\"maxLength\", maxLength);\nvalidation.setValidator(\"minLength\", minLength);\nvalidation.setValidator(\"number\", number);\nvalidation.setValidator(\"numeric\", numeric);\nvalidation.setValidator(\"password\", password);\nvalidation.setValidator(\"phone\", phone);\nvalidation.setValidator(\"required\", required);\nvalidation.setValidator(\"url\", url);\nvalidation.setValidator(\"dateGte\", dateGte);\nvalidation.setValidator(\"dateLte\", dateLte);\nvalidation.setValidator(\"timeGte\", timeGte);\nvalidation.setValidator(\"timeLte\", timeLte);\nvalidation.setValidator(\"slug\", slug);\n\nexport { validation, Validation, ValidationError };\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,IAAAA,WAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,gBAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,WAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,MAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,GAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,GAAA,GAAAN,sBAAA,CAAAC,OAAA;AACA,IAAAM,IAAA,GAAAP,sBAAA,CAAAC,OAAA;AACA,IAAAO,GAAA,GAAAR,sBAAA,CAAAC,OAAA;AACA,IAAAQ,QAAA,GAAAT,sBAAA,CAAAC,OAAA;AACA,IAAAS,KAAA,GAAAV,sBAAA,CAAAC,OAAA;AACA,IAAAU,GAAA,GAAAX,sBAAA,CAAAC,OAAA;AACA,IAAAW,IAAA,GAAAZ,sBAAA,CAAAC,OAAA;AACA,IAAAY,UAAA,GAAAb,sBAAA,CAAAC,OAAA;AACA,IAAAa,UAAA,GAAAd,sBAAA,CAAAC,OAAA;AACA,IAAAc,OAAA,GAAAf,sBAAA,CAAAC,OAAA;AACA,IAAAe,QAAA,GAAAhB,sBAAA,CAAAC,OAAA;AACA,IAAAgB,SAAA,GAAAjB,sBAAA,CAAAC,OAAA;AACA,IAAAiB,MAAA,GAAAlB,sBAAA,CAAAC,OAAA;AACA,IAAAkB,SAAA,GAAAnB,sBAAA,CAAAC,OAAA;AACA,IAAAmB,IAAA,GAAApB,sBAAA,CAAAC,OAAA;AACA,IAAAoB,QAAA,GAAArB,sBAAA,CAAAC,OAAA;AACA,IAAAqB,QAAA,GAAAtB,sBAAA,CAAAC,OAAA;AACA,IAAAsB,QAAA,GAAAvB,sBAAA,CAAAC,OAAA;AACA,IAAAuB,QAAA,GAAAxB,sBAAA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AAEmB,gBAAO,CAAC;AAC3CtB,UAAU,CAACG,YAAY,CAAC,SAAS,EAAEoB,gBAAO,CAAC;AAC3CvB,UAAU,CAACG,YAAY,CAAC,SAAS,EAAEqB,gBAAO,CAAC;AAC3CxB,UAAU,CAACG,YAAY,CAAC,SAAS,EAAEsB,gBAAO,CAAC;AAC3CzB,UAAU,CAACG,YAAY,CAAC,MAAM,EAAEuB,aAAI,CAAC","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/validation",
3
- "version": "0.0.0-unstable.ecd8734205",
3
+ "version": "0.0.0-unstable.f9f12f52a0",
4
4
  "main": "index.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,32 +14,23 @@
14
14
  ],
15
15
  "license": "MIT",
16
16
  "dependencies": {
17
- "@babel/runtime": "7.20.13",
18
17
  "isnumeric": "0.3.3",
19
18
  "lodash": "4.17.21"
20
19
  },
21
20
  "devDependencies": {
22
- "@babel/cli": "^7.19.3",
23
- "@babel/core": "^7.19.3",
24
- "@babel/preset-env": "^7.19.4",
25
- "@babel/preset-typescript": "^7.18.6",
26
- "@types/lodash": "^4.14.190",
27
- "@webiny/cli": "^0.0.0-unstable.ecd8734205",
28
- "@webiny/project-utils": "^0.0.0-unstable.ecd8734205",
29
- "babel-plugin-lodash": "^3.3.4",
30
- "jest": "^28.1.0",
31
- "merge": "^1.2.1",
32
- "rimraf": "^3.0.2",
33
- "ttypescript": "^1.5.13",
34
- "typescript": "4.7.4"
21
+ "@types/lodash": "4.17.13",
22
+ "@webiny/project-utils": "0.0.0-unstable.f9f12f52a0",
23
+ "jest": "29.7.0",
24
+ "rimraf": "6.0.1",
25
+ "typescript": "5.3.3"
35
26
  },
36
27
  "publishConfig": {
37
28
  "access": "public",
38
29
  "directory": "dist"
39
30
  },
40
31
  "scripts": {
41
- "build": "yarn webiny run build",
42
- "watch": "yarn webiny run watch"
32
+ "build": "node ../cli/bin.js run build",
33
+ "watch": "node ../cli/bin.js run watch"
43
34
  },
44
- "gitHead": "ecd8734205e0e21ae04076c28ff9806dad07a730"
35
+ "gitHead": "f9f12f52a0e2f8e4a2987aa71b4104f70f5d68c8"
45
36
  }
package/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import ValidationError from "./validationError";
2
- declare type ValidatorResult = boolean | ValidationError | void | Promise<boolean | ValidationError | void>;
1
+ import type ValidationError from "./validationError";
2
+ type ValidatorResult = boolean | ValidationError | void | Promise<boolean | ValidationError | void>;
3
3
  /**
4
4
  * @typedef Validator
5
5
  * @name Validator
@@ -8,7 +8,10 @@ declare type ValidatorResult = boolean | ValidationError | void | Promise<boolea
8
8
  * @param {Array<string>} parameters (Optional) This represents an array validator parameters.
9
9
  * @throws {ValidationError}
10
10
  */
11
- export declare type Validator = (value: any, params?: string[]) => ValidatorResult;
11
+ export interface Validator {
12
+ (value: any, params?: string[]): ValidatorResult;
13
+ validatorName?: string;
14
+ }
12
15
  /**
13
16
  * @typedef ValidateOptions
14
17
  * @name ValidateOptions
package/types.js CHANGED
@@ -2,4 +2,6 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
- });
5
+ });
6
+
7
+ //# sourceMappingURL=types.js.map
package/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import ValidationError from \"~/validationError\";\n\ntype ValidatorResult = boolean | ValidationError | void | Promise<boolean | ValidationError | void>;\n/**\n * @typedef Validator\n * @name Validator\n * @description This type defines the validator function.\n * @param {any} value This is the value being validated.\n * @param {Array<string>} parameters (Optional) This represents an array validator parameters.\n * @throws {ValidationError}\n */\nexport type Validator = (value: any, params?: string[]) => ValidatorResult;\n\n/**\n * @typedef ValidateOptions\n * @name ValidateOptions\n * @description This is an object containing validation options.\n * @property {boolean} throw Should validation throw on failure? Default: true.\n */\nexport interface ValidateOptions {\n throw?: boolean;\n}\n\n/**\n * @private\n * @typedef ParsedValidators\n * @name ParsedValidators\n * @description An object containing validators with parameters: `{ [string]: Array<string> }`.\n */\nexport interface ParsedValidators {\n [key: string]: Array<string>;\n}\n"],"mappings":""}
1
+ {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type ValidationError from \"~/validationError\";\n\ntype ValidatorResult = boolean | ValidationError | void | Promise<boolean | ValidationError | void>;\n/**\n * @typedef Validator\n * @name Validator\n * @description This type defines the validator function.\n * @param {any} value This is the value being validated.\n * @param {Array<string>} parameters (Optional) This represents an array validator parameters.\n * @throws {ValidationError}\n */\nexport interface Validator {\n (value: any, params?: string[]): ValidatorResult;\n validatorName?: string;\n}\n\n/**\n * @typedef ValidateOptions\n * @name ValidateOptions\n * @description This is an object containing validation options.\n * @property {boolean} throw Should validation throw on failure? Default: true.\n */\nexport interface ValidateOptions {\n throw?: boolean;\n}\n\n/**\n * @private\n * @typedef ParsedValidators\n * @name ParsedValidators\n * @description An object containing validators with parameters: `{ [string]: Array<string> }`.\n */\nexport interface ParsedValidators {\n [key: string]: Array<string>;\n}\n"],"mappings":"","ignoreList":[]}
package/validation.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import ValidationError from "./validationError";
2
- import { Validator, ValidateOptions, ParsedValidators } from "./types";
2
+ import type { ParsedValidators, ValidateOptions, Validator } from "./types";
3
3
  /**
4
4
  * Main class of Validation library.
5
5
  * Exported as a singleton instance, it offers methods for sync/async data validation and overwriting or adding new validators.
package/validation.js CHANGED
@@ -1,31 +1,23 @@
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
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
- var _trim2 = _interopRequireDefault(require("lodash/trim"));
13
-
14
- var _isEmpty2 = _interopRequireDefault(require("lodash/isEmpty"));
15
-
16
- var _isString2 = _interopRequireDefault(require("lodash/isString"));
17
-
8
+ var _isString = _interopRequireDefault(require("lodash/isString"));
9
+ var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
10
+ var _trim = _interopRequireDefault(require("lodash/trim"));
18
11
  var _validationError = _interopRequireDefault(require("./validationError"));
19
-
20
12
  const entries = validators => {
21
13
  return Object.entries(validators);
22
14
  };
23
-
24
15
  const invalidRules = "Validators must be specified as a string (eg. required,minLength:10,email).";
25
16
  const createdValidators = {
26
17
  async: {},
27
18
  sync: {}
28
19
  };
20
+
29
21
  /**
30
22
  * Main class of Validation library.
31
23
  * Exported as a singleton instance, it offers methods for sync/async data validation and overwriting or adding new validators.
@@ -37,42 +29,40 @@ const createdValidators = {
37
29
  * // `validation` is a preconfigured instance of Validation class.
38
30
  * // From here you can either add new validators or use it as-is.
39
31
  */
40
-
41
32
  class Validation {
42
33
  /**
43
34
  * Contains a list of all set validators.
44
35
  * @private
45
36
  */
37
+
46
38
  constructor() {
47
- (0, _defineProperty2.default)(this, "__validators", void 0);
48
39
  this.__validators = {};
49
40
  }
41
+
50
42
  /**
51
43
  * Add new validator.
52
44
  * @param name Validator name.
53
45
  * @param callable Validator function which throws a ValidationError if validation fails.
54
46
  * @returns {Validation}
55
47
  */
56
-
57
-
58
48
  setValidator(name, callable) {
59
49
  this.__validators[name] = callable;
50
+ this.__validators[name].validatorName = name;
60
51
  return this;
61
52
  }
53
+
62
54
  /**
63
55
  * Get validator function by name.
64
56
  * @param name Validator name.
65
57
  * @returns {Validator} A validator function.
66
58
  */
67
-
68
-
69
59
  getValidator(name) {
70
60
  if (!this.__validators[name]) {
71
61
  throw new _validationError.default("Validator `" + name + "` does not exist!", name);
72
62
  }
73
-
74
63
  return this.__validators[name];
75
64
  }
65
+
76
66
  /**
77
67
  * Asynchronously validates value.
78
68
  * @param value Value to validate.
@@ -80,37 +70,29 @@ class Validation {
80
70
  * @param [options] Validation options.
81
71
  * @returns {Promise<boolean | ValidationError>}
82
72
  */
83
-
84
-
85
73
  async validate(value, validators, options = {}) {
86
- if ((0, _isString2.default)(validators) && (0, _isEmpty2.default)(validators)) {
74
+ if ((0, _isString.default)(validators) && (0, _isEmpty.default)(validators)) {
87
75
  return true;
88
76
  }
89
-
90
- if (!(0, _isString2.default)(validators)) {
77
+ if (!(0, _isString.default)(validators)) {
91
78
  throw new Error(invalidRules);
92
79
  }
93
-
94
80
  const parsedValidateProperty = this.__parseValidateProperty(validators);
95
-
96
81
  for (const [name, params] of entries(parsedValidateProperty)) {
97
82
  const validator = this.getValidator(name);
98
-
99
83
  try {
100
84
  await validator(value, params);
101
85
  } catch (e) {
102
86
  const validationError = new _validationError.default(e.message, name, value);
103
-
104
87
  if (options.throw === false) {
105
88
  return validationError;
106
89
  }
107
-
108
90
  throw validationError;
109
91
  }
110
92
  }
111
-
112
93
  return true;
113
94
  }
95
+
114
96
  /**
115
97
  * Synchronously validates value.
116
98
  * @param value Value to validate.
@@ -118,82 +100,63 @@ class Validation {
118
100
  * @param [options] Validation options.
119
101
  * @returns {Promise<boolean | ValidationError>}
120
102
  */
121
-
122
-
123
103
  validateSync(value, validators, options = {}) {
124
- if ((0, _isString2.default)(validators) && (0, _isEmpty2.default)(validators)) {
104
+ if ((0, _isString.default)(validators) && (0, _isEmpty.default)(validators)) {
125
105
  return true;
126
106
  }
127
-
128
- if (!(0, _isString2.default)(validators)) {
107
+ if (!(0, _isString.default)(validators)) {
129
108
  throw new Error(invalidRules);
130
109
  }
131
-
132
110
  const parsedValidateProperty = this.__parseValidateProperty(validators);
133
-
134
111
  for (const [name, params] of entries(parsedValidateProperty)) {
135
112
  const validator = this.getValidator(name);
136
-
137
113
  try {
138
114
  validator(value, params);
139
115
  } catch (e) {
140
116
  const validationError = new _validationError.default(e.message, name, value);
141
-
142
117
  if (options.throw === false) {
143
118
  return validationError;
144
119
  }
145
-
146
120
  throw validationError;
147
121
  }
148
122
  }
149
-
150
123
  return true;
151
124
  }
152
-
153
125
  create(validators) {
154
126
  if (createdValidators.async[validators]) {
155
127
  return createdValidators.async[validators];
156
128
  }
157
-
158
129
  createdValidators.async[validators] = value => this.validate(value, validators);
159
-
160
130
  return createdValidators.async[validators];
161
131
  }
162
-
163
132
  createSync(validators) {
164
133
  if (createdValidators.sync[validators]) {
165
134
  return createdValidators.sync[validators];
166
135
  }
167
-
168
136
  createdValidators.sync[validators] = value => this.validateSync(value, validators);
169
-
170
137
  return createdValidators.sync[validators];
171
138
  }
139
+
172
140
  /**
173
141
  * Parses a string of validators with parameters.
174
142
  * @param validators A list of comma-separated validators (eg. required,number,gt:20).
175
143
  * @returns {ParsedValidators}
176
144
  * @private
177
145
  */
178
-
179
-
180
146
  __parseValidateProperty(validators) {
181
147
  const validate = validators.split(",");
182
148
  const parsedValidators = {};
183
149
  validate.forEach(v => {
184
- const params = (0, _trim2.default)(v).split(":");
150
+ const params = (0, _trim.default)(v).split(":");
185
151
  const vName = params.shift();
186
-
187
152
  if (!vName) {
188
153
  return;
189
154
  }
190
-
191
155
  parsedValidators[vName] = params;
192
156
  });
193
157
  return parsedValidators;
194
158
  }
195
-
196
159
  }
160
+ var _default = exports.default = Validation;
197
161
 
198
- var _default = Validation;
199
- exports.default = _default;
162
+ //# sourceMappingURL=validation.js.map
package/validation.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["entries","validators","Object","invalidRules","createdValidators","async","sync","Validation","constructor","__validators","setValidator","name","callable","getValidator","ValidationError","validate","value","options","Error","parsedValidateProperty","__parseValidateProperty","params","validator","e","validationError","message","throw","validateSync","create","createSync","split","parsedValidators","forEach","v","vName","shift"],"sources":["validation.ts"],"sourcesContent":["import _ from \"lodash\";\nimport ValidationError from \"./validationError\";\nimport { Validator, ValidateOptions, ParsedValidators } from \"./types\";\n\nconst entries = (validators: ParsedValidators): Array<[string, Array<string>]> => {\n return Object.entries(validators);\n};\n\nconst invalidRules = \"Validators must be specified as a string (eg. required,minLength:10,email).\";\n\ninterface CreatedValidators {\n async: Record<string, Validator>;\n sync: Record<string, Validator>;\n}\nconst createdValidators: CreatedValidators = {\n async: {},\n sync: {}\n};\n\n/**\n * Main class of Validation library.\n * Exported as a singleton instance, it offers methods for sync/async data validation and overwriting or adding new validators.\n *\n * @class Validation\n * @example\n * import { validation } from '@webiny/validation';\n *\n * // `validation` is a preconfigured instance of Validation class.\n * // From here you can either add new validators or use it as-is.\n */\nclass Validation {\n /**\n * Contains a list of all set validators.\n * @private\n */\n __validators: {\n [key: string]: Validator;\n };\n\n constructor() {\n this.__validators = {};\n }\n\n /**\n * Add new validator.\n * @param name Validator name.\n * @param callable Validator function which throws a ValidationError if validation fails.\n * @returns {Validation}\n */\n setValidator(name: string, callable: Validator): this {\n this.__validators[name] = callable;\n return this;\n }\n\n /**\n * Get validator function by name.\n * @param name Validator name.\n * @returns {Validator} A validator function.\n */\n getValidator(name: string): Validator {\n if (!this.__validators[name]) {\n throw new ValidationError(\"Validator `\" + name + \"` does not exist!\", name);\n }\n return this.__validators[name];\n }\n\n /**\n * Asynchronously validates value.\n * @param value Value to validate.\n * @param validators A list of comma-separated validators (eg. required,number,gt:20).\n * @param [options] Validation options.\n * @returns {Promise<boolean | ValidationError>}\n */\n async validate(\n value: any,\n validators: string,\n options: ValidateOptions = {}\n ): Promise<boolean | ValidationError> {\n if (_.isString(validators) && _.isEmpty(validators)) {\n return true;\n }\n\n if (!_.isString(validators)) {\n throw new Error(invalidRules);\n }\n\n const parsedValidateProperty = this.__parseValidateProperty(validators);\n\n for (const [name, params] of entries(parsedValidateProperty)) {\n const validator = this.getValidator(name);\n try {\n await validator(value, params);\n } catch (e) {\n const validationError = new ValidationError(e.message, name, value);\n if (options.throw === false) {\n return validationError;\n }\n throw validationError;\n }\n }\n return true;\n }\n\n /**\n * Synchronously validates value.\n * @param value Value to validate.\n * @param validators A list of comma-separated validators (eg. required,number,gt:20).\n * @param [options] Validation options.\n * @returns {Promise<boolean | ValidationError>}\n */\n validateSync(\n value: any,\n validators: string,\n options: ValidateOptions = {}\n ): boolean | ValidationError {\n if (_.isString(validators) && _.isEmpty(validators)) {\n return true;\n }\n\n if (!_.isString(validators)) {\n throw new Error(invalidRules);\n }\n\n const parsedValidateProperty = this.__parseValidateProperty(validators);\n\n for (const [name, params] of entries(parsedValidateProperty)) {\n const validator = this.getValidator(name);\n try {\n validator(value, params);\n } catch (e) {\n const validationError = new ValidationError(e.message, name, value);\n if (options.throw === false) {\n return validationError;\n }\n throw validationError;\n }\n }\n return true;\n }\n\n create(validators: string) {\n if (createdValidators.async[validators]) {\n return createdValidators.async[validators];\n }\n\n createdValidators.async[validators] = value => this.validate(value, validators);\n return createdValidators.async[validators];\n }\n\n createSync(validators: string) {\n if (createdValidators.sync[validators]) {\n return createdValidators.sync[validators];\n }\n\n createdValidators.sync[validators] = value => this.validateSync(value, validators);\n return createdValidators.sync[validators];\n }\n\n /**\n * Parses a string of validators with parameters.\n * @param validators A list of comma-separated validators (eg. required,number,gt:20).\n * @returns {ParsedValidators}\n * @private\n */\n __parseValidateProperty(validators: string): ParsedValidators {\n const validate: Array<string> = validators.split(\",\");\n\n const parsedValidators: ParsedValidators = {};\n validate.forEach((v: string) => {\n const params = _.trim(v).split(\":\");\n const vName = params.shift();\n if (!vName) {\n return;\n }\n parsedValidators[vName] = params;\n });\n return parsedValidators;\n }\n}\n\nexport default Validation;\n"],"mappings":";;;;;;;;;;;;;;;;;AACA;;AAGA,MAAMA,OAAO,GAAIC,UAAD,IAAkE;EAC9E,OAAOC,MAAM,CAACF,OAAP,CAAeC,UAAf,CAAP;AACH,CAFD;;AAIA,MAAME,YAAY,GAAG,6EAArB;AAMA,MAAMC,iBAAoC,GAAG;EACzCC,KAAK,EAAE,EADkC;EAEzCC,IAAI,EAAE;AAFmC,CAA7C;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,UAAN,CAAiB;EACb;AACJ;AACA;AACA;EAKIC,WAAW,GAAG;IAAA;IACV,KAAKC,YAAL,GAAoB,EAApB;EACH;EAED;AACJ;AACA;AACA;AACA;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,EAAqB;IAC3B,IAAIG,iBAAiB,CAACE,IAAlB,CAAuBL,UAAvB,CAAJ,EAAwC;MACpC,OAAOG,iBAAiB,CAACE,IAAlB,CAAuBL,UAAvB,CAAP;IACH;;IAEDG,iBAAiB,CAACE,IAAlB,CAAuBL,UAAvB,IAAqCe,KAAK,IAAI,KAAKW,YAAL,CAAkBX,KAAlB,EAAyBf,UAAzB,CAA9C;;IACA,OAAOG,iBAAiB,CAACE,IAAlB,CAAuBL,UAAvB,CAAP;EACH;EAED;AACJ;AACA;AACA;AACA;AACA;;;EACImB,uBAAuB,CAACnB,UAAD,EAAuC;IAC1D,MAAMc,QAAuB,GAAGd,UAAU,CAAC6B,KAAX,CAAiB,GAAjB,CAAhC;IAEA,MAAMC,gBAAkC,GAAG,EAA3C;IACAhB,QAAQ,CAACiB,OAAT,CAAkBC,CAAD,IAAe;MAC5B,MAAMZ,MAAM,GAAG,oBAAOY,CAAP,EAAUH,KAAV,CAAgB,GAAhB,CAAf;MACA,MAAMI,KAAK,GAAGb,MAAM,CAACc,KAAP,EAAd;;MACA,IAAI,CAACD,KAAL,EAAY;QACR;MACH;;MACDH,gBAAgB,CAACG,KAAD,CAAhB,GAA0Bb,MAA1B;IACH,CAPD;IAQA,OAAOU,gBAAP;EACH;;AAnJY;;eAsJFxB,U"}
1
+ {"version":3,"names":["_isString","_interopRequireDefault","require","_isEmpty","_trim","_validationError","entries","validators","Object","invalidRules","createdValidators","async","sync","Validation","constructor","__validators","setValidator","name","callable","validatorName","getValidator","ValidationError","validate","value","options","isString","isEmpty","Error","parsedValidateProperty","__parseValidateProperty","params","validator","e","validationError","message","throw","validateSync","create","createSync","split","parsedValidators","forEach","v","trim","vName","shift","_default","exports","default"],"sources":["validation.ts"],"sourcesContent":["import isString from \"lodash/isString\";\nimport isEmpty from \"lodash/isEmpty\";\nimport trim from \"lodash/trim\";\nimport ValidationError from \"./validationError\";\nimport type { ParsedValidators, ValidateOptions, Validator } from \"./types\";\n\nconst entries = (validators: ParsedValidators): Array<[string, Array<string>]> => {\n return Object.entries(validators);\n};\n\nconst invalidRules = \"Validators must be specified as a string (eg. required,minLength:10,email).\";\n\ninterface CreatedValidators {\n async: Record<string, Validator>;\n sync: Record<string, Validator>;\n}\nconst createdValidators: CreatedValidators = {\n async: {},\n sync: {}\n};\n\n/**\n * Main class of Validation library.\n * Exported as a singleton instance, it offers methods for sync/async data validation and overwriting or adding new validators.\n *\n * @class Validation\n * @example\n * import { validation } from '@webiny/validation';\n *\n * // `validation` is a preconfigured instance of Validation class.\n * // From here you can either add new validators or use it as-is.\n */\nclass Validation {\n /**\n * Contains a list of all set validators.\n * @private\n */\n __validators: {\n [key: string]: Validator;\n };\n\n constructor() {\n this.__validators = {};\n }\n\n /**\n * Add new validator.\n * @param name Validator name.\n * @param callable Validator function which throws a ValidationError if validation fails.\n * @returns {Validation}\n */\n setValidator(name: string, callable: Validator): this {\n this.__validators[name] = callable;\n this.__validators[name].validatorName = name;\n return this;\n }\n\n /**\n * Get validator function by name.\n * @param name Validator name.\n * @returns {Validator} A validator function.\n */\n getValidator(name: string): Validator {\n if (!this.__validators[name]) {\n throw new ValidationError(\"Validator `\" + name + \"` does not exist!\", name);\n }\n return this.__validators[name];\n }\n\n /**\n * Asynchronously validates value.\n * @param value Value to validate.\n * @param validators A list of comma-separated validators (eg. required,number,gt:20).\n * @param [options] Validation options.\n * @returns {Promise<boolean | ValidationError>}\n */\n async validate(\n value: any,\n validators: string,\n options: ValidateOptions = {}\n ): Promise<boolean | ValidationError> {\n if (isString(validators) && isEmpty(validators)) {\n return true;\n }\n\n if (!isString(validators)) {\n throw new Error(invalidRules);\n }\n\n const parsedValidateProperty = this.__parseValidateProperty(validators);\n\n for (const [name, params] of entries(parsedValidateProperty)) {\n const validator = this.getValidator(name);\n try {\n await validator(value, params);\n } catch (e) {\n const validationError = new ValidationError(e.message, name, value);\n if (options.throw === false) {\n return validationError;\n }\n throw validationError;\n }\n }\n return true;\n }\n\n /**\n * Synchronously validates value.\n * @param value Value to validate.\n * @param validators A list of comma-separated validators (eg. required,number,gt:20).\n * @param [options] Validation options.\n * @returns {Promise<boolean | ValidationError>}\n */\n validateSync(\n value: any,\n validators: string,\n options: ValidateOptions = {}\n ): boolean | ValidationError {\n if (isString(validators) && isEmpty(validators)) {\n return true;\n }\n\n if (!isString(validators)) {\n throw new Error(invalidRules);\n }\n\n const parsedValidateProperty = this.__parseValidateProperty(validators);\n\n for (const [name, params] of entries(parsedValidateProperty)) {\n const validator = this.getValidator(name);\n try {\n validator(value, params);\n } catch (e) {\n const validationError = new ValidationError(e.message, name, value);\n if (options.throw === false) {\n return validationError;\n }\n throw validationError;\n }\n }\n return true;\n }\n\n create(validators: string) {\n if (createdValidators.async[validators]) {\n return createdValidators.async[validators];\n }\n\n createdValidators.async[validators] = value => this.validate(value, validators);\n return createdValidators.async[validators];\n }\n\n createSync(validators: string) {\n if (createdValidators.sync[validators]) {\n return createdValidators.sync[validators];\n }\n\n createdValidators.sync[validators] = value => this.validateSync(value, validators);\n return createdValidators.sync[validators];\n }\n\n /**\n * Parses a string of validators with parameters.\n * @param validators A list of comma-separated validators (eg. required,number,gt:20).\n * @returns {ParsedValidators}\n * @private\n */\n __parseValidateProperty(validators: string): ParsedValidators {\n const validate: Array<string> = validators.split(\",\");\n\n const parsedValidators: ParsedValidators = {};\n validate.forEach((v: string) => {\n const params = trim(v).split(\":\");\n const vName = params.shift();\n if (!vName) {\n return;\n }\n parsedValidators[vName] = params;\n });\n return parsedValidators;\n }\n}\n\nexport default Validation;\n"],"mappings":";;;;;;;AAAA,IAAAA,SAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,QAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,KAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,gBAAA,GAAAJ,sBAAA,CAAAC,OAAA;AAGA,MAAMI,OAAO,GAAIC,UAA4B,IAAqC;EAC9E,OAAOC,MAAM,CAACF,OAAO,CAACC,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AAgB,CAACI,KAAK,CAAC,GAAGd,MAAM;IACpC,CAAC,CAAC;IACF,OAAOU,gBAAgB;EAC3B;AACJ;AAAC,IAAAM,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEcnC,UAAU","ignoreList":[]}
@@ -1,29 +1,20 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
3
  Object.defineProperty(exports, "__esModule", {
6
4
  value: true
7
5
  });
8
6
  exports.default = void 0;
9
-
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
7
  /**
13
8
  * This class is used by validators to throw an error when value validation fails.
14
9
  */
15
10
  class ValidationError extends Error {
16
11
  constructor(message = "", validator = null, value = null) {
17
12
  super();
18
- (0, _defineProperty2.default)(this, "message", void 0);
19
- (0, _defineProperty2.default)(this, "validator", void 0);
20
- (0, _defineProperty2.default)(this, "value", void 0);
21
13
  this.message = message;
22
14
  this.validator = validator;
23
15
  this.value = value;
24
16
  }
25
-
26
17
  }
18
+ var _default = exports.default = ValidationError;
27
19
 
28
- var _default = ValidationError;
29
- exports.default = _default;
20
+ //# sourceMappingURL=validationError.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["ValidationError","Error","constructor","message","validator","value"],"sources":["validationError.ts"],"sourcesContent":["/**\n * This class is used by validators to throw an error when value validation fails.\n */\nclass ValidationError extends Error {\n public override readonly message: string;\n public readonly validator: string | null;\n public readonly value: any;\n\n constructor(message = \"\", validator: string | null = null, value: string | null = null) {\n super();\n this.message = message;\n this.validator = validator;\n this.value = value;\n }\n}\n\nexport default ValidationError;\n"],"mappings":";;;;;;;;;;;AAAA;AACA;AACA;AACA,MAAMA,eAAN,SAA8BC,KAA9B,CAAoC;EAKhCC,WAAW,CAACC,OAAO,GAAG,EAAX,EAAeC,SAAwB,GAAG,IAA1C,EAAgDC,KAAoB,GAAG,IAAvE,EAA6E;IACpF;IADoF;IAAA;IAAA;IAEpF,KAAKF,OAAL,GAAeA,OAAf;IACA,KAAKC,SAAL,GAAiBA,SAAjB;IACA,KAAKC,KAAL,GAAaA,KAAb;EACH;;AAV+B;;eAarBL,e"}
1
+ {"version":3,"names":["ValidationError","Error","constructor","message","validator","value","_default","exports","default"],"sources":["validationError.ts"],"sourcesContent":["/**\n * This class is used by validators to throw an error when value validation fails.\n */\nclass ValidationError extends Error {\n public override readonly message: string;\n public readonly validator: string | null;\n public readonly value: any;\n\n constructor(message = \"\", validator: string | null = null, value: string | null = null) {\n super();\n this.message = message;\n this.validator = validator;\n this.value = value;\n }\n}\n\nexport default ValidationError;\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA,MAAMA,eAAe,SAASC,KAAK,CAAC;EAKhCC,WAAWA,CAACC,OAAO,GAAG,EAAE,EAAEC,SAAwB,GAAG,IAAI,EAAEC,KAAoB,GAAG,IAAI,EAAE;IACpF,KAAK,CAAC,CAAC;IACP,IAAI,CAACF,OAAO,GAAGA,OAAO;IACtB,IAAI,CAACC,SAAS,GAAGA,SAAS;IAC1B,IAAI,CAACC,KAAK,GAAGA,KAAK;EACtB;AACJ;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEcR,eAAe","ignoreList":[]}
@@ -1,14 +1,11 @@
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
  /**
13
10
  * @name creditCard
14
11
  * @description Credit card validator. This validator will check if the given value is a credit card number.
@@ -26,44 +23,35 @@ var _default = value => {
26
23
  if (!value) {
27
24
  return;
28
25
  }
29
-
30
26
  value = value + "";
31
-
32
27
  if (value.length < 12) {
33
28
  throw new _validationError.default("Credit card number too short.");
34
29
  }
35
-
36
30
  if (/[^0-9-\s]+/.test(value)) {
37
31
  throw new _validationError.default("Credit card number invalid.");
38
32
  }
39
-
40
33
  let nCheck = 0;
41
34
  let nDigit = 0;
42
35
  let bEven = false;
43
36
  value = value.replace(/ /g, "");
44
37
  value = value.replace(/\D/g, "");
45
-
46
38
  for (let n = value.length - 1; n >= 0; n--) {
47
39
  const cDigit = value.charAt(n);
48
40
  nDigit = parseInt(cDigit);
49
-
50
41
  if (bEven) {
51
42
  nDigit *= 2;
52
-
53
43
  if (nDigit > 9) {
54
44
  nDigit -= 9;
55
45
  }
56
46
  }
57
-
58
47
  nCheck += nDigit;
59
48
  bEven = !bEven;
60
49
  }
61
-
62
50
  if (nCheck % 10 === 0) {
63
51
  return;
64
52
  }
65
-
66
53
  throw new _validationError.default("Credit card number invalid.");
67
54
  };
55
+ exports.default = _default;
68
56
 
69
- exports.default = _default;
57
+ //# sourceMappingURL=creditCard.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["value","length","ValidationError","test","nCheck","nDigit","bEven","replace","n","cDigit","charAt","parseInt"],"sources":["creditCard.ts"],"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"],"mappings":";;;;;;;;;AAAA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;eACgBA,KAAD,IAAsB;EACjC,IAAI,CAACA,KAAL,EAAY;IACR;EACH;;EACDA,KAAK,GAAGA,KAAK,GAAG,EAAhB;;EAEA,IAAIA,KAAK,CAACC,MAAN,GAAe,EAAnB,EAAuB;IACnB,MAAM,IAAIC,wBAAJ,CAAoB,+BAApB,CAAN;EACH;;EAED,IAAI,aAAaC,IAAb,CAAkBH,KAAlB,CAAJ,EAA8B;IAC1B,MAAM,IAAIE,wBAAJ,CAAoB,6BAApB,CAAN;EACH;;EAED,IAAIE,MAAM,GAAG,CAAb;EACA,IAAIC,MAAM,GAAG,CAAb;EACA,IAAIC,KAAK,GAAG,KAAZ;EAEAN,KAAK,GAAGA,KAAK,CAACO,OAAN,CAAc,IAAd,EAAoB,EAApB,CAAR;EACAP,KAAK,GAAGA,KAAK,CAACO,OAAN,CAAc,KAAd,EAAqB,EAArB,CAAR;;EAEA,KAAK,IAAIC,CAAC,GAAGR,KAAK,CAACC,MAAN,GAAe,CAA5B,EAA+BO,CAAC,IAAI,CAApC,EAAuCA,CAAC,EAAxC,EAA4C;IACxC,MAAMC,MAAM,GAAGT,KAAK,CAACU,MAAN,CAAaF,CAAb,CAAf;IACAH,MAAM,GAAGM,QAAQ,CAACF,MAAD,CAAjB;;IAEA,IAAIH,KAAJ,EAAW;MACPD,MAAM,IAAI,CAAV;;MACA,IAAIA,MAAM,GAAG,CAAb,EAAgB;QACZA,MAAM,IAAI,CAAV;MACH;IACJ;;IAEDD,MAAM,IAAIC,MAAV;IACAC,KAAK,GAAG,CAACA,KAAT;EACH;;EAED,IAAIF,MAAM,GAAG,EAAT,KAAgB,CAApB,EAAuB;IACnB;EACH;;EAED,MAAM,IAAIF,wBAAJ,CAAoB,6BAApB,CAAN;AACH,C"}
1
+ {"version":3,"names":["_validationError","_interopRequireDefault","require","_default","value","length","ValidationError","test","nCheck","nDigit","bEven","replace","n","cDigit","charAt","parseInt","exports","default"],"sources":["creditCard.ts"],"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"],"mappings":";;;;;;;AAAA,IAAAA,gBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAZA,IAAAC,QAAA,GAagBC,KAAU,IAAW;EACjC,IAAI,CAACA,KAAK,EAAE;IACR;EACJ;EACAA,KAAK,GAAGA,KAAK,GAAG,EAAE;EAElB,IAAIA,KAAK,CAACC,MAAM,GAAG,EAAE,EAAE;IACnB,MAAM,IAAIC,wBAAe,CAAC,+BAA+B,CAAC;EAC9D;EAEA,IAAI,YAAY,CAACC,IAAI,CAACH,KAAK,CAAC,EAAE;IAC1B,MAAM,IAAIE,wBAAe,CAAC,6BAA6B,CAAC;EAC5D;EAEA,IAAIE,MAAM,GAAG,CAAC;EACd,IAAIC,MAAM,GAAG,CAAC;EACd,IAAIC,KAAK,GAAG,KAAK;EAEjBN,KAAK,GAAGA,KAAK,CAACO,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC;EAC/BP,KAAK,GAAGA,KAAK,CAACO,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;EAEhC,KAAK,IAAIC,CAAC,GAAGR,KAAK,CAACC,MAAM,GAAG,CAAC,EAAEO,CAAC,IAAI,CAAC,EAAEA,CAAC,EAAE,EAAE;IACxC,MAAMC,MAAM,GAAGT,KAAK,CAACU,MAAM,CAACF,CAAC,CAAC;IAC9BH,MAAM,GAAGM,QAAQ,CAACF,MAAM,CAAC;IAEzB,IAAIH,KAAK,EAAE;MACPD,MAAM,IAAI,CAAC;MACX,IAAIA,MAAM,GAAG,CAAC,EAAE;QACZA,MAAM,IAAI,CAAC;MACf;IACJ;IAEAD,MAAM,IAAIC,MAAM;IAChBC,KAAK,GAAG,CAACA,KAAK;EAClB;EAEA,IAAIF,MAAM,GAAG,EAAE,KAAK,CAAC,EAAE;IACnB;EACJ;EAEA,MAAM,IAAIF,wBAAe,CAAC,6BAA6B,CAAC;AAC5D,CAAC;AAAAU,OAAA,CAAAC,OAAA,GAAAd,QAAA","ignoreList":[]}
@@ -1,37 +1,30 @@
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
  /**
13
10
  * Validates that given value is a greater or equal date to a gteValue
14
11
  */
15
12
  var _default = (value, params) => {
16
13
  if (!value || !params) {
17
14
  return;
18
- } // we need to join because validation params are being split by :
19
-
20
-
15
+ }
16
+ // we need to join because validation params are being split by :
21
17
  const gteValue = params.join(":");
22
-
23
18
  if (!gteValue) {
24
19
  return;
25
20
  }
26
-
27
21
  const date = new Date(value);
28
22
  const gteDate = new Date(gteValue);
29
-
30
23
  if (date >= gteDate) {
31
24
  return;
32
25
  }
33
-
34
26
  throw new _validationError.default(`Value needs to be greater than or equal to "${gteDate.toISOString()}".`);
35
27
  };
28
+ exports.default = _default;
36
29
 
37
- exports.default = _default;
30
+ //# sourceMappingURL=dateGte.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["value","params","gteValue","join","date","Date","gteDate","ValidationError","toISOString"],"sources":["dateGte.ts"],"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 || !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 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"],"mappings":";;;;;;;;;AAAA;;AAEA;AACA;AACA;eACe,CAACA,KAAD,EAAgBC,MAAhB,KAAsC;EACjD,IAAI,CAACD,KAAD,IAAU,CAACC,MAAf,EAAuB;IACnB;EACH,CAHgD,CAIjD;;;EACA,MAAMC,QAAQ,GAAGD,MAAM,CAACE,IAAP,CAAY,GAAZ,CAAjB;;EACA,IAAI,CAACD,QAAL,EAAe;IACX;EACH;;EAED,MAAME,IAAI,GAAG,IAAIC,IAAJ,CAASL,KAAT,CAAb;EACA,MAAMM,OAAO,GAAG,IAAID,IAAJ,CAASH,QAAT,CAAhB;;EAEA,IAAIE,IAAI,IAAIE,OAAZ,EAAqB;IACjB;EACH;;EACD,MAAM,IAAIC,wBAAJ,CACD,+CAA8CD,OAAO,CAACE,WAAR,EAAsB,IADnE,CAAN;AAGH,C"}
1
+ {"version":3,"names":["_validationError","_interopRequireDefault","require","_default","value","params","gteValue","join","date","Date","gteDate","ValidationError","toISOString","exports","default"],"sources":["dateGte.ts"],"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 || !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 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"],"mappings":";;;;;;;AAAA,IAAAA,gBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA;AACA;AACA;AAFA,IAAAC,QAAA,GAGeA,CAACC,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,IAAI,GAAG,IAAIC,IAAI,CAACL,KAAK,CAAC;EAC5B,MAAMM,OAAO,GAAG,IAAID,IAAI,CAACH,QAAQ,CAAC;EAElC,IAAIE,IAAI,IAAIE,OAAO,EAAE;IACjB;EACJ;EACA,MAAM,IAAIC,wBAAe,CACrB,+CAA+CD,OAAO,CAACE,WAAW,CAAC,CAAC,IACxE,CAAC;AACL,CAAC;AAAAC,OAAA,CAAAC,OAAA,GAAAX,QAAA","ignoreList":[]}