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.
- package/.eslintignore +2 -0
- package/.eslintrc.json +275 -0
- package/.flowconfig +23 -0
- package/conf/dev.js +19 -0
- package/conf/dist.js +19 -0
- package/conf/polyfills/tempPolyfills.js +7 -0
- package/package.json +16 -16
- package/src/Account/Load.jsx +79 -0
- package/src/Account/actions.js +10 -0
- package/src/Account/index.js +11 -0
- package/src/Account/reducer.js +139 -0
- package/src/Account/request.js +36 -0
- package/src/Async/InitModule.jsx +114 -0
- package/src/Async/RouteLoading.jsx +52 -0
- package/src/Async/SimulatedException.jsx +19 -0
- package/src/Async/index.jsx +75 -0
- package/src/Async/types.js +39 -0
- package/src/Company/Load.jsx +84 -0
- package/src/Company/actions.js +10 -0
- package/src/Company/index.js +11 -0
- package/src/Company/reducer.js +201 -0
- package/src/Company/request.js +30 -0
- package/src/Company/util.js +7 -0
- package/src/Header/AccountOptionsContainer.jsx +124 -0
- package/src/Header/AdminSelectCompany.jsx +101 -0
- package/src/Header/ClientSelectCompany.jsx +90 -0
- package/src/Header/Header.jsx +120 -0
- package/src/Header/HeaderContainer.jsx +30 -0
- package/src/Header/Logo.jsx +16 -0
- package/src/Header/LogoutButton.jsx +34 -0
- package/src/Header/index.jsx +9 -0
- package/src/Header/request.js +28 -0
- package/src/Header/types.js +6 -0
- package/src/Header/util.jsx +61 -0
- package/src/Inputs/Business/BankAccount.jsx +39 -0
- package/src/Inputs/Business/BankName.jsx +40 -0
- package/src/Inputs/Business/CifField.jsx +93 -0
- package/src/Inputs/Business/CifFieldContainer.jsx +142 -0
- package/src/Inputs/Business/Email.jsx +23 -0
- package/src/Inputs/Business/NidField.jsx +77 -0
- package/src/Inputs/Business/Phone.jsx +23 -0
- package/src/Inputs/Business/index.js +16 -0
- package/src/Inputs/Business/request.js +39 -0
- package/src/Inputs/CaptchaBox.jsx +131 -0
- package/src/Inputs/DateInput.jsx +188 -0
- package/src/Inputs/DateTemplate.jsx +213 -0
- package/src/Inputs/DelayInputChange.jsx +130 -0
- package/src/Inputs/FocusTemplate.jsx +41 -0
- package/src/Inputs/InputTemplate.jsx +79 -0
- package/src/Inputs/LabelTemplate.jsx +47 -0
- package/src/Inputs/NumericInput.jsx +142 -0
- package/src/Inputs/NumericTemplate.jsx +155 -0
- package/src/Inputs/Selects/County.jsx +19 -0
- package/src/Inputs/Selects/Custom.jsx +55 -0
- package/src/Inputs/Selects/Simple.jsx +73 -0
- package/src/Inputs/Selects/index.jsx +37 -0
- package/src/Inputs/SimpleInput.jsx +40 -0
- package/src/Inputs/SimpleTextarea.jsx +55 -0
- package/src/Inputs/TextareaTemplate.jsx +57 -0
- package/src/Inputs/Tooltip.jsx +61 -0
- package/src/Inputs/index.js +22 -0
- package/src/Messages/Error.jsx +83 -0
- package/src/Messages/Loading.jsx +43 -0
- package/src/Messages/index.jsx +4 -0
- package/src/Modal/Delete.jsx +237 -0
- package/src/Modal/Root.jsx +57 -0
- package/src/Modal/SimpleModal.jsx +47 -0
- package/src/Modal/actions.js +7 -0
- package/src/Modal/getComponent.jsx +32 -0
- package/src/Modal/index.jsx +12 -0
- package/src/Modal/reducer.js +40 -0
- package/src/Modal/types.js +6 -0
- package/src/Modal/util.js +15 -0
- package/src/Payment/EstimatePrice/Description.jsx +101 -0
- package/src/Payment/EstimatePrice/PayBox.jsx +173 -0
- package/src/Payment/EstimatePrice/index.jsx +63 -0
- package/src/Payment/EstimatePrice/util.js +15 -0
- package/src/Payment/MobilpayForm.jsx +77 -0
- package/src/Payment/Modal/BankTransfer.jsx +129 -0
- package/src/Payment/Modal/CompanyValability.jsx +14 -0
- package/src/Payment/Modal/DoneForm.jsx +209 -0
- package/src/Payment/Modal/PaymentDone.jsx +27 -0
- package/src/Payment/Modal/index.js +13 -0
- package/src/Payment/actions.jsx +22 -0
- package/{Payment → src/Payment}/codes.js +16 -19
- package/src/Payment/index.jsx +124 -0
- package/src/Payment/request.js +50 -0
- package/src/Payment/types.js +14 -0
- package/src/Payment/util.jsx +52 -0
- package/src/Payment/validate.js +25 -0
- package/src/Sidebar.jsx +158 -0
- package/src/Things.jsx +35 -0
- package/src/actions.js +36 -0
- package/src/config.js +7 -0
- package/src/dev/ErrorBoundary.jsx +98 -0
- package/src/dev/TheError.jsx +87 -0
- package/src/dev/index.js +127 -0
- package/src/dev/types.js +10 -0
- package/src/prod/SentryErrorBoundary.jsx +98 -0
- package/src/reducer/captchas.js +44 -0
- package/src/reducer/counties.js +46 -0
- package/src/reducer/index.js +25 -0
- package/src/reducer/module.jsx +43 -0
- package/src/style/.sass-lint.yml +84 -0
- package/src/style/.stylelintrc.json +161 -0
- package/src/style/_fancy-text.scss +37 -0
- package/src/style/_fix_bootstrap_placeholder_color.scss +14 -0
- package/src/style/_header-company.scss +69 -0
- package/src/style/_inputs.scss +12 -0
- package/src/style/_minimal.scss +31 -0
- package/src/style/_navigation.scss +24 -0
- package/src/style/_others.scss +79 -0
- package/src/style/index.scss +7 -0
- package/src/style/sidebar/_animations.scss +21 -0
- package/src/style/sidebar/_dark-theme.scss +77 -0
- package/src/style/sidebar/_scroll.scss +37 -0
- package/src/style/sidebar/_structure.scss +299 -0
- package/src/style/sidebar.scss +4 -0
- package/src/types.js +31 -0
- package/src/utility/calendar.js +39 -0
- package/src/utility/date.js +100 -0
- package/src/utility/index.js +12 -0
- package/src/utility/language.js +17 -0
- package/src/utility/mql.js +3 -0
- package/src/utility/normalize-test.js +58 -0
- package/src/utility/normalize.js +119 -0
- package/src/utility/numbers.js +87 -0
- package/src/utility/numeric.js +114 -0
- package/src/utility/others.jsx +160 -0
- package/src/utility/strings-test.js +136 -0
- package/src/utility/strings.js +80 -0
- package/src/utility/validation/common.js +360 -0
- package/src/utility/validation/index.js +70 -0
- package/src/utility/validation/specific.js +9 -0
- package/src/utility/validation/validate/bank-test.js +129 -0
- package/src/utility/validation/validate/bank.js +176 -0
- package/src/utility/validation/validate/cif-test.js +105 -0
- package/src/utility/validation/validate/cif.js +44 -0
- package/src/utility/validation/validate/cnp-test.js +216 -0
- package/src/utility/validation/validate/cnp.js +261 -0
- package/{utility → src/utility}/validation/validate/date.js +73 -61
- package/src/utility/validation/validate/email-test.js +36 -0
- package/src/utility/validation/validate/email.js +6 -0
- package/src/utility/validation/validate/index.js +7 -0
- package/webpack.config.js +90 -0
- package/x25.wiki/Account.md +41 -0
- package/x25.wiki/Company.md +39 -0
- package/x25.wiki/Header.md +21 -0
- package/x25.wiki/Home.md +1 -0
- package/x25.wiki/Inputs.md +33 -0
- package/x25.wiki/Messages.md +27 -0
- package/x25.wiki/Payment.md +42 -0
- package/Account/Load.js +0 -75
- package/Account/actions.js +0 -15
- package/Account/index.js +0 -20
- package/Account/reducer.js +0 -122
- package/Account/request.js +0 -44
- package/Async/InitModule.js +0 -190
- package/Async/RouteLoading.js +0 -64
- package/Async/SimulatedException.js +0 -44
- package/Async/index.js +0 -95
- package/Async/types.js +0 -1
- package/Company/Load.js +0 -82
- package/Company/actions.js +0 -15
- package/Company/index.js +0 -20
- package/Company/reducer.js +0 -165
- package/Company/request.js +0 -36
- package/Company/util.js +0 -10
- package/Header/AccountOptionsContainer.js +0 -144
- package/Header/AdminSelectCompany.js +0 -109
- package/Header/ClientSelectCompany.js +0 -104
- package/Header/Header.js +0 -127
- package/Header/HeaderContainer.js +0 -39
- package/Header/Logo.js +0 -30
- package/Header/LogoutButton.js +0 -39
- package/Header/index.js +0 -19
- package/Header/request.js +0 -26
- package/Header/types.js +0 -1
- package/Header/util.js +0 -58
- package/Inputs/Business/BankAccount.js +0 -48
- package/Inputs/Business/BankName.js +0 -49
- package/Inputs/Business/CifField.js +0 -112
- package/Inputs/Business/CifFieldContainer.js +0 -157
- package/Inputs/Business/Email.js +0 -37
- package/Inputs/Business/NidField.js +0 -91
- package/Inputs/Business/Phone.js +0 -37
- package/Inputs/Business/index.js +0 -34
- package/Inputs/Business/request.js +0 -39
- package/Inputs/CaptchaBox.js +0 -151
- package/Inputs/DateInput.js +0 -172
- package/Inputs/DateTemplate.js +0 -200
- package/Inputs/DelayInputChange.js +0 -135
- package/Inputs/FocusTemplate.js +0 -47
- package/Inputs/InputTemplate.js +0 -78
- package/Inputs/LabelTemplate.js +0 -59
- package/Inputs/NumericInput.js +0 -139
- package/Inputs/NumericTemplate.js +0 -148
- package/Inputs/Selects/County.js +0 -29
- package/Inputs/Selects/Custom.js +0 -56
- package/Inputs/Selects/Simple.js +0 -75
- package/Inputs/Selects/index.js +0 -52
- package/Inputs/SimpleInput.js +0 -42
- package/Inputs/SimpleTextarea.js +0 -47
- package/Inputs/TextareaTemplate.js +0 -55
- package/Inputs/Tooltip.js +0 -82
- package/Inputs/index.js +0 -185
- package/Messages/Error.js +0 -106
- package/Messages/Loading.js +0 -68
- package/Messages/index.js +0 -29
- package/Modal/Delete.js +0 -240
- package/Modal/Root.js +0 -81
- package/Modal/SimpleModal.js +0 -57
- package/Modal/actions.js +0 -10
- package/Modal/getComponent.js +0 -42
- package/Modal/index.js +0 -22
- package/Modal/reducer.js +0 -53
- package/Modal/types.js +0 -7
- package/Modal/util.js +0 -17
- package/Payment/EstimatePrice/Description.js +0 -92
- package/Payment/EstimatePrice/PayBox.js +0 -220
- package/Payment/EstimatePrice/index.js +0 -92
- package/Payment/EstimatePrice/util.js +0 -21
- package/Payment/MobilpayForm.js +0 -86
- package/Payment/Modal/BankTransfer.js +0 -233
- package/Payment/Modal/CompanyValability.js +0 -28
- package/Payment/Modal/DoneForm.js +0 -222
- package/Payment/Modal/PaymentDone.js +0 -53
- package/Payment/Modal/index.js +0 -27
- package/Payment/actions.js +0 -23
- package/Payment/index.js +0 -141
- package/Payment/request.js +0 -49
- package/Payment/types.js +0 -1
- package/Payment/util.js +0 -50
- package/Payment/validate.js +0 -23
- package/Sidebar.js +0 -156
- package/Things.js +0 -53
- package/actions.js +0 -73
- package/config.js +0 -10
- package/dev/ErrorBoundary.js +0 -109
- package/dev/TheError.js +0 -113
- package/dev/index.js +0 -132
- package/dev/types.js +0 -1
- package/prod/SentryErrorBoundary.js +0 -150
- package/reducer/captchas.js +0 -51
- package/reducer/counties.js +0 -57
- package/reducer/index.js +0 -38
- package/reducer/module.js +0 -48
- package/style/index.css +0 -1
- package/style/sidebar.css +0 -1
- package/types.js +0 -1
- package/utility/calendar.js +0 -45
- package/utility/date.js +0 -111
- package/utility/index.js +0 -125
- package/utility/language.js +0 -20
- package/utility/mql.js +0 -6
- package/utility/normalize-test.js +0 -54
- package/utility/normalize.js +0 -108
- package/utility/numbers.js +0 -93
- package/utility/numeric.js +0 -103
- package/utility/others.js +0 -142
- package/utility/strings-test.js +0 -216
- package/utility/strings.js +0 -85
- package/utility/validation/common.js +0 -278
- package/utility/validation/index.js +0 -110
- package/utility/validation/specific.js +0 -14
- package/utility/validation/validate/bank-test.js +0 -41
- package/utility/validation/validate/bank.js +0 -176
- package/utility/validation/validate/cif-test.js +0 -37
- package/utility/validation/validate/cif.js +0 -44
- package/utility/validation/validate/cnp-test.js +0 -68
- package/utility/validation/validate/cnp.js +0 -193
- package/utility/validation/validate/email-test.js +0 -30
- package/utility/validation/validate/email.js +0 -11
- 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
|
+
));
|