x25 2.9.2 → 3.0.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 (274) hide show
  1. package/.eslintignore +2 -0
  2. package/.eslintrc.json +275 -0
  3. package/.flowconfig +23 -0
  4. package/conf/dev.js +19 -0
  5. package/conf/dist.js +19 -0
  6. package/conf/polyfills/tempPolyfills.js +7 -0
  7. package/package.json +16 -16
  8. package/src/Account/Load.jsx +79 -0
  9. package/src/Account/actions.js +10 -0
  10. package/src/Account/index.js +11 -0
  11. package/src/Account/reducer.js +139 -0
  12. package/src/Account/request.js +36 -0
  13. package/src/Async/InitModule.jsx +114 -0
  14. package/src/Async/RouteLoading.jsx +52 -0
  15. package/src/Async/SimulatedException.jsx +19 -0
  16. package/src/Async/index.jsx +75 -0
  17. package/src/Async/types.js +39 -0
  18. package/src/Company/Load.jsx +84 -0
  19. package/src/Company/actions.js +10 -0
  20. package/src/Company/index.js +11 -0
  21. package/src/Company/reducer.js +201 -0
  22. package/src/Company/request.js +30 -0
  23. package/src/Company/util.js +7 -0
  24. package/src/Header/AccountOptionsContainer.jsx +124 -0
  25. package/src/Header/AdminSelectCompany.jsx +101 -0
  26. package/src/Header/ClientSelectCompany.jsx +90 -0
  27. package/src/Header/Header.jsx +120 -0
  28. package/src/Header/HeaderContainer.jsx +30 -0
  29. package/src/Header/Logo.jsx +16 -0
  30. package/src/Header/LogoutButton.jsx +34 -0
  31. package/src/Header/index.jsx +9 -0
  32. package/src/Header/request.js +28 -0
  33. package/src/Header/types.js +6 -0
  34. package/src/Header/util.jsx +61 -0
  35. package/src/Inputs/Business/BankAccount.jsx +39 -0
  36. package/src/Inputs/Business/BankName.jsx +40 -0
  37. package/src/Inputs/Business/CifField.jsx +93 -0
  38. package/src/Inputs/Business/CifFieldContainer.jsx +142 -0
  39. package/src/Inputs/Business/Email.jsx +23 -0
  40. package/src/Inputs/Business/NidField.jsx +77 -0
  41. package/src/Inputs/Business/Phone.jsx +23 -0
  42. package/src/Inputs/Business/index.js +16 -0
  43. package/src/Inputs/Business/request.js +39 -0
  44. package/src/Inputs/CaptchaBox.jsx +131 -0
  45. package/src/Inputs/DateInput.jsx +188 -0
  46. package/src/Inputs/DateTemplate.jsx +213 -0
  47. package/src/Inputs/DelayInputChange.jsx +130 -0
  48. package/src/Inputs/FocusTemplate.jsx +41 -0
  49. package/src/Inputs/InputTemplate.jsx +79 -0
  50. package/src/Inputs/LabelTemplate.jsx +47 -0
  51. package/src/Inputs/NumericInput.jsx +142 -0
  52. package/src/Inputs/NumericTemplate.jsx +155 -0
  53. package/src/Inputs/Selects/County.jsx +19 -0
  54. package/src/Inputs/Selects/Custom.jsx +55 -0
  55. package/src/Inputs/Selects/Simple.jsx +73 -0
  56. package/src/Inputs/Selects/index.jsx +37 -0
  57. package/src/Inputs/SimpleInput.jsx +40 -0
  58. package/src/Inputs/SimpleTextarea.jsx +55 -0
  59. package/src/Inputs/TextareaTemplate.jsx +57 -0
  60. package/src/Inputs/Tooltip.jsx +61 -0
  61. package/src/Inputs/index.js +22 -0
  62. package/src/Messages/Error.jsx +83 -0
  63. package/src/Messages/Loading.jsx +43 -0
  64. package/src/Messages/index.jsx +4 -0
  65. package/src/Modal/Delete.jsx +237 -0
  66. package/src/Modal/Root.jsx +57 -0
  67. package/src/Modal/SimpleModal.jsx +47 -0
  68. package/src/Modal/actions.js +7 -0
  69. package/src/Modal/getComponent.jsx +32 -0
  70. package/src/Modal/index.jsx +12 -0
  71. package/src/Modal/reducer.js +40 -0
  72. package/src/Modal/types.js +6 -0
  73. package/src/Modal/util.js +15 -0
  74. package/src/Payment/EstimatePrice/Description.jsx +101 -0
  75. package/src/Payment/EstimatePrice/PayBox.jsx +173 -0
  76. package/src/Payment/EstimatePrice/index.jsx +63 -0
  77. package/src/Payment/EstimatePrice/util.js +15 -0
  78. package/src/Payment/MobilpayForm.jsx +77 -0
  79. package/src/Payment/Modal/BankTransfer.jsx +129 -0
  80. package/src/Payment/Modal/CompanyValability.jsx +14 -0
  81. package/src/Payment/Modal/DoneForm.jsx +209 -0
  82. package/src/Payment/Modal/PaymentDone.jsx +27 -0
  83. package/src/Payment/Modal/index.js +13 -0
  84. package/src/Payment/actions.jsx +22 -0
  85. package/{Payment → src/Payment}/codes.js +16 -19
  86. package/src/Payment/index.jsx +124 -0
  87. package/src/Payment/request.js +50 -0
  88. package/src/Payment/types.js +14 -0
  89. package/src/Payment/util.jsx +52 -0
  90. package/src/Payment/validate.js +25 -0
  91. package/src/Sidebar.jsx +158 -0
  92. package/src/Things.jsx +35 -0
  93. package/src/actions.js +36 -0
  94. package/src/config.js +7 -0
  95. package/src/dev/ErrorBoundary.jsx +98 -0
  96. package/src/dev/TheError.jsx +87 -0
  97. package/src/dev/index.js +127 -0
  98. package/src/dev/types.js +10 -0
  99. package/src/prod/SentryErrorBoundary.jsx +98 -0
  100. package/src/reducer/captchas.js +44 -0
  101. package/src/reducer/counties.js +46 -0
  102. package/src/reducer/index.js +25 -0
  103. package/src/reducer/module.jsx +43 -0
  104. package/src/style/.sass-lint.yml +84 -0
  105. package/src/style/.stylelintrc.json +161 -0
  106. package/src/style/_fancy-text.scss +37 -0
  107. package/src/style/_fix_bootstrap_placeholder_color.scss +14 -0
  108. package/src/style/_header-company.scss +69 -0
  109. package/src/style/_inputs.scss +12 -0
  110. package/src/style/_minimal.scss +31 -0
  111. package/src/style/_navigation.scss +24 -0
  112. package/src/style/_others.scss +79 -0
  113. package/src/style/index.scss +7 -0
  114. package/src/style/sidebar/_animations.scss +21 -0
  115. package/src/style/sidebar/_dark-theme.scss +77 -0
  116. package/src/style/sidebar/_scroll.scss +37 -0
  117. package/src/style/sidebar/_structure.scss +299 -0
  118. package/src/style/sidebar.scss +4 -0
  119. package/src/types.js +31 -0
  120. package/src/utility/calendar.js +39 -0
  121. package/src/utility/date.js +100 -0
  122. package/src/utility/index.js +12 -0
  123. package/src/utility/language.js +17 -0
  124. package/src/utility/mql.js +3 -0
  125. package/src/utility/normalize-test.js +58 -0
  126. package/src/utility/normalize.js +119 -0
  127. package/src/utility/numbers.js +87 -0
  128. package/src/utility/numeric.js +114 -0
  129. package/src/utility/others.jsx +160 -0
  130. package/src/utility/strings-test.js +136 -0
  131. package/src/utility/strings.js +80 -0
  132. package/src/utility/validation/common.js +360 -0
  133. package/src/utility/validation/index.js +70 -0
  134. package/src/utility/validation/specific.js +9 -0
  135. package/src/utility/validation/validate/bank-test.js +129 -0
  136. package/src/utility/validation/validate/bank.js +176 -0
  137. package/src/utility/validation/validate/cif-test.js +105 -0
  138. package/src/utility/validation/validate/cif.js +44 -0
  139. package/src/utility/validation/validate/cnp-test.js +216 -0
  140. package/src/utility/validation/validate/cnp.js +261 -0
  141. package/{utility → src/utility}/validation/validate/date.js +73 -61
  142. package/src/utility/validation/validate/email-test.js +36 -0
  143. package/src/utility/validation/validate/email.js +6 -0
  144. package/src/utility/validation/validate/index.js +7 -0
  145. package/webpack.config.js +90 -0
  146. package/x25.wiki/Account.md +41 -0
  147. package/x25.wiki/Company.md +39 -0
  148. package/x25.wiki/Header.md +21 -0
  149. package/x25.wiki/Home.md +1 -0
  150. package/x25.wiki/Inputs.md +33 -0
  151. package/x25.wiki/Messages.md +27 -0
  152. package/x25.wiki/Payment.md +42 -0
  153. package/Account/Load.js +0 -75
  154. package/Account/actions.js +0 -15
  155. package/Account/index.js +0 -20
  156. package/Account/reducer.js +0 -122
  157. package/Account/request.js +0 -44
  158. package/Async/InitModule.js +0 -190
  159. package/Async/RouteLoading.js +0 -64
  160. package/Async/SimulatedException.js +0 -44
  161. package/Async/index.js +0 -95
  162. package/Async/types.js +0 -1
  163. package/Company/Load.js +0 -82
  164. package/Company/actions.js +0 -15
  165. package/Company/index.js +0 -20
  166. package/Company/reducer.js +0 -165
  167. package/Company/request.js +0 -36
  168. package/Company/util.js +0 -10
  169. package/Header/AccountOptionsContainer.js +0 -144
  170. package/Header/AdminSelectCompany.js +0 -109
  171. package/Header/ClientSelectCompany.js +0 -104
  172. package/Header/Header.js +0 -127
  173. package/Header/HeaderContainer.js +0 -39
  174. package/Header/Logo.js +0 -30
  175. package/Header/LogoutButton.js +0 -39
  176. package/Header/index.js +0 -19
  177. package/Header/request.js +0 -26
  178. package/Header/types.js +0 -1
  179. package/Header/util.js +0 -58
  180. package/Inputs/Business/BankAccount.js +0 -48
  181. package/Inputs/Business/BankName.js +0 -49
  182. package/Inputs/Business/CifField.js +0 -112
  183. package/Inputs/Business/CifFieldContainer.js +0 -157
  184. package/Inputs/Business/Email.js +0 -37
  185. package/Inputs/Business/NidField.js +0 -91
  186. package/Inputs/Business/Phone.js +0 -37
  187. package/Inputs/Business/index.js +0 -34
  188. package/Inputs/Business/request.js +0 -39
  189. package/Inputs/CaptchaBox.js +0 -151
  190. package/Inputs/DateInput.js +0 -172
  191. package/Inputs/DateTemplate.js +0 -200
  192. package/Inputs/DelayInputChange.js +0 -135
  193. package/Inputs/FocusTemplate.js +0 -47
  194. package/Inputs/InputTemplate.js +0 -78
  195. package/Inputs/LabelTemplate.js +0 -59
  196. package/Inputs/NumericInput.js +0 -139
  197. package/Inputs/NumericTemplate.js +0 -148
  198. package/Inputs/Selects/County.js +0 -29
  199. package/Inputs/Selects/Custom.js +0 -56
  200. package/Inputs/Selects/Simple.js +0 -75
  201. package/Inputs/Selects/index.js +0 -52
  202. package/Inputs/SimpleInput.js +0 -42
  203. package/Inputs/SimpleTextarea.js +0 -47
  204. package/Inputs/TextareaTemplate.js +0 -55
  205. package/Inputs/Tooltip.js +0 -82
  206. package/Inputs/index.js +0 -185
  207. package/Messages/Error.js +0 -106
  208. package/Messages/Loading.js +0 -68
  209. package/Messages/index.js +0 -29
  210. package/Modal/Delete.js +0 -240
  211. package/Modal/Root.js +0 -81
  212. package/Modal/SimpleModal.js +0 -57
  213. package/Modal/actions.js +0 -10
  214. package/Modal/getComponent.js +0 -42
  215. package/Modal/index.js +0 -22
  216. package/Modal/reducer.js +0 -53
  217. package/Modal/types.js +0 -7
  218. package/Modal/util.js +0 -17
  219. package/Payment/EstimatePrice/Description.js +0 -92
  220. package/Payment/EstimatePrice/PayBox.js +0 -220
  221. package/Payment/EstimatePrice/index.js +0 -92
  222. package/Payment/EstimatePrice/util.js +0 -21
  223. package/Payment/MobilpayForm.js +0 -86
  224. package/Payment/Modal/BankTransfer.js +0 -233
  225. package/Payment/Modal/CompanyValability.js +0 -28
  226. package/Payment/Modal/DoneForm.js +0 -222
  227. package/Payment/Modal/PaymentDone.js +0 -53
  228. package/Payment/Modal/index.js +0 -27
  229. package/Payment/actions.js +0 -23
  230. package/Payment/index.js +0 -141
  231. package/Payment/request.js +0 -49
  232. package/Payment/types.js +0 -1
  233. package/Payment/util.js +0 -50
  234. package/Payment/validate.js +0 -23
  235. package/Sidebar.js +0 -156
  236. package/Things.js +0 -53
  237. package/actions.js +0 -73
  238. package/config.js +0 -10
  239. package/dev/ErrorBoundary.js +0 -109
  240. package/dev/TheError.js +0 -113
  241. package/dev/index.js +0 -132
  242. package/dev/types.js +0 -1
  243. package/prod/SentryErrorBoundary.js +0 -150
  244. package/reducer/captchas.js +0 -51
  245. package/reducer/counties.js +0 -57
  246. package/reducer/index.js +0 -38
  247. package/reducer/module.js +0 -48
  248. package/style/index.css +0 -1
  249. package/style/sidebar.css +0 -1
  250. package/types.js +0 -1
  251. package/utility/calendar.js +0 -45
  252. package/utility/date.js +0 -111
  253. package/utility/index.js +0 -125
  254. package/utility/language.js +0 -20
  255. package/utility/mql.js +0 -6
  256. package/utility/normalize-test.js +0 -54
  257. package/utility/normalize.js +0 -108
  258. package/utility/numbers.js +0 -93
  259. package/utility/numeric.js +0 -103
  260. package/utility/others.js +0 -142
  261. package/utility/strings-test.js +0 -216
  262. package/utility/strings.js +0 -85
  263. package/utility/validation/common.js +0 -278
  264. package/utility/validation/index.js +0 -110
  265. package/utility/validation/specific.js +0 -14
  266. package/utility/validation/validate/bank-test.js +0 -41
  267. package/utility/validation/validate/bank.js +0 -176
  268. package/utility/validation/validate/cif-test.js +0 -37
  269. package/utility/validation/validate/cif.js +0 -44
  270. package/utility/validation/validate/cnp-test.js +0 -68
  271. package/utility/validation/validate/cnp.js +0 -193
  272. package/utility/validation/validate/email-test.js +0 -30
  273. package/utility/validation/validate/email.js +0 -11
  274. package/utility/validation/validate/index.js +0 -65
@@ -0,0 +1,176 @@
1
+ // @flow
2
+
3
+ export const isValidBankAccount = (rawValue : string) : boolean => {
4
+
5
+ // Remove spaces and to upper case
6
+ const checkPosition = 4,
7
+ iban = rawValue.replace(/ /gu,
8
+ "").toUpperCase(),
9
+ hasGoodCountryCode = () : boolean => {
10
+
11
+ if (iban.length <= 2) {
12
+ return false;
13
+ }
14
+
15
+ const countrycode = iban.substring(0,
16
+ 2),
17
+ bbancountrypatterns = {
18
+ "AD" : "\\d{8}[\\dA-Z]{12}",
19
+ "AE" : "\\d{3}\\d{16}",
20
+ "AL" : "\\d{8}[\\dA-Z]{16}",
21
+ "AT" : "\\d{16}",
22
+ "AZ" : "[\\dA-Z]{4}\\d{20}",
23
+ "BA" : "\\d{16}",
24
+ "BE" : "\\d{12}",
25
+ "BG" : "[A-Z]{4}\\d{6}[\\dA-Z]{8}",
26
+ "BH" : "[A-Z]{4}[\\dA-Z]{14}",
27
+ "BR" : "\\d{23}[A-Z][\\dA-Z]",
28
+ "CH" : "\\d{5}[\\dA-Z]{12}",
29
+ "CR" : "\\d{17}",
30
+ "CY" : "\\d{8}[\\dA-Z]{16}",
31
+ "CZ" : "\\d{20}",
32
+ "DE" : "\\d{18}",
33
+ "DK" : "\\d{14}",
34
+ "DO" : "[A-Z]{4}\\d{20}",
35
+ "EE" : "\\d{16}",
36
+ "ES" : "\\d{20}",
37
+ "FI" : "\\d{14}",
38
+ "FO" : "\\d{14}",
39
+ "FR" : "\\d{10}[\\dA-Z]{11}\\d{2}",
40
+ "GB" : "[A-Z]{4}\\d{14}",
41
+ "GE" : "[\\dA-Z]{2}\\d{16}",
42
+ "GI" : "[A-Z]{4}[\\dA-Z]{15}",
43
+ "GL" : "\\d{14}",
44
+ "GR" : "\\d{7}[\\dA-Z]{16}",
45
+ "GT" : "[\\dA-Z]{4}[\\dA-Z]{20}",
46
+ "HR" : "\\d{17}",
47
+ "HU" : "\\d{24}",
48
+ "IE" : "[\\dA-Z]{4}\\d{14}",
49
+ "IL" : "\\d{19}",
50
+ "IS" : "\\d{22}",
51
+ "IT" : "[A-Z]\\d{10}[\\dA-Z]{12}",
52
+ "KW" : "[A-Z]{4}[\\dA-Z]{22}",
53
+ "KZ" : "\\d{3}[\\dA-Z]{13}",
54
+ "LB" : "\\d{4}[\\dA-Z]{20}",
55
+ "LI" : "\\d{5}[\\dA-Z]{12}",
56
+ "LT" : "\\d{16}",
57
+ "LU" : "\\d{3}[\\dA-Z]{13}",
58
+ "LV" : "[A-Z]{4}[\\dA-Z]{13}",
59
+ "MC" : "\\d{10}[\\dA-Z]{11}\\d{2}",
60
+ "MD" : "[\\dA-Z]{2}\\d{18}",
61
+ "ME" : "\\d{18}",
62
+ "MK" : "\\d{3}[\\dA-Z]{10}\\d{2}",
63
+ "MR" : "\\d{23}",
64
+ "MT" : "[A-Z]{4}\\d{5}[\\dA-Z]{18}",
65
+ "MU" : "[A-Z]{4}\\d{19}[A-Z]{3}",
66
+ "NL" : "[A-Z]{4}\\d{10}",
67
+ "NO" : "\\d{11}",
68
+ "PK" : "[\\dA-Z]{4}\\d{16}",
69
+ "PL" : "\\d{24}",
70
+ "PS" : "[\\dA-Z]{4}\\d{21}",
71
+ "PT" : "\\d{21}",
72
+ "RO" : "[A-Z]{4}[\\dA-Z]{16}",
73
+ "RS" : "\\d{18}",
74
+ "SA" : "\\d{2}[\\dA-Z]{18}",
75
+ "SE" : "\\d{20}",
76
+ "SI" : "\\d{15}",
77
+ "SK" : "\\d{20}",
78
+ "SM" : "[A-Z]\\d{10}[\\dA-Z]{12}",
79
+ "TN" : "\\d{20}",
80
+ "TR" : "\\d{5}[\\dA-Z]{17}",
81
+ "VG" : "[\\dA-Z]{4}\\d{16}",
82
+ },
83
+ bbanpattern = bbancountrypatterns[countrycode];
84
+
85
+ /*
86
+ * As new countries will start using IBAN in the
87
+ * future, we only check if the countrycode is known.
88
+ * This prevents false negatives, while almost all
89
+ * false positives introduced by this, will be caught
90
+ * by the checksum validation below anyway.
91
+ * Strict checking should return FALSE for unknown
92
+ * countries.
93
+ */
94
+ if (typeof bbanpattern === "undefined") {
95
+ return false;
96
+ }
97
+
98
+ const ibanregexp = new RegExp(`^[A-Z]{2}\\d{2}${bbanpattern}$`,
99
+ "u");
100
+
101
+ // Invalid country specific format
102
+ return ibanregexp.test(iban);
103
+ },
104
+ hasGoodRest = () : boolean => {
105
+ const getCheckDigits = () => {
106
+
107
+ const getCheck = () : string => {
108
+ const first = String(iban.substring(checkPosition,
109
+ iban.length)),
110
+ second = String(iban.substring(0,
111
+ checkPosition));
112
+
113
+ return first + second;
114
+ },
115
+ ibancheck = getCheck();
116
+
117
+
118
+ let leadingZeroes = true,
119
+ value = "";
120
+
121
+ for (let index = 0; index < ibancheck.length; index += 1) {
122
+ const character = ibancheck.charAt(index);
123
+
124
+ if (character !== "0") {
125
+ leadingZeroes = false;
126
+ }
127
+
128
+ if (!leadingZeroes) {
129
+ value += "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".indexOf(character);
130
+ }
131
+ }
132
+
133
+ return value;
134
+ },
135
+ ibancheckdigits = getCheckDigits(),
136
+ nrToDevide = 97,
137
+ getOperator = ({ cRest, cChar } : { cRest: number, cChar : string}) => {
138
+ const rest = (cRest === 0) ? "" : String(cRest);
139
+
140
+ return Number(`${rest}${cChar}`);
141
+ };
142
+
143
+ let currentRest = 0;
144
+
145
+ for (let index = 0; index < ibancheckdigits.length; index += 1) {
146
+ const cChar = ibancheckdigits.charAt(index),
147
+ cOperator = getOperator({
148
+ cRest: currentRest,
149
+ cChar,
150
+ });
151
+
152
+ if (cOperator === "" || isNaN(cOperator)) {
153
+ return false;
154
+ }
155
+
156
+ currentRest = cOperator % nrToDevide;
157
+ }
158
+
159
+ return currentRest === 1;
160
+ };
161
+
162
+ // 1. Check the country code and find the country specific format
163
+
164
+ if (!hasGoodCountryCode()) {
165
+
166
+ return false;
167
+ }
168
+
169
+ // 2. Check the checksum{
170
+ if (!hasGoodRest()) {
171
+
172
+ return false;
173
+ }
174
+
175
+ return true;
176
+ };
@@ -0,0 +1,105 @@
1
+ import { isValidCIF } from "./cif";
2
+
3
+ const valid = true,
4
+ notValid = false;
5
+
6
+ const wrong = [
7
+
8
+ "adsasd",
9
+
10
+ // too short < 6
11
+ "00",
12
+
13
+ // too long > 10
14
+ "00000000001",
15
+
16
+ // contains other things
17
+ "aaaaaaaaaa",
18
+
19
+ "1450123",
20
+
21
+ "13880060",
22
+ "13880061",
23
+ "13880062",
24
+ // "51584214", // <-- this is good
25
+ "13880064",
26
+ "13880065",
27
+ "13880066",
28
+ "13880067",
29
+ "13880068",
30
+ "13880069",
31
+ ];
32
+
33
+ wrong.map((cif) => (
34
+ describe(`given the wrong CIF ${cif}`,
35
+ () => {
36
+ it("should not be valid",
37
+ () => {
38
+ expect(isValidCIF(cif)).toBe(notValid);
39
+ });
40
+ })
41
+ ));
42
+
43
+ const good = [
44
+
45
+ "4446651",
46
+ "3678190",
47
+ "4352719",
48
+ "3627676",
49
+ "7525881",
50
+ "4347666",
51
+ "3372840",
52
+ "5217524",
53
+ "4317819",
54
+ "4192600",
55
+ "4266928",
56
+ "4233815",
57
+ "4288004",
58
+ "4300787",
59
+ "4300574",
60
+ "4332134",
61
+ "3519380",
62
+ "4375178",
63
+ "4297924",
64
+ "3127336",
65
+ "11078781",
66
+ "3897033",
67
+ "4541874",
68
+ "4605609",
69
+ "4245518",
70
+ "4358002",
71
+ "4230436",
72
+ "4266898",
73
+ "2613486",
74
+ "4318113",
75
+ "2844154",
76
+ "4222310",
77
+ "2540830",
78
+ "4287378",
79
+ "3897343",
80
+ "4540062",
81
+ "5397247",
82
+ "4556140",
83
+ "4231881",
84
+ "4244393",
85
+ "4280213",
86
+ "4323179",
87
+ "4567890",
88
+ "6412248",
89
+ "4269304",
90
+ "4321658",
91
+ "4494721",
92
+ "4404613",
93
+
94
+ "51584214",
95
+ ];
96
+
97
+ good.map((cif) => (
98
+ describe(`given the good CIF ${cif}`,
99
+ () => {
100
+ it("should be valid",
101
+ () => {
102
+ expect(isValidCIF(cif)).toBe(valid);
103
+ });
104
+ })
105
+ ));
@@ -0,0 +1,44 @@
1
+ // @flow
2
+
3
+ export const isValidCIF = (rawValue : string) : boolean => {
4
+ const len = rawValue.length,
5
+ value = Number(rawValue),
6
+ ten = 10,
7
+ eleven = 11,
8
+ controlDigit1 = value % ten,
9
+ upperLimit = 10,
10
+ lowerLimit = 4,
11
+ getControlDigit2 = () : number => {
12
+ let controlNumber = 753217532,
13
+ controlDigit2 = 0,
14
+ current = parseInt(value / ten,
15
+ ten),
16
+ accumulator = 0;
17
+
18
+ while (current > 0) {
19
+ const controlDigit = (controlNumber % ten);
20
+
21
+ accumulator += (current % ten) * controlDigit;
22
+
23
+ current = parseInt(current / ten,
24
+ ten);
25
+ controlNumber = parseInt(controlNumber / ten,
26
+ ten);
27
+ }
28
+
29
+ controlDigit2 = accumulator * ten % eleven;
30
+
31
+ if (controlDigit2 === ten) {
32
+ controlDigit2 = 0;
33
+ }
34
+
35
+ return controlDigit2;
36
+ };
37
+
38
+ if (isNaN(value) || len > upperLimit || len < lowerLimit) {
39
+ // console.warn("The length must be between 6 and 10 digits");
40
+ return false;
41
+ }
42
+
43
+ return controlDigit1 === getControlDigit2();
44
+ };
@@ -0,0 +1,216 @@
1
+ import { isValidCNP } from "./cnp";
2
+
3
+ const valid = true,
4
+ notValid = false;
5
+
6
+ const wrongCNPs = [
7
+
8
+ // less than 13 characters
9
+ "000",
10
+
11
+ // more than 13 characters
12
+ "00000000000000",
13
+
14
+ // not all digits
15
+ " ",
16
+ "a234567890123",
17
+ "1x34567890123",
18
+ "12y4567890123",
19
+ "123(567890123",
20
+ "1234*67890123",
21
+ "12345-7890123",
22
+ "123456+890123",
23
+ "1234567`90123",
24
+ "12345678!0123",
25
+ "123456789@123",
26
+ "12345678901&3",
27
+ "123456789012=",
28
+
29
+ // Digit 1 not 0
30
+ "0000000000000",
31
+
32
+ /*
33
+ * Wrong month
34
+ * Too small
35
+ */
36
+ "1230000000000",
37
+ // Too big
38
+ "1231300000000",
39
+ "1234500000000",
40
+ "1239900000000",
41
+
42
+ // Wrong date
43
+ "1000100000000",
44
+ "1000100000000",
45
+ "1231200000000",
46
+ "3431250000000",
47
+ "8430100000000",
48
+ "6431132000000",
49
+ "5160230000000",
50
+
51
+ /*
52
+ * Wrong County
53
+ * 0
54
+ */
55
+ "1930426000000",
56
+
57
+ // Too big
58
+ "1930426530000",
59
+ "1930426990000",
60
+
61
+ // Number - allowed only 001 --> 999
62
+ "1930426010000",
63
+
64
+ // Check controll all posible conbinations
65
+ "1930426450030",
66
+ "1930426450031",
67
+ "1930426450032",
68
+ "1930426450033",
69
+ "1930426450034",
70
+ // "1930426450035", // --> this is good
71
+ "1930426450036",
72
+ "1930426450037",
73
+ "1930426450038",
74
+ "1930426450039",
75
+
76
+ "1730513635451",
77
+ ];
78
+
79
+ wrongCNPs.map((cnp) => (
80
+ describe(`given the wrong CNP ${cnp}`,
81
+ () => {
82
+ it("should not be valid",
83
+ () => {
84
+ expect(isValidCNP(cnp)).toBe(notValid);
85
+ });
86
+ })
87
+ ));
88
+
89
+ const goodCNPs = [
90
+
91
+ "1601224522490",
92
+ // list from http://cnp-orange-young.blogspot.ro/
93
+ "1851021345131",
94
+ "1920617149053",
95
+ "1870505168646",
96
+ "1870619152998",
97
+ "1921204325416",
98
+ "1931011351347",
99
+ "1860601214764",
100
+ "1930114152084",
101
+ "1930729213031",
102
+ "1931110257176",
103
+ "1900806182888",
104
+ "1920201181713",
105
+ "1911202393786",
106
+ "1860114313017",
107
+ "1900129321797",
108
+ "1910319357474",
109
+ "1881110136241",
110
+ "1910313389932",
111
+ "1930324128027",
112
+ "1860713267955",
113
+ "1920110059921",
114
+ "1920323137670",
115
+ "1910524257786",
116
+ "1910219353588",
117
+ "1921113049026",
118
+ "1910510171180",
119
+ "1921219189118",
120
+ "1930614296921",
121
+ "1930408137659",
122
+ "1860525171600",
123
+ "1871008113318",
124
+ "1900809164551",
125
+ "1870418305339",
126
+ "1920622093590",
127
+ "1860228422041",
128
+ "1881024199710",
129
+ "1901119289825",
130
+ "1870623151354",
131
+ "1880717053385",
132
+ "1860331281263",
133
+ "1921127239892",
134
+ "1860726084246",
135
+ "1891209392109",
136
+ "1870610429939",
137
+ "1891101155151",
138
+ "1900515188610",
139
+ "1900817347850",
140
+ "1850603113108",
141
+ "1920219031621",
142
+ "1880716319353",
143
+ "1851123072213",
144
+ "1890503074079",
145
+ "1920929194685",
146
+ "1930604396824",
147
+ "1920721211943",
148
+ "1911125017410",
149
+ "1920328331453",
150
+ "1891012055602",
151
+ "1850412422567",
152
+ "1900830012030",
153
+ "1901109372453",
154
+ "1901119063169",
155
+ "1910801238953",
156
+ "1850126336642",
157
+ "1870619334654",
158
+ "1880930146221",
159
+ "1861019351849",
160
+ "1930502103999",
161
+ "1930425361934",
162
+ "1871108269030",
163
+ "1860622273209",
164
+ "1920723362204",
165
+ "1880919016077",
166
+ "1860627124609",
167
+ "1930210191367",
168
+ "1920306379899",
169
+ "1860621221169",
170
+ "1890514289320",
171
+ "1920421395061",
172
+ "1930426272907",
173
+ "1861224076805",
174
+ "1850204207530",
175
+ "1930726241832",
176
+ "1920229184105",
177
+ "1910318245177",
178
+ "1871225154992",
179
+ "1890425099446",
180
+
181
+ "1920918187490",
182
+ "1911017023863",
183
+ "1900514401426",
184
+ "1860117328230",
185
+ "1861019339785",
186
+ "1870119334824",
187
+ "1880316079025",
188
+ "1910216018631",
189
+ "1920425405811",
190
+ "1920904145205",
191
+ "1881201016278",
192
+ "1920731125084",
193
+ "1901003395568",
194
+
195
+ "1590512521591",
196
+ "1660418230010",
197
+ "1891119450065",
198
+ "1920310430037",
199
+ "1920504521696",
200
+ "1930426450035",
201
+ "2770926521590",
202
+ "2830111410090",
203
+ "2880330521699",
204
+ "2900117521690",
205
+ "2910825522143",
206
+ ];
207
+
208
+ goodCNPs.map((cnp) => (
209
+ describe(`given the good CNP ${cnp}`,
210
+ () => {
211
+ it("should be valid",
212
+ () => {
213
+ expect(isValidCNP(cnp)).toBe(valid);
214
+ });
215
+ })
216
+ ));