@webiny/validation 0.0.0-unstable.78f581c1d2 → 0.0.0-unstable.7be00a75a9

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 (61) hide show
  1. package/README.md +7 -405
  2. package/index.d.ts +4 -4
  3. package/index.js +52 -96
  4. package/index.js.map +1 -1
  5. package/package.json +17 -25
  6. package/types.d.ts +6 -3
  7. package/types.js +0 -5
  8. package/validation.d.ts +2 -2
  9. package/validation.js +66 -184
  10. package/validation.js.map +1 -1
  11. package/validationError.js +9 -26
  12. package/validationError.js.map +1 -1
  13. package/validators/creditCard.js +24 -66
  14. package/validators/creditCard.js.map +1 -1
  15. package/validators/dateGte.js +11 -35
  16. package/validators/dateGte.js.map +1 -1
  17. package/validators/dateLte.js +11 -35
  18. package/validators/dateLte.js.map +1 -1
  19. package/validators/email.js +9 -39
  20. package/validators/email.js.map +1 -1
  21. package/validators/eq.js +8 -39
  22. package/validators/eq.js.map +1 -1
  23. package/validators/gt.js +8 -36
  24. package/validators/gt.js.map +1 -1
  25. package/validators/gte.js +8 -36
  26. package/validators/gte.js.map +1 -1
  27. package/validators/in.js +8 -25
  28. package/validators/in.js.map +1 -1
  29. package/validators/integer.js +8 -24
  30. package/validators/integer.js.map +1 -1
  31. package/validators/json.js +10 -22
  32. package/validators/json.js.map +1 -1
  33. package/validators/lt.js +8 -24
  34. package/validators/lt.js.map +1 -1
  35. package/validators/lte.js +8 -24
  36. package/validators/lte.js.map +1 -1
  37. package/validators/maxLength.js +15 -42
  38. package/validators/maxLength.js.map +1 -1
  39. package/validators/minLength.js +15 -42
  40. package/validators/minLength.js.map +1 -1
  41. package/validators/number.js +9 -32
  42. package/validators/number.js.map +1 -1
  43. package/validators/numeric.js +9 -40
  44. package/validators/numeric.js.map +1 -1
  45. package/validators/password.js +9 -24
  46. package/validators/password.js.map +1 -1
  47. package/validators/phone.js +8 -24
  48. package/validators/phone.js.map +1 -1
  49. package/validators/required.js +7 -19
  50. package/validators/required.js.map +1 -1
  51. package/validators/slug.js +8 -24
  52. package/validators/slug.js.map +1 -1
  53. package/validators/time/index.js +29 -75
  54. package/validators/time/index.js.map +1 -1
  55. package/validators/timeGte.js +11 -36
  56. package/validators/timeGte.js.map +1 -1
  57. package/validators/timeLte.js +11 -36
  58. package/validators/timeLte.js.map +1 -1
  59. package/validators/url.js +19 -52
  60. package/validators/url.js.map +1 -1
  61. package/types.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"names":["regex","base","RegExp","ip","relative","href","value","params","startsWith","replace","test","includes","ValidationError"],"sources":["url.ts"],"sourcesContent":["import ValidationError from \"~/validationError\";\n\nconst regex = {\n base: new RegExp(\n // eslint-disable-next-line\n /^(https?:\\/\\/)((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|((\\d{1,3}\\.){3}\\d{1,3}))(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*(\\?[;&a-z\\d%_.~+=!-]*)?(\\#[-a-z\\d_]*)?$/i\n ),\n ip: new RegExp(\n // eslint-disable-next-line\n /^(https?:\\/\\/)(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/\n ),\n relative: new RegExp(\n // eslint-disable-next-line\n /^\\/.*$/\n ),\n href: new RegExp(\n // eslint-disable-next-line\n /^(#|mailto:|tel:)\\S*$/\n )\n};\n\nexport default (value: any, params?: string[]) => {\n if (!value || !params) {\n return;\n }\n value = value + \"\";\n\n if (value.startsWith(\"http://localhost\") || value.startsWith(\"https://localhost\")) {\n value = value.replace(\"//localhost\", \"//localhost.com\");\n }\n\n if (regex.base.test(value)) {\n if (!params.includes(\"noIp\")) {\n return;\n }\n\n if (!regex.ip.test(value)) {\n return;\n }\n }\n\n if (params.includes(\"allowRelative\")) {\n if (regex.relative.test(value)) {\n return;\n }\n }\n\n if (params.includes(\"allowHref\")) {\n if (regex.href.test(value)) {\n return;\n }\n }\n\n throw new ValidationError(\"Value must be a valid URL.\");\n};\n"],"mappings":";;;;;;;;;AAAA;;AAEA,MAAMA,KAAK,GAAG;EACVC,IAAI,EAAE,IAAIC,MAAJ,EACF;EACA,uJAFE,CADI;EAKVC,EAAE,EAAE,IAAID,MAAJ,EACA;EACA,+KAFA,CALM;EASVE,QAAQ,EAAE,IAAIF,MAAJ,EACN;EACA,QAFM,CATA;EAaVG,IAAI,EAAE,IAAIH,MAAJ,EACF;EACA,uBAFE;AAbI,CAAd;;eAmBe,CAACI,KAAD,EAAaC,MAAb,KAAmC;EAC9C,IAAI,CAACD,KAAD,IAAU,CAACC,MAAf,EAAuB;IACnB;EACH;;EACDD,KAAK,GAAGA,KAAK,GAAG,EAAhB;;EAEA,IAAIA,KAAK,CAACE,UAAN,CAAiB,kBAAjB,KAAwCF,KAAK,CAACE,UAAN,CAAiB,mBAAjB,CAA5C,EAAmF;IAC/EF,KAAK,GAAGA,KAAK,CAACG,OAAN,CAAc,aAAd,EAA6B,iBAA7B,CAAR;EACH;;EAED,IAAIT,KAAK,CAACC,IAAN,CAAWS,IAAX,CAAgBJ,KAAhB,CAAJ,EAA4B;IACxB,IAAI,CAACC,MAAM,CAACI,QAAP,CAAgB,MAAhB,CAAL,EAA8B;MAC1B;IACH;;IAED,IAAI,CAACX,KAAK,CAACG,EAAN,CAASO,IAAT,CAAcJ,KAAd,CAAL,EAA2B;MACvB;IACH;EACJ;;EAED,IAAIC,MAAM,CAACI,QAAP,CAAgB,eAAhB,CAAJ,EAAsC;IAClC,IAAIX,KAAK,CAACI,QAAN,CAAeM,IAAf,CAAoBJ,KAApB,CAAJ,EAAgC;MAC5B;IACH;EACJ;;EAED,IAAIC,MAAM,CAACI,QAAP,CAAgB,WAAhB,CAAJ,EAAkC;IAC9B,IAAIX,KAAK,CAACK,IAAN,CAAWK,IAAX,CAAgBJ,KAAhB,CAAJ,EAA4B;MACxB;IACH;EACJ;;EAED,MAAM,IAAIM,wBAAJ,CAAoB,4BAApB,CAAN;AACH,C"}
1
+ {"version":3,"file":"validators/url.js","sources":["../../src/validators/url.ts"],"sourcesContent":["import ValidationError from \"~/validationError.js\";\n\nconst regex = {\n base: new RegExp(\n /^(https?:\\/\\/)((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|((\\d{1,3}\\.){3}\\d{1,3}))(:\\d+)?(\\/[-a-z\\d%_.~+]*)*(\\?[;&a-z\\d%_.~+=!-]*)?(#[-a-z\\d_]*)?$/i\n ),\n ip: new RegExp(\n /^(https?:\\/\\/)(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/\n ),\n relative: new RegExp(/^\\/.*$/),\n href: new RegExp(/^(#|mailto:|tel:)\\S*$/)\n};\n\nexport default (value: any, params?: string[]) => {\n if (!value || !params) {\n return;\n }\n value = value + \"\";\n\n if (value.startsWith(\"http://localhost\") || value.startsWith(\"https://localhost\")) {\n value = value.replace(\"//localhost\", \"//localhost.com\");\n }\n\n if (regex.base.test(value)) {\n if (!params.includes(\"noIp\")) {\n return;\n }\n\n if (!regex.ip.test(value)) {\n return;\n }\n }\n\n if (params.includes(\"allowRelative\")) {\n if (regex.relative.test(value)) {\n return;\n }\n }\n\n if (params.includes(\"allowHref\")) {\n if (regex.href.test(value)) {\n return;\n }\n }\n\n throw new ValidationError(\"Value must be a valid URL.\");\n};\n"],"names":["regex","RegExp","value","params","ValidationError"],"mappings":";AAEA,MAAMA,QAAQ;IACV,MAAM,IAAIC,OACN;IAEJ,IAAI,IAAIA,OACJ;IAEJ,UAAU,IAAIA,OAAO;IACrB,MAAM,IAAIA,OAAO;AACrB;AAEA,YAAgB,CAAAC,OAAYC;IACxB,IAAI,CAACD,SAAS,CAACC,QACX;IAEJD,SAAgB;IAEhB,IAAIA,MAAM,UAAU,CAAC,uBAAuBA,MAAM,UAAU,CAAC,sBACzDA,QAAQA,MAAM,OAAO,CAAC,eAAe;IAGzC,IAAIF,MAAM,IAAI,CAAC,IAAI,CAACE,QAAQ;QACxB,IAAI,CAACC,OAAO,QAAQ,CAAC,SACjB;QAGJ,IAAI,CAACH,MAAM,EAAE,CAAC,IAAI,CAACE,QACf;IAER;IAEA,IAAIC,OAAO,QAAQ,CAAC,kBAChB;QAAA,IAAIH,MAAM,QAAQ,CAAC,IAAI,CAACE,QACpB;IACJ;IAGJ,IAAIC,OAAO,QAAQ,CAAC,cAChB;QAAA,IAAIH,MAAM,IAAI,CAAC,IAAI,CAACE,QAChB;IACJ;IAGJ,MAAM,IAAIE,gBAAgB;AAC9B"}
package/types.js.map DELETED
@@ -1 +0,0 @@
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":""}