MCPcopy Create free account
hub / github.com/Tron521/codex-console-temp / parseCardText

Function parseCardText

static/js/payment.js:412–601  ·  view source on GitHub ↗
(rawText)

Source from the content-addressed store, hash-verified

410}
411
412function parseCardText(rawText) {
413 const text = String(rawText || "").trim();
414 if (!text) return {};
415
416 const lines = text
417 .split(/\r?\n/)
418 .map((line) => line.trim())
419 .filter(Boolean);
420 const kv = {};
421 for (const line of lines) {
422 const match = line.match(/^(.+?)\s*[::]\s*(.+)$/);
423 if (match) {
424 kv[match[1].trim().toLowerCase()] = match[2].trim();
425 }
426 }
427
428 const result = {};
429
430 // 卡号
431 const cardKeyCandidates = [
432 "卡号",
433 "card number",
434 "card",
435 "card_number",
436 ];
437 for (const key of cardKeyCandidates) {
438 if (!kv[key]) continue;
439 const digits = kv[key].replace(/\D/g, "");
440 if (digits.length >= 13 && digits.length <= 19) {
441 result.card_number = digits;
442 break;
443 }
444 }
445
446 if (!result.card_number) {
447 for (const line of lines) {
448 const m = line.replace(/-/g, " ").match(/^(\d{13,19})\s+(0[1-9]|1[0-2])\s+(\d{2,4})\s+(\d{3,4})$/);
449 if (m) {
450 result.card_number = m[1];
451 result.exp_month = normalizeMonth(m[2]);
452 result.exp_year = normalizeYear(m[3]);
453 result.cvv = m[4];
454 break;
455 }
456 }
457 }
458
459 if (!result.card_number) {
460 for (const line of lines) {
461 const digits = line.replace(/\D/g, "");
462 if (digits.length >= 13 && digits.length <= 19) {
463 result.card_number = digits;
464 break;
465 }
466 }
467 }
468
469 // 有效期

Callers 2

parseSingleBillingTextFunction · 0.85
parseBatchBillingTextFunction · 0.85

Calls 4

normalizeMonthFunction · 0.85
normalizeYearFunction · 0.85
resolveCountryAliasFunction · 0.85
filterMethod · 0.45

Tested by

no test coverage detected