@luftborn/custom-elements 2.4.0 → 2.4.1
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/demo/index.js +30 -60
- package/demo/index.min.js +29 -59
- package/demo/index.min.js.map +1 -1
- package/dist/framework/Validation/Validators/SEPersonalNumber.d.ts +2 -2
- package/dist/framework/Validation/Validators/SEPersonalNumber.js +28 -58
- package/dist/framework/Validation/Validators/SEPersonalNumber.js.map +1 -1
- package/package.json +1 -1
- package/src/framework/Validation/Validators/SEPersonalNumber.ts +32 -69
package/demo/index.min.js
CHANGED
|
@@ -6256,68 +6256,38 @@ exports.default = SECompanyRegistrationValidator;
|
|
|
6256
6256
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6257
6257
|
var SEPersonalNumberValidator = /** @class */ (function () {
|
|
6258
6258
|
function SEPersonalNumberValidator() {
|
|
6259
|
-
this.regex = new RegExp(/^(\d{2}){0,1}(\d{2})(\d{2})(\d{2})([\+\-]?)((?!000)\d{3})(\d)$/);
|
|
6260
6259
|
}
|
|
6261
6260
|
SEPersonalNumberValidator.prototype.isSatisfiedBy = function (input, allowEmpty) {
|
|
6262
6261
|
if (allowEmpty === void 0) { allowEmpty = true; }
|
|
6263
|
-
|
|
6264
|
-
|
|
6265
|
-
|
|
6266
|
-
|
|
6267
|
-
if (!
|
|
6268
|
-
return false;
|
|
6269
|
-
|
|
6270
|
-
|
|
6271
|
-
|
|
6272
|
-
|
|
6273
|
-
|
|
6274
|
-
|
|
6275
|
-
|
|
6276
|
-
|
|
6277
|
-
|
|
6278
|
-
|
|
6279
|
-
|
|
6280
|
-
|
|
6281
|
-
|
|
6282
|
-
|
|
6283
|
-
|
|
6284
|
-
var
|
|
6285
|
-
var
|
|
6286
|
-
|
|
6287
|
-
|
|
6288
|
-
|
|
6289
|
-
|
|
6290
|
-
var
|
|
6291
|
-
|
|
6292
|
-
var controlNumber = groups[7];
|
|
6293
|
-
// Try parse date-time to make sure it's actually a real date.
|
|
6294
|
-
if (!Date.parse(fullYear + "-" + month + "-" + realDay)) {
|
|
6295
|
-
return false;
|
|
6296
|
-
}
|
|
6297
|
-
if (this.luhn("" + year + month + day + groups[6]) !== parseInt(controlNumber, 10)) {
|
|
6298
|
-
return false;
|
|
6299
|
-
}
|
|
6300
|
-
return true;
|
|
6301
|
-
};
|
|
6302
|
-
SEPersonalNumberValidator.prototype.luhn = function (value) {
|
|
6303
|
-
// Luhm algorithm doubles every other number in the value.
|
|
6304
|
-
// To get the correct checksum digit we aught to append a 0 on the sequence.
|
|
6305
|
-
// If the result becomes a two digit number, subtract 9 from the value.
|
|
6306
|
-
// If the total sum is not a 0, the last checksum value should be subtracted from 10.
|
|
6307
|
-
// The resulting value is the check value that we use as control number.
|
|
6308
|
-
// The value passed is a string, so we aught to get the actual integer value from each char (i.e., subtract '0' which is 48).
|
|
6309
|
-
var t = value.split('').map(function (d) { return parseInt(d, 10); });
|
|
6310
|
-
var sum = 0;
|
|
6311
|
-
var temp;
|
|
6312
|
-
for (var i = 0; i < t.length; i++) {
|
|
6313
|
-
temp = t[i];
|
|
6314
|
-
temp *= 2 - (i % 2);
|
|
6315
|
-
if (temp > 9) {
|
|
6316
|
-
temp -= 9;
|
|
6317
|
-
}
|
|
6318
|
-
sum += temp;
|
|
6319
|
-
}
|
|
6320
|
-
return Math.ceil(sum / 10.0) * 10 - sum;
|
|
6262
|
+
// Format: 10 or 12 digits [YY]YYMMDD[-/+]NNNN and pass checksum validation
|
|
6263
|
+
var match = input
|
|
6264
|
+
.replace(/[ +-]/g, '')
|
|
6265
|
+
.match(/^(\d{2}|\d{4})(\d{2})(\d{2})(\d{4})$/i);
|
|
6266
|
+
if (!match)
|
|
6267
|
+
return false; // not matching regex
|
|
6268
|
+
var _a = match.slice(1).map(Number), month = _a[1], day = _a[2];
|
|
6269
|
+
return ((!allowEmpty ? !!input : true) &&
|
|
6270
|
+
this.validateDayAndMonth(month, day) &&
|
|
6271
|
+
this.validateChecksum(input));
|
|
6272
|
+
};
|
|
6273
|
+
SEPersonalNumberValidator.prototype.validateDayAndMonth = function (month, day) {
|
|
6274
|
+
var maxDaysInMonth = [0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
6275
|
+
return (!(month < 1 || month > 12) && !(day < 1 || day > maxDaysInMonth[month]));
|
|
6276
|
+
};
|
|
6277
|
+
SEPersonalNumberValidator.prototype.validateChecksum = function (persNo) {
|
|
6278
|
+
var digits = persNo
|
|
6279
|
+
.replace(/[ +-]/g, '')
|
|
6280
|
+
.slice(-10)
|
|
6281
|
+
.split('')
|
|
6282
|
+
.map(Number);
|
|
6283
|
+
var luhnWeights = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1];
|
|
6284
|
+
var luhnF = function (n) { return (n < 10 ? n : n - 9); };
|
|
6285
|
+
var luhnSum = luhnWeights
|
|
6286
|
+
.map(function (value, index) { return value * digits[index]; })
|
|
6287
|
+
.map(luhnF)
|
|
6288
|
+
.reduce(function (a, b) { return a + b; });
|
|
6289
|
+
var controlSum = 10 - (+luhnSum % 10);
|
|
6290
|
+
return controlSum % 10 == 0;
|
|
6321
6291
|
};
|
|
6322
6292
|
return SEPersonalNumberValidator;
|
|
6323
6293
|
}());
|