validator.js 184 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562
  1. /*!
  2. * Copyright (c) 2018 Chris O'Hara <cohara87@gmail.com>
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining
  5. * a copy of this software and associated documentation files (the
  6. * "Software"), to deal in the Software without restriction, including
  7. * without limitation the rights to use, copy, modify, merge, publish,
  8. * distribute, sublicense, and/or sell copies of the Software, and to
  9. * permit persons to whom the Software is furnished to do so, subject to
  10. * the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be
  13. * included in all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  19. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  20. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  21. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. (function (global, factory) {
  24. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  25. typeof define === 'function' && define.amd ? define(factory) :
  26. (global.validator = factory());
  27. }(this, (function () { 'use strict';
  28. function old_createMetadataMethodsForProperty(e, t, a, r) {
  29. return {
  30. getMetadata: function (o) {
  31. old_assertNotFinished(r, "getMetadata"), old_assertMetadataKey(o);
  32. var i = e[o];
  33. if (void 0 !== i) if (1 === t) {
  34. var n = i.public;
  35. if (void 0 !== n) return n[a];
  36. } else if (2 === t) {
  37. var l = i.private;
  38. if (void 0 !== l) return l.get(a);
  39. } else if (Object.hasOwnProperty.call(i, "constructor")) return i.constructor;
  40. },
  41. setMetadata: function (o, i) {
  42. old_assertNotFinished(r, "setMetadata"), old_assertMetadataKey(o);
  43. var n = e[o];
  44. if (void 0 === n && (n = e[o] = {}), 1 === t) {
  45. var l = n.public;
  46. void 0 === l && (l = n.public = {}), l[a] = i;
  47. } else if (2 === t) {
  48. var s = n.priv;
  49. void 0 === s && (s = n.private = new Map()), s.set(a, i);
  50. } else n.constructor = i;
  51. }
  52. };
  53. }
  54. function old_createAddInitializerMethod(e, t) {
  55. return function (a) {
  56. old_assertNotFinished(t, "addInitializer"), old_assertCallable(a, "An initializer"), e.push(a);
  57. };
  58. }
  59. function old_memberDec(e, t, a, r, o, i, n, l, s) {
  60. var c;
  61. switch (i) {
  62. case 1:
  63. c = "accessor";
  64. break;
  65. case 2:
  66. c = "method";
  67. break;
  68. case 3:
  69. c = "getter";
  70. break;
  71. case 4:
  72. c = "setter";
  73. break;
  74. default:
  75. c = "field";
  76. }
  77. var d,
  78. u,
  79. f = {
  80. kind: c,
  81. name: l ? "#" + t : _toPropertyKey(t),
  82. isStatic: n,
  83. isPrivate: l
  84. },
  85. p = {
  86. v: !1
  87. };
  88. if (0 !== i && (f.addInitializer = old_createAddInitializerMethod(o, p)), l) {
  89. d = 2, u = Symbol(t);
  90. var v = {};
  91. 0 === i ? (v.get = a.get, v.set = a.set) : 2 === i ? v.get = function () {
  92. return a.value;
  93. } : (1 !== i && 3 !== i || (v.get = function () {
  94. return a.get.call(this);
  95. }), 1 !== i && 4 !== i || (v.set = function (e) {
  96. a.set.call(this, e);
  97. })), f.access = v;
  98. } else d = 1, u = t;
  99. try {
  100. return e(s, Object.assign(f, old_createMetadataMethodsForProperty(r, d, u, p)));
  101. } finally {
  102. p.v = !0;
  103. }
  104. }
  105. function old_assertNotFinished(e, t) {
  106. if (e.v) throw Error("attempted to call " + t + " after decoration was finished");
  107. }
  108. function old_assertMetadataKey(e) {
  109. if ("symbol" != typeof e) throw new TypeError("Metadata keys must be symbols, received: " + e);
  110. }
  111. function old_assertCallable(e, t) {
  112. if ("function" != typeof e) throw new TypeError(t + " must be a function");
  113. }
  114. function old_assertValidReturnValue(e, t) {
  115. var a = typeof t;
  116. if (1 === e) {
  117. if ("object" !== a || null === t) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
  118. void 0 !== t.get && old_assertCallable(t.get, "accessor.get"), void 0 !== t.set && old_assertCallable(t.set, "accessor.set"), void 0 !== t.init && old_assertCallable(t.init, "accessor.init"), void 0 !== t.initializer && old_assertCallable(t.initializer, "accessor.initializer");
  119. } else if ("function" !== a) throw new TypeError((0 === e ? "field" : 10 === e ? "class" : "method") + " decorators must return a function or void 0");
  120. }
  121. function old_getInit(e) {
  122. var t;
  123. return null == (t = e.init) && (t = e.initializer) && void 0 !== console && console.warn(".initializer has been renamed to .init as of March 2022"), t;
  124. }
  125. function _iterableToArrayLimit(r, l) {
  126. var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
  127. if (null != t) {
  128. var e,
  129. n,
  130. i,
  131. u,
  132. a = [],
  133. f = !0,
  134. o = !1;
  135. try {
  136. if (i = (t = t.call(r)).next, 0 === l) {
  137. if (Object(t) !== t) return;
  138. f = !1;
  139. } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
  140. } catch (r) {
  141. o = !0, n = r;
  142. } finally {
  143. try {
  144. if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
  145. } finally {
  146. if (o) throw n;
  147. }
  148. }
  149. return a;
  150. }
  151. }
  152. function _setFunctionName(e, t, n) {
  153. "symbol" == typeof t && (t = (t = t.description) ? "[" + t + "]" : "");
  154. try {
  155. Object.defineProperty(e, "name", {
  156. configurable: !0,
  157. value: n ? n + " " + t : t
  158. });
  159. } catch (e) {}
  160. return e;
  161. }
  162. function _toPrimitive(t, r) {
  163. if ("object" != typeof t || !t) return t;
  164. var e = t[Symbol.toPrimitive];
  165. if (void 0 !== e) {
  166. var i = e.call(t, r || "default");
  167. if ("object" != typeof i) return i;
  168. throw new TypeError("@@toPrimitive must return a primitive value.");
  169. }
  170. return ("string" === r ? String : Number)(t);
  171. }
  172. function _toPropertyKey(t) {
  173. var i = _toPrimitive(t, "string");
  174. return "symbol" == typeof i ? i : i + "";
  175. }
  176. function _typeof(o) {
  177. "@babel/helpers - typeof";
  178. return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
  179. return typeof o;
  180. } : function (o) {
  181. return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
  182. }, _typeof(o);
  183. }
  184. function _slicedToArray(arr, i) {
  185. return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
  186. }
  187. function _toConsumableArray(arr) {
  188. return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
  189. }
  190. function _arrayWithoutHoles(arr) {
  191. if (Array.isArray(arr)) return _arrayLikeToArray(arr);
  192. }
  193. function _arrayWithHoles(arr) {
  194. if (Array.isArray(arr)) return arr;
  195. }
  196. function _iterableToArray(iter) {
  197. if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
  198. }
  199. function _unsupportedIterableToArray(o, minLen) {
  200. if (!o) return;
  201. if (typeof o === "string") return _arrayLikeToArray(o, minLen);
  202. var n = Object.prototype.toString.call(o).slice(8, -1);
  203. if (n === "Object" && o.constructor) n = o.constructor.name;
  204. if (n === "Map" || n === "Set") return Array.from(o);
  205. if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
  206. }
  207. function _arrayLikeToArray(arr, len) {
  208. if (len == null || len > arr.length) len = arr.length;
  209. for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
  210. return arr2;
  211. }
  212. function _nonIterableSpread() {
  213. throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  214. }
  215. function _nonIterableRest() {
  216. throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  217. }
  218. function _createForOfIteratorHelper(o, allowArrayLike) {
  219. var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
  220. if (!it) {
  221. if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
  222. if (it) o = it;
  223. var i = 0;
  224. var F = function () {};
  225. return {
  226. s: F,
  227. n: function () {
  228. if (i >= o.length) return {
  229. done: true
  230. };
  231. return {
  232. done: false,
  233. value: o[i++]
  234. };
  235. },
  236. e: function (e) {
  237. throw e;
  238. },
  239. f: F
  240. };
  241. }
  242. throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  243. }
  244. var normalCompletion = true,
  245. didErr = false,
  246. err;
  247. return {
  248. s: function () {
  249. it = it.call(o);
  250. },
  251. n: function () {
  252. var step = it.next();
  253. normalCompletion = step.done;
  254. return step;
  255. },
  256. e: function (e) {
  257. didErr = true;
  258. err = e;
  259. },
  260. f: function () {
  261. try {
  262. if (!normalCompletion && it.return != null) it.return();
  263. } finally {
  264. if (didErr) throw err;
  265. }
  266. }
  267. };
  268. }
  269. function assertString(input) {
  270. var isString = typeof input === 'string' || input instanceof String;
  271. if (!isString) {
  272. var invalidType = _typeof(input);
  273. if (input === null) invalidType = 'null';else if (invalidType === 'object') invalidType = input.constructor.name;
  274. throw new TypeError("Expected a string but received a ".concat(invalidType));
  275. }
  276. }
  277. function toDate(date) {
  278. assertString(date);
  279. date = Date.parse(date);
  280. return !isNaN(date) ? new Date(date) : null;
  281. }
  282. var alpha = {
  283. 'en-US': /^[A-Z]+$/i,
  284. 'az-AZ': /^[A-VXYZÇƏĞİıÖŞÜ]+$/i,
  285. 'bg-BG': /^[А-Я]+$/i,
  286. 'cs-CZ': /^[A-ZÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ]+$/i,
  287. 'da-DK': /^[A-ZÆØÅ]+$/i,
  288. 'de-DE': /^[A-ZÄÖÜß]+$/i,
  289. 'el-GR': /^[Α-ώ]+$/i,
  290. 'es-ES': /^[A-ZÁÉÍÑÓÚÜ]+$/i,
  291. 'fa-IR': /^[ابپتثجچحخدذرزژسشصضطظعغفقکگلمنوهی]+$/i,
  292. 'fi-FI': /^[A-ZÅÄÖ]+$/i,
  293. 'fr-FR': /^[A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i,
  294. 'it-IT': /^[A-ZÀÉÈÌÎÓÒÙ]+$/i,
  295. 'ja-JP': /^[ぁ-んァ-ヶヲ-゚一-龠ー・。、]+$/i,
  296. 'nb-NO': /^[A-ZÆØÅ]+$/i,
  297. 'nl-NL': /^[A-ZÁÉËÏÓÖÜÚ]+$/i,
  298. 'nn-NO': /^[A-ZÆØÅ]+$/i,
  299. 'hu-HU': /^[A-ZÁÉÍÓÖŐÚÜŰ]+$/i,
  300. 'pl-PL': /^[A-ZĄĆĘŚŁŃÓŻŹ]+$/i,
  301. 'pt-PT': /^[A-ZÃÁÀÂÄÇÉÊËÍÏÕÓÔÖÚÜ]+$/i,
  302. 'ru-RU': /^[А-ЯЁ]+$/i,
  303. 'kk-KZ': /^[А-ЯЁ\u04D8\u04B0\u0406\u04A2\u0492\u04AE\u049A\u04E8\u04BA]+$/i,
  304. 'sl-SI': /^[A-ZČĆĐŠŽ]+$/i,
  305. 'sk-SK': /^[A-ZÁČĎÉÍŇÓŠŤÚÝŽĹŔĽÄÔ]+$/i,
  306. 'sr-RS@latin': /^[A-ZČĆŽŠĐ]+$/i,
  307. 'sr-RS': /^[А-ЯЂЈЉЊЋЏ]+$/i,
  308. 'sv-SE': /^[A-ZÅÄÖ]+$/i,
  309. 'th-TH': /^[ก-๐\s]+$/i,
  310. 'tr-TR': /^[A-ZÇĞİıÖŞÜ]+$/i,
  311. 'uk-UA': /^[А-ЩЬЮЯЄIЇҐі]+$/i,
  312. 'vi-VN': /^[A-ZÀÁẠẢÃÂẦẤẬẨẪĂẰẮẶẲẴĐÈÉẸẺẼÊỀẾỆỂỄÌÍỊỈĨÒÓỌỎÕÔỒỐỘỔỖƠỜỚỢỞỠÙÚỤỦŨƯỪỨỰỬỮỲÝỴỶỸ]+$/i,
  313. 'ko-KR': /^[ㄱ-ㅎㅏ-ㅣ가-힣]*$/,
  314. 'ku-IQ': /^[ئابپتجچحخدرڕزژسشعغفڤقکگلڵمنوۆھەیێيطؤثآإأكضصةظذ]+$/i,
  315. ar: /^[ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/,
  316. he: /^[א-ת]+$/,
  317. fa: /^['آاءأؤئبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهةی']+$/i,
  318. bn: /^['ঀঁংঃঅআইঈউঊঋঌএঐওঔকখগঘঙচছজঝঞটঠডঢণতথদধনপফবভমযরলশষসহ়ঽািীুূৃৄেৈোৌ্ৎৗড়ঢ়য়ৠৡৢৣৰৱ৲৳৴৵৶৷৸৹৺৻']+$/,
  319. eo: /^[ABCĈD-GĜHĤIJĴK-PRSŜTUŬVZ]+$/i,
  320. 'hi-IN': /^[\u0900-\u0961]+[\u0972-\u097F]*$/i,
  321. 'si-LK': /^[\u0D80-\u0DFF]+$/
  322. };
  323. var alphanumeric = {
  324. 'en-US': /^[0-9A-Z]+$/i,
  325. 'az-AZ': /^[0-9A-VXYZÇƏĞİıÖŞÜ]+$/i,
  326. 'bg-BG': /^[0-9А-Я]+$/i,
  327. 'cs-CZ': /^[0-9A-ZÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ]+$/i,
  328. 'da-DK': /^[0-9A-ZÆØÅ]+$/i,
  329. 'de-DE': /^[0-9A-ZÄÖÜß]+$/i,
  330. 'el-GR': /^[0-9Α-ω]+$/i,
  331. 'es-ES': /^[0-9A-ZÁÉÍÑÓÚÜ]+$/i,
  332. 'fi-FI': /^[0-9A-ZÅÄÖ]+$/i,
  333. 'fr-FR': /^[0-9A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i,
  334. 'it-IT': /^[0-9A-ZÀÉÈÌÎÓÒÙ]+$/i,
  335. 'ja-JP': /^[0-90-9ぁ-んァ-ヶヲ-゚一-龠ー・。、]+$/i,
  336. 'hu-HU': /^[0-9A-ZÁÉÍÓÖŐÚÜŰ]+$/i,
  337. 'nb-NO': /^[0-9A-ZÆØÅ]+$/i,
  338. 'nl-NL': /^[0-9A-ZÁÉËÏÓÖÜÚ]+$/i,
  339. 'nn-NO': /^[0-9A-ZÆØÅ]+$/i,
  340. 'pl-PL': /^[0-9A-ZĄĆĘŚŁŃÓŻŹ]+$/i,
  341. 'pt-PT': /^[0-9A-ZÃÁÀÂÄÇÉÊËÍÏÕÓÔÖÚÜ]+$/i,
  342. 'ru-RU': /^[0-9А-ЯЁ]+$/i,
  343. 'kk-KZ': /^[0-9А-ЯЁ\u04D8\u04B0\u0406\u04A2\u0492\u04AE\u049A\u04E8\u04BA]+$/i,
  344. 'sl-SI': /^[0-9A-ZČĆĐŠŽ]+$/i,
  345. 'sk-SK': /^[0-9A-ZÁČĎÉÍŇÓŠŤÚÝŽĹŔĽÄÔ]+$/i,
  346. 'sr-RS@latin': /^[0-9A-ZČĆŽŠĐ]+$/i,
  347. 'sr-RS': /^[0-9А-ЯЂЈЉЊЋЏ]+$/i,
  348. 'sv-SE': /^[0-9A-ZÅÄÖ]+$/i,
  349. 'th-TH': /^[ก-๙\s]+$/i,
  350. 'tr-TR': /^[0-9A-ZÇĞİıÖŞÜ]+$/i,
  351. 'uk-UA': /^[0-9А-ЩЬЮЯЄIЇҐі]+$/i,
  352. 'ko-KR': /^[0-9ㄱ-ㅎㅏ-ㅣ가-힣]*$/,
  353. 'ku-IQ': /^[٠١٢٣٤٥٦٧٨٩0-9ئابپتجچحخدرڕزژسشعغفڤقکگلڵمنوۆھەیێيطؤثآإأكضصةظذ]+$/i,
  354. 'vi-VN': /^[0-9A-ZÀÁẠẢÃÂẦẤẬẨẪĂẰẮẶẲẴĐÈÉẸẺẼÊỀẾỆỂỄÌÍỊỈĨÒÓỌỎÕÔỒỐỘỔỖƠỜỚỢỞỠÙÚỤỦŨƯỪỨỰỬỮỲÝỴỶỸ]+$/i,
  355. ar: /^[٠١٢٣٤٥٦٧٨٩0-9ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/,
  356. he: /^[0-9א-ת]+$/,
  357. fa: /^['0-9آاءأؤئبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهةی۱۲۳۴۵۶۷۸۹۰']+$/i,
  358. bn: /^['ঀঁংঃঅআইঈউঊঋঌএঐওঔকখগঘঙচছজঝঞটঠডঢণতথদধনপফবভমযরলশষসহ়ঽািীুূৃৄেৈোৌ্ৎৗড়ঢ়য়ৠৡৢৣ০১২৩৪৫৬৭৮৯ৰৱ৲৳৴৵৶৷৸৹৺৻']+$/,
  359. eo: /^[0-9ABCĈD-GĜHĤIJĴK-PRSŜTUŬVZ]+$/i,
  360. 'hi-IN': /^[\u0900-\u0963]+[\u0966-\u097F]*$/i,
  361. 'si-LK': /^[0-9\u0D80-\u0DFF]+$/
  362. };
  363. var decimal = {
  364. 'en-US': '.',
  365. ar: '٫'
  366. };
  367. var englishLocales = ['AU', 'GB', 'HK', 'IN', 'NZ', 'ZA', 'ZM'];
  368. for (var locale, i = 0; i < englishLocales.length; i++) {
  369. locale = "en-".concat(englishLocales[i]);
  370. alpha[locale] = alpha['en-US'];
  371. alphanumeric[locale] = alphanumeric['en-US'];
  372. decimal[locale] = decimal['en-US'];
  373. }
  374. // Source: http://www.localeplanet.com/java/
  375. var arabicLocales = ['AE', 'BH', 'DZ', 'EG', 'IQ', 'JO', 'KW', 'LB', 'LY', 'MA', 'QM', 'QA', 'SA', 'SD', 'SY', 'TN', 'YE'];
  376. for (var _locale, _i = 0; _i < arabicLocales.length; _i++) {
  377. _locale = "ar-".concat(arabicLocales[_i]);
  378. alpha[_locale] = alpha.ar;
  379. alphanumeric[_locale] = alphanumeric.ar;
  380. decimal[_locale] = decimal.ar;
  381. }
  382. var farsiLocales = ['IR', 'AF'];
  383. for (var _locale2, _i2 = 0; _i2 < farsiLocales.length; _i2++) {
  384. _locale2 = "fa-".concat(farsiLocales[_i2]);
  385. alphanumeric[_locale2] = alphanumeric.fa;
  386. decimal[_locale2] = decimal.ar;
  387. }
  388. var bengaliLocales = ['BD', 'IN'];
  389. for (var _locale3, _i3 = 0; _i3 < bengaliLocales.length; _i3++) {
  390. _locale3 = "bn-".concat(bengaliLocales[_i3]);
  391. alpha[_locale3] = alpha.bn;
  392. alphanumeric[_locale3] = alphanumeric.bn;
  393. decimal[_locale3] = decimal['en-US'];
  394. }
  395. // Source: https://en.wikipedia.org/wiki/Decimal_mark
  396. var dotDecimal = ['ar-EG', 'ar-LB', 'ar-LY'];
  397. var commaDecimal = ['bg-BG', 'cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'en-ZM', 'eo', 'es-ES', 'fr-CA', 'fr-FR', 'id-ID', 'it-IT', 'ku-IQ', 'hi-IN', 'hu-HU', 'nb-NO', 'nn-NO', 'nl-NL', 'pl-PL', 'pt-PT', 'ru-RU', 'kk-KZ', 'si-LK', 'sl-SI', 'sr-RS@latin', 'sr-RS', 'sv-SE', 'tr-TR', 'uk-UA', 'vi-VN'];
  398. for (var _i4 = 0; _i4 < dotDecimal.length; _i4++) {
  399. decimal[dotDecimal[_i4]] = decimal['en-US'];
  400. }
  401. for (var _i5 = 0; _i5 < commaDecimal.length; _i5++) {
  402. decimal[commaDecimal[_i5]] = ',';
  403. }
  404. alpha['fr-CA'] = alpha['fr-FR'];
  405. alphanumeric['fr-CA'] = alphanumeric['fr-FR'];
  406. alpha['pt-BR'] = alpha['pt-PT'];
  407. alphanumeric['pt-BR'] = alphanumeric['pt-PT'];
  408. decimal['pt-BR'] = decimal['pt-PT'];
  409. // see #862
  410. alpha['pl-Pl'] = alpha['pl-PL'];
  411. alphanumeric['pl-Pl'] = alphanumeric['pl-PL'];
  412. decimal['pl-Pl'] = decimal['pl-PL'];
  413. // see #1455
  414. alpha['fa-AF'] = alpha.fa;
  415. function isFloat(str, options) {
  416. assertString(str);
  417. options = options || {};
  418. var _float = new RegExp("^(?:[-+])?(?:[0-9]+)?(?:\\".concat(options.locale ? decimal[options.locale] : '.', "[0-9]*)?(?:[eE][\\+\\-]?(?:[0-9]+))?$"));
  419. if (str === '' || str === '.' || str === ',' || str === '-' || str === '+') {
  420. return false;
  421. }
  422. var value = parseFloat(str.replace(',', '.'));
  423. return _float.test(str) && (!options.hasOwnProperty('min') || value >= options.min) && (!options.hasOwnProperty('max') || value <= options.max) && (!options.hasOwnProperty('lt') || value < options.lt) && (!options.hasOwnProperty('gt') || value > options.gt);
  424. }
  425. var locales = Object.keys(decimal);
  426. function toFloat(str) {
  427. if (!isFloat(str)) return NaN;
  428. return parseFloat(str);
  429. }
  430. function toInt(str, radix) {
  431. assertString(str);
  432. return parseInt(str, radix || 10);
  433. }
  434. function toBoolean(str, strict) {
  435. assertString(str);
  436. if (strict) {
  437. return str === '1' || /^true$/i.test(str);
  438. }
  439. return str !== '0' && !/^false$/i.test(str) && str !== '';
  440. }
  441. function equals(str, comparison) {
  442. assertString(str);
  443. return str === comparison;
  444. }
  445. function toString$1(input) {
  446. if (_typeof(input) === 'object' && input !== null) {
  447. if (typeof input.toString === 'function') {
  448. input = input.toString();
  449. } else {
  450. input = '[object Object]';
  451. }
  452. } else if (input === null || typeof input === 'undefined' || isNaN(input) && !input.length) {
  453. input = '';
  454. }
  455. return String(input);
  456. }
  457. function merge() {
  458. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  459. var defaults = arguments.length > 1 ? arguments[1] : undefined;
  460. for (var key in defaults) {
  461. if (typeof obj[key] === 'undefined') {
  462. obj[key] = defaults[key];
  463. }
  464. }
  465. return obj;
  466. }
  467. var defaulContainsOptions = {
  468. ignoreCase: false,
  469. minOccurrences: 1
  470. };
  471. function contains(str, elem, options) {
  472. assertString(str);
  473. options = merge(options, defaulContainsOptions);
  474. if (options.ignoreCase) {
  475. return str.toLowerCase().split(toString$1(elem).toLowerCase()).length > options.minOccurrences;
  476. }
  477. return str.split(toString$1(elem)).length > options.minOccurrences;
  478. }
  479. function matches(str, pattern, modifiers) {
  480. assertString(str);
  481. if (Object.prototype.toString.call(pattern) !== '[object RegExp]') {
  482. pattern = new RegExp(pattern, modifiers);
  483. }
  484. return !!str.match(pattern);
  485. }
  486. /* eslint-disable prefer-rest-params */
  487. function isByteLength(str, options) {
  488. assertString(str);
  489. var min;
  490. var max;
  491. if (_typeof(options) === 'object') {
  492. min = options.min || 0;
  493. max = options.max;
  494. } else {
  495. // backwards compatibility: isByteLength(str, min [, max])
  496. min = arguments[1];
  497. max = arguments[2];
  498. }
  499. var len = encodeURI(str).split(/%..|./).length - 1;
  500. return len >= min && (typeof max === 'undefined' || len <= max);
  501. }
  502. var default_fqdn_options = {
  503. require_tld: true,
  504. allow_underscores: false,
  505. allow_trailing_dot: false,
  506. allow_numeric_tld: false,
  507. allow_wildcard: false,
  508. ignore_max_length: false
  509. };
  510. function isFQDN(str, options) {
  511. assertString(str);
  512. options = merge(options, default_fqdn_options);
  513. /* Remove the optional trailing dot before checking validity */
  514. if (options.allow_trailing_dot && str[str.length - 1] === '.') {
  515. str = str.substring(0, str.length - 1);
  516. }
  517. /* Remove the optional wildcard before checking validity */
  518. if (options.allow_wildcard === true && str.indexOf('*.') === 0) {
  519. str = str.substring(2);
  520. }
  521. var parts = str.split('.');
  522. var tld = parts[parts.length - 1];
  523. if (options.require_tld) {
  524. // disallow fqdns without tld
  525. if (parts.length < 2) {
  526. return false;
  527. }
  528. if (!options.allow_numeric_tld && !/^([a-z\u00A1-\u00A8\u00AA-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]{2,}|xn[a-z0-9-]{2,})$/i.test(tld)) {
  529. return false;
  530. }
  531. // disallow spaces
  532. if (/\s/.test(tld)) {
  533. return false;
  534. }
  535. }
  536. // reject numeric TLDs
  537. if (!options.allow_numeric_tld && /^\d+$/.test(tld)) {
  538. return false;
  539. }
  540. return parts.every(function (part) {
  541. if (part.length > 63 && !options.ignore_max_length) {
  542. return false;
  543. }
  544. if (!/^[a-z_\u00a1-\uffff0-9-]+$/i.test(part)) {
  545. return false;
  546. }
  547. // disallow full-width chars
  548. if (/[\uff01-\uff5e]/.test(part)) {
  549. return false;
  550. }
  551. // disallow parts starting or ending with hyphen
  552. if (/^-|-$/.test(part)) {
  553. return false;
  554. }
  555. if (!options.allow_underscores && /_/.test(part)) {
  556. return false;
  557. }
  558. return true;
  559. });
  560. }
  561. /**
  562. 11.3. Examples
  563. The following addresses
  564. fe80::1234 (on the 1st link of the node)
  565. ff02::5678 (on the 5th link of the node)
  566. ff08::9abc (on the 10th organization of the node)
  567. would be represented as follows:
  568. fe80::1234%1
  569. ff02::5678%5
  570. ff08::9abc%10
  571. (Here we assume a natural translation from a zone index to the
  572. <zone_id> part, where the Nth zone of any scope is translated into
  573. "N".)
  574. If we use interface names as <zone_id>, those addresses could also be
  575. represented as follows:
  576. fe80::1234%ne0
  577. ff02::5678%pvc1.3
  578. ff08::9abc%interface10
  579. where the interface "ne0" belongs to the 1st link, "pvc1.3" belongs
  580. to the 5th link, and "interface10" belongs to the 10th organization.
  581. * * */
  582. var IPv4SegmentFormat = '(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])';
  583. var IPv4AddressFormat = "(".concat(IPv4SegmentFormat, "[.]){3}").concat(IPv4SegmentFormat);
  584. var IPv4AddressRegExp = new RegExp("^".concat(IPv4AddressFormat, "$"));
  585. var IPv6SegmentFormat = '(?:[0-9a-fA-F]{1,4})';
  586. var IPv6AddressRegExp = new RegExp('^(' + "(?:".concat(IPv6SegmentFormat, ":){7}(?:").concat(IPv6SegmentFormat, "|:)|") + "(?:".concat(IPv6SegmentFormat, ":){6}(?:").concat(IPv4AddressFormat, "|:").concat(IPv6SegmentFormat, "|:)|") + "(?:".concat(IPv6SegmentFormat, ":){5}(?::").concat(IPv4AddressFormat, "|(:").concat(IPv6SegmentFormat, "){1,2}|:)|") + "(?:".concat(IPv6SegmentFormat, ":){4}(?:(:").concat(IPv6SegmentFormat, "){0,1}:").concat(IPv4AddressFormat, "|(:").concat(IPv6SegmentFormat, "){1,3}|:)|") + "(?:".concat(IPv6SegmentFormat, ":){3}(?:(:").concat(IPv6SegmentFormat, "){0,2}:").concat(IPv4AddressFormat, "|(:").concat(IPv6SegmentFormat, "){1,4}|:)|") + "(?:".concat(IPv6SegmentFormat, ":){2}(?:(:").concat(IPv6SegmentFormat, "){0,3}:").concat(IPv4AddressFormat, "|(:").concat(IPv6SegmentFormat, "){1,5}|:)|") + "(?:".concat(IPv6SegmentFormat, ":){1}(?:(:").concat(IPv6SegmentFormat, "){0,4}:").concat(IPv4AddressFormat, "|(:").concat(IPv6SegmentFormat, "){1,6}|:)|") + "(?::((?::".concat(IPv6SegmentFormat, "){0,5}:").concat(IPv4AddressFormat, "|(?::").concat(IPv6SegmentFormat, "){1,7}|:))") + ')(%[0-9a-zA-Z-.:]{1,})?$');
  587. function isIP(str) {
  588. var version = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
  589. assertString(str);
  590. version = String(version);
  591. if (!version) {
  592. return isIP(str, 4) || isIP(str, 6);
  593. }
  594. if (version === '4') {
  595. return IPv4AddressRegExp.test(str);
  596. }
  597. if (version === '6') {
  598. return IPv6AddressRegExp.test(str);
  599. }
  600. return false;
  601. }
  602. var default_email_options = {
  603. allow_display_name: false,
  604. allow_underscores: false,
  605. require_display_name: false,
  606. allow_utf8_local_part: true,
  607. require_tld: true,
  608. blacklisted_chars: '',
  609. ignore_max_length: false,
  610. host_blacklist: [],
  611. host_whitelist: []
  612. };
  613. /* eslint-disable max-len */
  614. /* eslint-disable no-control-regex */
  615. var splitNameAddress = /^([^\x00-\x1F\x7F-\x9F\cX]+)</i;
  616. var emailUserPart = /^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~]+$/i;
  617. var gmailUserPart = /^[a-z\d]+$/;
  618. var quotedEmailUser = /^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f]))*$/i;
  619. var emailUserUtf8Part = /^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\u00A1-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+$/i;
  620. var quotedEmailUserUtf8 = /^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))*$/i;
  621. var defaultMaxEmailLength = 254;
  622. /* eslint-enable max-len */
  623. /* eslint-enable no-control-regex */
  624. /**
  625. * Validate display name according to the RFC2822: https://tools.ietf.org/html/rfc2822#appendix-A.1.2
  626. * @param {String} display_name
  627. */
  628. function validateDisplayName(display_name) {
  629. var display_name_without_quotes = display_name.replace(/^"(.+)"$/, '$1');
  630. // display name with only spaces is not valid
  631. if (!display_name_without_quotes.trim()) {
  632. return false;
  633. }
  634. // check whether display name contains illegal character
  635. var contains_illegal = /[\.";<>]/.test(display_name_without_quotes);
  636. if (contains_illegal) {
  637. // if contains illegal characters,
  638. // must to be enclosed in double-quotes, otherwise it's not a valid display name
  639. if (display_name_without_quotes === display_name) {
  640. return false;
  641. }
  642. // the quotes in display name must start with character symbol \
  643. var all_start_with_back_slash = display_name_without_quotes.split('"').length === display_name_without_quotes.split('\\"').length;
  644. if (!all_start_with_back_slash) {
  645. return false;
  646. }
  647. }
  648. return true;
  649. }
  650. function isEmail(str, options) {
  651. assertString(str);
  652. options = merge(options, default_email_options);
  653. if (options.require_display_name || options.allow_display_name) {
  654. var display_email = str.match(splitNameAddress);
  655. if (display_email) {
  656. var display_name = display_email[1];
  657. // Remove display name and angle brackets to get email address
  658. // Can be done in the regex but will introduce a ReDOS (See #1597 for more info)
  659. str = str.replace(display_name, '').replace(/(^<|>$)/g, '');
  660. // sometimes need to trim the last space to get the display name
  661. // because there may be a space between display name and email address
  662. // eg. myname <address@gmail.com>
  663. // the display name is `myname` instead of `myname `, so need to trim the last space
  664. if (display_name.endsWith(' ')) {
  665. display_name = display_name.slice(0, -1);
  666. }
  667. if (!validateDisplayName(display_name)) {
  668. return false;
  669. }
  670. } else if (options.require_display_name) {
  671. return false;
  672. }
  673. }
  674. if (!options.ignore_max_length && str.length > defaultMaxEmailLength) {
  675. return false;
  676. }
  677. var parts = str.split('@');
  678. var domain = parts.pop();
  679. var lower_domain = domain.toLowerCase();
  680. if (options.host_blacklist.includes(lower_domain)) {
  681. return false;
  682. }
  683. if (options.host_whitelist.length > 0 && !options.host_whitelist.includes(lower_domain)) {
  684. return false;
  685. }
  686. var user = parts.join('@');
  687. if (options.domain_specific_validation && (lower_domain === 'gmail.com' || lower_domain === 'googlemail.com')) {
  688. /*
  689. Previously we removed dots for gmail addresses before validating.
  690. This was removed because it allows `multiple..dots@gmail.com`
  691. to be reported as valid, but it is not.
  692. Gmail only normalizes single dots, removing them from here is pointless,
  693. should be done in normalizeEmail
  694. */
  695. user = user.toLowerCase();
  696. // Removing sub-address from username before gmail validation
  697. var username = user.split('+')[0];
  698. // Dots are not included in gmail length restriction
  699. if (!isByteLength(username.replace(/\./g, ''), {
  700. min: 6,
  701. max: 30
  702. })) {
  703. return false;
  704. }
  705. var _user_parts = username.split('.');
  706. for (var i = 0; i < _user_parts.length; i++) {
  707. if (!gmailUserPart.test(_user_parts[i])) {
  708. return false;
  709. }
  710. }
  711. }
  712. if (options.ignore_max_length === false && (!isByteLength(user, {
  713. max: 64
  714. }) || !isByteLength(domain, {
  715. max: 254
  716. }))) {
  717. return false;
  718. }
  719. if (!isFQDN(domain, {
  720. require_tld: options.require_tld,
  721. ignore_max_length: options.ignore_max_length,
  722. allow_underscores: options.allow_underscores
  723. })) {
  724. if (!options.allow_ip_domain) {
  725. return false;
  726. }
  727. if (!isIP(domain)) {
  728. if (!domain.startsWith('[') || !domain.endsWith(']')) {
  729. return false;
  730. }
  731. var noBracketdomain = domain.slice(1, -1);
  732. if (noBracketdomain.length === 0 || !isIP(noBracketdomain)) {
  733. return false;
  734. }
  735. }
  736. }
  737. if (user[0] === '"') {
  738. user = user.slice(1, user.length - 1);
  739. return options.allow_utf8_local_part ? quotedEmailUserUtf8.test(user) : quotedEmailUser.test(user);
  740. }
  741. var pattern = options.allow_utf8_local_part ? emailUserUtf8Part : emailUserPart;
  742. var user_parts = user.split('.');
  743. for (var _i = 0; _i < user_parts.length; _i++) {
  744. if (!pattern.test(user_parts[_i])) {
  745. return false;
  746. }
  747. }
  748. if (options.blacklisted_chars) {
  749. if (user.search(new RegExp("[".concat(options.blacklisted_chars, "]+"), 'g')) !== -1) return false;
  750. }
  751. return true;
  752. }
  753. /*
  754. options for isURL method
  755. require_protocol - if set as true isURL will return false if protocol is not present in the URL
  756. require_valid_protocol - isURL will check if the URL's protocol is present in the protocols option
  757. protocols - valid protocols can be modified with this option
  758. require_host - if set as false isURL will not check if host is present in the URL
  759. require_port - if set as true isURL will check if port is present in the URL
  760. allow_protocol_relative_urls - if set as true protocol relative URLs will be allowed
  761. validate_length - if set as false isURL will skip string length validation (IE maximum is 2083)
  762. */
  763. var default_url_options = {
  764. protocols: ['http', 'https', 'ftp'],
  765. require_tld: true,
  766. require_protocol: false,
  767. require_host: true,
  768. require_port: false,
  769. require_valid_protocol: true,
  770. allow_underscores: false,
  771. allow_trailing_dot: false,
  772. allow_protocol_relative_urls: false,
  773. allow_fragments: true,
  774. allow_query_components: true,
  775. validate_length: true
  776. };
  777. var wrapped_ipv6 = /^\[([^\]]+)\](?::([0-9]+))?$/;
  778. function isRegExp(obj) {
  779. return Object.prototype.toString.call(obj) === '[object RegExp]';
  780. }
  781. function checkHost(host, matches) {
  782. for (var i = 0; i < matches.length; i++) {
  783. var match = matches[i];
  784. if (host === match || isRegExp(match) && match.test(host)) {
  785. return true;
  786. }
  787. }
  788. return false;
  789. }
  790. function isURL(url, options) {
  791. assertString(url);
  792. if (!url || /[\s<>]/.test(url)) {
  793. return false;
  794. }
  795. if (url.indexOf('mailto:') === 0) {
  796. return false;
  797. }
  798. options = merge(options, default_url_options);
  799. if (options.validate_length && url.length >= 2083) {
  800. return false;
  801. }
  802. if (!options.allow_fragments && url.includes('#')) {
  803. return false;
  804. }
  805. if (!options.allow_query_components && (url.includes('?') || url.includes('&'))) {
  806. return false;
  807. }
  808. var protocol, auth, host, hostname, port, port_str, split, ipv6;
  809. split = url.split('#');
  810. url = split.shift();
  811. split = url.split('?');
  812. url = split.shift();
  813. split = url.split('://');
  814. if (split.length > 1) {
  815. protocol = split.shift().toLowerCase();
  816. if (options.require_valid_protocol && options.protocols.indexOf(protocol) === -1) {
  817. return false;
  818. }
  819. } else if (options.require_protocol) {
  820. return false;
  821. } else if (url.slice(0, 2) === '//') {
  822. if (!options.allow_protocol_relative_urls) {
  823. return false;
  824. }
  825. split[0] = url.slice(2);
  826. }
  827. url = split.join('://');
  828. if (url === '') {
  829. return false;
  830. }
  831. split = url.split('/');
  832. url = split.shift();
  833. if (url === '' && !options.require_host) {
  834. return true;
  835. }
  836. split = url.split('@');
  837. if (split.length > 1) {
  838. if (options.disallow_auth) {
  839. return false;
  840. }
  841. if (split[0] === '') {
  842. return false;
  843. }
  844. auth = split.shift();
  845. if (auth.indexOf(':') >= 0 && auth.split(':').length > 2) {
  846. return false;
  847. }
  848. var _auth$split = auth.split(':'),
  849. _auth$split2 = _slicedToArray(_auth$split, 2),
  850. user = _auth$split2[0],
  851. password = _auth$split2[1];
  852. if (user === '' && password === '') {
  853. return false;
  854. }
  855. }
  856. hostname = split.join('@');
  857. port_str = null;
  858. ipv6 = null;
  859. var ipv6_match = hostname.match(wrapped_ipv6);
  860. if (ipv6_match) {
  861. host = '';
  862. ipv6 = ipv6_match[1];
  863. port_str = ipv6_match[2] || null;
  864. } else {
  865. split = hostname.split(':');
  866. host = split.shift();
  867. if (split.length) {
  868. port_str = split.join(':');
  869. }
  870. }
  871. if (port_str !== null && port_str.length > 0) {
  872. port = parseInt(port_str, 10);
  873. if (!/^[0-9]+$/.test(port_str) || port <= 0 || port > 65535) {
  874. return false;
  875. }
  876. } else if (options.require_port) {
  877. return false;
  878. }
  879. if (options.host_whitelist) {
  880. return checkHost(host, options.host_whitelist);
  881. }
  882. if (host === '' && !options.require_host) {
  883. return true;
  884. }
  885. if (!isIP(host) && !isFQDN(host, options) && (!ipv6 || !isIP(ipv6, 6))) {
  886. return false;
  887. }
  888. host = host || ipv6;
  889. if (options.host_blacklist && checkHost(host, options.host_blacklist)) {
  890. return false;
  891. }
  892. return true;
  893. }
  894. var macAddress48 = /^(?:[0-9a-fA-F]{2}([-:\s]))([0-9a-fA-F]{2}\1){4}([0-9a-fA-F]{2})$/;
  895. var macAddress48NoSeparators = /^([0-9a-fA-F]){12}$/;
  896. var macAddress48WithDots = /^([0-9a-fA-F]{4}\.){2}([0-9a-fA-F]{4})$/;
  897. var macAddress64 = /^(?:[0-9a-fA-F]{2}([-:\s]))([0-9a-fA-F]{2}\1){6}([0-9a-fA-F]{2})$/;
  898. var macAddress64NoSeparators = /^([0-9a-fA-F]){16}$/;
  899. var macAddress64WithDots = /^([0-9a-fA-F]{4}\.){3}([0-9a-fA-F]{4})$/;
  900. function isMACAddress(str, options) {
  901. assertString(str);
  902. if (options !== null && options !== void 0 && options.eui) {
  903. options.eui = String(options.eui);
  904. }
  905. /**
  906. * @deprecated `no_colons` TODO: remove it in the next major
  907. */
  908. if (options !== null && options !== void 0 && options.no_colons || options !== null && options !== void 0 && options.no_separators) {
  909. if (options.eui === '48') {
  910. return macAddress48NoSeparators.test(str);
  911. }
  912. if (options.eui === '64') {
  913. return macAddress64NoSeparators.test(str);
  914. }
  915. return macAddress48NoSeparators.test(str) || macAddress64NoSeparators.test(str);
  916. }
  917. if ((options === null || options === void 0 ? void 0 : options.eui) === '48') {
  918. return macAddress48.test(str) || macAddress48WithDots.test(str);
  919. }
  920. if ((options === null || options === void 0 ? void 0 : options.eui) === '64') {
  921. return macAddress64.test(str) || macAddress64WithDots.test(str);
  922. }
  923. return isMACAddress(str, {
  924. eui: '48'
  925. }) || isMACAddress(str, {
  926. eui: '64'
  927. });
  928. }
  929. var subnetMaybe = /^\d{1,3}$/;
  930. var v4Subnet = 32;
  931. var v6Subnet = 128;
  932. function isIPRange(str) {
  933. var version = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
  934. assertString(str);
  935. var parts = str.split('/');
  936. // parts[0] -> ip, parts[1] -> subnet
  937. if (parts.length !== 2) {
  938. return false;
  939. }
  940. if (!subnetMaybe.test(parts[1])) {
  941. return false;
  942. }
  943. // Disallow preceding 0 i.e. 01, 02, ...
  944. if (parts[1].length > 1 && parts[1].startsWith('0')) {
  945. return false;
  946. }
  947. var isValidIP = isIP(parts[0], version);
  948. if (!isValidIP) {
  949. return false;
  950. }
  951. // Define valid subnet according to IP's version
  952. var expectedSubnet = null;
  953. switch (String(version)) {
  954. case '4':
  955. expectedSubnet = v4Subnet;
  956. break;
  957. case '6':
  958. expectedSubnet = v6Subnet;
  959. break;
  960. default:
  961. expectedSubnet = isIP(parts[0], '6') ? v6Subnet : v4Subnet;
  962. }
  963. return parts[1] <= expectedSubnet && parts[1] >= 0;
  964. }
  965. var default_date_options = {
  966. format: 'YYYY/MM/DD',
  967. delimiters: ['/', '-'],
  968. strictMode: false
  969. };
  970. function isValidFormat(format) {
  971. return /(^(y{4}|y{2})[.\/-](m{1,2})[.\/-](d{1,2})$)|(^(m{1,2})[.\/-](d{1,2})[.\/-]((y{4}|y{2})$))|(^(d{1,2})[.\/-](m{1,2})[.\/-]((y{4}|y{2})$))/gi.test(format);
  972. }
  973. function zip(date, format) {
  974. var zippedArr = [],
  975. len = Math.min(date.length, format.length);
  976. for (var i = 0; i < len; i++) {
  977. zippedArr.push([date[i], format[i]]);
  978. }
  979. return zippedArr;
  980. }
  981. function isDate(input, options) {
  982. if (typeof options === 'string') {
  983. // Allow backward compatibility for old format isDate(input [, format])
  984. options = merge({
  985. format: options
  986. }, default_date_options);
  987. } else {
  988. options = merge(options, default_date_options);
  989. }
  990. if (typeof input === 'string' && isValidFormat(options.format)) {
  991. var formatDelimiter = options.delimiters.find(function (delimiter) {
  992. return options.format.indexOf(delimiter) !== -1;
  993. });
  994. var dateDelimiter = options.strictMode ? formatDelimiter : options.delimiters.find(function (delimiter) {
  995. return input.indexOf(delimiter) !== -1;
  996. });
  997. var dateAndFormat = zip(input.split(dateDelimiter), options.format.toLowerCase().split(formatDelimiter));
  998. var dateObj = {};
  999. var _iterator = _createForOfIteratorHelper(dateAndFormat),
  1000. _step;
  1001. try {
  1002. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  1003. var _step$value = _slicedToArray(_step.value, 2),
  1004. dateWord = _step$value[0],
  1005. formatWord = _step$value[1];
  1006. if (dateWord.length !== formatWord.length) {
  1007. return false;
  1008. }
  1009. dateObj[formatWord.charAt(0)] = dateWord;
  1010. }
  1011. } catch (err) {
  1012. _iterator.e(err);
  1013. } finally {
  1014. _iterator.f();
  1015. }
  1016. var fullYear = dateObj.y;
  1017. // Check if the year starts with a hyphen
  1018. if (fullYear.startsWith('-')) {
  1019. return false; // Hyphen before year is not allowed
  1020. }
  1021. if (dateObj.y.length === 2) {
  1022. var parsedYear = parseInt(dateObj.y, 10);
  1023. if (isNaN(parsedYear)) {
  1024. return false;
  1025. }
  1026. var currentYearLastTwoDigits = new Date().getFullYear() % 100;
  1027. if (parsedYear < currentYearLastTwoDigits) {
  1028. fullYear = "20".concat(dateObj.y);
  1029. } else {
  1030. fullYear = "19".concat(dateObj.y);
  1031. }
  1032. }
  1033. var month = dateObj.m;
  1034. if (dateObj.m.length === 1) {
  1035. month = "0".concat(dateObj.m);
  1036. }
  1037. var day = dateObj.d;
  1038. if (dateObj.d.length === 1) {
  1039. day = "0".concat(dateObj.d);
  1040. }
  1041. return new Date("".concat(fullYear, "-").concat(month, "-").concat(day, "T00:00:00.000Z")).getUTCDate() === +dateObj.d;
  1042. }
  1043. if (!options.strictMode) {
  1044. return Object.prototype.toString.call(input) === '[object Date]' && isFinite(input);
  1045. }
  1046. return false;
  1047. }
  1048. var default_time_options = {
  1049. hourFormat: 'hour24',
  1050. mode: 'default'
  1051. };
  1052. var formats = {
  1053. hour24: {
  1054. "default": /^([01]?[0-9]|2[0-3]):([0-5][0-9])$/,
  1055. withSeconds: /^([01]?[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$/
  1056. },
  1057. hour12: {
  1058. "default": /^(0?[1-9]|1[0-2]):([0-5][0-9]) (A|P)M$/,
  1059. withSeconds: /^(0?[1-9]|1[0-2]):([0-5][0-9]):([0-5][0-9]) (A|P)M$/
  1060. }
  1061. };
  1062. function isTime(input, options) {
  1063. options = merge(options, default_time_options);
  1064. if (typeof input !== 'string') return false;
  1065. return formats[options.hourFormat][options.mode].test(input);
  1066. }
  1067. var defaultOptions = {
  1068. loose: false
  1069. };
  1070. var strictBooleans = ['true', 'false', '1', '0'];
  1071. var looseBooleans = [].concat(strictBooleans, ['yes', 'no']);
  1072. function isBoolean(str) {
  1073. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultOptions;
  1074. assertString(str);
  1075. if (options.loose) {
  1076. return looseBooleans.includes(str.toLowerCase());
  1077. }
  1078. return strictBooleans.includes(str);
  1079. }
  1080. /*
  1081. = 3ALPHA ; selected ISO 639 codes
  1082. *2("-" 3ALPHA) ; permanently reserved
  1083. */
  1084. var extlang = '([A-Za-z]{3}(-[A-Za-z]{3}){0,2})';
  1085. /*
  1086. = 2*3ALPHA ; shortest ISO 639 code
  1087. ["-" extlang] ; sometimes followed by
  1088. ; extended language subtags
  1089. / 4ALPHA ; or reserved for future use
  1090. / 5*8ALPHA ; or registered language subtag
  1091. */
  1092. var language = "(([a-zA-Z]{2,3}(-".concat(extlang, ")?)|([a-zA-Z]{5,8}))");
  1093. /*
  1094. = 4ALPHA ; ISO 15924 code
  1095. */
  1096. var script = '([A-Za-z]{4})';
  1097. /*
  1098. = 2ALPHA ; ISO 3166-1 code
  1099. / 3DIGIT ; UN M.49 code
  1100. */
  1101. var region = '([A-Za-z]{2}|\\d{3})';
  1102. /*
  1103. = 5*8alphanum ; registered variants
  1104. / (DIGIT 3alphanum)
  1105. */
  1106. var variant = '([A-Za-z0-9]{5,8}|(\\d[A-Z-a-z0-9]{3}))';
  1107. /*
  1108. = DIGIT ; 0 - 9
  1109. / %x41-57 ; A - W
  1110. / %x59-5A ; Y - Z
  1111. / %x61-77 ; a - w
  1112. / %x79-7A ; y - z
  1113. */
  1114. var singleton = '(\\d|[A-W]|[Y-Z]|[a-w]|[y-z])';
  1115. /*
  1116. = singleton 1*("-" (2*8alphanum))
  1117. ; Single alphanumerics
  1118. ; "x" reserved for private use
  1119. */
  1120. var extension = "(".concat(singleton, "(-[A-Za-z0-9]{2,8})+)");
  1121. /*
  1122. = "x" 1*("-" (1*8alphanum))
  1123. */
  1124. var privateuse = '(x(-[A-Za-z0-9]{1,8})+)';
  1125. // irregular tags do not match the 'langtag' production and would not
  1126. // otherwise be considered 'well-formed'. These tags are all valid, but
  1127. // most are deprecated in favor of more modern subtags or subtag combination
  1128. var irregular = '((en-GB-oed)|(i-ami)|(i-bnn)|(i-default)|(i-enochian)|' + '(i-hak)|(i-klingon)|(i-lux)|(i-mingo)|(i-navajo)|(i-pwn)|(i-tao)|' + '(i-tay)|(i-tsu)|(sgn-BE-FR)|(sgn-BE-NL)|(sgn-CH-DE))';
  1129. // regular tags match the 'langtag' production, but their subtags are not
  1130. // extended language or variant subtags: their meaning is defined by
  1131. // their registration and all of these are deprecated in favor of a more
  1132. // modern subtag or sequence of subtags
  1133. var regular = '((art-lojban)|(cel-gaulish)|(no-bok)|(no-nyn)|(zh-guoyu)|' + '(zh-hakka)|(zh-min)|(zh-min-nan)|(zh-xiang))';
  1134. /*
  1135. = irregular ; non-redundant tags registered
  1136. / regular ; during the RFC 3066 era
  1137. */
  1138. var grandfathered = "(".concat(irregular, "|").concat(regular, ")");
  1139. /*
  1140. RFC 5646 defines delimitation of subtags via a hyphen:
  1141. "Subtag" refers to a specific section of a tag, delimited by a
  1142. hyphen, such as the subtags 'zh', 'Hant', and 'CN' in the tag "zh-
  1143. Hant-CN". Examples of subtags in this document are enclosed in
  1144. single quotes ('Hant')
  1145. However, we need to add "_" to maintain the existing behaviour.
  1146. */
  1147. var delimiter = '(-|_)';
  1148. /*
  1149. = language
  1150. ["-" script]
  1151. ["-" region]
  1152. *("-" variant)
  1153. *("-" extension)
  1154. ["-" privateuse]
  1155. */
  1156. var langtag = "".concat(language, "(").concat(delimiter).concat(script, ")?(").concat(delimiter).concat(region, ")?(").concat(delimiter).concat(variant, ")*(").concat(delimiter).concat(extension, ")*(").concat(delimiter).concat(privateuse, ")?");
  1157. /*
  1158. Regex implementation based on BCP RFC 5646
  1159. Tags for Identifying Languages
  1160. https://www.rfc-editor.org/rfc/rfc5646.html
  1161. */
  1162. var languageTagRegex = new RegExp("(^".concat(privateuse, "$)|(^").concat(grandfathered, "$)|(^").concat(langtag, "$)"));
  1163. function isLocale(str) {
  1164. assertString(str);
  1165. return languageTagRegex.test(str);
  1166. }
  1167. // http://www.brainjar.com/js/validation/
  1168. // https://www.aba.com/news-research/research-analysis/routing-number-policy-procedures
  1169. // series reserved for future use are excluded
  1170. var isRoutingReg = /^(?!(1[3-9])|(20)|(3[3-9])|(4[0-9])|(5[0-9])|(60)|(7[3-9])|(8[1-9])|(9[0-2])|(9[3-9]))[0-9]{9}$/;
  1171. function isAbaRouting(str) {
  1172. assertString(str);
  1173. if (!isRoutingReg.test(str)) return false;
  1174. var checkSumVal = 0;
  1175. for (var i = 0; i < str.length; i++) {
  1176. if (i % 3 === 0) checkSumVal += str[i] * 3;else if (i % 3 === 1) checkSumVal += str[i] * 7;else checkSumVal += str[i] * 1;
  1177. }
  1178. return checkSumVal % 10 === 0;
  1179. }
  1180. function isAlpha(_str) {
  1181. var locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'en-US';
  1182. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  1183. assertString(_str);
  1184. var str = _str;
  1185. var ignore = options.ignore;
  1186. if (ignore) {
  1187. if (ignore instanceof RegExp) {
  1188. str = str.replace(ignore, '');
  1189. } else if (typeof ignore === 'string') {
  1190. str = str.replace(new RegExp("[".concat(ignore.replace(/[-[\]{}()*+?.,\\^$|#\\s]/g, '\\$&'), "]"), 'g'), ''); // escape regex for ignore
  1191. } else {
  1192. throw new Error('ignore should be instance of a String or RegExp');
  1193. }
  1194. }
  1195. if (locale in alpha) {
  1196. return alpha[locale].test(str);
  1197. }
  1198. throw new Error("Invalid locale '".concat(locale, "'"));
  1199. }
  1200. var locales$1 = Object.keys(alpha);
  1201. function isAlphanumeric(_str) {
  1202. var locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'en-US';
  1203. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  1204. assertString(_str);
  1205. var str = _str;
  1206. var ignore = options.ignore;
  1207. if (ignore) {
  1208. if (ignore instanceof RegExp) {
  1209. str = str.replace(ignore, '');
  1210. } else if (typeof ignore === 'string') {
  1211. str = str.replace(new RegExp("[".concat(ignore.replace(/[-[\]{}()*+?.,\\^$|#\\s]/g, '\\$&'), "]"), 'g'), ''); // escape regex for ignore
  1212. } else {
  1213. throw new Error('ignore should be instance of a String or RegExp');
  1214. }
  1215. }
  1216. if (locale in alphanumeric) {
  1217. return alphanumeric[locale].test(str);
  1218. }
  1219. throw new Error("Invalid locale '".concat(locale, "'"));
  1220. }
  1221. var locales$2 = Object.keys(alphanumeric);
  1222. var numericNoSymbols = /^[0-9]+$/;
  1223. function isNumeric(str, options) {
  1224. assertString(str);
  1225. if (options && options.no_symbols) {
  1226. return numericNoSymbols.test(str);
  1227. }
  1228. return new RegExp("^[+-]?([0-9]*[".concat((options || {}).locale ? decimal[options.locale] : '.', "])?[0-9]+$")).test(str);
  1229. }
  1230. /**
  1231. * Reference:
  1232. * https://en.wikipedia.org/ -- Wikipedia
  1233. * https://docs.microsoft.com/en-us/microsoft-365/compliance/eu-passport-number -- EU Passport Number
  1234. * https://countrycode.org/ -- Country Codes
  1235. */
  1236. var passportRegexByCountryCode = {
  1237. AM: /^[A-Z]{2}\d{7}$/,
  1238. // ARMENIA
  1239. AR: /^[A-Z]{3}\d{6}$/,
  1240. // ARGENTINA
  1241. AT: /^[A-Z]\d{7}$/,
  1242. // AUSTRIA
  1243. AU: /^[A-Z]\d{7}$/,
  1244. // AUSTRALIA
  1245. AZ: /^[A-Z]{1}\d{8}$/,
  1246. // AZERBAIJAN
  1247. BE: /^[A-Z]{2}\d{6}$/,
  1248. // BELGIUM
  1249. BG: /^\d{9}$/,
  1250. // BULGARIA
  1251. BR: /^[A-Z]{2}\d{6}$/,
  1252. // BRAZIL
  1253. BY: /^[A-Z]{2}\d{7}$/,
  1254. // BELARUS
  1255. CA: /^[A-Z]{2}\d{6}$/,
  1256. // CANADA
  1257. CH: /^[A-Z]\d{7}$/,
  1258. // SWITZERLAND
  1259. CN: /^G\d{8}$|^E(?![IO])[A-Z0-9]\d{7}$/,
  1260. // CHINA [G=Ordinary, E=Electronic] followed by 8-digits, or E followed by any UPPERCASE letter (except I and O) followed by 7 digits
  1261. CY: /^[A-Z](\d{6}|\d{8})$/,
  1262. // CYPRUS
  1263. CZ: /^\d{8}$/,
  1264. // CZECH REPUBLIC
  1265. DE: /^[CFGHJKLMNPRTVWXYZ0-9]{9}$/,
  1266. // GERMANY
  1267. DK: /^\d{9}$/,
  1268. // DENMARK
  1269. DZ: /^\d{9}$/,
  1270. // ALGERIA
  1271. EE: /^([A-Z]\d{7}|[A-Z]{2}\d{7})$/,
  1272. // ESTONIA (K followed by 7-digits), e-passports have 2 UPPERCASE followed by 7 digits
  1273. ES: /^[A-Z0-9]{2}([A-Z0-9]?)\d{6}$/,
  1274. // SPAIN
  1275. FI: /^[A-Z]{2}\d{7}$/,
  1276. // FINLAND
  1277. FR: /^\d{2}[A-Z]{2}\d{5}$/,
  1278. // FRANCE
  1279. GB: /^\d{9}$/,
  1280. // UNITED KINGDOM
  1281. GR: /^[A-Z]{2}\d{7}$/,
  1282. // GREECE
  1283. HR: /^\d{9}$/,
  1284. // CROATIA
  1285. HU: /^[A-Z]{2}(\d{6}|\d{7})$/,
  1286. // HUNGARY
  1287. IE: /^[A-Z0-9]{2}\d{7}$/,
  1288. // IRELAND
  1289. IN: /^[A-Z]{1}-?\d{7}$/,
  1290. // INDIA
  1291. ID: /^[A-C]\d{7}$/,
  1292. // INDONESIA
  1293. IR: /^[A-Z]\d{8}$/,
  1294. // IRAN
  1295. IS: /^(A)\d{7}$/,
  1296. // ICELAND
  1297. IT: /^[A-Z0-9]{2}\d{7}$/,
  1298. // ITALY
  1299. JM: /^[Aa]\d{7}$/,
  1300. // JAMAICA
  1301. JP: /^[A-Z]{2}\d{7}$/,
  1302. // JAPAN
  1303. KR: /^[MS]\d{8}$/,
  1304. // SOUTH KOREA, REPUBLIC OF KOREA, [S=PS Passports, M=PM Passports]
  1305. KZ: /^[a-zA-Z]\d{7}$/,
  1306. // KAZAKHSTAN
  1307. LI: /^[a-zA-Z]\d{5}$/,
  1308. // LIECHTENSTEIN
  1309. LT: /^[A-Z0-9]{8}$/,
  1310. // LITHUANIA
  1311. LU: /^[A-Z0-9]{8}$/,
  1312. // LUXEMBURG
  1313. LV: /^[A-Z0-9]{2}\d{7}$/,
  1314. // LATVIA
  1315. LY: /^[A-Z0-9]{8}$/,
  1316. // LIBYA
  1317. MT: /^\d{7}$/,
  1318. // MALTA
  1319. MZ: /^([A-Z]{2}\d{7})|(\d{2}[A-Z]{2}\d{5})$/,
  1320. // MOZAMBIQUE
  1321. MY: /^[AHK]\d{8}$/,
  1322. // MALAYSIA
  1323. MX: /^\d{10,11}$/,
  1324. // MEXICO
  1325. NL: /^[A-Z]{2}[A-Z0-9]{6}\d$/,
  1326. // NETHERLANDS
  1327. NZ: /^([Ll]([Aa]|[Dd]|[Ff]|[Hh])|[Ee]([Aa]|[Pp])|[Nn])\d{6}$/,
  1328. // NEW ZEALAND
  1329. PH: /^([A-Z](\d{6}|\d{7}[A-Z]))|([A-Z]{2}(\d{6}|\d{7}))$/,
  1330. // PHILIPPINES
  1331. PK: /^[A-Z]{2}\d{7}$/,
  1332. // PAKISTAN
  1333. PL: /^[A-Z]{2}\d{7}$/,
  1334. // POLAND
  1335. PT: /^[A-Z]\d{6}$/,
  1336. // PORTUGAL
  1337. RO: /^\d{8,9}$/,
  1338. // ROMANIA
  1339. RU: /^\d{9}$/,
  1340. // RUSSIAN FEDERATION
  1341. SE: /^\d{8}$/,
  1342. // SWEDEN
  1343. SL: /^(P)[A-Z]\d{7}$/,
  1344. // SLOVENIA
  1345. SK: /^[0-9A-Z]\d{7}$/,
  1346. // SLOVAKIA
  1347. TH: /^[A-Z]{1,2}\d{6,7}$/,
  1348. // THAILAND
  1349. TR: /^[A-Z]\d{8}$/,
  1350. // TURKEY
  1351. UA: /^[A-Z]{2}\d{6}$/,
  1352. // UKRAINE
  1353. US: /^\d{9}$/,
  1354. // UNITED STATES
  1355. ZA: /^[TAMD]\d{8}$/ // SOUTH AFRICA
  1356. };
  1357. /**
  1358. * Check if str is a valid passport number
  1359. * relative to provided ISO Country Code.
  1360. *
  1361. * @param {string} str
  1362. * @param {string} countryCode
  1363. * @return {boolean}
  1364. */
  1365. function isPassportNumber(str, countryCode) {
  1366. assertString(str);
  1367. /** Remove All Whitespaces, Convert to UPPERCASE */
  1368. var normalizedStr = str.replace(/\s/g, '').toUpperCase();
  1369. return countryCode.toUpperCase() in passportRegexByCountryCode && passportRegexByCountryCode[countryCode].test(normalizedStr);
  1370. }
  1371. var _int = /^(?:[-+]?(?:0|[1-9][0-9]*))$/;
  1372. var intLeadingZeroes = /^[-+]?[0-9]+$/;
  1373. function isInt(str, options) {
  1374. assertString(str);
  1375. options = options || {};
  1376. // Get the regex to use for testing, based on whether
  1377. // leading zeroes are allowed or not.
  1378. var regex = options.allow_leading_zeroes === false ? _int : intLeadingZeroes;
  1379. // Check min/max/lt/gt
  1380. var minCheckPassed = !options.hasOwnProperty('min') || str >= options.min;
  1381. var maxCheckPassed = !options.hasOwnProperty('max') || str <= options.max;
  1382. var ltCheckPassed = !options.hasOwnProperty('lt') || str < options.lt;
  1383. var gtCheckPassed = !options.hasOwnProperty('gt') || str > options.gt;
  1384. return regex.test(str) && minCheckPassed && maxCheckPassed && ltCheckPassed && gtCheckPassed;
  1385. }
  1386. function isPort(str) {
  1387. return isInt(str, {
  1388. allow_leading_zeroes: false,
  1389. min: 0,
  1390. max: 65535
  1391. });
  1392. }
  1393. function isLowercase(str) {
  1394. assertString(str);
  1395. return str === str.toLowerCase();
  1396. }
  1397. function isUppercase(str) {
  1398. assertString(str);
  1399. return str === str.toUpperCase();
  1400. }
  1401. var imeiRegexWithoutHypens = /^[0-9]{15}$/;
  1402. var imeiRegexWithHypens = /^\d{2}-\d{6}-\d{6}-\d{1}$/;
  1403. function isIMEI(str, options) {
  1404. assertString(str);
  1405. options = options || {};
  1406. // default regex for checking imei is the one without hyphens
  1407. var imeiRegex = imeiRegexWithoutHypens;
  1408. if (options.allow_hyphens) {
  1409. imeiRegex = imeiRegexWithHypens;
  1410. }
  1411. if (!imeiRegex.test(str)) {
  1412. return false;
  1413. }
  1414. str = str.replace(/-/g, '');
  1415. var sum = 0,
  1416. mul = 2,
  1417. l = 14;
  1418. for (var i = 0; i < l; i++) {
  1419. var digit = str.substring(l - i - 1, l - i);
  1420. var tp = parseInt(digit, 10) * mul;
  1421. if (tp >= 10) {
  1422. sum += tp % 10 + 1;
  1423. } else {
  1424. sum += tp;
  1425. }
  1426. if (mul === 1) {
  1427. mul += 1;
  1428. } else {
  1429. mul -= 1;
  1430. }
  1431. }
  1432. var chk = (10 - sum % 10) % 10;
  1433. if (chk !== parseInt(str.substring(14, 15), 10)) {
  1434. return false;
  1435. }
  1436. return true;
  1437. }
  1438. /* eslint-disable no-control-regex */
  1439. var ascii = /^[\x00-\x7F]+$/;
  1440. /* eslint-enable no-control-regex */
  1441. function isAscii(str) {
  1442. assertString(str);
  1443. return ascii.test(str);
  1444. }
  1445. var fullWidth = /[^\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;
  1446. function isFullWidth(str) {
  1447. assertString(str);
  1448. return fullWidth.test(str);
  1449. }
  1450. var halfWidth = /[\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;
  1451. function isHalfWidth(str) {
  1452. assertString(str);
  1453. return halfWidth.test(str);
  1454. }
  1455. function isVariableWidth(str) {
  1456. assertString(str);
  1457. return fullWidth.test(str) && halfWidth.test(str);
  1458. }
  1459. /* eslint-disable no-control-regex */
  1460. var multibyte = /[^\x00-\x7F]/;
  1461. /* eslint-enable no-control-regex */
  1462. function isMultibyte(str) {
  1463. assertString(str);
  1464. return multibyte.test(str);
  1465. }
  1466. /**
  1467. * Build RegExp object from an array
  1468. * of multiple/multi-line regexp parts
  1469. *
  1470. * @param {string[]} parts
  1471. * @param {string} flags
  1472. * @return {object} - RegExp object
  1473. */
  1474. function multilineRegexp(parts, flags) {
  1475. var regexpAsStringLiteral = parts.join('');
  1476. return new RegExp(regexpAsStringLiteral, flags);
  1477. }
  1478. /**
  1479. * Regular Expression to match
  1480. * semantic versioning (SemVer)
  1481. * built from multi-line, multi-parts regexp
  1482. * Reference: https://semver.org/
  1483. */
  1484. var semanticVersioningRegex = multilineRegexp(['^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)', '(?:-((?:0|[1-9]\\d*|\\d*[a-z-][0-9a-z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-z-][0-9a-z-]*))*))', '?(?:\\+([0-9a-z-]+(?:\\.[0-9a-z-]+)*))?$'], 'i');
  1485. function isSemVer(str) {
  1486. assertString(str);
  1487. return semanticVersioningRegex.test(str);
  1488. }
  1489. var surrogatePair = /[\uD800-\uDBFF][\uDC00-\uDFFF]/;
  1490. function isSurrogatePair(str) {
  1491. assertString(str);
  1492. return surrogatePair.test(str);
  1493. }
  1494. var includes = function includes(arr, val) {
  1495. return arr.some(function (arrVal) {
  1496. return val === arrVal;
  1497. });
  1498. };
  1499. function decimalRegExp(options) {
  1500. var regExp = new RegExp("^[-+]?([0-9]+)?(\\".concat(decimal[options.locale], "[0-9]{").concat(options.decimal_digits, "})").concat(options.force_decimal ? '' : '?', "$"));
  1501. return regExp;
  1502. }
  1503. var default_decimal_options = {
  1504. force_decimal: false,
  1505. decimal_digits: '1,',
  1506. locale: 'en-US'
  1507. };
  1508. var blacklist = ['', '-', '+'];
  1509. function isDecimal(str, options) {
  1510. assertString(str);
  1511. options = merge(options, default_decimal_options);
  1512. if (options.locale in decimal) {
  1513. return !includes(blacklist, str.replace(/ /g, '')) && decimalRegExp(options).test(str);
  1514. }
  1515. throw new Error("Invalid locale '".concat(options.locale, "'"));
  1516. }
  1517. var hexadecimal = /^(0x|0h)?[0-9A-F]+$/i;
  1518. function isHexadecimal(str) {
  1519. assertString(str);
  1520. return hexadecimal.test(str);
  1521. }
  1522. var octal = /^(0o)?[0-7]+$/i;
  1523. function isOctal(str) {
  1524. assertString(str);
  1525. return octal.test(str);
  1526. }
  1527. function isDivisibleBy(str, num) {
  1528. assertString(str);
  1529. return toFloat(str) % parseInt(num, 10) === 0;
  1530. }
  1531. var hexcolor = /^#?([0-9A-F]{3}|[0-9A-F]{4}|[0-9A-F]{6}|[0-9A-F]{8})$/i;
  1532. function isHexColor(str) {
  1533. assertString(str);
  1534. return hexcolor.test(str);
  1535. }
  1536. var rgbColor = /^rgb\((([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]),){2}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\)$/;
  1537. var rgbaColor = /^rgba\((([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]),){3}(0?\.\d|1(\.0)?|0(\.0)?)\)$/;
  1538. var rgbColorPercent = /^rgb\((([0-9]%|[1-9][0-9]%|100%),){2}([0-9]%|[1-9][0-9]%|100%)\)$/;
  1539. var rgbaColorPercent = /^rgba\((([0-9]%|[1-9][0-9]%|100%),){3}(0?\.\d|1(\.0)?|0(\.0)?)\)$/;
  1540. function isRgbColor(str) {
  1541. var includePercentValues = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
  1542. assertString(str);
  1543. if (!includePercentValues) {
  1544. return rgbColor.test(str) || rgbaColor.test(str);
  1545. }
  1546. return rgbColor.test(str) || rgbaColor.test(str) || rgbColorPercent.test(str) || rgbaColorPercent.test(str);
  1547. }
  1548. var hslComma = /^hsla?\(((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn)?(,(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}(,((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?))?\)$/i;
  1549. var hslSpace = /^hsla?\(((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn)?(\s(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s?(\/\s((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s?)?\)$/i;
  1550. function isHSL(str) {
  1551. assertString(str);
  1552. // Strip duplicate spaces before calling the validation regex (See #1598 for more info)
  1553. var strippedStr = str.replace(/\s+/g, ' ').replace(/\s?(hsla?\(|\)|,)\s?/ig, '$1');
  1554. if (strippedStr.indexOf(',') !== -1) {
  1555. return hslComma.test(strippedStr);
  1556. }
  1557. return hslSpace.test(strippedStr);
  1558. }
  1559. // see http://isrc.ifpi.org/en/isrc-standard/code-syntax
  1560. var isrc = /^[A-Z]{2}[0-9A-Z]{3}\d{2}\d{5}$/;
  1561. function isISRC(str) {
  1562. assertString(str);
  1563. return isrc.test(str);
  1564. }
  1565. /**
  1566. * List of country codes with
  1567. * corresponding IBAN regular expression
  1568. * Reference: https://en.wikipedia.org/wiki/International_Bank_Account_Number
  1569. */
  1570. var ibanRegexThroughCountryCode = {
  1571. AD: /^(AD[0-9]{2})\d{8}[A-Z0-9]{12}$/,
  1572. AE: /^(AE[0-9]{2})\d{3}\d{16}$/,
  1573. AL: /^(AL[0-9]{2})\d{8}[A-Z0-9]{16}$/,
  1574. AT: /^(AT[0-9]{2})\d{16}$/,
  1575. AZ: /^(AZ[0-9]{2})[A-Z0-9]{4}\d{20}$/,
  1576. BA: /^(BA[0-9]{2})\d{16}$/,
  1577. BE: /^(BE[0-9]{2})\d{12}$/,
  1578. BG: /^(BG[0-9]{2})[A-Z]{4}\d{6}[A-Z0-9]{8}$/,
  1579. BH: /^(BH[0-9]{2})[A-Z]{4}[A-Z0-9]{14}$/,
  1580. BR: /^(BR[0-9]{2})\d{23}[A-Z]{1}[A-Z0-9]{1}$/,
  1581. BY: /^(BY[0-9]{2})[A-Z0-9]{4}\d{20}$/,
  1582. CH: /^(CH[0-9]{2})\d{5}[A-Z0-9]{12}$/,
  1583. CR: /^(CR[0-9]{2})\d{18}$/,
  1584. CY: /^(CY[0-9]{2})\d{8}[A-Z0-9]{16}$/,
  1585. CZ: /^(CZ[0-9]{2})\d{20}$/,
  1586. DE: /^(DE[0-9]{2})\d{18}$/,
  1587. DK: /^(DK[0-9]{2})\d{14}$/,
  1588. DO: /^(DO[0-9]{2})[A-Z]{4}\d{20}$/,
  1589. DZ: /^(DZ\d{24})$/,
  1590. EE: /^(EE[0-9]{2})\d{16}$/,
  1591. EG: /^(EG[0-9]{2})\d{25}$/,
  1592. ES: /^(ES[0-9]{2})\d{20}$/,
  1593. FI: /^(FI[0-9]{2})\d{14}$/,
  1594. FO: /^(FO[0-9]{2})\d{14}$/,
  1595. FR: /^(FR[0-9]{2})\d{10}[A-Z0-9]{11}\d{2}$/,
  1596. GB: /^(GB[0-9]{2})[A-Z]{4}\d{14}$/,
  1597. GE: /^(GE[0-9]{2})[A-Z0-9]{2}\d{16}$/,
  1598. GI: /^(GI[0-9]{2})[A-Z]{4}[A-Z0-9]{15}$/,
  1599. GL: /^(GL[0-9]{2})\d{14}$/,
  1600. GR: /^(GR[0-9]{2})\d{7}[A-Z0-9]{16}$/,
  1601. GT: /^(GT[0-9]{2})[A-Z0-9]{4}[A-Z0-9]{20}$/,
  1602. HR: /^(HR[0-9]{2})\d{17}$/,
  1603. HU: /^(HU[0-9]{2})\d{24}$/,
  1604. IE: /^(IE[0-9]{2})[A-Z0-9]{4}\d{14}$/,
  1605. IL: /^(IL[0-9]{2})\d{19}$/,
  1606. IQ: /^(IQ[0-9]{2})[A-Z]{4}\d{15}$/,
  1607. IR: /^(IR[0-9]{2})0\d{2}0\d{18}$/,
  1608. IS: /^(IS[0-9]{2})\d{22}$/,
  1609. IT: /^(IT[0-9]{2})[A-Z]{1}\d{10}[A-Z0-9]{12}$/,
  1610. JO: /^(JO[0-9]{2})[A-Z]{4}\d{22}$/,
  1611. KW: /^(KW[0-9]{2})[A-Z]{4}[A-Z0-9]{22}$/,
  1612. KZ: /^(KZ[0-9]{2})\d{3}[A-Z0-9]{13}$/,
  1613. LB: /^(LB[0-9]{2})\d{4}[A-Z0-9]{20}$/,
  1614. LC: /^(LC[0-9]{2})[A-Z]{4}[A-Z0-9]{24}$/,
  1615. LI: /^(LI[0-9]{2})\d{5}[A-Z0-9]{12}$/,
  1616. LT: /^(LT[0-9]{2})\d{16}$/,
  1617. LU: /^(LU[0-9]{2})\d{3}[A-Z0-9]{13}$/,
  1618. LV: /^(LV[0-9]{2})[A-Z]{4}[A-Z0-9]{13}$/,
  1619. MA: /^(MA[0-9]{26})$/,
  1620. MC: /^(MC[0-9]{2})\d{10}[A-Z0-9]{11}\d{2}$/,
  1621. MD: /^(MD[0-9]{2})[A-Z0-9]{20}$/,
  1622. ME: /^(ME[0-9]{2})\d{18}$/,
  1623. MK: /^(MK[0-9]{2})\d{3}[A-Z0-9]{10}\d{2}$/,
  1624. MR: /^(MR[0-9]{2})\d{23}$/,
  1625. MT: /^(MT[0-9]{2})[A-Z]{4}\d{5}[A-Z0-9]{18}$/,
  1626. MU: /^(MU[0-9]{2})[A-Z]{4}\d{19}[A-Z]{3}$/,
  1627. MZ: /^(MZ[0-9]{2})\d{21}$/,
  1628. NL: /^(NL[0-9]{2})[A-Z]{4}\d{10}$/,
  1629. NO: /^(NO[0-9]{2})\d{11}$/,
  1630. PK: /^(PK[0-9]{2})[A-Z0-9]{4}\d{16}$/,
  1631. PL: /^(PL[0-9]{2})\d{24}$/,
  1632. PS: /^(PS[0-9]{2})[A-Z0-9]{4}\d{21}$/,
  1633. PT: /^(PT[0-9]{2})\d{21}$/,
  1634. QA: /^(QA[0-9]{2})[A-Z]{4}[A-Z0-9]{21}$/,
  1635. RO: /^(RO[0-9]{2})[A-Z]{4}[A-Z0-9]{16}$/,
  1636. RS: /^(RS[0-9]{2})\d{18}$/,
  1637. SA: /^(SA[0-9]{2})\d{2}[A-Z0-9]{18}$/,
  1638. SC: /^(SC[0-9]{2})[A-Z]{4}\d{20}[A-Z]{3}$/,
  1639. SE: /^(SE[0-9]{2})\d{20}$/,
  1640. SI: /^(SI[0-9]{2})\d{15}$/,
  1641. SK: /^(SK[0-9]{2})\d{20}$/,
  1642. SM: /^(SM[0-9]{2})[A-Z]{1}\d{10}[A-Z0-9]{12}$/,
  1643. SV: /^(SV[0-9]{2})[A-Z0-9]{4}\d{20}$/,
  1644. TL: /^(TL[0-9]{2})\d{19}$/,
  1645. TN: /^(TN[0-9]{2})\d{20}$/,
  1646. TR: /^(TR[0-9]{2})\d{5}[A-Z0-9]{17}$/,
  1647. UA: /^(UA[0-9]{2})\d{6}[A-Z0-9]{19}$/,
  1648. VA: /^(VA[0-9]{2})\d{18}$/,
  1649. VG: /^(VG[0-9]{2})[A-Z0-9]{4}\d{16}$/,
  1650. XK: /^(XK[0-9]{2})\d{16}$/
  1651. };
  1652. /**
  1653. * Check if the country codes passed are valid using the
  1654. * ibanRegexThroughCountryCode as a reference
  1655. *
  1656. * @param {array} countryCodeArray
  1657. * @return {boolean}
  1658. */
  1659. function hasOnlyValidCountryCodes(countryCodeArray) {
  1660. var countryCodeArrayFilteredWithObjectIbanCode = countryCodeArray.filter(function (countryCode) {
  1661. return !(countryCode in ibanRegexThroughCountryCode);
  1662. });
  1663. if (countryCodeArrayFilteredWithObjectIbanCode.length > 0) {
  1664. return false;
  1665. }
  1666. return true;
  1667. }
  1668. /**
  1669. * Check whether string has correct universal IBAN format
  1670. * The IBAN consists of up to 34 alphanumeric characters, as follows:
  1671. * Country Code using ISO 3166-1 alpha-2, two letters
  1672. * check digits, two digits and
  1673. * Basic Bank Account Number (BBAN), up to 30 alphanumeric characters.
  1674. * NOTE: Permitted IBAN characters are: digits [0-9] and the 26 latin alphabetic [A-Z]
  1675. *
  1676. * @param {string} str - string under validation
  1677. * @param {object} options - object to pass the countries to be either whitelisted or blacklisted
  1678. * @return {boolean}
  1679. */
  1680. function hasValidIbanFormat(str, options) {
  1681. // Strip white spaces and hyphens
  1682. var strippedStr = str.replace(/[\s\-]+/gi, '').toUpperCase();
  1683. var isoCountryCode = strippedStr.slice(0, 2).toUpperCase();
  1684. var isoCountryCodeInIbanRegexCodeObject = (isoCountryCode in ibanRegexThroughCountryCode);
  1685. if (options.whitelist) {
  1686. if (!hasOnlyValidCountryCodes(options.whitelist)) {
  1687. return false;
  1688. }
  1689. var isoCountryCodeInWhiteList = options.whitelist.includes(isoCountryCode);
  1690. if (!isoCountryCodeInWhiteList) {
  1691. return false;
  1692. }
  1693. }
  1694. if (options.blacklist) {
  1695. var isoCountryCodeInBlackList = options.blacklist.includes(isoCountryCode);
  1696. if (isoCountryCodeInBlackList) {
  1697. return false;
  1698. }
  1699. }
  1700. return isoCountryCodeInIbanRegexCodeObject && ibanRegexThroughCountryCode[isoCountryCode].test(strippedStr);
  1701. }
  1702. /**
  1703. * Check whether string has valid IBAN Checksum
  1704. * by performing basic mod-97 operation and
  1705. * the remainder should equal 1
  1706. * -- Start by rearranging the IBAN by moving the four initial characters to the end of the string
  1707. * -- Replace each letter in the string with two digits, A -> 10, B = 11, Z = 35
  1708. * -- Interpret the string as a decimal integer and
  1709. * -- compute the remainder on division by 97 (mod 97)
  1710. * Reference: https://en.wikipedia.org/wiki/International_Bank_Account_Number
  1711. *
  1712. * @param {string} str
  1713. * @return {boolean}
  1714. */
  1715. function hasValidIbanChecksum(str) {
  1716. var strippedStr = str.replace(/[^A-Z0-9]+/gi, '').toUpperCase(); // Keep only digits and A-Z latin alphabetic
  1717. var rearranged = strippedStr.slice(4) + strippedStr.slice(0, 4);
  1718. var alphaCapsReplacedWithDigits = rearranged.replace(/[A-Z]/g, function (_char) {
  1719. return _char.charCodeAt(0) - 55;
  1720. });
  1721. var remainder = alphaCapsReplacedWithDigits.match(/\d{1,7}/g).reduce(function (acc, value) {
  1722. return Number(acc + value) % 97;
  1723. }, '');
  1724. return remainder === 1;
  1725. }
  1726. function isIBAN(str) {
  1727. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  1728. assertString(str);
  1729. return hasValidIbanFormat(str, options) && hasValidIbanChecksum(str);
  1730. }
  1731. var locales$3 = Object.keys(ibanRegexThroughCountryCode);
  1732. // from https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
  1733. var validISO31661Alpha2CountriesCodes = new Set(['AD', 'AE', 'AF', 'AG', 'AI', 'AL', 'AM', 'AO', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AW', 'AX', 'AZ', 'BA', 'BB', 'BD', 'BE', 'BF', 'BG', 'BH', 'BI', 'BJ', 'BL', 'BM', 'BN', 'BO', 'BQ', 'BR', 'BS', 'BT', 'BV', 'BW', 'BY', 'BZ', 'CA', 'CC', 'CD', 'CF', 'CG', 'CH', 'CI', 'CK', 'CL', 'CM', 'CN', 'CO', 'CR', 'CU', 'CV', 'CW', 'CX', 'CY', 'CZ', 'DE', 'DJ', 'DK', 'DM', 'DO', 'DZ', 'EC', 'EE', 'EG', 'EH', 'ER', 'ES', 'ET', 'FI', 'FJ', 'FK', 'FM', 'FO', 'FR', 'GA', 'GB', 'GD', 'GE', 'GF', 'GG', 'GH', 'GI', 'GL', 'GM', 'GN', 'GP', 'GQ', 'GR', 'GS', 'GT', 'GU', 'GW', 'GY', 'HK', 'HM', 'HN', 'HR', 'HT', 'HU', 'ID', 'IE', 'IL', 'IM', 'IN', 'IO', 'IQ', 'IR', 'IS', 'IT', 'JE', 'JM', 'JO', 'JP', 'KE', 'KG', 'KH', 'KI', 'KM', 'KN', 'KP', 'KR', 'KW', 'KY', 'KZ', 'LA', 'LB', 'LC', 'LI', 'LK', 'LR', 'LS', 'LT', 'LU', 'LV', 'LY', 'MA', 'MC', 'MD', 'ME', 'MF', 'MG', 'MH', 'MK', 'ML', 'MM', 'MN', 'MO', 'MP', 'MQ', 'MR', 'MS', 'MT', 'MU', 'MV', 'MW', 'MX', 'MY', 'MZ', 'NA', 'NC', 'NE', 'NF', 'NG', 'NI', 'NL', 'NO', 'NP', 'NR', 'NU', 'NZ', 'OM', 'PA', 'PE', 'PF', 'PG', 'PH', 'PK', 'PL', 'PM', 'PN', 'PR', 'PS', 'PT', 'PW', 'PY', 'QA', 'RE', 'RO', 'RS', 'RU', 'RW', 'SA', 'SB', 'SC', 'SD', 'SE', 'SG', 'SH', 'SI', 'SJ', 'SK', 'SL', 'SM', 'SN', 'SO', 'SR', 'SS', 'ST', 'SV', 'SX', 'SY', 'SZ', 'TC', 'TD', 'TF', 'TG', 'TH', 'TJ', 'TK', 'TL', 'TM', 'TN', 'TO', 'TR', 'TT', 'TV', 'TW', 'TZ', 'UA', 'UG', 'UM', 'US', 'UY', 'UZ', 'VA', 'VC', 'VE', 'VG', 'VI', 'VN', 'VU', 'WF', 'WS', 'YE', 'YT', 'ZA', 'ZM', 'ZW']);
  1734. function isISO31661Alpha2(str) {
  1735. assertString(str);
  1736. return validISO31661Alpha2CountriesCodes.has(str.toUpperCase());
  1737. }
  1738. var CountryCodes = validISO31661Alpha2CountriesCodes;
  1739. // https://en.wikipedia.org/wiki/ISO_9362
  1740. var isBICReg = /^[A-Za-z]{6}[A-Za-z0-9]{2}([A-Za-z0-9]{3})?$/;
  1741. function isBIC(str) {
  1742. assertString(str);
  1743. // toUpperCase() should be removed when a new major version goes out that changes
  1744. // the regex to [A-Z] (per the spec).
  1745. var countryCode = str.slice(4, 6).toUpperCase();
  1746. if (!CountryCodes.has(countryCode) && countryCode !== 'XK') {
  1747. return false;
  1748. }
  1749. return isBICReg.test(str);
  1750. }
  1751. var md5 = /^[a-f0-9]{32}$/;
  1752. function isMD5(str) {
  1753. assertString(str);
  1754. return md5.test(str);
  1755. }
  1756. var lengths = {
  1757. md5: 32,
  1758. md4: 32,
  1759. sha1: 40,
  1760. sha256: 64,
  1761. sha384: 96,
  1762. sha512: 128,
  1763. ripemd128: 32,
  1764. ripemd160: 40,
  1765. tiger128: 32,
  1766. tiger160: 40,
  1767. tiger192: 48,
  1768. crc32: 8,
  1769. crc32b: 8
  1770. };
  1771. function isHash(str, algorithm) {
  1772. assertString(str);
  1773. var hash = new RegExp("^[a-fA-F0-9]{".concat(lengths[algorithm], "}$"));
  1774. return hash.test(str);
  1775. }
  1776. var notBase64 = /[^A-Z0-9+\/=]/i;
  1777. var urlSafeBase64 = /^[A-Z0-9_\-]*$/i;
  1778. var defaultBase64Options = {
  1779. urlSafe: false
  1780. };
  1781. function isBase64(str, options) {
  1782. assertString(str);
  1783. options = merge(options, defaultBase64Options);
  1784. var len = str.length;
  1785. if (options.urlSafe) {
  1786. return urlSafeBase64.test(str);
  1787. }
  1788. if (len % 4 !== 0 || notBase64.test(str)) {
  1789. return false;
  1790. }
  1791. var firstPaddingChar = str.indexOf('=');
  1792. return firstPaddingChar === -1 || firstPaddingChar === len - 1 || firstPaddingChar === len - 2 && str[len - 1] === '=';
  1793. }
  1794. function isJWT(str) {
  1795. assertString(str);
  1796. var dotSplit = str.split('.');
  1797. var len = dotSplit.length;
  1798. if (len !== 3) {
  1799. return false;
  1800. }
  1801. return dotSplit.reduce(function (acc, currElem) {
  1802. return acc && isBase64(currElem, {
  1803. urlSafe: true
  1804. });
  1805. }, true);
  1806. }
  1807. var default_json_options = {
  1808. allow_primitives: false
  1809. };
  1810. function isJSON(str, options) {
  1811. assertString(str);
  1812. try {
  1813. options = merge(options, default_json_options);
  1814. var primitives = [];
  1815. if (options.allow_primitives) {
  1816. primitives = [null, false, true];
  1817. }
  1818. var obj = JSON.parse(str);
  1819. return primitives.includes(obj) || !!obj && _typeof(obj) === 'object';
  1820. } catch (e) {/* ignore */}
  1821. return false;
  1822. }
  1823. var default_is_empty_options = {
  1824. ignore_whitespace: false
  1825. };
  1826. function isEmpty(str, options) {
  1827. assertString(str);
  1828. options = merge(options, default_is_empty_options);
  1829. return (options.ignore_whitespace ? str.trim().length : str.length) === 0;
  1830. }
  1831. /* eslint-disable prefer-rest-params */
  1832. function isLength(str, options) {
  1833. assertString(str);
  1834. var min;
  1835. var max;
  1836. if (_typeof(options) === 'object') {
  1837. min = options.min || 0;
  1838. max = options.max;
  1839. } else {
  1840. // backwards compatibility: isLength(str, min [, max])
  1841. min = arguments[1] || 0;
  1842. max = arguments[2];
  1843. }
  1844. var presentationSequences = str.match(/(\uFE0F|\uFE0E)/g) || [];
  1845. var surrogatePairs = str.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g) || [];
  1846. var len = str.length - presentationSequences.length - surrogatePairs.length;
  1847. return len >= min && (typeof max === 'undefined' || len <= max);
  1848. }
  1849. var uuid = {
  1850. 1: /^[0-9A-F]{8}-[0-9A-F]{4}-1[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,
  1851. 2: /^[0-9A-F]{8}-[0-9A-F]{4}-2[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,
  1852. 3: /^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,
  1853. 4: /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
  1854. 5: /^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
  1855. 7: /^[0-9A-F]{8}-[0-9A-F]{4}-7[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
  1856. all: /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i
  1857. };
  1858. function isUUID(str, version) {
  1859. assertString(str);
  1860. var pattern = uuid[![undefined, null].includes(version) ? version : 'all'];
  1861. return !!pattern && pattern.test(str);
  1862. }
  1863. function isMongoId(str) {
  1864. assertString(str);
  1865. return isHexadecimal(str) && str.length === 24;
  1866. }
  1867. function isAfter(date, options) {
  1868. // For backwards compatibility:
  1869. // isAfter(str [, date]), i.e. `options` could be used as argument for the legacy `date`
  1870. var comparisonDate = (options === null || options === void 0 ? void 0 : options.comparisonDate) || options || Date().toString();
  1871. var comparison = toDate(comparisonDate);
  1872. var original = toDate(date);
  1873. return !!(original && comparison && original > comparison);
  1874. }
  1875. function isBefore(str) {
  1876. var date = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : String(new Date());
  1877. assertString(str);
  1878. var comparison = toDate(date);
  1879. var original = toDate(str);
  1880. return !!(original && comparison && original < comparison);
  1881. }
  1882. function isIn(str, options) {
  1883. assertString(str);
  1884. var i;
  1885. if (Object.prototype.toString.call(options) === '[object Array]') {
  1886. var array = [];
  1887. for (i in options) {
  1888. // https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md#ignoring-code-for-coverage-purposes
  1889. // istanbul ignore else
  1890. if ({}.hasOwnProperty.call(options, i)) {
  1891. array[i] = toString$1(options[i]);
  1892. }
  1893. }
  1894. return array.indexOf(str) >= 0;
  1895. } else if (_typeof(options) === 'object') {
  1896. return options.hasOwnProperty(str);
  1897. } else if (options && typeof options.indexOf === 'function') {
  1898. return options.indexOf(str) >= 0;
  1899. }
  1900. return false;
  1901. }
  1902. function isLuhnNumber(str) {
  1903. assertString(str);
  1904. var sanitized = str.replace(/[- ]+/g, '');
  1905. var sum = 0;
  1906. var digit;
  1907. var tmpNum;
  1908. var shouldDouble;
  1909. for (var i = sanitized.length - 1; i >= 0; i--) {
  1910. digit = sanitized.substring(i, i + 1);
  1911. tmpNum = parseInt(digit, 10);
  1912. if (shouldDouble) {
  1913. tmpNum *= 2;
  1914. if (tmpNum >= 10) {
  1915. sum += tmpNum % 10 + 1;
  1916. } else {
  1917. sum += tmpNum;
  1918. }
  1919. } else {
  1920. sum += tmpNum;
  1921. }
  1922. shouldDouble = !shouldDouble;
  1923. }
  1924. return !!(sum % 10 === 0 ? sanitized : false);
  1925. }
  1926. var cards = {
  1927. amex: /^3[47][0-9]{13}$/,
  1928. dinersclub: /^3(?:0[0-5]|[68][0-9])[0-9]{11}$/,
  1929. discover: /^6(?:011|5[0-9][0-9])[0-9]{12,15}$/,
  1930. jcb: /^(?:2131|1800|35\d{3})\d{11}$/,
  1931. 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}$/,
  1932. // /^[25][1-7][0-9]{14}$/;
  1933. unionpay: /^(6[27][0-9]{14}|^(81[0-9]{14,17}))$/,
  1934. visa: /^(?:4[0-9]{12})(?:[0-9]{3,6})?$/
  1935. };
  1936. var allCards = function () {
  1937. var tmpCardsArray = [];
  1938. for (var cardProvider in cards) {
  1939. // istanbul ignore else
  1940. if (cards.hasOwnProperty(cardProvider)) {
  1941. tmpCardsArray.push(cards[cardProvider]);
  1942. }
  1943. }
  1944. return tmpCardsArray;
  1945. }();
  1946. function isCreditCard(card) {
  1947. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  1948. assertString(card);
  1949. var provider = options.provider;
  1950. var sanitized = card.replace(/[- ]+/g, '');
  1951. if (provider && provider.toLowerCase() in cards) {
  1952. // specific provider in the list
  1953. if (!cards[provider.toLowerCase()].test(sanitized)) {
  1954. return false;
  1955. }
  1956. } else if (provider && !(provider.toLowerCase() in cards)) {
  1957. /* specific provider not in the list */
  1958. throw new Error("".concat(provider, " is not a valid credit card provider."));
  1959. } else if (!allCards.some(function (cardProvider) {
  1960. return cardProvider.test(sanitized);
  1961. })) {
  1962. // no specific provider
  1963. return false;
  1964. }
  1965. return isLuhnNumber(card);
  1966. }
  1967. var validators = {
  1968. PL: function PL(str) {
  1969. assertString(str);
  1970. var weightOfDigits = {
  1971. 1: 1,
  1972. 2: 3,
  1973. 3: 7,
  1974. 4: 9,
  1975. 5: 1,
  1976. 6: 3,
  1977. 7: 7,
  1978. 8: 9,
  1979. 9: 1,
  1980. 10: 3,
  1981. 11: 0
  1982. };
  1983. if (str != null && str.length === 11 && isInt(str, {
  1984. allow_leading_zeroes: true
  1985. })) {
  1986. var digits = str.split('').slice(0, -1);
  1987. var sum = digits.reduce(function (acc, digit, index) {
  1988. return acc + Number(digit) * weightOfDigits[index + 1];
  1989. }, 0);
  1990. var modulo = sum % 10;
  1991. var lastDigit = Number(str.charAt(str.length - 1));
  1992. if (modulo === 0 && lastDigit === 0 || lastDigit === 10 - modulo) {
  1993. return true;
  1994. }
  1995. }
  1996. return false;
  1997. },
  1998. ES: function ES(str) {
  1999. assertString(str);
  2000. var DNI = /^[0-9X-Z][0-9]{7}[TRWAGMYFPDXBNJZSQVHLCKE]$/;
  2001. var charsValue = {
  2002. X: 0,
  2003. Y: 1,
  2004. Z: 2
  2005. };
  2006. var controlDigits = ['T', 'R', 'W', 'A', 'G', 'M', 'Y', 'F', 'P', 'D', 'X', 'B', 'N', 'J', 'Z', 'S', 'Q', 'V', 'H', 'L', 'C', 'K', 'E'];
  2007. // sanitize user input
  2008. var sanitized = str.trim().toUpperCase();
  2009. // validate the data structure
  2010. if (!DNI.test(sanitized)) {
  2011. return false;
  2012. }
  2013. // validate the control digit
  2014. var number = sanitized.slice(0, -1).replace(/[X,Y,Z]/g, function (_char) {
  2015. return charsValue[_char];
  2016. });
  2017. return sanitized.endsWith(controlDigits[number % 23]);
  2018. },
  2019. FI: function FI(str) {
  2020. // https://dvv.fi/en/personal-identity-code#:~:text=control%20character%20for%20a-,personal,-identity%20code%20calculated
  2021. assertString(str);
  2022. if (str.length !== 11) {
  2023. return false;
  2024. }
  2025. if (!str.match(/^\d{6}[\-A\+]\d{3}[0-9ABCDEFHJKLMNPRSTUVWXY]{1}$/)) {
  2026. return false;
  2027. }
  2028. var checkDigits = '0123456789ABCDEFHJKLMNPRSTUVWXY';
  2029. var idAsNumber = parseInt(str.slice(0, 6), 10) * 1000 + parseInt(str.slice(7, 10), 10);
  2030. var remainder = idAsNumber % 31;
  2031. var checkDigit = checkDigits[remainder];
  2032. return checkDigit === str.slice(10, 11);
  2033. },
  2034. IN: function IN(str) {
  2035. var DNI = /^[1-9]\d{3}\s?\d{4}\s?\d{4}$/;
  2036. // multiplication table
  2037. var d = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 2, 3, 4, 0, 6, 7, 8, 9, 5], [2, 3, 4, 0, 1, 7, 8, 9, 5, 6], [3, 4, 0, 1, 2, 8, 9, 5, 6, 7], [4, 0, 1, 2, 3, 9, 5, 6, 7, 8], [5, 9, 8, 7, 6, 0, 4, 3, 2, 1], [6, 5, 9, 8, 7, 1, 0, 4, 3, 2], [7, 6, 5, 9, 8, 2, 1, 0, 4, 3], [8, 7, 6, 5, 9, 3, 2, 1, 0, 4], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]];
  2038. // permutation table
  2039. var p = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 5, 7, 6, 2, 8, 3, 0, 9, 4], [5, 8, 0, 3, 7, 9, 6, 1, 4, 2], [8, 9, 1, 6, 0, 4, 3, 5, 2, 7], [9, 4, 5, 3, 1, 2, 6, 8, 7, 0], [4, 2, 8, 6, 5, 7, 3, 9, 0, 1], [2, 7, 9, 3, 8, 0, 6, 4, 1, 5], [7, 0, 4, 6, 9, 1, 3, 2, 5, 8]];
  2040. // sanitize user input
  2041. var sanitized = str.trim();
  2042. // validate the data structure
  2043. if (!DNI.test(sanitized)) {
  2044. return false;
  2045. }
  2046. var c = 0;
  2047. var invertedArray = sanitized.replace(/\s/g, '').split('').map(Number).reverse();
  2048. invertedArray.forEach(function (val, i) {
  2049. c = d[c][p[i % 8][val]];
  2050. });
  2051. return c === 0;
  2052. },
  2053. IR: function IR(str) {
  2054. if (!str.match(/^\d{10}$/)) return false;
  2055. str = "0000".concat(str).slice(str.length - 6);
  2056. if (parseInt(str.slice(3, 9), 10) === 0) return false;
  2057. var lastNumber = parseInt(str.slice(9, 10), 10);
  2058. var sum = 0;
  2059. for (var i = 0; i < 9; i++) {
  2060. sum += parseInt(str.slice(i, i + 1), 10) * (10 - i);
  2061. }
  2062. sum %= 11;
  2063. return sum < 2 && lastNumber === sum || sum >= 2 && lastNumber === 11 - sum;
  2064. },
  2065. IT: function IT(str) {
  2066. if (str.length !== 9) return false;
  2067. if (str === 'CA00000AA') return false; // https://it.wikipedia.org/wiki/Carta_d%27identit%C3%A0_elettronica_italiana
  2068. return str.search(/C[A-Z]\d{5}[A-Z]{2}/i) > -1;
  2069. },
  2070. NO: function NO(str) {
  2071. var sanitized = str.trim();
  2072. if (isNaN(Number(sanitized))) return false;
  2073. if (sanitized.length !== 11) return false;
  2074. if (sanitized === '00000000000') return false;
  2075. // https://no.wikipedia.org/wiki/F%C3%B8dselsnummer
  2076. var f = sanitized.split('').map(Number);
  2077. var k1 = (11 - (3 * f[0] + 7 * f[1] + 6 * f[2] + 1 * f[3] + 8 * f[4] + 9 * f[5] + 4 * f[6] + 5 * f[7] + 2 * f[8]) % 11) % 11;
  2078. var k2 = (11 - (5 * f[0] + 4 * f[1] + 3 * f[2] + 2 * f[3] + 7 * f[4] + 6 * f[5] + 5 * f[6] + 4 * f[7] + 3 * f[8] + 2 * k1) % 11) % 11;
  2079. if (k1 !== f[9] || k2 !== f[10]) return false;
  2080. return true;
  2081. },
  2082. TH: function TH(str) {
  2083. if (!str.match(/^[1-8]\d{12}$/)) return false;
  2084. // validate check digit
  2085. var sum = 0;
  2086. for (var i = 0; i < 12; i++) {
  2087. sum += parseInt(str[i], 10) * (13 - i);
  2088. }
  2089. return str[12] === ((11 - sum % 11) % 10).toString();
  2090. },
  2091. LK: function LK(str) {
  2092. var old_nic = /^[1-9]\d{8}[vx]$/i;
  2093. var new_nic = /^[1-9]\d{11}$/i;
  2094. if (str.length === 10 && old_nic.test(str)) return true;else if (str.length === 12 && new_nic.test(str)) return true;
  2095. return false;
  2096. },
  2097. 'he-IL': function heIL(str) {
  2098. var DNI = /^\d{9}$/;
  2099. // sanitize user input
  2100. var sanitized = str.trim();
  2101. // validate the data structure
  2102. if (!DNI.test(sanitized)) {
  2103. return false;
  2104. }
  2105. var id = sanitized;
  2106. var sum = 0,
  2107. incNum;
  2108. for (var i = 0; i < id.length; i++) {
  2109. incNum = Number(id[i]) * (i % 2 + 1); // Multiply number by 1 or 2
  2110. sum += incNum > 9 ? incNum - 9 : incNum; // Sum the digits up and add to total
  2111. }
  2112. return sum % 10 === 0;
  2113. },
  2114. 'ar-LY': function arLY(str) {
  2115. // Libya National Identity Number NIN is 12 digits, the first digit is either 1 or 2
  2116. var NIN = /^(1|2)\d{11}$/;
  2117. // sanitize user input
  2118. var sanitized = str.trim();
  2119. // validate the data structure
  2120. if (!NIN.test(sanitized)) {
  2121. return false;
  2122. }
  2123. return true;
  2124. },
  2125. 'ar-TN': function arTN(str) {
  2126. var DNI = /^\d{8}$/;
  2127. // sanitize user input
  2128. var sanitized = str.trim();
  2129. // validate the data structure
  2130. if (!DNI.test(sanitized)) {
  2131. return false;
  2132. }
  2133. return true;
  2134. },
  2135. 'zh-CN': function zhCN(str) {
  2136. var provincesAndCities = ['11',
  2137. // 北京
  2138. '12',
  2139. // 天津
  2140. '13',
  2141. // 河北
  2142. '14',
  2143. // 山西
  2144. '15',
  2145. // 内蒙古
  2146. '21',
  2147. // 辽宁
  2148. '22',
  2149. // 吉林
  2150. '23',
  2151. // 黑龙江
  2152. '31',
  2153. // 上海
  2154. '32',
  2155. // 江苏
  2156. '33',
  2157. // 浙江
  2158. '34',
  2159. // 安徽
  2160. '35',
  2161. // 福建
  2162. '36',
  2163. // 江西
  2164. '37',
  2165. // 山东
  2166. '41',
  2167. // 河南
  2168. '42',
  2169. // 湖北
  2170. '43',
  2171. // 湖南
  2172. '44',
  2173. // 广东
  2174. '45',
  2175. // 广西
  2176. '46',
  2177. // 海南
  2178. '50',
  2179. // 重庆
  2180. '51',
  2181. // 四川
  2182. '52',
  2183. // 贵州
  2184. '53',
  2185. // 云南
  2186. '54',
  2187. // 西藏
  2188. '61',
  2189. // 陕西
  2190. '62',
  2191. // 甘肃
  2192. '63',
  2193. // 青海
  2194. '64',
  2195. // 宁夏
  2196. '65',
  2197. // 新疆
  2198. '71',
  2199. // 台湾
  2200. '81',
  2201. // 香港
  2202. '82',
  2203. // 澳门
  2204. '91' // 国外
  2205. ];
  2206. var powers = ['7', '9', '10', '5', '8', '4', '2', '1', '6', '3', '7', '9', '10', '5', '8', '4', '2'];
  2207. var parityBit = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'];
  2208. var checkAddressCode = function checkAddressCode(addressCode) {
  2209. return provincesAndCities.includes(addressCode);
  2210. };
  2211. var checkBirthDayCode = function checkBirthDayCode(birDayCode) {
  2212. var yyyy = parseInt(birDayCode.substring(0, 4), 10);
  2213. var mm = parseInt(birDayCode.substring(4, 6), 10);
  2214. var dd = parseInt(birDayCode.substring(6), 10);
  2215. var xdata = new Date(yyyy, mm - 1, dd);
  2216. if (xdata > new Date()) {
  2217. return false;
  2218. // eslint-disable-next-line max-len
  2219. } else if (xdata.getFullYear() === yyyy && xdata.getMonth() === mm - 1 && xdata.getDate() === dd) {
  2220. return true;
  2221. }
  2222. return false;
  2223. };
  2224. var getParityBit = function getParityBit(idCardNo) {
  2225. var id17 = idCardNo.substring(0, 17);
  2226. var power = 0;
  2227. for (var i = 0; i < 17; i++) {
  2228. power += parseInt(id17.charAt(i), 10) * parseInt(powers[i], 10);
  2229. }
  2230. var mod = power % 11;
  2231. return parityBit[mod];
  2232. };
  2233. var checkParityBit = function checkParityBit(idCardNo) {
  2234. return getParityBit(idCardNo) === idCardNo.charAt(17).toUpperCase();
  2235. };
  2236. var check15IdCardNo = function check15IdCardNo(idCardNo) {
  2237. var check = /^[1-9]\d{7}((0[1-9])|(1[0-2]))((0[1-9])|([1-2][0-9])|(3[0-1]))\d{3}$/.test(idCardNo);
  2238. if (!check) return false;
  2239. var addressCode = idCardNo.substring(0, 2);
  2240. check = checkAddressCode(addressCode);
  2241. if (!check) return false;
  2242. var birDayCode = "19".concat(idCardNo.substring(6, 12));
  2243. check = checkBirthDayCode(birDayCode);
  2244. if (!check) return false;
  2245. return true;
  2246. };
  2247. var check18IdCardNo = function check18IdCardNo(idCardNo) {
  2248. var check = /^[1-9]\d{5}[1-9]\d{3}((0[1-9])|(1[0-2]))((0[1-9])|([1-2][0-9])|(3[0-1]))\d{3}(\d|x|X)$/.test(idCardNo);
  2249. if (!check) return false;
  2250. var addressCode = idCardNo.substring(0, 2);
  2251. check = checkAddressCode(addressCode);
  2252. if (!check) return false;
  2253. var birDayCode = idCardNo.substring(6, 14);
  2254. check = checkBirthDayCode(birDayCode);
  2255. if (!check) return false;
  2256. return checkParityBit(idCardNo);
  2257. };
  2258. var checkIdCardNo = function checkIdCardNo(idCardNo) {
  2259. var check = /^\d{15}|(\d{17}(\d|x|X))$/.test(idCardNo);
  2260. if (!check) return false;
  2261. if (idCardNo.length === 15) {
  2262. return check15IdCardNo(idCardNo);
  2263. }
  2264. return check18IdCardNo(idCardNo);
  2265. };
  2266. return checkIdCardNo(str);
  2267. },
  2268. 'zh-HK': function zhHK(str) {
  2269. // sanitize user input
  2270. str = str.trim();
  2271. // HKID number starts with 1 or 2 letters, followed by 6 digits,
  2272. // then a checksum contained in square / round brackets or nothing
  2273. var regexHKID = /^[A-Z]{1,2}[0-9]{6}((\([0-9A]\))|(\[[0-9A]\])|([0-9A]))$/;
  2274. var regexIsDigit = /^[0-9]$/;
  2275. // convert the user input to all uppercase and apply regex
  2276. str = str.toUpperCase();
  2277. if (!regexHKID.test(str)) return false;
  2278. str = str.replace(/\[|\]|\(|\)/g, '');
  2279. if (str.length === 8) str = "3".concat(str);
  2280. var checkSumVal = 0;
  2281. for (var i = 0; i <= 7; i++) {
  2282. var convertedChar = void 0;
  2283. if (!regexIsDigit.test(str[i])) convertedChar = (str[i].charCodeAt(0) - 55) % 11;else convertedChar = str[i];
  2284. checkSumVal += convertedChar * (9 - i);
  2285. }
  2286. checkSumVal %= 11;
  2287. var checkSumConverted;
  2288. if (checkSumVal === 0) checkSumConverted = '0';else if (checkSumVal === 1) checkSumConverted = 'A';else checkSumConverted = String(11 - checkSumVal);
  2289. if (checkSumConverted === str[str.length - 1]) return true;
  2290. return false;
  2291. },
  2292. 'zh-TW': function zhTW(str) {
  2293. var ALPHABET_CODES = {
  2294. A: 10,
  2295. B: 11,
  2296. C: 12,
  2297. D: 13,
  2298. E: 14,
  2299. F: 15,
  2300. G: 16,
  2301. H: 17,
  2302. I: 34,
  2303. J: 18,
  2304. K: 19,
  2305. L: 20,
  2306. M: 21,
  2307. N: 22,
  2308. O: 35,
  2309. P: 23,
  2310. Q: 24,
  2311. R: 25,
  2312. S: 26,
  2313. T: 27,
  2314. U: 28,
  2315. V: 29,
  2316. W: 32,
  2317. X: 30,
  2318. Y: 31,
  2319. Z: 33
  2320. };
  2321. var sanitized = str.trim().toUpperCase();
  2322. if (!/^[A-Z][0-9]{9}$/.test(sanitized)) return false;
  2323. return Array.from(sanitized).reduce(function (sum, number, index) {
  2324. if (index === 0) {
  2325. var code = ALPHABET_CODES[number];
  2326. return code % 10 * 9 + Math.floor(code / 10);
  2327. }
  2328. if (index === 9) {
  2329. return (10 - sum % 10 - Number(number)) % 10 === 0;
  2330. }
  2331. return sum + Number(number) * (9 - index);
  2332. }, 0);
  2333. }
  2334. };
  2335. function isIdentityCard(str, locale) {
  2336. assertString(str);
  2337. if (locale in validators) {
  2338. return validators[locale](str);
  2339. } else if (locale === 'any') {
  2340. for (var key in validators) {
  2341. // https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md#ignoring-code-for-coverage-purposes
  2342. // istanbul ignore else
  2343. if (validators.hasOwnProperty(key)) {
  2344. var validator = validators[key];
  2345. if (validator(str)) {
  2346. return true;
  2347. }
  2348. }
  2349. }
  2350. return false;
  2351. }
  2352. throw new Error("Invalid locale '".concat(locale, "'"));
  2353. }
  2354. /**
  2355. * The most commonly used EAN standard is
  2356. * the thirteen-digit EAN-13, while the
  2357. * less commonly used 8-digit EAN-8 barcode was
  2358. * introduced for use on small packages.
  2359. * Also EAN/UCC-14 is used for Grouping of individual
  2360. * trade items above unit level(Intermediate, Carton or Pallet).
  2361. * For more info about EAN-14 checkout: https://www.gtin.info/itf-14-barcodes/
  2362. * EAN consists of:
  2363. * GS1 prefix, manufacturer code, product code and check digit
  2364. * Reference: https://en.wikipedia.org/wiki/International_Article_Number
  2365. * Reference: https://www.gtin.info/
  2366. */
  2367. /**
  2368. * Define EAN Lenghts; 8 for EAN-8; 13 for EAN-13; 14 for EAN-14
  2369. * and Regular Expression for valid EANs (EAN-8, EAN-13, EAN-14),
  2370. * with exact numberic matching of 8 or 13 or 14 digits [0-9]
  2371. */
  2372. var LENGTH_EAN_8 = 8;
  2373. var LENGTH_EAN_14 = 14;
  2374. var validEanRegex = /^(\d{8}|\d{13}|\d{14})$/;
  2375. /**
  2376. * Get position weight given:
  2377. * EAN length and digit index/position
  2378. *
  2379. * @param {number} length
  2380. * @param {number} index
  2381. * @return {number}
  2382. */
  2383. function getPositionWeightThroughLengthAndIndex(length, index) {
  2384. if (length === LENGTH_EAN_8 || length === LENGTH_EAN_14) {
  2385. return index % 2 === 0 ? 3 : 1;
  2386. }
  2387. return index % 2 === 0 ? 1 : 3;
  2388. }
  2389. /**
  2390. * Calculate EAN Check Digit
  2391. * Reference: https://en.wikipedia.org/wiki/International_Article_Number#Calculation_of_checksum_digit
  2392. *
  2393. * @param {string} ean
  2394. * @return {number}
  2395. */
  2396. function calculateCheckDigit(ean) {
  2397. var checksum = ean.slice(0, -1).split('').map(function (_char, index) {
  2398. return Number(_char) * getPositionWeightThroughLengthAndIndex(ean.length, index);
  2399. }).reduce(function (acc, partialSum) {
  2400. return acc + partialSum;
  2401. }, 0);
  2402. var remainder = 10 - checksum % 10;
  2403. return remainder < 10 ? remainder : 0;
  2404. }
  2405. /**
  2406. * Check if string is valid EAN:
  2407. * Matches EAN-8/EAN-13/EAN-14 regex
  2408. * Has valid check digit.
  2409. *
  2410. * @param {string} str
  2411. * @return {boolean}
  2412. */
  2413. function isEAN(str) {
  2414. assertString(str);
  2415. var actualCheckDigit = Number(str.slice(-1));
  2416. return validEanRegex.test(str) && actualCheckDigit === calculateCheckDigit(str);
  2417. }
  2418. var isin = /^[A-Z]{2}[0-9A-Z]{9}[0-9]$/;
  2419. // this link details how the check digit is calculated:
  2420. // https://www.isin.org/isin-format/. it is a little bit
  2421. // odd in that it works with digits, not numbers. in order
  2422. // to make only one pass through the ISIN characters, the
  2423. // each alpha character is handled as 2 characters within
  2424. // the loop.
  2425. function isISIN(str) {
  2426. assertString(str);
  2427. if (!isin.test(str)) {
  2428. return false;
  2429. }
  2430. var _double = true;
  2431. var sum = 0;
  2432. // convert values
  2433. for (var i = str.length - 2; i >= 0; i--) {
  2434. if (str[i] >= 'A' && str[i] <= 'Z') {
  2435. var value = str[i].charCodeAt(0) - 55;
  2436. var lo = value % 10;
  2437. var hi = Math.trunc(value / 10);
  2438. // letters have two digits, so handle the low order
  2439. // and high order digits separately.
  2440. for (var _i = 0, _arr = [lo, hi]; _i < _arr.length; _i++) {
  2441. var digit = _arr[_i];
  2442. if (_double) {
  2443. if (digit >= 5) {
  2444. sum += 1 + (digit - 5) * 2;
  2445. } else {
  2446. sum += digit * 2;
  2447. }
  2448. } else {
  2449. sum += digit;
  2450. }
  2451. _double = !_double;
  2452. }
  2453. } else {
  2454. var _digit = str[i].charCodeAt(0) - '0'.charCodeAt(0);
  2455. if (_double) {
  2456. if (_digit >= 5) {
  2457. sum += 1 + (_digit - 5) * 2;
  2458. } else {
  2459. sum += _digit * 2;
  2460. }
  2461. } else {
  2462. sum += _digit;
  2463. }
  2464. _double = !_double;
  2465. }
  2466. }
  2467. var check = Math.trunc((sum + 9) / 10) * 10 - sum;
  2468. return +str[str.length - 1] === check;
  2469. }
  2470. var possibleIsbn10 = /^(?:[0-9]{9}X|[0-9]{10})$/;
  2471. var possibleIsbn13 = /^(?:[0-9]{13})$/;
  2472. var factor = [1, 3];
  2473. function isISBN(isbn, options) {
  2474. assertString(isbn);
  2475. // For backwards compatibility:
  2476. // isISBN(str [, version]), i.e. `options` could be used as argument for the legacy `version`
  2477. var version = String((options === null || options === void 0 ? void 0 : options.version) || options);
  2478. if (!(options !== null && options !== void 0 && options.version || options)) {
  2479. return isISBN(isbn, {
  2480. version: 10
  2481. }) || isISBN(isbn, {
  2482. version: 13
  2483. });
  2484. }
  2485. var sanitizedIsbn = isbn.replace(/[\s-]+/g, '');
  2486. var checksum = 0;
  2487. if (version === '10') {
  2488. if (!possibleIsbn10.test(sanitizedIsbn)) {
  2489. return false;
  2490. }
  2491. for (var i = 0; i < version - 1; i++) {
  2492. checksum += (i + 1) * sanitizedIsbn.charAt(i);
  2493. }
  2494. if (sanitizedIsbn.charAt(9) === 'X') {
  2495. checksum += 10 * 10;
  2496. } else {
  2497. checksum += 10 * sanitizedIsbn.charAt(9);
  2498. }
  2499. if (checksum % 11 === 0) {
  2500. return true;
  2501. }
  2502. } else if (version === '13') {
  2503. if (!possibleIsbn13.test(sanitizedIsbn)) {
  2504. return false;
  2505. }
  2506. for (var _i = 0; _i < 12; _i++) {
  2507. checksum += factor[_i % 2] * sanitizedIsbn.charAt(_i);
  2508. }
  2509. if (sanitizedIsbn.charAt(12) - (10 - checksum % 10) % 10 === 0) {
  2510. return true;
  2511. }
  2512. }
  2513. return false;
  2514. }
  2515. var issn = '^\\d{4}-?\\d{3}[\\dX]$';
  2516. function isISSN(str) {
  2517. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  2518. assertString(str);
  2519. var testIssn = issn;
  2520. testIssn = options.require_hyphen ? testIssn.replace('?', '') : testIssn;
  2521. testIssn = options.case_sensitive ? new RegExp(testIssn) : new RegExp(testIssn, 'i');
  2522. if (!testIssn.test(str)) {
  2523. return false;
  2524. }
  2525. var digits = str.replace('-', '').toUpperCase();
  2526. var checksum = 0;
  2527. for (var i = 0; i < digits.length; i++) {
  2528. var digit = digits[i];
  2529. checksum += (digit === 'X' ? 10 : +digit) * (8 - i);
  2530. }
  2531. return checksum % 11 === 0;
  2532. }
  2533. /**
  2534. * Algorithmic validation functions
  2535. * May be used as is or implemented in the workflow of other validators.
  2536. */
  2537. /*
  2538. * ISO 7064 validation function
  2539. * Called with a string of numbers (incl. check digit)
  2540. * to validate according to ISO 7064 (MOD 11, 10).
  2541. */
  2542. function iso7064Check(str) {
  2543. var checkvalue = 10;
  2544. for (var i = 0; i < str.length - 1; i++) {
  2545. checkvalue = (parseInt(str[i], 10) + checkvalue) % 10 === 0 ? 10 * 2 % 11 : (parseInt(str[i], 10) + checkvalue) % 10 * 2 % 11;
  2546. }
  2547. checkvalue = checkvalue === 1 ? 0 : 11 - checkvalue;
  2548. return checkvalue === parseInt(str[10], 10);
  2549. }
  2550. /*
  2551. * Luhn (mod 10) validation function
  2552. * Called with a string of numbers (incl. check digit)
  2553. * to validate according to the Luhn algorithm.
  2554. */
  2555. function luhnCheck(str) {
  2556. var checksum = 0;
  2557. var second = false;
  2558. for (var i = str.length - 1; i >= 0; i--) {
  2559. if (second) {
  2560. var product = parseInt(str[i], 10) * 2;
  2561. if (product > 9) {
  2562. // sum digits of product and add to checksum
  2563. checksum += product.toString().split('').map(function (a) {
  2564. return parseInt(a, 10);
  2565. }).reduce(function (a, b) {
  2566. return a + b;
  2567. }, 0);
  2568. } else {
  2569. checksum += product;
  2570. }
  2571. } else {
  2572. checksum += parseInt(str[i], 10);
  2573. }
  2574. second = !second;
  2575. }
  2576. return checksum % 10 === 0;
  2577. }
  2578. /*
  2579. * Reverse TIN multiplication and summation helper function
  2580. * Called with an array of single-digit integers and a base multiplier
  2581. * to calculate the sum of the digits multiplied in reverse.
  2582. * Normally used in variations of MOD 11 algorithmic checks.
  2583. */
  2584. function reverseMultiplyAndSum(digits, base) {
  2585. var total = 0;
  2586. for (var i = 0; i < digits.length; i++) {
  2587. total += digits[i] * (base - i);
  2588. }
  2589. return total;
  2590. }
  2591. /*
  2592. * Verhoeff validation helper function
  2593. * Called with a string of numbers
  2594. * to validate according to the Verhoeff algorithm.
  2595. */
  2596. function verhoeffCheck(str) {
  2597. var d_table = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 2, 3, 4, 0, 6, 7, 8, 9, 5], [2, 3, 4, 0, 1, 7, 8, 9, 5, 6], [3, 4, 0, 1, 2, 8, 9, 5, 6, 7], [4, 0, 1, 2, 3, 9, 5, 6, 7, 8], [5, 9, 8, 7, 6, 0, 4, 3, 2, 1], [6, 5, 9, 8, 7, 1, 0, 4, 3, 2], [7, 6, 5, 9, 8, 2, 1, 0, 4, 3], [8, 7, 6, 5, 9, 3, 2, 1, 0, 4], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]];
  2598. var p_table = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 5, 7, 6, 2, 8, 3, 0, 9, 4], [5, 8, 0, 3, 7, 9, 6, 1, 4, 2], [8, 9, 1, 6, 0, 4, 3, 5, 2, 7], [9, 4, 5, 3, 1, 2, 6, 8, 7, 0], [4, 2, 8, 6, 5, 7, 3, 9, 0, 1], [2, 7, 9, 3, 8, 0, 6, 4, 1, 5], [7, 0, 4, 6, 9, 1, 3, 2, 5, 8]];
  2599. // Copy (to prevent replacement) and reverse
  2600. var str_copy = str.split('').reverse().join('');
  2601. var checksum = 0;
  2602. for (var i = 0; i < str_copy.length; i++) {
  2603. checksum = d_table[checksum][p_table[i % 8][parseInt(str_copy[i], 10)]];
  2604. }
  2605. return checksum === 0;
  2606. }
  2607. /**
  2608. * TIN Validation
  2609. * Validates Tax Identification Numbers (TINs) from the US, EU member states and the United Kingdom.
  2610. *
  2611. * EU-UK:
  2612. * National TIN validity is calculated using public algorithms as made available by DG TAXUD.
  2613. *
  2614. * See `https://ec.europa.eu/taxation_customs/tin/specs/FS-TIN%20Algorithms-Public.docx` for more information.
  2615. *
  2616. * US:
  2617. * An Employer Identification Number (EIN), also known as a Federal Tax Identification Number,
  2618. * is used to identify a business entity.
  2619. *
  2620. * NOTES:
  2621. * - Prefix 47 is being reserved for future use
  2622. * - Prefixes 26, 27, 45, 46 and 47 were previously assigned by the Philadelphia campus.
  2623. *
  2624. * See `http://www.irs.gov/Businesses/Small-Businesses-&-Self-Employed/How-EINs-are-Assigned-and-Valid-EIN-Prefixes`
  2625. * for more information.
  2626. */
  2627. // Locale functions
  2628. /*
  2629. * bg-BG validation function
  2630. * (Edinen graždanski nomer (EGN/ЕГН), persons only)
  2631. * Checks if birth date (first six digits) is valid and calculates check (last) digit
  2632. */
  2633. function bgBgCheck(tin) {
  2634. // Extract full year, normalize month and check birth date validity
  2635. var century_year = tin.slice(0, 2);
  2636. var month = parseInt(tin.slice(2, 4), 10);
  2637. if (month > 40) {
  2638. month -= 40;
  2639. century_year = "20".concat(century_year);
  2640. } else if (month > 20) {
  2641. month -= 20;
  2642. century_year = "18".concat(century_year);
  2643. } else {
  2644. century_year = "19".concat(century_year);
  2645. }
  2646. if (month < 10) {
  2647. month = "0".concat(month);
  2648. }
  2649. var date = "".concat(century_year, "/").concat(month, "/").concat(tin.slice(4, 6));
  2650. if (!isDate(date, 'YYYY/MM/DD')) {
  2651. return false;
  2652. }
  2653. // split digits into an array for further processing
  2654. var digits = tin.split('').map(function (a) {
  2655. return parseInt(a, 10);
  2656. });
  2657. // Calculate checksum by multiplying digits with fixed values
  2658. var multip_lookup = [2, 4, 8, 5, 10, 9, 7, 3, 6];
  2659. var checksum = 0;
  2660. for (var i = 0; i < multip_lookup.length; i++) {
  2661. checksum += digits[i] * multip_lookup[i];
  2662. }
  2663. checksum = checksum % 11 === 10 ? 0 : checksum % 11;
  2664. return checksum === digits[9];
  2665. }
  2666. /**
  2667. * Check if an input is a valid Canadian SIN (Social Insurance Number)
  2668. *
  2669. * The Social Insurance Number (SIN) is a 9 digit number that
  2670. * you need to work in Canada or to have access to government programs and benefits.
  2671. *
  2672. * https://en.wikipedia.org/wiki/Social_Insurance_Number
  2673. * https://www.canada.ca/en/employment-social-development/services/sin.html
  2674. * https://www.codercrunch.com/challenge/819302488/sin-validator
  2675. *
  2676. * @param {string} input
  2677. * @return {boolean}
  2678. */
  2679. function isCanadianSIN(input) {
  2680. var digitsArray = input.split('');
  2681. var even = digitsArray.filter(function (_, idx) {
  2682. return idx % 2;
  2683. }).map(function (i) {
  2684. return Number(i) * 2;
  2685. }).join('').split('');
  2686. var total = digitsArray.filter(function (_, idx) {
  2687. return !(idx % 2);
  2688. }).concat(even).map(function (i) {
  2689. return Number(i);
  2690. }).reduce(function (acc, cur) {
  2691. return acc + cur;
  2692. });
  2693. return total % 10 === 0;
  2694. }
  2695. /*
  2696. * cs-CZ validation function
  2697. * (Rodné číslo (RČ), persons only)
  2698. * Checks if birth date (first six digits) is valid and divisibility by 11
  2699. * Material not in DG TAXUD document sourced from:
  2700. * -`https://lorenc.info/3MA381/overeni-spravnosti-rodneho-cisla.htm`
  2701. * -`https://www.mvcr.cz/clanek/rady-a-sluzby-dokumenty-rodne-cislo.aspx`
  2702. */
  2703. function csCzCheck(tin) {
  2704. tin = tin.replace(/\W/, '');
  2705. // Extract full year from TIN length
  2706. var full_year = parseInt(tin.slice(0, 2), 10);
  2707. if (tin.length === 10) {
  2708. if (full_year < 54) {
  2709. full_year = "20".concat(full_year);
  2710. } else {
  2711. full_year = "19".concat(full_year);
  2712. }
  2713. } else {
  2714. if (tin.slice(6) === '000') {
  2715. return false;
  2716. } // Three-zero serial not assigned before 1954
  2717. if (full_year < 54) {
  2718. full_year = "19".concat(full_year);
  2719. } else {
  2720. return false; // No 18XX years seen in any of the resources
  2721. }
  2722. }
  2723. // Add missing zero if needed
  2724. if (full_year.length === 3) {
  2725. full_year = [full_year.slice(0, 2), '0', full_year.slice(2)].join('');
  2726. }
  2727. // Extract month from TIN and normalize
  2728. var month = parseInt(tin.slice(2, 4), 10);
  2729. if (month > 50) {
  2730. month -= 50;
  2731. }
  2732. if (month > 20) {
  2733. // Month-plus-twenty was only introduced in 2004
  2734. if (parseInt(full_year, 10) < 2004) {
  2735. return false;
  2736. }
  2737. month -= 20;
  2738. }
  2739. if (month < 10) {
  2740. month = "0".concat(month);
  2741. }
  2742. // Check date validity
  2743. var date = "".concat(full_year, "/").concat(month, "/").concat(tin.slice(4, 6));
  2744. if (!isDate(date, 'YYYY/MM/DD')) {
  2745. return false;
  2746. }
  2747. // Verify divisibility by 11
  2748. if (tin.length === 10) {
  2749. if (parseInt(tin, 10) % 11 !== 0) {
  2750. // Some numbers up to and including 1985 are still valid if
  2751. // check (last) digit equals 0 and modulo of first 9 digits equals 10
  2752. var checkdigit = parseInt(tin.slice(0, 9), 10) % 11;
  2753. if (parseInt(full_year, 10) < 1986 && checkdigit === 10) {
  2754. if (parseInt(tin.slice(9), 10) !== 0) {
  2755. return false;
  2756. }
  2757. } else {
  2758. return false;
  2759. }
  2760. }
  2761. }
  2762. return true;
  2763. }
  2764. /*
  2765. * de-AT validation function
  2766. * (Abgabenkontonummer, persons/entities)
  2767. * Verify TIN validity by calling luhnCheck()
  2768. */
  2769. function deAtCheck(tin) {
  2770. return luhnCheck(tin);
  2771. }
  2772. /*
  2773. * de-DE validation function
  2774. * (Steueridentifikationsnummer (Steuer-IdNr.), persons only)
  2775. * Tests for single duplicate/triplicate value, then calculates ISO 7064 check (last) digit
  2776. * Partial implementation of spec (same result with both algorithms always)
  2777. */
  2778. function deDeCheck(tin) {
  2779. // Split digits into an array for further processing
  2780. var digits = tin.split('').map(function (a) {
  2781. return parseInt(a, 10);
  2782. });
  2783. // Fill array with strings of number positions
  2784. var occurences = [];
  2785. for (var i = 0; i < digits.length - 1; i++) {
  2786. occurences.push('');
  2787. for (var j = 0; j < digits.length - 1; j++) {
  2788. if (digits[i] === digits[j]) {
  2789. occurences[i] += j;
  2790. }
  2791. }
  2792. }
  2793. // Remove digits with one occurence and test for only one duplicate/triplicate
  2794. occurences = occurences.filter(function (a) {
  2795. return a.length > 1;
  2796. });
  2797. if (occurences.length !== 2 && occurences.length !== 3) {
  2798. return false;
  2799. }
  2800. // In case of triplicate value only two digits are allowed next to each other
  2801. if (occurences[0].length === 3) {
  2802. var trip_locations = occurences[0].split('').map(function (a) {
  2803. return parseInt(a, 10);
  2804. });
  2805. var recurrent = 0; // Amount of neighbour occurences
  2806. for (var _i = 0; _i < trip_locations.length - 1; _i++) {
  2807. if (trip_locations[_i] + 1 === trip_locations[_i + 1]) {
  2808. recurrent += 1;
  2809. }
  2810. }
  2811. if (recurrent === 2) {
  2812. return false;
  2813. }
  2814. }
  2815. return iso7064Check(tin);
  2816. }
  2817. /*
  2818. * dk-DK validation function
  2819. * (CPR-nummer (personnummer), persons only)
  2820. * Checks if birth date (first six digits) is valid and assigned to century (seventh) digit,
  2821. * and calculates check (last) digit
  2822. */
  2823. function dkDkCheck(tin) {
  2824. tin = tin.replace(/\W/, '');
  2825. // Extract year, check if valid for given century digit and add century
  2826. var year = parseInt(tin.slice(4, 6), 10);
  2827. var century_digit = tin.slice(6, 7);
  2828. switch (century_digit) {
  2829. case '0':
  2830. case '1':
  2831. case '2':
  2832. case '3':
  2833. year = "19".concat(year);
  2834. break;
  2835. case '4':
  2836. case '9':
  2837. if (year < 37) {
  2838. year = "20".concat(year);
  2839. } else {
  2840. year = "19".concat(year);
  2841. }
  2842. break;
  2843. default:
  2844. if (year < 37) {
  2845. year = "20".concat(year);
  2846. } else if (year > 58) {
  2847. year = "18".concat(year);
  2848. } else {
  2849. return false;
  2850. }
  2851. break;
  2852. }
  2853. // Add missing zero if needed
  2854. if (year.length === 3) {
  2855. year = [year.slice(0, 2), '0', year.slice(2)].join('');
  2856. }
  2857. // Check date validity
  2858. var date = "".concat(year, "/").concat(tin.slice(2, 4), "/").concat(tin.slice(0, 2));
  2859. if (!isDate(date, 'YYYY/MM/DD')) {
  2860. return false;
  2861. }
  2862. // Split digits into an array for further processing
  2863. var digits = tin.split('').map(function (a) {
  2864. return parseInt(a, 10);
  2865. });
  2866. var checksum = 0;
  2867. var weight = 4;
  2868. // Multiply by weight and add to checksum
  2869. for (var i = 0; i < 9; i++) {
  2870. checksum += digits[i] * weight;
  2871. weight -= 1;
  2872. if (weight === 1) {
  2873. weight = 7;
  2874. }
  2875. }
  2876. checksum %= 11;
  2877. if (checksum === 1) {
  2878. return false;
  2879. }
  2880. return checksum === 0 ? digits[9] === 0 : digits[9] === 11 - checksum;
  2881. }
  2882. /*
  2883. * el-CY validation function
  2884. * (Arithmos Forologikou Mitroou (AFM/ΑΦΜ), persons only)
  2885. * Verify TIN validity by calculating ASCII value of check (last) character
  2886. */
  2887. function elCyCheck(tin) {
  2888. // split digits into an array for further processing
  2889. var digits = tin.slice(0, 8).split('').map(function (a) {
  2890. return parseInt(a, 10);
  2891. });
  2892. var checksum = 0;
  2893. // add digits in even places
  2894. for (var i = 1; i < digits.length; i += 2) {
  2895. checksum += digits[i];
  2896. }
  2897. // add digits in odd places
  2898. for (var _i2 = 0; _i2 < digits.length; _i2 += 2) {
  2899. if (digits[_i2] < 2) {
  2900. checksum += 1 - digits[_i2];
  2901. } else {
  2902. checksum += 2 * (digits[_i2] - 2) + 5;
  2903. if (digits[_i2] > 4) {
  2904. checksum += 2;
  2905. }
  2906. }
  2907. }
  2908. return String.fromCharCode(checksum % 26 + 65) === tin.charAt(8);
  2909. }
  2910. /*
  2911. * el-GR validation function
  2912. * (Arithmos Forologikou Mitroou (AFM/ΑΦΜ), persons/entities)
  2913. * Verify TIN validity by calculating check (last) digit
  2914. * Algorithm not in DG TAXUD document- sourced from:
  2915. * - `http://epixeirisi.gr/%CE%9A%CE%A1%CE%99%CE%A3%CE%99%CE%9C%CE%91-%CE%98%CE%95%CE%9C%CE%91%CE%A4%CE%91-%CE%A6%CE%9F%CE%A1%CE%9F%CE%9B%CE%9F%CE%93%CE%99%CE%91%CE%A3-%CE%9A%CE%91%CE%99-%CE%9B%CE%9F%CE%93%CE%99%CE%A3%CE%A4%CE%99%CE%9A%CE%97%CE%A3/23791/%CE%91%CF%81%CE%B9%CE%B8%CE%BC%CF%8C%CF%82-%CE%A6%CE%BF%CF%81%CE%BF%CE%BB%CE%BF%CE%B3%CE%B9%CE%BA%CE%BF%CF%8D-%CE%9C%CE%B7%CF%84%CF%81%CF%8E%CE%BF%CF%85`
  2916. */
  2917. function elGrCheck(tin) {
  2918. // split digits into an array for further processing
  2919. var digits = tin.split('').map(function (a) {
  2920. return parseInt(a, 10);
  2921. });
  2922. var checksum = 0;
  2923. for (var i = 0; i < 8; i++) {
  2924. checksum += digits[i] * Math.pow(2, 8 - i);
  2925. }
  2926. return checksum % 11 % 10 === digits[8];
  2927. }
  2928. /*
  2929. * en-GB validation function (should go here if needed)
  2930. * (National Insurance Number (NINO) or Unique Taxpayer Reference (UTR),
  2931. * persons/entities respectively)
  2932. */
  2933. /*
  2934. * en-IE validation function
  2935. * (Personal Public Service Number (PPS No), persons only)
  2936. * Verify TIN validity by calculating check (second to last) character
  2937. */
  2938. function enIeCheck(tin) {
  2939. var checksum = reverseMultiplyAndSum(tin.split('').slice(0, 7).map(function (a) {
  2940. return parseInt(a, 10);
  2941. }), 8);
  2942. if (tin.length === 9 && tin[8] !== 'W') {
  2943. checksum += (tin[8].charCodeAt(0) - 64) * 9;
  2944. }
  2945. checksum %= 23;
  2946. if (checksum === 0) {
  2947. return tin[7].toUpperCase() === 'W';
  2948. }
  2949. return tin[7].toUpperCase() === String.fromCharCode(64 + checksum);
  2950. }
  2951. // Valid US IRS campus prefixes
  2952. var enUsCampusPrefix = {
  2953. andover: ['10', '12'],
  2954. atlanta: ['60', '67'],
  2955. austin: ['50', '53'],
  2956. brookhaven: ['01', '02', '03', '04', '05', '06', '11', '13', '14', '16', '21', '22', '23', '25', '34', '51', '52', '54', '55', '56', '57', '58', '59', '65'],
  2957. cincinnati: ['30', '32', '35', '36', '37', '38', '61'],
  2958. fresno: ['15', '24'],
  2959. internet: ['20', '26', '27', '45', '46', '47'],
  2960. kansas: ['40', '44'],
  2961. memphis: ['94', '95'],
  2962. ogden: ['80', '90'],
  2963. philadelphia: ['33', '39', '41', '42', '43', '46', '48', '62', '63', '64', '66', '68', '71', '72', '73', '74', '75', '76', '77', '81', '82', '83', '84', '85', '86', '87', '88', '91', '92', '93', '98', '99'],
  2964. sba: ['31']
  2965. };
  2966. // Return an array of all US IRS campus prefixes
  2967. function enUsGetPrefixes() {
  2968. var prefixes = [];
  2969. for (var location in enUsCampusPrefix) {
  2970. // https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md#ignoring-code-for-coverage-purposes
  2971. // istanbul ignore else
  2972. if (enUsCampusPrefix.hasOwnProperty(location)) {
  2973. prefixes.push.apply(prefixes, _toConsumableArray(enUsCampusPrefix[location]));
  2974. }
  2975. }
  2976. return prefixes;
  2977. }
  2978. /*
  2979. * en-US validation function
  2980. * Verify that the TIN starts with a valid IRS campus prefix
  2981. */
  2982. function enUsCheck(tin) {
  2983. return enUsGetPrefixes().indexOf(tin.slice(0, 2)) !== -1;
  2984. }
  2985. /*
  2986. * es-AR validation function
  2987. * Clave Única de Identificación Tributaria (CUIT/CUIL)
  2988. * Sourced from:
  2989. * - https://servicioscf.afip.gob.ar/publico/abc/ABCpaso2.aspx?id_nivel1=3036&id_nivel2=3040&p=Conceptos%20b%C3%A1sicos
  2990. * - https://es.wikipedia.org/wiki/Clave_%C3%9Anica_de_Identificaci%C3%B3n_Tributaria
  2991. */
  2992. function esArCheck(tin) {
  2993. var accum = 0;
  2994. var digits = tin.split('');
  2995. var digit = parseInt(digits.pop(), 10);
  2996. for (var i = 0; i < digits.length; i++) {
  2997. accum += digits[9 - i] * (2 + i % 6);
  2998. }
  2999. var verif = 11 - accum % 11;
  3000. if (verif === 11) {
  3001. verif = 0;
  3002. } else if (verif === 10) {
  3003. verif = 9;
  3004. }
  3005. return digit === verif;
  3006. }
  3007. /*
  3008. * es-ES validation function
  3009. * (Documento Nacional de Identidad (DNI)
  3010. * or Número de Identificación de Extranjero (NIE), persons only)
  3011. * Verify TIN validity by calculating check (last) character
  3012. */
  3013. function esEsCheck(tin) {
  3014. // Split characters into an array for further processing
  3015. var chars = tin.toUpperCase().split('');
  3016. // Replace initial letter if needed
  3017. if (isNaN(parseInt(chars[0], 10)) && chars.length > 1) {
  3018. var lead_replace = 0;
  3019. switch (chars[0]) {
  3020. case 'Y':
  3021. lead_replace = 1;
  3022. break;
  3023. case 'Z':
  3024. lead_replace = 2;
  3025. break;
  3026. default:
  3027. }
  3028. chars.splice(0, 1, lead_replace);
  3029. // Fill with zeros if smaller than proper
  3030. } else {
  3031. while (chars.length < 9) {
  3032. chars.unshift(0);
  3033. }
  3034. }
  3035. // Calculate checksum and check according to lookup
  3036. var lookup = ['T', 'R', 'W', 'A', 'G', 'M', 'Y', 'F', 'P', 'D', 'X', 'B', 'N', 'J', 'Z', 'S', 'Q', 'V', 'H', 'L', 'C', 'K', 'E'];
  3037. chars = chars.join('');
  3038. var checksum = parseInt(chars.slice(0, 8), 10) % 23;
  3039. return chars[8] === lookup[checksum];
  3040. }
  3041. /*
  3042. * et-EE validation function
  3043. * (Isikukood (IK), persons only)
  3044. * Checks if birth date (century digit and six following) is valid and calculates check (last) digit
  3045. * Material not in DG TAXUD document sourced from:
  3046. * - `https://www.oecd.org/tax/automatic-exchange/crs-implementation-and-assistance/tax-identification-numbers/Estonia-TIN.pdf`
  3047. */
  3048. function etEeCheck(tin) {
  3049. // Extract year and add century
  3050. var full_year = tin.slice(1, 3);
  3051. var century_digit = tin.slice(0, 1);
  3052. switch (century_digit) {
  3053. case '1':
  3054. case '2':
  3055. full_year = "18".concat(full_year);
  3056. break;
  3057. case '3':
  3058. case '4':
  3059. full_year = "19".concat(full_year);
  3060. break;
  3061. default:
  3062. full_year = "20".concat(full_year);
  3063. break;
  3064. }
  3065. // Check date validity
  3066. var date = "".concat(full_year, "/").concat(tin.slice(3, 5), "/").concat(tin.slice(5, 7));
  3067. if (!isDate(date, 'YYYY/MM/DD')) {
  3068. return false;
  3069. }
  3070. // Split digits into an array for further processing
  3071. var digits = tin.split('').map(function (a) {
  3072. return parseInt(a, 10);
  3073. });
  3074. var checksum = 0;
  3075. var weight = 1;
  3076. // Multiply by weight and add to checksum
  3077. for (var i = 0; i < 10; i++) {
  3078. checksum += digits[i] * weight;
  3079. weight += 1;
  3080. if (weight === 10) {
  3081. weight = 1;
  3082. }
  3083. }
  3084. // Do again if modulo 11 of checksum is 10
  3085. if (checksum % 11 === 10) {
  3086. checksum = 0;
  3087. weight = 3;
  3088. for (var _i3 = 0; _i3 < 10; _i3++) {
  3089. checksum += digits[_i3] * weight;
  3090. weight += 1;
  3091. if (weight === 10) {
  3092. weight = 1;
  3093. }
  3094. }
  3095. if (checksum % 11 === 10) {
  3096. return digits[10] === 0;
  3097. }
  3098. }
  3099. return checksum % 11 === digits[10];
  3100. }
  3101. /*
  3102. * fi-FI validation function
  3103. * (Henkilötunnus (HETU), persons only)
  3104. * Checks if birth date (first six digits plus century symbol) is valid
  3105. * and calculates check (last) digit
  3106. */
  3107. function fiFiCheck(tin) {
  3108. // Extract year and add century
  3109. var full_year = tin.slice(4, 6);
  3110. var century_symbol = tin.slice(6, 7);
  3111. switch (century_symbol) {
  3112. case '+':
  3113. full_year = "18".concat(full_year);
  3114. break;
  3115. case '-':
  3116. full_year = "19".concat(full_year);
  3117. break;
  3118. default:
  3119. full_year = "20".concat(full_year);
  3120. break;
  3121. }
  3122. // Check date validity
  3123. var date = "".concat(full_year, "/").concat(tin.slice(2, 4), "/").concat(tin.slice(0, 2));
  3124. if (!isDate(date, 'YYYY/MM/DD')) {
  3125. return false;
  3126. }
  3127. // Calculate check character
  3128. var checksum = parseInt(tin.slice(0, 6) + tin.slice(7, 10), 10) % 31;
  3129. if (checksum < 10) {
  3130. return checksum === parseInt(tin.slice(10), 10);
  3131. }
  3132. checksum -= 10;
  3133. var letters_lookup = ['A', 'B', 'C', 'D', 'E', 'F', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y'];
  3134. return letters_lookup[checksum] === tin.slice(10);
  3135. }
  3136. /*
  3137. * fr/nl-BE validation function
  3138. * (Numéro national (N.N.), persons only)
  3139. * Checks if birth date (first six digits) is valid and calculates check (last two) digits
  3140. */
  3141. function frBeCheck(tin) {
  3142. // Zero month/day value is acceptable
  3143. if (tin.slice(2, 4) !== '00' || tin.slice(4, 6) !== '00') {
  3144. // Extract date from first six digits of TIN
  3145. var date = "".concat(tin.slice(0, 2), "/").concat(tin.slice(2, 4), "/").concat(tin.slice(4, 6));
  3146. if (!isDate(date, 'YY/MM/DD')) {
  3147. return false;
  3148. }
  3149. }
  3150. var checksum = 97 - parseInt(tin.slice(0, 9), 10) % 97;
  3151. var checkdigits = parseInt(tin.slice(9, 11), 10);
  3152. if (checksum !== checkdigits) {
  3153. checksum = 97 - parseInt("2".concat(tin.slice(0, 9)), 10) % 97;
  3154. if (checksum !== checkdigits) {
  3155. return false;
  3156. }
  3157. }
  3158. return true;
  3159. }
  3160. /*
  3161. * fr-FR validation function
  3162. * (Numéro fiscal de référence (numéro SPI), persons only)
  3163. * Verify TIN validity by calculating check (last three) digits
  3164. */
  3165. function frFrCheck(tin) {
  3166. tin = tin.replace(/\s/g, '');
  3167. var checksum = parseInt(tin.slice(0, 10), 10) % 511;
  3168. var checkdigits = parseInt(tin.slice(10, 13), 10);
  3169. return checksum === checkdigits;
  3170. }
  3171. /*
  3172. * fr/lb-LU validation function
  3173. * (numéro d’identification personnelle, persons only)
  3174. * Verify birth date validity and run Luhn and Verhoeff checks
  3175. */
  3176. function frLuCheck(tin) {
  3177. // Extract date and check validity
  3178. var date = "".concat(tin.slice(0, 4), "/").concat(tin.slice(4, 6), "/").concat(tin.slice(6, 8));
  3179. if (!isDate(date, 'YYYY/MM/DD')) {
  3180. return false;
  3181. }
  3182. // Run Luhn check
  3183. if (!luhnCheck(tin.slice(0, 12))) {
  3184. return false;
  3185. }
  3186. // Remove Luhn check digit and run Verhoeff check
  3187. return verhoeffCheck("".concat(tin.slice(0, 11)).concat(tin[12]));
  3188. }
  3189. /*
  3190. * hr-HR validation function
  3191. * (Osobni identifikacijski broj (OIB), persons/entities)
  3192. * Verify TIN validity by calling iso7064Check(digits)
  3193. */
  3194. function hrHrCheck(tin) {
  3195. return iso7064Check(tin);
  3196. }
  3197. /*
  3198. * hu-HU validation function
  3199. * (Adóazonosító jel, persons only)
  3200. * Verify TIN validity by calculating check (last) digit
  3201. */
  3202. function huHuCheck(tin) {
  3203. // split digits into an array for further processing
  3204. var digits = tin.split('').map(function (a) {
  3205. return parseInt(a, 10);
  3206. });
  3207. var checksum = 8;
  3208. for (var i = 1; i < 9; i++) {
  3209. checksum += digits[i] * (i + 1);
  3210. }
  3211. return checksum % 11 === digits[9];
  3212. }
  3213. /*
  3214. * lt-LT validation function (should go here if needed)
  3215. * (Asmens kodas, persons/entities respectively)
  3216. * Current validation check is alias of etEeCheck- same format applies
  3217. */
  3218. /*
  3219. * it-IT first/last name validity check
  3220. * Accepts it-IT TIN-encoded names as a three-element character array and checks their validity
  3221. * Due to lack of clarity between resources ("Are only Italian consonants used?
  3222. * What happens if a person has X in their name?" etc.) only two test conditions
  3223. * have been implemented:
  3224. * Vowels may only be followed by other vowels or an X character
  3225. * and X characters after vowels may only be followed by other X characters.
  3226. */
  3227. function itItNameCheck(name) {
  3228. // true at the first occurence of a vowel
  3229. var vowelflag = false;
  3230. // true at the first occurence of an X AFTER vowel
  3231. // (to properly handle last names with X as consonant)
  3232. var xflag = false;
  3233. for (var i = 0; i < 3; i++) {
  3234. if (!vowelflag && /[AEIOU]/.test(name[i])) {
  3235. vowelflag = true;
  3236. } else if (!xflag && vowelflag && name[i] === 'X') {
  3237. xflag = true;
  3238. } else if (i > 0) {
  3239. if (vowelflag && !xflag) {
  3240. if (!/[AEIOU]/.test(name[i])) {
  3241. return false;
  3242. }
  3243. }
  3244. if (xflag) {
  3245. if (!/X/.test(name[i])) {
  3246. return false;
  3247. }
  3248. }
  3249. }
  3250. }
  3251. return true;
  3252. }
  3253. /*
  3254. * it-IT validation function
  3255. * (Codice fiscale (TIN-IT), persons only)
  3256. * Verify name, birth date and codice catastale validity
  3257. * and calculate check character.
  3258. * Material not in DG-TAXUD document sourced from:
  3259. * `https://en.wikipedia.org/wiki/Italian_fiscal_code`
  3260. */
  3261. function itItCheck(tin) {
  3262. // Capitalize and split characters into an array for further processing
  3263. var chars = tin.toUpperCase().split('');
  3264. // Check first and last name validity calling itItNameCheck()
  3265. if (!itItNameCheck(chars.slice(0, 3))) {
  3266. return false;
  3267. }
  3268. if (!itItNameCheck(chars.slice(3, 6))) {
  3269. return false;
  3270. }
  3271. // Convert letters in number spaces back to numbers if any
  3272. var number_locations = [6, 7, 9, 10, 12, 13, 14];
  3273. var number_replace = {
  3274. L: '0',
  3275. M: '1',
  3276. N: '2',
  3277. P: '3',
  3278. Q: '4',
  3279. R: '5',
  3280. S: '6',
  3281. T: '7',
  3282. U: '8',
  3283. V: '9'
  3284. };
  3285. for (var _i4 = 0, _number_locations = number_locations; _i4 < _number_locations.length; _i4++) {
  3286. var i = _number_locations[_i4];
  3287. if (chars[i] in number_replace) {
  3288. chars.splice(i, 1, number_replace[chars[i]]);
  3289. }
  3290. }
  3291. // Extract month and day, and check date validity
  3292. var month_replace = {
  3293. A: '01',
  3294. B: '02',
  3295. C: '03',
  3296. D: '04',
  3297. E: '05',
  3298. H: '06',
  3299. L: '07',
  3300. M: '08',
  3301. P: '09',
  3302. R: '10',
  3303. S: '11',
  3304. T: '12'
  3305. };
  3306. var month = month_replace[chars[8]];
  3307. var day = parseInt(chars[9] + chars[10], 10);
  3308. if (day > 40) {
  3309. day -= 40;
  3310. }
  3311. if (day < 10) {
  3312. day = "0".concat(day);
  3313. }
  3314. var date = "".concat(chars[6]).concat(chars[7], "/").concat(month, "/").concat(day);
  3315. if (!isDate(date, 'YY/MM/DD')) {
  3316. return false;
  3317. }
  3318. // Calculate check character by adding up even and odd characters as numbers
  3319. var checksum = 0;
  3320. for (var _i5 = 1; _i5 < chars.length - 1; _i5 += 2) {
  3321. var char_to_int = parseInt(chars[_i5], 10);
  3322. if (isNaN(char_to_int)) {
  3323. char_to_int = chars[_i5].charCodeAt(0) - 65;
  3324. }
  3325. checksum += char_to_int;
  3326. }
  3327. var odd_convert = {
  3328. // Maps of characters at odd places
  3329. A: 1,
  3330. B: 0,
  3331. C: 5,
  3332. D: 7,
  3333. E: 9,
  3334. F: 13,
  3335. G: 15,
  3336. H: 17,
  3337. I: 19,
  3338. J: 21,
  3339. K: 2,
  3340. L: 4,
  3341. M: 18,
  3342. N: 20,
  3343. O: 11,
  3344. P: 3,
  3345. Q: 6,
  3346. R: 8,
  3347. S: 12,
  3348. T: 14,
  3349. U: 16,
  3350. V: 10,
  3351. W: 22,
  3352. X: 25,
  3353. Y: 24,
  3354. Z: 23,
  3355. 0: 1,
  3356. 1: 0
  3357. };
  3358. for (var _i6 = 0; _i6 < chars.length - 1; _i6 += 2) {
  3359. var _char_to_int = 0;
  3360. if (chars[_i6] in odd_convert) {
  3361. _char_to_int = odd_convert[chars[_i6]];
  3362. } else {
  3363. var multiplier = parseInt(chars[_i6], 10);
  3364. _char_to_int = 2 * multiplier + 1;
  3365. if (multiplier > 4) {
  3366. _char_to_int += 2;
  3367. }
  3368. }
  3369. checksum += _char_to_int;
  3370. }
  3371. if (String.fromCharCode(65 + checksum % 26) !== chars[15]) {
  3372. return false;
  3373. }
  3374. return true;
  3375. }
  3376. /*
  3377. * lv-LV validation function
  3378. * (Personas kods (PK), persons only)
  3379. * Check validity of birth date and calculate check (last) digit
  3380. * Support only for old format numbers (not starting with '32', issued before 2017/07/01)
  3381. * Material not in DG TAXUD document sourced from:
  3382. * `https://boot.ritakafija.lv/forums/index.php?/topic/88314-personas-koda-algoritms-%C4%8Deksumma/`
  3383. */
  3384. function lvLvCheck(tin) {
  3385. tin = tin.replace(/\W/, '');
  3386. // Extract date from TIN
  3387. var day = tin.slice(0, 2);
  3388. if (day !== '32') {
  3389. // No date/checksum check if new format
  3390. var month = tin.slice(2, 4);
  3391. if (month !== '00') {
  3392. // No date check if unknown month
  3393. var full_year = tin.slice(4, 6);
  3394. switch (tin[6]) {
  3395. case '0':
  3396. full_year = "18".concat(full_year);
  3397. break;
  3398. case '1':
  3399. full_year = "19".concat(full_year);
  3400. break;
  3401. default:
  3402. full_year = "20".concat(full_year);
  3403. break;
  3404. }
  3405. // Check date validity
  3406. var date = "".concat(full_year, "/").concat(tin.slice(2, 4), "/").concat(day);
  3407. if (!isDate(date, 'YYYY/MM/DD')) {
  3408. return false;
  3409. }
  3410. }
  3411. // Calculate check digit
  3412. var checksum = 1101;
  3413. var multip_lookup = [1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
  3414. for (var i = 0; i < tin.length - 1; i++) {
  3415. checksum -= parseInt(tin[i], 10) * multip_lookup[i];
  3416. }
  3417. return parseInt(tin[10], 10) === checksum % 11;
  3418. }
  3419. return true;
  3420. }
  3421. /*
  3422. * mt-MT validation function
  3423. * (Identity Card Number or Unique Taxpayer Reference, persons/entities)
  3424. * Verify Identity Card Number structure (no other tests found)
  3425. */
  3426. function mtMtCheck(tin) {
  3427. if (tin.length !== 9) {
  3428. // No tests for UTR
  3429. var chars = tin.toUpperCase().split('');
  3430. // Fill with zeros if smaller than proper
  3431. while (chars.length < 8) {
  3432. chars.unshift(0);
  3433. }
  3434. // Validate format according to last character
  3435. switch (tin[7]) {
  3436. case 'A':
  3437. case 'P':
  3438. if (parseInt(chars[6], 10) === 0) {
  3439. return false;
  3440. }
  3441. break;
  3442. default:
  3443. {
  3444. var first_part = parseInt(chars.join('').slice(0, 5), 10);
  3445. if (first_part > 32000) {
  3446. return false;
  3447. }
  3448. var second_part = parseInt(chars.join('').slice(5, 7), 10);
  3449. if (first_part === second_part) {
  3450. return false;
  3451. }
  3452. }
  3453. }
  3454. }
  3455. return true;
  3456. }
  3457. /*
  3458. * nl-NL validation function
  3459. * (Burgerservicenummer (BSN) or Rechtspersonen Samenwerkingsverbanden Informatie Nummer (RSIN),
  3460. * persons/entities respectively)
  3461. * Verify TIN validity by calculating check (last) digit (variant of MOD 11)
  3462. */
  3463. function nlNlCheck(tin) {
  3464. return reverseMultiplyAndSum(tin.split('').slice(0, 8).map(function (a) {
  3465. return parseInt(a, 10);
  3466. }), 9) % 11 === parseInt(tin[8], 10);
  3467. }
  3468. /*
  3469. * pl-PL validation function
  3470. * (Powszechny Elektroniczny System Ewidencji Ludności (PESEL)
  3471. * or Numer identyfikacji podatkowej (NIP), persons/entities)
  3472. * Verify TIN validity by validating birth date (PESEL) and calculating check (last) digit
  3473. */
  3474. function plPlCheck(tin) {
  3475. // NIP
  3476. if (tin.length === 10) {
  3477. // Calculate last digit by multiplying with lookup
  3478. var lookup = [6, 5, 7, 2, 3, 4, 5, 6, 7];
  3479. var _checksum = 0;
  3480. for (var i = 0; i < lookup.length; i++) {
  3481. _checksum += parseInt(tin[i], 10) * lookup[i];
  3482. }
  3483. _checksum %= 11;
  3484. if (_checksum === 10) {
  3485. return false;
  3486. }
  3487. return _checksum === parseInt(tin[9], 10);
  3488. }
  3489. // PESEL
  3490. // Extract full year using month
  3491. var full_year = tin.slice(0, 2);
  3492. var month = parseInt(tin.slice(2, 4), 10);
  3493. if (month > 80) {
  3494. full_year = "18".concat(full_year);
  3495. month -= 80;
  3496. } else if (month > 60) {
  3497. full_year = "22".concat(full_year);
  3498. month -= 60;
  3499. } else if (month > 40) {
  3500. full_year = "21".concat(full_year);
  3501. month -= 40;
  3502. } else if (month > 20) {
  3503. full_year = "20".concat(full_year);
  3504. month -= 20;
  3505. } else {
  3506. full_year = "19".concat(full_year);
  3507. }
  3508. // Add leading zero to month if needed
  3509. if (month < 10) {
  3510. month = "0".concat(month);
  3511. }
  3512. // Check date validity
  3513. var date = "".concat(full_year, "/").concat(month, "/").concat(tin.slice(4, 6));
  3514. if (!isDate(date, 'YYYY/MM/DD')) {
  3515. return false;
  3516. }
  3517. // Calculate last digit by mulitplying with odd one-digit numbers except 5
  3518. var checksum = 0;
  3519. var multiplier = 1;
  3520. for (var _i7 = 0; _i7 < tin.length - 1; _i7++) {
  3521. checksum += parseInt(tin[_i7], 10) * multiplier % 10;
  3522. multiplier += 2;
  3523. if (multiplier > 10) {
  3524. multiplier = 1;
  3525. } else if (multiplier === 5) {
  3526. multiplier += 2;
  3527. }
  3528. }
  3529. checksum = 10 - checksum % 10;
  3530. return checksum === parseInt(tin[10], 10);
  3531. }
  3532. /*
  3533. * pt-BR validation function
  3534. * (Cadastro de Pessoas Físicas (CPF, persons)
  3535. * Cadastro Nacional de Pessoas Jurídicas (CNPJ, entities)
  3536. * Both inputs will be validated
  3537. */
  3538. function ptBrCheck(tin) {
  3539. if (tin.length === 11) {
  3540. var _sum;
  3541. var remainder;
  3542. _sum = 0;
  3543. if (
  3544. // Reject known invalid CPFs
  3545. tin === '11111111111' || tin === '22222222222' || tin === '33333333333' || tin === '44444444444' || tin === '55555555555' || tin === '66666666666' || tin === '77777777777' || tin === '88888888888' || tin === '99999999999' || tin === '00000000000') return false;
  3546. for (var i = 1; i <= 9; i++) _sum += parseInt(tin.substring(i - 1, i), 10) * (11 - i);
  3547. remainder = _sum * 10 % 11;
  3548. if (remainder === 10) remainder = 0;
  3549. if (remainder !== parseInt(tin.substring(9, 10), 10)) return false;
  3550. _sum = 0;
  3551. for (var _i8 = 1; _i8 <= 10; _i8++) _sum += parseInt(tin.substring(_i8 - 1, _i8), 10) * (12 - _i8);
  3552. remainder = _sum * 10 % 11;
  3553. if (remainder === 10) remainder = 0;
  3554. if (remainder !== parseInt(tin.substring(10, 11), 10)) return false;
  3555. return true;
  3556. }
  3557. if (
  3558. // Reject know invalid CNPJs
  3559. tin === '00000000000000' || tin === '11111111111111' || tin === '22222222222222' || tin === '33333333333333' || tin === '44444444444444' || tin === '55555555555555' || tin === '66666666666666' || tin === '77777777777777' || tin === '88888888888888' || tin === '99999999999999') {
  3560. return false;
  3561. }
  3562. var length = tin.length - 2;
  3563. var identifiers = tin.substring(0, length);
  3564. var verificators = tin.substring(length);
  3565. var sum = 0;
  3566. var pos = length - 7;
  3567. for (var _i9 = length; _i9 >= 1; _i9--) {
  3568. sum += identifiers.charAt(length - _i9) * pos;
  3569. pos -= 1;
  3570. if (pos < 2) {
  3571. pos = 9;
  3572. }
  3573. }
  3574. var result = sum % 11 < 2 ? 0 : 11 - sum % 11;
  3575. if (result !== parseInt(verificators.charAt(0), 10)) {
  3576. return false;
  3577. }
  3578. length += 1;
  3579. identifiers = tin.substring(0, length);
  3580. sum = 0;
  3581. pos = length - 7;
  3582. for (var _i10 = length; _i10 >= 1; _i10--) {
  3583. sum += identifiers.charAt(length - _i10) * pos;
  3584. pos -= 1;
  3585. if (pos < 2) {
  3586. pos = 9;
  3587. }
  3588. }
  3589. result = sum % 11 < 2 ? 0 : 11 - sum % 11;
  3590. if (result !== parseInt(verificators.charAt(1), 10)) {
  3591. return false;
  3592. }
  3593. return true;
  3594. }
  3595. /*
  3596. * pt-PT validation function
  3597. * (Número de identificação fiscal (NIF), persons/entities)
  3598. * Verify TIN validity by calculating check (last) digit (variant of MOD 11)
  3599. */
  3600. function ptPtCheck(tin) {
  3601. var checksum = 11 - reverseMultiplyAndSum(tin.split('').slice(0, 8).map(function (a) {
  3602. return parseInt(a, 10);
  3603. }), 9) % 11;
  3604. if (checksum > 9) {
  3605. return parseInt(tin[8], 10) === 0;
  3606. }
  3607. return checksum === parseInt(tin[8], 10);
  3608. }
  3609. /*
  3610. * ro-RO validation function
  3611. * (Cod Numeric Personal (CNP) or Cod de înregistrare fiscală (CIF),
  3612. * persons only)
  3613. * Verify CNP validity by calculating check (last) digit (test not found for CIF)
  3614. * Material not in DG TAXUD document sourced from:
  3615. * `https://en.wikipedia.org/wiki/National_identification_number#Romania`
  3616. */
  3617. function roRoCheck(tin) {
  3618. if (tin.slice(0, 4) !== '9000') {
  3619. // No test found for this format
  3620. // Extract full year using century digit if possible
  3621. var full_year = tin.slice(1, 3);
  3622. switch (tin[0]) {
  3623. case '1':
  3624. case '2':
  3625. full_year = "19".concat(full_year);
  3626. break;
  3627. case '3':
  3628. case '4':
  3629. full_year = "18".concat(full_year);
  3630. break;
  3631. case '5':
  3632. case '6':
  3633. full_year = "20".concat(full_year);
  3634. break;
  3635. default:
  3636. }
  3637. // Check date validity
  3638. var date = "".concat(full_year, "/").concat(tin.slice(3, 5), "/").concat(tin.slice(5, 7));
  3639. if (date.length === 8) {
  3640. if (!isDate(date, 'YY/MM/DD')) {
  3641. return false;
  3642. }
  3643. } else if (!isDate(date, 'YYYY/MM/DD')) {
  3644. return false;
  3645. }
  3646. // Calculate check digit
  3647. var digits = tin.split('').map(function (a) {
  3648. return parseInt(a, 10);
  3649. });
  3650. var multipliers = [2, 7, 9, 1, 4, 6, 3, 5, 8, 2, 7, 9];
  3651. var checksum = 0;
  3652. for (var i = 0; i < multipliers.length; i++) {
  3653. checksum += digits[i] * multipliers[i];
  3654. }
  3655. if (checksum % 11 === 10) {
  3656. return digits[12] === 1;
  3657. }
  3658. return digits[12] === checksum % 11;
  3659. }
  3660. return true;
  3661. }
  3662. /*
  3663. * sk-SK validation function
  3664. * (Rodné číslo (RČ) or bezvýznamové identifikačné číslo (BIČ), persons only)
  3665. * Checks validity of pre-1954 birth numbers (rodné číslo) only
  3666. * Due to the introduction of the pseudo-random BIČ it is not possible to test
  3667. * post-1954 birth numbers without knowing whether they are BIČ or RČ beforehand
  3668. */
  3669. function skSkCheck(tin) {
  3670. if (tin.length === 9) {
  3671. tin = tin.replace(/\W/, '');
  3672. if (tin.slice(6) === '000') {
  3673. return false;
  3674. } // Three-zero serial not assigned before 1954
  3675. // Extract full year from TIN length
  3676. var full_year = parseInt(tin.slice(0, 2), 10);
  3677. if (full_year > 53) {
  3678. return false;
  3679. }
  3680. if (full_year < 10) {
  3681. full_year = "190".concat(full_year);
  3682. } else {
  3683. full_year = "19".concat(full_year);
  3684. }
  3685. // Extract month from TIN and normalize
  3686. var month = parseInt(tin.slice(2, 4), 10);
  3687. if (month > 50) {
  3688. month -= 50;
  3689. }
  3690. if (month < 10) {
  3691. month = "0".concat(month);
  3692. }
  3693. // Check date validity
  3694. var date = "".concat(full_year, "/").concat(month, "/").concat(tin.slice(4, 6));
  3695. if (!isDate(date, 'YYYY/MM/DD')) {
  3696. return false;
  3697. }
  3698. }
  3699. return true;
  3700. }
  3701. /*
  3702. * sl-SI validation function
  3703. * (Davčna številka, persons/entities)
  3704. * Verify TIN validity by calculating check (last) digit (variant of MOD 11)
  3705. */
  3706. function slSiCheck(tin) {
  3707. var checksum = 11 - reverseMultiplyAndSum(tin.split('').slice(0, 7).map(function (a) {
  3708. return parseInt(a, 10);
  3709. }), 8) % 11;
  3710. if (checksum === 10) {
  3711. return parseInt(tin[7], 10) === 0;
  3712. }
  3713. return checksum === parseInt(tin[7], 10);
  3714. }
  3715. /*
  3716. * sv-SE validation function
  3717. * (Personnummer or samordningsnummer, persons only)
  3718. * Checks validity of birth date and calls luhnCheck() to validate check (last) digit
  3719. */
  3720. function svSeCheck(tin) {
  3721. // Make copy of TIN and normalize to two-digit year form
  3722. var tin_copy = tin.slice(0);
  3723. if (tin.length > 11) {
  3724. tin_copy = tin_copy.slice(2);
  3725. }
  3726. // Extract date of birth
  3727. var full_year = '';
  3728. var month = tin_copy.slice(2, 4);
  3729. var day = parseInt(tin_copy.slice(4, 6), 10);
  3730. if (tin.length > 11) {
  3731. full_year = tin.slice(0, 4);
  3732. } else {
  3733. full_year = tin.slice(0, 2);
  3734. if (tin.length === 11 && day < 60) {
  3735. // Extract full year from centenarian symbol
  3736. // Should work just fine until year 10000 or so
  3737. var current_year = new Date().getFullYear().toString();
  3738. var current_century = parseInt(current_year.slice(0, 2), 10);
  3739. current_year = parseInt(current_year, 10);
  3740. if (tin[6] === '-') {
  3741. if (parseInt("".concat(current_century).concat(full_year), 10) > current_year) {
  3742. full_year = "".concat(current_century - 1).concat(full_year);
  3743. } else {
  3744. full_year = "".concat(current_century).concat(full_year);
  3745. }
  3746. } else {
  3747. full_year = "".concat(current_century - 1).concat(full_year);
  3748. if (current_year - parseInt(full_year, 10) < 100) {
  3749. return false;
  3750. }
  3751. }
  3752. }
  3753. }
  3754. // Normalize day and check date validity
  3755. if (day > 60) {
  3756. day -= 60;
  3757. }
  3758. if (day < 10) {
  3759. day = "0".concat(day);
  3760. }
  3761. var date = "".concat(full_year, "/").concat(month, "/").concat(day);
  3762. if (date.length === 8) {
  3763. if (!isDate(date, 'YY/MM/DD')) {
  3764. return false;
  3765. }
  3766. } else if (!isDate(date, 'YYYY/MM/DD')) {
  3767. return false;
  3768. }
  3769. return luhnCheck(tin.replace(/\W/, ''));
  3770. }
  3771. /**
  3772. * uk-UA validation function
  3773. * Verify TIN validity by calculating check (last) digit (variant of MOD 11)
  3774. */
  3775. function ukUaCheck(tin) {
  3776. // Calculate check digit
  3777. var digits = tin.split('').map(function (a) {
  3778. return parseInt(a, 10);
  3779. });
  3780. var multipliers = [-1, 5, 7, 9, 4, 6, 10, 5, 7];
  3781. var checksum = 0;
  3782. for (var i = 0; i < multipliers.length; i++) {
  3783. checksum += digits[i] * multipliers[i];
  3784. }
  3785. return checksum % 11 === 10 ? digits[9] === 0 : digits[9] === checksum % 11;
  3786. }
  3787. // Locale lookup objects
  3788. /*
  3789. * Tax id regex formats for various locales
  3790. *
  3791. * Where not explicitly specified in DG-TAXUD document both
  3792. * uppercase and lowercase letters are acceptable.
  3793. */
  3794. var taxIdFormat = {
  3795. 'bg-BG': /^\d{10}$/,
  3796. 'cs-CZ': /^\d{6}\/{0,1}\d{3,4}$/,
  3797. 'de-AT': /^\d{9}$/,
  3798. 'de-DE': /^[1-9]\d{10}$/,
  3799. 'dk-DK': /^\d{6}-{0,1}\d{4}$/,
  3800. 'el-CY': /^[09]\d{7}[A-Z]$/,
  3801. 'el-GR': /^([0-4]|[7-9])\d{8}$/,
  3802. 'en-CA': /^\d{9}$/,
  3803. 'en-GB': /^\d{10}$|^(?!GB|NK|TN|ZZ)(?![DFIQUV])[A-Z](?![DFIQUVO])[A-Z]\d{6}[ABCD ]$/i,
  3804. 'en-IE': /^\d{7}[A-W][A-IW]{0,1}$/i,
  3805. 'en-US': /^\d{2}[- ]{0,1}\d{7}$/,
  3806. 'es-AR': /(20|23|24|27|30|33|34)[0-9]{8}[0-9]/,
  3807. 'es-ES': /^(\d{0,8}|[XYZKLM]\d{7})[A-HJ-NP-TV-Z]$/i,
  3808. 'et-EE': /^[1-6]\d{6}(00[1-9]|0[1-9][0-9]|[1-6][0-9]{2}|70[0-9]|710)\d$/,
  3809. 'fi-FI': /^\d{6}[-+A]\d{3}[0-9A-FHJ-NPR-Y]$/i,
  3810. 'fr-BE': /^\d{11}$/,
  3811. 'fr-FR': /^[0-3]\d{12}$|^[0-3]\d\s\d{2}(\s\d{3}){3}$/,
  3812. // Conforms both to official spec and provided example
  3813. 'fr-LU': /^\d{13}$/,
  3814. 'hr-HR': /^\d{11}$/,
  3815. 'hu-HU': /^8\d{9}$/,
  3816. 'it-IT': /^[A-Z]{6}[L-NP-V0-9]{2}[A-EHLMPRST][L-NP-V0-9]{2}[A-ILMZ][L-NP-V0-9]{3}[A-Z]$/i,
  3817. 'lv-LV': /^\d{6}-{0,1}\d{5}$/,
  3818. // Conforms both to DG TAXUD spec and original research
  3819. 'mt-MT': /^\d{3,7}[APMGLHBZ]$|^([1-8])\1\d{7}$/i,
  3820. 'nl-NL': /^\d{9}$/,
  3821. 'pl-PL': /^\d{10,11}$/,
  3822. 'pt-BR': /(?:^\d{11}$)|(?:^\d{14}$)/,
  3823. 'pt-PT': /^\d{9}$/,
  3824. 'ro-RO': /^\d{13}$/,
  3825. 'sk-SK': /^\d{6}\/{0,1}\d{3,4}$/,
  3826. 'sl-SI': /^[1-9]\d{7}$/,
  3827. 'sv-SE': /^(\d{6}[-+]{0,1}\d{4}|(18|19|20)\d{6}[-+]{0,1}\d{4})$/,
  3828. 'uk-UA': /^\d{10}$/
  3829. };
  3830. // taxIdFormat locale aliases
  3831. taxIdFormat['lb-LU'] = taxIdFormat['fr-LU'];
  3832. taxIdFormat['lt-LT'] = taxIdFormat['et-EE'];
  3833. taxIdFormat['nl-BE'] = taxIdFormat['fr-BE'];
  3834. taxIdFormat['fr-CA'] = taxIdFormat['en-CA'];
  3835. // Algorithmic tax id check functions for various locales
  3836. var taxIdCheck = {
  3837. 'bg-BG': bgBgCheck,
  3838. 'cs-CZ': csCzCheck,
  3839. 'de-AT': deAtCheck,
  3840. 'de-DE': deDeCheck,
  3841. 'dk-DK': dkDkCheck,
  3842. 'el-CY': elCyCheck,
  3843. 'el-GR': elGrCheck,
  3844. 'en-CA': isCanadianSIN,
  3845. 'en-IE': enIeCheck,
  3846. 'en-US': enUsCheck,
  3847. 'es-AR': esArCheck,
  3848. 'es-ES': esEsCheck,
  3849. 'et-EE': etEeCheck,
  3850. 'fi-FI': fiFiCheck,
  3851. 'fr-BE': frBeCheck,
  3852. 'fr-FR': frFrCheck,
  3853. 'fr-LU': frLuCheck,
  3854. 'hr-HR': hrHrCheck,
  3855. 'hu-HU': huHuCheck,
  3856. 'it-IT': itItCheck,
  3857. 'lv-LV': lvLvCheck,
  3858. 'mt-MT': mtMtCheck,
  3859. 'nl-NL': nlNlCheck,
  3860. 'pl-PL': plPlCheck,
  3861. 'pt-BR': ptBrCheck,
  3862. 'pt-PT': ptPtCheck,
  3863. 'ro-RO': roRoCheck,
  3864. 'sk-SK': skSkCheck,
  3865. 'sl-SI': slSiCheck,
  3866. 'sv-SE': svSeCheck,
  3867. 'uk-UA': ukUaCheck
  3868. };
  3869. // taxIdCheck locale aliases
  3870. taxIdCheck['lb-LU'] = taxIdCheck['fr-LU'];
  3871. taxIdCheck['lt-LT'] = taxIdCheck['et-EE'];
  3872. taxIdCheck['nl-BE'] = taxIdCheck['fr-BE'];
  3873. taxIdCheck['fr-CA'] = taxIdCheck['en-CA'];
  3874. // Regexes for locales where characters should be omitted before checking format
  3875. var allsymbols = /[-\\\/!@#$%\^&\*\(\)\+\=\[\]]+/g;
  3876. var sanitizeRegexes = {
  3877. 'de-AT': allsymbols,
  3878. 'de-DE': /[\/\\]/g,
  3879. 'fr-BE': allsymbols
  3880. };
  3881. // sanitizeRegexes locale aliases
  3882. sanitizeRegexes['nl-BE'] = sanitizeRegexes['fr-BE'];
  3883. /*
  3884. * Validator function
  3885. * Return true if the passed string is a valid tax identification number
  3886. * for the specified locale.
  3887. * Throw an error exception if the locale is not supported.
  3888. */
  3889. function isTaxID(str) {
  3890. var locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'en-US';
  3891. assertString(str);
  3892. // Copy TIN to avoid replacement if sanitized
  3893. var strcopy = str.slice(0);
  3894. if (locale in taxIdFormat) {
  3895. if (locale in sanitizeRegexes) {
  3896. strcopy = strcopy.replace(sanitizeRegexes[locale], '');
  3897. }
  3898. if (!taxIdFormat[locale].test(strcopy)) {
  3899. return false;
  3900. }
  3901. if (locale in taxIdCheck) {
  3902. return taxIdCheck[locale](strcopy);
  3903. }
  3904. // Fallthrough; not all locales have algorithmic checks
  3905. return true;
  3906. }
  3907. throw new Error("Invalid locale '".concat(locale, "'"));
  3908. }
  3909. /* eslint-disable max-len */
  3910. var phones = {
  3911. 'am-AM': /^(\+?374|0)(33|4[134]|55|77|88|9[13-689])\d{6}$/,
  3912. 'ar-AE': /^((\+?971)|0)?5[024568]\d{7}$/,
  3913. 'ar-BH': /^(\+?973)?(3|6)\d{7}$/,
  3914. 'ar-DZ': /^(\+?213|0)(5|6|7)\d{8}$/,
  3915. 'ar-LB': /^(\+?961)?((3|81)\d{6}|7\d{7})$/,
  3916. 'ar-EG': /^((\+?20)|0)?1[0125]\d{8}$/,
  3917. 'ar-IQ': /^(\+?964|0)?7[0-9]\d{8}$/,
  3918. 'ar-JO': /^(\+?962|0)?7[789]\d{7}$/,
  3919. 'ar-KW': /^(\+?965)([569]\d{7}|41\d{6})$/,
  3920. 'ar-LY': /^((\+?218)|0)?(9[1-6]\d{7}|[1-8]\d{7,9})$/,
  3921. 'ar-MA': /^(?:(?:\+|00)212|0)[5-7]\d{8}$/,
  3922. 'ar-OM': /^((\+|00)968)?(9[1-9])\d{6}$/,
  3923. 'ar-PS': /^(\+?970|0)5[6|9](\d{7})$/,
  3924. 'ar-SA': /^(!?(\+?966)|0)?5\d{8}$/,
  3925. 'ar-SD': /^((\+?249)|0)?(9[012369]|1[012])\d{7}$/,
  3926. 'ar-SY': /^(!?(\+?963)|0)?9\d{8}$/,
  3927. 'ar-TN': /^(\+?216)?[2459]\d{7}$/,
  3928. 'az-AZ': /^(\+994|0)(10|5[015]|7[07]|99)\d{7}$/,
  3929. 'bs-BA': /^((((\+|00)3876)|06))((([0-3]|[5-6])\d{6})|(4\d{7}))$/,
  3930. 'be-BY': /^(\+?375)?(24|25|29|33|44)\d{7}$/,
  3931. 'bg-BG': /^(\+?359|0)?8[789]\d{7}$/,
  3932. 'bn-BD': /^(\+?880|0)1[13456789][0-9]{8}$/,
  3933. 'ca-AD': /^(\+376)?[346]\d{5}$/,
  3934. 'cs-CZ': /^(\+?420)? ?[1-9][0-9]{2} ?[0-9]{3} ?[0-9]{3}$/,
  3935. 'da-DK': /^(\+?45)?\s?\d{2}\s?\d{2}\s?\d{2}\s?\d{2}$/,
  3936. 'de-DE': /^((\+49|0)1)(5[0-25-9]\d|6([23]|0\d?)|7([0-57-9]|6\d))\d{7,9}$/,
  3937. 'de-AT': /^(\+43|0)\d{1,4}\d{3,12}$/,
  3938. 'de-CH': /^(\+41|0)([1-9])\d{1,9}$/,
  3939. 'de-LU': /^(\+352)?((6\d1)\d{6})$/,
  3940. 'dv-MV': /^(\+?960)?(7[2-9]|9[1-9])\d{5}$/,
  3941. 'el-GR': /^(\+?30|0)?6(8[5-9]|9(?![26])[0-9])\d{7}$/,
  3942. 'el-CY': /^(\+?357?)?(9(9|6)\d{6})$/,
  3943. 'en-AI': /^(\+?1|0)264(?:2(35|92)|4(?:6[1-2]|76|97)|5(?:3[6-9]|8[1-4])|7(?:2(4|9)|72))\d{4}$/,
  3944. 'en-AU': /^(\+?61|0)4\d{8}$/,
  3945. 'en-AG': /^(?:\+1|1)268(?:464|7(?:1[3-9]|[28]\d|3[0246]|64|7[0-689]))\d{4}$/,
  3946. 'en-BM': /^(\+?1)?441(((3|7)\d{6}$)|(5[0-3][0-9]\d{4}$)|(59\d{5}$))/,
  3947. 'en-BS': /^(\+?1[-\s]?|0)?\(?242\)?[-\s]?\d{3}[-\s]?\d{4}$/,
  3948. 'en-GB': /^(\+?44|0)7\d{9}$/,
  3949. 'en-GG': /^(\+?44|0)1481\d{6}$/,
  3950. 'en-GH': /^(\+233|0)(20|50|24|54|27|57|26|56|23|28|55|59)\d{7}$/,
  3951. 'en-GY': /^(\+592|0)6\d{6}$/,
  3952. 'en-HK': /^(\+?852[-\s]?)?[456789]\d{3}[-\s]?\d{4}$/,
  3953. 'en-MO': /^(\+?853[-\s]?)?[6]\d{3}[-\s]?\d{4}$/,
  3954. 'en-IE': /^(\+?353|0)8[356789]\d{7}$/,
  3955. 'en-IN': /^(\+?91|0)?[6789]\d{9}$/,
  3956. 'en-JM': /^(\+?876)?\d{7}$/,
  3957. 'en-KE': /^(\+?254|0)(7|1)\d{8}$/,
  3958. 'fr-CF': /^(\+?236| ?)(70|75|77|72|21|22)\d{6}$/,
  3959. 'en-SS': /^(\+?211|0)(9[1257])\d{7}$/,
  3960. 'en-KI': /^((\+686|686)?)?( )?((6|7)(2|3|8)[0-9]{6})$/,
  3961. 'en-KN': /^(?:\+1|1)869(?:46\d|48[89]|55[6-8]|66\d|76[02-7])\d{4}$/,
  3962. 'en-LS': /^(\+?266)(22|28|57|58|59|27|52)\d{6}$/,
  3963. 'en-MT': /^(\+?356|0)?(99|79|77|21|27|22|25)[0-9]{6}$/,
  3964. 'en-MU': /^(\+?230|0)?\d{8}$/,
  3965. 'en-MW': /^(\+?265|0)(((77|88|31|99|98|21)\d{7})|(((111)|1)\d{6})|(32000\d{4}))$/,
  3966. 'en-NA': /^(\+?264|0)(6|8)\d{7}$/,
  3967. 'en-NG': /^(\+?234|0)?[789]\d{9}$/,
  3968. 'en-NZ': /^(\+?64|0)[28]\d{7,9}$/,
  3969. 'en-PG': /^(\+?675|0)?(7\d|8[18])\d{6}$/,
  3970. 'en-PK': /^((00|\+)?92|0)3[0-6]\d{8}$/,
  3971. 'en-PH': /^(09|\+639)\d{9}$/,
  3972. 'en-RW': /^(\+?250|0)?[7]\d{8}$/,
  3973. 'en-SG': /^(\+65)?[3689]\d{7}$/,
  3974. 'en-SL': /^(\+?232|0)\d{8}$/,
  3975. 'en-TZ': /^(\+?255|0)?[67]\d{8}$/,
  3976. 'en-UG': /^(\+?256|0)?[7]\d{8}$/,
  3977. 'en-US': /^((\+1|1)?( |-)?)?(\([2-9][0-9]{2}\)|[2-9][0-9]{2})( |-)?([2-9][0-9]{2}( |-)?[0-9]{4})$/,
  3978. 'en-ZA': /^(\+?27|0)\d{9}$/,
  3979. 'en-ZM': /^(\+?26)?09[567]\d{7}$/,
  3980. 'en-ZW': /^(\+263)[0-9]{9}$/,
  3981. 'en-BW': /^(\+?267)?(7[1-8]{1})\d{6}$/,
  3982. 'es-AR': /^\+?549(11|[2368]\d)\d{8}$/,
  3983. 'es-BO': /^(\+?591)?(6|7)\d{7}$/,
  3984. 'es-CO': /^(\+?57)?3(0(0|1|2|4|5)|1\d|2[0-4]|5(0|1))\d{7}$/,
  3985. 'es-CL': /^(\+?56|0)[2-9]\d{1}\d{7}$/,
  3986. 'es-CR': /^(\+506)?[2-8]\d{7}$/,
  3987. 'es-CU': /^(\+53|0053)?5\d{7}$/,
  3988. 'es-DO': /^(\+?1)?8[024]9\d{7}$/,
  3989. 'es-HN': /^(\+?504)?[9|8|3|2]\d{7}$/,
  3990. 'es-EC': /^(\+?593|0)([2-7]|9[2-9])\d{7}$/,
  3991. 'es-ES': /^(\+?34)?[6|7]\d{8}$/,
  3992. 'es-PE': /^(\+?51)?9\d{8}$/,
  3993. 'es-MX': /^(\+?52)?(1|01)?\d{10,11}$/,
  3994. 'es-NI': /^(\+?505)\d{7,8}$/,
  3995. 'es-PA': /^(\+?507)\d{7,8}$/,
  3996. 'es-PY': /^(\+?595|0)9[9876]\d{7}$/,
  3997. 'es-SV': /^(\+?503)?[67]\d{7}$/,
  3998. 'es-UY': /^(\+598|0)9[1-9][\d]{6}$/,
  3999. 'es-VE': /^(\+?58)?(2|4)\d{9}$/,
  4000. 'et-EE': /^(\+?372)?\s?(5|8[1-4])\s?([0-9]\s?){6,7}$/,
  4001. 'fa-IR': /^(\+?98[\-\s]?|0)9[0-39]\d[\-\s]?\d{3}[\-\s]?\d{4}$/,
  4002. 'fi-FI': /^(\+?358|0)\s?(4[0-6]|50)\s?(\d\s?){4,8}$/,
  4003. 'fj-FJ': /^(\+?679)?\s?\d{3}\s?\d{4}$/,
  4004. 'fo-FO': /^(\+?298)?\s?\d{2}\s?\d{2}\s?\d{2}$/,
  4005. 'fr-BF': /^(\+226|0)[67]\d{7}$/,
  4006. 'fr-BJ': /^(\+229)\d{8}$/,
  4007. 'fr-CD': /^(\+?243|0)?(8|9)\d{8}$/,
  4008. 'fr-CM': /^(\+?237)6[0-9]{8}$/,
  4009. 'fr-FR': /^(\+?33|0)[67]\d{8}$/,
  4010. 'fr-GF': /^(\+?594|0|00594)[67]\d{8}$/,
  4011. 'fr-GP': /^(\+?590|0|00590)[67]\d{8}$/,
  4012. 'fr-MQ': /^(\+?596|0|00596)[67]\d{8}$/,
  4013. 'fr-PF': /^(\+?689)?8[789]\d{6}$/,
  4014. 'fr-RE': /^(\+?262|0|00262)[67]\d{8}$/,
  4015. 'fr-WF': /^(\+681)?\d{6}$/,
  4016. 'he-IL': /^(\+972|0)([23489]|5[012345689]|77)[1-9]\d{6}$/,
  4017. 'hu-HU': /^(\+?36|06)(20|30|31|50|70)\d{7}$/,
  4018. 'id-ID': /^(\+?62|0)8(1[123456789]|2[1238]|3[1238]|5[12356789]|7[78]|9[56789]|8[123456789])([\s?|\d]{5,11})$/,
  4019. 'ir-IR': /^(\+98|0)?9\d{9}$/,
  4020. 'it-IT': /^(\+?39)?\s?3\d{2} ?\d{6,7}$/,
  4021. 'it-SM': /^((\+378)|(0549)|(\+390549)|(\+3780549))?6\d{5,9}$/,
  4022. 'ja-JP': /^(\+81[ \-]?(\(0\))?|0)[6789]0[ \-]?\d{4}[ \-]?\d{4}$/,
  4023. 'ka-GE': /^(\+?995)?(79\d{7}|5\d{8})$/,
  4024. 'kk-KZ': /^(\+?7|8)?7\d{9}$/,
  4025. 'kl-GL': /^(\+?299)?\s?\d{2}\s?\d{2}\s?\d{2}$/,
  4026. 'ko-KR': /^((\+?82)[ \-]?)?0?1([0|1|6|7|8|9]{1})[ \-]?\d{3,4}[ \-]?\d{4}$/,
  4027. 'ky-KG': /^(\+?7\s?\+?7|0)\s?\d{2}\s?\d{3}\s?\d{4}$/,
  4028. 'lt-LT': /^(\+370|8)\d{8}$/,
  4029. 'lv-LV': /^(\+?371)2\d{7}$/,
  4030. 'mg-MG': /^((\+?261|0)(2|3)\d)?\d{7}$/,
  4031. 'mn-MN': /^(\+|00|011)?976(77|81|88|91|94|95|96|99)\d{6}$/,
  4032. 'my-MM': /^(\+?959|09|9)(2[5-7]|3[1-2]|4[0-5]|6[6-9]|7[5-9]|9[6-9])[0-9]{7}$/,
  4033. 'ms-MY': /^(\+?60|0)1(([0145](-|\s)?\d{7,8})|([236-9](-|\s)?\d{7}))$/,
  4034. 'mz-MZ': /^(\+?258)?8[234567]\d{7}$/,
  4035. 'nb-NO': /^(\+?47)?[49]\d{7}$/,
  4036. 'ne-NP': /^(\+?977)?9[78]\d{8}$/,
  4037. 'nl-BE': /^(\+?32|0)4\d{8}$/,
  4038. 'nl-NL': /^(((\+|00)?31\(0\))|((\+|00)?31)|0)6{1}\d{8}$/,
  4039. 'nl-AW': /^(\+)?297(56|59|64|73|74|99)\d{5}$/,
  4040. 'nn-NO': /^(\+?47)?[49]\d{7}$/,
  4041. 'pl-PL': /^(\+?48)? ?([5-8]\d|45) ?\d{3} ?\d{2} ?\d{2}$/,
  4042. 'pt-BR': /^((\+?55\ ?[1-9]{2}\ ?)|(\+?55\ ?\([1-9]{2}\)\ ?)|(0[1-9]{2}\ ?)|(\([1-9]{2}\)\ ?)|([1-9]{2}\ ?))((\d{4}\-?\d{4})|(9[1-9]{1}\d{3}\-?\d{4}))$/,
  4043. 'pt-PT': /^(\+?351)?9[1236]\d{7}$/,
  4044. 'pt-AO': /^(\+244)\d{9}$/,
  4045. 'ro-MD': /^(\+?373|0)((6(0|1|2|6|7|8|9))|(7(6|7|8|9)))\d{6}$/,
  4046. 'ro-RO': /^(\+?40|0)\s?7\d{2}(\/|\s|\.|-)?\d{3}(\s|\.|-)?\d{3}$/,
  4047. 'ru-RU': /^(\+?7|8)?9\d{9}$/,
  4048. 'si-LK': /^(?:0|94|\+94)?(7(0|1|2|4|5|6|7|8)( |-)?)\d{7}$/,
  4049. 'sl-SI': /^(\+386\s?|0)(\d{1}\s?\d{3}\s?\d{2}\s?\d{2}|\d{2}\s?\d{3}\s?\d{3})$/,
  4050. 'sk-SK': /^(\+?421)? ?[1-9][0-9]{2} ?[0-9]{3} ?[0-9]{3}$/,
  4051. 'so-SO': /^(\+?252|0)((6[0-9])\d{7}|(7[1-9])\d{7})$/,
  4052. 'sq-AL': /^(\+355|0)6[789]\d{6}$/,
  4053. 'sr-RS': /^(\+3816|06)[- \d]{5,9}$/,
  4054. 'sv-SE': /^(\+?46|0)[\s\-]?7[\s\-]?[02369]([\s\-]?\d){7}$/,
  4055. 'tg-TJ': /^(\+?992)?[5][5]\d{7}$/,
  4056. 'th-TH': /^(\+66|66|0)\d{9}$/,
  4057. 'tr-TR': /^(\+?90|0)?5\d{9}$/,
  4058. 'tk-TM': /^(\+993|993|8)\d{8}$/,
  4059. 'uk-UA': /^(\+?38|8)?0\d{9}$/,
  4060. 'uz-UZ': /^(\+?998)?(6[125-79]|7[1-69]|88|9\d)\d{7}$/,
  4061. 'vi-VN': /^((\+?84)|0)((3([2-9]))|(5([25689]))|(7([0|6-9]))|(8([1-9]))|(9([0-9])))([0-9]{7})$/,
  4062. 'zh-CN': /^((\+|00)86)?(1[3-9]|9[28])\d{9}$/,
  4063. 'zh-TW': /^(\+?886\-?|0)?9\d{8}$/,
  4064. 'dz-BT': /^(\+?975|0)?(17|16|77|02)\d{6}$/,
  4065. 'ar-YE': /^(((\+|00)9677|0?7)[0137]\d{7}|((\+|00)967|0)[1-7]\d{6})$/,
  4066. 'ar-EH': /^(\+?212|0)[\s\-]?(5288|5289)[\s\-]?\d{5}$/,
  4067. 'fa-AF': /^(\+93|0)?(2{1}[0-8]{1}|[3-5]{1}[0-4]{1})(\d{7})$/
  4068. };
  4069. /* eslint-enable max-len */
  4070. // aliases
  4071. phones['en-CA'] = phones['en-US'];
  4072. phones['fr-CA'] = phones['en-CA'];
  4073. phones['fr-BE'] = phones['nl-BE'];
  4074. phones['zh-HK'] = phones['en-HK'];
  4075. phones['zh-MO'] = phones['en-MO'];
  4076. phones['ga-IE'] = phones['en-IE'];
  4077. phones['fr-CH'] = phones['de-CH'];
  4078. phones['it-CH'] = phones['fr-CH'];
  4079. function isMobilePhone(str, locale, options) {
  4080. assertString(str);
  4081. if (options && options.strictMode && !str.startsWith('+')) {
  4082. return false;
  4083. }
  4084. if (Array.isArray(locale)) {
  4085. return locale.some(function (key) {
  4086. // https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md#ignoring-code-for-coverage-purposes
  4087. // istanbul ignore else
  4088. if (phones.hasOwnProperty(key)) {
  4089. var phone = phones[key];
  4090. if (phone.test(str)) {
  4091. return true;
  4092. }
  4093. }
  4094. return false;
  4095. });
  4096. } else if (locale in phones) {
  4097. return phones[locale].test(str);
  4098. // alias falsey locale as 'any'
  4099. } else if (!locale || locale === 'any') {
  4100. for (var key in phones) {
  4101. // istanbul ignore else
  4102. if (phones.hasOwnProperty(key)) {
  4103. var phone = phones[key];
  4104. if (phone.test(str)) {
  4105. return true;
  4106. }
  4107. }
  4108. }
  4109. return false;
  4110. }
  4111. throw new Error("Invalid locale '".concat(locale, "'"));
  4112. }
  4113. var locales$4 = Object.keys(phones);
  4114. var eth = /^(0x)[0-9a-f]{40}$/i;
  4115. function isEthereumAddress(str) {
  4116. assertString(str);
  4117. return eth.test(str);
  4118. }
  4119. function currencyRegex(options) {
  4120. var decimal_digits = "\\d{".concat(options.digits_after_decimal[0], "}");
  4121. options.digits_after_decimal.forEach(function (digit, index) {
  4122. if (index !== 0) decimal_digits = "".concat(decimal_digits, "|\\d{").concat(digit, "}");
  4123. });
  4124. var symbol = "(".concat(options.symbol.replace(/\W/, function (m) {
  4125. return "\\".concat(m);
  4126. }), ")").concat(options.require_symbol ? '' : '?'),
  4127. negative = '-?',
  4128. whole_dollar_amount_without_sep = '[1-9]\\d*',
  4129. whole_dollar_amount_with_sep = "[1-9]\\d{0,2}(\\".concat(options.thousands_separator, "\\d{3})*"),
  4130. valid_whole_dollar_amounts = ['0', whole_dollar_amount_without_sep, whole_dollar_amount_with_sep],
  4131. whole_dollar_amount = "(".concat(valid_whole_dollar_amounts.join('|'), ")?"),
  4132. decimal_amount = "(\\".concat(options.decimal_separator, "(").concat(decimal_digits, "))").concat(options.require_decimal ? '' : '?');
  4133. var pattern = whole_dollar_amount + (options.allow_decimal || options.require_decimal ? decimal_amount : '');
  4134. // default is negative sign before symbol, but there are two other options (besides parens)
  4135. if (options.allow_negatives && !options.parens_for_negatives) {
  4136. if (options.negative_sign_after_digits) {
  4137. pattern += negative;
  4138. } else if (options.negative_sign_before_digits) {
  4139. pattern = negative + pattern;
  4140. }
  4141. }
  4142. // South African Rand, for example, uses R 123 (space) and R-123 (no space)
  4143. if (options.allow_negative_sign_placeholder) {
  4144. pattern = "( (?!\\-))?".concat(pattern);
  4145. } else if (options.allow_space_after_symbol) {
  4146. pattern = " ?".concat(pattern);
  4147. } else if (options.allow_space_after_digits) {
  4148. pattern += '( (?!$))?';
  4149. }
  4150. if (options.symbol_after_digits) {
  4151. pattern += symbol;
  4152. } else {
  4153. pattern = symbol + pattern;
  4154. }
  4155. if (options.allow_negatives) {
  4156. if (options.parens_for_negatives) {
  4157. pattern = "(\\(".concat(pattern, "\\)|").concat(pattern, ")");
  4158. } else if (!(options.negative_sign_before_digits || options.negative_sign_after_digits)) {
  4159. pattern = negative + pattern;
  4160. }
  4161. }
  4162. // ensure there's a dollar and/or decimal amount, and that
  4163. // it doesn't start with a space or a negative sign followed by a space
  4164. return new RegExp("^(?!-? )(?=.*\\d)".concat(pattern, "$"));
  4165. }
  4166. var default_currency_options = {
  4167. symbol: '$',
  4168. require_symbol: false,
  4169. allow_space_after_symbol: false,
  4170. symbol_after_digits: false,
  4171. allow_negatives: true,
  4172. parens_for_negatives: false,
  4173. negative_sign_before_digits: false,
  4174. negative_sign_after_digits: false,
  4175. allow_negative_sign_placeholder: false,
  4176. thousands_separator: ',',
  4177. decimal_separator: '.',
  4178. allow_decimal: true,
  4179. require_decimal: false,
  4180. digits_after_decimal: [2],
  4181. allow_space_after_digits: false
  4182. };
  4183. function isCurrency(str, options) {
  4184. assertString(str);
  4185. options = merge(options, default_currency_options);
  4186. return currencyRegex(options).test(str);
  4187. }
  4188. var bech32 = /^(bc1)[a-z0-9]{25,39}$/;
  4189. var base58 = /^(1|3)[A-HJ-NP-Za-km-z1-9]{25,39}$/;
  4190. function isBtcAddress(str) {
  4191. assertString(str);
  4192. return bech32.test(str) || base58.test(str);
  4193. }
  4194. // https://en.wikipedia.org/wiki/ISO_6346
  4195. // according to ISO6346 standard, checksum digit is mandatory for freight container but recommended
  4196. // for other container types (J and Z)
  4197. var isISO6346Str = /^[A-Z]{3}(U[0-9]{7})|([J,Z][0-9]{6,7})$/;
  4198. var isDigit = /^[0-9]$/;
  4199. function isISO6346(str) {
  4200. assertString(str);
  4201. str = str.toUpperCase();
  4202. if (!isISO6346Str.test(str)) return false;
  4203. if (str.length === 11) {
  4204. var sum = 0;
  4205. for (var i = 0; i < str.length - 1; i++) {
  4206. if (!isDigit.test(str[i])) {
  4207. var convertedCode = void 0;
  4208. var letterCode = str.charCodeAt(i) - 55;
  4209. if (letterCode < 11) convertedCode = letterCode;else if (letterCode >= 11 && letterCode <= 20) convertedCode = 12 + letterCode % 11;else if (letterCode >= 21 && letterCode <= 30) convertedCode = 23 + letterCode % 21;else convertedCode = 34 + letterCode % 31;
  4210. sum += convertedCode * Math.pow(2, i);
  4211. } else sum += str[i] * Math.pow(2, i);
  4212. }
  4213. var checkSumDigit = sum % 11;
  4214. return Number(str[str.length - 1]) === checkSumDigit;
  4215. }
  4216. return true;
  4217. }
  4218. var isFreightContainerID = isISO6346;
  4219. var isISO6391Set = new Set(['aa', 'ab', 'ae', 'af', 'ak', 'am', 'an', 'ar', 'as', 'av', 'ay', 'az', 'az', 'ba', 'be', 'bg', 'bh', 'bi', 'bm', 'bn', 'bo', 'br', 'bs', 'ca', 'ce', 'ch', 'co', 'cr', 'cs', 'cu', 'cv', 'cy', 'da', 'de', 'dv', 'dz', 'ee', 'el', 'en', 'eo', 'es', 'et', 'eu', 'fa', 'ff', 'fi', 'fj', 'fo', 'fr', 'fy', 'ga', 'gd', 'gl', 'gn', 'gu', 'gv', 'ha', 'he', 'hi', 'ho', 'hr', 'ht', 'hu', 'hy', 'hz', 'ia', 'id', 'ie', 'ig', 'ii', 'ik', 'io', 'is', 'it', 'iu', 'ja', 'jv', 'ka', 'kg', 'ki', 'kj', 'kk', 'kl', 'km', 'kn', 'ko', 'kr', 'ks', 'ku', 'kv', 'kw', 'ky', 'la', 'lb', 'lg', 'li', 'ln', 'lo', 'lt', 'lu', 'lv', 'mg', 'mh', 'mi', 'mk', 'ml', 'mn', 'mr', 'ms', 'mt', 'my', 'na', 'nb', 'nd', 'ne', 'ng', 'nl', 'nn', 'no', 'nr', 'nv', 'ny', 'oc', 'oj', 'om', 'or', 'os', 'pa', 'pi', 'pl', 'ps', 'pt', 'qu', 'rm', 'rn', 'ro', 'ru', 'rw', 'sa', 'sc', 'sd', 'se', 'sg', 'si', 'sk', 'sl', 'sm', 'sn', 'so', 'sq', 'sr', 'ss', 'st', 'su', 'sv', 'sw', 'ta', 'te', 'tg', 'th', 'ti', 'tk', 'tl', 'tn', 'to', 'tr', 'ts', 'tt', 'tw', 'ty', 'ug', 'uk', 'ur', 'uz', 've', 'vi', 'vo', 'wa', 'wo', 'xh', 'yi', 'yo', 'za', 'zh', 'zu']);
  4220. function isISO6391(str) {
  4221. assertString(str);
  4222. return isISO6391Set.has(str);
  4223. }
  4224. /* eslint-disable max-len */
  4225. // from http://goo.gl/0ejHHW
  4226. var iso8601 = /^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-3])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/;
  4227. // same as above, except with a strict 'T' separator between date and time
  4228. var iso8601StrictSeparator = /^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-3])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T]((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/;
  4229. /* eslint-enable max-len */
  4230. var isValidDate = function isValidDate(str) {
  4231. // str must have passed the ISO8601 check
  4232. // this check is meant to catch invalid dates
  4233. // like 2009-02-31
  4234. // first check for ordinal dates
  4235. var ordinalMatch = str.match(/^(\d{4})-?(\d{3})([ T]{1}\.*|$)/);
  4236. if (ordinalMatch) {
  4237. var oYear = Number(ordinalMatch[1]);
  4238. var oDay = Number(ordinalMatch[2]);
  4239. // if is leap year
  4240. if (oYear % 4 === 0 && oYear % 100 !== 0 || oYear % 400 === 0) return oDay <= 366;
  4241. return oDay <= 365;
  4242. }
  4243. var match = str.match(/(\d{4})-?(\d{0,2})-?(\d*)/).map(Number);
  4244. var year = match[1];
  4245. var month = match[2];
  4246. var day = match[3];
  4247. var monthString = month ? "0".concat(month).slice(-2) : month;
  4248. var dayString = day ? "0".concat(day).slice(-2) : day;
  4249. // create a date object and compare
  4250. var d = new Date("".concat(year, "-").concat(monthString || '01', "-").concat(dayString || '01'));
  4251. if (month && day) {
  4252. return d.getUTCFullYear() === year && d.getUTCMonth() + 1 === month && d.getUTCDate() === day;
  4253. }
  4254. return true;
  4255. };
  4256. function isISO8601(str) {
  4257. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  4258. assertString(str);
  4259. var check = options.strictSeparator ? iso8601StrictSeparator.test(str) : iso8601.test(str);
  4260. if (check && options.strict) return isValidDate(str);
  4261. return check;
  4262. }
  4263. /* Based on https://tools.ietf.org/html/rfc3339#section-5.6 */
  4264. var dateFullYear = /[0-9]{4}/;
  4265. var dateMonth = /(0[1-9]|1[0-2])/;
  4266. var dateMDay = /([12]\d|0[1-9]|3[01])/;
  4267. var timeHour = /([01][0-9]|2[0-3])/;
  4268. var timeMinute = /[0-5][0-9]/;
  4269. var timeSecond = /([0-5][0-9]|60)/;
  4270. var timeSecFrac = /(\.[0-9]+)?/;
  4271. var timeNumOffset = new RegExp("[-+]".concat(timeHour.source, ":").concat(timeMinute.source));
  4272. var timeOffset = new RegExp("([zZ]|".concat(timeNumOffset.source, ")"));
  4273. var partialTime = new RegExp("".concat(timeHour.source, ":").concat(timeMinute.source, ":").concat(timeSecond.source).concat(timeSecFrac.source));
  4274. var fullDate = new RegExp("".concat(dateFullYear.source, "-").concat(dateMonth.source, "-").concat(dateMDay.source));
  4275. var fullTime = new RegExp("".concat(partialTime.source).concat(timeOffset.source));
  4276. var rfc3339 = new RegExp("^".concat(fullDate.source, "[ tT]").concat(fullTime.source, "$"));
  4277. function isRFC3339(str) {
  4278. assertString(str);
  4279. return rfc3339.test(str);
  4280. }
  4281. // from https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3
  4282. var validISO31661Alpha3CountriesCodes = new Set(['AFG', 'ALA', 'ALB', 'DZA', 'ASM', 'AND', 'AGO', 'AIA', 'ATA', 'ATG', 'ARG', 'ARM', 'ABW', 'AUS', 'AUT', 'AZE', 'BHS', 'BHR', 'BGD', 'BRB', 'BLR', 'BEL', 'BLZ', 'BEN', 'BMU', 'BTN', 'BOL', 'BES', 'BIH', 'BWA', 'BVT', 'BRA', 'IOT', 'BRN', 'BGR', 'BFA', 'BDI', 'KHM', 'CMR', 'CAN', 'CPV', 'CYM', 'CAF', 'TCD', 'CHL', 'CHN', 'CXR', 'CCK', 'COL', 'COM', 'COG', 'COD', 'COK', 'CRI', 'CIV', 'HRV', 'CUB', 'CUW', 'CYP', 'CZE', 'DNK', 'DJI', 'DMA', 'DOM', 'ECU', 'EGY', 'SLV', 'GNQ', 'ERI', 'EST', 'ETH', 'FLK', 'FRO', 'FJI', 'FIN', 'FRA', 'GUF', 'PYF', 'ATF', 'GAB', 'GMB', 'GEO', 'DEU', 'GHA', 'GIB', 'GRC', 'GRL', 'GRD', 'GLP', 'GUM', 'GTM', 'GGY', 'GIN', 'GNB', 'GUY', 'HTI', 'HMD', 'VAT', 'HND', 'HKG', 'HUN', 'ISL', 'IND', 'IDN', 'IRN', 'IRQ', 'IRL', 'IMN', 'ISR', 'ITA', 'JAM', 'JPN', 'JEY', 'JOR', 'KAZ', 'KEN', 'KIR', 'PRK', 'KOR', 'KWT', 'KGZ', 'LAO', 'LVA', 'LBN', 'LSO', 'LBR', 'LBY', 'LIE', 'LTU', 'LUX', 'MAC', 'MKD', 'MDG', 'MWI', 'MYS', 'MDV', 'MLI', 'MLT', 'MHL', 'MTQ', 'MRT', 'MUS', 'MYT', 'MEX', 'FSM', 'MDA', 'MCO', 'MNG', 'MNE', 'MSR', 'MAR', 'MOZ', 'MMR', 'NAM', 'NRU', 'NPL', 'NLD', 'NCL', 'NZL', 'NIC', 'NER', 'NGA', 'NIU', 'NFK', 'MNP', 'NOR', 'OMN', 'PAK', 'PLW', 'PSE', 'PAN', 'PNG', 'PRY', 'PER', 'PHL', 'PCN', 'POL', 'PRT', 'PRI', 'QAT', 'REU', 'ROU', 'RUS', 'RWA', 'BLM', 'SHN', 'KNA', 'LCA', 'MAF', 'SPM', 'VCT', 'WSM', 'SMR', 'STP', 'SAU', 'SEN', 'SRB', 'SYC', 'SLE', 'SGP', 'SXM', 'SVK', 'SVN', 'SLB', 'SOM', 'ZAF', 'SGS', 'SSD', 'ESP', 'LKA', 'SDN', 'SUR', 'SJM', 'SWZ', 'SWE', 'CHE', 'SYR', 'TWN', 'TJK', 'TZA', 'THA', 'TLS', 'TGO', 'TKL', 'TON', 'TTO', 'TUN', 'TUR', 'TKM', 'TCA', 'TUV', 'UGA', 'UKR', 'ARE', 'GBR', 'USA', 'UMI', 'URY', 'UZB', 'VUT', 'VEN', 'VNM', 'VGB', 'VIR', 'WLF', 'ESH', 'YEM', 'ZMB', 'ZWE']);
  4283. function isISO31661Alpha3(str) {
  4284. assertString(str);
  4285. return validISO31661Alpha3CountriesCodes.has(str.toUpperCase());
  4286. }
  4287. // from https://en.wikipedia.org/wiki/ISO_4217
  4288. var validISO4217CurrencyCodes = new Set(['AED', 'AFN', 'ALL', 'AMD', 'ANG', 'AOA', 'ARS', 'AUD', 'AWG', 'AZN', 'BAM', 'BBD', 'BDT', 'BGN', 'BHD', 'BIF', 'BMD', 'BND', 'BOB', 'BOV', 'BRL', 'BSD', 'BTN', 'BWP', 'BYN', 'BZD', 'CAD', 'CDF', 'CHE', 'CHF', 'CHW', 'CLF', 'CLP', 'CNY', 'COP', 'COU', 'CRC', 'CUC', 'CUP', 'CVE', 'CZK', 'DJF', 'DKK', 'DOP', 'DZD', 'EGP', 'ERN', 'ETB', 'EUR', 'FJD', 'FKP', 'GBP', 'GEL', 'GHS', 'GIP', 'GMD', 'GNF', 'GTQ', 'GYD', 'HKD', 'HNL', 'HRK', 'HTG', 'HUF', 'IDR', 'ILS', 'INR', 'IQD', 'IRR', 'ISK', 'JMD', 'JOD', 'JPY', 'KES', 'KGS', 'KHR', 'KMF', 'KPW', 'KRW', 'KWD', 'KYD', 'KZT', 'LAK', 'LBP', 'LKR', 'LRD', 'LSL', 'LYD', 'MAD', 'MDL', 'MGA', 'MKD', 'MMK', 'MNT', 'MOP', 'MRU', 'MUR', 'MVR', 'MWK', 'MXN', 'MXV', 'MYR', 'MZN', 'NAD', 'NGN', 'NIO', 'NOK', 'NPR', 'NZD', 'OMR', 'PAB', 'PEN', 'PGK', 'PHP', 'PKR', 'PLN', 'PYG', 'QAR', 'RON', 'RSD', 'RUB', 'RWF', 'SAR', 'SBD', 'SCR', 'SDG', 'SEK', 'SGD', 'SHP', 'SLE', 'SLL', 'SOS', 'SRD', 'SSP', 'STN', 'SVC', 'SYP', 'SZL', 'THB', 'TJS', 'TMT', 'TND', 'TOP', 'TRY', 'TTD', 'TWD', 'TZS', 'UAH', 'UGX', 'USD', 'USN', 'UYI', 'UYU', 'UYW', 'UZS', 'VES', 'VND', 'VUV', 'WST', 'XAF', 'XAG', 'XAU', 'XBA', 'XBB', 'XBC', 'XBD', 'XCD', 'XDR', 'XOF', 'XPD', 'XPF', 'XPT', 'XSU', 'XTS', 'XUA', 'XXX', 'YER', 'ZAR', 'ZMW', 'ZWL']);
  4289. function isISO4217(str) {
  4290. assertString(str);
  4291. return validISO4217CurrencyCodes.has(str.toUpperCase());
  4292. }
  4293. var base32 = /^[A-Z2-7]+=*$/;
  4294. var crockfordBase32 = /^[A-HJKMNP-TV-Z0-9]+$/;
  4295. var defaultBase32Options = {
  4296. crockford: false
  4297. };
  4298. function isBase32(str, options) {
  4299. assertString(str);
  4300. options = merge(options, defaultBase32Options);
  4301. if (options.crockford) {
  4302. return crockfordBase32.test(str);
  4303. }
  4304. var len = str.length;
  4305. if (len % 8 === 0 && base32.test(str)) {
  4306. return true;
  4307. }
  4308. return false;
  4309. }
  4310. // Accepted chars - 123456789ABCDEFGH JKLMN PQRSTUVWXYZabcdefghijk mnopqrstuvwxyz
  4311. var base58Reg = /^[A-HJ-NP-Za-km-z1-9]*$/;
  4312. function isBase58(str) {
  4313. assertString(str);
  4314. if (base58Reg.test(str)) {
  4315. return true;
  4316. }
  4317. return false;
  4318. }
  4319. var validMediaType = /^[a-z]+\/[a-z0-9\-\+\._]+$/i;
  4320. var validAttribute = /^[a-z\-]+=[a-z0-9\-]+$/i;
  4321. var validData = /^[a-z0-9!\$&'\(\)\*\+,;=\-\._~:@\/\?%\s]*$/i;
  4322. function isDataURI(str) {
  4323. assertString(str);
  4324. var data = str.split(',');
  4325. if (data.length < 2) {
  4326. return false;
  4327. }
  4328. var attributes = data.shift().trim().split(';');
  4329. var schemeAndMediaType = attributes.shift();
  4330. if (schemeAndMediaType.slice(0, 5) !== 'data:') {
  4331. return false;
  4332. }
  4333. var mediaType = schemeAndMediaType.slice(5);
  4334. if (mediaType !== '' && !validMediaType.test(mediaType)) {
  4335. return false;
  4336. }
  4337. for (var i = 0; i < attributes.length; i++) {
  4338. if (!(i === attributes.length - 1 && attributes[i].toLowerCase() === 'base64') && !validAttribute.test(attributes[i])) {
  4339. return false;
  4340. }
  4341. }
  4342. for (var _i = 0; _i < data.length; _i++) {
  4343. if (!validData.test(data[_i])) {
  4344. return false;
  4345. }
  4346. }
  4347. return true;
  4348. }
  4349. var magnetURIComponent = /(?:^magnet:\?|[^?&]&)xt(?:\.1)?=urn:(?:(?:aich|bitprint|btih|ed2k|ed2khash|kzhash|md5|sha1|tree:tiger):[a-z0-9]{32}(?:[a-z0-9]{8})?|btmh:1220[a-z0-9]{64})(?:$|&)/i;
  4350. function isMagnetURI(url) {
  4351. assertString(url);
  4352. if (url.indexOf('magnet:?') !== 0) {
  4353. return false;
  4354. }
  4355. return magnetURIComponent.test(url);
  4356. }
  4357. function rtrim(str, chars) {
  4358. assertString(str);
  4359. if (chars) {
  4360. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Escaping
  4361. var pattern = new RegExp("[".concat(chars.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), "]+$"), 'g');
  4362. return str.replace(pattern, '');
  4363. }
  4364. // Use a faster and more safe than regex trim method https://blog.stevenlevithan.com/archives/faster-trim-javascript
  4365. var strIndex = str.length - 1;
  4366. while (/\s/.test(str.charAt(strIndex))) {
  4367. strIndex -= 1;
  4368. }
  4369. return str.slice(0, strIndex + 1);
  4370. }
  4371. function ltrim(str, chars) {
  4372. assertString(str);
  4373. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Escaping
  4374. var pattern = chars ? new RegExp("^[".concat(chars.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), "]+"), 'g') : /^\s+/g;
  4375. return str.replace(pattern, '');
  4376. }
  4377. function trim(str, chars) {
  4378. return rtrim(ltrim(str, chars), chars);
  4379. }
  4380. function parseMailtoQueryString(queryString) {
  4381. var allowedParams = new Set(['subject', 'body', 'cc', 'bcc']),
  4382. query = {
  4383. cc: '',
  4384. bcc: ''
  4385. };
  4386. var isParseFailed = false;
  4387. var queryParams = queryString.split('&');
  4388. if (queryParams.length > 4) {
  4389. return false;
  4390. }
  4391. var _iterator = _createForOfIteratorHelper(queryParams),
  4392. _step;
  4393. try {
  4394. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  4395. var q = _step.value;
  4396. var _q$split = q.split('='),
  4397. _q$split2 = _slicedToArray(_q$split, 2),
  4398. key = _q$split2[0],
  4399. value = _q$split2[1];
  4400. // checked for invalid and duplicated query params
  4401. if (key && !allowedParams.has(key)) {
  4402. isParseFailed = true;
  4403. break;
  4404. }
  4405. if (value && (key === 'cc' || key === 'bcc')) {
  4406. query[key] = value;
  4407. }
  4408. if (key) {
  4409. allowedParams["delete"](key);
  4410. }
  4411. }
  4412. } catch (err) {
  4413. _iterator.e(err);
  4414. } finally {
  4415. _iterator.f();
  4416. }
  4417. return isParseFailed ? false : query;
  4418. }
  4419. function isMailtoURI(url, options) {
  4420. assertString(url);
  4421. if (url.indexOf('mailto:') !== 0) {
  4422. return false;
  4423. }
  4424. var _url$replace$split = url.replace('mailto:', '').split('?'),
  4425. _url$replace$split2 = _slicedToArray(_url$replace$split, 2),
  4426. to = _url$replace$split2[0],
  4427. _url$replace$split2$ = _url$replace$split2[1],
  4428. queryString = _url$replace$split2$ === void 0 ? '' : _url$replace$split2$;
  4429. if (!to && !queryString) {
  4430. return true;
  4431. }
  4432. var query = parseMailtoQueryString(queryString);
  4433. if (!query) {
  4434. return false;
  4435. }
  4436. return "".concat(to, ",").concat(query.cc, ",").concat(query.bcc).split(',').every(function (email) {
  4437. email = trim(email, ' ');
  4438. if (email) {
  4439. return isEmail(email, options);
  4440. }
  4441. return true;
  4442. });
  4443. }
  4444. /*
  4445. Checks if the provided string matches to a correct Media type format (MIME type)
  4446. This function only checks is the string format follows the
  4447. etablished rules by the according RFC specifications.
  4448. This function supports 'charset' in textual media types
  4449. (https://tools.ietf.org/html/rfc6657).
  4450. This function does not check against all the media types listed
  4451. by the IANA (https://www.iana.org/assignments/media-types/media-types.xhtml)
  4452. because of lightness purposes : it would require to include
  4453. all these MIME types in this librairy, which would weigh it
  4454. significantly. This kind of effort maybe is not worth for the use that
  4455. this function has in this entire librairy.
  4456. More informations in the RFC specifications :
  4457. - https://tools.ietf.org/html/rfc2045
  4458. - https://tools.ietf.org/html/rfc2046
  4459. - https://tools.ietf.org/html/rfc7231#section-3.1.1.1
  4460. - https://tools.ietf.org/html/rfc7231#section-3.1.1.5
  4461. */
  4462. // Match simple MIME types
  4463. // NB :
  4464. // Subtype length must not exceed 100 characters.
  4465. // This rule does not comply to the RFC specs (what is the max length ?).
  4466. var mimeTypeSimple = /^(application|audio|font|image|message|model|multipart|text|video)\/[a-zA-Z0-9\.\-\+_]{1,100}$/i; // eslint-disable-line max-len
  4467. // Handle "charset" in "text/*"
  4468. var mimeTypeText = /^text\/[a-zA-Z0-9\.\-\+]{1,100};\s?charset=("[a-zA-Z0-9\.\-\+\s]{0,70}"|[a-zA-Z0-9\.\-\+]{0,70})(\s?\([a-zA-Z0-9\.\-\+\s]{1,20}\))?$/i; // eslint-disable-line max-len
  4469. // Handle "boundary" in "multipart/*"
  4470. var mimeTypeMultipart = /^multipart\/[a-zA-Z0-9\.\-\+]{1,100}(;\s?(boundary|charset)=("[a-zA-Z0-9\.\-\+\s]{0,70}"|[a-zA-Z0-9\.\-\+]{0,70})(\s?\([a-zA-Z0-9\.\-\+\s]{1,20}\))?){0,2}$/i; // eslint-disable-line max-len
  4471. function isMimeType(str) {
  4472. assertString(str);
  4473. return mimeTypeSimple.test(str) || mimeTypeText.test(str) || mimeTypeMultipart.test(str);
  4474. }
  4475. var lat = /^\(?[+-]?(90(\.0+)?|[1-8]?\d(\.\d+)?)$/;
  4476. var _long = /^\s?[+-]?(180(\.0+)?|1[0-7]\d(\.\d+)?|\d{1,2}(\.\d+)?)\)?$/;
  4477. var latDMS = /^(([1-8]?\d)\D+([1-5]?\d|60)\D+([1-5]?\d|60)(\.\d+)?|90\D+0\D+0)\D+[NSns]?$/i;
  4478. var longDMS = /^\s*([1-7]?\d{1,2}\D+([1-5]?\d|60)\D+([1-5]?\d|60)(\.\d+)?|180\D+0\D+0)\D+[EWew]?$/i;
  4479. var defaultLatLongOptions = {
  4480. checkDMS: false
  4481. };
  4482. function isLatLong(str, options) {
  4483. assertString(str);
  4484. options = merge(options, defaultLatLongOptions);
  4485. if (!str.includes(',')) return false;
  4486. var pair = str.split(',');
  4487. if (pair[0].startsWith('(') && !pair[1].endsWith(')') || pair[1].endsWith(')') && !pair[0].startsWith('(')) return false;
  4488. if (options.checkDMS) {
  4489. return latDMS.test(pair[0]) && longDMS.test(pair[1]);
  4490. }
  4491. return lat.test(pair[0]) && _long.test(pair[1]);
  4492. }
  4493. // common patterns
  4494. var threeDigit = /^\d{3}$/;
  4495. var fourDigit = /^\d{4}$/;
  4496. var fiveDigit = /^\d{5}$/;
  4497. var sixDigit = /^\d{6}$/;
  4498. var patterns = {
  4499. AD: /^AD\d{3}$/,
  4500. AT: fourDigit,
  4501. AU: fourDigit,
  4502. AZ: /^AZ\d{4}$/,
  4503. BA: /^([7-8]\d{4}$)/,
  4504. BE: fourDigit,
  4505. BG: fourDigit,
  4506. BR: /^\d{5}-\d{3}$/,
  4507. BY: /^2[1-4]\d{4}$/,
  4508. CA: /^[ABCEGHJKLMNPRSTVXY]\d[ABCEGHJ-NPRSTV-Z][\s\-]?\d[ABCEGHJ-NPRSTV-Z]\d$/i,
  4509. CH: fourDigit,
  4510. CN: /^(0[1-7]|1[012356]|2[0-7]|3[0-6]|4[0-7]|5[1-7]|6[1-7]|7[1-5]|8[1345]|9[09])\d{4}$/,
  4511. CZ: /^\d{3}\s?\d{2}$/,
  4512. DE: fiveDigit,
  4513. DK: fourDigit,
  4514. DO: fiveDigit,
  4515. DZ: fiveDigit,
  4516. EE: fiveDigit,
  4517. ES: /^(5[0-2]{1}|[0-4]{1}\d{1})\d{3}$/,
  4518. FI: fiveDigit,
  4519. FR: /^\d{2}\s?\d{3}$/,
  4520. GB: /^(gir\s?0aa|[a-z]{1,2}\d[\da-z]?\s?(\d[a-z]{2})?)$/i,
  4521. GR: /^\d{3}\s?\d{2}$/,
  4522. HR: /^([1-5]\d{4}$)/,
  4523. HT: /^HT\d{4}$/,
  4524. HU: fourDigit,
  4525. ID: fiveDigit,
  4526. IE: /^(?!.*(?:o))[A-Za-z]\d[\dw]\s\w{4}$/i,
  4527. IL: /^(\d{5}|\d{7})$/,
  4528. IN: /^((?!10|29|35|54|55|65|66|86|87|88|89)[1-9][0-9]{5})$/,
  4529. IR: /^(?!(\d)\1{3})[13-9]{4}[1346-9][013-9]{5}$/,
  4530. IS: threeDigit,
  4531. IT: fiveDigit,
  4532. JP: /^\d{3}\-\d{4}$/,
  4533. KE: fiveDigit,
  4534. KR: /^(\d{5}|\d{6})$/,
  4535. LI: /^(948[5-9]|949[0-7])$/,
  4536. LT: /^LT\-\d{5}$/,
  4537. LU: fourDigit,
  4538. LV: /^LV\-\d{4}$/,
  4539. LK: fiveDigit,
  4540. MG: threeDigit,
  4541. MX: fiveDigit,
  4542. MT: /^[A-Za-z]{3}\s{0,1}\d{4}$/,
  4543. MY: fiveDigit,
  4544. NL: /^[1-9]\d{3}\s?(?!sa|sd|ss)[a-z]{2}$/i,
  4545. NO: fourDigit,
  4546. NP: /^(10|21|22|32|33|34|44|45|56|57)\d{3}$|^(977)$/i,
  4547. NZ: fourDigit,
  4548. PL: /^\d{2}\-\d{3}$/,
  4549. PR: /^00[679]\d{2}([ -]\d{4})?$/,
  4550. PT: /^\d{4}\-\d{3}?$/,
  4551. RO: sixDigit,
  4552. RU: sixDigit,
  4553. SA: fiveDigit,
  4554. SE: /^[1-9]\d{2}\s?\d{2}$/,
  4555. SG: sixDigit,
  4556. SI: fourDigit,
  4557. SK: /^\d{3}\s?\d{2}$/,
  4558. TH: fiveDigit,
  4559. TN: fourDigit,
  4560. TW: /^\d{3}(\d{2})?$/,
  4561. UA: fiveDigit,
  4562. US: /^\d{5}(-\d{4})?$/,
  4563. ZA: fourDigit,
  4564. ZM: fiveDigit
  4565. };
  4566. var locales$5 = Object.keys(patterns);
  4567. function isPostalCode(str, locale) {
  4568. assertString(str);
  4569. if (locale in patterns) {
  4570. return patterns[locale].test(str);
  4571. } else if (locale === 'any') {
  4572. for (var key in patterns) {
  4573. // https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md#ignoring-code-for-coverage-purposes
  4574. // istanbul ignore else
  4575. if (patterns.hasOwnProperty(key)) {
  4576. var pattern = patterns[key];
  4577. if (pattern.test(str)) {
  4578. return true;
  4579. }
  4580. }
  4581. }
  4582. return false;
  4583. }
  4584. throw new Error("Invalid locale '".concat(locale, "'"));
  4585. }
  4586. function escape(str) {
  4587. assertString(str);
  4588. return str.replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/'/g, '&#x27;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\//g, '&#x2F;').replace(/\\/g, '&#x5C;').replace(/`/g, '&#96;');
  4589. }
  4590. function unescape(str) {
  4591. assertString(str);
  4592. return str.replace(/&quot;/g, '"').replace(/&#x27;/g, "'").replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&#x2F;/g, '/').replace(/&#x5C;/g, '\\').replace(/&#96;/g, '`').replace(/&amp;/g, '&');
  4593. // &amp; replacement has to be the last one to prevent
  4594. // bugs with intermediate strings containing escape sequences
  4595. // See: https://github.com/validatorjs/validator.js/issues/1827
  4596. }
  4597. function blacklist$1(str, chars) {
  4598. assertString(str);
  4599. return str.replace(new RegExp("[".concat(chars, "]+"), 'g'), '');
  4600. }
  4601. function stripLow(str, keep_new_lines) {
  4602. assertString(str);
  4603. var chars = keep_new_lines ? '\\x00-\\x09\\x0B\\x0C\\x0E-\\x1F\\x7F' : '\\x00-\\x1F\\x7F';
  4604. return blacklist$1(str, chars);
  4605. }
  4606. function whitelist(str, chars) {
  4607. assertString(str);
  4608. return str.replace(new RegExp("[^".concat(chars, "]+"), 'g'), '');
  4609. }
  4610. function isWhitelisted(str, chars) {
  4611. assertString(str);
  4612. for (var i = str.length - 1; i >= 0; i--) {
  4613. if (chars.indexOf(str[i]) === -1) {
  4614. return false;
  4615. }
  4616. }
  4617. return true;
  4618. }
  4619. var default_normalize_email_options = {
  4620. // The following options apply to all email addresses
  4621. // Lowercases the local part of the email address.
  4622. // Please note this may violate RFC 5321 as per http://stackoverflow.com/a/9808332/192024).
  4623. // The domain is always lowercased, as per RFC 1035
  4624. all_lowercase: true,
  4625. // The following conversions are specific to GMail
  4626. // Lowercases the local part of the GMail address (known to be case-insensitive)
  4627. gmail_lowercase: true,
  4628. // Removes dots from the local part of the email address, as that's ignored by GMail
  4629. gmail_remove_dots: true,
  4630. // Removes the subaddress (e.g. "+foo") from the email address
  4631. gmail_remove_subaddress: true,
  4632. // Conversts the googlemail.com domain to gmail.com
  4633. gmail_convert_googlemaildotcom: true,
  4634. // The following conversions are specific to Outlook.com / Windows Live / Hotmail
  4635. // Lowercases the local part of the Outlook.com address (known to be case-insensitive)
  4636. outlookdotcom_lowercase: true,
  4637. // Removes the subaddress (e.g. "+foo") from the email address
  4638. outlookdotcom_remove_subaddress: true,
  4639. // The following conversions are specific to Yahoo
  4640. // Lowercases the local part of the Yahoo address (known to be case-insensitive)
  4641. yahoo_lowercase: true,
  4642. // Removes the subaddress (e.g. "-foo") from the email address
  4643. yahoo_remove_subaddress: true,
  4644. // The following conversions are specific to Yandex
  4645. // Lowercases the local part of the Yandex address (known to be case-insensitive)
  4646. yandex_lowercase: true,
  4647. // The following conversions are specific to iCloud
  4648. // Lowercases the local part of the iCloud address (known to be case-insensitive)
  4649. icloud_lowercase: true,
  4650. // Removes the subaddress (e.g. "+foo") from the email address
  4651. icloud_remove_subaddress: true
  4652. };
  4653. // List of domains used by iCloud
  4654. var icloud_domains = ['icloud.com', 'me.com'];
  4655. // List of domains used by Outlook.com and its predecessors
  4656. // This list is likely incomplete.
  4657. // Partial reference:
  4658. // https://blogs.office.com/2013/04/17/outlook-com-gets-two-step-verification-sign-in-by-alias-and-new-international-domains/
  4659. var outlookdotcom_domains = ['hotmail.at', 'hotmail.be', 'hotmail.ca', 'hotmail.cl', 'hotmail.co.il', 'hotmail.co.nz', 'hotmail.co.th', 'hotmail.co.uk', 'hotmail.com', 'hotmail.com.ar', 'hotmail.com.au', 'hotmail.com.br', 'hotmail.com.gr', 'hotmail.com.mx', 'hotmail.com.pe', 'hotmail.com.tr', 'hotmail.com.vn', 'hotmail.cz', 'hotmail.de', 'hotmail.dk', 'hotmail.es', 'hotmail.fr', 'hotmail.hu', 'hotmail.id', 'hotmail.ie', 'hotmail.in', 'hotmail.it', 'hotmail.jp', 'hotmail.kr', 'hotmail.lv', 'hotmail.my', 'hotmail.ph', 'hotmail.pt', 'hotmail.sa', 'hotmail.sg', 'hotmail.sk', 'live.be', 'live.co.uk', 'live.com', 'live.com.ar', 'live.com.mx', 'live.de', 'live.es', 'live.eu', 'live.fr', 'live.it', 'live.nl', 'msn.com', 'outlook.at', 'outlook.be', 'outlook.cl', 'outlook.co.il', 'outlook.co.nz', 'outlook.co.th', 'outlook.com', 'outlook.com.ar', 'outlook.com.au', 'outlook.com.br', 'outlook.com.gr', 'outlook.com.pe', 'outlook.com.tr', 'outlook.com.vn', 'outlook.cz', 'outlook.de', 'outlook.dk', 'outlook.es', 'outlook.fr', 'outlook.hu', 'outlook.id', 'outlook.ie', 'outlook.in', 'outlook.it', 'outlook.jp', 'outlook.kr', 'outlook.lv', 'outlook.my', 'outlook.ph', 'outlook.pt', 'outlook.sa', 'outlook.sg', 'outlook.sk', 'passport.com'];
  4660. // List of domains used by Yahoo Mail
  4661. // This list is likely incomplete
  4662. var yahoo_domains = ['rocketmail.com', 'yahoo.ca', 'yahoo.co.uk', 'yahoo.com', 'yahoo.de', 'yahoo.fr', 'yahoo.in', 'yahoo.it', 'ymail.com'];
  4663. // List of domains used by yandex.ru
  4664. var yandex_domains = ['yandex.ru', 'yandex.ua', 'yandex.kz', 'yandex.com', 'yandex.by', 'ya.ru'];
  4665. // replace single dots, but not multiple consecutive dots
  4666. function dotsReplacer(match) {
  4667. if (match.length > 1) {
  4668. return match;
  4669. }
  4670. return '';
  4671. }
  4672. function normalizeEmail(email, options) {
  4673. options = merge(options, default_normalize_email_options);
  4674. var raw_parts = email.split('@');
  4675. var domain = raw_parts.pop();
  4676. var user = raw_parts.join('@');
  4677. var parts = [user, domain];
  4678. // The domain is always lowercased, as it's case-insensitive per RFC 1035
  4679. parts[1] = parts[1].toLowerCase();
  4680. if (parts[1] === 'gmail.com' || parts[1] === 'googlemail.com') {
  4681. // Address is GMail
  4682. if (options.gmail_remove_subaddress) {
  4683. parts[0] = parts[0].split('+')[0];
  4684. }
  4685. if (options.gmail_remove_dots) {
  4686. // this does not replace consecutive dots like example..email@gmail.com
  4687. parts[0] = parts[0].replace(/\.+/g, dotsReplacer);
  4688. }
  4689. if (!parts[0].length) {
  4690. return false;
  4691. }
  4692. if (options.all_lowercase || options.gmail_lowercase) {
  4693. parts[0] = parts[0].toLowerCase();
  4694. }
  4695. parts[1] = options.gmail_convert_googlemaildotcom ? 'gmail.com' : parts[1];
  4696. } else if (icloud_domains.indexOf(parts[1]) >= 0) {
  4697. // Address is iCloud
  4698. if (options.icloud_remove_subaddress) {
  4699. parts[0] = parts[0].split('+')[0];
  4700. }
  4701. if (!parts[0].length) {
  4702. return false;
  4703. }
  4704. if (options.all_lowercase || options.icloud_lowercase) {
  4705. parts[0] = parts[0].toLowerCase();
  4706. }
  4707. } else if (outlookdotcom_domains.indexOf(parts[1]) >= 0) {
  4708. // Address is Outlook.com
  4709. if (options.outlookdotcom_remove_subaddress) {
  4710. parts[0] = parts[0].split('+')[0];
  4711. }
  4712. if (!parts[0].length) {
  4713. return false;
  4714. }
  4715. if (options.all_lowercase || options.outlookdotcom_lowercase) {
  4716. parts[0] = parts[0].toLowerCase();
  4717. }
  4718. } else if (yahoo_domains.indexOf(parts[1]) >= 0) {
  4719. // Address is Yahoo
  4720. if (options.yahoo_remove_subaddress) {
  4721. var components = parts[0].split('-');
  4722. parts[0] = components.length > 1 ? components.slice(0, -1).join('-') : components[0];
  4723. }
  4724. if (!parts[0].length) {
  4725. return false;
  4726. }
  4727. if (options.all_lowercase || options.yahoo_lowercase) {
  4728. parts[0] = parts[0].toLowerCase();
  4729. }
  4730. } else if (yandex_domains.indexOf(parts[1]) >= 0) {
  4731. if (options.all_lowercase || options.yandex_lowercase) {
  4732. parts[0] = parts[0].toLowerCase();
  4733. }
  4734. parts[1] = 'yandex.ru'; // all yandex domains are equal, 1st preferred
  4735. } else if (options.all_lowercase) {
  4736. // Any other address
  4737. parts[0] = parts[0].toLowerCase();
  4738. }
  4739. return parts.join('@');
  4740. }
  4741. var charsetRegex = /^[^\s-_](?!.*?[-_]{2,})[a-z0-9-\\][^\s]*[^-_\s]$/;
  4742. function isSlug(str) {
  4743. assertString(str);
  4744. return charsetRegex.test(str);
  4745. }
  4746. var validators$1 = {
  4747. 'cs-CZ': function csCZ(str) {
  4748. return /^(([ABCDEFHIJKLMNPRSTUVXYZ]|[0-9])-?){5,8}$/.test(str);
  4749. },
  4750. 'de-DE': function deDE(str) {
  4751. return /^((A|AA|AB|AC|AE|AH|AK|AM|AN|AÖ|AP|AS|AT|AU|AW|AZ|B|BA|BB|BC|BE|BF|BH|BI|BK|BL|BM|BN|BO|BÖ|BS|BT|BZ|C|CA|CB|CE|CO|CR|CW|D|DA|DD|DE|DH|DI|DL|DM|DN|DO|DU|DW|DZ|E|EA|EB|ED|EE|EF|EG|EH|EI|EL|EM|EN|ER|ES|EU|EW|F|FB|FD|FF|FG|FI|FL|FN|FO|FR|FS|FT|FÜ|FW|FZ|G|GA|GC|GD|GE|GF|GG|GI|GK|GL|GM|GN|GÖ|GP|GR|GS|GT|GÜ|GV|GW|GZ|H|HA|HB|HC|HD|HE|HF|HG|HH|HI|HK|HL|HM|HN|HO|HP|HR|HS|HU|HV|HX|HY|HZ|IK|IL|IN|IZ|J|JE|JL|K|KA|KB|KC|KE|KF|KG|KH|KI|KK|KL|KM|KN|KO|KR|KS|KT|KU|KW|KY|L|LA|LB|LC|LD|LF|LG|LH|LI|LL|LM|LN|LÖ|LP|LR|LU|M|MA|MB|MC|MD|ME|MG|MH|MI|MK|ML|MM|MN|MO|MQ|MR|MS|MÜ|MW|MY|MZ|N|NB|ND|NE|NF|NH|NI|NK|NM|NÖ|NP|NR|NT|NU|NW|NY|NZ|OA|OB|OC|OD|OE|OF|OG|OH|OK|OL|OP|OS|OZ|P|PA|PB|PE|PF|PI|PL|PM|PN|PR|PS|PW|PZ|R|RA|RC|RD|RE|RG|RH|RI|RL|RM|RN|RO|RP|RS|RT|RU|RV|RW|RZ|S|SB|SC|SE|SG|SI|SK|SL|SM|SN|SO|SP|SR|ST|SU|SW|SY|SZ|TE|TF|TG|TO|TP|TR|TS|TT|TÜ|ÜB|UE|UH|UL|UM|UN|V|VB|VG|VK|VR|VS|W|WA|WB|WE|WF|WI|WK|WL|WM|WN|WO|WR|WS|WT|WÜ|WW|WZ|Z|ZE|ZI|ZP|ZR|ZW|ZZ)[- ]?[A-Z]{1,2}[- ]?\d{1,4}|(ABG|ABI|AIB|AIC|ALF|ALZ|ANA|ANG|ANK|APD|ARN|ART|ASL|ASZ|AUR|AZE|BAD|BAR|BBG|BCH|BED|BER|BGD|BGL|BID|BIN|BIR|BIT|BIW|BKS|BLB|BLK|BNA|BOG|BOH|BOR|BOT|BRA|BRB|BRG|BRK|BRL|BRV|BSB|BSK|BTF|BÜD|BUL|BÜR|BÜS|BÜZ|CAS|CHA|CLP|CLZ|COC|COE|CUX|DAH|DAN|DAU|DBR|DEG|DEL|DGF|DIL|DIN|DIZ|DKB|DLG|DON|DUD|DÜW|EBE|EBN|EBS|ECK|EIC|EIL|EIN|EIS|EMD|EMS|ERB|ERH|ERK|ERZ|ESB|ESW|FDB|FDS|FEU|FFB|FKB|FLÖ|FOR|FRG|FRI|FRW|FTL|FÜS|GAN|GAP|GDB|GEL|GEO|GER|GHA|GHC|GLA|GMN|GNT|GOA|GOH|GRA|GRH|GRI|GRM|GRZ|GTH|GUB|GUN|GVM|HAB|HAL|HAM|HAS|HBN|HBS|HCH|HDH|HDL|HEB|HEF|HEI|HER|HET|HGN|HGW|HHM|HIG|HIP|HMÜ|HOG|HOH|HOL|HOM|HOR|HÖS|HOT|HRO|HSK|HST|HVL|HWI|IGB|ILL|JÜL|KEH|KEL|KEM|KIB|KLE|KLZ|KÖN|KÖT|KÖZ|KRU|KÜN|KUS|KYF|LAN|LAU|LBS|LBZ|LDK|LDS|LEO|LER|LEV|LIB|LIF|LIP|LÖB|LOS|LRO|LSZ|LÜN|LUP|LWL|MAB|MAI|MAK|MAL|MED|MEG|MEI|MEK|MEL|MER|MET|MGH|MGN|MHL|MIL|MKK|MOD|MOL|MON|MOS|MSE|MSH|MSP|MST|MTK|MTL|MÜB|MÜR|MYK|MZG|NAB|NAI|NAU|NDH|NEA|NEB|NEC|NEN|NES|NEW|NMB|NMS|NOH|NOL|NOM|NOR|NVP|NWM|OAL|OBB|OBG|OCH|OHA|ÖHR|OHV|OHZ|OPR|OSL|OVI|OVL|OVP|PAF|PAN|PAR|PCH|PEG|PIR|PLÖ|PRÜ|QFT|QLB|RDG|REG|REH|REI|RID|RIE|ROD|ROF|ROK|ROL|ROS|ROT|ROW|RSL|RÜD|RÜG|SAB|SAD|SAN|SAW|SBG|SBK|SCZ|SDH|SDL|SDT|SEB|SEE|SEF|SEL|SFB|SFT|SGH|SHA|SHG|SHK|SHL|SIG|SIM|SLE|SLF|SLK|SLN|SLS|SLÜ|SLZ|SMÜ|SOB|SOG|SOK|SÖM|SON|SPB|SPN|SRB|SRO|STA|STB|STD|STE|STL|SUL|SÜW|SWA|SZB|TBB|TDO|TET|TIR|TÖL|TUT|UEM|UER|UFF|USI|VAI|VEC|VER|VIB|VIE|VIT|VOH|WAF|WAK|WAN|WAR|WAT|WBS|WDA|WEL|WEN|WER|WES|WHV|WIL|WIS|WIT|WIZ|WLG|WMS|WND|WOB|WOH|WOL|WOR|WOS|WRN|WSF|WST|WSW|WTL|WTM|WUG|WÜM|WUN|WUR|WZL|ZEL|ZIG)[- ]?(([A-Z][- ]?\d{1,4})|([A-Z]{2}[- ]?\d{1,3})))[- ]?(E|H)?$/.test(str);
  4752. },
  4753. 'de-LI': function deLI(str) {
  4754. return /^FL[- ]?\d{1,5}[UZ]?$/.test(str);
  4755. },
  4756. 'en-IN': function enIN(str) {
  4757. return /^[A-Z]{2}[ -]?[0-9]{1,2}(?:[ -]?[A-Z])(?:[ -]?[A-Z]*)?[ -]?[0-9]{4}$/.test(str);
  4758. },
  4759. 'es-AR': function esAR(str) {
  4760. return /^(([A-Z]{2} ?[0-9]{3} ?[A-Z]{2})|([A-Z]{3} ?[0-9]{3}))$/.test(str);
  4761. },
  4762. 'fi-FI': function fiFI(str) {
  4763. return /^(?=.{4,7})(([A-Z]{1,3}|[0-9]{1,3})[\s-]?([A-Z]{1,3}|[0-9]{1,5}))$/.test(str);
  4764. },
  4765. 'hu-HU': function huHU(str) {
  4766. return /^((((?!AAA)(([A-NPRSTVZWXY]{1})([A-PR-Z]{1})([A-HJ-NPR-Z]))|(A[ABC]I)|A[ABC]O|A[A-W]Q|BPI|BPO|UCO|UDO|XAO)-(?!000)\d{3})|(M\d{6})|((CK|DT|CD|HC|H[ABEFIKLMNPRSTVX]|MA|OT|R[A-Z]) \d{2}-\d{2})|(CD \d{3}-\d{3})|(C-(C|X) \d{4})|(X-(A|B|C) \d{4})|(([EPVZ]-\d{5}))|(S A[A-Z]{2} \d{2})|(SP \d{2}-\d{2}))$/.test(str);
  4767. },
  4768. 'pt-BR': function ptBR(str) {
  4769. return /^[A-Z]{3}[ -]?[0-9][A-Z][0-9]{2}|[A-Z]{3}[ -]?[0-9]{4}$/.test(str);
  4770. },
  4771. 'pt-PT': function ptPT(str) {
  4772. return /^([A-Z]{2}|[0-9]{2})[ -·]?([A-Z]{2}|[0-9]{2})[ -·]?([A-Z]{2}|[0-9]{2})$/.test(str);
  4773. },
  4774. 'sq-AL': function sqAL(str) {
  4775. return /^[A-Z]{2}[- ]?((\d{3}[- ]?(([A-Z]{2})|T))|(R[- ]?\d{3}))$/.test(str);
  4776. },
  4777. 'sv-SE': function svSE(str) {
  4778. return /^[A-HJ-PR-UW-Z]{3} ?[\d]{2}[A-HJ-PR-UW-Z1-9]$|(^[A-ZÅÄÖ ]{2,7}$)/.test(str.trim());
  4779. },
  4780. 'en-PK': function enPK(str) {
  4781. return /(^[A-Z]{2}((\s|-){0,1})[0-9]{3,4}((\s|-)[0-9]{2}){0,1}$)|(^[A-Z]{3}((\s|-){0,1})[0-9]{3,4}((\s|-)[0-9]{2}){0,1}$)|(^[A-Z]{4}((\s|-){0,1})[0-9]{3,4}((\s|-)[0-9]{2}){0,1}$)|(^[A-Z]((\s|-){0,1})[0-9]{4}((\s|-)[0-9]{2}){0,1}$)/.test(str.trim());
  4782. }
  4783. };
  4784. function isLicensePlate(str, locale) {
  4785. assertString(str);
  4786. if (locale in validators$1) {
  4787. return validators$1[locale](str);
  4788. } else if (locale === 'any') {
  4789. for (var key in validators$1) {
  4790. /* eslint guard-for-in: 0 */
  4791. var validator = validators$1[key];
  4792. if (validator(str)) {
  4793. return true;
  4794. }
  4795. }
  4796. return false;
  4797. }
  4798. throw new Error("Invalid locale '".concat(locale, "'"));
  4799. }
  4800. var upperCaseRegex = /^[A-Z]$/;
  4801. var lowerCaseRegex = /^[a-z]$/;
  4802. var numberRegex = /^[0-9]$/;
  4803. var symbolRegex = /^[-#!$@£%^&*()_+|~=`{}\[\]:";'<>?,.\/\\ ]$/;
  4804. var defaultOptions$1 = {
  4805. minLength: 8,
  4806. minLowercase: 1,
  4807. minUppercase: 1,
  4808. minNumbers: 1,
  4809. minSymbols: 1,
  4810. returnScore: false,
  4811. pointsPerUnique: 1,
  4812. pointsPerRepeat: 0.5,
  4813. pointsForContainingLower: 10,
  4814. pointsForContainingUpper: 10,
  4815. pointsForContainingNumber: 10,
  4816. pointsForContainingSymbol: 10
  4817. };
  4818. /* Counts number of occurrences of each char in a string
  4819. * could be moved to util/ ?
  4820. */
  4821. function countChars(str) {
  4822. var result = {};
  4823. Array.from(str).forEach(function (_char) {
  4824. var curVal = result[_char];
  4825. if (curVal) {
  4826. result[_char] += 1;
  4827. } else {
  4828. result[_char] = 1;
  4829. }
  4830. });
  4831. return result;
  4832. }
  4833. /* Return information about a password */
  4834. function analyzePassword(password) {
  4835. var charMap = countChars(password);
  4836. var analysis = {
  4837. length: password.length,
  4838. uniqueChars: Object.keys(charMap).length,
  4839. uppercaseCount: 0,
  4840. lowercaseCount: 0,
  4841. numberCount: 0,
  4842. symbolCount: 0
  4843. };
  4844. Object.keys(charMap).forEach(function (_char2) {
  4845. /* istanbul ignore else */
  4846. if (upperCaseRegex.test(_char2)) {
  4847. analysis.uppercaseCount += charMap[_char2];
  4848. } else if (lowerCaseRegex.test(_char2)) {
  4849. analysis.lowercaseCount += charMap[_char2];
  4850. } else if (numberRegex.test(_char2)) {
  4851. analysis.numberCount += charMap[_char2];
  4852. } else if (symbolRegex.test(_char2)) {
  4853. analysis.symbolCount += charMap[_char2];
  4854. }
  4855. });
  4856. return analysis;
  4857. }
  4858. function scorePassword(analysis, scoringOptions) {
  4859. var points = 0;
  4860. points += analysis.uniqueChars * scoringOptions.pointsPerUnique;
  4861. points += (analysis.length - analysis.uniqueChars) * scoringOptions.pointsPerRepeat;
  4862. if (analysis.lowercaseCount > 0) {
  4863. points += scoringOptions.pointsForContainingLower;
  4864. }
  4865. if (analysis.uppercaseCount > 0) {
  4866. points += scoringOptions.pointsForContainingUpper;
  4867. }
  4868. if (analysis.numberCount > 0) {
  4869. points += scoringOptions.pointsForContainingNumber;
  4870. }
  4871. if (analysis.symbolCount > 0) {
  4872. points += scoringOptions.pointsForContainingSymbol;
  4873. }
  4874. return points;
  4875. }
  4876. function isStrongPassword(str) {
  4877. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  4878. assertString(str);
  4879. var analysis = analyzePassword(str);
  4880. options = merge(options || {}, defaultOptions$1);
  4881. if (options.returnScore) {
  4882. return scorePassword(analysis, options);
  4883. }
  4884. return analysis.length >= options.minLength && analysis.lowercaseCount >= options.minLowercase && analysis.uppercaseCount >= options.minUppercase && analysis.numberCount >= options.minNumbers && analysis.symbolCount >= options.minSymbols;
  4885. }
  4886. var AU = function AU(str) {
  4887. var match = str.match(/^(AU)?(\d{11})$/);
  4888. if (!match) {
  4889. return false;
  4890. }
  4891. // @see {@link https://abr.business.gov.au/Help/AbnFormat}
  4892. var weights = [10, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19];
  4893. str = str.replace(/^AU/, '');
  4894. var ABN = (parseInt(str.slice(0, 1), 10) - 1).toString() + str.slice(1);
  4895. var total = 0;
  4896. for (var i = 0; i < 11; i++) {
  4897. total += weights[i] * ABN.charAt(i);
  4898. }
  4899. return total !== 0 && total % 89 === 0;
  4900. };
  4901. var CH = function CH(str) {
  4902. // @see {@link https://www.ech.ch/de/ech/ech-0097/5.2.0}
  4903. var hasValidCheckNumber = function hasValidCheckNumber(digits) {
  4904. var lastDigit = digits.pop(); // used as check number
  4905. var weights = [5, 4, 3, 2, 7, 6, 5, 4];
  4906. var calculatedCheckNumber = (11 - digits.reduce(function (acc, el, idx) {
  4907. return acc + el * weights[idx];
  4908. }, 0) % 11) % 11;
  4909. return lastDigit === calculatedCheckNumber;
  4910. };
  4911. // @see {@link https://www.estv.admin.ch/estv/de/home/mehrwertsteuer/uid/mwst-uid-nummer.html}
  4912. return /^(CHE[- ]?)?(\d{9}|(\d{3}\.\d{3}\.\d{3})|(\d{3} \d{3} \d{3})) ?(TVA|MWST|IVA)?$/.test(str) && hasValidCheckNumber(str.match(/\d/g).map(function (el) {
  4913. return +el;
  4914. }));
  4915. };
  4916. var PT = function PT(str) {
  4917. var match = str.match(/^(PT)?(\d{9})$/);
  4918. if (!match) {
  4919. return false;
  4920. }
  4921. var tin = match[2];
  4922. var checksum = 11 - reverseMultiplyAndSum(tin.split('').slice(0, 8).map(function (a) {
  4923. return parseInt(a, 10);
  4924. }), 9) % 11;
  4925. if (checksum > 9) {
  4926. return parseInt(tin[8], 10) === 0;
  4927. }
  4928. return checksum === parseInt(tin[8], 10);
  4929. };
  4930. var vatMatchers = {
  4931. /**
  4932. * European Union VAT identification numbers
  4933. */
  4934. AT: function AT(str) {
  4935. return /^(AT)?U\d{8}$/.test(str);
  4936. },
  4937. BE: function BE(str) {
  4938. return /^(BE)?\d{10}$/.test(str);
  4939. },
  4940. BG: function BG(str) {
  4941. return /^(BG)?\d{9,10}$/.test(str);
  4942. },
  4943. HR: function HR(str) {
  4944. return /^(HR)?\d{11}$/.test(str);
  4945. },
  4946. CY: function CY(str) {
  4947. return /^(CY)?\w{9}$/.test(str);
  4948. },
  4949. CZ: function CZ(str) {
  4950. return /^(CZ)?\d{8,10}$/.test(str);
  4951. },
  4952. DK: function DK(str) {
  4953. return /^(DK)?\d{8}$/.test(str);
  4954. },
  4955. EE: function EE(str) {
  4956. return /^(EE)?\d{9}$/.test(str);
  4957. },
  4958. FI: function FI(str) {
  4959. return /^(FI)?\d{8}$/.test(str);
  4960. },
  4961. FR: function FR(str) {
  4962. return /^(FR)?\w{2}\d{9}$/.test(str);
  4963. },
  4964. DE: function DE(str) {
  4965. return /^(DE)?\d{9}$/.test(str);
  4966. },
  4967. EL: function EL(str) {
  4968. return /^(EL)?\d{9}$/.test(str);
  4969. },
  4970. HU: function HU(str) {
  4971. return /^(HU)?\d{8}$/.test(str);
  4972. },
  4973. IE: function IE(str) {
  4974. return /^(IE)?\d{7}\w{1}(W)?$/.test(str);
  4975. },
  4976. IT: function IT(str) {
  4977. return /^(IT)?\d{11}$/.test(str);
  4978. },
  4979. LV: function LV(str) {
  4980. return /^(LV)?\d{11}$/.test(str);
  4981. },
  4982. LT: function LT(str) {
  4983. return /^(LT)?\d{9,12}$/.test(str);
  4984. },
  4985. LU: function LU(str) {
  4986. return /^(LU)?\d{8}$/.test(str);
  4987. },
  4988. MT: function MT(str) {
  4989. return /^(MT)?\d{8}$/.test(str);
  4990. },
  4991. NL: function NL(str) {
  4992. return /^(NL)?\d{9}B\d{2}$/.test(str);
  4993. },
  4994. PL: function PL(str) {
  4995. return /^(PL)?(\d{10}|(\d{3}-\d{3}-\d{2}-\d{2})|(\d{3}-\d{2}-\d{2}-\d{3}))$/.test(str);
  4996. },
  4997. PT: PT,
  4998. RO: function RO(str) {
  4999. return /^(RO)?\d{2,10}$/.test(str);
  5000. },
  5001. SK: function SK(str) {
  5002. return /^(SK)?\d{10}$/.test(str);
  5003. },
  5004. SI: function SI(str) {
  5005. return /^(SI)?\d{8}$/.test(str);
  5006. },
  5007. ES: function ES(str) {
  5008. return /^(ES)?\w\d{7}[A-Z]$/.test(str);
  5009. },
  5010. SE: function SE(str) {
  5011. return /^(SE)?\d{12}$/.test(str);
  5012. },
  5013. /**
  5014. * VAT numbers of non-EU countries
  5015. */
  5016. AL: function AL(str) {
  5017. return /^(AL)?\w{9}[A-Z]$/.test(str);
  5018. },
  5019. MK: function MK(str) {
  5020. return /^(MK)?\d{13}$/.test(str);
  5021. },
  5022. AU: AU,
  5023. BY: function BY(str) {
  5024. return /^(УНП )?\d{9}$/.test(str);
  5025. },
  5026. CA: function CA(str) {
  5027. return /^(CA)?\d{9}$/.test(str);
  5028. },
  5029. IS: function IS(str) {
  5030. return /^(IS)?\d{5,6}$/.test(str);
  5031. },
  5032. IN: function IN(str) {
  5033. return /^(IN)?\d{15}$/.test(str);
  5034. },
  5035. ID: function ID(str) {
  5036. return /^(ID)?(\d{15}|(\d{2}.\d{3}.\d{3}.\d{1}-\d{3}.\d{3}))$/.test(str);
  5037. },
  5038. IL: function IL(str) {
  5039. return /^(IL)?\d{9}$/.test(str);
  5040. },
  5041. KZ: function KZ(str) {
  5042. return /^(KZ)?\d{12}$/.test(str);
  5043. },
  5044. NZ: function NZ(str) {
  5045. return /^(NZ)?\d{9}$/.test(str);
  5046. },
  5047. NG: function NG(str) {
  5048. return /^(NG)?(\d{12}|(\d{8}-\d{4}))$/.test(str);
  5049. },
  5050. NO: function NO(str) {
  5051. return /^(NO)?\d{9}MVA$/.test(str);
  5052. },
  5053. PH: function PH(str) {
  5054. return /^(PH)?(\d{12}|\d{3} \d{3} \d{3} \d{3})$/.test(str);
  5055. },
  5056. RU: function RU(str) {
  5057. return /^(RU)?(\d{10}|\d{12})$/.test(str);
  5058. },
  5059. SM: function SM(str) {
  5060. return /^(SM)?\d{5}$/.test(str);
  5061. },
  5062. SA: function SA(str) {
  5063. return /^(SA)?\d{15}$/.test(str);
  5064. },
  5065. RS: function RS(str) {
  5066. return /^(RS)?\d{9}$/.test(str);
  5067. },
  5068. CH: CH,
  5069. TR: function TR(str) {
  5070. return /^(TR)?\d{10}$/.test(str);
  5071. },
  5072. UA: function UA(str) {
  5073. return /^(UA)?\d{12}$/.test(str);
  5074. },
  5075. GB: function GB(str) {
  5076. return /^GB((\d{3} \d{4} ([0-8][0-9]|9[0-6]))|(\d{9} \d{3})|(((GD[0-4])|(HA[5-9]))[0-9]{2}))$/.test(str);
  5077. },
  5078. UZ: function UZ(str) {
  5079. return /^(UZ)?\d{9}$/.test(str);
  5080. },
  5081. /**
  5082. * VAT numbers of Latin American countries
  5083. */
  5084. AR: function AR(str) {
  5085. return /^(AR)?\d{11}$/.test(str);
  5086. },
  5087. BO: function BO(str) {
  5088. return /^(BO)?\d{7}$/.test(str);
  5089. },
  5090. BR: function BR(str) {
  5091. return /^(BR)?((\d{2}.\d{3}.\d{3}\/\d{4}-\d{2})|(\d{3}.\d{3}.\d{3}-\d{2}))$/.test(str);
  5092. },
  5093. CL: function CL(str) {
  5094. return /^(CL)?\d{8}-\d{1}$/.test(str);
  5095. },
  5096. CO: function CO(str) {
  5097. return /^(CO)?\d{10}$/.test(str);
  5098. },
  5099. CR: function CR(str) {
  5100. return /^(CR)?\d{9,12}$/.test(str);
  5101. },
  5102. EC: function EC(str) {
  5103. return /^(EC)?\d{13}$/.test(str);
  5104. },
  5105. SV: function SV(str) {
  5106. return /^(SV)?\d{4}-\d{6}-\d{3}-\d{1}$/.test(str);
  5107. },
  5108. GT: function GT(str) {
  5109. return /^(GT)?\d{7}-\d{1}$/.test(str);
  5110. },
  5111. HN: function HN(str) {
  5112. return /^(HN)?$/.test(str);
  5113. },
  5114. MX: function MX(str) {
  5115. return /^(MX)?\w{3,4}\d{6}\w{3}$/.test(str);
  5116. },
  5117. NI: function NI(str) {
  5118. return /^(NI)?\d{3}-\d{6}-\d{4}\w{1}$/.test(str);
  5119. },
  5120. PA: function PA(str) {
  5121. return /^(PA)?$/.test(str);
  5122. },
  5123. PY: function PY(str) {
  5124. return /^(PY)?\d{6,8}-\d{1}$/.test(str);
  5125. },
  5126. PE: function PE(str) {
  5127. return /^(PE)?\d{11}$/.test(str);
  5128. },
  5129. DO: function DO(str) {
  5130. return /^(DO)?(\d{11}|(\d{3}-\d{7}-\d{1})|[1,4,5]{1}\d{8}|([1,4,5]{1})-\d{2}-\d{5}-\d{1})$/.test(str);
  5131. },
  5132. UY: function UY(str) {
  5133. return /^(UY)?\d{12}$/.test(str);
  5134. },
  5135. VE: function VE(str) {
  5136. return /^(VE)?[J,G,V,E]{1}-(\d{9}|(\d{8}-\d{1}))$/.test(str);
  5137. }
  5138. };
  5139. function isVAT(str, countryCode) {
  5140. assertString(str);
  5141. assertString(countryCode);
  5142. if (countryCode in vatMatchers) {
  5143. return vatMatchers[countryCode](str);
  5144. }
  5145. throw new Error("Invalid country code: '".concat(countryCode, "'"));
  5146. }
  5147. var version = '13.12.0';
  5148. var validator = {
  5149. version: version,
  5150. toDate: toDate,
  5151. toFloat: toFloat,
  5152. toInt: toInt,
  5153. toBoolean: toBoolean,
  5154. equals: equals,
  5155. contains: contains,
  5156. matches: matches,
  5157. isEmail: isEmail,
  5158. isURL: isURL,
  5159. isMACAddress: isMACAddress,
  5160. isIP: isIP,
  5161. isIPRange: isIPRange,
  5162. isFQDN: isFQDN,
  5163. isBoolean: isBoolean,
  5164. isIBAN: isIBAN,
  5165. isBIC: isBIC,
  5166. isAbaRouting: isAbaRouting,
  5167. isAlpha: isAlpha,
  5168. isAlphaLocales: locales$1,
  5169. isAlphanumeric: isAlphanumeric,
  5170. isAlphanumericLocales: locales$2,
  5171. isNumeric: isNumeric,
  5172. isPassportNumber: isPassportNumber,
  5173. isPort: isPort,
  5174. isLowercase: isLowercase,
  5175. isUppercase: isUppercase,
  5176. isAscii: isAscii,
  5177. isFullWidth: isFullWidth,
  5178. isHalfWidth: isHalfWidth,
  5179. isVariableWidth: isVariableWidth,
  5180. isMultibyte: isMultibyte,
  5181. isSemVer: isSemVer,
  5182. isSurrogatePair: isSurrogatePair,
  5183. isInt: isInt,
  5184. isIMEI: isIMEI,
  5185. isFloat: isFloat,
  5186. isFloatLocales: locales,
  5187. isDecimal: isDecimal,
  5188. isHexadecimal: isHexadecimal,
  5189. isOctal: isOctal,
  5190. isDivisibleBy: isDivisibleBy,
  5191. isHexColor: isHexColor,
  5192. isRgbColor: isRgbColor,
  5193. isHSL: isHSL,
  5194. isISRC: isISRC,
  5195. isMD5: isMD5,
  5196. isHash: isHash,
  5197. isJWT: isJWT,
  5198. isJSON: isJSON,
  5199. isEmpty: isEmpty,
  5200. isLength: isLength,
  5201. isLocale: isLocale,
  5202. isByteLength: isByteLength,
  5203. isUUID: isUUID,
  5204. isMongoId: isMongoId,
  5205. isAfter: isAfter,
  5206. isBefore: isBefore,
  5207. isIn: isIn,
  5208. isLuhnNumber: isLuhnNumber,
  5209. isCreditCard: isCreditCard,
  5210. isIdentityCard: isIdentityCard,
  5211. isEAN: isEAN,
  5212. isISIN: isISIN,
  5213. isISBN: isISBN,
  5214. isISSN: isISSN,
  5215. isMobilePhone: isMobilePhone,
  5216. isMobilePhoneLocales: locales$4,
  5217. isPostalCode: isPostalCode,
  5218. isPostalCodeLocales: locales$5,
  5219. isEthereumAddress: isEthereumAddress,
  5220. isCurrency: isCurrency,
  5221. isBtcAddress: isBtcAddress,
  5222. isISO6346: isISO6346,
  5223. isFreightContainerID: isFreightContainerID,
  5224. isISO6391: isISO6391,
  5225. isISO8601: isISO8601,
  5226. isRFC3339: isRFC3339,
  5227. isISO31661Alpha2: isISO31661Alpha2,
  5228. isISO31661Alpha3: isISO31661Alpha3,
  5229. isISO4217: isISO4217,
  5230. isBase32: isBase32,
  5231. isBase58: isBase58,
  5232. isBase64: isBase64,
  5233. isDataURI: isDataURI,
  5234. isMagnetURI: isMagnetURI,
  5235. isMailtoURI: isMailtoURI,
  5236. isMimeType: isMimeType,
  5237. isLatLong: isLatLong,
  5238. ltrim: ltrim,
  5239. rtrim: rtrim,
  5240. trim: trim,
  5241. escape: escape,
  5242. unescape: unescape,
  5243. stripLow: stripLow,
  5244. whitelist: whitelist,
  5245. blacklist: blacklist$1,
  5246. isWhitelisted: isWhitelisted,
  5247. normalizeEmail: normalizeEmail,
  5248. toString: toString,
  5249. isSlug: isSlug,
  5250. isStrongPassword: isStrongPassword,
  5251. isTaxID: isTaxID,
  5252. isDate: isDate,
  5253. isTime: isTime,
  5254. isLicensePlate: isLicensePlate,
  5255. isVAT: isVAT,
  5256. ibanLocales: locales$3
  5257. };
  5258. return validator;
  5259. })));