├── .editorconfig ├── .gitattributes ├── .gitignore ├── .npmrc ├── .travis.yml ├── fixtures ├── americanexpress.json ├── dinersclub.json ├── discover.json ├── jcb.json ├── maestro.json ├── mastercard.json └── visa.json ├── index.js ├── license ├── package.json ├── readme.md └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [*.yml] 11 | indent_style = space 12 | indent_size = 2 13 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | yarn.lock 3 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | node_js: 4 | - '11' 5 | - '10' 6 | - '8' 7 | -------------------------------------------------------------------------------- /fixtures/americanexpress.json: -------------------------------------------------------------------------------- 1 | [ 2 | "370218180742397", 3 | "372397607726296", 4 | "372482095016127", 5 | "341654131598940", 6 | "342092383097700", 7 | "371402651431602", 8 | "373999470893076", 9 | "348191837276326", 10 | "376197788590172", 11 | "346194337569648", 12 | "377951329307689", 13 | "372415734651649", 14 | "373613056412512", 15 | "375288451660755", 16 | "376713785956958", 17 | "378058657531895", 18 | "348912094040554", 19 | "372768635162284", 20 | "346632468550770", 21 | "373685521521341", 22 | "375817754841348", 23 | "348966851780083", 24 | "347777522125421", 25 | "349082365069846", 26 | "343916697911348", 27 | "378520082867194", 28 | "347984305466671", 29 | "342685147120427", 30 | "340723981791862", 31 | "344817514023771", 32 | "342830796835509", 33 | "376069266668582", 34 | "376764385401200", 35 | "347152446306285", 36 | "344167801647183", 37 | "345308889956950", 38 | "348929599720209", 39 | "375644109378390", 40 | "348018790892650", 41 | "373991218892163", 42 | "371551085600776", 43 | "345447498250353", 44 | "344699158855845", 45 | "348154855484768", 46 | "349310688749657", 47 | "343652760053599", 48 | "348242338160863", 49 | "347752311305534", 50 | "374854187267040", 51 | "346486972534774", 52 | "379057933755426", 53 | "373627072029043", 54 | "346631500015479", 55 | "340569944549800", 56 | "348936046052318", 57 | "373631870860500", 58 | "340566993941557", 59 | "372290680943765", 60 | "370988386537367", 61 | "376208080529196", 62 | "373210001669526", 63 | "371512577090827", 64 | "347101108902352", 65 | "371462891308242", 66 | "372265190766732", 67 | "370197060112618", 68 | "349195302314545", 69 | "373802665267819", 70 | "370038047911864", 71 | "374950557820507", 72 | "349071148275796", 73 | "344553938560946", 74 | "343638174522543", 75 | "377155214180231", 76 | "370216480733827", 77 | "371720652370978", 78 | "373834919037706", 79 | "344711733496084", 80 | "346294472746199", 81 | "340779737476067", 82 | "342666765564286", 83 | "376611714089927", 84 | "340367730803196", 85 | "346003788945886", 86 | "374720528028716", 87 | "344653599831055", 88 | "370822632101621", 89 | "371612917183975", 90 | "374227887630736", 91 | "344701087539670", 92 | "378639972955453", 93 | "379883538029093", 94 | "345046751534089", 95 | "349618294754790", 96 | "375308525244178", 97 | "378673342630082", 98 | "370586993845650", 99 | "344566883297843", 100 | "379811393604866", 101 | "378167408666270" 102 | ] 103 | -------------------------------------------------------------------------------- /fixtures/dinersclub.json: -------------------------------------------------------------------------------- 1 | [ 2 | "38790546741937", 3 | "38222940456326", 4 | "30013425411771", 5 | "36138858636158", 6 | "30344187702499", 7 | "30134903513019", 8 | "30182600831036", 9 | "30174614385828", 10 | "30280689508598", 11 | "36446985630329", 12 | "38378773006495", 13 | "30181036023143", 14 | "30310636040708", 15 | "30045564908811", 16 | "30360914863404", 17 | "30208973022554", 18 | "30375947287447", 19 | "36316702373604", 20 | "30198656820376", 21 | "30001733808861", 22 | "30015028970913", 23 | "30153356302449", 24 | "30320689240238", 25 | "30147986570219", 26 | "38893498602634", 27 | "30179463446670", 28 | "30162699797827", 29 | "36227757217325", 30 | "38256376852905", 31 | "36055777287055", 32 | "36755520879112", 33 | "36909931973390", 34 | "30125797171344", 35 | "30172162676481", 36 | "30092108379679", 37 | "38512091997007", 38 | "30095612829386", 39 | "30335636218988", 40 | "30202382641492", 41 | "38763708280614", 42 | "30177358246072", 43 | "30222985778483", 44 | "38057488587656", 45 | "30025515526490", 46 | "30225928901237", 47 | "30230133872470", 48 | "36229365856015", 49 | "36363811610153", 50 | "30350055292083", 51 | "30079242677274", 52 | "30151746275572", 53 | "36506990305066", 54 | "36975152158730", 55 | "38765432739526", 56 | "30008319658115", 57 | "36013706113603", 58 | "30058729925463", 59 | "30106377344279", 60 | "30078786567784", 61 | "30278456417274", 62 | "36501414470901", 63 | "30171016912514", 64 | "38126658758445", 65 | "30227061614304", 66 | "30015417611680", 67 | "30030546723546", 68 | "30276696730126", 69 | "30121835140813", 70 | "30332154894357", 71 | "30022996511869", 72 | "30389478563399", 73 | "36884349480744", 74 | "30363129898769", 75 | "30250352998798", 76 | "30109554012834", 77 | "30153508815504", 78 | "36158002091001", 79 | "30082685831754", 80 | "30056149294064", 81 | "30126700356980", 82 | "36943208024686", 83 | "30343624704670", 84 | "30288744272217", 85 | "30085144535809", 86 | "30069253537939", 87 | "30327998984513", 88 | "38330985748885", 89 | "30187369901391", 90 | "36831116285541", 91 | "30359005922665", 92 | "30041471423267", 93 | "36682345780210", 94 | "30085603315602", 95 | "36125138511814", 96 | "30261570501330", 97 | "30278776365005", 98 | "30324306195536", 99 | "30042294360918", 100 | "30365910478776", 101 | "36695601420305" 102 | ] 103 | -------------------------------------------------------------------------------- /fixtures/discover.json: -------------------------------------------------------------------------------- 1 | [ 2 | "6011884976274192", 3 | "6011858691125798", 4 | "6011921167664177", 5 | "6011090478296606", 6 | "6011338322230549", 7 | "6011945643529803", 8 | "6011656495188503", 9 | "6011716817024354", 10 | "6011724626856891", 11 | "6011684224628946", 12 | "6011081926126677", 13 | "6011251580027277", 14 | "6011029093414764", 15 | "6011509862639675", 16 | "6011115152336186", 17 | "6011018291342216", 18 | "6011460360133722", 19 | "6011402600989349", 20 | "6011295020014692", 21 | "6011931074288531", 22 | "6011314874743965", 23 | "6011123737541171", 24 | "6011486230599685", 25 | "6011857548903316", 26 | "6011960765187843", 27 | "6011760438659768", 28 | "6011023138388133", 29 | "6011812961887405", 30 | "6011275497130437", 31 | "6011154083146950", 32 | "6011662103293933", 33 | "6011425573990333", 34 | "6011400522081187", 35 | "6011044380817314", 36 | "6011054480742809", 37 | "6011147604461619", 38 | "6011127701335221", 39 | "6011158209927805", 40 | "6011235232188611", 41 | "6011099925582542", 42 | "6011861544494163", 43 | "6011495313401537", 44 | "6011122380507851", 45 | "6011380673399945", 46 | "6011788389742028", 47 | "6011112832697004", 48 | "6011364873193274", 49 | "6011840412805825", 50 | "6011622884736948", 51 | "6011492176223694", 52 | "6011128544045571", 53 | "6011348877363157", 54 | "6011222524245325", 55 | "6011708960730242", 56 | "6011714277765954", 57 | "6011038088447820", 58 | "6011217905876805", 59 | "6011420653712509", 60 | "6011231617441345", 61 | "6011053914084879", 62 | "6011437685580712", 63 | "6011047167621866", 64 | "6011651409266131", 65 | "6011418311128860", 66 | "6011407550709720", 67 | "6011416886255514", 68 | "6011356868975749", 69 | "6011927524709613", 70 | "6011068682213013", 71 | "6011712393899996", 72 | "6011781670924975", 73 | "6011271875143068", 74 | "6011812882668827", 75 | "6011646011045493", 76 | "6011844327061235", 77 | "6011608976277628", 78 | "6011830803449952", 79 | "6011829587628500", 80 | "6011491102645251", 81 | "6011431982378797", 82 | "6011712077099152", 83 | "6011839169369803", 84 | "6011912679961409", 85 | "6011860934998288", 86 | "6011448462785093", 87 | "6011342256264391", 88 | "6011665338662335", 89 | "6011933526011982", 90 | "6011547175071434", 91 | "6011330539017058", 92 | "6011156372645170", 93 | "6011195232381485", 94 | "6011982592694171", 95 | "6011684165936613", 96 | "6011327668732119", 97 | "6011605229416656", 98 | "6011952623931470", 99 | "6011702594478120", 100 | "6011465651608985", 101 | "6011447020500978" 102 | ] 103 | -------------------------------------------------------------------------------- /fixtures/jcb.json: -------------------------------------------------------------------------------- 1 | [ 2 | "3588228280601429", 3 | "3595904764717581", 4 | "3517044967420371", 5 | "3509638449153029", 6 | "3501613748325634", 7 | "3528311268001383", 8 | "3532099731401165", 9 | "3510171805066657", 10 | "3511968673777847", 11 | "3560584305904566", 12 | "3518283478430458", 13 | "3534860787708409", 14 | "3515609696674548", 15 | "3502356338228706", 16 | "3598374787662346", 17 | "3536114212282194", 18 | "3514788054100683", 19 | "3546481842636349", 20 | "3583751792185370", 21 | "3537196961132075", 22 | "3513012927849249", 23 | "3533305571518938", 24 | "3571384417868644", 25 | "3586733325170449", 26 | "3553807314294458", 27 | "3597154732589120", 28 | "3569374936842166", 29 | "3518817907000281", 30 | "3590966189425806", 31 | "3510739349061192", 32 | "3534547416298494", 33 | "3501240409404472", 34 | "3556050494567859", 35 | "3582305218110321", 36 | "3557530183907523", 37 | "3553588663432853", 38 | "3580934034454662", 39 | "3539232628266069", 40 | "3563176969590547", 41 | "3586194643913228", 42 | "3557065823576297", 43 | "3566860673430168", 44 | "3514177016022294", 45 | "3563637374718577", 46 | "3512361216304056", 47 | "3599634223937092", 48 | "3528627074238079", 49 | "3588763656363196", 50 | "3547326175129868", 51 | "3504442587057752", 52 | "3582275743773465", 53 | "3563071096946383", 54 | "3596070307061710", 55 | "3549728694774082", 56 | "3540632109145764", 57 | "3549508741451110", 58 | "3508390977475868", 59 | "3561592334011112", 60 | "3518539658019696", 61 | "3532392232853996", 62 | "3592585784990572", 63 | "3518470022013779", 64 | "3572208867439011", 65 | "3559227698193958", 66 | "3589715112274945", 67 | "3529993092203845", 68 | "3506799835619099", 69 | "3506497941666639", 70 | "3535516392293661", 71 | "3577777841698582", 72 | "3583919643141914", 73 | "3526480851173974", 74 | "3523630973694751", 75 | "3599746221623787", 76 | "3543728038428961", 77 | "3531900441149310", 78 | "3582381990926515", 79 | "3583789262522987", 80 | "3529168966852205", 81 | "3545202979839907", 82 | "3529423350979068", 83 | "3549360069782159", 84 | "3596144907472690", 85 | "3580887094345768", 86 | "3502332035962855", 87 | "3574921746336723", 88 | "3596320230412674", 89 | "3559705631865543", 90 | "3542433765912573", 91 | "3527712709029779", 92 | "3581964879696209", 93 | "3585297914929020", 94 | "3537795293911831", 95 | "3520546122522995", 96 | "3597010205665690", 97 | "3587987656762666", 98 | "3511235128236716", 99 | "3587718314676794", 100 | "3500278409448074", 101 | "3509173789871493" 102 | ] 103 | -------------------------------------------------------------------------------- /fixtures/maestro.json: -------------------------------------------------------------------------------- 1 | [ 2 | "502027541337210000", 3 | "6762358882800094000", 4 | "6759727141520", 5 | "50382480225114500", 6 | "630494939456722", 7 | "6762344627111", 8 | "676234558943443", 9 | "676276833652893", 10 | "67616907081437", 11 | "6761173428256949000", 12 | "6759952211292109", 13 | "676185659178331", 14 | "63048359908434", 15 | "5018535756304964", 16 | "5018787121305994000", 17 | "676385920686084", 18 | "502051930746", 19 | "5020824829808294000", 20 | "6304019929449847000", 21 | "676191911822", 22 | "501814349244", 23 | "5018321871615", 24 | "6763850779997198000", 25 | "50203313556644800", 26 | "67599429209197300", 27 | "67593837250717460", 28 | "50206805235431", 29 | "6759328295678390", 30 | "630465211447241", 31 | "503878903546365", 32 | "6759327622187309000", 33 | "6759884573618073000", 34 | "502069681778", 35 | "676378824806", 36 | "50386072153986", 37 | "50180199881664", 38 | "50184966346683656", 39 | "675919690991999700", 40 | "675913719444000", 41 | "503877948818912", 42 | "676207088615", 43 | "5018918363466834000", 44 | "50380161961779640", 45 | "502021915550218600", 46 | "676173599696869", 47 | "503836019101756800", 48 | "6762422905495181", 49 | "5020557928029047000", 50 | "6304899019174122", 51 | "675954502539", 52 | "5018606073118906", 53 | "676227191225", 54 | "67617198442502", 55 | "6763693904795503", 56 | "67621744018725", 57 | "67616192187880780", 58 | "6759801874059554", 59 | "50183309029240", 60 | "676125004660", 61 | "50387242292842270", 62 | "67597656893828", 63 | "6763235861686915000", 64 | "6763271547006040", 65 | "67594457044115", 66 | "503815335388003600", 67 | "6304440975433473", 68 | "67629140774202120", 69 | "503861826335181", 70 | "501814191015187", 71 | "5038148251622546", 72 | "6763849754995807000", 73 | "676293931192815400", 74 | "63044921460426", 75 | "6763992771065184", 76 | "630466901436452", 77 | "6762284479472143000", 78 | "67630476077213", 79 | "5018666585932979000", 80 | "6304055359020702", 81 | "5038015681531861000", 82 | "503808563823853", 83 | "63045656812627944", 84 | "6761522772628003", 85 | "50189676141724", 86 | "503896890459", 87 | "67597349078079380", 88 | "6759375548950", 89 | "6762366812595098", 90 | "67597647022169720", 91 | "6304193639211476", 92 | "501879647391", 93 | "63041748610175", 94 | "5020074006159", 95 | "50386023406343", 96 | "6763233853035138", 97 | "50384326969561810", 98 | "502047309748386", 99 | "67633006740009700", 100 | "63041344891195", 101 | "5018493270581155000" 102 | ] 103 | -------------------------------------------------------------------------------- /fixtures/mastercard.json: -------------------------------------------------------------------------------- 1 | [ 2 | "5536838507150030", 3 | "5260891164772911", 4 | "5219396629575596", 5 | "5435792276222979", 6 | "5349683774181608", 7 | "5577610446089177", 8 | "5297896944964610", 9 | "5117806760949197", 10 | "5490187796108117", 11 | "5217626328263918", 12 | "5390685782690841", 13 | "5372158344838607", 14 | "5357802498006086", 15 | "5302873782966414", 16 | "5432694781560666", 17 | "5256483758452484", 18 | "5296771877328607", 19 | "5458106790139001", 20 | "5451471742241223", 21 | "5595716436444971", 22 | "5452299782304240", 23 | "5372266428748400", 24 | "5566035285463874", 25 | "5575816185015800", 26 | "5190294492979057", 27 | "5259449135981534", 28 | "5208711983560757", 29 | "5423419697275592", 30 | "5243013511486051", 31 | "5202407772096667", 32 | "5212801665713909", 33 | "5529622568274197", 34 | "5504669498465766", 35 | "5499045604817991", 36 | "5598394594545653", 37 | "5263023235146357", 38 | "5435718869400300", 39 | "5396562973093412", 40 | "5513748171410189", 41 | "5174991074232710", 42 | "5502922443657801", 43 | "5353949267147767", 44 | "5453264155384327", 45 | "5145986912837270", 46 | "5396441033589604", 47 | "5160006478386156", 48 | "5330162648309381", 49 | "5230152175034040", 50 | "5588643403734219", 51 | "5136967791922426", 52 | "5181463080573298", 53 | "5101180469895665", 54 | "5474766043969395", 55 | "5146623048274883", 56 | "5278448436295187", 57 | "5417430669776655", 58 | "5319849031635407", 59 | "5599444012282808", 60 | "5363604946057519", 61 | "5263466846780231", 62 | "5314331071533102", 63 | "5202714872774485", 64 | "5155916107663253", 65 | "5517418148174807", 66 | "5373349654623585", 67 | "5149386090033865", 68 | "5263156791653612", 69 | "5555032023810121", 70 | "5122772305838274", 71 | "5566845195684371", 72 | "5597880768481676", 73 | "5195531812782157", 74 | "5449255578598391", 75 | "5313321894379289", 76 | "5417860141037468", 77 | "5525322032860671", 78 | "5494064234683009", 79 | "5569369327472834", 80 | "5410386461213643", 81 | "5471224475630641", 82 | "5181922152059932", 83 | "5155200104835358", 84 | "5251107874108150", 85 | "5308334582188612", 86 | "5176634854329680", 87 | "5123262119535570", 88 | "5523830524613020", 89 | "5571588167101221", 90 | "5483877699248544", 91 | "5583821126483737", 92 | "5531473562490116", 93 | "5178886927025319", 94 | "5511118280506651", 95 | "5532049603870414", 96 | "5491171986144180", 97 | "5184188640713756", 98 | "5206047820883843", 99 | "5337127009619341", 100 | "5371220244253435", 101 | "5495177150592373", 102 | "2221000010000015", 103 | "2720000010000015", 104 | "2222222222222224" 105 | ] 106 | -------------------------------------------------------------------------------- /fixtures/visa.json: -------------------------------------------------------------------------------- 1 | [ 2 | "4929588303328334", 3 | "4485437888912417", 4 | "4532692223025787", 5 | "4916221628582840", 6 | "4592721164494293", 7 | "4539975709814839", 8 | "4532418210097567", 9 | "4716406353172154", 10 | "4485947519538035", 11 | "4929440894207727", 12 | "4930044324233076", 13 | "4485723036499344", 14 | "4716613874968420", 15 | "4532415899808058", 16 | "4532672695295928", 17 | "4929210340880140", 18 | "4539826513725200", 19 | "4916249536661414", 20 | "4539771202755144", 21 | "4916421121026739", 22 | "4485888173178355", 23 | "4556376826875803", 24 | "4929106283010218", 25 | "4532502918647540", 26 | "4024007128455408", 27 | "4716107297128399", 28 | "4556394972337429", 29 | "4532027029516541", 30 | "4929190825222606", 31 | "4532293167003920", 32 | "4716963972520411", 33 | "4485977099772894", 34 | "4916728774703764", 35 | "4024007181672923", 36 | "4485226628264225", 37 | "4929079715032854", 38 | "4024007110199311", 39 | "4539771291609756", 40 | "4485237212976819", 41 | "4532417396542560", 42 | "4716096632244773", 43 | "4556854952406924", 44 | "4539908932472844", 45 | "4916530404602337", 46 | "4916523516367741", 47 | "4716856966978498", 48 | "4929136180018345", 49 | "4929649371963202", 50 | "4916707385890624", 51 | "4532132357353812", 52 | "4916299250374579", 53 | "4556491588633918", 54 | "4539203380637381", 55 | "4716656691242677", 56 | "4556666139035040", 57 | "4024007123152513", 58 | "4916647417587642", 59 | "4485444266027933", 60 | "4716532274017960", 61 | "4916430555176878", 62 | "4916783532405806", 63 | "4485941195852356", 64 | "4539931306128958", 65 | "4024007186901178", 66 | "4024007184254323", 67 | "4716807184661317", 68 | "4024007177507240", 69 | "4485758702691360", 70 | "4532674087660396", 71 | "4929568943565412", 72 | "4485445091782642", 73 | "4929016876950748", 74 | "4024007111243837", 75 | "4532992681689516", 76 | "4916667883714157", 77 | "4716272821190644", 78 | "4916681243851823", 79 | "4024007175989879", 80 | "4024007122737256", 81 | "4539338059928859", 82 | "4929587680741648", 83 | "4024007109123405", 84 | "4716944232327458", 85 | "4556779646210285", 86 | "4485853279220881", 87 | "4916053087916155", 88 | "4962307073648658", 89 | "4916404516214896", 90 | "4485347248936958", 91 | "4532530908643039", 92 | "4532950681783838", 93 | "4556861884882239", 94 | "4024007125124809", 95 | "4532859860303948", 96 | "4439008940377951", 97 | "4929577975332997", 98 | "4485435809947157", 99 | "4485368499956834", 100 | "4024007197879066", 101 | "4485486015130583", 102 | "4532909111526", 103 | "4741291174816", 104 | "4929361503127", 105 | "4485984775311", 106 | "4716483022460", 107 | "4302541043952", 108 | "4024007141761", 109 | "4024007121441", 110 | "4469852967069", 111 | "4532518404734", 112 | "4929866522176", 113 | "4556305950682", 114 | "4344263476309", 115 | "4556693417336", 116 | "4716502088021", 117 | "4024007181239", 118 | "4485116356097", 119 | "4716907584020", 120 | "4929677216448", 121 | "4736370527363", 122 | "4556997236424", 123 | "4556421836161", 124 | "4916492600443", 125 | "4024007150937", 126 | "4916110357632", 127 | "4532407248671", 128 | "4716278866535", 129 | "4916224885973", 130 | "4024007114404", 131 | "4984795323337", 132 | "4716390684733", 133 | "4716155644773", 134 | "4024007121789", 135 | "4532709792871", 136 | "4539436145760", 137 | "4485768413774", 138 | "4532176663514", 139 | "4485581484697", 140 | "4690646821706", 141 | "4024007192145", 142 | "4024007133081", 143 | "4916776202882", 144 | "4556499683164", 145 | "4916889209774", 146 | "4485556088234", 147 | "4716682081044", 148 | "4539339457007", 149 | "4532164415976", 150 | "4024007137918", 151 | "4916267946831", 152 | "4556209811808", 153 | "4532337001398", 154 | "4556678951697", 155 | "4539827541213", 156 | "4916592795267", 157 | "4485648464104", 158 | "4787922344773", 159 | "4539788150657", 160 | "4539719978796", 161 | "4556938601009", 162 | "4485555933000", 163 | "4716765034050", 164 | "4916830113828", 165 | "4916337125382", 166 | "4929267239479", 167 | "4716979170401", 168 | "4018093174595", 169 | "4929038224685", 170 | "4532845352978", 171 | "4916759708483", 172 | "4532282225257", 173 | "4539003611947", 174 | "4916069787466", 175 | "4556494398735", 176 | "4716673541576", 177 | "4532219030267", 178 | "4485247867798", 179 | "4485705499704", 180 | "4916780786227", 181 | "4929914739855", 182 | "4556067764917", 183 | "4811834114585", 184 | "4499592676373", 185 | "4897089743830", 186 | "4929703690087", 187 | "4532500956212", 188 | "4485025892059", 189 | "4539716164945", 190 | "4916998482858", 191 | "4716662031894", 192 | "4716534339749", 193 | "4716643010793", 194 | "4024007148402", 195 | "4716388064849", 196 | "4556819371912", 197 | "4532078648811", 198 | "4716919304110", 199 | "4716357073581", 200 | "4916699504323", 201 | "4916505486228" 202 | ] 203 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const americanExpress = '(?:3[47][0-9]{13})'; 3 | const dinersClub = '(?:3(?:0[0-5]|[68][0-9])[0-9]{11})'; 4 | const discover = '(?:6(?:011|5[0-9]{2})(?:[0-9]{12}))'; 5 | const jcb = '(?:(?:2131|1800|35\\d{3})\\d{11})'; 6 | const maestro = '(?:(?:5[0678]\\d\\d|6304|6390|67\\d\\d)\\d{8,15})'; 7 | const mastercard = '(?:(?:5[1-5][0-9]{2}|222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12})'; 8 | const visa = '(?:4[0-9]{12})(?:[0-9]{3})?'; 9 | 10 | const generate = pattern => (opts = {}) => opts.exact ? new RegExp(`(?:^${pattern}$)`) : new RegExp(pattern, 'g'); 11 | 12 | module.exports = generate([ 13 | americanExpress, 14 | dinersClub, 15 | discover, 16 | jcb, 17 | maestro, 18 | mastercard, 19 | visa 20 | ].join('|')); 21 | 22 | module.exports.americanExpress = generate(americanExpress); 23 | module.exports.dinersClub = generate(dinersClub); 24 | module.exports.discover = generate(discover); 25 | module.exports.jcb = generate(jcb); 26 | module.exports.maestro = generate(maestro); 27 | module.exports.mastercard = generate(mastercard); 28 | module.exports.visa = generate(visa); 29 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Kevin Mårtensson (github.com/kevva) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "credit-card-regex", 3 | "version": "3.0.0", 4 | "description": "Regular expression for matching credit card numbers", 5 | "license": "MIT", 6 | "repository": "kevva/credit-card-regex", 7 | "author": { 8 | "name": "Kevin Mårtensson", 9 | "email": "kevinmartensson@gmail.com", 10 | "url": "https://github.com/kevva" 11 | }, 12 | "engines": { 13 | "node": ">=8" 14 | }, 15 | "scripts": { 16 | "test": "xo && ava" 17 | }, 18 | "files": [ 19 | "index.js" 20 | ], 21 | "keywords": [ 22 | "americanexpress", 23 | "creditcard", 24 | "dinersclub", 25 | "discover", 26 | "jcb", 27 | "maestro", 28 | "mastercard", 29 | "number", 30 | "regex", 31 | "string", 32 | "visa" 33 | ], 34 | "devDependencies": { 35 | "ava": "*", 36 | "xo": "*" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # credit-card-regex [![Build Status](https://travis-ci.org/kevva/credit-card-regex.svg?branch=master)](https://travis-ci.org/kevva/credit-card-regex) 2 | 3 | > Regular expression for matching credit card numbers 4 | 5 | 6 | ## Install 7 | 8 | ``` 9 | $ npm install credit-card-regex 10 | ``` 11 | 12 | 13 | ## Usage 14 | 15 | ```js 16 | const creditCardRegex = require('credit-card-regex'); 17 | 18 | creditCardRegex().test('6011881485017922 foo bar'); 19 | //=> true 20 | 21 | creditCardRegex({exact: true}).test('6011881485017922 foo bar'); 22 | //=> false 23 | 24 | creditCardRegex({exact: true}).test('6011881485017922'); 25 | //=> true 26 | 27 | 'foo 6011881485017922 bar 5441068611005540'.match(creditCardRegex()); 28 | //=> ['6011881485017922', '5441068611005540'] 29 | ``` 30 | 31 | 32 | ## API 33 | 34 | ### creditCardRegex(options) 35 | 36 | Returns a regex for matching credit card numbers. It supports credit card numbers from the following vendors: 37 | 38 | * American Express 39 | * Diners Club 40 | * Discover 41 | * JCB 42 | * Maestro 43 | * MasterCard 44 | * VISA 45 | 46 | #### options 47 | 48 | ##### exact 49 | 50 | Type: `Boolean`
51 | Default: `false` *(Matches any credit card number in a string)* 52 | 53 | Only match an exact string. Useful with `RegExp#test` to check if a string is a credit card number. 54 | 55 | 56 | ## License 57 | 58 | MIT © [Kevin Mårtensson](https://github.com/kevva) 59 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | import test from 'ava'; 2 | import creditCardRegex from '.'; 3 | 4 | test('match credit card numbers', t => { 5 | const fixtures = [].concat( 6 | require('./fixtures/americanexpress.json'), 7 | require('./fixtures/dinersclub.json'), 8 | require('./fixtures/discover.json'), 9 | require('./fixtures/jcb.json'), 10 | require('./fixtures/maestro.json'), 11 | require('./fixtures/mastercard.json'), 12 | require('./fixtures/visa.json') 13 | ); 14 | 15 | for (const x of fixtures) { 16 | t.true(creditCardRegex({exact: true}).test(x)); 17 | } 18 | }); 19 | --------------------------------------------------------------------------------