redux-freeform 6.2.0-beta.1 → 6.2.1-beta.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/dist/redux-freeform.cjs.js +23 -24
- package/dist/redux-freeform.esm.js +23 -24
- package/dist/redux-freeform.umd.js +23 -24
- package/package.json +1 -1
|
@@ -150,43 +150,42 @@ validatorFns[NO_MORE_THAN_SIX_NUMBERS] = (value) => {
|
|
|
150
150
|
* https://stripe.com/en-ca/resources/more/how-to-use-the-luhn-algorithm-a-guide-in-applications-for-businesses#luhn-algorithm-formula
|
|
151
151
|
*/
|
|
152
152
|
|
|
153
|
-
function luhnValid(string) {
|
|
154
|
-
if (!string) {
|
|
153
|
+
function luhnValid(string) { if (!string) {
|
|
155
154
|
return false;
|
|
156
155
|
}
|
|
157
156
|
|
|
157
|
+
// Extract all digit characters from the string.
|
|
158
158
|
const digits = string.match(/\d/g);
|
|
159
159
|
if (!digits) {
|
|
160
160
|
return false;
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
-
const digitArray = digits.map(Number);
|
|
164
163
|
let totalSum = 0;
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
164
|
+
let shouldDouble = false;
|
|
165
|
+
|
|
166
|
+
// Process digits from right to left
|
|
167
|
+
for (let i = digits.length - 1; i >= 0; i--) {
|
|
168
|
+
// Convert the current character to a number.
|
|
169
|
+
let digit = parseInt(digits[i], 10);
|
|
170
|
+
|
|
171
|
+
// Double the digit and adjust if it exceeds 9.
|
|
172
|
+
if (shouldDouble) {
|
|
173
|
+
digit *= 2;
|
|
174
|
+
if (digit > 9) {
|
|
175
|
+
// If the result of any doubling operation is greater than nine,
|
|
176
|
+
// then add the digits of the result together to obtain a single-digit number.
|
|
177
|
+
// This is equivalent to adding the digits together (e.g. 16: 1 + 6 = 7 = 16 - 9).
|
|
178
|
+
digit -= 9;
|
|
179
179
|
}
|
|
180
|
-
|
|
181
|
-
totalSum += secondToLastDigitDoubled;
|
|
182
180
|
}
|
|
183
181
|
|
|
184
|
-
//
|
|
185
|
-
totalSum +=
|
|
182
|
+
// Add the processed digit to the total sum.
|
|
183
|
+
totalSum += digit;
|
|
184
|
+
// After doubling the value of the second-to-last digit, continue doing the same for every other digit.
|
|
185
|
+
shouldDouble = !shouldDouble;
|
|
186
186
|
}
|
|
187
187
|
|
|
188
|
-
//
|
|
189
|
-
// According to the Luhn algorithm, the number is considered to be valid if the total ends in zero.
|
|
188
|
+
// The number is valid if totalSum is divisible by 10.
|
|
190
189
|
return totalSum % 10 === 0;
|
|
191
190
|
}
|
|
192
191
|
|
|
@@ -203,7 +202,7 @@ validatorFns[INCLUDES_POTENTIAL_CARD_NUMBER] = (value) => {
|
|
|
203
202
|
// A potential credit card number is a sequence of 8 to 20 digits, with optional spaces or hyphens between them
|
|
204
203
|
const regexString = '(?:\\d[ -]*){8,20}';
|
|
205
204
|
const regex = new RegExp(regexString);
|
|
206
|
-
return
|
|
205
|
+
return !(luhnValid(value) && regex.test(value));
|
|
207
206
|
};
|
|
208
207
|
|
|
209
208
|
const NUMBER_LESS_THAN = 'validator/NUMBER_LESS_THAN';
|
|
@@ -146,43 +146,42 @@ validatorFns[NO_MORE_THAN_SIX_NUMBERS] = (value) => {
|
|
|
146
146
|
* https://stripe.com/en-ca/resources/more/how-to-use-the-luhn-algorithm-a-guide-in-applications-for-businesses#luhn-algorithm-formula
|
|
147
147
|
*/
|
|
148
148
|
|
|
149
|
-
function luhnValid(string) {
|
|
150
|
-
if (!string) {
|
|
149
|
+
function luhnValid(string) { if (!string) {
|
|
151
150
|
return false;
|
|
152
151
|
}
|
|
153
152
|
|
|
153
|
+
// Extract all digit characters from the string.
|
|
154
154
|
const digits = string.match(/\d/g);
|
|
155
155
|
if (!digits) {
|
|
156
156
|
return false;
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
-
const digitArray = digits.map(Number);
|
|
160
159
|
let totalSum = 0;
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
160
|
+
let shouldDouble = false;
|
|
161
|
+
|
|
162
|
+
// Process digits from right to left
|
|
163
|
+
for (let i = digits.length - 1; i >= 0; i--) {
|
|
164
|
+
// Convert the current character to a number.
|
|
165
|
+
let digit = parseInt(digits[i], 10);
|
|
166
|
+
|
|
167
|
+
// Double the digit and adjust if it exceeds 9.
|
|
168
|
+
if (shouldDouble) {
|
|
169
|
+
digit *= 2;
|
|
170
|
+
if (digit > 9) {
|
|
171
|
+
// If the result of any doubling operation is greater than nine,
|
|
172
|
+
// then add the digits of the result together to obtain a single-digit number.
|
|
173
|
+
// This is equivalent to adding the digits together (e.g. 16: 1 + 6 = 7 = 16 - 9).
|
|
174
|
+
digit -= 9;
|
|
175
175
|
}
|
|
176
|
-
|
|
177
|
-
totalSum += secondToLastDigitDoubled;
|
|
178
176
|
}
|
|
179
177
|
|
|
180
|
-
//
|
|
181
|
-
totalSum +=
|
|
178
|
+
// Add the processed digit to the total sum.
|
|
179
|
+
totalSum += digit;
|
|
180
|
+
// After doubling the value of the second-to-last digit, continue doing the same for every other digit.
|
|
181
|
+
shouldDouble = !shouldDouble;
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
-
//
|
|
185
|
-
// According to the Luhn algorithm, the number is considered to be valid if the total ends in zero.
|
|
184
|
+
// The number is valid if totalSum is divisible by 10.
|
|
186
185
|
return totalSum % 10 === 0;
|
|
187
186
|
}
|
|
188
187
|
|
|
@@ -199,7 +198,7 @@ validatorFns[INCLUDES_POTENTIAL_CARD_NUMBER] = (value) => {
|
|
|
199
198
|
// A potential credit card number is a sequence of 8 to 20 digits, with optional spaces or hyphens between them
|
|
200
199
|
const regexString = '(?:\\d[ -]*){8,20}';
|
|
201
200
|
const regex = new RegExp(regexString);
|
|
202
|
-
return
|
|
201
|
+
return !(luhnValid(value) && regex.test(value));
|
|
203
202
|
};
|
|
204
203
|
|
|
205
204
|
const NUMBER_LESS_THAN = 'validator/NUMBER_LESS_THAN';
|
|
@@ -152,43 +152,42 @@
|
|
|
152
152
|
* https://stripe.com/en-ca/resources/more/how-to-use-the-luhn-algorithm-a-guide-in-applications-for-businesses#luhn-algorithm-formula
|
|
153
153
|
*/
|
|
154
154
|
|
|
155
|
-
function luhnValid(string) {
|
|
156
|
-
if (!string) {
|
|
155
|
+
function luhnValid(string) { if (!string) {
|
|
157
156
|
return false;
|
|
158
157
|
}
|
|
159
158
|
|
|
159
|
+
// Extract all digit characters from the string.
|
|
160
160
|
const digits = string.match(/\d/g);
|
|
161
161
|
if (!digits) {
|
|
162
162
|
return false;
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
-
const digitArray = digits.map(Number);
|
|
166
165
|
let totalSum = 0;
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
166
|
+
let shouldDouble = false;
|
|
167
|
+
|
|
168
|
+
// Process digits from right to left
|
|
169
|
+
for (let i = digits.length - 1; i >= 0; i--) {
|
|
170
|
+
// Convert the current character to a number.
|
|
171
|
+
let digit = parseInt(digits[i], 10);
|
|
172
|
+
|
|
173
|
+
// Double the digit and adjust if it exceeds 9.
|
|
174
|
+
if (shouldDouble) {
|
|
175
|
+
digit *= 2;
|
|
176
|
+
if (digit > 9) {
|
|
177
|
+
// If the result of any doubling operation is greater than nine,
|
|
178
|
+
// then add the digits of the result together to obtain a single-digit number.
|
|
179
|
+
// This is equivalent to adding the digits together (e.g. 16: 1 + 6 = 7 = 16 - 9).
|
|
180
|
+
digit -= 9;
|
|
181
181
|
}
|
|
182
|
-
|
|
183
|
-
totalSum += secondToLastDigitDoubled;
|
|
184
182
|
}
|
|
185
183
|
|
|
186
|
-
//
|
|
187
|
-
totalSum +=
|
|
184
|
+
// Add the processed digit to the total sum.
|
|
185
|
+
totalSum += digit;
|
|
186
|
+
// After doubling the value of the second-to-last digit, continue doing the same for every other digit.
|
|
187
|
+
shouldDouble = !shouldDouble;
|
|
188
188
|
}
|
|
189
189
|
|
|
190
|
-
//
|
|
191
|
-
// According to the Luhn algorithm, the number is considered to be valid if the total ends in zero.
|
|
190
|
+
// The number is valid if totalSum is divisible by 10.
|
|
192
191
|
return totalSum % 10 === 0;
|
|
193
192
|
}
|
|
194
193
|
|
|
@@ -205,7 +204,7 @@
|
|
|
205
204
|
// A potential credit card number is a sequence of 8 to 20 digits, with optional spaces or hyphens between them
|
|
206
205
|
const regexString = '(?:\\d[ -]*){8,20}';
|
|
207
206
|
const regex = new RegExp(regexString);
|
|
208
|
-
return
|
|
207
|
+
return !(luhnValid(value) && regex.test(value));
|
|
209
208
|
};
|
|
210
209
|
|
|
211
210
|
const NUMBER_LESS_THAN = 'validator/NUMBER_LESS_THAN';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "redux-freeform",
|
|
3
|
-
"version": "6.2.
|
|
3
|
+
"version": "6.2.1-beta.0",
|
|
4
4
|
"description": "A small Redux form library that supports purely functional apps, without magic",
|
|
5
5
|
"main": "dist/redux-freeform.cjs.js",
|
|
6
6
|
"module": "dist/redux-freeform.esm.js",
|