@digigov/form 0.6.8 → 0.7.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 (298) hide show
  1. package/CHANGELOG.md +26 -1
  2. package/Field/FieldBase.js +110 -0
  3. package/Field/{ConditionalField.js → FieldConditional.js} +9 -29
  4. package/Field/FieldContainer.js +62 -0
  5. package/Field/index.js +11 -251
  6. package/Field/types.js +5 -0
  7. package/Field/utils.js +146 -0
  8. package/Fieldset/FieldsetWithContext.js +63 -0
  9. package/Fieldset/index.js +5 -64
  10. package/Fieldset/types.js +5 -0
  11. package/FormBuilder.js +178 -0
  12. package/FormContext.js +14 -0
  13. package/Questions/Questions.js +105 -0
  14. package/Questions/QuestionsContext.js +20 -0
  15. package/Questions/Step/ReviewStep.js +11 -7
  16. package/Questions/Step/Step.js +93 -0
  17. package/Questions/Step/StepArrayReview.js +79 -0
  18. package/Questions/Step/StepContext.js +37 -0
  19. package/Questions/Step/StepDescription.js +2 -2
  20. package/Questions/Step/StepForm.js +10 -6
  21. package/Questions/Step/StepTitle.js +2 -2
  22. package/Questions/Step/getAddMoreFields.js +31 -0
  23. package/Questions/Step/index.js +81 -200
  24. package/Questions/Step/types.js +5 -0
  25. package/Questions/__snapshots__/index.spec.tsx.snap +461 -2499
  26. package/Questions/getNextStep.js +30 -0
  27. package/Questions/index.js +4 -150
  28. package/Questions/types.js +5 -0
  29. package/es/Field/FieldBase.js +93 -0
  30. package/es/Field/{ConditionalField.js → FieldConditional.js} +5 -28
  31. package/es/Field/FieldContainer.js +40 -0
  32. package/es/Field/index.js +8 -233
  33. package/es/Field/types.js +1 -0
  34. package/es/Field/utils.js +122 -0
  35. package/es/Fieldset/FieldsetWithContext.js +41 -0
  36. package/es/Fieldset/index.js +4 -52
  37. package/es/Fieldset/types.js +1 -0
  38. package/es/FormBuilder.js +148 -0
  39. package/es/FormContext.js +5 -0
  40. package/es/Questions/Questions.js +84 -0
  41. package/es/Questions/QuestionsContext.js +11 -0
  42. package/es/Questions/Step/ReviewStep.js +5 -3
  43. package/es/Questions/Step/Step.js +69 -0
  44. package/es/Questions/Step/StepArrayReview.js +50 -0
  45. package/es/Questions/Step/StepContext.js +27 -0
  46. package/es/Questions/Step/StepDescription.js +1 -1
  47. package/es/Questions/Step/StepForm.js +4 -2
  48. package/es/Questions/Step/StepTitle.js +1 -1
  49. package/es/Questions/Step/getAddMoreFields.js +22 -0
  50. package/es/Questions/Step/index.js +13 -165
  51. package/es/Questions/Step/types.js +1 -0
  52. package/es/Questions/__snapshots__/index.spec.tsx.snap +461 -2499
  53. package/es/Questions/getNextStep.js +23 -0
  54. package/es/Questions/index.js +2 -119
  55. package/es/Questions/index.spec.js +2 -1
  56. package/es/Questions/types.js +1 -0
  57. package/es/index.js +2 -153
  58. package/es/inputs/index.js +5 -4
  59. package/es/internal.js +31 -0
  60. package/es/types.js +1 -0
  61. package/es/utils.js +5 -3
  62. package/es/validators/index.js +155 -0
  63. package/es/validators/types.js +1 -0
  64. package/es/validators/utils/afm.js +35 -0
  65. package/es/validators/utils/file.js +52 -0
  66. package/es/validators/utils/iban.js +123 -0
  67. package/es/validators/utils/index.js +105 -0
  68. package/es/validators/utils/phone.js +122 -0
  69. package/es/validators/utils/postal_code.js +29 -0
  70. package/es/validators/utils/uuid4.js +20 -0
  71. package/{esm → es/validators}/validators.spec.js +1 -1
  72. package/esm/Field/FieldBase.js +93 -0
  73. package/esm/Field/{ConditionalField.js → FieldConditional.js} +5 -28
  74. package/esm/Field/FieldContainer.js +40 -0
  75. package/esm/Field/index.js +8 -233
  76. package/esm/Field/types.js +1 -0
  77. package/esm/Field/utils.js +122 -0
  78. package/esm/Fieldset/FieldsetWithContext.js +41 -0
  79. package/esm/Fieldset/index.js +4 -52
  80. package/esm/Fieldset/types.js +1 -0
  81. package/esm/FormBuilder.js +148 -0
  82. package/esm/FormContext.js +5 -0
  83. package/esm/Questions/Questions.js +84 -0
  84. package/esm/Questions/QuestionsContext.js +11 -0
  85. package/esm/Questions/Step/ReviewStep.js +5 -3
  86. package/esm/Questions/Step/Step.js +69 -0
  87. package/esm/Questions/Step/StepArrayReview.js +50 -0
  88. package/esm/Questions/Step/StepContext.js +27 -0
  89. package/esm/Questions/Step/StepDescription.js +1 -1
  90. package/esm/Questions/Step/StepForm.js +4 -2
  91. package/esm/Questions/Step/StepTitle.js +1 -1
  92. package/esm/Questions/Step/getAddMoreFields.js +22 -0
  93. package/esm/Questions/Step/index.js +13 -165
  94. package/esm/Questions/Step/types.js +1 -0
  95. package/esm/Questions/__snapshots__/index.spec.tsx.snap +461 -2499
  96. package/esm/Questions/getNextStep.js +23 -0
  97. package/esm/Questions/index.js +2 -119
  98. package/esm/Questions/index.spec.js +2 -1
  99. package/esm/Questions/types.js +1 -0
  100. package/esm/index.js +3 -154
  101. package/esm/inputs/index.js +5 -4
  102. package/esm/internal.js +31 -0
  103. package/esm/types.js +1 -0
  104. package/esm/utils.js +5 -3
  105. package/esm/validators/index.js +155 -0
  106. package/esm/validators/types.js +1 -0
  107. package/esm/validators/utils/afm.js +35 -0
  108. package/esm/validators/utils/file.js +52 -0
  109. package/esm/validators/utils/iban.js +123 -0
  110. package/esm/validators/utils/index.js +105 -0
  111. package/esm/validators/utils/phone.js +122 -0
  112. package/esm/validators/utils/postal_code.js +29 -0
  113. package/esm/validators/utils/uuid4.js +20 -0
  114. package/{es → esm/validators}/validators.spec.js +1 -1
  115. package/index.js +8 -191
  116. package/inputs/index.js +13 -5
  117. package/internal.js +356 -0
  118. package/libs/form/src/Field/FieldBase.d.ts +3 -0
  119. package/libs/form/src/Field/FieldConditional.d.ts +4 -0
  120. package/libs/form/src/Field/FieldContainer.d.ts +4 -0
  121. package/libs/form/src/Field/index.d.ts +1 -62
  122. package/libs/form/src/Field/types.d.ts +75 -0
  123. package/libs/form/src/Field/utils.d.ts +5 -0
  124. package/libs/form/src/Fieldset/FieldsetWithContext.d.ts +4 -0
  125. package/libs/form/src/Fieldset/index.d.ts +2 -12
  126. package/libs/form/src/Fieldset/types.d.ts +6 -0
  127. package/libs/form/src/FormBuilder.d.ts +5 -0
  128. package/libs/form/src/FormContext.d.ts +3 -0
  129. package/libs/form/src/Questions/Questions.d.ts +8 -0
  130. package/libs/form/src/Questions/QuestionsContext.d.ts +3 -0
  131. package/libs/form/src/Questions/Step/ReviewStep.d.ts +1 -0
  132. package/libs/form/src/Questions/Step/Step.d.ts +9 -0
  133. package/libs/form/src/Questions/Step/StepArrayReview.d.ts +4 -0
  134. package/libs/form/src/Questions/Step/StepContext.d.ts +4 -0
  135. package/libs/form/src/Questions/Step/StepForm.d.ts +2 -1
  136. package/libs/form/src/Questions/Step/getAddMoreFields.d.ts +3 -0
  137. package/libs/form/src/Questions/Step/index.d.ts +12 -47
  138. package/libs/form/src/Questions/Step/types.d.ts +31 -0
  139. package/libs/form/src/Questions/getNextStep.d.ts +2 -0
  140. package/libs/form/src/Questions/index.d.ts +1 -28
  141. package/libs/form/src/Questions/types.d.ts +19 -0
  142. package/libs/form/src/index.d.ts +2 -73
  143. package/libs/form/src/inputs/Checkboxes/index.d.ts +1 -1
  144. package/libs/form/src/inputs/DateInput/index.d.ts +1 -1
  145. package/libs/form/src/inputs/FileInput/index.d.ts +1 -1
  146. package/libs/form/src/inputs/Input/index.d.ts +1 -1
  147. package/libs/form/src/inputs/Label/index.d.ts +2 -1
  148. package/libs/form/src/inputs/Radio/index.d.ts +1 -1
  149. package/libs/form/src/inputs/Select/index.d.ts +1 -1
  150. package/libs/form/src/inputs/index.d.ts +4 -3
  151. package/libs/form/src/internal.d.ts +31 -0
  152. package/libs/form/src/types.d.ts +70 -0
  153. package/libs/form/src/validators/index.d.ts +8 -0
  154. package/libs/form/src/validators/types.d.ts +2 -0
  155. package/libs/form/src/validators/utils/afm.d.ts +6 -0
  156. package/libs/form/src/validators/utils/file.d.ts +1 -0
  157. package/libs/form/src/validators/utils/iban.d.ts +2 -0
  158. package/libs/form/src/validators/utils/index.d.ts +12 -0
  159. package/libs/form/src/validators/utils/phone.d.ts +9 -0
  160. package/libs/form/src/validators/utils/postal_code.d.ts +2 -0
  161. package/libs/form/src/validators/utils/uuid4.d.ts +6 -0
  162. package/libs/form/src/{validators.spec.d.ts → validators/validators.spec.d.ts} +0 -0
  163. package/libs/ui/src/core/Accordion/index.d.ts +3 -3
  164. package/libs/ui/src/core/BackLink/index.d.ts +3 -0
  165. package/libs/ui/src/core/Blockquote/index.d.ts +1 -1
  166. package/libs/ui/src/core/Breadcrumbs/index.d.ts +2 -0
  167. package/libs/ui/src/core/Button/BackButton.d.ts +1 -1
  168. package/libs/ui/src/core/Button/ButtonLink.d.ts +1 -1
  169. package/libs/ui/src/core/Button/index.d.ts +1 -1
  170. package/libs/ui/src/core/Confirmation/index.d.ts +5 -0
  171. package/libs/ui/src/core/Divider/index.d.ts +1 -1
  172. package/libs/ui/src/core/NavList/NavList.d.ts +1 -14
  173. package/libs/ui/src/core/NavList/NavListBase.d.ts +4 -0
  174. package/libs/ui/src/core/NavList/NavListItem.d.ts +2 -1
  175. package/libs/ui/src/core/NavList/NavListItemBase.d.ts +2 -1
  176. package/libs/ui/src/core/NavList/NavListSubMenu.d.ts +1 -1
  177. package/libs/ui/src/core/NavList/types.d.ts +14 -0
  178. package/libs/ui/src/core/NotificationBanner/index.d.ts +1 -1
  179. package/libs/ui/src/core/PhaseBanner/index.d.ts +6 -0
  180. package/libs/ui/src/core/Table/TableFloatingScroll.d.ts +3 -0
  181. package/libs/ui/src/core/Table/index.d.ts +1 -0
  182. package/libs/ui/src/core/TextArea/index.d.ts +3 -0
  183. package/libs/ui/src/core/TextInput/index.d.ts +3 -0
  184. package/libs/ui/src/core/VisuallyHidden/index.d.ts +2 -0
  185. package/libs/ui/src/core/index.d.ts +8 -2
  186. package/libs/ui/src/hooks/useTogglableSections.d.ts +3 -2
  187. package/libs/ui/src/layouts/Grid/index.d.ts +4 -0
  188. package/libs/ui/src/locales/el.d.ts +1 -0
  189. package/libs/ui/src/typography/{Caption.d.ts → Caption/index.d.ts} +1 -1
  190. package/libs/ui/src/typography/{NormalText.d.ts → NormalText/index.d.ts} +0 -0
  191. package/libs/ui/src/typography/{Paragraph.d.ts → Paragraph/index.d.ts} +0 -0
  192. package/libs/ui/src/typography/{Title.d.ts → Title/index.d.ts} +0 -0
  193. package/libs-ui/react-core/src/Accordion/index.d.ts +1 -1
  194. package/libs-ui/react-core/src/AccordionControls/index.d.ts +1 -1
  195. package/libs-ui/react-core/src/AccordionSection/index.d.ts +1 -1
  196. package/libs-ui/react-core/src/AccordionSectionContent/index.d.ts +1 -1
  197. package/libs-ui/react-core/src/AccordionSectionHeader/index.d.ts +1 -1
  198. package/libs-ui/react-core/src/AccordionSectionSummary/index.d.ts +2 -1
  199. package/libs-ui/react-core/src/AccordionSectionSummaryHeading/index.d.ts +1 -1
  200. package/libs-ui/react-core/src/BackLink/index.d.ts +1 -1
  201. package/libs-ui/react-core/src/Blockquote/index.d.ts +1 -1
  202. package/libs-ui/react-core/src/Breadcrumbs/index.d.ts +1 -1
  203. package/libs-ui/react-core/src/BreadcrumbsList/index.d.ts +1 -1
  204. package/libs-ui/react-core/src/BreadcrumbsListItem/index.d.ts +1 -1
  205. package/libs-ui/react-core/src/Button/index.d.ts +1 -1
  206. package/libs-ui/react-core/src/ButtonGroup/index.d.ts +1 -1
  207. package/libs-ui/react-core/src/ButtonLink/index.d.ts +1 -1
  208. package/libs-ui/react-core/src/CallToAction/index.d.ts +1 -1
  209. package/libs-ui/react-core/src/Card/index.d.ts +1 -1
  210. package/libs-ui/react-core/src/CardAction/index.d.ts +1 -1
  211. package/libs-ui/react-core/src/CardHeading/index.d.ts +1 -1
  212. package/libs-ui/react-core/src/CardText/index.d.ts +1 -1
  213. package/libs-ui/react-core/src/Checkbox/index.d.ts +1 -1
  214. package/libs-ui/react-core/src/CheckboxItem/index.d.ts +1 -1
  215. package/libs-ui/react-core/src/Confirmation/index.d.ts +9 -0
  216. package/libs-ui/react-core/src/ConfirmationBody/index.d.ts +9 -0
  217. package/libs-ui/react-core/src/ConfirmationTitle/index.d.ts +9 -0
  218. package/libs-ui/react-core/src/DateInput/index.d.ts +1 -1
  219. package/libs-ui/react-core/src/DateInputItem/index.d.ts +1 -1
  220. package/libs-ui/react-core/src/Details/index.d.ts +1 -1
  221. package/libs-ui/react-core/src/DetailsContent/index.d.ts +1 -1
  222. package/libs-ui/react-core/src/DetailsSummary/index.d.ts +1 -1
  223. package/libs-ui/react-core/src/ErrorMessage/index.d.ts +1 -1
  224. package/libs-ui/react-core/src/ErrorSummary/index.d.ts +1 -1
  225. package/libs-ui/react-core/src/Field/index.d.ts +3 -3
  226. package/libs-ui/react-core/src/Fieldset/index.d.ts +1 -1
  227. package/libs-ui/react-core/src/FieldsetLegend/index.d.ts +1 -1
  228. package/libs-ui/react-core/src/FileUpload/index.d.ts +1 -1
  229. package/libs-ui/react-core/src/Form/index.d.ts +11 -0
  230. package/libs-ui/react-core/src/Grid/index.d.ts +20 -0
  231. package/libs-ui/react-core/src/Heading/index.d.ts +1 -1
  232. package/libs-ui/react-core/src/HeadingCaption/index.d.ts +1 -1
  233. package/libs-ui/react-core/src/Hidden/index.d.ts +1 -1
  234. package/libs-ui/react-core/src/Hint/index.d.ts +1 -1
  235. package/libs-ui/react-core/src/Label/index.d.ts +1 -1
  236. package/libs-ui/react-core/src/LabelTitle/index.d.ts +1 -1
  237. package/libs-ui/react-core/src/Link/index.d.ts +1 -1
  238. package/libs-ui/react-core/src/List/index.d.ts +1 -1
  239. package/libs-ui/react-core/src/ListItem/index.d.ts +1 -1
  240. package/libs-ui/react-core/src/NormalText/index.d.ts +1 -1
  241. package/libs-ui/react-core/src/NotificationBanner/index.d.ts +1 -1
  242. package/libs-ui/react-core/src/NotificationBannerContent/index.d.ts +1 -1
  243. package/libs-ui/react-core/src/NotificationBannerHeader/index.d.ts +1 -1
  244. package/libs-ui/react-core/src/NotificationBannerHeading/index.d.ts +1 -1
  245. package/libs-ui/react-core/src/NotificationBannerLink/index.d.ts +1 -1
  246. package/libs-ui/react-core/src/Paragraph/index.d.ts +1 -1
  247. package/libs-ui/react-core/src/PhaseBanner/index.d.ts +1 -1
  248. package/libs-ui/react-core/src/PhaseBannerHeaderContainer/index.d.ts +8 -0
  249. package/libs-ui/react-core/src/PhaseBannerTag/index.d.ts +1 -1
  250. package/libs-ui/react-core/src/PhaseBannerText/index.d.ts +1 -1
  251. package/libs-ui/react-core/src/Radio/index.d.ts +5 -1
  252. package/libs-ui/react-core/src/RadioItem/index.d.ts +1 -1
  253. package/libs-ui/react-core/src/SectionBreak/index.d.ts +1 -1
  254. package/libs-ui/react-core/src/Select/index.d.ts +1 -1
  255. package/libs-ui/react-core/src/SelectOption/index.d.ts +1 -1
  256. package/libs-ui/react-core/src/SummaryList/index.d.ts +7 -1
  257. package/libs-ui/react-core/src/SummaryListItem/index.d.ts +1 -1
  258. package/libs-ui/react-core/src/SummaryListItemAction/index.d.ts +1 -1
  259. package/libs-ui/react-core/src/SummaryListItemKey/index.d.ts +1 -1
  260. package/libs-ui/react-core/src/SummaryListItemValue/index.d.ts +1 -1
  261. package/libs-ui/react-core/src/SvgIcon/index.d.ts +1 -1
  262. package/libs-ui/react-core/src/Table/index.d.ts +1 -1
  263. package/libs-ui/react-core/src/TableBody/index.d.ts +1 -1
  264. package/libs-ui/react-core/src/TableCaption/index.d.ts +1 -1
  265. package/libs-ui/react-core/src/TableContainer/index.d.ts +1 -1
  266. package/libs-ui/react-core/src/TableDataCell/index.d.ts +1 -1
  267. package/libs-ui/react-core/src/TableHead/index.d.ts +1 -1
  268. package/libs-ui/react-core/src/TableHeadCell/index.d.ts +1 -1
  269. package/libs-ui/react-core/src/TableNoDataRow/index.d.ts +1 -1
  270. package/libs-ui/react-core/src/TableRow/index.d.ts +1 -1
  271. package/libs-ui/react-core/src/Tabs/index.d.ts +1 -1
  272. package/libs-ui/react-core/src/TabsHeading/index.d.ts +1 -1
  273. package/libs-ui/react-core/src/TabsList/index.d.ts +1 -1
  274. package/libs-ui/react-core/src/TabsListItem/index.d.ts +1 -1
  275. package/libs-ui/react-core/src/TabsPanel/index.d.ts +1 -1
  276. package/libs-ui/react-core/src/TextArea/index.d.ts +1 -1
  277. package/libs-ui/react-core/src/TextInput/index.d.ts +1 -1
  278. package/libs-ui/react-core/src/VisuallyHidden/index.d.ts +1 -1
  279. package/libs-ui/react-core/src/WarningText/index.d.ts +1 -1
  280. package/package.json +3 -4
  281. package/types.js +5 -0
  282. package/utils.js +6 -4
  283. package/validators/index.js +181 -0
  284. package/validators/types.js +5 -0
  285. package/validators/utils/afm.js +45 -0
  286. package/validators/utils/file.js +62 -0
  287. package/validators/utils/iban.js +134 -0
  288. package/validators/utils/index.js +210 -0
  289. package/validators/utils/phone.js +144 -0
  290. package/validators/utils/postal_code.js +40 -0
  291. package/validators/utils/uuid4.js +30 -0
  292. package/validators/validators.spec.js +88 -0
  293. package/es/validators.js +0 -626
  294. package/esm/validators.js +0 -626
  295. package/libs/form/src/Field/ConditionalField.d.ts +0 -17
  296. package/libs/form/src/validators.d.ts +0 -14
  297. package/validators.js +0 -662
  298. package/validators.spec.js +0 -88
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digigov/form",
3
- "version": "0.6.8",
3
+ "version": "0.7.0",
4
4
  "description": "@digigov form builder",
5
5
  "author": "GRNET Developers <devs@lists.grnet.gr>",
6
6
  "license": "BSD-2-Clause",
@@ -17,9 +17,8 @@
17
17
  "dayjs": "1.10.4"
18
18
  },
19
19
  "peerDependencies": {
20
- "@digigov/ui": "0.21.1",
21
- "@material-ui/core": "4.11.3",
22
- "@material-ui/icons": "4.11.2",
20
+ "@digigov/ui": "0.23.0",
21
+ "@digigov/react-core": "0.15.3",
23
22
  "clsx": "1.1.1",
24
23
  "react": "16.14.0",
25
24
  "react-dom": "16.14.0"
package/types.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
package/utils.js CHANGED
@@ -2,13 +2,13 @@
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
4
 
5
+ var _typeof = require("@babel/runtime/helpers/typeof");
6
+
5
7
  Object.defineProperty(exports, "__esModule", {
6
8
  value: true
7
9
  });
8
10
  exports.yupResolver = void 0;
9
11
 
10
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
-
12
12
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
13
13
 
14
14
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
@@ -17,6 +17,8 @@ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers
17
17
 
18
18
  var _extends3 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
19
19
 
20
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return generator._invoke = function (innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; }(innerFn, self, context), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; this._invoke = function (method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); }; } function maybeInvokeDelegate(delegate, context) { var method = delegate.iterator[context.method]; if (undefined === method) { if (context.delegate = null, "throw" === context.method) { if (delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel; context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method"); } return ContinueSentinel; } var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (object) { var keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
21
+
20
22
  /* eslint-disable @typescript-eslint/no-explicit-any */
21
23
  var parseErrorSchema = function parseErrorSchema(error, validateAllFieldCriteria) {
22
24
  return Array.isArray(error.inner) && error.inner.length ? error.inner.reduce(function (previous, _ref) {
@@ -42,11 +44,11 @@ var yupResolver = function yupResolver(schema) {
42
44
  abortEarly: false
43
45
  };
44
46
  return /*#__PURE__*/function () {
45
- var _ref4 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(values, context) {
47
+ var _ref4 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(values, context) {
46
48
  var validateAllFieldCriteria,
47
49
  parsedErrors,
48
50
  _args = arguments;
49
- return _regenerator["default"].wrap(function _callee$(_context) {
51
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
50
52
  while (1) {
51
53
  switch (_context.prev = _context.next) {
52
54
  case 0:
@@ -0,0 +1,181 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ var _typeof3 = require("@babel/runtime/helpers/typeof");
6
+
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ exports.getYUPTypeMap = void 0;
11
+ exports.useValidationSchema = useValidationSchema;
12
+
13
+ var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
14
+
15
+ var yup = _interopRequireWildcard(require("yup"));
16
+
17
+ var _react = require("react");
18
+
19
+ var _dayjs = _interopRequireDefault(require("dayjs"));
20
+
21
+ var _customParseFormat = _interopRequireDefault(require("dayjs/plugin/customParseFormat"));
22
+
23
+ var _utils = require("@digigov/form/validators/utils");
24
+
25
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
26
+
27
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof3(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
28
+
29
+ _dayjs["default"].extend(_customParseFormat["default"]);
30
+
31
+ var VALID_DATE_FORMATS = ['DD/MM/YYYY'];
32
+ var DATE_CACHE = {};
33
+
34
+ var getDate = function getDate(v) {
35
+ return DATE_CACHE[v] ? DATE_CACHE[v] : (0, _dayjs["default"])(v, VALID_DATE_FORMATS, true);
36
+ };
37
+
38
+ var getYUPTypeMap = function getYUPTypeMap() {
39
+ var yupTypeMap = {
40
+ file: function file(field) {
41
+ return yup.mixed().transform(function (value) {
42
+ if (!value.length) {
43
+ return null;
44
+ }
45
+
46
+ return value;
47
+ }).nullable().test((0, _utils.FILE_MAX_SIZE_VALIDATOR)(field));
48
+ },
49
+ string: yup.string,
50
+ text: yup.string,
51
+ "boolean": yup["boolean"],
52
+ object: function object(field) {
53
+ return (0, _utils.getYupObjectShape)(field.extra.fields, yupTypeMap);
54
+ },
55
+ array: function array(field) {
56
+ if ((0, _typeof2["default"])(field.extra.of) === 'object') {
57
+ // else if the field is an object then it is a scalar type
58
+ // eg. number, string etc.
59
+ return yup.array().of(yupTypeMap[field.extra.of.type](field.extra.of)); // .min(field.extra.min)
60
+ // .max(field.extra.max)
61
+ // .length(field.extra.length)
62
+ // .required(field.required);
63
+ } else if (typeof field.extra.of === 'string') {
64
+ return yup.array().of(yupTypeMap[field.extra.of]());
65
+ } else {
66
+ // in any other case it will be string
67
+ return yup.array().of(yup.string());
68
+ }
69
+ },
70
+ "int": function int() {
71
+ return yup.number().typeError('form.error.number').positive('form.error.positive_number');
72
+ },
73
+ email: function email() {
74
+ return yup.string().email('form.error.email');
75
+ },
76
+ afm: function afm() {
77
+ return yup.string().test(_utils.AFM_VALIDATOR);
78
+ },
79
+ uuid4: function uuid4() {
80
+ return yup.string().test(_utils.UUID4_VALIDATOR);
81
+ },
82
+ iban: function iban(field) {
83
+ return yup.string().test((0, _utils.IBAN_VALIDATOR)(field));
84
+ },
85
+ postal_code: function postal_code(field) {
86
+ return yup.string().test((0, _utils.POSTALCODE_VALIDATOR)(field));
87
+ },
88
+ mobile_phone: function mobile_phone() {
89
+ return yup.string().test(_utils.MOBILE_PHONE_VALIDATOR);
90
+ },
91
+ phone_number: function phone_number(field) {
92
+ return yup.string().test((0, _utils.PHONE_NUMBER_VALIDATOR)(field));
93
+ },
94
+ 'choice:multiple': function choiceMultiple() {
95
+ return yup.array().of(yup.string()).nullable();
96
+ },
97
+ 'choice:single': function choiceSingle() {
98
+ return yup.string().nullable();
99
+ },
100
+ date: function date(field) {
101
+ var simpleDate = yup.string().nullable(true).test('date', 'form.error.date.invalid', function (value) {
102
+ if (!value) return true;
103
+ value = getDate(value);
104
+ return value.isValid();
105
+ });
106
+ var params = field.extra || {};
107
+
108
+ if (params.max) {
109
+ var maxDate;
110
+
111
+ if (params.max === 'now') {
112
+ var today = new Date();
113
+ maxDate = new Date(today);
114
+ } else {
115
+ maxDate = getDate(params.max).toDate();
116
+ }
117
+
118
+ var maxNextDate = new Date(maxDate);
119
+ maxNextDate.setDate(maxDate.getDate() + 1);
120
+ simpleDate = simpleDate.test({
121
+ name: 'earlier-than',
122
+ message: {
123
+ key: 'form.error.date.earlier_than',
124
+ context: {
125
+ maxDate: maxNextDate.toLocaleDateString()
126
+ }
127
+ },
128
+ test: function test(value) {
129
+ if (!value) return true;
130
+ value = getDate(value);
131
+ var isValid = +value.toDate() < +maxDate;
132
+ return isValid;
133
+ }
134
+ });
135
+ }
136
+
137
+ if (params.min) {
138
+ var minDate;
139
+
140
+ if (params.min === 'now') {
141
+ var _today = new Date();
142
+
143
+ minDate = new Date(_today);
144
+ } else {
145
+ minDate = getDate(params.min).toDate();
146
+ }
147
+
148
+ var minPreviousDate = new Date(minDate);
149
+ minPreviousDate.setDate(minDate.getDate() - 1);
150
+ simpleDate = simpleDate.test({
151
+ name: 'later-than',
152
+ message: {
153
+ key: 'form.error.date.later_than',
154
+ context: {
155
+ minDate: minPreviousDate.toLocaleDateString()
156
+ }
157
+ },
158
+ test: function test(value) {
159
+ if (!value) return true;
160
+ value = getDate(value);
161
+ var isValid = +value.toDate() > +minDate;
162
+ return isValid;
163
+ }
164
+ });
165
+ }
166
+
167
+ return simpleDate;
168
+ }
169
+ };
170
+ return yupTypeMap;
171
+ };
172
+
173
+ exports.getYUPTypeMap = getYUPTypeMap;
174
+
175
+ // Create a yup validation schema from given fields input
176
+ function useValidationSchema(fields, validatorRegistry) {
177
+ return (0, _react.useMemo)(function () {
178
+ var yupTypeMap = getYUPTypeMap();
179
+ return (0, _utils.getYupObjectShape)(fields, yupTypeMap, validatorRegistry);
180
+ }, []);
181
+ }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.AFM_VALIDATOR = void 0;
7
+ exports.validateAFM = validateAFM;
8
+
9
+ function validateAFM(afm) {
10
+ if (afm.length !== 9) {
11
+ // "afm should be 9 digits"
12
+ return false;
13
+ }
14
+
15
+ if (!/^\d+$/.test(afm)) {
16
+ // "This is not a number"
17
+ return false;
18
+ }
19
+
20
+ if (afm === '0'.repeat(9)) {
21
+ // "This is zero number (000000000)"
22
+ return false;
23
+ }
24
+
25
+ var sum = afm.substring(0, 8).split('').reduce(function (s, v, i) {
26
+ return s + (parseInt(v) << 8 - i);
27
+ }, 0);
28
+ var calc = sum % 11;
29
+ var d9 = parseInt(afm[8]);
30
+ var valid = calc % 10 === d9;
31
+ return valid;
32
+ }
33
+
34
+ var AFM_VALIDATOR = {
35
+ name: 'afm-validator',
36
+ message: 'form.error.afm',
37
+ test: function test(value) {
38
+ if (value) {
39
+ return validateAFM(value);
40
+ }
41
+
42
+ return true;
43
+ }
44
+ };
45
+ exports.AFM_VALIDATOR = AFM_VALIDATOR;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.FILE_MAX_SIZE_VALIDATOR = void 0;
7
+
8
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
9
+
10
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
11
+
12
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
13
+
14
+ var DEFAULT_FILE_MAX_SIZE = 10000000;
15
+
16
+ var FILE_MAX_SIZE_VALIDATOR = function FILE_MAX_SIZE_VALIDATOR(field) {
17
+ return {
18
+ name: 'file-max-size-validator',
19
+ message: 'form.error.file_size',
20
+ test: function test(value) {
21
+ if (field.extra && field.extra.maxSize && value) {
22
+ var _iterator = _createForOfIteratorHelper(value),
23
+ _step;
24
+
25
+ try {
26
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
27
+ var file = _step.value;
28
+
29
+ if (file.size >= field.extra.maxSize) {
30
+ return false;
31
+ }
32
+ }
33
+ } catch (err) {
34
+ _iterator.e(err);
35
+ } finally {
36
+ _iterator.f();
37
+ }
38
+ } else if (value) {
39
+ var _iterator2 = _createForOfIteratorHelper(value),
40
+ _step2;
41
+
42
+ try {
43
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
44
+ var _file = _step2.value;
45
+
46
+ if (_file.size >= DEFAULT_FILE_MAX_SIZE) {
47
+ return false;
48
+ }
49
+ }
50
+ } catch (err) {
51
+ _iterator2.e(err);
52
+ } finally {
53
+ _iterator2.f();
54
+ }
55
+ }
56
+
57
+ return true;
58
+ }
59
+ };
60
+ };
61
+
62
+ exports.FILE_MAX_SIZE_VALIDATOR = FILE_MAX_SIZE_VALIDATOR;
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.IBAN_VALIDATOR = void 0;
7
+ exports.validateIban = validateIban;
8
+
9
+ function validateIban(value, countryCode) {
10
+ value = value.replace(/\s/g, '').replace(/-/g, '');
11
+
12
+ if (value.match(/^[0-9]*$/i)) {
13
+ // this is for greek iban without the country code
14
+ if (value.length !== 25) {
15
+ return false;
16
+ }
17
+ } else {
18
+ value = value.toUpperCase();
19
+
20
+ if (countryCode) {
21
+ if (!value.startsWith(countryCode.toUpperCase())) {
22
+ return false;
23
+ }
24
+
25
+ if (value.length === ibanCountryCodesLengths[countryCode.toUpperCase()]) {
26
+ return true;
27
+ }
28
+ }
29
+
30
+ if (value.length !== 27) {
31
+ // this is for greek iban
32
+ return false;
33
+ }
34
+ }
35
+
36
+ return true;
37
+ }
38
+
39
+ var IBAN_VALIDATOR = function IBAN_VALIDATOR(field) {
40
+ var _field$extra;
41
+
42
+ var countryCode = field === null || field === void 0 ? void 0 : (_field$extra = field.extra) === null || _field$extra === void 0 ? void 0 : _field$extra.country;
43
+ return {
44
+ name: 'iban-validator',
45
+ message: 'form.error.iban',
46
+ test: function test(value) {
47
+ if (!value) {
48
+ return true;
49
+ }
50
+
51
+ return validateIban(value, countryCode);
52
+ }
53
+ };
54
+ };
55
+
56
+ exports.IBAN_VALIDATOR = IBAN_VALIDATOR;
57
+ var ibanCountryCodesLengths = {
58
+ AD: 24,
59
+ AT: 20,
60
+ AZ: 28,
61
+ BH: 22,
62
+ BY: 28,
63
+ BE: 16,
64
+ BA: 20,
65
+ BR: 29,
66
+ BG: 22,
67
+ CR: 22,
68
+ HR: 21,
69
+ CY: 28,
70
+ CZ: 24,
71
+ DK: 18,
72
+ DO: 28,
73
+ EG: 29,
74
+ SV: 28,
75
+ EE: 20,
76
+ FO: 18,
77
+ FI: 18,
78
+ FR: 27,
79
+ GE: 22,
80
+ DE: 22,
81
+ GI: 23,
82
+ GR: 27,
83
+ GL: 18,
84
+ GT: 28,
85
+ VA: 22,
86
+ HU: 28,
87
+ IS: 26,
88
+ IQ: 23,
89
+ IE: 22,
90
+ IL: 23,
91
+ IT: 27,
92
+ JO: 30,
93
+ KZ: 20,
94
+ XK: 20,
95
+ KW: 30,
96
+ LV: 21,
97
+ LB: 28,
98
+ LI: 21,
99
+ LT: 20,
100
+ LU: 20,
101
+ MT: 31,
102
+ MR: 27,
103
+ MU: 30,
104
+ MD: 24,
105
+ MC: 27,
106
+ ME: 22,
107
+ NL: 18,
108
+ MK: 19,
109
+ NO: 15,
110
+ PK: 24,
111
+ PS: 29,
112
+ PL: 28,
113
+ PT: 25,
114
+ QA: 29,
115
+ RO: 24,
116
+ LC: 32,
117
+ SM: 27,
118
+ ST: 25,
119
+ SA: 24,
120
+ RS: 22,
121
+ SC: 31,
122
+ SK: 24,
123
+ SI: 19,
124
+ ES: 24,
125
+ SE: 24,
126
+ CH: 21,
127
+ TL: 23,
128
+ TN: 24,
129
+ TR: 26,
130
+ UA: 29,
131
+ AE: 23,
132
+ GB: 22,
133
+ VG: 24
134
+ };