@fifteen/design-system-vue
Version:
Vue 3 (Composition API + Typescript) implementation of the Fifteen Design System
136 lines (135 loc) • 2.56 kB
JavaScript
const m = [
{
name: "Visa",
type: "visa",
patterns: [4],
lengths: [16],
code: {
name: "CVV",
size: 3
},
mask: "#### #### #### ####"
},
{
name: "Mastercard",
type: "mastercard",
patterns: [[51, 55], [22, 26], [270, 271], 2720],
lengths: [16],
code: {
name: "CVC",
size: 3
},
mask: "#### #### #### ####"
},
{
name: "American Express",
type: "americanExpress",
patterns: [34, 37],
lengths: [15],
code: {
name: "CID",
size: 4
},
mask: "#### ###### #####"
},
{
name: "Diners Club",
type: "dinersClub",
patterns: [[300, 305], 36, 38, 39],
lengths: [14, 16],
code: {
name: "CVV",
size: 3
},
mask: ["#### ###### ####", "#### #### #### ####"]
},
{
name: "Discover",
type: "discover",
patterns: [6011, [644, 649], 65],
lengths: [16],
code: {
name: "CID",
size: 3
},
mask: "#### #### #### ####"
},
{
name: "JCB",
type: "jcb",
patterns: [2131, 1800, [3528, 3589]],
lengths: [16],
code: {
name: "CVV",
size: 3
},
mask: "#### #### #### ####"
},
{
name: "UnionPay",
type: "unionpay",
patterns: [
62,
620,
[624, 626],
[62100, 62182],
[62184, 62187],
[62185, 62197],
[62200, 62205],
[622010, 622999],
622018,
[622019, 622999],
[62207, 62209],
[622126, 622925],
[623, 626],
6270,
6272,
6276,
[627700, 627779],
[627781, 627799],
[6282, 6289],
6291,
6292,
81,
810,
[8110, 8131],
[8132, 8151],
[8152, 8163],
[8164, 8171]
],
lengths: [16, 19],
code: {
name: "CVN",
size: 3
},
mask: ["#### #### #### ####", "#### #### #### #### ###"]
}
];
function c(e, t) {
if (Array.isArray(t)) {
const [a, s] = t, r = a.toString().length, i = parseInt(
e.substring(0, r)
);
return i >= a && i <= s;
}
const n = t.toString();
return n.substring(0, e.length) === e.substring(0, n.length);
}
function o(e) {
return e ? m.filter((n) => n.patterns.some(
(a) => c(e, a)
))[0] ?? null : null;
}
function p(e) {
const t = e.split("").map((s) => parseInt(s)), n = t.pop() ?? 0;
return (t.reduce(
(s, r, i) => i % 2 !== 0 ? s + r : s + ((r *= 2) > 9 ? r - 9 : r),
0
) + n) % 10 === 0;
}
export {
m as cardTypes,
o as getCardInfo,
p as luhnCheck,
c as matchCardNumberByPattern
};