monkey-front-core 0.0.515 → 0.0.517
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/esm2020/lib/core/utils/utils.mjs +147 -3
- package/fesm2015/monkey-front-core.mjs +146 -2
- package/fesm2015/monkey-front-core.mjs.map +1 -1
- package/fesm2020/monkey-front-core.mjs +146 -2
- package/fesm2020/monkey-front-core.mjs.map +1 -1
- package/monkey-front-core-0.0.517.tgz +0 -0
- package/package.json +1 -1
- package/monkey-front-core-0.0.515.tgz +0 -0
|
@@ -291,8 +291,152 @@ class MonkeyEcxUtils {
|
|
|
291
291
|
return dvCalc === dgv;
|
|
292
292
|
}
|
|
293
293
|
static isValidRFC(document) {
|
|
294
|
-
const
|
|
295
|
-
|
|
294
|
+
const RFC_REGEXP = /^([A-ZÑ\x26]{3,4})([0-9]{6})([A-Z0-9]{3})$/;
|
|
295
|
+
const SPECIAL_CASES = {
|
|
296
|
+
'XEXX010101000': 'foreign',
|
|
297
|
+
'XAXX010101000': 'generic'
|
|
298
|
+
};
|
|
299
|
+
const FORBIDDEN_WORDS = [
|
|
300
|
+
"BUEI",
|
|
301
|
+
"BUEY",
|
|
302
|
+
"CACA",
|
|
303
|
+
"CACO",
|
|
304
|
+
"CAGA",
|
|
305
|
+
"CAGO",
|
|
306
|
+
"CAKA",
|
|
307
|
+
"CAKO",
|
|
308
|
+
"COGE",
|
|
309
|
+
"COJA",
|
|
310
|
+
"COJE",
|
|
311
|
+
"COJI",
|
|
312
|
+
"COJO",
|
|
313
|
+
"CULO",
|
|
314
|
+
"FETO",
|
|
315
|
+
"GUEY",
|
|
316
|
+
"JOTO",
|
|
317
|
+
"KACA",
|
|
318
|
+
"KACO",
|
|
319
|
+
"KAGA",
|
|
320
|
+
"KAGO",
|
|
321
|
+
"KOGE",
|
|
322
|
+
"KOJO",
|
|
323
|
+
"KAKA",
|
|
324
|
+
"KULO",
|
|
325
|
+
"MAME",
|
|
326
|
+
"MAMO",
|
|
327
|
+
"MEAR",
|
|
328
|
+
"MEAS",
|
|
329
|
+
"MEON",
|
|
330
|
+
"MION",
|
|
331
|
+
"MOCO",
|
|
332
|
+
"MULA",
|
|
333
|
+
"PEDA",
|
|
334
|
+
"PEDO",
|
|
335
|
+
"PENE",
|
|
336
|
+
"PUTA",
|
|
337
|
+
"PUTO",
|
|
338
|
+
"QULO",
|
|
339
|
+
"RATA",
|
|
340
|
+
"RUIN"
|
|
341
|
+
];
|
|
342
|
+
const VALUES_MAP = {
|
|
343
|
+
'0': 0,
|
|
344
|
+
'1': 1,
|
|
345
|
+
'2': 2,
|
|
346
|
+
'3': 3,
|
|
347
|
+
'4': 4,
|
|
348
|
+
'5': 5,
|
|
349
|
+
'6': 6,
|
|
350
|
+
'7': 7,
|
|
351
|
+
'8': 8,
|
|
352
|
+
'9': 9,
|
|
353
|
+
'A': 10,
|
|
354
|
+
'B': 11,
|
|
355
|
+
'C': 12,
|
|
356
|
+
'D': 13,
|
|
357
|
+
'E': 14,
|
|
358
|
+
'F': 15,
|
|
359
|
+
'G': 16,
|
|
360
|
+
'H': 17,
|
|
361
|
+
'I': 18,
|
|
362
|
+
'J': 19,
|
|
363
|
+
'K': 20,
|
|
364
|
+
'L': 21,
|
|
365
|
+
'M': 22,
|
|
366
|
+
'N': 23,
|
|
367
|
+
'&': 24,
|
|
368
|
+
'O': 25,
|
|
369
|
+
'P': 26,
|
|
370
|
+
'Q': 27,
|
|
371
|
+
'R': 28,
|
|
372
|
+
'S': 29,
|
|
373
|
+
'T': 30,
|
|
374
|
+
'U': 31,
|
|
375
|
+
'V': 32,
|
|
376
|
+
'W': 33,
|
|
377
|
+
'X': 34,
|
|
378
|
+
'Y': 35,
|
|
379
|
+
'Z': 36,
|
|
380
|
+
' ': 37,
|
|
381
|
+
'Ñ': 38
|
|
382
|
+
};
|
|
383
|
+
const getScore = (doc) => doc.split('').reverse().reduce((sum, char, i) => {
|
|
384
|
+
const index = i + 2;
|
|
385
|
+
const value = VALUES_MAP[char] || 0;
|
|
386
|
+
return sum + value * index;
|
|
387
|
+
}, 0);
|
|
388
|
+
const parseInput = (doc) => {
|
|
389
|
+
return String(doc)
|
|
390
|
+
.trim()
|
|
391
|
+
.toUpperCase()
|
|
392
|
+
.replace(/[^0-9A-ZÑ\x26]/g, '');
|
|
393
|
+
};
|
|
394
|
+
const validateDate = (doc) => {
|
|
395
|
+
const dateStr = doc.slice(0, -3).slice(-6);
|
|
396
|
+
const year = dateStr.slice(0, 2);
|
|
397
|
+
const month = dateStr.slice(2, 4);
|
|
398
|
+
const day = dateStr.slice(4, 6);
|
|
399
|
+
const date = new Date(`20${year}-${month}-${day}`);
|
|
400
|
+
return !isNaN(date.getTime());
|
|
401
|
+
};
|
|
402
|
+
const validateVerificationDigit = (doc) => {
|
|
403
|
+
const digit = doc.slice(-1);
|
|
404
|
+
const rfc = doc.length === 12 ? ` ${doc}` : doc;
|
|
405
|
+
const base = rfc.slice(0, -1);
|
|
406
|
+
const score = getScore(base);
|
|
407
|
+
const mod = (11000 - score) % 11;
|
|
408
|
+
if (mod === 11)
|
|
409
|
+
return '0' === digit;
|
|
410
|
+
if (mod === 10)
|
|
411
|
+
return 'A' === digit;
|
|
412
|
+
return String(mod) === digit;
|
|
413
|
+
};
|
|
414
|
+
const isSpecialCase = (doc) => doc in SPECIAL_CASES;
|
|
415
|
+
const hasForbiddenWords = (doc) => {
|
|
416
|
+
const prefix = (doc || '').slice(0, 4);
|
|
417
|
+
return FORBIDDEN_WORDS.includes(prefix);
|
|
418
|
+
};
|
|
419
|
+
try {
|
|
420
|
+
const input = parseInput(document);
|
|
421
|
+
if (isSpecialCase(input))
|
|
422
|
+
return false;
|
|
423
|
+
const hasValidFormat = RFC_REGEXP.test(input);
|
|
424
|
+
if (!hasValidFormat)
|
|
425
|
+
return false;
|
|
426
|
+
const hasValidDate = validateDate(input);
|
|
427
|
+
if (!hasValidDate)
|
|
428
|
+
return false;
|
|
429
|
+
const hasValidDigit = validateVerificationDigit(input);
|
|
430
|
+
if (!hasValidDigit)
|
|
431
|
+
return false;
|
|
432
|
+
if (hasForbiddenWords(input))
|
|
433
|
+
return false;
|
|
434
|
+
return true;
|
|
435
|
+
}
|
|
436
|
+
catch (e) {
|
|
437
|
+
//not to do
|
|
438
|
+
}
|
|
439
|
+
return false;
|
|
296
440
|
}
|
|
297
441
|
static isValidUrl(txt) {
|
|
298
442
|
const regex = /(https?:\/\/(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9])(:?\d*)\/?([a-z_\\/0-9\-#.]*)\??([a-z_\\/0-9\-#=&]*)/g;
|