ZSchema-browser-test.js 911 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407
  1. (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
  2. 'use strict'
  3. exports.byteLength = byteLength
  4. exports.toByteArray = toByteArray
  5. exports.fromByteArray = fromByteArray
  6. var lookup = []
  7. var revLookup = []
  8. var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array
  9. var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
  10. for (var i = 0, len = code.length; i < len; ++i) {
  11. lookup[i] = code[i]
  12. revLookup[code.charCodeAt(i)] = i
  13. }
  14. // Support decoding URL-safe base64 strings, as Node.js does.
  15. // See: https://en.wikipedia.org/wiki/Base64#URL_applications
  16. revLookup['-'.charCodeAt(0)] = 62
  17. revLookup['_'.charCodeAt(0)] = 63
  18. function getLens (b64) {
  19. var len = b64.length
  20. if (len % 4 > 0) {
  21. throw new Error('Invalid string. Length must be a multiple of 4')
  22. }
  23. // Trim off extra bytes after placeholder bytes are found
  24. // See: https://github.com/beatgammit/base64-js/issues/42
  25. var validLen = b64.indexOf('=')
  26. if (validLen === -1) validLen = len
  27. var placeHoldersLen = validLen === len
  28. ? 0
  29. : 4 - (validLen % 4)
  30. return [validLen, placeHoldersLen]
  31. }
  32. // base64 is 4/3 + up to two characters of the original data
  33. function byteLength (b64) {
  34. var lens = getLens(b64)
  35. var validLen = lens[0]
  36. var placeHoldersLen = lens[1]
  37. return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
  38. }
  39. function _byteLength (b64, validLen, placeHoldersLen) {
  40. return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
  41. }
  42. function toByteArray (b64) {
  43. var tmp
  44. var lens = getLens(b64)
  45. var validLen = lens[0]
  46. var placeHoldersLen = lens[1]
  47. var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen))
  48. var curByte = 0
  49. // if there are placeholders, only get up to the last complete 4 chars
  50. var len = placeHoldersLen > 0
  51. ? validLen - 4
  52. : validLen
  53. var i
  54. for (i = 0; i < len; i += 4) {
  55. tmp =
  56. (revLookup[b64.charCodeAt(i)] << 18) |
  57. (revLookup[b64.charCodeAt(i + 1)] << 12) |
  58. (revLookup[b64.charCodeAt(i + 2)] << 6) |
  59. revLookup[b64.charCodeAt(i + 3)]
  60. arr[curByte++] = (tmp >> 16) & 0xFF
  61. arr[curByte++] = (tmp >> 8) & 0xFF
  62. arr[curByte++] = tmp & 0xFF
  63. }
  64. if (placeHoldersLen === 2) {
  65. tmp =
  66. (revLookup[b64.charCodeAt(i)] << 2) |
  67. (revLookup[b64.charCodeAt(i + 1)] >> 4)
  68. arr[curByte++] = tmp & 0xFF
  69. }
  70. if (placeHoldersLen === 1) {
  71. tmp =
  72. (revLookup[b64.charCodeAt(i)] << 10) |
  73. (revLookup[b64.charCodeAt(i + 1)] << 4) |
  74. (revLookup[b64.charCodeAt(i + 2)] >> 2)
  75. arr[curByte++] = (tmp >> 8) & 0xFF
  76. arr[curByte++] = tmp & 0xFF
  77. }
  78. return arr
  79. }
  80. function tripletToBase64 (num) {
  81. return lookup[num >> 18 & 0x3F] +
  82. lookup[num >> 12 & 0x3F] +
  83. lookup[num >> 6 & 0x3F] +
  84. lookup[num & 0x3F]
  85. }
  86. function encodeChunk (uint8, start, end) {
  87. var tmp
  88. var output = []
  89. for (var i = start; i < end; i += 3) {
  90. tmp =
  91. ((uint8[i] << 16) & 0xFF0000) +
  92. ((uint8[i + 1] << 8) & 0xFF00) +
  93. (uint8[i + 2] & 0xFF)
  94. output.push(tripletToBase64(tmp))
  95. }
  96. return output.join('')
  97. }
  98. function fromByteArray (uint8) {
  99. var tmp
  100. var len = uint8.length
  101. var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes
  102. var parts = []
  103. var maxChunkLength = 16383 // must be multiple of 3
  104. // go through the array every three bytes, we'll deal with trailing stuff later
  105. for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
  106. parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)))
  107. }
  108. // pad the end with zeros, but make sure to not forget the extra bytes
  109. if (extraBytes === 1) {
  110. tmp = uint8[len - 1]
  111. parts.push(
  112. lookup[tmp >> 2] +
  113. lookup[(tmp << 4) & 0x3F] +
  114. '=='
  115. )
  116. } else if (extraBytes === 2) {
  117. tmp = (uint8[len - 2] << 8) + uint8[len - 1]
  118. parts.push(
  119. lookup[tmp >> 10] +
  120. lookup[(tmp >> 4) & 0x3F] +
  121. lookup[(tmp << 2) & 0x3F] +
  122. '='
  123. )
  124. }
  125. return parts.join('')
  126. }
  127. },{}],2:[function(require,module,exports){
  128. },{}],3:[function(require,module,exports){
  129. (function (Buffer){(function (){
  130. /*!
  131. * The buffer module from node.js, for the browser.
  132. *
  133. * @author Feross Aboukhadijeh <https://feross.org>
  134. * @license MIT
  135. */
  136. /* eslint-disable no-proto */
  137. 'use strict'
  138. var base64 = require('base64-js')
  139. var ieee754 = require('ieee754')
  140. exports.Buffer = Buffer
  141. exports.SlowBuffer = SlowBuffer
  142. exports.INSPECT_MAX_BYTES = 50
  143. var K_MAX_LENGTH = 0x7fffffff
  144. exports.kMaxLength = K_MAX_LENGTH
  145. /**
  146. * If `Buffer.TYPED_ARRAY_SUPPORT`:
  147. * === true Use Uint8Array implementation (fastest)
  148. * === false Print warning and recommend using `buffer` v4.x which has an Object
  149. * implementation (most compatible, even IE6)
  150. *
  151. * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
  152. * Opera 11.6+, iOS 4.2+.
  153. *
  154. * We report that the browser does not support typed arrays if the are not subclassable
  155. * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array`
  156. * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support
  157. * for __proto__ and has a buggy typed array implementation.
  158. */
  159. Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport()
  160. if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' &&
  161. typeof console.error === 'function') {
  162. console.error(
  163. 'This browser lacks typed array (Uint8Array) support which is required by ' +
  164. '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.'
  165. )
  166. }
  167. function typedArraySupport () {
  168. // Can typed array instances can be augmented?
  169. try {
  170. var arr = new Uint8Array(1)
  171. arr.__proto__ = { __proto__: Uint8Array.prototype, foo: function () { return 42 } }
  172. return arr.foo() === 42
  173. } catch (e) {
  174. return false
  175. }
  176. }
  177. Object.defineProperty(Buffer.prototype, 'parent', {
  178. enumerable: true,
  179. get: function () {
  180. if (!Buffer.isBuffer(this)) return undefined
  181. return this.buffer
  182. }
  183. })
  184. Object.defineProperty(Buffer.prototype, 'offset', {
  185. enumerable: true,
  186. get: function () {
  187. if (!Buffer.isBuffer(this)) return undefined
  188. return this.byteOffset
  189. }
  190. })
  191. function createBuffer (length) {
  192. if (length > K_MAX_LENGTH) {
  193. throw new RangeError('The value "' + length + '" is invalid for option "size"')
  194. }
  195. // Return an augmented `Uint8Array` instance
  196. var buf = new Uint8Array(length)
  197. buf.__proto__ = Buffer.prototype
  198. return buf
  199. }
  200. /**
  201. * The Buffer constructor returns instances of `Uint8Array` that have their
  202. * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
  203. * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
  204. * and the `Uint8Array` methods. Square bracket notation works as expected -- it
  205. * returns a single octet.
  206. *
  207. * The `Uint8Array` prototype remains unmodified.
  208. */
  209. function Buffer (arg, encodingOrOffset, length) {
  210. // Common case.
  211. if (typeof arg === 'number') {
  212. if (typeof encodingOrOffset === 'string') {
  213. throw new TypeError(
  214. 'The "string" argument must be of type string. Received type number'
  215. )
  216. }
  217. return allocUnsafe(arg)
  218. }
  219. return from(arg, encodingOrOffset, length)
  220. }
  221. // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
  222. if (typeof Symbol !== 'undefined' && Symbol.species != null &&
  223. Buffer[Symbol.species] === Buffer) {
  224. Object.defineProperty(Buffer, Symbol.species, {
  225. value: null,
  226. configurable: true,
  227. enumerable: false,
  228. writable: false
  229. })
  230. }
  231. Buffer.poolSize = 8192 // not used by this implementation
  232. function from (value, encodingOrOffset, length) {
  233. if (typeof value === 'string') {
  234. return fromString(value, encodingOrOffset)
  235. }
  236. if (ArrayBuffer.isView(value)) {
  237. return fromArrayLike(value)
  238. }
  239. if (value == null) {
  240. throw TypeError(
  241. 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
  242. 'or Array-like Object. Received type ' + (typeof value)
  243. )
  244. }
  245. if (isInstance(value, ArrayBuffer) ||
  246. (value && isInstance(value.buffer, ArrayBuffer))) {
  247. return fromArrayBuffer(value, encodingOrOffset, length)
  248. }
  249. if (typeof value === 'number') {
  250. throw new TypeError(
  251. 'The "value" argument must not be of type number. Received type number'
  252. )
  253. }
  254. var valueOf = value.valueOf && value.valueOf()
  255. if (valueOf != null && valueOf !== value) {
  256. return Buffer.from(valueOf, encodingOrOffset, length)
  257. }
  258. var b = fromObject(value)
  259. if (b) return b
  260. if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null &&
  261. typeof value[Symbol.toPrimitive] === 'function') {
  262. return Buffer.from(
  263. value[Symbol.toPrimitive]('string'), encodingOrOffset, length
  264. )
  265. }
  266. throw new TypeError(
  267. 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
  268. 'or Array-like Object. Received type ' + (typeof value)
  269. )
  270. }
  271. /**
  272. * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
  273. * if value is a number.
  274. * Buffer.from(str[, encoding])
  275. * Buffer.from(array)
  276. * Buffer.from(buffer)
  277. * Buffer.from(arrayBuffer[, byteOffset[, length]])
  278. **/
  279. Buffer.from = function (value, encodingOrOffset, length) {
  280. return from(value, encodingOrOffset, length)
  281. }
  282. // Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
  283. // https://github.com/feross/buffer/pull/148
  284. Buffer.prototype.__proto__ = Uint8Array.prototype
  285. Buffer.__proto__ = Uint8Array
  286. function assertSize (size) {
  287. if (typeof size !== 'number') {
  288. throw new TypeError('"size" argument must be of type number')
  289. } else if (size < 0) {
  290. throw new RangeError('The value "' + size + '" is invalid for option "size"')
  291. }
  292. }
  293. function alloc (size, fill, encoding) {
  294. assertSize(size)
  295. if (size <= 0) {
  296. return createBuffer(size)
  297. }
  298. if (fill !== undefined) {
  299. // Only pay attention to encoding if it's a string. This
  300. // prevents accidentally sending in a number that would
  301. // be interpretted as a start offset.
  302. return typeof encoding === 'string'
  303. ? createBuffer(size).fill(fill, encoding)
  304. : createBuffer(size).fill(fill)
  305. }
  306. return createBuffer(size)
  307. }
  308. /**
  309. * Creates a new filled Buffer instance.
  310. * alloc(size[, fill[, encoding]])
  311. **/
  312. Buffer.alloc = function (size, fill, encoding) {
  313. return alloc(size, fill, encoding)
  314. }
  315. function allocUnsafe (size) {
  316. assertSize(size)
  317. return createBuffer(size < 0 ? 0 : checked(size) | 0)
  318. }
  319. /**
  320. * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
  321. * */
  322. Buffer.allocUnsafe = function (size) {
  323. return allocUnsafe(size)
  324. }
  325. /**
  326. * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
  327. */
  328. Buffer.allocUnsafeSlow = function (size) {
  329. return allocUnsafe(size)
  330. }
  331. function fromString (string, encoding) {
  332. if (typeof encoding !== 'string' || encoding === '') {
  333. encoding = 'utf8'
  334. }
  335. if (!Buffer.isEncoding(encoding)) {
  336. throw new TypeError('Unknown encoding: ' + encoding)
  337. }
  338. var length = byteLength(string, encoding) | 0
  339. var buf = createBuffer(length)
  340. var actual = buf.write(string, encoding)
  341. if (actual !== length) {
  342. // Writing a hex string, for example, that contains invalid characters will
  343. // cause everything after the first invalid character to be ignored. (e.g.
  344. // 'abxxcd' will be treated as 'ab')
  345. buf = buf.slice(0, actual)
  346. }
  347. return buf
  348. }
  349. function fromArrayLike (array) {
  350. var length = array.length < 0 ? 0 : checked(array.length) | 0
  351. var buf = createBuffer(length)
  352. for (var i = 0; i < length; i += 1) {
  353. buf[i] = array[i] & 255
  354. }
  355. return buf
  356. }
  357. function fromArrayBuffer (array, byteOffset, length) {
  358. if (byteOffset < 0 || array.byteLength < byteOffset) {
  359. throw new RangeError('"offset" is outside of buffer bounds')
  360. }
  361. if (array.byteLength < byteOffset + (length || 0)) {
  362. throw new RangeError('"length" is outside of buffer bounds')
  363. }
  364. var buf
  365. if (byteOffset === undefined && length === undefined) {
  366. buf = new Uint8Array(array)
  367. } else if (length === undefined) {
  368. buf = new Uint8Array(array, byteOffset)
  369. } else {
  370. buf = new Uint8Array(array, byteOffset, length)
  371. }
  372. // Return an augmented `Uint8Array` instance
  373. buf.__proto__ = Buffer.prototype
  374. return buf
  375. }
  376. function fromObject (obj) {
  377. if (Buffer.isBuffer(obj)) {
  378. var len = checked(obj.length) | 0
  379. var buf = createBuffer(len)
  380. if (buf.length === 0) {
  381. return buf
  382. }
  383. obj.copy(buf, 0, 0, len)
  384. return buf
  385. }
  386. if (obj.length !== undefined) {
  387. if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
  388. return createBuffer(0)
  389. }
  390. return fromArrayLike(obj)
  391. }
  392. if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
  393. return fromArrayLike(obj.data)
  394. }
  395. }
  396. function checked (length) {
  397. // Note: cannot use `length < K_MAX_LENGTH` here because that fails when
  398. // length is NaN (which is otherwise coerced to zero.)
  399. if (length >= K_MAX_LENGTH) {
  400. throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
  401. 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes')
  402. }
  403. return length | 0
  404. }
  405. function SlowBuffer (length) {
  406. if (+length != length) { // eslint-disable-line eqeqeq
  407. length = 0
  408. }
  409. return Buffer.alloc(+length)
  410. }
  411. Buffer.isBuffer = function isBuffer (b) {
  412. return b != null && b._isBuffer === true &&
  413. b !== Buffer.prototype // so Buffer.isBuffer(Buffer.prototype) will be false
  414. }
  415. Buffer.compare = function compare (a, b) {
  416. if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength)
  417. if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength)
  418. if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
  419. throw new TypeError(
  420. 'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'
  421. )
  422. }
  423. if (a === b) return 0
  424. var x = a.length
  425. var y = b.length
  426. for (var i = 0, len = Math.min(x, y); i < len; ++i) {
  427. if (a[i] !== b[i]) {
  428. x = a[i]
  429. y = b[i]
  430. break
  431. }
  432. }
  433. if (x < y) return -1
  434. if (y < x) return 1
  435. return 0
  436. }
  437. Buffer.isEncoding = function isEncoding (encoding) {
  438. switch (String(encoding).toLowerCase()) {
  439. case 'hex':
  440. case 'utf8':
  441. case 'utf-8':
  442. case 'ascii':
  443. case 'latin1':
  444. case 'binary':
  445. case 'base64':
  446. case 'ucs2':
  447. case 'ucs-2':
  448. case 'utf16le':
  449. case 'utf-16le':
  450. return true
  451. default:
  452. return false
  453. }
  454. }
  455. Buffer.concat = function concat (list, length) {
  456. if (!Array.isArray(list)) {
  457. throw new TypeError('"list" argument must be an Array of Buffers')
  458. }
  459. if (list.length === 0) {
  460. return Buffer.alloc(0)
  461. }
  462. var i
  463. if (length === undefined) {
  464. length = 0
  465. for (i = 0; i < list.length; ++i) {
  466. length += list[i].length
  467. }
  468. }
  469. var buffer = Buffer.allocUnsafe(length)
  470. var pos = 0
  471. for (i = 0; i < list.length; ++i) {
  472. var buf = list[i]
  473. if (isInstance(buf, Uint8Array)) {
  474. buf = Buffer.from(buf)
  475. }
  476. if (!Buffer.isBuffer(buf)) {
  477. throw new TypeError('"list" argument must be an Array of Buffers')
  478. }
  479. buf.copy(buffer, pos)
  480. pos += buf.length
  481. }
  482. return buffer
  483. }
  484. function byteLength (string, encoding) {
  485. if (Buffer.isBuffer(string)) {
  486. return string.length
  487. }
  488. if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
  489. return string.byteLength
  490. }
  491. if (typeof string !== 'string') {
  492. throw new TypeError(
  493. 'The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' +
  494. 'Received type ' + typeof string
  495. )
  496. }
  497. var len = string.length
  498. var mustMatch = (arguments.length > 2 && arguments[2] === true)
  499. if (!mustMatch && len === 0) return 0
  500. // Use a for loop to avoid recursion
  501. var loweredCase = false
  502. for (;;) {
  503. switch (encoding) {
  504. case 'ascii':
  505. case 'latin1':
  506. case 'binary':
  507. return len
  508. case 'utf8':
  509. case 'utf-8':
  510. return utf8ToBytes(string).length
  511. case 'ucs2':
  512. case 'ucs-2':
  513. case 'utf16le':
  514. case 'utf-16le':
  515. return len * 2
  516. case 'hex':
  517. return len >>> 1
  518. case 'base64':
  519. return base64ToBytes(string).length
  520. default:
  521. if (loweredCase) {
  522. return mustMatch ? -1 : utf8ToBytes(string).length // assume utf8
  523. }
  524. encoding = ('' + encoding).toLowerCase()
  525. loweredCase = true
  526. }
  527. }
  528. }
  529. Buffer.byteLength = byteLength
  530. function slowToString (encoding, start, end) {
  531. var loweredCase = false
  532. // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
  533. // property of a typed array.
  534. // This behaves neither like String nor Uint8Array in that we set start/end
  535. // to their upper/lower bounds if the value passed is out of range.
  536. // undefined is handled specially as per ECMA-262 6th Edition,
  537. // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
  538. if (start === undefined || start < 0) {
  539. start = 0
  540. }
  541. // Return early if start > this.length. Done here to prevent potential uint32
  542. // coercion fail below.
  543. if (start > this.length) {
  544. return ''
  545. }
  546. if (end === undefined || end > this.length) {
  547. end = this.length
  548. }
  549. if (end <= 0) {
  550. return ''
  551. }
  552. // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
  553. end >>>= 0
  554. start >>>= 0
  555. if (end <= start) {
  556. return ''
  557. }
  558. if (!encoding) encoding = 'utf8'
  559. while (true) {
  560. switch (encoding) {
  561. case 'hex':
  562. return hexSlice(this, start, end)
  563. case 'utf8':
  564. case 'utf-8':
  565. return utf8Slice(this, start, end)
  566. case 'ascii':
  567. return asciiSlice(this, start, end)
  568. case 'latin1':
  569. case 'binary':
  570. return latin1Slice(this, start, end)
  571. case 'base64':
  572. return base64Slice(this, start, end)
  573. case 'ucs2':
  574. case 'ucs-2':
  575. case 'utf16le':
  576. case 'utf-16le':
  577. return utf16leSlice(this, start, end)
  578. default:
  579. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  580. encoding = (encoding + '').toLowerCase()
  581. loweredCase = true
  582. }
  583. }
  584. }
  585. // This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)
  586. // to detect a Buffer instance. It's not possible to use `instanceof Buffer`
  587. // reliably in a browserify context because there could be multiple different
  588. // copies of the 'buffer' package in use. This method works even for Buffer
  589. // instances that were created from another copy of the `buffer` package.
  590. // See: https://github.com/feross/buffer/issues/154
  591. Buffer.prototype._isBuffer = true
  592. function swap (b, n, m) {
  593. var i = b[n]
  594. b[n] = b[m]
  595. b[m] = i
  596. }
  597. Buffer.prototype.swap16 = function swap16 () {
  598. var len = this.length
  599. if (len % 2 !== 0) {
  600. throw new RangeError('Buffer size must be a multiple of 16-bits')
  601. }
  602. for (var i = 0; i < len; i += 2) {
  603. swap(this, i, i + 1)
  604. }
  605. return this
  606. }
  607. Buffer.prototype.swap32 = function swap32 () {
  608. var len = this.length
  609. if (len % 4 !== 0) {
  610. throw new RangeError('Buffer size must be a multiple of 32-bits')
  611. }
  612. for (var i = 0; i < len; i += 4) {
  613. swap(this, i, i + 3)
  614. swap(this, i + 1, i + 2)
  615. }
  616. return this
  617. }
  618. Buffer.prototype.swap64 = function swap64 () {
  619. var len = this.length
  620. if (len % 8 !== 0) {
  621. throw new RangeError('Buffer size must be a multiple of 64-bits')
  622. }
  623. for (var i = 0; i < len; i += 8) {
  624. swap(this, i, i + 7)
  625. swap(this, i + 1, i + 6)
  626. swap(this, i + 2, i + 5)
  627. swap(this, i + 3, i + 4)
  628. }
  629. return this
  630. }
  631. Buffer.prototype.toString = function toString () {
  632. var length = this.length
  633. if (length === 0) return ''
  634. if (arguments.length === 0) return utf8Slice(this, 0, length)
  635. return slowToString.apply(this, arguments)
  636. }
  637. Buffer.prototype.toLocaleString = Buffer.prototype.toString
  638. Buffer.prototype.equals = function equals (b) {
  639. if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
  640. if (this === b) return true
  641. return Buffer.compare(this, b) === 0
  642. }
  643. Buffer.prototype.inspect = function inspect () {
  644. var str = ''
  645. var max = exports.INSPECT_MAX_BYTES
  646. str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim()
  647. if (this.length > max) str += ' ... '
  648. return '<Buffer ' + str + '>'
  649. }
  650. Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
  651. if (isInstance(target, Uint8Array)) {
  652. target = Buffer.from(target, target.offset, target.byteLength)
  653. }
  654. if (!Buffer.isBuffer(target)) {
  655. throw new TypeError(
  656. 'The "target" argument must be one of type Buffer or Uint8Array. ' +
  657. 'Received type ' + (typeof target)
  658. )
  659. }
  660. if (start === undefined) {
  661. start = 0
  662. }
  663. if (end === undefined) {
  664. end = target ? target.length : 0
  665. }
  666. if (thisStart === undefined) {
  667. thisStart = 0
  668. }
  669. if (thisEnd === undefined) {
  670. thisEnd = this.length
  671. }
  672. if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
  673. throw new RangeError('out of range index')
  674. }
  675. if (thisStart >= thisEnd && start >= end) {
  676. return 0
  677. }
  678. if (thisStart >= thisEnd) {
  679. return -1
  680. }
  681. if (start >= end) {
  682. return 1
  683. }
  684. start >>>= 0
  685. end >>>= 0
  686. thisStart >>>= 0
  687. thisEnd >>>= 0
  688. if (this === target) return 0
  689. var x = thisEnd - thisStart
  690. var y = end - start
  691. var len = Math.min(x, y)
  692. var thisCopy = this.slice(thisStart, thisEnd)
  693. var targetCopy = target.slice(start, end)
  694. for (var i = 0; i < len; ++i) {
  695. if (thisCopy[i] !== targetCopy[i]) {
  696. x = thisCopy[i]
  697. y = targetCopy[i]
  698. break
  699. }
  700. }
  701. if (x < y) return -1
  702. if (y < x) return 1
  703. return 0
  704. }
  705. // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
  706. // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
  707. //
  708. // Arguments:
  709. // - buffer - a Buffer to search
  710. // - val - a string, Buffer, or number
  711. // - byteOffset - an index into `buffer`; will be clamped to an int32
  712. // - encoding - an optional encoding, relevant is val is a string
  713. // - dir - true for indexOf, false for lastIndexOf
  714. function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
  715. // Empty buffer means no match
  716. if (buffer.length === 0) return -1
  717. // Normalize byteOffset
  718. if (typeof byteOffset === 'string') {
  719. encoding = byteOffset
  720. byteOffset = 0
  721. } else if (byteOffset > 0x7fffffff) {
  722. byteOffset = 0x7fffffff
  723. } else if (byteOffset < -0x80000000) {
  724. byteOffset = -0x80000000
  725. }
  726. byteOffset = +byteOffset // Coerce to Number.
  727. if (numberIsNaN(byteOffset)) {
  728. // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
  729. byteOffset = dir ? 0 : (buffer.length - 1)
  730. }
  731. // Normalize byteOffset: negative offsets start from the end of the buffer
  732. if (byteOffset < 0) byteOffset = buffer.length + byteOffset
  733. if (byteOffset >= buffer.length) {
  734. if (dir) return -1
  735. else byteOffset = buffer.length - 1
  736. } else if (byteOffset < 0) {
  737. if (dir) byteOffset = 0
  738. else return -1
  739. }
  740. // Normalize val
  741. if (typeof val === 'string') {
  742. val = Buffer.from(val, encoding)
  743. }
  744. // Finally, search either indexOf (if dir is true) or lastIndexOf
  745. if (Buffer.isBuffer(val)) {
  746. // Special case: looking for empty string/buffer always fails
  747. if (val.length === 0) {
  748. return -1
  749. }
  750. return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
  751. } else if (typeof val === 'number') {
  752. val = val & 0xFF // Search for a byte value [0-255]
  753. if (typeof Uint8Array.prototype.indexOf === 'function') {
  754. if (dir) {
  755. return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
  756. } else {
  757. return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
  758. }
  759. }
  760. return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir)
  761. }
  762. throw new TypeError('val must be string, number or Buffer')
  763. }
  764. function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
  765. var indexSize = 1
  766. var arrLength = arr.length
  767. var valLength = val.length
  768. if (encoding !== undefined) {
  769. encoding = String(encoding).toLowerCase()
  770. if (encoding === 'ucs2' || encoding === 'ucs-2' ||
  771. encoding === 'utf16le' || encoding === 'utf-16le') {
  772. if (arr.length < 2 || val.length < 2) {
  773. return -1
  774. }
  775. indexSize = 2
  776. arrLength /= 2
  777. valLength /= 2
  778. byteOffset /= 2
  779. }
  780. }
  781. function read (buf, i) {
  782. if (indexSize === 1) {
  783. return buf[i]
  784. } else {
  785. return buf.readUInt16BE(i * indexSize)
  786. }
  787. }
  788. var i
  789. if (dir) {
  790. var foundIndex = -1
  791. for (i = byteOffset; i < arrLength; i++) {
  792. if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
  793. if (foundIndex === -1) foundIndex = i
  794. if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
  795. } else {
  796. if (foundIndex !== -1) i -= i - foundIndex
  797. foundIndex = -1
  798. }
  799. }
  800. } else {
  801. if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength
  802. for (i = byteOffset; i >= 0; i--) {
  803. var found = true
  804. for (var j = 0; j < valLength; j++) {
  805. if (read(arr, i + j) !== read(val, j)) {
  806. found = false
  807. break
  808. }
  809. }
  810. if (found) return i
  811. }
  812. }
  813. return -1
  814. }
  815. Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
  816. return this.indexOf(val, byteOffset, encoding) !== -1
  817. }
  818. Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
  819. return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
  820. }
  821. Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
  822. return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
  823. }
  824. function hexWrite (buf, string, offset, length) {
  825. offset = Number(offset) || 0
  826. var remaining = buf.length - offset
  827. if (!length) {
  828. length = remaining
  829. } else {
  830. length = Number(length)
  831. if (length > remaining) {
  832. length = remaining
  833. }
  834. }
  835. var strLen = string.length
  836. if (length > strLen / 2) {
  837. length = strLen / 2
  838. }
  839. for (var i = 0; i < length; ++i) {
  840. var parsed = parseInt(string.substr(i * 2, 2), 16)
  841. if (numberIsNaN(parsed)) return i
  842. buf[offset + i] = parsed
  843. }
  844. return i
  845. }
  846. function utf8Write (buf, string, offset, length) {
  847. return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
  848. }
  849. function asciiWrite (buf, string, offset, length) {
  850. return blitBuffer(asciiToBytes(string), buf, offset, length)
  851. }
  852. function latin1Write (buf, string, offset, length) {
  853. return asciiWrite(buf, string, offset, length)
  854. }
  855. function base64Write (buf, string, offset, length) {
  856. return blitBuffer(base64ToBytes(string), buf, offset, length)
  857. }
  858. function ucs2Write (buf, string, offset, length) {
  859. return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
  860. }
  861. Buffer.prototype.write = function write (string, offset, length, encoding) {
  862. // Buffer#write(string)
  863. if (offset === undefined) {
  864. encoding = 'utf8'
  865. length = this.length
  866. offset = 0
  867. // Buffer#write(string, encoding)
  868. } else if (length === undefined && typeof offset === 'string') {
  869. encoding = offset
  870. length = this.length
  871. offset = 0
  872. // Buffer#write(string, offset[, length][, encoding])
  873. } else if (isFinite(offset)) {
  874. offset = offset >>> 0
  875. if (isFinite(length)) {
  876. length = length >>> 0
  877. if (encoding === undefined) encoding = 'utf8'
  878. } else {
  879. encoding = length
  880. length = undefined
  881. }
  882. } else {
  883. throw new Error(
  884. 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
  885. )
  886. }
  887. var remaining = this.length - offset
  888. if (length === undefined || length > remaining) length = remaining
  889. if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
  890. throw new RangeError('Attempt to write outside buffer bounds')
  891. }
  892. if (!encoding) encoding = 'utf8'
  893. var loweredCase = false
  894. for (;;) {
  895. switch (encoding) {
  896. case 'hex':
  897. return hexWrite(this, string, offset, length)
  898. case 'utf8':
  899. case 'utf-8':
  900. return utf8Write(this, string, offset, length)
  901. case 'ascii':
  902. return asciiWrite(this, string, offset, length)
  903. case 'latin1':
  904. case 'binary':
  905. return latin1Write(this, string, offset, length)
  906. case 'base64':
  907. // Warning: maxLength not taken into account in base64Write
  908. return base64Write(this, string, offset, length)
  909. case 'ucs2':
  910. case 'ucs-2':
  911. case 'utf16le':
  912. case 'utf-16le':
  913. return ucs2Write(this, string, offset, length)
  914. default:
  915. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  916. encoding = ('' + encoding).toLowerCase()
  917. loweredCase = true
  918. }
  919. }
  920. }
  921. Buffer.prototype.toJSON = function toJSON () {
  922. return {
  923. type: 'Buffer',
  924. data: Array.prototype.slice.call(this._arr || this, 0)
  925. }
  926. }
  927. function base64Slice (buf, start, end) {
  928. if (start === 0 && end === buf.length) {
  929. return base64.fromByteArray(buf)
  930. } else {
  931. return base64.fromByteArray(buf.slice(start, end))
  932. }
  933. }
  934. function utf8Slice (buf, start, end) {
  935. end = Math.min(buf.length, end)
  936. var res = []
  937. var i = start
  938. while (i < end) {
  939. var firstByte = buf[i]
  940. var codePoint = null
  941. var bytesPerSequence = (firstByte > 0xEF) ? 4
  942. : (firstByte > 0xDF) ? 3
  943. : (firstByte > 0xBF) ? 2
  944. : 1
  945. if (i + bytesPerSequence <= end) {
  946. var secondByte, thirdByte, fourthByte, tempCodePoint
  947. switch (bytesPerSequence) {
  948. case 1:
  949. if (firstByte < 0x80) {
  950. codePoint = firstByte
  951. }
  952. break
  953. case 2:
  954. secondByte = buf[i + 1]
  955. if ((secondByte & 0xC0) === 0x80) {
  956. tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F)
  957. if (tempCodePoint > 0x7F) {
  958. codePoint = tempCodePoint
  959. }
  960. }
  961. break
  962. case 3:
  963. secondByte = buf[i + 1]
  964. thirdByte = buf[i + 2]
  965. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
  966. tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F)
  967. if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
  968. codePoint = tempCodePoint
  969. }
  970. }
  971. break
  972. case 4:
  973. secondByte = buf[i + 1]
  974. thirdByte = buf[i + 2]
  975. fourthByte = buf[i + 3]
  976. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
  977. tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F)
  978. if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
  979. codePoint = tempCodePoint
  980. }
  981. }
  982. }
  983. }
  984. if (codePoint === null) {
  985. // we did not generate a valid codePoint so insert a
  986. // replacement char (U+FFFD) and advance only 1 byte
  987. codePoint = 0xFFFD
  988. bytesPerSequence = 1
  989. } else if (codePoint > 0xFFFF) {
  990. // encode to utf16 (surrogate pair dance)
  991. codePoint -= 0x10000
  992. res.push(codePoint >>> 10 & 0x3FF | 0xD800)
  993. codePoint = 0xDC00 | codePoint & 0x3FF
  994. }
  995. res.push(codePoint)
  996. i += bytesPerSequence
  997. }
  998. return decodeCodePointsArray(res)
  999. }
  1000. // Based on http://stackoverflow.com/a/22747272/680742, the browser with
  1001. // the lowest limit is Chrome, with 0x10000 args.
  1002. // We go 1 magnitude less, for safety
  1003. var MAX_ARGUMENTS_LENGTH = 0x1000
  1004. function decodeCodePointsArray (codePoints) {
  1005. var len = codePoints.length
  1006. if (len <= MAX_ARGUMENTS_LENGTH) {
  1007. return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
  1008. }
  1009. // Decode in chunks to avoid "call stack size exceeded".
  1010. var res = ''
  1011. var i = 0
  1012. while (i < len) {
  1013. res += String.fromCharCode.apply(
  1014. String,
  1015. codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
  1016. )
  1017. }
  1018. return res
  1019. }
  1020. function asciiSlice (buf, start, end) {
  1021. var ret = ''
  1022. end = Math.min(buf.length, end)
  1023. for (var i = start; i < end; ++i) {
  1024. ret += String.fromCharCode(buf[i] & 0x7F)
  1025. }
  1026. return ret
  1027. }
  1028. function latin1Slice (buf, start, end) {
  1029. var ret = ''
  1030. end = Math.min(buf.length, end)
  1031. for (var i = start; i < end; ++i) {
  1032. ret += String.fromCharCode(buf[i])
  1033. }
  1034. return ret
  1035. }
  1036. function hexSlice (buf, start, end) {
  1037. var len = buf.length
  1038. if (!start || start < 0) start = 0
  1039. if (!end || end < 0 || end > len) end = len
  1040. var out = ''
  1041. for (var i = start; i < end; ++i) {
  1042. out += toHex(buf[i])
  1043. }
  1044. return out
  1045. }
  1046. function utf16leSlice (buf, start, end) {
  1047. var bytes = buf.slice(start, end)
  1048. var res = ''
  1049. for (var i = 0; i < bytes.length; i += 2) {
  1050. res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256))
  1051. }
  1052. return res
  1053. }
  1054. Buffer.prototype.slice = function slice (start, end) {
  1055. var len = this.length
  1056. start = ~~start
  1057. end = end === undefined ? len : ~~end
  1058. if (start < 0) {
  1059. start += len
  1060. if (start < 0) start = 0
  1061. } else if (start > len) {
  1062. start = len
  1063. }
  1064. if (end < 0) {
  1065. end += len
  1066. if (end < 0) end = 0
  1067. } else if (end > len) {
  1068. end = len
  1069. }
  1070. if (end < start) end = start
  1071. var newBuf = this.subarray(start, end)
  1072. // Return an augmented `Uint8Array` instance
  1073. newBuf.__proto__ = Buffer.prototype
  1074. return newBuf
  1075. }
  1076. /*
  1077. * Need to make sure that buffer isn't trying to write out of bounds.
  1078. */
  1079. function checkOffset (offset, ext, length) {
  1080. if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
  1081. if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
  1082. }
  1083. Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
  1084. offset = offset >>> 0
  1085. byteLength = byteLength >>> 0
  1086. if (!noAssert) checkOffset(offset, byteLength, this.length)
  1087. var val = this[offset]
  1088. var mul = 1
  1089. var i = 0
  1090. while (++i < byteLength && (mul *= 0x100)) {
  1091. val += this[offset + i] * mul
  1092. }
  1093. return val
  1094. }
  1095. Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
  1096. offset = offset >>> 0
  1097. byteLength = byteLength >>> 0
  1098. if (!noAssert) {
  1099. checkOffset(offset, byteLength, this.length)
  1100. }
  1101. var val = this[offset + --byteLength]
  1102. var mul = 1
  1103. while (byteLength > 0 && (mul *= 0x100)) {
  1104. val += this[offset + --byteLength] * mul
  1105. }
  1106. return val
  1107. }
  1108. Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
  1109. offset = offset >>> 0
  1110. if (!noAssert) checkOffset(offset, 1, this.length)
  1111. return this[offset]
  1112. }
  1113. Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
  1114. offset = offset >>> 0
  1115. if (!noAssert) checkOffset(offset, 2, this.length)
  1116. return this[offset] | (this[offset + 1] << 8)
  1117. }
  1118. Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
  1119. offset = offset >>> 0
  1120. if (!noAssert) checkOffset(offset, 2, this.length)
  1121. return (this[offset] << 8) | this[offset + 1]
  1122. }
  1123. Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
  1124. offset = offset >>> 0
  1125. if (!noAssert) checkOffset(offset, 4, this.length)
  1126. return ((this[offset]) |
  1127. (this[offset + 1] << 8) |
  1128. (this[offset + 2] << 16)) +
  1129. (this[offset + 3] * 0x1000000)
  1130. }
  1131. Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
  1132. offset = offset >>> 0
  1133. if (!noAssert) checkOffset(offset, 4, this.length)
  1134. return (this[offset] * 0x1000000) +
  1135. ((this[offset + 1] << 16) |
  1136. (this[offset + 2] << 8) |
  1137. this[offset + 3])
  1138. }
  1139. Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
  1140. offset = offset >>> 0
  1141. byteLength = byteLength >>> 0
  1142. if (!noAssert) checkOffset(offset, byteLength, this.length)
  1143. var val = this[offset]
  1144. var mul = 1
  1145. var i = 0
  1146. while (++i < byteLength && (mul *= 0x100)) {
  1147. val += this[offset + i] * mul
  1148. }
  1149. mul *= 0x80
  1150. if (val >= mul) val -= Math.pow(2, 8 * byteLength)
  1151. return val
  1152. }
  1153. Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
  1154. offset = offset >>> 0
  1155. byteLength = byteLength >>> 0
  1156. if (!noAssert) checkOffset(offset, byteLength, this.length)
  1157. var i = byteLength
  1158. var mul = 1
  1159. var val = this[offset + --i]
  1160. while (i > 0 && (mul *= 0x100)) {
  1161. val += this[offset + --i] * mul
  1162. }
  1163. mul *= 0x80
  1164. if (val >= mul) val -= Math.pow(2, 8 * byteLength)
  1165. return val
  1166. }
  1167. Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
  1168. offset = offset >>> 0
  1169. if (!noAssert) checkOffset(offset, 1, this.length)
  1170. if (!(this[offset] & 0x80)) return (this[offset])
  1171. return ((0xff - this[offset] + 1) * -1)
  1172. }
  1173. Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
  1174. offset = offset >>> 0
  1175. if (!noAssert) checkOffset(offset, 2, this.length)
  1176. var val = this[offset] | (this[offset + 1] << 8)
  1177. return (val & 0x8000) ? val | 0xFFFF0000 : val
  1178. }
  1179. Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
  1180. offset = offset >>> 0
  1181. if (!noAssert) checkOffset(offset, 2, this.length)
  1182. var val = this[offset + 1] | (this[offset] << 8)
  1183. return (val & 0x8000) ? val | 0xFFFF0000 : val
  1184. }
  1185. Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
  1186. offset = offset >>> 0
  1187. if (!noAssert) checkOffset(offset, 4, this.length)
  1188. return (this[offset]) |
  1189. (this[offset + 1] << 8) |
  1190. (this[offset + 2] << 16) |
  1191. (this[offset + 3] << 24)
  1192. }
  1193. Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
  1194. offset = offset >>> 0
  1195. if (!noAssert) checkOffset(offset, 4, this.length)
  1196. return (this[offset] << 24) |
  1197. (this[offset + 1] << 16) |
  1198. (this[offset + 2] << 8) |
  1199. (this[offset + 3])
  1200. }
  1201. Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
  1202. offset = offset >>> 0
  1203. if (!noAssert) checkOffset(offset, 4, this.length)
  1204. return ieee754.read(this, offset, true, 23, 4)
  1205. }
  1206. Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
  1207. offset = offset >>> 0
  1208. if (!noAssert) checkOffset(offset, 4, this.length)
  1209. return ieee754.read(this, offset, false, 23, 4)
  1210. }
  1211. Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
  1212. offset = offset >>> 0
  1213. if (!noAssert) checkOffset(offset, 8, this.length)
  1214. return ieee754.read(this, offset, true, 52, 8)
  1215. }
  1216. Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
  1217. offset = offset >>> 0
  1218. if (!noAssert) checkOffset(offset, 8, this.length)
  1219. return ieee754.read(this, offset, false, 52, 8)
  1220. }
  1221. function checkInt (buf, value, offset, ext, max, min) {
  1222. if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
  1223. if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
  1224. if (offset + ext > buf.length) throw new RangeError('Index out of range')
  1225. }
  1226. Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
  1227. value = +value
  1228. offset = offset >>> 0
  1229. byteLength = byteLength >>> 0
  1230. if (!noAssert) {
  1231. var maxBytes = Math.pow(2, 8 * byteLength) - 1
  1232. checkInt(this, value, offset, byteLength, maxBytes, 0)
  1233. }
  1234. var mul = 1
  1235. var i = 0
  1236. this[offset] = value & 0xFF
  1237. while (++i < byteLength && (mul *= 0x100)) {
  1238. this[offset + i] = (value / mul) & 0xFF
  1239. }
  1240. return offset + byteLength
  1241. }
  1242. Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
  1243. value = +value
  1244. offset = offset >>> 0
  1245. byteLength = byteLength >>> 0
  1246. if (!noAssert) {
  1247. var maxBytes = Math.pow(2, 8 * byteLength) - 1
  1248. checkInt(this, value, offset, byteLength, maxBytes, 0)
  1249. }
  1250. var i = byteLength - 1
  1251. var mul = 1
  1252. this[offset + i] = value & 0xFF
  1253. while (--i >= 0 && (mul *= 0x100)) {
  1254. this[offset + i] = (value / mul) & 0xFF
  1255. }
  1256. return offset + byteLength
  1257. }
  1258. Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
  1259. value = +value
  1260. offset = offset >>> 0
  1261. if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)
  1262. this[offset] = (value & 0xff)
  1263. return offset + 1
  1264. }
  1265. Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
  1266. value = +value
  1267. offset = offset >>> 0
  1268. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
  1269. this[offset] = (value & 0xff)
  1270. this[offset + 1] = (value >>> 8)
  1271. return offset + 2
  1272. }
  1273. Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
  1274. value = +value
  1275. offset = offset >>> 0
  1276. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
  1277. this[offset] = (value >>> 8)
  1278. this[offset + 1] = (value & 0xff)
  1279. return offset + 2
  1280. }
  1281. Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
  1282. value = +value
  1283. offset = offset >>> 0
  1284. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
  1285. this[offset + 3] = (value >>> 24)
  1286. this[offset + 2] = (value >>> 16)
  1287. this[offset + 1] = (value >>> 8)
  1288. this[offset] = (value & 0xff)
  1289. return offset + 4
  1290. }
  1291. Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
  1292. value = +value
  1293. offset = offset >>> 0
  1294. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
  1295. this[offset] = (value >>> 24)
  1296. this[offset + 1] = (value >>> 16)
  1297. this[offset + 2] = (value >>> 8)
  1298. this[offset + 3] = (value & 0xff)
  1299. return offset + 4
  1300. }
  1301. Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
  1302. value = +value
  1303. offset = offset >>> 0
  1304. if (!noAssert) {
  1305. var limit = Math.pow(2, (8 * byteLength) - 1)
  1306. checkInt(this, value, offset, byteLength, limit - 1, -limit)
  1307. }
  1308. var i = 0
  1309. var mul = 1
  1310. var sub = 0
  1311. this[offset] = value & 0xFF
  1312. while (++i < byteLength && (mul *= 0x100)) {
  1313. if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
  1314. sub = 1
  1315. }
  1316. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
  1317. }
  1318. return offset + byteLength
  1319. }
  1320. Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
  1321. value = +value
  1322. offset = offset >>> 0
  1323. if (!noAssert) {
  1324. var limit = Math.pow(2, (8 * byteLength) - 1)
  1325. checkInt(this, value, offset, byteLength, limit - 1, -limit)
  1326. }
  1327. var i = byteLength - 1
  1328. var mul = 1
  1329. var sub = 0
  1330. this[offset + i] = value & 0xFF
  1331. while (--i >= 0 && (mul *= 0x100)) {
  1332. if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
  1333. sub = 1
  1334. }
  1335. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
  1336. }
  1337. return offset + byteLength
  1338. }
  1339. Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
  1340. value = +value
  1341. offset = offset >>> 0
  1342. if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80)
  1343. if (value < 0) value = 0xff + value + 1
  1344. this[offset] = (value & 0xff)
  1345. return offset + 1
  1346. }
  1347. Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
  1348. value = +value
  1349. offset = offset >>> 0
  1350. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
  1351. this[offset] = (value & 0xff)
  1352. this[offset + 1] = (value >>> 8)
  1353. return offset + 2
  1354. }
  1355. Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
  1356. value = +value
  1357. offset = offset >>> 0
  1358. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
  1359. this[offset] = (value >>> 8)
  1360. this[offset + 1] = (value & 0xff)
  1361. return offset + 2
  1362. }
  1363. Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
  1364. value = +value
  1365. offset = offset >>> 0
  1366. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
  1367. this[offset] = (value & 0xff)
  1368. this[offset + 1] = (value >>> 8)
  1369. this[offset + 2] = (value >>> 16)
  1370. this[offset + 3] = (value >>> 24)
  1371. return offset + 4
  1372. }
  1373. Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
  1374. value = +value
  1375. offset = offset >>> 0
  1376. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
  1377. if (value < 0) value = 0xffffffff + value + 1
  1378. this[offset] = (value >>> 24)
  1379. this[offset + 1] = (value >>> 16)
  1380. this[offset + 2] = (value >>> 8)
  1381. this[offset + 3] = (value & 0xff)
  1382. return offset + 4
  1383. }
  1384. function checkIEEE754 (buf, value, offset, ext, max, min) {
  1385. if (offset + ext > buf.length) throw new RangeError('Index out of range')
  1386. if (offset < 0) throw new RangeError('Index out of range')
  1387. }
  1388. function writeFloat (buf, value, offset, littleEndian, noAssert) {
  1389. value = +value
  1390. offset = offset >>> 0
  1391. if (!noAssert) {
  1392. checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
  1393. }
  1394. ieee754.write(buf, value, offset, littleEndian, 23, 4)
  1395. return offset + 4
  1396. }
  1397. Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
  1398. return writeFloat(this, value, offset, true, noAssert)
  1399. }
  1400. Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
  1401. return writeFloat(this, value, offset, false, noAssert)
  1402. }
  1403. function writeDouble (buf, value, offset, littleEndian, noAssert) {
  1404. value = +value
  1405. offset = offset >>> 0
  1406. if (!noAssert) {
  1407. checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
  1408. }
  1409. ieee754.write(buf, value, offset, littleEndian, 52, 8)
  1410. return offset + 8
  1411. }
  1412. Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
  1413. return writeDouble(this, value, offset, true, noAssert)
  1414. }
  1415. Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
  1416. return writeDouble(this, value, offset, false, noAssert)
  1417. }
  1418. // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
  1419. Buffer.prototype.copy = function copy (target, targetStart, start, end) {
  1420. if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer')
  1421. if (!start) start = 0
  1422. if (!end && end !== 0) end = this.length
  1423. if (targetStart >= target.length) targetStart = target.length
  1424. if (!targetStart) targetStart = 0
  1425. if (end > 0 && end < start) end = start
  1426. // Copy 0 bytes; we're done
  1427. if (end === start) return 0
  1428. if (target.length === 0 || this.length === 0) return 0
  1429. // Fatal error conditions
  1430. if (targetStart < 0) {
  1431. throw new RangeError('targetStart out of bounds')
  1432. }
  1433. if (start < 0 || start >= this.length) throw new RangeError('Index out of range')
  1434. if (end < 0) throw new RangeError('sourceEnd out of bounds')
  1435. // Are we oob?
  1436. if (end > this.length) end = this.length
  1437. if (target.length - targetStart < end - start) {
  1438. end = target.length - targetStart + start
  1439. }
  1440. var len = end - start
  1441. if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {
  1442. // Use built-in when available, missing from IE11
  1443. this.copyWithin(targetStart, start, end)
  1444. } else if (this === target && start < targetStart && targetStart < end) {
  1445. // descending copy from end
  1446. for (var i = len - 1; i >= 0; --i) {
  1447. target[i + targetStart] = this[i + start]
  1448. }
  1449. } else {
  1450. Uint8Array.prototype.set.call(
  1451. target,
  1452. this.subarray(start, end),
  1453. targetStart
  1454. )
  1455. }
  1456. return len
  1457. }
  1458. // Usage:
  1459. // buffer.fill(number[, offset[, end]])
  1460. // buffer.fill(buffer[, offset[, end]])
  1461. // buffer.fill(string[, offset[, end]][, encoding])
  1462. Buffer.prototype.fill = function fill (val, start, end, encoding) {
  1463. // Handle string cases:
  1464. if (typeof val === 'string') {
  1465. if (typeof start === 'string') {
  1466. encoding = start
  1467. start = 0
  1468. end = this.length
  1469. } else if (typeof end === 'string') {
  1470. encoding = end
  1471. end = this.length
  1472. }
  1473. if (encoding !== undefined && typeof encoding !== 'string') {
  1474. throw new TypeError('encoding must be a string')
  1475. }
  1476. if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
  1477. throw new TypeError('Unknown encoding: ' + encoding)
  1478. }
  1479. if (val.length === 1) {
  1480. var code = val.charCodeAt(0)
  1481. if ((encoding === 'utf8' && code < 128) ||
  1482. encoding === 'latin1') {
  1483. // Fast path: If `val` fits into a single byte, use that numeric value.
  1484. val = code
  1485. }
  1486. }
  1487. } else if (typeof val === 'number') {
  1488. val = val & 255
  1489. }
  1490. // Invalid ranges are not set to a default, so can range check early.
  1491. if (start < 0 || this.length < start || this.length < end) {
  1492. throw new RangeError('Out of range index')
  1493. }
  1494. if (end <= start) {
  1495. return this
  1496. }
  1497. start = start >>> 0
  1498. end = end === undefined ? this.length : end >>> 0
  1499. if (!val) val = 0
  1500. var i
  1501. if (typeof val === 'number') {
  1502. for (i = start; i < end; ++i) {
  1503. this[i] = val
  1504. }
  1505. } else {
  1506. var bytes = Buffer.isBuffer(val)
  1507. ? val
  1508. : Buffer.from(val, encoding)
  1509. var len = bytes.length
  1510. if (len === 0) {
  1511. throw new TypeError('The value "' + val +
  1512. '" is invalid for argument "value"')
  1513. }
  1514. for (i = 0; i < end - start; ++i) {
  1515. this[i + start] = bytes[i % len]
  1516. }
  1517. }
  1518. return this
  1519. }
  1520. // HELPER FUNCTIONS
  1521. // ================
  1522. var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g
  1523. function base64clean (str) {
  1524. // Node takes equal signs as end of the Base64 encoding
  1525. str = str.split('=')[0]
  1526. // Node strips out invalid characters like \n and \t from the string, base64-js does not
  1527. str = str.trim().replace(INVALID_BASE64_RE, '')
  1528. // Node converts strings with length < 2 to ''
  1529. if (str.length < 2) return ''
  1530. // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
  1531. while (str.length % 4 !== 0) {
  1532. str = str + '='
  1533. }
  1534. return str
  1535. }
  1536. function toHex (n) {
  1537. if (n < 16) return '0' + n.toString(16)
  1538. return n.toString(16)
  1539. }
  1540. function utf8ToBytes (string, units) {
  1541. units = units || Infinity
  1542. var codePoint
  1543. var length = string.length
  1544. var leadSurrogate = null
  1545. var bytes = []
  1546. for (var i = 0; i < length; ++i) {
  1547. codePoint = string.charCodeAt(i)
  1548. // is surrogate component
  1549. if (codePoint > 0xD7FF && codePoint < 0xE000) {
  1550. // last char was a lead
  1551. if (!leadSurrogate) {
  1552. // no lead yet
  1553. if (codePoint > 0xDBFF) {
  1554. // unexpected trail
  1555. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  1556. continue
  1557. } else if (i + 1 === length) {
  1558. // unpaired lead
  1559. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  1560. continue
  1561. }
  1562. // valid lead
  1563. leadSurrogate = codePoint
  1564. continue
  1565. }
  1566. // 2 leads in a row
  1567. if (codePoint < 0xDC00) {
  1568. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  1569. leadSurrogate = codePoint
  1570. continue
  1571. }
  1572. // valid surrogate pair
  1573. codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000
  1574. } else if (leadSurrogate) {
  1575. // valid bmp char, but last char was a lead
  1576. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  1577. }
  1578. leadSurrogate = null
  1579. // encode utf8
  1580. if (codePoint < 0x80) {
  1581. if ((units -= 1) < 0) break
  1582. bytes.push(codePoint)
  1583. } else if (codePoint < 0x800) {
  1584. if ((units -= 2) < 0) break
  1585. bytes.push(
  1586. codePoint >> 0x6 | 0xC0,
  1587. codePoint & 0x3F | 0x80
  1588. )
  1589. } else if (codePoint < 0x10000) {
  1590. if ((units -= 3) < 0) break
  1591. bytes.push(
  1592. codePoint >> 0xC | 0xE0,
  1593. codePoint >> 0x6 & 0x3F | 0x80,
  1594. codePoint & 0x3F | 0x80
  1595. )
  1596. } else if (codePoint < 0x110000) {
  1597. if ((units -= 4) < 0) break
  1598. bytes.push(
  1599. codePoint >> 0x12 | 0xF0,
  1600. codePoint >> 0xC & 0x3F | 0x80,
  1601. codePoint >> 0x6 & 0x3F | 0x80,
  1602. codePoint & 0x3F | 0x80
  1603. )
  1604. } else {
  1605. throw new Error('Invalid code point')
  1606. }
  1607. }
  1608. return bytes
  1609. }
  1610. function asciiToBytes (str) {
  1611. var byteArray = []
  1612. for (var i = 0; i < str.length; ++i) {
  1613. // Node's code seems to be doing this and not & 0x7F..
  1614. byteArray.push(str.charCodeAt(i) & 0xFF)
  1615. }
  1616. return byteArray
  1617. }
  1618. function utf16leToBytes (str, units) {
  1619. var c, hi, lo
  1620. var byteArray = []
  1621. for (var i = 0; i < str.length; ++i) {
  1622. if ((units -= 2) < 0) break
  1623. c = str.charCodeAt(i)
  1624. hi = c >> 8
  1625. lo = c % 256
  1626. byteArray.push(lo)
  1627. byteArray.push(hi)
  1628. }
  1629. return byteArray
  1630. }
  1631. function base64ToBytes (str) {
  1632. return base64.toByteArray(base64clean(str))
  1633. }
  1634. function blitBuffer (src, dst, offset, length) {
  1635. for (var i = 0; i < length; ++i) {
  1636. if ((i + offset >= dst.length) || (i >= src.length)) break
  1637. dst[i + offset] = src[i]
  1638. }
  1639. return i
  1640. }
  1641. // ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass
  1642. // the `instanceof` check but they should be treated as of that type.
  1643. // See: https://github.com/feross/buffer/issues/166
  1644. function isInstance (obj, type) {
  1645. return obj instanceof type ||
  1646. (obj != null && obj.constructor != null && obj.constructor.name != null &&
  1647. obj.constructor.name === type.name)
  1648. }
  1649. function numberIsNaN (obj) {
  1650. // For IE11 support
  1651. return obj !== obj // eslint-disable-line no-self-compare
  1652. }
  1653. }).call(this)}).call(this,require("buffer").Buffer)
  1654. },{"base64-js":1,"buffer":3,"ieee754":7}],4:[function(require,module,exports){
  1655. module.exports = {
  1656. "100": "Continue",
  1657. "101": "Switching Protocols",
  1658. "102": "Processing",
  1659. "200": "OK",
  1660. "201": "Created",
  1661. "202": "Accepted",
  1662. "203": "Non-Authoritative Information",
  1663. "204": "No Content",
  1664. "205": "Reset Content",
  1665. "206": "Partial Content",
  1666. "207": "Multi-Status",
  1667. "208": "Already Reported",
  1668. "226": "IM Used",
  1669. "300": "Multiple Choices",
  1670. "301": "Moved Permanently",
  1671. "302": "Found",
  1672. "303": "See Other",
  1673. "304": "Not Modified",
  1674. "305": "Use Proxy",
  1675. "307": "Temporary Redirect",
  1676. "308": "Permanent Redirect",
  1677. "400": "Bad Request",
  1678. "401": "Unauthorized",
  1679. "402": "Payment Required",
  1680. "403": "Forbidden",
  1681. "404": "Not Found",
  1682. "405": "Method Not Allowed",
  1683. "406": "Not Acceptable",
  1684. "407": "Proxy Authentication Required",
  1685. "408": "Request Timeout",
  1686. "409": "Conflict",
  1687. "410": "Gone",
  1688. "411": "Length Required",
  1689. "412": "Precondition Failed",
  1690. "413": "Payload Too Large",
  1691. "414": "URI Too Long",
  1692. "415": "Unsupported Media Type",
  1693. "416": "Range Not Satisfiable",
  1694. "417": "Expectation Failed",
  1695. "418": "I'm a teapot",
  1696. "421": "Misdirected Request",
  1697. "422": "Unprocessable Entity",
  1698. "423": "Locked",
  1699. "424": "Failed Dependency",
  1700. "425": "Unordered Collection",
  1701. "426": "Upgrade Required",
  1702. "428": "Precondition Required",
  1703. "429": "Too Many Requests",
  1704. "431": "Request Header Fields Too Large",
  1705. "451": "Unavailable For Legal Reasons",
  1706. "500": "Internal Server Error",
  1707. "501": "Not Implemented",
  1708. "502": "Bad Gateway",
  1709. "503": "Service Unavailable",
  1710. "504": "Gateway Timeout",
  1711. "505": "HTTP Version Not Supported",
  1712. "506": "Variant Also Negotiates",
  1713. "507": "Insufficient Storage",
  1714. "508": "Loop Detected",
  1715. "509": "Bandwidth Limit Exceeded",
  1716. "510": "Not Extended",
  1717. "511": "Network Authentication Required"
  1718. }
  1719. },{}],5:[function(require,module,exports){
  1720. // Copyright Joyent, Inc. and other Node contributors.
  1721. //
  1722. // Permission is hereby granted, free of charge, to any person obtaining a
  1723. // copy of this software and associated documentation files (the
  1724. // "Software"), to deal in the Software without restriction, including
  1725. // without limitation the rights to use, copy, modify, merge, publish,
  1726. // distribute, sublicense, and/or sell copies of the Software, and to permit
  1727. // persons to whom the Software is furnished to do so, subject to the
  1728. // following conditions:
  1729. //
  1730. // The above copyright notice and this permission notice shall be included
  1731. // in all copies or substantial portions of the Software.
  1732. //
  1733. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  1734. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  1735. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  1736. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  1737. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  1738. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  1739. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  1740. var objectCreate = Object.create || objectCreatePolyfill
  1741. var objectKeys = Object.keys || objectKeysPolyfill
  1742. var bind = Function.prototype.bind || functionBindPolyfill
  1743. function EventEmitter() {
  1744. if (!this._events || !Object.prototype.hasOwnProperty.call(this, '_events')) {
  1745. this._events = objectCreate(null);
  1746. this._eventsCount = 0;
  1747. }
  1748. this._maxListeners = this._maxListeners || undefined;
  1749. }
  1750. module.exports = EventEmitter;
  1751. // Backwards-compat with node 0.10.x
  1752. EventEmitter.EventEmitter = EventEmitter;
  1753. EventEmitter.prototype._events = undefined;
  1754. EventEmitter.prototype._maxListeners = undefined;
  1755. // By default EventEmitters will print a warning if more than 10 listeners are
  1756. // added to it. This is a useful default which helps finding memory leaks.
  1757. var defaultMaxListeners = 10;
  1758. var hasDefineProperty;
  1759. try {
  1760. var o = {};
  1761. if (Object.defineProperty) Object.defineProperty(o, 'x', { value: 0 });
  1762. hasDefineProperty = o.x === 0;
  1763. } catch (err) { hasDefineProperty = false }
  1764. if (hasDefineProperty) {
  1765. Object.defineProperty(EventEmitter, 'defaultMaxListeners', {
  1766. enumerable: true,
  1767. get: function() {
  1768. return defaultMaxListeners;
  1769. },
  1770. set: function(arg) {
  1771. // check whether the input is a positive number (whose value is zero or
  1772. // greater and not a NaN).
  1773. if (typeof arg !== 'number' || arg < 0 || arg !== arg)
  1774. throw new TypeError('"defaultMaxListeners" must be a positive number');
  1775. defaultMaxListeners = arg;
  1776. }
  1777. });
  1778. } else {
  1779. EventEmitter.defaultMaxListeners = defaultMaxListeners;
  1780. }
  1781. // Obviously not all Emitters should be limited to 10. This function allows
  1782. // that to be increased. Set to zero for unlimited.
  1783. EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
  1784. if (typeof n !== 'number' || n < 0 || isNaN(n))
  1785. throw new TypeError('"n" argument must be a positive number');
  1786. this._maxListeners = n;
  1787. return this;
  1788. };
  1789. function $getMaxListeners(that) {
  1790. if (that._maxListeners === undefined)
  1791. return EventEmitter.defaultMaxListeners;
  1792. return that._maxListeners;
  1793. }
  1794. EventEmitter.prototype.getMaxListeners = function getMaxListeners() {
  1795. return $getMaxListeners(this);
  1796. };
  1797. // These standalone emit* functions are used to optimize calling of event
  1798. // handlers for fast cases because emit() itself often has a variable number of
  1799. // arguments and can be deoptimized because of that. These functions always have
  1800. // the same number of arguments and thus do not get deoptimized, so the code
  1801. // inside them can execute faster.
  1802. function emitNone(handler, isFn, self) {
  1803. if (isFn)
  1804. handler.call(self);
  1805. else {
  1806. var len = handler.length;
  1807. var listeners = arrayClone(handler, len);
  1808. for (var i = 0; i < len; ++i)
  1809. listeners[i].call(self);
  1810. }
  1811. }
  1812. function emitOne(handler, isFn, self, arg1) {
  1813. if (isFn)
  1814. handler.call(self, arg1);
  1815. else {
  1816. var len = handler.length;
  1817. var listeners = arrayClone(handler, len);
  1818. for (var i = 0; i < len; ++i)
  1819. listeners[i].call(self, arg1);
  1820. }
  1821. }
  1822. function emitTwo(handler, isFn, self, arg1, arg2) {
  1823. if (isFn)
  1824. handler.call(self, arg1, arg2);
  1825. else {
  1826. var len = handler.length;
  1827. var listeners = arrayClone(handler, len);
  1828. for (var i = 0; i < len; ++i)
  1829. listeners[i].call(self, arg1, arg2);
  1830. }
  1831. }
  1832. function emitThree(handler, isFn, self, arg1, arg2, arg3) {
  1833. if (isFn)
  1834. handler.call(self, arg1, arg2, arg3);
  1835. else {
  1836. var len = handler.length;
  1837. var listeners = arrayClone(handler, len);
  1838. for (var i = 0; i < len; ++i)
  1839. listeners[i].call(self, arg1, arg2, arg3);
  1840. }
  1841. }
  1842. function emitMany(handler, isFn, self, args) {
  1843. if (isFn)
  1844. handler.apply(self, args);
  1845. else {
  1846. var len = handler.length;
  1847. var listeners = arrayClone(handler, len);
  1848. for (var i = 0; i < len; ++i)
  1849. listeners[i].apply(self, args);
  1850. }
  1851. }
  1852. EventEmitter.prototype.emit = function emit(type) {
  1853. var er, handler, len, args, i, events;
  1854. var doError = (type === 'error');
  1855. events = this._events;
  1856. if (events)
  1857. doError = (doError && events.error == null);
  1858. else if (!doError)
  1859. return false;
  1860. // If there is no 'error' event listener then throw.
  1861. if (doError) {
  1862. if (arguments.length > 1)
  1863. er = arguments[1];
  1864. if (er instanceof Error) {
  1865. throw er; // Unhandled 'error' event
  1866. } else {
  1867. // At least give some kind of context to the user
  1868. var err = new Error('Unhandled "error" event. (' + er + ')');
  1869. err.context = er;
  1870. throw err;
  1871. }
  1872. return false;
  1873. }
  1874. handler = events[type];
  1875. if (!handler)
  1876. return false;
  1877. var isFn = typeof handler === 'function';
  1878. len = arguments.length;
  1879. switch (len) {
  1880. // fast cases
  1881. case 1:
  1882. emitNone(handler, isFn, this);
  1883. break;
  1884. case 2:
  1885. emitOne(handler, isFn, this, arguments[1]);
  1886. break;
  1887. case 3:
  1888. emitTwo(handler, isFn, this, arguments[1], arguments[2]);
  1889. break;
  1890. case 4:
  1891. emitThree(handler, isFn, this, arguments[1], arguments[2], arguments[3]);
  1892. break;
  1893. // slower
  1894. default:
  1895. args = new Array(len - 1);
  1896. for (i = 1; i < len; i++)
  1897. args[i - 1] = arguments[i];
  1898. emitMany(handler, isFn, this, args);
  1899. }
  1900. return true;
  1901. };
  1902. function _addListener(target, type, listener, prepend) {
  1903. var m;
  1904. var events;
  1905. var existing;
  1906. if (typeof listener !== 'function')
  1907. throw new TypeError('"listener" argument must be a function');
  1908. events = target._events;
  1909. if (!events) {
  1910. events = target._events = objectCreate(null);
  1911. target._eventsCount = 0;
  1912. } else {
  1913. // To avoid recursion in the case that type === "newListener"! Before
  1914. // adding it to the listeners, first emit "newListener".
  1915. if (events.newListener) {
  1916. target.emit('newListener', type,
  1917. listener.listener ? listener.listener : listener);
  1918. // Re-assign `events` because a newListener handler could have caused the
  1919. // this._events to be assigned to a new object
  1920. events = target._events;
  1921. }
  1922. existing = events[type];
  1923. }
  1924. if (!existing) {
  1925. // Optimize the case of one listener. Don't need the extra array object.
  1926. existing = events[type] = listener;
  1927. ++target._eventsCount;
  1928. } else {
  1929. if (typeof existing === 'function') {
  1930. // Adding the second element, need to change to array.
  1931. existing = events[type] =
  1932. prepend ? [listener, existing] : [existing, listener];
  1933. } else {
  1934. // If we've already got an array, just append.
  1935. if (prepend) {
  1936. existing.unshift(listener);
  1937. } else {
  1938. existing.push(listener);
  1939. }
  1940. }
  1941. // Check for listener leak
  1942. if (!existing.warned) {
  1943. m = $getMaxListeners(target);
  1944. if (m && m > 0 && existing.length > m) {
  1945. existing.warned = true;
  1946. var w = new Error('Possible EventEmitter memory leak detected. ' +
  1947. existing.length + ' "' + String(type) + '" listeners ' +
  1948. 'added. Use emitter.setMaxListeners() to ' +
  1949. 'increase limit.');
  1950. w.name = 'MaxListenersExceededWarning';
  1951. w.emitter = target;
  1952. w.type = type;
  1953. w.count = existing.length;
  1954. if (typeof console === 'object' && console.warn) {
  1955. console.warn('%s: %s', w.name, w.message);
  1956. }
  1957. }
  1958. }
  1959. }
  1960. return target;
  1961. }
  1962. EventEmitter.prototype.addListener = function addListener(type, listener) {
  1963. return _addListener(this, type, listener, false);
  1964. };
  1965. EventEmitter.prototype.on = EventEmitter.prototype.addListener;
  1966. EventEmitter.prototype.prependListener =
  1967. function prependListener(type, listener) {
  1968. return _addListener(this, type, listener, true);
  1969. };
  1970. function onceWrapper() {
  1971. if (!this.fired) {
  1972. this.target.removeListener(this.type, this.wrapFn);
  1973. this.fired = true;
  1974. switch (arguments.length) {
  1975. case 0:
  1976. return this.listener.call(this.target);
  1977. case 1:
  1978. return this.listener.call(this.target, arguments[0]);
  1979. case 2:
  1980. return this.listener.call(this.target, arguments[0], arguments[1]);
  1981. case 3:
  1982. return this.listener.call(this.target, arguments[0], arguments[1],
  1983. arguments[2]);
  1984. default:
  1985. var args = new Array(arguments.length);
  1986. for (var i = 0; i < args.length; ++i)
  1987. args[i] = arguments[i];
  1988. this.listener.apply(this.target, args);
  1989. }
  1990. }
  1991. }
  1992. function _onceWrap(target, type, listener) {
  1993. var state = { fired: false, wrapFn: undefined, target: target, type: type, listener: listener };
  1994. var wrapped = bind.call(onceWrapper, state);
  1995. wrapped.listener = listener;
  1996. state.wrapFn = wrapped;
  1997. return wrapped;
  1998. }
  1999. EventEmitter.prototype.once = function once(type, listener) {
  2000. if (typeof listener !== 'function')
  2001. throw new TypeError('"listener" argument must be a function');
  2002. this.on(type, _onceWrap(this, type, listener));
  2003. return this;
  2004. };
  2005. EventEmitter.prototype.prependOnceListener =
  2006. function prependOnceListener(type, listener) {
  2007. if (typeof listener !== 'function')
  2008. throw new TypeError('"listener" argument must be a function');
  2009. this.prependListener(type, _onceWrap(this, type, listener));
  2010. return this;
  2011. };
  2012. // Emits a 'removeListener' event if and only if the listener was removed.
  2013. EventEmitter.prototype.removeListener =
  2014. function removeListener(type, listener) {
  2015. var list, events, position, i, originalListener;
  2016. if (typeof listener !== 'function')
  2017. throw new TypeError('"listener" argument must be a function');
  2018. events = this._events;
  2019. if (!events)
  2020. return this;
  2021. list = events[type];
  2022. if (!list)
  2023. return this;
  2024. if (list === listener || list.listener === listener) {
  2025. if (--this._eventsCount === 0)
  2026. this._events = objectCreate(null);
  2027. else {
  2028. delete events[type];
  2029. if (events.removeListener)
  2030. this.emit('removeListener', type, list.listener || listener);
  2031. }
  2032. } else if (typeof list !== 'function') {
  2033. position = -1;
  2034. for (i = list.length - 1; i >= 0; i--) {
  2035. if (list[i] === listener || list[i].listener === listener) {
  2036. originalListener = list[i].listener;
  2037. position = i;
  2038. break;
  2039. }
  2040. }
  2041. if (position < 0)
  2042. return this;
  2043. if (position === 0)
  2044. list.shift();
  2045. else
  2046. spliceOne(list, position);
  2047. if (list.length === 1)
  2048. events[type] = list[0];
  2049. if (events.removeListener)
  2050. this.emit('removeListener', type, originalListener || listener);
  2051. }
  2052. return this;
  2053. };
  2054. EventEmitter.prototype.removeAllListeners =
  2055. function removeAllListeners(type) {
  2056. var listeners, events, i;
  2057. events = this._events;
  2058. if (!events)
  2059. return this;
  2060. // not listening for removeListener, no need to emit
  2061. if (!events.removeListener) {
  2062. if (arguments.length === 0) {
  2063. this._events = objectCreate(null);
  2064. this._eventsCount = 0;
  2065. } else if (events[type]) {
  2066. if (--this._eventsCount === 0)
  2067. this._events = objectCreate(null);
  2068. else
  2069. delete events[type];
  2070. }
  2071. return this;
  2072. }
  2073. // emit removeListener for all listeners on all events
  2074. if (arguments.length === 0) {
  2075. var keys = objectKeys(events);
  2076. var key;
  2077. for (i = 0; i < keys.length; ++i) {
  2078. key = keys[i];
  2079. if (key === 'removeListener') continue;
  2080. this.removeAllListeners(key);
  2081. }
  2082. this.removeAllListeners('removeListener');
  2083. this._events = objectCreate(null);
  2084. this._eventsCount = 0;
  2085. return this;
  2086. }
  2087. listeners = events[type];
  2088. if (typeof listeners === 'function') {
  2089. this.removeListener(type, listeners);
  2090. } else if (listeners) {
  2091. // LIFO order
  2092. for (i = listeners.length - 1; i >= 0; i--) {
  2093. this.removeListener(type, listeners[i]);
  2094. }
  2095. }
  2096. return this;
  2097. };
  2098. function _listeners(target, type, unwrap) {
  2099. var events = target._events;
  2100. if (!events)
  2101. return [];
  2102. var evlistener = events[type];
  2103. if (!evlistener)
  2104. return [];
  2105. if (typeof evlistener === 'function')
  2106. return unwrap ? [evlistener.listener || evlistener] : [evlistener];
  2107. return unwrap ? unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length);
  2108. }
  2109. EventEmitter.prototype.listeners = function listeners(type) {
  2110. return _listeners(this, type, true);
  2111. };
  2112. EventEmitter.prototype.rawListeners = function rawListeners(type) {
  2113. return _listeners(this, type, false);
  2114. };
  2115. EventEmitter.listenerCount = function(emitter, type) {
  2116. if (typeof emitter.listenerCount === 'function') {
  2117. return emitter.listenerCount(type);
  2118. } else {
  2119. return listenerCount.call(emitter, type);
  2120. }
  2121. };
  2122. EventEmitter.prototype.listenerCount = listenerCount;
  2123. function listenerCount(type) {
  2124. var events = this._events;
  2125. if (events) {
  2126. var evlistener = events[type];
  2127. if (typeof evlistener === 'function') {
  2128. return 1;
  2129. } else if (evlistener) {
  2130. return evlistener.length;
  2131. }
  2132. }
  2133. return 0;
  2134. }
  2135. EventEmitter.prototype.eventNames = function eventNames() {
  2136. return this._eventsCount > 0 ? Reflect.ownKeys(this._events) : [];
  2137. };
  2138. // About 1.5x faster than the two-arg version of Array#splice().
  2139. function spliceOne(list, index) {
  2140. for (var i = index, k = i + 1, n = list.length; k < n; i += 1, k += 1)
  2141. list[i] = list[k];
  2142. list.pop();
  2143. }
  2144. function arrayClone(arr, n) {
  2145. var copy = new Array(n);
  2146. for (var i = 0; i < n; ++i)
  2147. copy[i] = arr[i];
  2148. return copy;
  2149. }
  2150. function unwrapListeners(arr) {
  2151. var ret = new Array(arr.length);
  2152. for (var i = 0; i < ret.length; ++i) {
  2153. ret[i] = arr[i].listener || arr[i];
  2154. }
  2155. return ret;
  2156. }
  2157. function objectCreatePolyfill(proto) {
  2158. var F = function() {};
  2159. F.prototype = proto;
  2160. return new F;
  2161. }
  2162. function objectKeysPolyfill(obj) {
  2163. var keys = [];
  2164. for (var k in obj) if (Object.prototype.hasOwnProperty.call(obj, k)) {
  2165. keys.push(k);
  2166. }
  2167. return k;
  2168. }
  2169. function functionBindPolyfill(context) {
  2170. var fn = this;
  2171. return function () {
  2172. return fn.apply(context, arguments);
  2173. };
  2174. }
  2175. },{}],6:[function(require,module,exports){
  2176. var http = require('http')
  2177. var url = require('url')
  2178. var https = module.exports
  2179. for (var key in http) {
  2180. if (http.hasOwnProperty(key)) https[key] = http[key]
  2181. }
  2182. https.request = function (params, cb) {
  2183. params = validateParams(params)
  2184. return http.request.call(this, params, cb)
  2185. }
  2186. https.get = function (params, cb) {
  2187. params = validateParams(params)
  2188. return http.get.call(this, params, cb)
  2189. }
  2190. function validateParams (params) {
  2191. if (typeof params === 'string') {
  2192. params = url.parse(params)
  2193. }
  2194. if (!params.protocol) {
  2195. params.protocol = 'https:'
  2196. }
  2197. if (params.protocol !== 'https:') {
  2198. throw new Error('Protocol "' + params.protocol + '" not supported. Expected "https:"')
  2199. }
  2200. return params
  2201. }
  2202. },{"http":17,"url":37}],7:[function(require,module,exports){
  2203. /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
  2204. exports.read = function (buffer, offset, isLE, mLen, nBytes) {
  2205. var e, m
  2206. var eLen = (nBytes * 8) - mLen - 1
  2207. var eMax = (1 << eLen) - 1
  2208. var eBias = eMax >> 1
  2209. var nBits = -7
  2210. var i = isLE ? (nBytes - 1) : 0
  2211. var d = isLE ? -1 : 1
  2212. var s = buffer[offset + i]
  2213. i += d
  2214. e = s & ((1 << (-nBits)) - 1)
  2215. s >>= (-nBits)
  2216. nBits += eLen
  2217. for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {}
  2218. m = e & ((1 << (-nBits)) - 1)
  2219. e >>= (-nBits)
  2220. nBits += mLen
  2221. for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {}
  2222. if (e === 0) {
  2223. e = 1 - eBias
  2224. } else if (e === eMax) {
  2225. return m ? NaN : ((s ? -1 : 1) * Infinity)
  2226. } else {
  2227. m = m + Math.pow(2, mLen)
  2228. e = e - eBias
  2229. }
  2230. return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
  2231. }
  2232. exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
  2233. var e, m, c
  2234. var eLen = (nBytes * 8) - mLen - 1
  2235. var eMax = (1 << eLen) - 1
  2236. var eBias = eMax >> 1
  2237. var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
  2238. var i = isLE ? 0 : (nBytes - 1)
  2239. var d = isLE ? 1 : -1
  2240. var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
  2241. value = Math.abs(value)
  2242. if (isNaN(value) || value === Infinity) {
  2243. m = isNaN(value) ? 1 : 0
  2244. e = eMax
  2245. } else {
  2246. e = Math.floor(Math.log(value) / Math.LN2)
  2247. if (value * (c = Math.pow(2, -e)) < 1) {
  2248. e--
  2249. c *= 2
  2250. }
  2251. if (e + eBias >= 1) {
  2252. value += rt / c
  2253. } else {
  2254. value += rt * Math.pow(2, 1 - eBias)
  2255. }
  2256. if (value * c >= 2) {
  2257. e++
  2258. c /= 2
  2259. }
  2260. if (e + eBias >= eMax) {
  2261. m = 0
  2262. e = eMax
  2263. } else if (e + eBias >= 1) {
  2264. m = ((value * c) - 1) * Math.pow(2, mLen)
  2265. e = e + eBias
  2266. } else {
  2267. m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
  2268. e = 0
  2269. }
  2270. }
  2271. for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
  2272. e = (e << mLen) | m
  2273. eLen += mLen
  2274. for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
  2275. buffer[offset + i - d] |= s * 128
  2276. }
  2277. },{}],8:[function(require,module,exports){
  2278. if (typeof Object.create === 'function') {
  2279. // implementation from standard node.js 'util' module
  2280. module.exports = function inherits(ctor, superCtor) {
  2281. if (superCtor) {
  2282. ctor.super_ = superCtor
  2283. ctor.prototype = Object.create(superCtor.prototype, {
  2284. constructor: {
  2285. value: ctor,
  2286. enumerable: false,
  2287. writable: true,
  2288. configurable: true
  2289. }
  2290. })
  2291. }
  2292. };
  2293. } else {
  2294. // old school shim for old browsers
  2295. module.exports = function inherits(ctor, superCtor) {
  2296. if (superCtor) {
  2297. ctor.super_ = superCtor
  2298. var TempCtor = function () {}
  2299. TempCtor.prototype = superCtor.prototype
  2300. ctor.prototype = new TempCtor()
  2301. ctor.prototype.constructor = ctor
  2302. }
  2303. }
  2304. }
  2305. },{}],9:[function(require,module,exports){
  2306. (function (global){(function (){
  2307. /**
  2308. * lodash (Custom Build) <https://lodash.com/>
  2309. * Build: `lodash modularize exports="npm" -o ./`
  2310. * Copyright jQuery Foundation and other contributors <https://jquery.org/>
  2311. * Released under MIT license <https://lodash.com/license>
  2312. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  2313. * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  2314. */
  2315. /** Used as the `TypeError` message for "Functions" methods. */
  2316. var FUNC_ERROR_TEXT = 'Expected a function';
  2317. /** Used to stand-in for `undefined` hash values. */
  2318. var HASH_UNDEFINED = '__lodash_hash_undefined__';
  2319. /** Used as references for various `Number` constants. */
  2320. var INFINITY = 1 / 0;
  2321. /** `Object#toString` result references. */
  2322. var funcTag = '[object Function]',
  2323. genTag = '[object GeneratorFunction]',
  2324. symbolTag = '[object Symbol]';
  2325. /** Used to match property names within property paths. */
  2326. var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
  2327. reIsPlainProp = /^\w*$/,
  2328. reLeadingDot = /^\./,
  2329. rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
  2330. /**
  2331. * Used to match `RegExp`
  2332. * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
  2333. */
  2334. var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
  2335. /** Used to match backslashes in property paths. */
  2336. var reEscapeChar = /\\(\\)?/g;
  2337. /** Used to detect host constructors (Safari). */
  2338. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  2339. /** Detect free variable `global` from Node.js. */
  2340. var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
  2341. /** Detect free variable `self`. */
  2342. var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
  2343. /** Used as a reference to the global object. */
  2344. var root = freeGlobal || freeSelf || Function('return this')();
  2345. /**
  2346. * Gets the value at `key` of `object`.
  2347. *
  2348. * @private
  2349. * @param {Object} [object] The object to query.
  2350. * @param {string} key The key of the property to get.
  2351. * @returns {*} Returns the property value.
  2352. */
  2353. function getValue(object, key) {
  2354. return object == null ? undefined : object[key];
  2355. }
  2356. /**
  2357. * Checks if `value` is a host object in IE < 9.
  2358. *
  2359. * @private
  2360. * @param {*} value The value to check.
  2361. * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
  2362. */
  2363. function isHostObject(value) {
  2364. // Many host objects are `Object` objects that can coerce to strings
  2365. // despite having improperly defined `toString` methods.
  2366. var result = false;
  2367. if (value != null && typeof value.toString != 'function') {
  2368. try {
  2369. result = !!(value + '');
  2370. } catch (e) {}
  2371. }
  2372. return result;
  2373. }
  2374. /** Used for built-in method references. */
  2375. var arrayProto = Array.prototype,
  2376. funcProto = Function.prototype,
  2377. objectProto = Object.prototype;
  2378. /** Used to detect overreaching core-js shims. */
  2379. var coreJsData = root['__core-js_shared__'];
  2380. /** Used to detect methods masquerading as native. */
  2381. var maskSrcKey = (function() {
  2382. var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
  2383. return uid ? ('Symbol(src)_1.' + uid) : '';
  2384. }());
  2385. /** Used to resolve the decompiled source of functions. */
  2386. var funcToString = funcProto.toString;
  2387. /** Used to check objects for own properties. */
  2388. var hasOwnProperty = objectProto.hasOwnProperty;
  2389. /**
  2390. * Used to resolve the
  2391. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  2392. * of values.
  2393. */
  2394. var objectToString = objectProto.toString;
  2395. /** Used to detect if a method is native. */
  2396. var reIsNative = RegExp('^' +
  2397. funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
  2398. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  2399. );
  2400. /** Built-in value references. */
  2401. var Symbol = root.Symbol,
  2402. splice = arrayProto.splice;
  2403. /* Built-in method references that are verified to be native. */
  2404. var Map = getNative(root, 'Map'),
  2405. nativeCreate = getNative(Object, 'create');
  2406. /** Used to convert symbols to primitives and strings. */
  2407. var symbolProto = Symbol ? Symbol.prototype : undefined,
  2408. symbolToString = symbolProto ? symbolProto.toString : undefined;
  2409. /**
  2410. * Creates a hash object.
  2411. *
  2412. * @private
  2413. * @constructor
  2414. * @param {Array} [entries] The key-value pairs to cache.
  2415. */
  2416. function Hash(entries) {
  2417. var index = -1,
  2418. length = entries ? entries.length : 0;
  2419. this.clear();
  2420. while (++index < length) {
  2421. var entry = entries[index];
  2422. this.set(entry[0], entry[1]);
  2423. }
  2424. }
  2425. /**
  2426. * Removes all key-value entries from the hash.
  2427. *
  2428. * @private
  2429. * @name clear
  2430. * @memberOf Hash
  2431. */
  2432. function hashClear() {
  2433. this.__data__ = nativeCreate ? nativeCreate(null) : {};
  2434. }
  2435. /**
  2436. * Removes `key` and its value from the hash.
  2437. *
  2438. * @private
  2439. * @name delete
  2440. * @memberOf Hash
  2441. * @param {Object} hash The hash to modify.
  2442. * @param {string} key The key of the value to remove.
  2443. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  2444. */
  2445. function hashDelete(key) {
  2446. return this.has(key) && delete this.__data__[key];
  2447. }
  2448. /**
  2449. * Gets the hash value for `key`.
  2450. *
  2451. * @private
  2452. * @name get
  2453. * @memberOf Hash
  2454. * @param {string} key The key of the value to get.
  2455. * @returns {*} Returns the entry value.
  2456. */
  2457. function hashGet(key) {
  2458. var data = this.__data__;
  2459. if (nativeCreate) {
  2460. var result = data[key];
  2461. return result === HASH_UNDEFINED ? undefined : result;
  2462. }
  2463. return hasOwnProperty.call(data, key) ? data[key] : undefined;
  2464. }
  2465. /**
  2466. * Checks if a hash value for `key` exists.
  2467. *
  2468. * @private
  2469. * @name has
  2470. * @memberOf Hash
  2471. * @param {string} key The key of the entry to check.
  2472. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  2473. */
  2474. function hashHas(key) {
  2475. var data = this.__data__;
  2476. return nativeCreate ? data[key] !== undefined : hasOwnProperty.call(data, key);
  2477. }
  2478. /**
  2479. * Sets the hash `key` to `value`.
  2480. *
  2481. * @private
  2482. * @name set
  2483. * @memberOf Hash
  2484. * @param {string} key The key of the value to set.
  2485. * @param {*} value The value to set.
  2486. * @returns {Object} Returns the hash instance.
  2487. */
  2488. function hashSet(key, value) {
  2489. var data = this.__data__;
  2490. data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
  2491. return this;
  2492. }
  2493. // Add methods to `Hash`.
  2494. Hash.prototype.clear = hashClear;
  2495. Hash.prototype['delete'] = hashDelete;
  2496. Hash.prototype.get = hashGet;
  2497. Hash.prototype.has = hashHas;
  2498. Hash.prototype.set = hashSet;
  2499. /**
  2500. * Creates an list cache object.
  2501. *
  2502. * @private
  2503. * @constructor
  2504. * @param {Array} [entries] The key-value pairs to cache.
  2505. */
  2506. function ListCache(entries) {
  2507. var index = -1,
  2508. length = entries ? entries.length : 0;
  2509. this.clear();
  2510. while (++index < length) {
  2511. var entry = entries[index];
  2512. this.set(entry[0], entry[1]);
  2513. }
  2514. }
  2515. /**
  2516. * Removes all key-value entries from the list cache.
  2517. *
  2518. * @private
  2519. * @name clear
  2520. * @memberOf ListCache
  2521. */
  2522. function listCacheClear() {
  2523. this.__data__ = [];
  2524. }
  2525. /**
  2526. * Removes `key` and its value from the list cache.
  2527. *
  2528. * @private
  2529. * @name delete
  2530. * @memberOf ListCache
  2531. * @param {string} key The key of the value to remove.
  2532. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  2533. */
  2534. function listCacheDelete(key) {
  2535. var data = this.__data__,
  2536. index = assocIndexOf(data, key);
  2537. if (index < 0) {
  2538. return false;
  2539. }
  2540. var lastIndex = data.length - 1;
  2541. if (index == lastIndex) {
  2542. data.pop();
  2543. } else {
  2544. splice.call(data, index, 1);
  2545. }
  2546. return true;
  2547. }
  2548. /**
  2549. * Gets the list cache value for `key`.
  2550. *
  2551. * @private
  2552. * @name get
  2553. * @memberOf ListCache
  2554. * @param {string} key The key of the value to get.
  2555. * @returns {*} Returns the entry value.
  2556. */
  2557. function listCacheGet(key) {
  2558. var data = this.__data__,
  2559. index = assocIndexOf(data, key);
  2560. return index < 0 ? undefined : data[index][1];
  2561. }
  2562. /**
  2563. * Checks if a list cache value for `key` exists.
  2564. *
  2565. * @private
  2566. * @name has
  2567. * @memberOf ListCache
  2568. * @param {string} key The key of the entry to check.
  2569. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  2570. */
  2571. function listCacheHas(key) {
  2572. return assocIndexOf(this.__data__, key) > -1;
  2573. }
  2574. /**
  2575. * Sets the list cache `key` to `value`.
  2576. *
  2577. * @private
  2578. * @name set
  2579. * @memberOf ListCache
  2580. * @param {string} key The key of the value to set.
  2581. * @param {*} value The value to set.
  2582. * @returns {Object} Returns the list cache instance.
  2583. */
  2584. function listCacheSet(key, value) {
  2585. var data = this.__data__,
  2586. index = assocIndexOf(data, key);
  2587. if (index < 0) {
  2588. data.push([key, value]);
  2589. } else {
  2590. data[index][1] = value;
  2591. }
  2592. return this;
  2593. }
  2594. // Add methods to `ListCache`.
  2595. ListCache.prototype.clear = listCacheClear;
  2596. ListCache.prototype['delete'] = listCacheDelete;
  2597. ListCache.prototype.get = listCacheGet;
  2598. ListCache.prototype.has = listCacheHas;
  2599. ListCache.prototype.set = listCacheSet;
  2600. /**
  2601. * Creates a map cache object to store key-value pairs.
  2602. *
  2603. * @private
  2604. * @constructor
  2605. * @param {Array} [entries] The key-value pairs to cache.
  2606. */
  2607. function MapCache(entries) {
  2608. var index = -1,
  2609. length = entries ? entries.length : 0;
  2610. this.clear();
  2611. while (++index < length) {
  2612. var entry = entries[index];
  2613. this.set(entry[0], entry[1]);
  2614. }
  2615. }
  2616. /**
  2617. * Removes all key-value entries from the map.
  2618. *
  2619. * @private
  2620. * @name clear
  2621. * @memberOf MapCache
  2622. */
  2623. function mapCacheClear() {
  2624. this.__data__ = {
  2625. 'hash': new Hash,
  2626. 'map': new (Map || ListCache),
  2627. 'string': new Hash
  2628. };
  2629. }
  2630. /**
  2631. * Removes `key` and its value from the map.
  2632. *
  2633. * @private
  2634. * @name delete
  2635. * @memberOf MapCache
  2636. * @param {string} key The key of the value to remove.
  2637. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  2638. */
  2639. function mapCacheDelete(key) {
  2640. return getMapData(this, key)['delete'](key);
  2641. }
  2642. /**
  2643. * Gets the map value for `key`.
  2644. *
  2645. * @private
  2646. * @name get
  2647. * @memberOf MapCache
  2648. * @param {string} key The key of the value to get.
  2649. * @returns {*} Returns the entry value.
  2650. */
  2651. function mapCacheGet(key) {
  2652. return getMapData(this, key).get(key);
  2653. }
  2654. /**
  2655. * Checks if a map value for `key` exists.
  2656. *
  2657. * @private
  2658. * @name has
  2659. * @memberOf MapCache
  2660. * @param {string} key The key of the entry to check.
  2661. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  2662. */
  2663. function mapCacheHas(key) {
  2664. return getMapData(this, key).has(key);
  2665. }
  2666. /**
  2667. * Sets the map `key` to `value`.
  2668. *
  2669. * @private
  2670. * @name set
  2671. * @memberOf MapCache
  2672. * @param {string} key The key of the value to set.
  2673. * @param {*} value The value to set.
  2674. * @returns {Object} Returns the map cache instance.
  2675. */
  2676. function mapCacheSet(key, value) {
  2677. getMapData(this, key).set(key, value);
  2678. return this;
  2679. }
  2680. // Add methods to `MapCache`.
  2681. MapCache.prototype.clear = mapCacheClear;
  2682. MapCache.prototype['delete'] = mapCacheDelete;
  2683. MapCache.prototype.get = mapCacheGet;
  2684. MapCache.prototype.has = mapCacheHas;
  2685. MapCache.prototype.set = mapCacheSet;
  2686. /**
  2687. * Gets the index at which the `key` is found in `array` of key-value pairs.
  2688. *
  2689. * @private
  2690. * @param {Array} array The array to inspect.
  2691. * @param {*} key The key to search for.
  2692. * @returns {number} Returns the index of the matched value, else `-1`.
  2693. */
  2694. function assocIndexOf(array, key) {
  2695. var length = array.length;
  2696. while (length--) {
  2697. if (eq(array[length][0], key)) {
  2698. return length;
  2699. }
  2700. }
  2701. return -1;
  2702. }
  2703. /**
  2704. * The base implementation of `_.get` without support for default values.
  2705. *
  2706. * @private
  2707. * @param {Object} object The object to query.
  2708. * @param {Array|string} path The path of the property to get.
  2709. * @returns {*} Returns the resolved value.
  2710. */
  2711. function baseGet(object, path) {
  2712. path = isKey(path, object) ? [path] : castPath(path);
  2713. var index = 0,
  2714. length = path.length;
  2715. while (object != null && index < length) {
  2716. object = object[toKey(path[index++])];
  2717. }
  2718. return (index && index == length) ? object : undefined;
  2719. }
  2720. /**
  2721. * The base implementation of `_.isNative` without bad shim checks.
  2722. *
  2723. * @private
  2724. * @param {*} value The value to check.
  2725. * @returns {boolean} Returns `true` if `value` is a native function,
  2726. * else `false`.
  2727. */
  2728. function baseIsNative(value) {
  2729. if (!isObject(value) || isMasked(value)) {
  2730. return false;
  2731. }
  2732. var pattern = (isFunction(value) || isHostObject(value)) ? reIsNative : reIsHostCtor;
  2733. return pattern.test(toSource(value));
  2734. }
  2735. /**
  2736. * The base implementation of `_.toString` which doesn't convert nullish
  2737. * values to empty strings.
  2738. *
  2739. * @private
  2740. * @param {*} value The value to process.
  2741. * @returns {string} Returns the string.
  2742. */
  2743. function baseToString(value) {
  2744. // Exit early for strings to avoid a performance hit in some environments.
  2745. if (typeof value == 'string') {
  2746. return value;
  2747. }
  2748. if (isSymbol(value)) {
  2749. return symbolToString ? symbolToString.call(value) : '';
  2750. }
  2751. var result = (value + '');
  2752. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  2753. }
  2754. /**
  2755. * Casts `value` to a path array if it's not one.
  2756. *
  2757. * @private
  2758. * @param {*} value The value to inspect.
  2759. * @returns {Array} Returns the cast property path array.
  2760. */
  2761. function castPath(value) {
  2762. return isArray(value) ? value : stringToPath(value);
  2763. }
  2764. /**
  2765. * Gets the data for `map`.
  2766. *
  2767. * @private
  2768. * @param {Object} map The map to query.
  2769. * @param {string} key The reference key.
  2770. * @returns {*} Returns the map data.
  2771. */
  2772. function getMapData(map, key) {
  2773. var data = map.__data__;
  2774. return isKeyable(key)
  2775. ? data[typeof key == 'string' ? 'string' : 'hash']
  2776. : data.map;
  2777. }
  2778. /**
  2779. * Gets the native function at `key` of `object`.
  2780. *
  2781. * @private
  2782. * @param {Object} object The object to query.
  2783. * @param {string} key The key of the method to get.
  2784. * @returns {*} Returns the function if it's native, else `undefined`.
  2785. */
  2786. function getNative(object, key) {
  2787. var value = getValue(object, key);
  2788. return baseIsNative(value) ? value : undefined;
  2789. }
  2790. /**
  2791. * Checks if `value` is a property name and not a property path.
  2792. *
  2793. * @private
  2794. * @param {*} value The value to check.
  2795. * @param {Object} [object] The object to query keys on.
  2796. * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
  2797. */
  2798. function isKey(value, object) {
  2799. if (isArray(value)) {
  2800. return false;
  2801. }
  2802. var type = typeof value;
  2803. if (type == 'number' || type == 'symbol' || type == 'boolean' ||
  2804. value == null || isSymbol(value)) {
  2805. return true;
  2806. }
  2807. return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
  2808. (object != null && value in Object(object));
  2809. }
  2810. /**
  2811. * Checks if `value` is suitable for use as unique object key.
  2812. *
  2813. * @private
  2814. * @param {*} value The value to check.
  2815. * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
  2816. */
  2817. function isKeyable(value) {
  2818. var type = typeof value;
  2819. return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
  2820. ? (value !== '__proto__')
  2821. : (value === null);
  2822. }
  2823. /**
  2824. * Checks if `func` has its source masked.
  2825. *
  2826. * @private
  2827. * @param {Function} func The function to check.
  2828. * @returns {boolean} Returns `true` if `func` is masked, else `false`.
  2829. */
  2830. function isMasked(func) {
  2831. return !!maskSrcKey && (maskSrcKey in func);
  2832. }
  2833. /**
  2834. * Converts `string` to a property path array.
  2835. *
  2836. * @private
  2837. * @param {string} string The string to convert.
  2838. * @returns {Array} Returns the property path array.
  2839. */
  2840. var stringToPath = memoize(function(string) {
  2841. string = toString(string);
  2842. var result = [];
  2843. if (reLeadingDot.test(string)) {
  2844. result.push('');
  2845. }
  2846. string.replace(rePropName, function(match, number, quote, string) {
  2847. result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match));
  2848. });
  2849. return result;
  2850. });
  2851. /**
  2852. * Converts `value` to a string key if it's not a string or symbol.
  2853. *
  2854. * @private
  2855. * @param {*} value The value to inspect.
  2856. * @returns {string|symbol} Returns the key.
  2857. */
  2858. function toKey(value) {
  2859. if (typeof value == 'string' || isSymbol(value)) {
  2860. return value;
  2861. }
  2862. var result = (value + '');
  2863. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  2864. }
  2865. /**
  2866. * Converts `func` to its source code.
  2867. *
  2868. * @private
  2869. * @param {Function} func The function to process.
  2870. * @returns {string} Returns the source code.
  2871. */
  2872. function toSource(func) {
  2873. if (func != null) {
  2874. try {
  2875. return funcToString.call(func);
  2876. } catch (e) {}
  2877. try {
  2878. return (func + '');
  2879. } catch (e) {}
  2880. }
  2881. return '';
  2882. }
  2883. /**
  2884. * Creates a function that memoizes the result of `func`. If `resolver` is
  2885. * provided, it determines the cache key for storing the result based on the
  2886. * arguments provided to the memoized function. By default, the first argument
  2887. * provided to the memoized function is used as the map cache key. The `func`
  2888. * is invoked with the `this` binding of the memoized function.
  2889. *
  2890. * **Note:** The cache is exposed as the `cache` property on the memoized
  2891. * function. Its creation may be customized by replacing the `_.memoize.Cache`
  2892. * constructor with one whose instances implement the
  2893. * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
  2894. * method interface of `delete`, `get`, `has`, and `set`.
  2895. *
  2896. * @static
  2897. * @memberOf _
  2898. * @since 0.1.0
  2899. * @category Function
  2900. * @param {Function} func The function to have its output memoized.
  2901. * @param {Function} [resolver] The function to resolve the cache key.
  2902. * @returns {Function} Returns the new memoized function.
  2903. * @example
  2904. *
  2905. * var object = { 'a': 1, 'b': 2 };
  2906. * var other = { 'c': 3, 'd': 4 };
  2907. *
  2908. * var values = _.memoize(_.values);
  2909. * values(object);
  2910. * // => [1, 2]
  2911. *
  2912. * values(other);
  2913. * // => [3, 4]
  2914. *
  2915. * object.a = 2;
  2916. * values(object);
  2917. * // => [1, 2]
  2918. *
  2919. * // Modify the result cache.
  2920. * values.cache.set(object, ['a', 'b']);
  2921. * values(object);
  2922. * // => ['a', 'b']
  2923. *
  2924. * // Replace `_.memoize.Cache`.
  2925. * _.memoize.Cache = WeakMap;
  2926. */
  2927. function memoize(func, resolver) {
  2928. if (typeof func != 'function' || (resolver && typeof resolver != 'function')) {
  2929. throw new TypeError(FUNC_ERROR_TEXT);
  2930. }
  2931. var memoized = function() {
  2932. var args = arguments,
  2933. key = resolver ? resolver.apply(this, args) : args[0],
  2934. cache = memoized.cache;
  2935. if (cache.has(key)) {
  2936. return cache.get(key);
  2937. }
  2938. var result = func.apply(this, args);
  2939. memoized.cache = cache.set(key, result);
  2940. return result;
  2941. };
  2942. memoized.cache = new (memoize.Cache || MapCache);
  2943. return memoized;
  2944. }
  2945. // Assign cache to `_.memoize`.
  2946. memoize.Cache = MapCache;
  2947. /**
  2948. * Performs a
  2949. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  2950. * comparison between two values to determine if they are equivalent.
  2951. *
  2952. * @static
  2953. * @memberOf _
  2954. * @since 4.0.0
  2955. * @category Lang
  2956. * @param {*} value The value to compare.
  2957. * @param {*} other The other value to compare.
  2958. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  2959. * @example
  2960. *
  2961. * var object = { 'a': 1 };
  2962. * var other = { 'a': 1 };
  2963. *
  2964. * _.eq(object, object);
  2965. * // => true
  2966. *
  2967. * _.eq(object, other);
  2968. * // => false
  2969. *
  2970. * _.eq('a', 'a');
  2971. * // => true
  2972. *
  2973. * _.eq('a', Object('a'));
  2974. * // => false
  2975. *
  2976. * _.eq(NaN, NaN);
  2977. * // => true
  2978. */
  2979. function eq(value, other) {
  2980. return value === other || (value !== value && other !== other);
  2981. }
  2982. /**
  2983. * Checks if `value` is classified as an `Array` object.
  2984. *
  2985. * @static
  2986. * @memberOf _
  2987. * @since 0.1.0
  2988. * @category Lang
  2989. * @param {*} value The value to check.
  2990. * @returns {boolean} Returns `true` if `value` is an array, else `false`.
  2991. * @example
  2992. *
  2993. * _.isArray([1, 2, 3]);
  2994. * // => true
  2995. *
  2996. * _.isArray(document.body.children);
  2997. * // => false
  2998. *
  2999. * _.isArray('abc');
  3000. * // => false
  3001. *
  3002. * _.isArray(_.noop);
  3003. * // => false
  3004. */
  3005. var isArray = Array.isArray;
  3006. /**
  3007. * Checks if `value` is classified as a `Function` object.
  3008. *
  3009. * @static
  3010. * @memberOf _
  3011. * @since 0.1.0
  3012. * @category Lang
  3013. * @param {*} value The value to check.
  3014. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  3015. * @example
  3016. *
  3017. * _.isFunction(_);
  3018. * // => true
  3019. *
  3020. * _.isFunction(/abc/);
  3021. * // => false
  3022. */
  3023. function isFunction(value) {
  3024. // The use of `Object#toString` avoids issues with the `typeof` operator
  3025. // in Safari 8-9 which returns 'object' for typed array and other constructors.
  3026. var tag = isObject(value) ? objectToString.call(value) : '';
  3027. return tag == funcTag || tag == genTag;
  3028. }
  3029. /**
  3030. * Checks if `value` is the
  3031. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  3032. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  3033. *
  3034. * @static
  3035. * @memberOf _
  3036. * @since 0.1.0
  3037. * @category Lang
  3038. * @param {*} value The value to check.
  3039. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  3040. * @example
  3041. *
  3042. * _.isObject({});
  3043. * // => true
  3044. *
  3045. * _.isObject([1, 2, 3]);
  3046. * // => true
  3047. *
  3048. * _.isObject(_.noop);
  3049. * // => true
  3050. *
  3051. * _.isObject(null);
  3052. * // => false
  3053. */
  3054. function isObject(value) {
  3055. var type = typeof value;
  3056. return !!value && (type == 'object' || type == 'function');
  3057. }
  3058. /**
  3059. * Checks if `value` is object-like. A value is object-like if it's not `null`
  3060. * and has a `typeof` result of "object".
  3061. *
  3062. * @static
  3063. * @memberOf _
  3064. * @since 4.0.0
  3065. * @category Lang
  3066. * @param {*} value The value to check.
  3067. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  3068. * @example
  3069. *
  3070. * _.isObjectLike({});
  3071. * // => true
  3072. *
  3073. * _.isObjectLike([1, 2, 3]);
  3074. * // => true
  3075. *
  3076. * _.isObjectLike(_.noop);
  3077. * // => false
  3078. *
  3079. * _.isObjectLike(null);
  3080. * // => false
  3081. */
  3082. function isObjectLike(value) {
  3083. return !!value && typeof value == 'object';
  3084. }
  3085. /**
  3086. * Checks if `value` is classified as a `Symbol` primitive or object.
  3087. *
  3088. * @static
  3089. * @memberOf _
  3090. * @since 4.0.0
  3091. * @category Lang
  3092. * @param {*} value The value to check.
  3093. * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
  3094. * @example
  3095. *
  3096. * _.isSymbol(Symbol.iterator);
  3097. * // => true
  3098. *
  3099. * _.isSymbol('abc');
  3100. * // => false
  3101. */
  3102. function isSymbol(value) {
  3103. return typeof value == 'symbol' ||
  3104. (isObjectLike(value) && objectToString.call(value) == symbolTag);
  3105. }
  3106. /**
  3107. * Converts `value` to a string. An empty string is returned for `null`
  3108. * and `undefined` values. The sign of `-0` is preserved.
  3109. *
  3110. * @static
  3111. * @memberOf _
  3112. * @since 4.0.0
  3113. * @category Lang
  3114. * @param {*} value The value to process.
  3115. * @returns {string} Returns the string.
  3116. * @example
  3117. *
  3118. * _.toString(null);
  3119. * // => ''
  3120. *
  3121. * _.toString(-0);
  3122. * // => '-0'
  3123. *
  3124. * _.toString([1, 2, 3]);
  3125. * // => '1,2,3'
  3126. */
  3127. function toString(value) {
  3128. return value == null ? '' : baseToString(value);
  3129. }
  3130. /**
  3131. * Gets the value at `path` of `object`. If the resolved value is
  3132. * `undefined`, the `defaultValue` is returned in its place.
  3133. *
  3134. * @static
  3135. * @memberOf _
  3136. * @since 3.7.0
  3137. * @category Object
  3138. * @param {Object} object The object to query.
  3139. * @param {Array|string} path The path of the property to get.
  3140. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  3141. * @returns {*} Returns the resolved value.
  3142. * @example
  3143. *
  3144. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  3145. *
  3146. * _.get(object, 'a[0].b.c');
  3147. * // => 3
  3148. *
  3149. * _.get(object, ['a', '0', 'b', 'c']);
  3150. * // => 3
  3151. *
  3152. * _.get(object, 'a.b.c', 'default');
  3153. * // => 'default'
  3154. */
  3155. function get(object, path, defaultValue) {
  3156. var result = object == null ? undefined : baseGet(object, path);
  3157. return result === undefined ? defaultValue : result;
  3158. }
  3159. module.exports = get;
  3160. }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  3161. },{}],10:[function(require,module,exports){
  3162. (function (global){(function (){
  3163. /**
  3164. * Lodash (Custom Build) <https://lodash.com/>
  3165. * Build: `lodash modularize exports="npm" -o ./`
  3166. * Copyright JS Foundation and other contributors <https://js.foundation/>
  3167. * Released under MIT license <https://lodash.com/license>
  3168. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  3169. * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  3170. */
  3171. /** Used as the size to enable large array optimizations. */
  3172. var LARGE_ARRAY_SIZE = 200;
  3173. /** Used to stand-in for `undefined` hash values. */
  3174. var HASH_UNDEFINED = '__lodash_hash_undefined__';
  3175. /** Used to compose bitmasks for value comparisons. */
  3176. var COMPARE_PARTIAL_FLAG = 1,
  3177. COMPARE_UNORDERED_FLAG = 2;
  3178. /** Used as references for various `Number` constants. */
  3179. var MAX_SAFE_INTEGER = 9007199254740991;
  3180. /** `Object#toString` result references. */
  3181. var argsTag = '[object Arguments]',
  3182. arrayTag = '[object Array]',
  3183. asyncTag = '[object AsyncFunction]',
  3184. boolTag = '[object Boolean]',
  3185. dateTag = '[object Date]',
  3186. errorTag = '[object Error]',
  3187. funcTag = '[object Function]',
  3188. genTag = '[object GeneratorFunction]',
  3189. mapTag = '[object Map]',
  3190. numberTag = '[object Number]',
  3191. nullTag = '[object Null]',
  3192. objectTag = '[object Object]',
  3193. promiseTag = '[object Promise]',
  3194. proxyTag = '[object Proxy]',
  3195. regexpTag = '[object RegExp]',
  3196. setTag = '[object Set]',
  3197. stringTag = '[object String]',
  3198. symbolTag = '[object Symbol]',
  3199. undefinedTag = '[object Undefined]',
  3200. weakMapTag = '[object WeakMap]';
  3201. var arrayBufferTag = '[object ArrayBuffer]',
  3202. dataViewTag = '[object DataView]',
  3203. float32Tag = '[object Float32Array]',
  3204. float64Tag = '[object Float64Array]',
  3205. int8Tag = '[object Int8Array]',
  3206. int16Tag = '[object Int16Array]',
  3207. int32Tag = '[object Int32Array]',
  3208. uint8Tag = '[object Uint8Array]',
  3209. uint8ClampedTag = '[object Uint8ClampedArray]',
  3210. uint16Tag = '[object Uint16Array]',
  3211. uint32Tag = '[object Uint32Array]';
  3212. /**
  3213. * Used to match `RegExp`
  3214. * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
  3215. */
  3216. var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
  3217. /** Used to detect host constructors (Safari). */
  3218. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  3219. /** Used to detect unsigned integer values. */
  3220. var reIsUint = /^(?:0|[1-9]\d*)$/;
  3221. /** Used to identify `toStringTag` values of typed arrays. */
  3222. var typedArrayTags = {};
  3223. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
  3224. typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
  3225. typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
  3226. typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
  3227. typedArrayTags[uint32Tag] = true;
  3228. typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
  3229. typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
  3230. typedArrayTags[dataViewTag] = typedArrayTags[dateTag] =
  3231. typedArrayTags[errorTag] = typedArrayTags[funcTag] =
  3232. typedArrayTags[mapTag] = typedArrayTags[numberTag] =
  3233. typedArrayTags[objectTag] = typedArrayTags[regexpTag] =
  3234. typedArrayTags[setTag] = typedArrayTags[stringTag] =
  3235. typedArrayTags[weakMapTag] = false;
  3236. /** Detect free variable `global` from Node.js. */
  3237. var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
  3238. /** Detect free variable `self`. */
  3239. var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
  3240. /** Used as a reference to the global object. */
  3241. var root = freeGlobal || freeSelf || Function('return this')();
  3242. /** Detect free variable `exports`. */
  3243. var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;
  3244. /** Detect free variable `module`. */
  3245. var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;
  3246. /** Detect the popular CommonJS extension `module.exports`. */
  3247. var moduleExports = freeModule && freeModule.exports === freeExports;
  3248. /** Detect free variable `process` from Node.js. */
  3249. var freeProcess = moduleExports && freeGlobal.process;
  3250. /** Used to access faster Node.js helpers. */
  3251. var nodeUtil = (function() {
  3252. try {
  3253. return freeProcess && freeProcess.binding && freeProcess.binding('util');
  3254. } catch (e) {}
  3255. }());
  3256. /* Node.js helper references. */
  3257. var nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
  3258. /**
  3259. * A specialized version of `_.filter` for arrays without support for
  3260. * iteratee shorthands.
  3261. *
  3262. * @private
  3263. * @param {Array} [array] The array to iterate over.
  3264. * @param {Function} predicate The function invoked per iteration.
  3265. * @returns {Array} Returns the new filtered array.
  3266. */
  3267. function arrayFilter(array, predicate) {
  3268. var index = -1,
  3269. length = array == null ? 0 : array.length,
  3270. resIndex = 0,
  3271. result = [];
  3272. while (++index < length) {
  3273. var value = array[index];
  3274. if (predicate(value, index, array)) {
  3275. result[resIndex++] = value;
  3276. }
  3277. }
  3278. return result;
  3279. }
  3280. /**
  3281. * Appends the elements of `values` to `array`.
  3282. *
  3283. * @private
  3284. * @param {Array} array The array to modify.
  3285. * @param {Array} values The values to append.
  3286. * @returns {Array} Returns `array`.
  3287. */
  3288. function arrayPush(array, values) {
  3289. var index = -1,
  3290. length = values.length,
  3291. offset = array.length;
  3292. while (++index < length) {
  3293. array[offset + index] = values[index];
  3294. }
  3295. return array;
  3296. }
  3297. /**
  3298. * A specialized version of `_.some` for arrays without support for iteratee
  3299. * shorthands.
  3300. *
  3301. * @private
  3302. * @param {Array} [array] The array to iterate over.
  3303. * @param {Function} predicate The function invoked per iteration.
  3304. * @returns {boolean} Returns `true` if any element passes the predicate check,
  3305. * else `false`.
  3306. */
  3307. function arraySome(array, predicate) {
  3308. var index = -1,
  3309. length = array == null ? 0 : array.length;
  3310. while (++index < length) {
  3311. if (predicate(array[index], index, array)) {
  3312. return true;
  3313. }
  3314. }
  3315. return false;
  3316. }
  3317. /**
  3318. * The base implementation of `_.times` without support for iteratee shorthands
  3319. * or max array length checks.
  3320. *
  3321. * @private
  3322. * @param {number} n The number of times to invoke `iteratee`.
  3323. * @param {Function} iteratee The function invoked per iteration.
  3324. * @returns {Array} Returns the array of results.
  3325. */
  3326. function baseTimes(n, iteratee) {
  3327. var index = -1,
  3328. result = Array(n);
  3329. while (++index < n) {
  3330. result[index] = iteratee(index);
  3331. }
  3332. return result;
  3333. }
  3334. /**
  3335. * The base implementation of `_.unary` without support for storing metadata.
  3336. *
  3337. * @private
  3338. * @param {Function} func The function to cap arguments for.
  3339. * @returns {Function} Returns the new capped function.
  3340. */
  3341. function baseUnary(func) {
  3342. return function(value) {
  3343. return func(value);
  3344. };
  3345. }
  3346. /**
  3347. * Checks if a `cache` value for `key` exists.
  3348. *
  3349. * @private
  3350. * @param {Object} cache The cache to query.
  3351. * @param {string} key The key of the entry to check.
  3352. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  3353. */
  3354. function cacheHas(cache, key) {
  3355. return cache.has(key);
  3356. }
  3357. /**
  3358. * Gets the value at `key` of `object`.
  3359. *
  3360. * @private
  3361. * @param {Object} [object] The object to query.
  3362. * @param {string} key The key of the property to get.
  3363. * @returns {*} Returns the property value.
  3364. */
  3365. function getValue(object, key) {
  3366. return object == null ? undefined : object[key];
  3367. }
  3368. /**
  3369. * Converts `map` to its key-value pairs.
  3370. *
  3371. * @private
  3372. * @param {Object} map The map to convert.
  3373. * @returns {Array} Returns the key-value pairs.
  3374. */
  3375. function mapToArray(map) {
  3376. var index = -1,
  3377. result = Array(map.size);
  3378. map.forEach(function(value, key) {
  3379. result[++index] = [key, value];
  3380. });
  3381. return result;
  3382. }
  3383. /**
  3384. * Creates a unary function that invokes `func` with its argument transformed.
  3385. *
  3386. * @private
  3387. * @param {Function} func The function to wrap.
  3388. * @param {Function} transform The argument transform.
  3389. * @returns {Function} Returns the new function.
  3390. */
  3391. function overArg(func, transform) {
  3392. return function(arg) {
  3393. return func(transform(arg));
  3394. };
  3395. }
  3396. /**
  3397. * Converts `set` to an array of its values.
  3398. *
  3399. * @private
  3400. * @param {Object} set The set to convert.
  3401. * @returns {Array} Returns the values.
  3402. */
  3403. function setToArray(set) {
  3404. var index = -1,
  3405. result = Array(set.size);
  3406. set.forEach(function(value) {
  3407. result[++index] = value;
  3408. });
  3409. return result;
  3410. }
  3411. /** Used for built-in method references. */
  3412. var arrayProto = Array.prototype,
  3413. funcProto = Function.prototype,
  3414. objectProto = Object.prototype;
  3415. /** Used to detect overreaching core-js shims. */
  3416. var coreJsData = root['__core-js_shared__'];
  3417. /** Used to resolve the decompiled source of functions. */
  3418. var funcToString = funcProto.toString;
  3419. /** Used to check objects for own properties. */
  3420. var hasOwnProperty = objectProto.hasOwnProperty;
  3421. /** Used to detect methods masquerading as native. */
  3422. var maskSrcKey = (function() {
  3423. var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
  3424. return uid ? ('Symbol(src)_1.' + uid) : '';
  3425. }());
  3426. /**
  3427. * Used to resolve the
  3428. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  3429. * of values.
  3430. */
  3431. var nativeObjectToString = objectProto.toString;
  3432. /** Used to detect if a method is native. */
  3433. var reIsNative = RegExp('^' +
  3434. funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
  3435. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  3436. );
  3437. /** Built-in value references. */
  3438. var Buffer = moduleExports ? root.Buffer : undefined,
  3439. Symbol = root.Symbol,
  3440. Uint8Array = root.Uint8Array,
  3441. propertyIsEnumerable = objectProto.propertyIsEnumerable,
  3442. splice = arrayProto.splice,
  3443. symToStringTag = Symbol ? Symbol.toStringTag : undefined;
  3444. /* Built-in method references for those with the same name as other `lodash` methods. */
  3445. var nativeGetSymbols = Object.getOwnPropertySymbols,
  3446. nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined,
  3447. nativeKeys = overArg(Object.keys, Object);
  3448. /* Built-in method references that are verified to be native. */
  3449. var DataView = getNative(root, 'DataView'),
  3450. Map = getNative(root, 'Map'),
  3451. Promise = getNative(root, 'Promise'),
  3452. Set = getNative(root, 'Set'),
  3453. WeakMap = getNative(root, 'WeakMap'),
  3454. nativeCreate = getNative(Object, 'create');
  3455. /** Used to detect maps, sets, and weakmaps. */
  3456. var dataViewCtorString = toSource(DataView),
  3457. mapCtorString = toSource(Map),
  3458. promiseCtorString = toSource(Promise),
  3459. setCtorString = toSource(Set),
  3460. weakMapCtorString = toSource(WeakMap);
  3461. /** Used to convert symbols to primitives and strings. */
  3462. var symbolProto = Symbol ? Symbol.prototype : undefined,
  3463. symbolValueOf = symbolProto ? symbolProto.valueOf : undefined;
  3464. /**
  3465. * Creates a hash object.
  3466. *
  3467. * @private
  3468. * @constructor
  3469. * @param {Array} [entries] The key-value pairs to cache.
  3470. */
  3471. function Hash(entries) {
  3472. var index = -1,
  3473. length = entries == null ? 0 : entries.length;
  3474. this.clear();
  3475. while (++index < length) {
  3476. var entry = entries[index];
  3477. this.set(entry[0], entry[1]);
  3478. }
  3479. }
  3480. /**
  3481. * Removes all key-value entries from the hash.
  3482. *
  3483. * @private
  3484. * @name clear
  3485. * @memberOf Hash
  3486. */
  3487. function hashClear() {
  3488. this.__data__ = nativeCreate ? nativeCreate(null) : {};
  3489. this.size = 0;
  3490. }
  3491. /**
  3492. * Removes `key` and its value from the hash.
  3493. *
  3494. * @private
  3495. * @name delete
  3496. * @memberOf Hash
  3497. * @param {Object} hash The hash to modify.
  3498. * @param {string} key The key of the value to remove.
  3499. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  3500. */
  3501. function hashDelete(key) {
  3502. var result = this.has(key) && delete this.__data__[key];
  3503. this.size -= result ? 1 : 0;
  3504. return result;
  3505. }
  3506. /**
  3507. * Gets the hash value for `key`.
  3508. *
  3509. * @private
  3510. * @name get
  3511. * @memberOf Hash
  3512. * @param {string} key The key of the value to get.
  3513. * @returns {*} Returns the entry value.
  3514. */
  3515. function hashGet(key) {
  3516. var data = this.__data__;
  3517. if (nativeCreate) {
  3518. var result = data[key];
  3519. return result === HASH_UNDEFINED ? undefined : result;
  3520. }
  3521. return hasOwnProperty.call(data, key) ? data[key] : undefined;
  3522. }
  3523. /**
  3524. * Checks if a hash value for `key` exists.
  3525. *
  3526. * @private
  3527. * @name has
  3528. * @memberOf Hash
  3529. * @param {string} key The key of the entry to check.
  3530. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  3531. */
  3532. function hashHas(key) {
  3533. var data = this.__data__;
  3534. return nativeCreate ? (data[key] !== undefined) : hasOwnProperty.call(data, key);
  3535. }
  3536. /**
  3537. * Sets the hash `key` to `value`.
  3538. *
  3539. * @private
  3540. * @name set
  3541. * @memberOf Hash
  3542. * @param {string} key The key of the value to set.
  3543. * @param {*} value The value to set.
  3544. * @returns {Object} Returns the hash instance.
  3545. */
  3546. function hashSet(key, value) {
  3547. var data = this.__data__;
  3548. this.size += this.has(key) ? 0 : 1;
  3549. data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
  3550. return this;
  3551. }
  3552. // Add methods to `Hash`.
  3553. Hash.prototype.clear = hashClear;
  3554. Hash.prototype['delete'] = hashDelete;
  3555. Hash.prototype.get = hashGet;
  3556. Hash.prototype.has = hashHas;
  3557. Hash.prototype.set = hashSet;
  3558. /**
  3559. * Creates an list cache object.
  3560. *
  3561. * @private
  3562. * @constructor
  3563. * @param {Array} [entries] The key-value pairs to cache.
  3564. */
  3565. function ListCache(entries) {
  3566. var index = -1,
  3567. length = entries == null ? 0 : entries.length;
  3568. this.clear();
  3569. while (++index < length) {
  3570. var entry = entries[index];
  3571. this.set(entry[0], entry[1]);
  3572. }
  3573. }
  3574. /**
  3575. * Removes all key-value entries from the list cache.
  3576. *
  3577. * @private
  3578. * @name clear
  3579. * @memberOf ListCache
  3580. */
  3581. function listCacheClear() {
  3582. this.__data__ = [];
  3583. this.size = 0;
  3584. }
  3585. /**
  3586. * Removes `key` and its value from the list cache.
  3587. *
  3588. * @private
  3589. * @name delete
  3590. * @memberOf ListCache
  3591. * @param {string} key The key of the value to remove.
  3592. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  3593. */
  3594. function listCacheDelete(key) {
  3595. var data = this.__data__,
  3596. index = assocIndexOf(data, key);
  3597. if (index < 0) {
  3598. return false;
  3599. }
  3600. var lastIndex = data.length - 1;
  3601. if (index == lastIndex) {
  3602. data.pop();
  3603. } else {
  3604. splice.call(data, index, 1);
  3605. }
  3606. --this.size;
  3607. return true;
  3608. }
  3609. /**
  3610. * Gets the list cache value for `key`.
  3611. *
  3612. * @private
  3613. * @name get
  3614. * @memberOf ListCache
  3615. * @param {string} key The key of the value to get.
  3616. * @returns {*} Returns the entry value.
  3617. */
  3618. function listCacheGet(key) {
  3619. var data = this.__data__,
  3620. index = assocIndexOf(data, key);
  3621. return index < 0 ? undefined : data[index][1];
  3622. }
  3623. /**
  3624. * Checks if a list cache value for `key` exists.
  3625. *
  3626. * @private
  3627. * @name has
  3628. * @memberOf ListCache
  3629. * @param {string} key The key of the entry to check.
  3630. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  3631. */
  3632. function listCacheHas(key) {
  3633. return assocIndexOf(this.__data__, key) > -1;
  3634. }
  3635. /**
  3636. * Sets the list cache `key` to `value`.
  3637. *
  3638. * @private
  3639. * @name set
  3640. * @memberOf ListCache
  3641. * @param {string} key The key of the value to set.
  3642. * @param {*} value The value to set.
  3643. * @returns {Object} Returns the list cache instance.
  3644. */
  3645. function listCacheSet(key, value) {
  3646. var data = this.__data__,
  3647. index = assocIndexOf(data, key);
  3648. if (index < 0) {
  3649. ++this.size;
  3650. data.push([key, value]);
  3651. } else {
  3652. data[index][1] = value;
  3653. }
  3654. return this;
  3655. }
  3656. // Add methods to `ListCache`.
  3657. ListCache.prototype.clear = listCacheClear;
  3658. ListCache.prototype['delete'] = listCacheDelete;
  3659. ListCache.prototype.get = listCacheGet;
  3660. ListCache.prototype.has = listCacheHas;
  3661. ListCache.prototype.set = listCacheSet;
  3662. /**
  3663. * Creates a map cache object to store key-value pairs.
  3664. *
  3665. * @private
  3666. * @constructor
  3667. * @param {Array} [entries] The key-value pairs to cache.
  3668. */
  3669. function MapCache(entries) {
  3670. var index = -1,
  3671. length = entries == null ? 0 : entries.length;
  3672. this.clear();
  3673. while (++index < length) {
  3674. var entry = entries[index];
  3675. this.set(entry[0], entry[1]);
  3676. }
  3677. }
  3678. /**
  3679. * Removes all key-value entries from the map.
  3680. *
  3681. * @private
  3682. * @name clear
  3683. * @memberOf MapCache
  3684. */
  3685. function mapCacheClear() {
  3686. this.size = 0;
  3687. this.__data__ = {
  3688. 'hash': new Hash,
  3689. 'map': new (Map || ListCache),
  3690. 'string': new Hash
  3691. };
  3692. }
  3693. /**
  3694. * Removes `key` and its value from the map.
  3695. *
  3696. * @private
  3697. * @name delete
  3698. * @memberOf MapCache
  3699. * @param {string} key The key of the value to remove.
  3700. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  3701. */
  3702. function mapCacheDelete(key) {
  3703. var result = getMapData(this, key)['delete'](key);
  3704. this.size -= result ? 1 : 0;
  3705. return result;
  3706. }
  3707. /**
  3708. * Gets the map value for `key`.
  3709. *
  3710. * @private
  3711. * @name get
  3712. * @memberOf MapCache
  3713. * @param {string} key The key of the value to get.
  3714. * @returns {*} Returns the entry value.
  3715. */
  3716. function mapCacheGet(key) {
  3717. return getMapData(this, key).get(key);
  3718. }
  3719. /**
  3720. * Checks if a map value for `key` exists.
  3721. *
  3722. * @private
  3723. * @name has
  3724. * @memberOf MapCache
  3725. * @param {string} key The key of the entry to check.
  3726. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  3727. */
  3728. function mapCacheHas(key) {
  3729. return getMapData(this, key).has(key);
  3730. }
  3731. /**
  3732. * Sets the map `key` to `value`.
  3733. *
  3734. * @private
  3735. * @name set
  3736. * @memberOf MapCache
  3737. * @param {string} key The key of the value to set.
  3738. * @param {*} value The value to set.
  3739. * @returns {Object} Returns the map cache instance.
  3740. */
  3741. function mapCacheSet(key, value) {
  3742. var data = getMapData(this, key),
  3743. size = data.size;
  3744. data.set(key, value);
  3745. this.size += data.size == size ? 0 : 1;
  3746. return this;
  3747. }
  3748. // Add methods to `MapCache`.
  3749. MapCache.prototype.clear = mapCacheClear;
  3750. MapCache.prototype['delete'] = mapCacheDelete;
  3751. MapCache.prototype.get = mapCacheGet;
  3752. MapCache.prototype.has = mapCacheHas;
  3753. MapCache.prototype.set = mapCacheSet;
  3754. /**
  3755. *
  3756. * Creates an array cache object to store unique values.
  3757. *
  3758. * @private
  3759. * @constructor
  3760. * @param {Array} [values] The values to cache.
  3761. */
  3762. function SetCache(values) {
  3763. var index = -1,
  3764. length = values == null ? 0 : values.length;
  3765. this.__data__ = new MapCache;
  3766. while (++index < length) {
  3767. this.add(values[index]);
  3768. }
  3769. }
  3770. /**
  3771. * Adds `value` to the array cache.
  3772. *
  3773. * @private
  3774. * @name add
  3775. * @memberOf SetCache
  3776. * @alias push
  3777. * @param {*} value The value to cache.
  3778. * @returns {Object} Returns the cache instance.
  3779. */
  3780. function setCacheAdd(value) {
  3781. this.__data__.set(value, HASH_UNDEFINED);
  3782. return this;
  3783. }
  3784. /**
  3785. * Checks if `value` is in the array cache.
  3786. *
  3787. * @private
  3788. * @name has
  3789. * @memberOf SetCache
  3790. * @param {*} value The value to search for.
  3791. * @returns {number} Returns `true` if `value` is found, else `false`.
  3792. */
  3793. function setCacheHas(value) {
  3794. return this.__data__.has(value);
  3795. }
  3796. // Add methods to `SetCache`.
  3797. SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
  3798. SetCache.prototype.has = setCacheHas;
  3799. /**
  3800. * Creates a stack cache object to store key-value pairs.
  3801. *
  3802. * @private
  3803. * @constructor
  3804. * @param {Array} [entries] The key-value pairs to cache.
  3805. */
  3806. function Stack(entries) {
  3807. var data = this.__data__ = new ListCache(entries);
  3808. this.size = data.size;
  3809. }
  3810. /**
  3811. * Removes all key-value entries from the stack.
  3812. *
  3813. * @private
  3814. * @name clear
  3815. * @memberOf Stack
  3816. */
  3817. function stackClear() {
  3818. this.__data__ = new ListCache;
  3819. this.size = 0;
  3820. }
  3821. /**
  3822. * Removes `key` and its value from the stack.
  3823. *
  3824. * @private
  3825. * @name delete
  3826. * @memberOf Stack
  3827. * @param {string} key The key of the value to remove.
  3828. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  3829. */
  3830. function stackDelete(key) {
  3831. var data = this.__data__,
  3832. result = data['delete'](key);
  3833. this.size = data.size;
  3834. return result;
  3835. }
  3836. /**
  3837. * Gets the stack value for `key`.
  3838. *
  3839. * @private
  3840. * @name get
  3841. * @memberOf Stack
  3842. * @param {string} key The key of the value to get.
  3843. * @returns {*} Returns the entry value.
  3844. */
  3845. function stackGet(key) {
  3846. return this.__data__.get(key);
  3847. }
  3848. /**
  3849. * Checks if a stack value for `key` exists.
  3850. *
  3851. * @private
  3852. * @name has
  3853. * @memberOf Stack
  3854. * @param {string} key The key of the entry to check.
  3855. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  3856. */
  3857. function stackHas(key) {
  3858. return this.__data__.has(key);
  3859. }
  3860. /**
  3861. * Sets the stack `key` to `value`.
  3862. *
  3863. * @private
  3864. * @name set
  3865. * @memberOf Stack
  3866. * @param {string} key The key of the value to set.
  3867. * @param {*} value The value to set.
  3868. * @returns {Object} Returns the stack cache instance.
  3869. */
  3870. function stackSet(key, value) {
  3871. var data = this.__data__;
  3872. if (data instanceof ListCache) {
  3873. var pairs = data.__data__;
  3874. if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) {
  3875. pairs.push([key, value]);
  3876. this.size = ++data.size;
  3877. return this;
  3878. }
  3879. data = this.__data__ = new MapCache(pairs);
  3880. }
  3881. data.set(key, value);
  3882. this.size = data.size;
  3883. return this;
  3884. }
  3885. // Add methods to `Stack`.
  3886. Stack.prototype.clear = stackClear;
  3887. Stack.prototype['delete'] = stackDelete;
  3888. Stack.prototype.get = stackGet;
  3889. Stack.prototype.has = stackHas;
  3890. Stack.prototype.set = stackSet;
  3891. /**
  3892. * Creates an array of the enumerable property names of the array-like `value`.
  3893. *
  3894. * @private
  3895. * @param {*} value The value to query.
  3896. * @param {boolean} inherited Specify returning inherited property names.
  3897. * @returns {Array} Returns the array of property names.
  3898. */
  3899. function arrayLikeKeys(value, inherited) {
  3900. var isArr = isArray(value),
  3901. isArg = !isArr && isArguments(value),
  3902. isBuff = !isArr && !isArg && isBuffer(value),
  3903. isType = !isArr && !isArg && !isBuff && isTypedArray(value),
  3904. skipIndexes = isArr || isArg || isBuff || isType,
  3905. result = skipIndexes ? baseTimes(value.length, String) : [],
  3906. length = result.length;
  3907. for (var key in value) {
  3908. if ((inherited || hasOwnProperty.call(value, key)) &&
  3909. !(skipIndexes && (
  3910. // Safari 9 has enumerable `arguments.length` in strict mode.
  3911. key == 'length' ||
  3912. // Node.js 0.10 has enumerable non-index properties on buffers.
  3913. (isBuff && (key == 'offset' || key == 'parent')) ||
  3914. // PhantomJS 2 has enumerable non-index properties on typed arrays.
  3915. (isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) ||
  3916. // Skip index properties.
  3917. isIndex(key, length)
  3918. ))) {
  3919. result.push(key);
  3920. }
  3921. }
  3922. return result;
  3923. }
  3924. /**
  3925. * Gets the index at which the `key` is found in `array` of key-value pairs.
  3926. *
  3927. * @private
  3928. * @param {Array} array The array to inspect.
  3929. * @param {*} key The key to search for.
  3930. * @returns {number} Returns the index of the matched value, else `-1`.
  3931. */
  3932. function assocIndexOf(array, key) {
  3933. var length = array.length;
  3934. while (length--) {
  3935. if (eq(array[length][0], key)) {
  3936. return length;
  3937. }
  3938. }
  3939. return -1;
  3940. }
  3941. /**
  3942. * The base implementation of `getAllKeys` and `getAllKeysIn` which uses
  3943. * `keysFunc` and `symbolsFunc` to get the enumerable property names and
  3944. * symbols of `object`.
  3945. *
  3946. * @private
  3947. * @param {Object} object The object to query.
  3948. * @param {Function} keysFunc The function to get the keys of `object`.
  3949. * @param {Function} symbolsFunc The function to get the symbols of `object`.
  3950. * @returns {Array} Returns the array of property names and symbols.
  3951. */
  3952. function baseGetAllKeys(object, keysFunc, symbolsFunc) {
  3953. var result = keysFunc(object);
  3954. return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
  3955. }
  3956. /**
  3957. * The base implementation of `getTag` without fallbacks for buggy environments.
  3958. *
  3959. * @private
  3960. * @param {*} value The value to query.
  3961. * @returns {string} Returns the `toStringTag`.
  3962. */
  3963. function baseGetTag(value) {
  3964. if (value == null) {
  3965. return value === undefined ? undefinedTag : nullTag;
  3966. }
  3967. return (symToStringTag && symToStringTag in Object(value))
  3968. ? getRawTag(value)
  3969. : objectToString(value);
  3970. }
  3971. /**
  3972. * The base implementation of `_.isArguments`.
  3973. *
  3974. * @private
  3975. * @param {*} value The value to check.
  3976. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  3977. */
  3978. function baseIsArguments(value) {
  3979. return isObjectLike(value) && baseGetTag(value) == argsTag;
  3980. }
  3981. /**
  3982. * The base implementation of `_.isEqual` which supports partial comparisons
  3983. * and tracks traversed objects.
  3984. *
  3985. * @private
  3986. * @param {*} value The value to compare.
  3987. * @param {*} other The other value to compare.
  3988. * @param {boolean} bitmask The bitmask flags.
  3989. * 1 - Unordered comparison
  3990. * 2 - Partial comparison
  3991. * @param {Function} [customizer] The function to customize comparisons.
  3992. * @param {Object} [stack] Tracks traversed `value` and `other` objects.
  3993. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  3994. */
  3995. function baseIsEqual(value, other, bitmask, customizer, stack) {
  3996. if (value === other) {
  3997. return true;
  3998. }
  3999. if (value == null || other == null || (!isObjectLike(value) && !isObjectLike(other))) {
  4000. return value !== value && other !== other;
  4001. }
  4002. return baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack);
  4003. }
  4004. /**
  4005. * A specialized version of `baseIsEqual` for arrays and objects which performs
  4006. * deep comparisons and tracks traversed objects enabling objects with circular
  4007. * references to be compared.
  4008. *
  4009. * @private
  4010. * @param {Object} object The object to compare.
  4011. * @param {Object} other The other object to compare.
  4012. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  4013. * @param {Function} customizer The function to customize comparisons.
  4014. * @param {Function} equalFunc The function to determine equivalents of values.
  4015. * @param {Object} [stack] Tracks traversed `object` and `other` objects.
  4016. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  4017. */
  4018. function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) {
  4019. var objIsArr = isArray(object),
  4020. othIsArr = isArray(other),
  4021. objTag = objIsArr ? arrayTag : getTag(object),
  4022. othTag = othIsArr ? arrayTag : getTag(other);
  4023. objTag = objTag == argsTag ? objectTag : objTag;
  4024. othTag = othTag == argsTag ? objectTag : othTag;
  4025. var objIsObj = objTag == objectTag,
  4026. othIsObj = othTag == objectTag,
  4027. isSameTag = objTag == othTag;
  4028. if (isSameTag && isBuffer(object)) {
  4029. if (!isBuffer(other)) {
  4030. return false;
  4031. }
  4032. objIsArr = true;
  4033. objIsObj = false;
  4034. }
  4035. if (isSameTag && !objIsObj) {
  4036. stack || (stack = new Stack);
  4037. return (objIsArr || isTypedArray(object))
  4038. ? equalArrays(object, other, bitmask, customizer, equalFunc, stack)
  4039. : equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack);
  4040. }
  4041. if (!(bitmask & COMPARE_PARTIAL_FLAG)) {
  4042. var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
  4043. othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
  4044. if (objIsWrapped || othIsWrapped) {
  4045. var objUnwrapped = objIsWrapped ? object.value() : object,
  4046. othUnwrapped = othIsWrapped ? other.value() : other;
  4047. stack || (stack = new Stack);
  4048. return equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack);
  4049. }
  4050. }
  4051. if (!isSameTag) {
  4052. return false;
  4053. }
  4054. stack || (stack = new Stack);
  4055. return equalObjects(object, other, bitmask, customizer, equalFunc, stack);
  4056. }
  4057. /**
  4058. * The base implementation of `_.isNative` without bad shim checks.
  4059. *
  4060. * @private
  4061. * @param {*} value The value to check.
  4062. * @returns {boolean} Returns `true` if `value` is a native function,
  4063. * else `false`.
  4064. */
  4065. function baseIsNative(value) {
  4066. if (!isObject(value) || isMasked(value)) {
  4067. return false;
  4068. }
  4069. var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
  4070. return pattern.test(toSource(value));
  4071. }
  4072. /**
  4073. * The base implementation of `_.isTypedArray` without Node.js optimizations.
  4074. *
  4075. * @private
  4076. * @param {*} value The value to check.
  4077. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  4078. */
  4079. function baseIsTypedArray(value) {
  4080. return isObjectLike(value) &&
  4081. isLength(value.length) && !!typedArrayTags[baseGetTag(value)];
  4082. }
  4083. /**
  4084. * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
  4085. *
  4086. * @private
  4087. * @param {Object} object The object to query.
  4088. * @returns {Array} Returns the array of property names.
  4089. */
  4090. function baseKeys(object) {
  4091. if (!isPrototype(object)) {
  4092. return nativeKeys(object);
  4093. }
  4094. var result = [];
  4095. for (var key in Object(object)) {
  4096. if (hasOwnProperty.call(object, key) && key != 'constructor') {
  4097. result.push(key);
  4098. }
  4099. }
  4100. return result;
  4101. }
  4102. /**
  4103. * A specialized version of `baseIsEqualDeep` for arrays with support for
  4104. * partial deep comparisons.
  4105. *
  4106. * @private
  4107. * @param {Array} array The array to compare.
  4108. * @param {Array} other The other array to compare.
  4109. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  4110. * @param {Function} customizer The function to customize comparisons.
  4111. * @param {Function} equalFunc The function to determine equivalents of values.
  4112. * @param {Object} stack Tracks traversed `array` and `other` objects.
  4113. * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
  4114. */
  4115. function equalArrays(array, other, bitmask, customizer, equalFunc, stack) {
  4116. var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
  4117. arrLength = array.length,
  4118. othLength = other.length;
  4119. if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
  4120. return false;
  4121. }
  4122. // Assume cyclic values are equal.
  4123. var stacked = stack.get(array);
  4124. if (stacked && stack.get(other)) {
  4125. return stacked == other;
  4126. }
  4127. var index = -1,
  4128. result = true,
  4129. seen = (bitmask & COMPARE_UNORDERED_FLAG) ? new SetCache : undefined;
  4130. stack.set(array, other);
  4131. stack.set(other, array);
  4132. // Ignore non-index properties.
  4133. while (++index < arrLength) {
  4134. var arrValue = array[index],
  4135. othValue = other[index];
  4136. if (customizer) {
  4137. var compared = isPartial
  4138. ? customizer(othValue, arrValue, index, other, array, stack)
  4139. : customizer(arrValue, othValue, index, array, other, stack);
  4140. }
  4141. if (compared !== undefined) {
  4142. if (compared) {
  4143. continue;
  4144. }
  4145. result = false;
  4146. break;
  4147. }
  4148. // Recursively compare arrays (susceptible to call stack limits).
  4149. if (seen) {
  4150. if (!arraySome(other, function(othValue, othIndex) {
  4151. if (!cacheHas(seen, othIndex) &&
  4152. (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
  4153. return seen.push(othIndex);
  4154. }
  4155. })) {
  4156. result = false;
  4157. break;
  4158. }
  4159. } else if (!(
  4160. arrValue === othValue ||
  4161. equalFunc(arrValue, othValue, bitmask, customizer, stack)
  4162. )) {
  4163. result = false;
  4164. break;
  4165. }
  4166. }
  4167. stack['delete'](array);
  4168. stack['delete'](other);
  4169. return result;
  4170. }
  4171. /**
  4172. * A specialized version of `baseIsEqualDeep` for comparing objects of
  4173. * the same `toStringTag`.
  4174. *
  4175. * **Note:** This function only supports comparing values with tags of
  4176. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  4177. *
  4178. * @private
  4179. * @param {Object} object The object to compare.
  4180. * @param {Object} other The other object to compare.
  4181. * @param {string} tag The `toStringTag` of the objects to compare.
  4182. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  4183. * @param {Function} customizer The function to customize comparisons.
  4184. * @param {Function} equalFunc The function to determine equivalents of values.
  4185. * @param {Object} stack Tracks traversed `object` and `other` objects.
  4186. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  4187. */
  4188. function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) {
  4189. switch (tag) {
  4190. case dataViewTag:
  4191. if ((object.byteLength != other.byteLength) ||
  4192. (object.byteOffset != other.byteOffset)) {
  4193. return false;
  4194. }
  4195. object = object.buffer;
  4196. other = other.buffer;
  4197. case arrayBufferTag:
  4198. if ((object.byteLength != other.byteLength) ||
  4199. !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
  4200. return false;
  4201. }
  4202. return true;
  4203. case boolTag:
  4204. case dateTag:
  4205. case numberTag:
  4206. // Coerce booleans to `1` or `0` and dates to milliseconds.
  4207. // Invalid dates are coerced to `NaN`.
  4208. return eq(+object, +other);
  4209. case errorTag:
  4210. return object.name == other.name && object.message == other.message;
  4211. case regexpTag:
  4212. case stringTag:
  4213. // Coerce regexes to strings and treat strings, primitives and objects,
  4214. // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
  4215. // for more details.
  4216. return object == (other + '');
  4217. case mapTag:
  4218. var convert = mapToArray;
  4219. case setTag:
  4220. var isPartial = bitmask & COMPARE_PARTIAL_FLAG;
  4221. convert || (convert = setToArray);
  4222. if (object.size != other.size && !isPartial) {
  4223. return false;
  4224. }
  4225. // Assume cyclic values are equal.
  4226. var stacked = stack.get(object);
  4227. if (stacked) {
  4228. return stacked == other;
  4229. }
  4230. bitmask |= COMPARE_UNORDERED_FLAG;
  4231. // Recursively compare objects (susceptible to call stack limits).
  4232. stack.set(object, other);
  4233. var result = equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack);
  4234. stack['delete'](object);
  4235. return result;
  4236. case symbolTag:
  4237. if (symbolValueOf) {
  4238. return symbolValueOf.call(object) == symbolValueOf.call(other);
  4239. }
  4240. }
  4241. return false;
  4242. }
  4243. /**
  4244. * A specialized version of `baseIsEqualDeep` for objects with support for
  4245. * partial deep comparisons.
  4246. *
  4247. * @private
  4248. * @param {Object} object The object to compare.
  4249. * @param {Object} other The other object to compare.
  4250. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  4251. * @param {Function} customizer The function to customize comparisons.
  4252. * @param {Function} equalFunc The function to determine equivalents of values.
  4253. * @param {Object} stack Tracks traversed `object` and `other` objects.
  4254. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  4255. */
  4256. function equalObjects(object, other, bitmask, customizer, equalFunc, stack) {
  4257. var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
  4258. objProps = getAllKeys(object),
  4259. objLength = objProps.length,
  4260. othProps = getAllKeys(other),
  4261. othLength = othProps.length;
  4262. if (objLength != othLength && !isPartial) {
  4263. return false;
  4264. }
  4265. var index = objLength;
  4266. while (index--) {
  4267. var key = objProps[index];
  4268. if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
  4269. return false;
  4270. }
  4271. }
  4272. // Assume cyclic values are equal.
  4273. var stacked = stack.get(object);
  4274. if (stacked && stack.get(other)) {
  4275. return stacked == other;
  4276. }
  4277. var result = true;
  4278. stack.set(object, other);
  4279. stack.set(other, object);
  4280. var skipCtor = isPartial;
  4281. while (++index < objLength) {
  4282. key = objProps[index];
  4283. var objValue = object[key],
  4284. othValue = other[key];
  4285. if (customizer) {
  4286. var compared = isPartial
  4287. ? customizer(othValue, objValue, key, other, object, stack)
  4288. : customizer(objValue, othValue, key, object, other, stack);
  4289. }
  4290. // Recursively compare objects (susceptible to call stack limits).
  4291. if (!(compared === undefined
  4292. ? (objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack))
  4293. : compared
  4294. )) {
  4295. result = false;
  4296. break;
  4297. }
  4298. skipCtor || (skipCtor = key == 'constructor');
  4299. }
  4300. if (result && !skipCtor) {
  4301. var objCtor = object.constructor,
  4302. othCtor = other.constructor;
  4303. // Non `Object` object instances with different constructors are not equal.
  4304. if (objCtor != othCtor &&
  4305. ('constructor' in object && 'constructor' in other) &&
  4306. !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
  4307. typeof othCtor == 'function' && othCtor instanceof othCtor)) {
  4308. result = false;
  4309. }
  4310. }
  4311. stack['delete'](object);
  4312. stack['delete'](other);
  4313. return result;
  4314. }
  4315. /**
  4316. * Creates an array of own enumerable property names and symbols of `object`.
  4317. *
  4318. * @private
  4319. * @param {Object} object The object to query.
  4320. * @returns {Array} Returns the array of property names and symbols.
  4321. */
  4322. function getAllKeys(object) {
  4323. return baseGetAllKeys(object, keys, getSymbols);
  4324. }
  4325. /**
  4326. * Gets the data for `map`.
  4327. *
  4328. * @private
  4329. * @param {Object} map The map to query.
  4330. * @param {string} key The reference key.
  4331. * @returns {*} Returns the map data.
  4332. */
  4333. function getMapData(map, key) {
  4334. var data = map.__data__;
  4335. return isKeyable(key)
  4336. ? data[typeof key == 'string' ? 'string' : 'hash']
  4337. : data.map;
  4338. }
  4339. /**
  4340. * Gets the native function at `key` of `object`.
  4341. *
  4342. * @private
  4343. * @param {Object} object The object to query.
  4344. * @param {string} key The key of the method to get.
  4345. * @returns {*} Returns the function if it's native, else `undefined`.
  4346. */
  4347. function getNative(object, key) {
  4348. var value = getValue(object, key);
  4349. return baseIsNative(value) ? value : undefined;
  4350. }
  4351. /**
  4352. * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
  4353. *
  4354. * @private
  4355. * @param {*} value The value to query.
  4356. * @returns {string} Returns the raw `toStringTag`.
  4357. */
  4358. function getRawTag(value) {
  4359. var isOwn = hasOwnProperty.call(value, symToStringTag),
  4360. tag = value[symToStringTag];
  4361. try {
  4362. value[symToStringTag] = undefined;
  4363. var unmasked = true;
  4364. } catch (e) {}
  4365. var result = nativeObjectToString.call(value);
  4366. if (unmasked) {
  4367. if (isOwn) {
  4368. value[symToStringTag] = tag;
  4369. } else {
  4370. delete value[symToStringTag];
  4371. }
  4372. }
  4373. return result;
  4374. }
  4375. /**
  4376. * Creates an array of the own enumerable symbols of `object`.
  4377. *
  4378. * @private
  4379. * @param {Object} object The object to query.
  4380. * @returns {Array} Returns the array of symbols.
  4381. */
  4382. var getSymbols = !nativeGetSymbols ? stubArray : function(object) {
  4383. if (object == null) {
  4384. return [];
  4385. }
  4386. object = Object(object);
  4387. return arrayFilter(nativeGetSymbols(object), function(symbol) {
  4388. return propertyIsEnumerable.call(object, symbol);
  4389. });
  4390. };
  4391. /**
  4392. * Gets the `toStringTag` of `value`.
  4393. *
  4394. * @private
  4395. * @param {*} value The value to query.
  4396. * @returns {string} Returns the `toStringTag`.
  4397. */
  4398. var getTag = baseGetTag;
  4399. // Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6.
  4400. if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
  4401. (Map && getTag(new Map) != mapTag) ||
  4402. (Promise && getTag(Promise.resolve()) != promiseTag) ||
  4403. (Set && getTag(new Set) != setTag) ||
  4404. (WeakMap && getTag(new WeakMap) != weakMapTag)) {
  4405. getTag = function(value) {
  4406. var result = baseGetTag(value),
  4407. Ctor = result == objectTag ? value.constructor : undefined,
  4408. ctorString = Ctor ? toSource(Ctor) : '';
  4409. if (ctorString) {
  4410. switch (ctorString) {
  4411. case dataViewCtorString: return dataViewTag;
  4412. case mapCtorString: return mapTag;
  4413. case promiseCtorString: return promiseTag;
  4414. case setCtorString: return setTag;
  4415. case weakMapCtorString: return weakMapTag;
  4416. }
  4417. }
  4418. return result;
  4419. };
  4420. }
  4421. /**
  4422. * Checks if `value` is a valid array-like index.
  4423. *
  4424. * @private
  4425. * @param {*} value The value to check.
  4426. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  4427. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  4428. */
  4429. function isIndex(value, length) {
  4430. length = length == null ? MAX_SAFE_INTEGER : length;
  4431. return !!length &&
  4432. (typeof value == 'number' || reIsUint.test(value)) &&
  4433. (value > -1 && value % 1 == 0 && value < length);
  4434. }
  4435. /**
  4436. * Checks if `value` is suitable for use as unique object key.
  4437. *
  4438. * @private
  4439. * @param {*} value The value to check.
  4440. * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
  4441. */
  4442. function isKeyable(value) {
  4443. var type = typeof value;
  4444. return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
  4445. ? (value !== '__proto__')
  4446. : (value === null);
  4447. }
  4448. /**
  4449. * Checks if `func` has its source masked.
  4450. *
  4451. * @private
  4452. * @param {Function} func The function to check.
  4453. * @returns {boolean} Returns `true` if `func` is masked, else `false`.
  4454. */
  4455. function isMasked(func) {
  4456. return !!maskSrcKey && (maskSrcKey in func);
  4457. }
  4458. /**
  4459. * Checks if `value` is likely a prototype object.
  4460. *
  4461. * @private
  4462. * @param {*} value The value to check.
  4463. * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
  4464. */
  4465. function isPrototype(value) {
  4466. var Ctor = value && value.constructor,
  4467. proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
  4468. return value === proto;
  4469. }
  4470. /**
  4471. * Converts `value` to a string using `Object.prototype.toString`.
  4472. *
  4473. * @private
  4474. * @param {*} value The value to convert.
  4475. * @returns {string} Returns the converted string.
  4476. */
  4477. function objectToString(value) {
  4478. return nativeObjectToString.call(value);
  4479. }
  4480. /**
  4481. * Converts `func` to its source code.
  4482. *
  4483. * @private
  4484. * @param {Function} func The function to convert.
  4485. * @returns {string} Returns the source code.
  4486. */
  4487. function toSource(func) {
  4488. if (func != null) {
  4489. try {
  4490. return funcToString.call(func);
  4491. } catch (e) {}
  4492. try {
  4493. return (func + '');
  4494. } catch (e) {}
  4495. }
  4496. return '';
  4497. }
  4498. /**
  4499. * Performs a
  4500. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  4501. * comparison between two values to determine if they are equivalent.
  4502. *
  4503. * @static
  4504. * @memberOf _
  4505. * @since 4.0.0
  4506. * @category Lang
  4507. * @param {*} value The value to compare.
  4508. * @param {*} other The other value to compare.
  4509. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  4510. * @example
  4511. *
  4512. * var object = { 'a': 1 };
  4513. * var other = { 'a': 1 };
  4514. *
  4515. * _.eq(object, object);
  4516. * // => true
  4517. *
  4518. * _.eq(object, other);
  4519. * // => false
  4520. *
  4521. * _.eq('a', 'a');
  4522. * // => true
  4523. *
  4524. * _.eq('a', Object('a'));
  4525. * // => false
  4526. *
  4527. * _.eq(NaN, NaN);
  4528. * // => true
  4529. */
  4530. function eq(value, other) {
  4531. return value === other || (value !== value && other !== other);
  4532. }
  4533. /**
  4534. * Checks if `value` is likely an `arguments` object.
  4535. *
  4536. * @static
  4537. * @memberOf _
  4538. * @since 0.1.0
  4539. * @category Lang
  4540. * @param {*} value The value to check.
  4541. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  4542. * else `false`.
  4543. * @example
  4544. *
  4545. * _.isArguments(function() { return arguments; }());
  4546. * // => true
  4547. *
  4548. * _.isArguments([1, 2, 3]);
  4549. * // => false
  4550. */
  4551. var isArguments = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : function(value) {
  4552. return isObjectLike(value) && hasOwnProperty.call(value, 'callee') &&
  4553. !propertyIsEnumerable.call(value, 'callee');
  4554. };
  4555. /**
  4556. * Checks if `value` is classified as an `Array` object.
  4557. *
  4558. * @static
  4559. * @memberOf _
  4560. * @since 0.1.0
  4561. * @category Lang
  4562. * @param {*} value The value to check.
  4563. * @returns {boolean} Returns `true` if `value` is an array, else `false`.
  4564. * @example
  4565. *
  4566. * _.isArray([1, 2, 3]);
  4567. * // => true
  4568. *
  4569. * _.isArray(document.body.children);
  4570. * // => false
  4571. *
  4572. * _.isArray('abc');
  4573. * // => false
  4574. *
  4575. * _.isArray(_.noop);
  4576. * // => false
  4577. */
  4578. var isArray = Array.isArray;
  4579. /**
  4580. * Checks if `value` is array-like. A value is considered array-like if it's
  4581. * not a function and has a `value.length` that's an integer greater than or
  4582. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  4583. *
  4584. * @static
  4585. * @memberOf _
  4586. * @since 4.0.0
  4587. * @category Lang
  4588. * @param {*} value The value to check.
  4589. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  4590. * @example
  4591. *
  4592. * _.isArrayLike([1, 2, 3]);
  4593. * // => true
  4594. *
  4595. * _.isArrayLike(document.body.children);
  4596. * // => true
  4597. *
  4598. * _.isArrayLike('abc');
  4599. * // => true
  4600. *
  4601. * _.isArrayLike(_.noop);
  4602. * // => false
  4603. */
  4604. function isArrayLike(value) {
  4605. return value != null && isLength(value.length) && !isFunction(value);
  4606. }
  4607. /**
  4608. * Checks if `value` is a buffer.
  4609. *
  4610. * @static
  4611. * @memberOf _
  4612. * @since 4.3.0
  4613. * @category Lang
  4614. * @param {*} value The value to check.
  4615. * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
  4616. * @example
  4617. *
  4618. * _.isBuffer(new Buffer(2));
  4619. * // => true
  4620. *
  4621. * _.isBuffer(new Uint8Array(2));
  4622. * // => false
  4623. */
  4624. var isBuffer = nativeIsBuffer || stubFalse;
  4625. /**
  4626. * Performs a deep comparison between two values to determine if they are
  4627. * equivalent.
  4628. *
  4629. * **Note:** This method supports comparing arrays, array buffers, booleans,
  4630. * date objects, error objects, maps, numbers, `Object` objects, regexes,
  4631. * sets, strings, symbols, and typed arrays. `Object` objects are compared
  4632. * by their own, not inherited, enumerable properties. Functions and DOM
  4633. * nodes are compared by strict equality, i.e. `===`.
  4634. *
  4635. * @static
  4636. * @memberOf _
  4637. * @since 0.1.0
  4638. * @category Lang
  4639. * @param {*} value The value to compare.
  4640. * @param {*} other The other value to compare.
  4641. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  4642. * @example
  4643. *
  4644. * var object = { 'a': 1 };
  4645. * var other = { 'a': 1 };
  4646. *
  4647. * _.isEqual(object, other);
  4648. * // => true
  4649. *
  4650. * object === other;
  4651. * // => false
  4652. */
  4653. function isEqual(value, other) {
  4654. return baseIsEqual(value, other);
  4655. }
  4656. /**
  4657. * Checks if `value` is classified as a `Function` object.
  4658. *
  4659. * @static
  4660. * @memberOf _
  4661. * @since 0.1.0
  4662. * @category Lang
  4663. * @param {*} value The value to check.
  4664. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  4665. * @example
  4666. *
  4667. * _.isFunction(_);
  4668. * // => true
  4669. *
  4670. * _.isFunction(/abc/);
  4671. * // => false
  4672. */
  4673. function isFunction(value) {
  4674. if (!isObject(value)) {
  4675. return false;
  4676. }
  4677. // The use of `Object#toString` avoids issues with the `typeof` operator
  4678. // in Safari 9 which returns 'object' for typed arrays and other constructors.
  4679. var tag = baseGetTag(value);
  4680. return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
  4681. }
  4682. /**
  4683. * Checks if `value` is a valid array-like length.
  4684. *
  4685. * **Note:** This method is loosely based on
  4686. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  4687. *
  4688. * @static
  4689. * @memberOf _
  4690. * @since 4.0.0
  4691. * @category Lang
  4692. * @param {*} value The value to check.
  4693. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  4694. * @example
  4695. *
  4696. * _.isLength(3);
  4697. * // => true
  4698. *
  4699. * _.isLength(Number.MIN_VALUE);
  4700. * // => false
  4701. *
  4702. * _.isLength(Infinity);
  4703. * // => false
  4704. *
  4705. * _.isLength('3');
  4706. * // => false
  4707. */
  4708. function isLength(value) {
  4709. return typeof value == 'number' &&
  4710. value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  4711. }
  4712. /**
  4713. * Checks if `value` is the
  4714. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  4715. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  4716. *
  4717. * @static
  4718. * @memberOf _
  4719. * @since 0.1.0
  4720. * @category Lang
  4721. * @param {*} value The value to check.
  4722. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  4723. * @example
  4724. *
  4725. * _.isObject({});
  4726. * // => true
  4727. *
  4728. * _.isObject([1, 2, 3]);
  4729. * // => true
  4730. *
  4731. * _.isObject(_.noop);
  4732. * // => true
  4733. *
  4734. * _.isObject(null);
  4735. * // => false
  4736. */
  4737. function isObject(value) {
  4738. var type = typeof value;
  4739. return value != null && (type == 'object' || type == 'function');
  4740. }
  4741. /**
  4742. * Checks if `value` is object-like. A value is object-like if it's not `null`
  4743. * and has a `typeof` result of "object".
  4744. *
  4745. * @static
  4746. * @memberOf _
  4747. * @since 4.0.0
  4748. * @category Lang
  4749. * @param {*} value The value to check.
  4750. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  4751. * @example
  4752. *
  4753. * _.isObjectLike({});
  4754. * // => true
  4755. *
  4756. * _.isObjectLike([1, 2, 3]);
  4757. * // => true
  4758. *
  4759. * _.isObjectLike(_.noop);
  4760. * // => false
  4761. *
  4762. * _.isObjectLike(null);
  4763. * // => false
  4764. */
  4765. function isObjectLike(value) {
  4766. return value != null && typeof value == 'object';
  4767. }
  4768. /**
  4769. * Checks if `value` is classified as a typed array.
  4770. *
  4771. * @static
  4772. * @memberOf _
  4773. * @since 3.0.0
  4774. * @category Lang
  4775. * @param {*} value The value to check.
  4776. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  4777. * @example
  4778. *
  4779. * _.isTypedArray(new Uint8Array);
  4780. * // => true
  4781. *
  4782. * _.isTypedArray([]);
  4783. * // => false
  4784. */
  4785. var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
  4786. /**
  4787. * Creates an array of the own enumerable property names of `object`.
  4788. *
  4789. * **Note:** Non-object values are coerced to objects. See the
  4790. * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  4791. * for more details.
  4792. *
  4793. * @static
  4794. * @since 0.1.0
  4795. * @memberOf _
  4796. * @category Object
  4797. * @param {Object} object The object to query.
  4798. * @returns {Array} Returns the array of property names.
  4799. * @example
  4800. *
  4801. * function Foo() {
  4802. * this.a = 1;
  4803. * this.b = 2;
  4804. * }
  4805. *
  4806. * Foo.prototype.c = 3;
  4807. *
  4808. * _.keys(new Foo);
  4809. * // => ['a', 'b'] (iteration order is not guaranteed)
  4810. *
  4811. * _.keys('hi');
  4812. * // => ['0', '1']
  4813. */
  4814. function keys(object) {
  4815. return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
  4816. }
  4817. /**
  4818. * This method returns a new empty array.
  4819. *
  4820. * @static
  4821. * @memberOf _
  4822. * @since 4.13.0
  4823. * @category Util
  4824. * @returns {Array} Returns the new empty array.
  4825. * @example
  4826. *
  4827. * var arrays = _.times(2, _.stubArray);
  4828. *
  4829. * console.log(arrays);
  4830. * // => [[], []]
  4831. *
  4832. * console.log(arrays[0] === arrays[1]);
  4833. * // => false
  4834. */
  4835. function stubArray() {
  4836. return [];
  4837. }
  4838. /**
  4839. * This method returns `false`.
  4840. *
  4841. * @static
  4842. * @memberOf _
  4843. * @since 4.13.0
  4844. * @category Util
  4845. * @returns {boolean} Returns `false`.
  4846. * @example
  4847. *
  4848. * _.times(2, _.stubFalse);
  4849. * // => [false, false]
  4850. */
  4851. function stubFalse() {
  4852. return false;
  4853. }
  4854. module.exports = isEqual;
  4855. }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  4856. },{}],11:[function(require,module,exports){
  4857. // shim for using process in browser
  4858. var process = module.exports = {};
  4859. // cached from whatever global is present so that test runners that stub it
  4860. // don't break things. But we need to wrap it in a try catch in case it is
  4861. // wrapped in strict mode code which doesn't define any globals. It's inside a
  4862. // function because try/catches deoptimize in certain engines.
  4863. var cachedSetTimeout;
  4864. var cachedClearTimeout;
  4865. function defaultSetTimout() {
  4866. throw new Error('setTimeout has not been defined');
  4867. }
  4868. function defaultClearTimeout () {
  4869. throw new Error('clearTimeout has not been defined');
  4870. }
  4871. (function () {
  4872. try {
  4873. if (typeof setTimeout === 'function') {
  4874. cachedSetTimeout = setTimeout;
  4875. } else {
  4876. cachedSetTimeout = defaultSetTimout;
  4877. }
  4878. } catch (e) {
  4879. cachedSetTimeout = defaultSetTimout;
  4880. }
  4881. try {
  4882. if (typeof clearTimeout === 'function') {
  4883. cachedClearTimeout = clearTimeout;
  4884. } else {
  4885. cachedClearTimeout = defaultClearTimeout;
  4886. }
  4887. } catch (e) {
  4888. cachedClearTimeout = defaultClearTimeout;
  4889. }
  4890. } ())
  4891. function runTimeout(fun) {
  4892. if (cachedSetTimeout === setTimeout) {
  4893. //normal enviroments in sane situations
  4894. return setTimeout(fun, 0);
  4895. }
  4896. // if setTimeout wasn't available but was latter defined
  4897. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  4898. cachedSetTimeout = setTimeout;
  4899. return setTimeout(fun, 0);
  4900. }
  4901. try {
  4902. // when when somebody has screwed with setTimeout but no I.E. maddness
  4903. return cachedSetTimeout(fun, 0);
  4904. } catch(e){
  4905. try {
  4906. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  4907. return cachedSetTimeout.call(null, fun, 0);
  4908. } catch(e){
  4909. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
  4910. return cachedSetTimeout.call(this, fun, 0);
  4911. }
  4912. }
  4913. }
  4914. function runClearTimeout(marker) {
  4915. if (cachedClearTimeout === clearTimeout) {
  4916. //normal enviroments in sane situations
  4917. return clearTimeout(marker);
  4918. }
  4919. // if clearTimeout wasn't available but was latter defined
  4920. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  4921. cachedClearTimeout = clearTimeout;
  4922. return clearTimeout(marker);
  4923. }
  4924. try {
  4925. // when when somebody has screwed with setTimeout but no I.E. maddness
  4926. return cachedClearTimeout(marker);
  4927. } catch (e){
  4928. try {
  4929. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  4930. return cachedClearTimeout.call(null, marker);
  4931. } catch (e){
  4932. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
  4933. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  4934. return cachedClearTimeout.call(this, marker);
  4935. }
  4936. }
  4937. }
  4938. var queue = [];
  4939. var draining = false;
  4940. var currentQueue;
  4941. var queueIndex = -1;
  4942. function cleanUpNextTick() {
  4943. if (!draining || !currentQueue) {
  4944. return;
  4945. }
  4946. draining = false;
  4947. if (currentQueue.length) {
  4948. queue = currentQueue.concat(queue);
  4949. } else {
  4950. queueIndex = -1;
  4951. }
  4952. if (queue.length) {
  4953. drainQueue();
  4954. }
  4955. }
  4956. function drainQueue() {
  4957. if (draining) {
  4958. return;
  4959. }
  4960. var timeout = runTimeout(cleanUpNextTick);
  4961. draining = true;
  4962. var len = queue.length;
  4963. while(len) {
  4964. currentQueue = queue;
  4965. queue = [];
  4966. while (++queueIndex < len) {
  4967. if (currentQueue) {
  4968. currentQueue[queueIndex].run();
  4969. }
  4970. }
  4971. queueIndex = -1;
  4972. len = queue.length;
  4973. }
  4974. currentQueue = null;
  4975. draining = false;
  4976. runClearTimeout(timeout);
  4977. }
  4978. process.nextTick = function (fun) {
  4979. var args = new Array(arguments.length - 1);
  4980. if (arguments.length > 1) {
  4981. for (var i = 1; i < arguments.length; i++) {
  4982. args[i - 1] = arguments[i];
  4983. }
  4984. }
  4985. queue.push(new Item(fun, args));
  4986. if (queue.length === 1 && !draining) {
  4987. runTimeout(drainQueue);
  4988. }
  4989. };
  4990. // v8 likes predictible objects
  4991. function Item(fun, array) {
  4992. this.fun = fun;
  4993. this.array = array;
  4994. }
  4995. Item.prototype.run = function () {
  4996. this.fun.apply(null, this.array);
  4997. };
  4998. process.title = 'browser';
  4999. process.browser = true;
  5000. process.env = {};
  5001. process.argv = [];
  5002. process.version = ''; // empty string to avoid regexp issues
  5003. process.versions = {};
  5004. function noop() {}
  5005. process.on = noop;
  5006. process.addListener = noop;
  5007. process.once = noop;
  5008. process.off = noop;
  5009. process.removeListener = noop;
  5010. process.removeAllListeners = noop;
  5011. process.emit = noop;
  5012. process.prependListener = noop;
  5013. process.prependOnceListener = noop;
  5014. process.listeners = function (name) { return [] }
  5015. process.binding = function (name) {
  5016. throw new Error('process.binding is not supported');
  5017. };
  5018. process.cwd = function () { return '/' };
  5019. process.chdir = function (dir) {
  5020. throw new Error('process.chdir is not supported');
  5021. };
  5022. process.umask = function() { return 0; };
  5023. },{}],12:[function(require,module,exports){
  5024. (function (global){(function (){
  5025. /*! https://mths.be/punycode v1.4.1 by @mathias */
  5026. ;(function(root) {
  5027. /** Detect free variables */
  5028. var freeExports = typeof exports == 'object' && exports &&
  5029. !exports.nodeType && exports;
  5030. var freeModule = typeof module == 'object' && module &&
  5031. !module.nodeType && module;
  5032. var freeGlobal = typeof global == 'object' && global;
  5033. if (
  5034. freeGlobal.global === freeGlobal ||
  5035. freeGlobal.window === freeGlobal ||
  5036. freeGlobal.self === freeGlobal
  5037. ) {
  5038. root = freeGlobal;
  5039. }
  5040. /**
  5041. * The `punycode` object.
  5042. * @name punycode
  5043. * @type Object
  5044. */
  5045. var punycode,
  5046. /** Highest positive signed 32-bit float value */
  5047. maxInt = 2147483647, // aka. 0x7FFFFFFF or 2^31-1
  5048. /** Bootstring parameters */
  5049. base = 36,
  5050. tMin = 1,
  5051. tMax = 26,
  5052. skew = 38,
  5053. damp = 700,
  5054. initialBias = 72,
  5055. initialN = 128, // 0x80
  5056. delimiter = '-', // '\x2D'
  5057. /** Regular expressions */
  5058. regexPunycode = /^xn--/,
  5059. regexNonASCII = /[^\x20-\x7E]/, // unprintable ASCII chars + non-ASCII chars
  5060. regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g, // RFC 3490 separators
  5061. /** Error messages */
  5062. errors = {
  5063. 'overflow': 'Overflow: input needs wider integers to process',
  5064. 'not-basic': 'Illegal input >= 0x80 (not a basic code point)',
  5065. 'invalid-input': 'Invalid input'
  5066. },
  5067. /** Convenience shortcuts */
  5068. baseMinusTMin = base - tMin,
  5069. floor = Math.floor,
  5070. stringFromCharCode = String.fromCharCode,
  5071. /** Temporary variable */
  5072. key;
  5073. /*--------------------------------------------------------------------------*/
  5074. /**
  5075. * A generic error utility function.
  5076. * @private
  5077. * @param {String} type The error type.
  5078. * @returns {Error} Throws a `RangeError` with the applicable error message.
  5079. */
  5080. function error(type) {
  5081. throw new RangeError(errors[type]);
  5082. }
  5083. /**
  5084. * A generic `Array#map` utility function.
  5085. * @private
  5086. * @param {Array} array The array to iterate over.
  5087. * @param {Function} callback The function that gets called for every array
  5088. * item.
  5089. * @returns {Array} A new array of values returned by the callback function.
  5090. */
  5091. function map(array, fn) {
  5092. var length = array.length;
  5093. var result = [];
  5094. while (length--) {
  5095. result[length] = fn(array[length]);
  5096. }
  5097. return result;
  5098. }
  5099. /**
  5100. * A simple `Array#map`-like wrapper to work with domain name strings or email
  5101. * addresses.
  5102. * @private
  5103. * @param {String} domain The domain name or email address.
  5104. * @param {Function} callback The function that gets called for every
  5105. * character.
  5106. * @returns {Array} A new string of characters returned by the callback
  5107. * function.
  5108. */
  5109. function mapDomain(string, fn) {
  5110. var parts = string.split('@');
  5111. var result = '';
  5112. if (parts.length > 1) {
  5113. // In email addresses, only the domain name should be punycoded. Leave
  5114. // the local part (i.e. everything up to `@`) intact.
  5115. result = parts[0] + '@';
  5116. string = parts[1];
  5117. }
  5118. // Avoid `split(regex)` for IE8 compatibility. See #17.
  5119. string = string.replace(regexSeparators, '\x2E');
  5120. var labels = string.split('.');
  5121. var encoded = map(labels, fn).join('.');
  5122. return result + encoded;
  5123. }
  5124. /**
  5125. * Creates an array containing the numeric code points of each Unicode
  5126. * character in the string. While JavaScript uses UCS-2 internally,
  5127. * this function will convert a pair of surrogate halves (each of which
  5128. * UCS-2 exposes as separate characters) into a single code point,
  5129. * matching UTF-16.
  5130. * @see `punycode.ucs2.encode`
  5131. * @see <https://mathiasbynens.be/notes/javascript-encoding>
  5132. * @memberOf punycode.ucs2
  5133. * @name decode
  5134. * @param {String} string The Unicode input string (UCS-2).
  5135. * @returns {Array} The new array of code points.
  5136. */
  5137. function ucs2decode(string) {
  5138. var output = [],
  5139. counter = 0,
  5140. length = string.length,
  5141. value,
  5142. extra;
  5143. while (counter < length) {
  5144. value = string.charCodeAt(counter++);
  5145. if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
  5146. // high surrogate, and there is a next character
  5147. extra = string.charCodeAt(counter++);
  5148. if ((extra & 0xFC00) == 0xDC00) { // low surrogate
  5149. output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
  5150. } else {
  5151. // unmatched surrogate; only append this code unit, in case the next
  5152. // code unit is the high surrogate of a surrogate pair
  5153. output.push(value);
  5154. counter--;
  5155. }
  5156. } else {
  5157. output.push(value);
  5158. }
  5159. }
  5160. return output;
  5161. }
  5162. /**
  5163. * Creates a string based on an array of numeric code points.
  5164. * @see `punycode.ucs2.decode`
  5165. * @memberOf punycode.ucs2
  5166. * @name encode
  5167. * @param {Array} codePoints The array of numeric code points.
  5168. * @returns {String} The new Unicode string (UCS-2).
  5169. */
  5170. function ucs2encode(array) {
  5171. return map(array, function(value) {
  5172. var output = '';
  5173. if (value > 0xFFFF) {
  5174. value -= 0x10000;
  5175. output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800);
  5176. value = 0xDC00 | value & 0x3FF;
  5177. }
  5178. output += stringFromCharCode(value);
  5179. return output;
  5180. }).join('');
  5181. }
  5182. /**
  5183. * Converts a basic code point into a digit/integer.
  5184. * @see `digitToBasic()`
  5185. * @private
  5186. * @param {Number} codePoint The basic numeric code point value.
  5187. * @returns {Number} The numeric value of a basic code point (for use in
  5188. * representing integers) in the range `0` to `base - 1`, or `base` if
  5189. * the code point does not represent a value.
  5190. */
  5191. function basicToDigit(codePoint) {
  5192. if (codePoint - 48 < 10) {
  5193. return codePoint - 22;
  5194. }
  5195. if (codePoint - 65 < 26) {
  5196. return codePoint - 65;
  5197. }
  5198. if (codePoint - 97 < 26) {
  5199. return codePoint - 97;
  5200. }
  5201. return base;
  5202. }
  5203. /**
  5204. * Converts a digit/integer into a basic code point.
  5205. * @see `basicToDigit()`
  5206. * @private
  5207. * @param {Number} digit The numeric value of a basic code point.
  5208. * @returns {Number} The basic code point whose value (when used for
  5209. * representing integers) is `digit`, which needs to be in the range
  5210. * `0` to `base - 1`. If `flag` is non-zero, the uppercase form is
  5211. * used; else, the lowercase form is used. The behavior is undefined
  5212. * if `flag` is non-zero and `digit` has no uppercase form.
  5213. */
  5214. function digitToBasic(digit, flag) {
  5215. // 0..25 map to ASCII a..z or A..Z
  5216. // 26..35 map to ASCII 0..9
  5217. return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5);
  5218. }
  5219. /**
  5220. * Bias adaptation function as per section 3.4 of RFC 3492.
  5221. * https://tools.ietf.org/html/rfc3492#section-3.4
  5222. * @private
  5223. */
  5224. function adapt(delta, numPoints, firstTime) {
  5225. var k = 0;
  5226. delta = firstTime ? floor(delta / damp) : delta >> 1;
  5227. delta += floor(delta / numPoints);
  5228. for (/* no initialization */; delta > baseMinusTMin * tMax >> 1; k += base) {
  5229. delta = floor(delta / baseMinusTMin);
  5230. }
  5231. return floor(k + (baseMinusTMin + 1) * delta / (delta + skew));
  5232. }
  5233. /**
  5234. * Converts a Punycode string of ASCII-only symbols to a string of Unicode
  5235. * symbols.
  5236. * @memberOf punycode
  5237. * @param {String} input The Punycode string of ASCII-only symbols.
  5238. * @returns {String} The resulting string of Unicode symbols.
  5239. */
  5240. function decode(input) {
  5241. // Don't use UCS-2
  5242. var output = [],
  5243. inputLength = input.length,
  5244. out,
  5245. i = 0,
  5246. n = initialN,
  5247. bias = initialBias,
  5248. basic,
  5249. j,
  5250. index,
  5251. oldi,
  5252. w,
  5253. k,
  5254. digit,
  5255. t,
  5256. /** Cached calculation results */
  5257. baseMinusT;
  5258. // Handle the basic code points: let `basic` be the number of input code
  5259. // points before the last delimiter, or `0` if there is none, then copy
  5260. // the first basic code points to the output.
  5261. basic = input.lastIndexOf(delimiter);
  5262. if (basic < 0) {
  5263. basic = 0;
  5264. }
  5265. for (j = 0; j < basic; ++j) {
  5266. // if it's not a basic code point
  5267. if (input.charCodeAt(j) >= 0x80) {
  5268. error('not-basic');
  5269. }
  5270. output.push(input.charCodeAt(j));
  5271. }
  5272. // Main decoding loop: start just after the last delimiter if any basic code
  5273. // points were copied; start at the beginning otherwise.
  5274. for (index = basic > 0 ? basic + 1 : 0; index < inputLength; /* no final expression */) {
  5275. // `index` is the index of the next character to be consumed.
  5276. // Decode a generalized variable-length integer into `delta`,
  5277. // which gets added to `i`. The overflow checking is easier
  5278. // if we increase `i` as we go, then subtract off its starting
  5279. // value at the end to obtain `delta`.
  5280. for (oldi = i, w = 1, k = base; /* no condition */; k += base) {
  5281. if (index >= inputLength) {
  5282. error('invalid-input');
  5283. }
  5284. digit = basicToDigit(input.charCodeAt(index++));
  5285. if (digit >= base || digit > floor((maxInt - i) / w)) {
  5286. error('overflow');
  5287. }
  5288. i += digit * w;
  5289. t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
  5290. if (digit < t) {
  5291. break;
  5292. }
  5293. baseMinusT = base - t;
  5294. if (w > floor(maxInt / baseMinusT)) {
  5295. error('overflow');
  5296. }
  5297. w *= baseMinusT;
  5298. }
  5299. out = output.length + 1;
  5300. bias = adapt(i - oldi, out, oldi == 0);
  5301. // `i` was supposed to wrap around from `out` to `0`,
  5302. // incrementing `n` each time, so we'll fix that now:
  5303. if (floor(i / out) > maxInt - n) {
  5304. error('overflow');
  5305. }
  5306. n += floor(i / out);
  5307. i %= out;
  5308. // Insert `n` at position `i` of the output
  5309. output.splice(i++, 0, n);
  5310. }
  5311. return ucs2encode(output);
  5312. }
  5313. /**
  5314. * Converts a string of Unicode symbols (e.g. a domain name label) to a
  5315. * Punycode string of ASCII-only symbols.
  5316. * @memberOf punycode
  5317. * @param {String} input The string of Unicode symbols.
  5318. * @returns {String} The resulting Punycode string of ASCII-only symbols.
  5319. */
  5320. function encode(input) {
  5321. var n,
  5322. delta,
  5323. handledCPCount,
  5324. basicLength,
  5325. bias,
  5326. j,
  5327. m,
  5328. q,
  5329. k,
  5330. t,
  5331. currentValue,
  5332. output = [],
  5333. /** `inputLength` will hold the number of code points in `input`. */
  5334. inputLength,
  5335. /** Cached calculation results */
  5336. handledCPCountPlusOne,
  5337. baseMinusT,
  5338. qMinusT;
  5339. // Convert the input in UCS-2 to Unicode
  5340. input = ucs2decode(input);
  5341. // Cache the length
  5342. inputLength = input.length;
  5343. // Initialize the state
  5344. n = initialN;
  5345. delta = 0;
  5346. bias = initialBias;
  5347. // Handle the basic code points
  5348. for (j = 0; j < inputLength; ++j) {
  5349. currentValue = input[j];
  5350. if (currentValue < 0x80) {
  5351. output.push(stringFromCharCode(currentValue));
  5352. }
  5353. }
  5354. handledCPCount = basicLength = output.length;
  5355. // `handledCPCount` is the number of code points that have been handled;
  5356. // `basicLength` is the number of basic code points.
  5357. // Finish the basic string - if it is not empty - with a delimiter
  5358. if (basicLength) {
  5359. output.push(delimiter);
  5360. }
  5361. // Main encoding loop:
  5362. while (handledCPCount < inputLength) {
  5363. // All non-basic code points < n have been handled already. Find the next
  5364. // larger one:
  5365. for (m = maxInt, j = 0; j < inputLength; ++j) {
  5366. currentValue = input[j];
  5367. if (currentValue >= n && currentValue < m) {
  5368. m = currentValue;
  5369. }
  5370. }
  5371. // Increase `delta` enough to advance the decoder's <n,i> state to <m,0>,
  5372. // but guard against overflow
  5373. handledCPCountPlusOne = handledCPCount + 1;
  5374. if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) {
  5375. error('overflow');
  5376. }
  5377. delta += (m - n) * handledCPCountPlusOne;
  5378. n = m;
  5379. for (j = 0; j < inputLength; ++j) {
  5380. currentValue = input[j];
  5381. if (currentValue < n && ++delta > maxInt) {
  5382. error('overflow');
  5383. }
  5384. if (currentValue == n) {
  5385. // Represent delta as a generalized variable-length integer
  5386. for (q = delta, k = base; /* no condition */; k += base) {
  5387. t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
  5388. if (q < t) {
  5389. break;
  5390. }
  5391. qMinusT = q - t;
  5392. baseMinusT = base - t;
  5393. output.push(
  5394. stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0))
  5395. );
  5396. q = floor(qMinusT / baseMinusT);
  5397. }
  5398. output.push(stringFromCharCode(digitToBasic(q, 0)));
  5399. bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength);
  5400. delta = 0;
  5401. ++handledCPCount;
  5402. }
  5403. }
  5404. ++delta;
  5405. ++n;
  5406. }
  5407. return output.join('');
  5408. }
  5409. /**
  5410. * Converts a Punycode string representing a domain name or an email address
  5411. * to Unicode. Only the Punycoded parts of the input will be converted, i.e.
  5412. * it doesn't matter if you call it on a string that has already been
  5413. * converted to Unicode.
  5414. * @memberOf punycode
  5415. * @param {String} input The Punycoded domain name or email address to
  5416. * convert to Unicode.
  5417. * @returns {String} The Unicode representation of the given Punycode
  5418. * string.
  5419. */
  5420. function toUnicode(input) {
  5421. return mapDomain(input, function(string) {
  5422. return regexPunycode.test(string)
  5423. ? decode(string.slice(4).toLowerCase())
  5424. : string;
  5425. });
  5426. }
  5427. /**
  5428. * Converts a Unicode string representing a domain name or an email address to
  5429. * Punycode. Only the non-ASCII parts of the domain name will be converted,
  5430. * i.e. it doesn't matter if you call it with a domain that's already in
  5431. * ASCII.
  5432. * @memberOf punycode
  5433. * @param {String} input The domain name or email address to convert, as a
  5434. * Unicode string.
  5435. * @returns {String} The Punycode representation of the given domain name or
  5436. * email address.
  5437. */
  5438. function toASCII(input) {
  5439. return mapDomain(input, function(string) {
  5440. return regexNonASCII.test(string)
  5441. ? 'xn--' + encode(string)
  5442. : string;
  5443. });
  5444. }
  5445. /*--------------------------------------------------------------------------*/
  5446. /** Define the public API */
  5447. punycode = {
  5448. /**
  5449. * A string representing the current Punycode.js version number.
  5450. * @memberOf punycode
  5451. * @type String
  5452. */
  5453. 'version': '1.4.1',
  5454. /**
  5455. * An object of methods to convert from JavaScript's internal character
  5456. * representation (UCS-2) to Unicode code points, and back.
  5457. * @see <https://mathiasbynens.be/notes/javascript-encoding>
  5458. * @memberOf punycode
  5459. * @type Object
  5460. */
  5461. 'ucs2': {
  5462. 'decode': ucs2decode,
  5463. 'encode': ucs2encode
  5464. },
  5465. 'decode': decode,
  5466. 'encode': encode,
  5467. 'toASCII': toASCII,
  5468. 'toUnicode': toUnicode
  5469. };
  5470. /** Expose `punycode` */
  5471. // Some AMD build optimizers, like r.js, check for specific condition patterns
  5472. // like the following:
  5473. if (
  5474. typeof define == 'function' &&
  5475. typeof define.amd == 'object' &&
  5476. define.amd
  5477. ) {
  5478. define('punycode', function() {
  5479. return punycode;
  5480. });
  5481. } else if (freeExports && freeModule) {
  5482. if (module.exports == freeExports) {
  5483. // in Node.js, io.js, or RingoJS v0.8.0+
  5484. freeModule.exports = punycode;
  5485. } else {
  5486. // in Narwhal or RingoJS v0.7.0-
  5487. for (key in punycode) {
  5488. punycode.hasOwnProperty(key) && (freeExports[key] = punycode[key]);
  5489. }
  5490. }
  5491. } else {
  5492. // in Rhino or a web browser
  5493. root.punycode = punycode;
  5494. }
  5495. }(this));
  5496. }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  5497. },{}],13:[function(require,module,exports){
  5498. // Copyright Joyent, Inc. and other Node contributors.
  5499. //
  5500. // Permission is hereby granted, free of charge, to any person obtaining a
  5501. // copy of this software and associated documentation files (the
  5502. // "Software"), to deal in the Software without restriction, including
  5503. // without limitation the rights to use, copy, modify, merge, publish,
  5504. // distribute, sublicense, and/or sell copies of the Software, and to permit
  5505. // persons to whom the Software is furnished to do so, subject to the
  5506. // following conditions:
  5507. //
  5508. // The above copyright notice and this permission notice shall be included
  5509. // in all copies or substantial portions of the Software.
  5510. //
  5511. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  5512. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  5513. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  5514. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  5515. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  5516. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  5517. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  5518. 'use strict';
  5519. // If obj.hasOwnProperty has been overridden, then calling
  5520. // obj.hasOwnProperty(prop) will break.
  5521. // See: https://github.com/joyent/node/issues/1707
  5522. function hasOwnProperty(obj, prop) {
  5523. return Object.prototype.hasOwnProperty.call(obj, prop);
  5524. }
  5525. module.exports = function(qs, sep, eq, options) {
  5526. sep = sep || '&';
  5527. eq = eq || '=';
  5528. var obj = {};
  5529. if (typeof qs !== 'string' || qs.length === 0) {
  5530. return obj;
  5531. }
  5532. var regexp = /\+/g;
  5533. qs = qs.split(sep);
  5534. var maxKeys = 1000;
  5535. if (options && typeof options.maxKeys === 'number') {
  5536. maxKeys = options.maxKeys;
  5537. }
  5538. var len = qs.length;
  5539. // maxKeys <= 0 means that we should not limit keys count
  5540. if (maxKeys > 0 && len > maxKeys) {
  5541. len = maxKeys;
  5542. }
  5543. for (var i = 0; i < len; ++i) {
  5544. var x = qs[i].replace(regexp, '%20'),
  5545. idx = x.indexOf(eq),
  5546. kstr, vstr, k, v;
  5547. if (idx >= 0) {
  5548. kstr = x.substr(0, idx);
  5549. vstr = x.substr(idx + 1);
  5550. } else {
  5551. kstr = x;
  5552. vstr = '';
  5553. }
  5554. k = decodeURIComponent(kstr);
  5555. v = decodeURIComponent(vstr);
  5556. if (!hasOwnProperty(obj, k)) {
  5557. obj[k] = v;
  5558. } else if (isArray(obj[k])) {
  5559. obj[k].push(v);
  5560. } else {
  5561. obj[k] = [obj[k], v];
  5562. }
  5563. }
  5564. return obj;
  5565. };
  5566. var isArray = Array.isArray || function (xs) {
  5567. return Object.prototype.toString.call(xs) === '[object Array]';
  5568. };
  5569. },{}],14:[function(require,module,exports){
  5570. // Copyright Joyent, Inc. and other Node contributors.
  5571. //
  5572. // Permission is hereby granted, free of charge, to any person obtaining a
  5573. // copy of this software and associated documentation files (the
  5574. // "Software"), to deal in the Software without restriction, including
  5575. // without limitation the rights to use, copy, modify, merge, publish,
  5576. // distribute, sublicense, and/or sell copies of the Software, and to permit
  5577. // persons to whom the Software is furnished to do so, subject to the
  5578. // following conditions:
  5579. //
  5580. // The above copyright notice and this permission notice shall be included
  5581. // in all copies or substantial portions of the Software.
  5582. //
  5583. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  5584. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  5585. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  5586. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  5587. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  5588. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  5589. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  5590. 'use strict';
  5591. var stringifyPrimitive = function(v) {
  5592. switch (typeof v) {
  5593. case 'string':
  5594. return v;
  5595. case 'boolean':
  5596. return v ? 'true' : 'false';
  5597. case 'number':
  5598. return isFinite(v) ? v : '';
  5599. default:
  5600. return '';
  5601. }
  5602. };
  5603. module.exports = function(obj, sep, eq, name) {
  5604. sep = sep || '&';
  5605. eq = eq || '=';
  5606. if (obj === null) {
  5607. obj = undefined;
  5608. }
  5609. if (typeof obj === 'object') {
  5610. return map(objectKeys(obj), function(k) {
  5611. var ks = encodeURIComponent(stringifyPrimitive(k)) + eq;
  5612. if (isArray(obj[k])) {
  5613. return map(obj[k], function(v) {
  5614. return ks + encodeURIComponent(stringifyPrimitive(v));
  5615. }).join(sep);
  5616. } else {
  5617. return ks + encodeURIComponent(stringifyPrimitive(obj[k]));
  5618. }
  5619. }).join(sep);
  5620. }
  5621. if (!name) return '';
  5622. return encodeURIComponent(stringifyPrimitive(name)) + eq +
  5623. encodeURIComponent(stringifyPrimitive(obj));
  5624. };
  5625. var isArray = Array.isArray || function (xs) {
  5626. return Object.prototype.toString.call(xs) === '[object Array]';
  5627. };
  5628. function map (xs, f) {
  5629. if (xs.map) return xs.map(f);
  5630. var res = [];
  5631. for (var i = 0; i < xs.length; i++) {
  5632. res.push(f(xs[i], i));
  5633. }
  5634. return res;
  5635. }
  5636. var objectKeys = Object.keys || function (obj) {
  5637. var res = [];
  5638. for (var key in obj) {
  5639. if (Object.prototype.hasOwnProperty.call(obj, key)) res.push(key);
  5640. }
  5641. return res;
  5642. };
  5643. },{}],15:[function(require,module,exports){
  5644. 'use strict';
  5645. exports.decode = exports.parse = require('./decode');
  5646. exports.encode = exports.stringify = require('./encode');
  5647. },{"./decode":13,"./encode":14}],16:[function(require,module,exports){
  5648. /*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
  5649. /* eslint-disable node/no-deprecated-api */
  5650. var buffer = require('buffer')
  5651. var Buffer = buffer.Buffer
  5652. // alternative to using Object.keys for old browsers
  5653. function copyProps (src, dst) {
  5654. for (var key in src) {
  5655. dst[key] = src[key]
  5656. }
  5657. }
  5658. if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) {
  5659. module.exports = buffer
  5660. } else {
  5661. // Copy properties from require('buffer')
  5662. copyProps(buffer, exports)
  5663. exports.Buffer = SafeBuffer
  5664. }
  5665. function SafeBuffer (arg, encodingOrOffset, length) {
  5666. return Buffer(arg, encodingOrOffset, length)
  5667. }
  5668. SafeBuffer.prototype = Object.create(Buffer.prototype)
  5669. // Copy static methods from Buffer
  5670. copyProps(Buffer, SafeBuffer)
  5671. SafeBuffer.from = function (arg, encodingOrOffset, length) {
  5672. if (typeof arg === 'number') {
  5673. throw new TypeError('Argument must not be a number')
  5674. }
  5675. return Buffer(arg, encodingOrOffset, length)
  5676. }
  5677. SafeBuffer.alloc = function (size, fill, encoding) {
  5678. if (typeof size !== 'number') {
  5679. throw new TypeError('Argument must be a number')
  5680. }
  5681. var buf = Buffer(size)
  5682. if (fill !== undefined) {
  5683. if (typeof encoding === 'string') {
  5684. buf.fill(fill, encoding)
  5685. } else {
  5686. buf.fill(fill)
  5687. }
  5688. } else {
  5689. buf.fill(0)
  5690. }
  5691. return buf
  5692. }
  5693. SafeBuffer.allocUnsafe = function (size) {
  5694. if (typeof size !== 'number') {
  5695. throw new TypeError('Argument must be a number')
  5696. }
  5697. return Buffer(size)
  5698. }
  5699. SafeBuffer.allocUnsafeSlow = function (size) {
  5700. if (typeof size !== 'number') {
  5701. throw new TypeError('Argument must be a number')
  5702. }
  5703. return buffer.SlowBuffer(size)
  5704. }
  5705. },{"buffer":3}],17:[function(require,module,exports){
  5706. (function (global){(function (){
  5707. var ClientRequest = require('./lib/request')
  5708. var response = require('./lib/response')
  5709. var extend = require('xtend')
  5710. var statusCodes = require('builtin-status-codes')
  5711. var url = require('url')
  5712. var http = exports
  5713. http.request = function (opts, cb) {
  5714. if (typeof opts === 'string')
  5715. opts = url.parse(opts)
  5716. else
  5717. opts = extend(opts)
  5718. // Normally, the page is loaded from http or https, so not specifying a protocol
  5719. // will result in a (valid) protocol-relative url. However, this won't work if
  5720. // the protocol is something else, like 'file:'
  5721. var defaultProtocol = global.location.protocol.search(/^https?:$/) === -1 ? 'http:' : ''
  5722. var protocol = opts.protocol || defaultProtocol
  5723. var host = opts.hostname || opts.host
  5724. var port = opts.port
  5725. var path = opts.path || '/'
  5726. // Necessary for IPv6 addresses
  5727. if (host && host.indexOf(':') !== -1)
  5728. host = '[' + host + ']'
  5729. // This may be a relative url. The browser should always be able to interpret it correctly.
  5730. opts.url = (host ? (protocol + '//' + host) : '') + (port ? ':' + port : '') + path
  5731. opts.method = (opts.method || 'GET').toUpperCase()
  5732. opts.headers = opts.headers || {}
  5733. // Also valid opts.auth, opts.mode
  5734. var req = new ClientRequest(opts)
  5735. if (cb)
  5736. req.on('response', cb)
  5737. return req
  5738. }
  5739. http.get = function get (opts, cb) {
  5740. var req = http.request(opts, cb)
  5741. req.end()
  5742. return req
  5743. }
  5744. http.ClientRequest = ClientRequest
  5745. http.IncomingMessage = response.IncomingMessage
  5746. http.Agent = function () {}
  5747. http.Agent.defaultMaxSockets = 4
  5748. http.globalAgent = new http.Agent()
  5749. http.STATUS_CODES = statusCodes
  5750. http.METHODS = [
  5751. 'CHECKOUT',
  5752. 'CONNECT',
  5753. 'COPY',
  5754. 'DELETE',
  5755. 'GET',
  5756. 'HEAD',
  5757. 'LOCK',
  5758. 'M-SEARCH',
  5759. 'MERGE',
  5760. 'MKACTIVITY',
  5761. 'MKCOL',
  5762. 'MOVE',
  5763. 'NOTIFY',
  5764. 'OPTIONS',
  5765. 'PATCH',
  5766. 'POST',
  5767. 'PROPFIND',
  5768. 'PROPPATCH',
  5769. 'PURGE',
  5770. 'PUT',
  5771. 'REPORT',
  5772. 'SEARCH',
  5773. 'SUBSCRIBE',
  5774. 'TRACE',
  5775. 'UNLOCK',
  5776. 'UNSUBSCRIBE'
  5777. ]
  5778. }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  5779. },{"./lib/request":19,"./lib/response":20,"builtin-status-codes":4,"url":37,"xtend":141}],18:[function(require,module,exports){
  5780. (function (global){(function (){
  5781. exports.fetch = isFunction(global.fetch) && isFunction(global.ReadableStream)
  5782. exports.writableStream = isFunction(global.WritableStream)
  5783. exports.abortController = isFunction(global.AbortController)
  5784. // The xhr request to example.com may violate some restrictive CSP configurations,
  5785. // so if we're running in a browser that supports `fetch`, avoid calling getXHR()
  5786. // and assume support for certain features below.
  5787. var xhr
  5788. function getXHR () {
  5789. // Cache the xhr value
  5790. if (xhr !== undefined) return xhr
  5791. if (global.XMLHttpRequest) {
  5792. xhr = new global.XMLHttpRequest()
  5793. // If XDomainRequest is available (ie only, where xhr might not work
  5794. // cross domain), use the page location. Otherwise use example.com
  5795. // Note: this doesn't actually make an http request.
  5796. try {
  5797. xhr.open('GET', global.XDomainRequest ? '/' : 'https://example.com')
  5798. } catch(e) {
  5799. xhr = null
  5800. }
  5801. } else {
  5802. // Service workers don't have XHR
  5803. xhr = null
  5804. }
  5805. return xhr
  5806. }
  5807. function checkTypeSupport (type) {
  5808. var xhr = getXHR()
  5809. if (!xhr) return false
  5810. try {
  5811. xhr.responseType = type
  5812. return xhr.responseType === type
  5813. } catch (e) {}
  5814. return false
  5815. }
  5816. // If fetch is supported, then arraybuffer will be supported too. Skip calling
  5817. // checkTypeSupport(), since that calls getXHR().
  5818. exports.arraybuffer = exports.fetch || checkTypeSupport('arraybuffer')
  5819. // These next two tests unavoidably show warnings in Chrome. Since fetch will always
  5820. // be used if it's available, just return false for these to avoid the warnings.
  5821. exports.msstream = !exports.fetch && checkTypeSupport('ms-stream')
  5822. exports.mozchunkedarraybuffer = !exports.fetch && checkTypeSupport('moz-chunked-arraybuffer')
  5823. // If fetch is supported, then overrideMimeType will be supported too. Skip calling
  5824. // getXHR().
  5825. exports.overrideMimeType = exports.fetch || (getXHR() ? isFunction(getXHR().overrideMimeType) : false)
  5826. function isFunction (value) {
  5827. return typeof value === 'function'
  5828. }
  5829. xhr = null // Help gc
  5830. }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  5831. },{}],19:[function(require,module,exports){
  5832. (function (process,global,Buffer){(function (){
  5833. var capability = require('./capability')
  5834. var inherits = require('inherits')
  5835. var response = require('./response')
  5836. var stream = require('readable-stream')
  5837. var IncomingMessage = response.IncomingMessage
  5838. var rStates = response.readyStates
  5839. function decideMode (preferBinary, useFetch) {
  5840. if (capability.fetch && useFetch) {
  5841. return 'fetch'
  5842. } else if (capability.mozchunkedarraybuffer) {
  5843. return 'moz-chunked-arraybuffer'
  5844. } else if (capability.msstream) {
  5845. return 'ms-stream'
  5846. } else if (capability.arraybuffer && preferBinary) {
  5847. return 'arraybuffer'
  5848. } else {
  5849. return 'text'
  5850. }
  5851. }
  5852. var ClientRequest = module.exports = function (opts) {
  5853. var self = this
  5854. stream.Writable.call(self)
  5855. self._opts = opts
  5856. self._body = []
  5857. self._headers = {}
  5858. if (opts.auth)
  5859. self.setHeader('Authorization', 'Basic ' + Buffer.from(opts.auth).toString('base64'))
  5860. Object.keys(opts.headers).forEach(function (name) {
  5861. self.setHeader(name, opts.headers[name])
  5862. })
  5863. var preferBinary
  5864. var useFetch = true
  5865. if (opts.mode === 'disable-fetch' || ('requestTimeout' in opts && !capability.abortController)) {
  5866. // If the use of XHR should be preferred. Not typically needed.
  5867. useFetch = false
  5868. preferBinary = true
  5869. } else if (opts.mode === 'prefer-streaming') {
  5870. // If streaming is a high priority but binary compatibility and
  5871. // the accuracy of the 'content-type' header aren't
  5872. preferBinary = false
  5873. } else if (opts.mode === 'allow-wrong-content-type') {
  5874. // If streaming is more important than preserving the 'content-type' header
  5875. preferBinary = !capability.overrideMimeType
  5876. } else if (!opts.mode || opts.mode === 'default' || opts.mode === 'prefer-fast') {
  5877. // Use binary if text streaming may corrupt data or the content-type header, or for speed
  5878. preferBinary = true
  5879. } else {
  5880. throw new Error('Invalid value for opts.mode')
  5881. }
  5882. self._mode = decideMode(preferBinary, useFetch)
  5883. self._fetchTimer = null
  5884. self._socketTimeout = null
  5885. self._socketTimer = null
  5886. self.on('finish', function () {
  5887. self._onFinish()
  5888. })
  5889. }
  5890. inherits(ClientRequest, stream.Writable)
  5891. ClientRequest.prototype.setHeader = function (name, value) {
  5892. var self = this
  5893. var lowerName = name.toLowerCase()
  5894. // This check is not necessary, but it prevents warnings from browsers about setting unsafe
  5895. // headers. To be honest I'm not entirely sure hiding these warnings is a good thing, but
  5896. // http-browserify did it, so I will too.
  5897. if (unsafeHeaders.indexOf(lowerName) !== -1)
  5898. return
  5899. self._headers[lowerName] = {
  5900. name: name,
  5901. value: value
  5902. }
  5903. }
  5904. ClientRequest.prototype.getHeader = function (name) {
  5905. var header = this._headers[name.toLowerCase()]
  5906. if (header)
  5907. return header.value
  5908. return null
  5909. }
  5910. ClientRequest.prototype.removeHeader = function (name) {
  5911. var self = this
  5912. delete self._headers[name.toLowerCase()]
  5913. }
  5914. ClientRequest.prototype._onFinish = function () {
  5915. var self = this
  5916. if (self._destroyed)
  5917. return
  5918. var opts = self._opts
  5919. if ('timeout' in opts && opts.timeout !== 0) {
  5920. self.setTimeout(opts.timeout)
  5921. }
  5922. var headersObj = self._headers
  5923. var body = null
  5924. if (opts.method !== 'GET' && opts.method !== 'HEAD') {
  5925. body = new Blob(self._body, {
  5926. type: (headersObj['content-type'] || {}).value || ''
  5927. });
  5928. }
  5929. // create flattened list of headers
  5930. var headersList = []
  5931. Object.keys(headersObj).forEach(function (keyName) {
  5932. var name = headersObj[keyName].name
  5933. var value = headersObj[keyName].value
  5934. if (Array.isArray(value)) {
  5935. value.forEach(function (v) {
  5936. headersList.push([name, v])
  5937. })
  5938. } else {
  5939. headersList.push([name, value])
  5940. }
  5941. })
  5942. if (self._mode === 'fetch') {
  5943. var signal = null
  5944. if (capability.abortController) {
  5945. var controller = new AbortController()
  5946. signal = controller.signal
  5947. self._fetchAbortController = controller
  5948. if ('requestTimeout' in opts && opts.requestTimeout !== 0) {
  5949. self._fetchTimer = global.setTimeout(function () {
  5950. self.emit('requestTimeout')
  5951. if (self._fetchAbortController)
  5952. self._fetchAbortController.abort()
  5953. }, opts.requestTimeout)
  5954. }
  5955. }
  5956. global.fetch(self._opts.url, {
  5957. method: self._opts.method,
  5958. headers: headersList,
  5959. body: body || undefined,
  5960. mode: 'cors',
  5961. credentials: opts.withCredentials ? 'include' : 'same-origin',
  5962. signal: signal
  5963. }).then(function (response) {
  5964. self._fetchResponse = response
  5965. self._resetTimers(false)
  5966. self._connect()
  5967. }, function (reason) {
  5968. self._resetTimers(true)
  5969. if (!self._destroyed)
  5970. self.emit('error', reason)
  5971. })
  5972. } else {
  5973. var xhr = self._xhr = new global.XMLHttpRequest()
  5974. try {
  5975. xhr.open(self._opts.method, self._opts.url, true)
  5976. } catch (err) {
  5977. process.nextTick(function () {
  5978. self.emit('error', err)
  5979. })
  5980. return
  5981. }
  5982. // Can't set responseType on really old browsers
  5983. if ('responseType' in xhr)
  5984. xhr.responseType = self._mode
  5985. if ('withCredentials' in xhr)
  5986. xhr.withCredentials = !!opts.withCredentials
  5987. if (self._mode === 'text' && 'overrideMimeType' in xhr)
  5988. xhr.overrideMimeType('text/plain; charset=x-user-defined')
  5989. if ('requestTimeout' in opts) {
  5990. xhr.timeout = opts.requestTimeout
  5991. xhr.ontimeout = function () {
  5992. self.emit('requestTimeout')
  5993. }
  5994. }
  5995. headersList.forEach(function (header) {
  5996. xhr.setRequestHeader(header[0], header[1])
  5997. })
  5998. self._response = null
  5999. xhr.onreadystatechange = function () {
  6000. switch (xhr.readyState) {
  6001. case rStates.LOADING:
  6002. case rStates.DONE:
  6003. self._onXHRProgress()
  6004. break
  6005. }
  6006. }
  6007. // Necessary for streaming in Firefox, since xhr.response is ONLY defined
  6008. // in onprogress, not in onreadystatechange with xhr.readyState = 3
  6009. if (self._mode === 'moz-chunked-arraybuffer') {
  6010. xhr.onprogress = function () {
  6011. self._onXHRProgress()
  6012. }
  6013. }
  6014. xhr.onerror = function () {
  6015. if (self._destroyed)
  6016. return
  6017. self._resetTimers(true)
  6018. self.emit('error', new Error('XHR error'))
  6019. }
  6020. try {
  6021. xhr.send(body)
  6022. } catch (err) {
  6023. process.nextTick(function () {
  6024. self.emit('error', err)
  6025. })
  6026. return
  6027. }
  6028. }
  6029. }
  6030. /**
  6031. * Checks if xhr.status is readable and non-zero, indicating no error.
  6032. * Even though the spec says it should be available in readyState 3,
  6033. * accessing it throws an exception in IE8
  6034. */
  6035. function statusValid (xhr) {
  6036. try {
  6037. var status = xhr.status
  6038. return (status !== null && status !== 0)
  6039. } catch (e) {
  6040. return false
  6041. }
  6042. }
  6043. ClientRequest.prototype._onXHRProgress = function () {
  6044. var self = this
  6045. self._resetTimers(false)
  6046. if (!statusValid(self._xhr) || self._destroyed)
  6047. return
  6048. if (!self._response)
  6049. self._connect()
  6050. self._response._onXHRProgress(self._resetTimers.bind(self))
  6051. }
  6052. ClientRequest.prototype._connect = function () {
  6053. var self = this
  6054. if (self._destroyed)
  6055. return
  6056. self._response = new IncomingMessage(self._xhr, self._fetchResponse, self._mode, self._resetTimers.bind(self))
  6057. self._response.on('error', function(err) {
  6058. self.emit('error', err)
  6059. })
  6060. self.emit('response', self._response)
  6061. }
  6062. ClientRequest.prototype._write = function (chunk, encoding, cb) {
  6063. var self = this
  6064. self._body.push(chunk)
  6065. cb()
  6066. }
  6067. ClientRequest.prototype._resetTimers = function (done) {
  6068. var self = this
  6069. global.clearTimeout(self._socketTimer)
  6070. self._socketTimer = null
  6071. if (done) {
  6072. global.clearTimeout(self._fetchTimer)
  6073. self._fetchTimer = null
  6074. } else if (self._socketTimeout) {
  6075. self._socketTimer = global.setTimeout(function () {
  6076. self.emit('timeout')
  6077. }, self._socketTimeout)
  6078. }
  6079. }
  6080. ClientRequest.prototype.abort = ClientRequest.prototype.destroy = function (err) {
  6081. var self = this
  6082. self._destroyed = true
  6083. self._resetTimers(true)
  6084. if (self._response)
  6085. self._response._destroyed = true
  6086. if (self._xhr)
  6087. self._xhr.abort()
  6088. else if (self._fetchAbortController)
  6089. self._fetchAbortController.abort()
  6090. if (err)
  6091. self.emit('error', err)
  6092. }
  6093. ClientRequest.prototype.end = function (data, encoding, cb) {
  6094. var self = this
  6095. if (typeof data === 'function') {
  6096. cb = data
  6097. data = undefined
  6098. }
  6099. stream.Writable.prototype.end.call(self, data, encoding, cb)
  6100. }
  6101. ClientRequest.prototype.setTimeout = function (timeout, cb) {
  6102. var self = this
  6103. if (cb)
  6104. self.once('timeout', cb)
  6105. self._socketTimeout = timeout
  6106. self._resetTimers(false)
  6107. }
  6108. ClientRequest.prototype.flushHeaders = function () {}
  6109. ClientRequest.prototype.setNoDelay = function () {}
  6110. ClientRequest.prototype.setSocketKeepAlive = function () {}
  6111. // Taken from http://www.w3.org/TR/XMLHttpRequest/#the-setrequestheader%28%29-method
  6112. var unsafeHeaders = [
  6113. 'accept-charset',
  6114. 'accept-encoding',
  6115. 'access-control-request-headers',
  6116. 'access-control-request-method',
  6117. 'connection',
  6118. 'content-length',
  6119. 'cookie',
  6120. 'cookie2',
  6121. 'date',
  6122. 'dnt',
  6123. 'expect',
  6124. 'host',
  6125. 'keep-alive',
  6126. 'origin',
  6127. 'referer',
  6128. 'te',
  6129. 'trailer',
  6130. 'transfer-encoding',
  6131. 'upgrade',
  6132. 'via'
  6133. ]
  6134. }).call(this)}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer)
  6135. },{"./capability":18,"./response":20,"_process":11,"buffer":3,"inherits":8,"readable-stream":35}],20:[function(require,module,exports){
  6136. (function (process,global,Buffer){(function (){
  6137. var capability = require('./capability')
  6138. var inherits = require('inherits')
  6139. var stream = require('readable-stream')
  6140. var rStates = exports.readyStates = {
  6141. UNSENT: 0,
  6142. OPENED: 1,
  6143. HEADERS_RECEIVED: 2,
  6144. LOADING: 3,
  6145. DONE: 4
  6146. }
  6147. var IncomingMessage = exports.IncomingMessage = function (xhr, response, mode, resetTimers) {
  6148. var self = this
  6149. stream.Readable.call(self)
  6150. self._mode = mode
  6151. self.headers = {}
  6152. self.rawHeaders = []
  6153. self.trailers = {}
  6154. self.rawTrailers = []
  6155. // Fake the 'close' event, but only once 'end' fires
  6156. self.on('end', function () {
  6157. // The nextTick is necessary to prevent the 'request' module from causing an infinite loop
  6158. process.nextTick(function () {
  6159. self.emit('close')
  6160. })
  6161. })
  6162. if (mode === 'fetch') {
  6163. self._fetchResponse = response
  6164. self.url = response.url
  6165. self.statusCode = response.status
  6166. self.statusMessage = response.statusText
  6167. response.headers.forEach(function (header, key){
  6168. self.headers[key.toLowerCase()] = header
  6169. self.rawHeaders.push(key, header)
  6170. })
  6171. if (capability.writableStream) {
  6172. var writable = new WritableStream({
  6173. write: function (chunk) {
  6174. resetTimers(false)
  6175. return new Promise(function (resolve, reject) {
  6176. if (self._destroyed) {
  6177. reject()
  6178. } else if(self.push(Buffer.from(chunk))) {
  6179. resolve()
  6180. } else {
  6181. self._resumeFetch = resolve
  6182. }
  6183. })
  6184. },
  6185. close: function () {
  6186. resetTimers(true)
  6187. if (!self._destroyed)
  6188. self.push(null)
  6189. },
  6190. abort: function (err) {
  6191. resetTimers(true)
  6192. if (!self._destroyed)
  6193. self.emit('error', err)
  6194. }
  6195. })
  6196. try {
  6197. response.body.pipeTo(writable).catch(function (err) {
  6198. resetTimers(true)
  6199. if (!self._destroyed)
  6200. self.emit('error', err)
  6201. })
  6202. return
  6203. } catch (e) {} // pipeTo method isn't defined. Can't find a better way to feature test this
  6204. }
  6205. // fallback for when writableStream or pipeTo aren't available
  6206. var reader = response.body.getReader()
  6207. function read () {
  6208. reader.read().then(function (result) {
  6209. if (self._destroyed)
  6210. return
  6211. resetTimers(result.done)
  6212. if (result.done) {
  6213. self.push(null)
  6214. return
  6215. }
  6216. self.push(Buffer.from(result.value))
  6217. read()
  6218. }).catch(function (err) {
  6219. resetTimers(true)
  6220. if (!self._destroyed)
  6221. self.emit('error', err)
  6222. })
  6223. }
  6224. read()
  6225. } else {
  6226. self._xhr = xhr
  6227. self._pos = 0
  6228. self.url = xhr.responseURL
  6229. self.statusCode = xhr.status
  6230. self.statusMessage = xhr.statusText
  6231. var headers = xhr.getAllResponseHeaders().split(/\r?\n/)
  6232. headers.forEach(function (header) {
  6233. var matches = header.match(/^([^:]+):\s*(.*)/)
  6234. if (matches) {
  6235. var key = matches[1].toLowerCase()
  6236. if (key === 'set-cookie') {
  6237. if (self.headers[key] === undefined) {
  6238. self.headers[key] = []
  6239. }
  6240. self.headers[key].push(matches[2])
  6241. } else if (self.headers[key] !== undefined) {
  6242. self.headers[key] += ', ' + matches[2]
  6243. } else {
  6244. self.headers[key] = matches[2]
  6245. }
  6246. self.rawHeaders.push(matches[1], matches[2])
  6247. }
  6248. })
  6249. self._charset = 'x-user-defined'
  6250. if (!capability.overrideMimeType) {
  6251. var mimeType = self.rawHeaders['mime-type']
  6252. if (mimeType) {
  6253. var charsetMatch = mimeType.match(/;\s*charset=([^;])(;|$)/)
  6254. if (charsetMatch) {
  6255. self._charset = charsetMatch[1].toLowerCase()
  6256. }
  6257. }
  6258. if (!self._charset)
  6259. self._charset = 'utf-8' // best guess
  6260. }
  6261. }
  6262. }
  6263. inherits(IncomingMessage, stream.Readable)
  6264. IncomingMessage.prototype._read = function () {
  6265. var self = this
  6266. var resolve = self._resumeFetch
  6267. if (resolve) {
  6268. self._resumeFetch = null
  6269. resolve()
  6270. }
  6271. }
  6272. IncomingMessage.prototype._onXHRProgress = function (resetTimers) {
  6273. var self = this
  6274. var xhr = self._xhr
  6275. var response = null
  6276. switch (self._mode) {
  6277. case 'text':
  6278. response = xhr.responseText
  6279. if (response.length > self._pos) {
  6280. var newData = response.substr(self._pos)
  6281. if (self._charset === 'x-user-defined') {
  6282. var buffer = Buffer.alloc(newData.length)
  6283. for (var i = 0; i < newData.length; i++)
  6284. buffer[i] = newData.charCodeAt(i) & 0xff
  6285. self.push(buffer)
  6286. } else {
  6287. self.push(newData, self._charset)
  6288. }
  6289. self._pos = response.length
  6290. }
  6291. break
  6292. case 'arraybuffer':
  6293. if (xhr.readyState !== rStates.DONE || !xhr.response)
  6294. break
  6295. response = xhr.response
  6296. self.push(Buffer.from(new Uint8Array(response)))
  6297. break
  6298. case 'moz-chunked-arraybuffer': // take whole
  6299. response = xhr.response
  6300. if (xhr.readyState !== rStates.LOADING || !response)
  6301. break
  6302. self.push(Buffer.from(new Uint8Array(response)))
  6303. break
  6304. case 'ms-stream':
  6305. response = xhr.response
  6306. if (xhr.readyState !== rStates.LOADING)
  6307. break
  6308. var reader = new global.MSStreamReader()
  6309. reader.onprogress = function () {
  6310. if (reader.result.byteLength > self._pos) {
  6311. self.push(Buffer.from(new Uint8Array(reader.result.slice(self._pos))))
  6312. self._pos = reader.result.byteLength
  6313. }
  6314. }
  6315. reader.onload = function () {
  6316. resetTimers(true)
  6317. self.push(null)
  6318. }
  6319. // reader.onerror = ??? // TODO: this
  6320. reader.readAsArrayBuffer(response)
  6321. break
  6322. }
  6323. // The ms-stream case handles end separately in reader.onload()
  6324. if (self._xhr.readyState === rStates.DONE && self._mode !== 'ms-stream') {
  6325. resetTimers(true)
  6326. self.push(null)
  6327. }
  6328. }
  6329. }).call(this)}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer)
  6330. },{"./capability":18,"_process":11,"buffer":3,"inherits":8,"readable-stream":35}],21:[function(require,module,exports){
  6331. 'use strict';
  6332. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  6333. var codes = {};
  6334. function createErrorType(code, message, Base) {
  6335. if (!Base) {
  6336. Base = Error;
  6337. }
  6338. function getMessage(arg1, arg2, arg3) {
  6339. if (typeof message === 'string') {
  6340. return message;
  6341. } else {
  6342. return message(arg1, arg2, arg3);
  6343. }
  6344. }
  6345. var NodeError =
  6346. /*#__PURE__*/
  6347. function (_Base) {
  6348. _inheritsLoose(NodeError, _Base);
  6349. function NodeError(arg1, arg2, arg3) {
  6350. return _Base.call(this, getMessage(arg1, arg2, arg3)) || this;
  6351. }
  6352. return NodeError;
  6353. }(Base);
  6354. NodeError.prototype.name = Base.name;
  6355. NodeError.prototype.code = code;
  6356. codes[code] = NodeError;
  6357. } // https://github.com/nodejs/node/blob/v10.8.0/lib/internal/errors.js
  6358. function oneOf(expected, thing) {
  6359. if (Array.isArray(expected)) {
  6360. var len = expected.length;
  6361. expected = expected.map(function (i) {
  6362. return String(i);
  6363. });
  6364. if (len > 2) {
  6365. return "one of ".concat(thing, " ").concat(expected.slice(0, len - 1).join(', '), ", or ") + expected[len - 1];
  6366. } else if (len === 2) {
  6367. return "one of ".concat(thing, " ").concat(expected[0], " or ").concat(expected[1]);
  6368. } else {
  6369. return "of ".concat(thing, " ").concat(expected[0]);
  6370. }
  6371. } else {
  6372. return "of ".concat(thing, " ").concat(String(expected));
  6373. }
  6374. } // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith
  6375. function startsWith(str, search, pos) {
  6376. return str.substr(!pos || pos < 0 ? 0 : +pos, search.length) === search;
  6377. } // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith
  6378. function endsWith(str, search, this_len) {
  6379. if (this_len === undefined || this_len > str.length) {
  6380. this_len = str.length;
  6381. }
  6382. return str.substring(this_len - search.length, this_len) === search;
  6383. } // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes
  6384. function includes(str, search, start) {
  6385. if (typeof start !== 'number') {
  6386. start = 0;
  6387. }
  6388. if (start + search.length > str.length) {
  6389. return false;
  6390. } else {
  6391. return str.indexOf(search, start) !== -1;
  6392. }
  6393. }
  6394. createErrorType('ERR_INVALID_OPT_VALUE', function (name, value) {
  6395. return 'The value "' + value + '" is invalid for option "' + name + '"';
  6396. }, TypeError);
  6397. createErrorType('ERR_INVALID_ARG_TYPE', function (name, expected, actual) {
  6398. // determiner: 'must be' or 'must not be'
  6399. var determiner;
  6400. if (typeof expected === 'string' && startsWith(expected, 'not ')) {
  6401. determiner = 'must not be';
  6402. expected = expected.replace(/^not /, '');
  6403. } else {
  6404. determiner = 'must be';
  6405. }
  6406. var msg;
  6407. if (endsWith(name, ' argument')) {
  6408. // For cases like 'first argument'
  6409. msg = "The ".concat(name, " ").concat(determiner, " ").concat(oneOf(expected, 'type'));
  6410. } else {
  6411. var type = includes(name, '.') ? 'property' : 'argument';
  6412. msg = "The \"".concat(name, "\" ").concat(type, " ").concat(determiner, " ").concat(oneOf(expected, 'type'));
  6413. }
  6414. msg += ". Received type ".concat(typeof actual);
  6415. return msg;
  6416. }, TypeError);
  6417. createErrorType('ERR_STREAM_PUSH_AFTER_EOF', 'stream.push() after EOF');
  6418. createErrorType('ERR_METHOD_NOT_IMPLEMENTED', function (name) {
  6419. return 'The ' + name + ' method is not implemented';
  6420. });
  6421. createErrorType('ERR_STREAM_PREMATURE_CLOSE', 'Premature close');
  6422. createErrorType('ERR_STREAM_DESTROYED', function (name) {
  6423. return 'Cannot call ' + name + ' after a stream was destroyed';
  6424. });
  6425. createErrorType('ERR_MULTIPLE_CALLBACK', 'Callback called multiple times');
  6426. createErrorType('ERR_STREAM_CANNOT_PIPE', 'Cannot pipe, not readable');
  6427. createErrorType('ERR_STREAM_WRITE_AFTER_END', 'write after end');
  6428. createErrorType('ERR_STREAM_NULL_VALUES', 'May not write null values to stream', TypeError);
  6429. createErrorType('ERR_UNKNOWN_ENCODING', function (arg) {
  6430. return 'Unknown encoding: ' + arg;
  6431. }, TypeError);
  6432. createErrorType('ERR_STREAM_UNSHIFT_AFTER_END_EVENT', 'stream.unshift() after end event');
  6433. module.exports.codes = codes;
  6434. },{}],22:[function(require,module,exports){
  6435. (function (process){(function (){
  6436. // Copyright Joyent, Inc. and other Node contributors.
  6437. //
  6438. // Permission is hereby granted, free of charge, to any person obtaining a
  6439. // copy of this software and associated documentation files (the
  6440. // "Software"), to deal in the Software without restriction, including
  6441. // without limitation the rights to use, copy, modify, merge, publish,
  6442. // distribute, sublicense, and/or sell copies of the Software, and to permit
  6443. // persons to whom the Software is furnished to do so, subject to the
  6444. // following conditions:
  6445. //
  6446. // The above copyright notice and this permission notice shall be included
  6447. // in all copies or substantial portions of the Software.
  6448. //
  6449. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  6450. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  6451. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  6452. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  6453. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  6454. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  6455. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  6456. // a duplex stream is just a stream that is both readable and writable.
  6457. // Since JS doesn't have multiple prototypal inheritance, this class
  6458. // prototypally inherits from Readable, and then parasitically from
  6459. // Writable.
  6460. 'use strict';
  6461. /*<replacement>*/
  6462. var objectKeys = Object.keys || function (obj) {
  6463. var keys = [];
  6464. for (var key in obj) {
  6465. keys.push(key);
  6466. }
  6467. return keys;
  6468. };
  6469. /*</replacement>*/
  6470. module.exports = Duplex;
  6471. var Readable = require('./_stream_readable');
  6472. var Writable = require('./_stream_writable');
  6473. require('inherits')(Duplex, Readable);
  6474. {
  6475. // Allow the keys array to be GC'ed.
  6476. var keys = objectKeys(Writable.prototype);
  6477. for (var v = 0; v < keys.length; v++) {
  6478. var method = keys[v];
  6479. if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method];
  6480. }
  6481. }
  6482. function Duplex(options) {
  6483. if (!(this instanceof Duplex)) return new Duplex(options);
  6484. Readable.call(this, options);
  6485. Writable.call(this, options);
  6486. this.allowHalfOpen = true;
  6487. if (options) {
  6488. if (options.readable === false) this.readable = false;
  6489. if (options.writable === false) this.writable = false;
  6490. if (options.allowHalfOpen === false) {
  6491. this.allowHalfOpen = false;
  6492. this.once('end', onend);
  6493. }
  6494. }
  6495. }
  6496. Object.defineProperty(Duplex.prototype, 'writableHighWaterMark', {
  6497. // making it explicit this property is not enumerable
  6498. // because otherwise some prototype manipulation in
  6499. // userland will fail
  6500. enumerable: false,
  6501. get: function get() {
  6502. return this._writableState.highWaterMark;
  6503. }
  6504. });
  6505. Object.defineProperty(Duplex.prototype, 'writableBuffer', {
  6506. // making it explicit this property is not enumerable
  6507. // because otherwise some prototype manipulation in
  6508. // userland will fail
  6509. enumerable: false,
  6510. get: function get() {
  6511. return this._writableState && this._writableState.getBuffer();
  6512. }
  6513. });
  6514. Object.defineProperty(Duplex.prototype, 'writableLength', {
  6515. // making it explicit this property is not enumerable
  6516. // because otherwise some prototype manipulation in
  6517. // userland will fail
  6518. enumerable: false,
  6519. get: function get() {
  6520. return this._writableState.length;
  6521. }
  6522. }); // the no-half-open enforcer
  6523. function onend() {
  6524. // If the writable side ended, then we're ok.
  6525. if (this._writableState.ended) return; // no more data can be written.
  6526. // But allow more writes to happen in this tick.
  6527. process.nextTick(onEndNT, this);
  6528. }
  6529. function onEndNT(self) {
  6530. self.end();
  6531. }
  6532. Object.defineProperty(Duplex.prototype, 'destroyed', {
  6533. // making it explicit this property is not enumerable
  6534. // because otherwise some prototype manipulation in
  6535. // userland will fail
  6536. enumerable: false,
  6537. get: function get() {
  6538. if (this._readableState === undefined || this._writableState === undefined) {
  6539. return false;
  6540. }
  6541. return this._readableState.destroyed && this._writableState.destroyed;
  6542. },
  6543. set: function set(value) {
  6544. // we ignore the value if the stream
  6545. // has not been initialized yet
  6546. if (this._readableState === undefined || this._writableState === undefined) {
  6547. return;
  6548. } // backward compatibility, the user is explicitly
  6549. // managing destroyed
  6550. this._readableState.destroyed = value;
  6551. this._writableState.destroyed = value;
  6552. }
  6553. });
  6554. }).call(this)}).call(this,require('_process'))
  6555. },{"./_stream_readable":24,"./_stream_writable":26,"_process":11,"inherits":8}],23:[function(require,module,exports){
  6556. // Copyright Joyent, Inc. and other Node contributors.
  6557. //
  6558. // Permission is hereby granted, free of charge, to any person obtaining a
  6559. // copy of this software and associated documentation files (the
  6560. // "Software"), to deal in the Software without restriction, including
  6561. // without limitation the rights to use, copy, modify, merge, publish,
  6562. // distribute, sublicense, and/or sell copies of the Software, and to permit
  6563. // persons to whom the Software is furnished to do so, subject to the
  6564. // following conditions:
  6565. //
  6566. // The above copyright notice and this permission notice shall be included
  6567. // in all copies or substantial portions of the Software.
  6568. //
  6569. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  6570. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  6571. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  6572. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  6573. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  6574. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  6575. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  6576. // a passthrough stream.
  6577. // basically just the most minimal sort of Transform stream.
  6578. // Every written chunk gets output as-is.
  6579. 'use strict';
  6580. module.exports = PassThrough;
  6581. var Transform = require('./_stream_transform');
  6582. require('inherits')(PassThrough, Transform);
  6583. function PassThrough(options) {
  6584. if (!(this instanceof PassThrough)) return new PassThrough(options);
  6585. Transform.call(this, options);
  6586. }
  6587. PassThrough.prototype._transform = function (chunk, encoding, cb) {
  6588. cb(null, chunk);
  6589. };
  6590. },{"./_stream_transform":25,"inherits":8}],24:[function(require,module,exports){
  6591. (function (process,global){(function (){
  6592. // Copyright Joyent, Inc. and other Node contributors.
  6593. //
  6594. // Permission is hereby granted, free of charge, to any person obtaining a
  6595. // copy of this software and associated documentation files (the
  6596. // "Software"), to deal in the Software without restriction, including
  6597. // without limitation the rights to use, copy, modify, merge, publish,
  6598. // distribute, sublicense, and/or sell copies of the Software, and to permit
  6599. // persons to whom the Software is furnished to do so, subject to the
  6600. // following conditions:
  6601. //
  6602. // The above copyright notice and this permission notice shall be included
  6603. // in all copies or substantial portions of the Software.
  6604. //
  6605. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  6606. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  6607. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  6608. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  6609. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  6610. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  6611. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  6612. 'use strict';
  6613. module.exports = Readable;
  6614. /*<replacement>*/
  6615. var Duplex;
  6616. /*</replacement>*/
  6617. Readable.ReadableState = ReadableState;
  6618. /*<replacement>*/
  6619. var EE = require('events').EventEmitter;
  6620. var EElistenerCount = function EElistenerCount(emitter, type) {
  6621. return emitter.listeners(type).length;
  6622. };
  6623. /*</replacement>*/
  6624. /*<replacement>*/
  6625. var Stream = require('./internal/streams/stream');
  6626. /*</replacement>*/
  6627. var Buffer = require('buffer').Buffer;
  6628. var OurUint8Array = global.Uint8Array || function () {};
  6629. function _uint8ArrayToBuffer(chunk) {
  6630. return Buffer.from(chunk);
  6631. }
  6632. function _isUint8Array(obj) {
  6633. return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
  6634. }
  6635. /*<replacement>*/
  6636. var debugUtil = require('util');
  6637. var debug;
  6638. if (debugUtil && debugUtil.debuglog) {
  6639. debug = debugUtil.debuglog('stream');
  6640. } else {
  6641. debug = function debug() {};
  6642. }
  6643. /*</replacement>*/
  6644. var BufferList = require('./internal/streams/buffer_list');
  6645. var destroyImpl = require('./internal/streams/destroy');
  6646. var _require = require('./internal/streams/state'),
  6647. getHighWaterMark = _require.getHighWaterMark;
  6648. var _require$codes = require('../errors').codes,
  6649. ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE,
  6650. ERR_STREAM_PUSH_AFTER_EOF = _require$codes.ERR_STREAM_PUSH_AFTER_EOF,
  6651. ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED,
  6652. ERR_STREAM_UNSHIFT_AFTER_END_EVENT = _require$codes.ERR_STREAM_UNSHIFT_AFTER_END_EVENT; // Lazy loaded to improve the startup performance.
  6653. var StringDecoder;
  6654. var createReadableStreamAsyncIterator;
  6655. var from;
  6656. require('inherits')(Readable, Stream);
  6657. var errorOrDestroy = destroyImpl.errorOrDestroy;
  6658. var kProxyEvents = ['error', 'close', 'destroy', 'pause', 'resume'];
  6659. function prependListener(emitter, event, fn) {
  6660. // Sadly this is not cacheable as some libraries bundle their own
  6661. // event emitter implementation with them.
  6662. if (typeof emitter.prependListener === 'function') return emitter.prependListener(event, fn); // This is a hack to make sure that our error handler is attached before any
  6663. // userland ones. NEVER DO THIS. This is here only because this code needs
  6664. // to continue to work with older versions of Node.js that do not include
  6665. // the prependListener() method. The goal is to eventually remove this hack.
  6666. if (!emitter._events || !emitter._events[event]) emitter.on(event, fn);else if (Array.isArray(emitter._events[event])) emitter._events[event].unshift(fn);else emitter._events[event] = [fn, emitter._events[event]];
  6667. }
  6668. function ReadableState(options, stream, isDuplex) {
  6669. Duplex = Duplex || require('./_stream_duplex');
  6670. options = options || {}; // Duplex streams are both readable and writable, but share
  6671. // the same options object.
  6672. // However, some cases require setting options to different
  6673. // values for the readable and the writable sides of the duplex stream.
  6674. // These options can be provided separately as readableXXX and writableXXX.
  6675. if (typeof isDuplex !== 'boolean') isDuplex = stream instanceof Duplex; // object stream flag. Used to make read(n) ignore n and to
  6676. // make all the buffer merging and length checks go away
  6677. this.objectMode = !!options.objectMode;
  6678. if (isDuplex) this.objectMode = this.objectMode || !!options.readableObjectMode; // the point at which it stops calling _read() to fill the buffer
  6679. // Note: 0 is a valid value, means "don't call _read preemptively ever"
  6680. this.highWaterMark = getHighWaterMark(this, options, 'readableHighWaterMark', isDuplex); // A linked list is used to store data chunks instead of an array because the
  6681. // linked list can remove elements from the beginning faster than
  6682. // array.shift()
  6683. this.buffer = new BufferList();
  6684. this.length = 0;
  6685. this.pipes = null;
  6686. this.pipesCount = 0;
  6687. this.flowing = null;
  6688. this.ended = false;
  6689. this.endEmitted = false;
  6690. this.reading = false; // a flag to be able to tell if the event 'readable'/'data' is emitted
  6691. // immediately, or on a later tick. We set this to true at first, because
  6692. // any actions that shouldn't happen until "later" should generally also
  6693. // not happen before the first read call.
  6694. this.sync = true; // whenever we return null, then we set a flag to say
  6695. // that we're awaiting a 'readable' event emission.
  6696. this.needReadable = false;
  6697. this.emittedReadable = false;
  6698. this.readableListening = false;
  6699. this.resumeScheduled = false;
  6700. this.paused = true; // Should close be emitted on destroy. Defaults to true.
  6701. this.emitClose = options.emitClose !== false; // Should .destroy() be called after 'end' (and potentially 'finish')
  6702. this.autoDestroy = !!options.autoDestroy; // has it been destroyed
  6703. this.destroyed = false; // Crypto is kind of old and crusty. Historically, its default string
  6704. // encoding is 'binary' so we have to make this configurable.
  6705. // Everything else in the universe uses 'utf8', though.
  6706. this.defaultEncoding = options.defaultEncoding || 'utf8'; // the number of writers that are awaiting a drain event in .pipe()s
  6707. this.awaitDrain = 0; // if true, a maybeReadMore has been scheduled
  6708. this.readingMore = false;
  6709. this.decoder = null;
  6710. this.encoding = null;
  6711. if (options.encoding) {
  6712. if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
  6713. this.decoder = new StringDecoder(options.encoding);
  6714. this.encoding = options.encoding;
  6715. }
  6716. }
  6717. function Readable(options) {
  6718. Duplex = Duplex || require('./_stream_duplex');
  6719. if (!(this instanceof Readable)) return new Readable(options); // Checking for a Stream.Duplex instance is faster here instead of inside
  6720. // the ReadableState constructor, at least with V8 6.5
  6721. var isDuplex = this instanceof Duplex;
  6722. this._readableState = new ReadableState(options, this, isDuplex); // legacy
  6723. this.readable = true;
  6724. if (options) {
  6725. if (typeof options.read === 'function') this._read = options.read;
  6726. if (typeof options.destroy === 'function') this._destroy = options.destroy;
  6727. }
  6728. Stream.call(this);
  6729. }
  6730. Object.defineProperty(Readable.prototype, 'destroyed', {
  6731. // making it explicit this property is not enumerable
  6732. // because otherwise some prototype manipulation in
  6733. // userland will fail
  6734. enumerable: false,
  6735. get: function get() {
  6736. if (this._readableState === undefined) {
  6737. return false;
  6738. }
  6739. return this._readableState.destroyed;
  6740. },
  6741. set: function set(value) {
  6742. // we ignore the value if the stream
  6743. // has not been initialized yet
  6744. if (!this._readableState) {
  6745. return;
  6746. } // backward compatibility, the user is explicitly
  6747. // managing destroyed
  6748. this._readableState.destroyed = value;
  6749. }
  6750. });
  6751. Readable.prototype.destroy = destroyImpl.destroy;
  6752. Readable.prototype._undestroy = destroyImpl.undestroy;
  6753. Readable.prototype._destroy = function (err, cb) {
  6754. cb(err);
  6755. }; // Manually shove something into the read() buffer.
  6756. // This returns true if the highWaterMark has not been hit yet,
  6757. // similar to how Writable.write() returns true if you should
  6758. // write() some more.
  6759. Readable.prototype.push = function (chunk, encoding) {
  6760. var state = this._readableState;
  6761. var skipChunkCheck;
  6762. if (!state.objectMode) {
  6763. if (typeof chunk === 'string') {
  6764. encoding = encoding || state.defaultEncoding;
  6765. if (encoding !== state.encoding) {
  6766. chunk = Buffer.from(chunk, encoding);
  6767. encoding = '';
  6768. }
  6769. skipChunkCheck = true;
  6770. }
  6771. } else {
  6772. skipChunkCheck = true;
  6773. }
  6774. return readableAddChunk(this, chunk, encoding, false, skipChunkCheck);
  6775. }; // Unshift should *always* be something directly out of read()
  6776. Readable.prototype.unshift = function (chunk) {
  6777. return readableAddChunk(this, chunk, null, true, false);
  6778. };
  6779. function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) {
  6780. debug('readableAddChunk', chunk);
  6781. var state = stream._readableState;
  6782. if (chunk === null) {
  6783. state.reading = false;
  6784. onEofChunk(stream, state);
  6785. } else {
  6786. var er;
  6787. if (!skipChunkCheck) er = chunkInvalid(state, chunk);
  6788. if (er) {
  6789. errorOrDestroy(stream, er);
  6790. } else if (state.objectMode || chunk && chunk.length > 0) {
  6791. if (typeof chunk !== 'string' && !state.objectMode && Object.getPrototypeOf(chunk) !== Buffer.prototype) {
  6792. chunk = _uint8ArrayToBuffer(chunk);
  6793. }
  6794. if (addToFront) {
  6795. if (state.endEmitted) errorOrDestroy(stream, new ERR_STREAM_UNSHIFT_AFTER_END_EVENT());else addChunk(stream, state, chunk, true);
  6796. } else if (state.ended) {
  6797. errorOrDestroy(stream, new ERR_STREAM_PUSH_AFTER_EOF());
  6798. } else if (state.destroyed) {
  6799. return false;
  6800. } else {
  6801. state.reading = false;
  6802. if (state.decoder && !encoding) {
  6803. chunk = state.decoder.write(chunk);
  6804. if (state.objectMode || chunk.length !== 0) addChunk(stream, state, chunk, false);else maybeReadMore(stream, state);
  6805. } else {
  6806. addChunk(stream, state, chunk, false);
  6807. }
  6808. }
  6809. } else if (!addToFront) {
  6810. state.reading = false;
  6811. maybeReadMore(stream, state);
  6812. }
  6813. } // We can push more data if we are below the highWaterMark.
  6814. // Also, if we have no data yet, we can stand some more bytes.
  6815. // This is to work around cases where hwm=0, such as the repl.
  6816. return !state.ended && (state.length < state.highWaterMark || state.length === 0);
  6817. }
  6818. function addChunk(stream, state, chunk, addToFront) {
  6819. if (state.flowing && state.length === 0 && !state.sync) {
  6820. state.awaitDrain = 0;
  6821. stream.emit('data', chunk);
  6822. } else {
  6823. // update the buffer info.
  6824. state.length += state.objectMode ? 1 : chunk.length;
  6825. if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk);
  6826. if (state.needReadable) emitReadable(stream);
  6827. }
  6828. maybeReadMore(stream, state);
  6829. }
  6830. function chunkInvalid(state, chunk) {
  6831. var er;
  6832. if (!_isUint8Array(chunk) && typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
  6833. er = new ERR_INVALID_ARG_TYPE('chunk', ['string', 'Buffer', 'Uint8Array'], chunk);
  6834. }
  6835. return er;
  6836. }
  6837. Readable.prototype.isPaused = function () {
  6838. return this._readableState.flowing === false;
  6839. }; // backwards compatibility.
  6840. Readable.prototype.setEncoding = function (enc) {
  6841. if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
  6842. var decoder = new StringDecoder(enc);
  6843. this._readableState.decoder = decoder; // If setEncoding(null), decoder.encoding equals utf8
  6844. this._readableState.encoding = this._readableState.decoder.encoding; // Iterate over current buffer to convert already stored Buffers:
  6845. var p = this._readableState.buffer.head;
  6846. var content = '';
  6847. while (p !== null) {
  6848. content += decoder.write(p.data);
  6849. p = p.next;
  6850. }
  6851. this._readableState.buffer.clear();
  6852. if (content !== '') this._readableState.buffer.push(content);
  6853. this._readableState.length = content.length;
  6854. return this;
  6855. }; // Don't raise the hwm > 1GB
  6856. var MAX_HWM = 0x40000000;
  6857. function computeNewHighWaterMark(n) {
  6858. if (n >= MAX_HWM) {
  6859. // TODO(ronag): Throw ERR_VALUE_OUT_OF_RANGE.
  6860. n = MAX_HWM;
  6861. } else {
  6862. // Get the next highest power of 2 to prevent increasing hwm excessively in
  6863. // tiny amounts
  6864. n--;
  6865. n |= n >>> 1;
  6866. n |= n >>> 2;
  6867. n |= n >>> 4;
  6868. n |= n >>> 8;
  6869. n |= n >>> 16;
  6870. n++;
  6871. }
  6872. return n;
  6873. } // This function is designed to be inlinable, so please take care when making
  6874. // changes to the function body.
  6875. function howMuchToRead(n, state) {
  6876. if (n <= 0 || state.length === 0 && state.ended) return 0;
  6877. if (state.objectMode) return 1;
  6878. if (n !== n) {
  6879. // Only flow one buffer at a time
  6880. if (state.flowing && state.length) return state.buffer.head.data.length;else return state.length;
  6881. } // If we're asking for more than the current hwm, then raise the hwm.
  6882. if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n);
  6883. if (n <= state.length) return n; // Don't have enough
  6884. if (!state.ended) {
  6885. state.needReadable = true;
  6886. return 0;
  6887. }
  6888. return state.length;
  6889. } // you can override either this method, or the async _read(n) below.
  6890. Readable.prototype.read = function (n) {
  6891. debug('read', n);
  6892. n = parseInt(n, 10);
  6893. var state = this._readableState;
  6894. var nOrig = n;
  6895. if (n !== 0) state.emittedReadable = false; // if we're doing read(0) to trigger a readable event, but we
  6896. // already have a bunch of data in the buffer, then just trigger
  6897. // the 'readable' event and move on.
  6898. if (n === 0 && state.needReadable && ((state.highWaterMark !== 0 ? state.length >= state.highWaterMark : state.length > 0) || state.ended)) {
  6899. debug('read: emitReadable', state.length, state.ended);
  6900. if (state.length === 0 && state.ended) endReadable(this);else emitReadable(this);
  6901. return null;
  6902. }
  6903. n = howMuchToRead(n, state); // if we've ended, and we're now clear, then finish it up.
  6904. if (n === 0 && state.ended) {
  6905. if (state.length === 0) endReadable(this);
  6906. return null;
  6907. } // All the actual chunk generation logic needs to be
  6908. // *below* the call to _read. The reason is that in certain
  6909. // synthetic stream cases, such as passthrough streams, _read
  6910. // may be a completely synchronous operation which may change
  6911. // the state of the read buffer, providing enough data when
  6912. // before there was *not* enough.
  6913. //
  6914. // So, the steps are:
  6915. // 1. Figure out what the state of things will be after we do
  6916. // a read from the buffer.
  6917. //
  6918. // 2. If that resulting state will trigger a _read, then call _read.
  6919. // Note that this may be asynchronous, or synchronous. Yes, it is
  6920. // deeply ugly to write APIs this way, but that still doesn't mean
  6921. // that the Readable class should behave improperly, as streams are
  6922. // designed to be sync/async agnostic.
  6923. // Take note if the _read call is sync or async (ie, if the read call
  6924. // has returned yet), so that we know whether or not it's safe to emit
  6925. // 'readable' etc.
  6926. //
  6927. // 3. Actually pull the requested chunks out of the buffer and return.
  6928. // if we need a readable event, then we need to do some reading.
  6929. var doRead = state.needReadable;
  6930. debug('need readable', doRead); // if we currently have less than the highWaterMark, then also read some
  6931. if (state.length === 0 || state.length - n < state.highWaterMark) {
  6932. doRead = true;
  6933. debug('length less than watermark', doRead);
  6934. } // however, if we've ended, then there's no point, and if we're already
  6935. // reading, then it's unnecessary.
  6936. if (state.ended || state.reading) {
  6937. doRead = false;
  6938. debug('reading or ended', doRead);
  6939. } else if (doRead) {
  6940. debug('do read');
  6941. state.reading = true;
  6942. state.sync = true; // if the length is currently zero, then we *need* a readable event.
  6943. if (state.length === 0) state.needReadable = true; // call internal read method
  6944. this._read(state.highWaterMark);
  6945. state.sync = false; // If _read pushed data synchronously, then `reading` will be false,
  6946. // and we need to re-evaluate how much data we can return to the user.
  6947. if (!state.reading) n = howMuchToRead(nOrig, state);
  6948. }
  6949. var ret;
  6950. if (n > 0) ret = fromList(n, state);else ret = null;
  6951. if (ret === null) {
  6952. state.needReadable = state.length <= state.highWaterMark;
  6953. n = 0;
  6954. } else {
  6955. state.length -= n;
  6956. state.awaitDrain = 0;
  6957. }
  6958. if (state.length === 0) {
  6959. // If we have nothing in the buffer, then we want to know
  6960. // as soon as we *do* get something into the buffer.
  6961. if (!state.ended) state.needReadable = true; // If we tried to read() past the EOF, then emit end on the next tick.
  6962. if (nOrig !== n && state.ended) endReadable(this);
  6963. }
  6964. if (ret !== null) this.emit('data', ret);
  6965. return ret;
  6966. };
  6967. function onEofChunk(stream, state) {
  6968. debug('onEofChunk');
  6969. if (state.ended) return;
  6970. if (state.decoder) {
  6971. var chunk = state.decoder.end();
  6972. if (chunk && chunk.length) {
  6973. state.buffer.push(chunk);
  6974. state.length += state.objectMode ? 1 : chunk.length;
  6975. }
  6976. }
  6977. state.ended = true;
  6978. if (state.sync) {
  6979. // if we are sync, wait until next tick to emit the data.
  6980. // Otherwise we risk emitting data in the flow()
  6981. // the readable code triggers during a read() call
  6982. emitReadable(stream);
  6983. } else {
  6984. // emit 'readable' now to make sure it gets picked up.
  6985. state.needReadable = false;
  6986. if (!state.emittedReadable) {
  6987. state.emittedReadable = true;
  6988. emitReadable_(stream);
  6989. }
  6990. }
  6991. } // Don't emit readable right away in sync mode, because this can trigger
  6992. // another read() call => stack overflow. This way, it might trigger
  6993. // a nextTick recursion warning, but that's not so bad.
  6994. function emitReadable(stream) {
  6995. var state = stream._readableState;
  6996. debug('emitReadable', state.needReadable, state.emittedReadable);
  6997. state.needReadable = false;
  6998. if (!state.emittedReadable) {
  6999. debug('emitReadable', state.flowing);
  7000. state.emittedReadable = true;
  7001. process.nextTick(emitReadable_, stream);
  7002. }
  7003. }
  7004. function emitReadable_(stream) {
  7005. var state = stream._readableState;
  7006. debug('emitReadable_', state.destroyed, state.length, state.ended);
  7007. if (!state.destroyed && (state.length || state.ended)) {
  7008. stream.emit('readable');
  7009. state.emittedReadable = false;
  7010. } // The stream needs another readable event if
  7011. // 1. It is not flowing, as the flow mechanism will take
  7012. // care of it.
  7013. // 2. It is not ended.
  7014. // 3. It is below the highWaterMark, so we can schedule
  7015. // another readable later.
  7016. state.needReadable = !state.flowing && !state.ended && state.length <= state.highWaterMark;
  7017. flow(stream);
  7018. } // at this point, the user has presumably seen the 'readable' event,
  7019. // and called read() to consume some data. that may have triggered
  7020. // in turn another _read(n) call, in which case reading = true if
  7021. // it's in progress.
  7022. // However, if we're not ended, or reading, and the length < hwm,
  7023. // then go ahead and try to read some more preemptively.
  7024. function maybeReadMore(stream, state) {
  7025. if (!state.readingMore) {
  7026. state.readingMore = true;
  7027. process.nextTick(maybeReadMore_, stream, state);
  7028. }
  7029. }
  7030. function maybeReadMore_(stream, state) {
  7031. // Attempt to read more data if we should.
  7032. //
  7033. // The conditions for reading more data are (one of):
  7034. // - Not enough data buffered (state.length < state.highWaterMark). The loop
  7035. // is responsible for filling the buffer with enough data if such data
  7036. // is available. If highWaterMark is 0 and we are not in the flowing mode
  7037. // we should _not_ attempt to buffer any extra data. We'll get more data
  7038. // when the stream consumer calls read() instead.
  7039. // - No data in the buffer, and the stream is in flowing mode. In this mode
  7040. // the loop below is responsible for ensuring read() is called. Failing to
  7041. // call read here would abort the flow and there's no other mechanism for
  7042. // continuing the flow if the stream consumer has just subscribed to the
  7043. // 'data' event.
  7044. //
  7045. // In addition to the above conditions to keep reading data, the following
  7046. // conditions prevent the data from being read:
  7047. // - The stream has ended (state.ended).
  7048. // - There is already a pending 'read' operation (state.reading). This is a
  7049. // case where the the stream has called the implementation defined _read()
  7050. // method, but they are processing the call asynchronously and have _not_
  7051. // called push() with new data. In this case we skip performing more
  7052. // read()s. The execution ends in this method again after the _read() ends
  7053. // up calling push() with more data.
  7054. while (!state.reading && !state.ended && (state.length < state.highWaterMark || state.flowing && state.length === 0)) {
  7055. var len = state.length;
  7056. debug('maybeReadMore read 0');
  7057. stream.read(0);
  7058. if (len === state.length) // didn't get any data, stop spinning.
  7059. break;
  7060. }
  7061. state.readingMore = false;
  7062. } // abstract method. to be overridden in specific implementation classes.
  7063. // call cb(er, data) where data is <= n in length.
  7064. // for virtual (non-string, non-buffer) streams, "length" is somewhat
  7065. // arbitrary, and perhaps not very meaningful.
  7066. Readable.prototype._read = function (n) {
  7067. errorOrDestroy(this, new ERR_METHOD_NOT_IMPLEMENTED('_read()'));
  7068. };
  7069. Readable.prototype.pipe = function (dest, pipeOpts) {
  7070. var src = this;
  7071. var state = this._readableState;
  7072. switch (state.pipesCount) {
  7073. case 0:
  7074. state.pipes = dest;
  7075. break;
  7076. case 1:
  7077. state.pipes = [state.pipes, dest];
  7078. break;
  7079. default:
  7080. state.pipes.push(dest);
  7081. break;
  7082. }
  7083. state.pipesCount += 1;
  7084. debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts);
  7085. var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr;
  7086. var endFn = doEnd ? onend : unpipe;
  7087. if (state.endEmitted) process.nextTick(endFn);else src.once('end', endFn);
  7088. dest.on('unpipe', onunpipe);
  7089. function onunpipe(readable, unpipeInfo) {
  7090. debug('onunpipe');
  7091. if (readable === src) {
  7092. if (unpipeInfo && unpipeInfo.hasUnpiped === false) {
  7093. unpipeInfo.hasUnpiped = true;
  7094. cleanup();
  7095. }
  7096. }
  7097. }
  7098. function onend() {
  7099. debug('onend');
  7100. dest.end();
  7101. } // when the dest drains, it reduces the awaitDrain counter
  7102. // on the source. This would be more elegant with a .once()
  7103. // handler in flow(), but adding and removing repeatedly is
  7104. // too slow.
  7105. var ondrain = pipeOnDrain(src);
  7106. dest.on('drain', ondrain);
  7107. var cleanedUp = false;
  7108. function cleanup() {
  7109. debug('cleanup'); // cleanup event handlers once the pipe is broken
  7110. dest.removeListener('close', onclose);
  7111. dest.removeListener('finish', onfinish);
  7112. dest.removeListener('drain', ondrain);
  7113. dest.removeListener('error', onerror);
  7114. dest.removeListener('unpipe', onunpipe);
  7115. src.removeListener('end', onend);
  7116. src.removeListener('end', unpipe);
  7117. src.removeListener('data', ondata);
  7118. cleanedUp = true; // if the reader is waiting for a drain event from this
  7119. // specific writer, then it would cause it to never start
  7120. // flowing again.
  7121. // So, if this is awaiting a drain, then we just call it now.
  7122. // If we don't know, then assume that we are waiting for one.
  7123. if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain();
  7124. }
  7125. src.on('data', ondata);
  7126. function ondata(chunk) {
  7127. debug('ondata');
  7128. var ret = dest.write(chunk);
  7129. debug('dest.write', ret);
  7130. if (ret === false) {
  7131. // If the user unpiped during `dest.write()`, it is possible
  7132. // to get stuck in a permanently paused state if that write
  7133. // also returned false.
  7134. // => Check whether `dest` is still a piping destination.
  7135. if ((state.pipesCount === 1 && state.pipes === dest || state.pipesCount > 1 && indexOf(state.pipes, dest) !== -1) && !cleanedUp) {
  7136. debug('false write response, pause', state.awaitDrain);
  7137. state.awaitDrain++;
  7138. }
  7139. src.pause();
  7140. }
  7141. } // if the dest has an error, then stop piping into it.
  7142. // however, don't suppress the throwing behavior for this.
  7143. function onerror(er) {
  7144. debug('onerror', er);
  7145. unpipe();
  7146. dest.removeListener('error', onerror);
  7147. if (EElistenerCount(dest, 'error') === 0) errorOrDestroy(dest, er);
  7148. } // Make sure our error handler is attached before userland ones.
  7149. prependListener(dest, 'error', onerror); // Both close and finish should trigger unpipe, but only once.
  7150. function onclose() {
  7151. dest.removeListener('finish', onfinish);
  7152. unpipe();
  7153. }
  7154. dest.once('close', onclose);
  7155. function onfinish() {
  7156. debug('onfinish');
  7157. dest.removeListener('close', onclose);
  7158. unpipe();
  7159. }
  7160. dest.once('finish', onfinish);
  7161. function unpipe() {
  7162. debug('unpipe');
  7163. src.unpipe(dest);
  7164. } // tell the dest that it's being piped to
  7165. dest.emit('pipe', src); // start the flow if it hasn't been started already.
  7166. if (!state.flowing) {
  7167. debug('pipe resume');
  7168. src.resume();
  7169. }
  7170. return dest;
  7171. };
  7172. function pipeOnDrain(src) {
  7173. return function pipeOnDrainFunctionResult() {
  7174. var state = src._readableState;
  7175. debug('pipeOnDrain', state.awaitDrain);
  7176. if (state.awaitDrain) state.awaitDrain--;
  7177. if (state.awaitDrain === 0 && EElistenerCount(src, 'data')) {
  7178. state.flowing = true;
  7179. flow(src);
  7180. }
  7181. };
  7182. }
  7183. Readable.prototype.unpipe = function (dest) {
  7184. var state = this._readableState;
  7185. var unpipeInfo = {
  7186. hasUnpiped: false
  7187. }; // if we're not piping anywhere, then do nothing.
  7188. if (state.pipesCount === 0) return this; // just one destination. most common case.
  7189. if (state.pipesCount === 1) {
  7190. // passed in one, but it's not the right one.
  7191. if (dest && dest !== state.pipes) return this;
  7192. if (!dest) dest = state.pipes; // got a match.
  7193. state.pipes = null;
  7194. state.pipesCount = 0;
  7195. state.flowing = false;
  7196. if (dest) dest.emit('unpipe', this, unpipeInfo);
  7197. return this;
  7198. } // slow case. multiple pipe destinations.
  7199. if (!dest) {
  7200. // remove all.
  7201. var dests = state.pipes;
  7202. var len = state.pipesCount;
  7203. state.pipes = null;
  7204. state.pipesCount = 0;
  7205. state.flowing = false;
  7206. for (var i = 0; i < len; i++) {
  7207. dests[i].emit('unpipe', this, {
  7208. hasUnpiped: false
  7209. });
  7210. }
  7211. return this;
  7212. } // try to find the right one.
  7213. var index = indexOf(state.pipes, dest);
  7214. if (index === -1) return this;
  7215. state.pipes.splice(index, 1);
  7216. state.pipesCount -= 1;
  7217. if (state.pipesCount === 1) state.pipes = state.pipes[0];
  7218. dest.emit('unpipe', this, unpipeInfo);
  7219. return this;
  7220. }; // set up data events if they are asked for
  7221. // Ensure readable listeners eventually get something
  7222. Readable.prototype.on = function (ev, fn) {
  7223. var res = Stream.prototype.on.call(this, ev, fn);
  7224. var state = this._readableState;
  7225. if (ev === 'data') {
  7226. // update readableListening so that resume() may be a no-op
  7227. // a few lines down. This is needed to support once('readable').
  7228. state.readableListening = this.listenerCount('readable') > 0; // Try start flowing on next tick if stream isn't explicitly paused
  7229. if (state.flowing !== false) this.resume();
  7230. } else if (ev === 'readable') {
  7231. if (!state.endEmitted && !state.readableListening) {
  7232. state.readableListening = state.needReadable = true;
  7233. state.flowing = false;
  7234. state.emittedReadable = false;
  7235. debug('on readable', state.length, state.reading);
  7236. if (state.length) {
  7237. emitReadable(this);
  7238. } else if (!state.reading) {
  7239. process.nextTick(nReadingNextTick, this);
  7240. }
  7241. }
  7242. }
  7243. return res;
  7244. };
  7245. Readable.prototype.addListener = Readable.prototype.on;
  7246. Readable.prototype.removeListener = function (ev, fn) {
  7247. var res = Stream.prototype.removeListener.call(this, ev, fn);
  7248. if (ev === 'readable') {
  7249. // We need to check if there is someone still listening to
  7250. // readable and reset the state. However this needs to happen
  7251. // after readable has been emitted but before I/O (nextTick) to
  7252. // support once('readable', fn) cycles. This means that calling
  7253. // resume within the same tick will have no
  7254. // effect.
  7255. process.nextTick(updateReadableListening, this);
  7256. }
  7257. return res;
  7258. };
  7259. Readable.prototype.removeAllListeners = function (ev) {
  7260. var res = Stream.prototype.removeAllListeners.apply(this, arguments);
  7261. if (ev === 'readable' || ev === undefined) {
  7262. // We need to check if there is someone still listening to
  7263. // readable and reset the state. However this needs to happen
  7264. // after readable has been emitted but before I/O (nextTick) to
  7265. // support once('readable', fn) cycles. This means that calling
  7266. // resume within the same tick will have no
  7267. // effect.
  7268. process.nextTick(updateReadableListening, this);
  7269. }
  7270. return res;
  7271. };
  7272. function updateReadableListening(self) {
  7273. var state = self._readableState;
  7274. state.readableListening = self.listenerCount('readable') > 0;
  7275. if (state.resumeScheduled && !state.paused) {
  7276. // flowing needs to be set to true now, otherwise
  7277. // the upcoming resume will not flow.
  7278. state.flowing = true; // crude way to check if we should resume
  7279. } else if (self.listenerCount('data') > 0) {
  7280. self.resume();
  7281. }
  7282. }
  7283. function nReadingNextTick(self) {
  7284. debug('readable nexttick read 0');
  7285. self.read(0);
  7286. } // pause() and resume() are remnants of the legacy readable stream API
  7287. // If the user uses them, then switch into old mode.
  7288. Readable.prototype.resume = function () {
  7289. var state = this._readableState;
  7290. if (!state.flowing) {
  7291. debug('resume'); // we flow only if there is no one listening
  7292. // for readable, but we still have to call
  7293. // resume()
  7294. state.flowing = !state.readableListening;
  7295. resume(this, state);
  7296. }
  7297. state.paused = false;
  7298. return this;
  7299. };
  7300. function resume(stream, state) {
  7301. if (!state.resumeScheduled) {
  7302. state.resumeScheduled = true;
  7303. process.nextTick(resume_, stream, state);
  7304. }
  7305. }
  7306. function resume_(stream, state) {
  7307. debug('resume', state.reading);
  7308. if (!state.reading) {
  7309. stream.read(0);
  7310. }
  7311. state.resumeScheduled = false;
  7312. stream.emit('resume');
  7313. flow(stream);
  7314. if (state.flowing && !state.reading) stream.read(0);
  7315. }
  7316. Readable.prototype.pause = function () {
  7317. debug('call pause flowing=%j', this._readableState.flowing);
  7318. if (this._readableState.flowing !== false) {
  7319. debug('pause');
  7320. this._readableState.flowing = false;
  7321. this.emit('pause');
  7322. }
  7323. this._readableState.paused = true;
  7324. return this;
  7325. };
  7326. function flow(stream) {
  7327. var state = stream._readableState;
  7328. debug('flow', state.flowing);
  7329. while (state.flowing && stream.read() !== null) {
  7330. ;
  7331. }
  7332. } // wrap an old-style stream as the async data source.
  7333. // This is *not* part of the readable stream interface.
  7334. // It is an ugly unfortunate mess of history.
  7335. Readable.prototype.wrap = function (stream) {
  7336. var _this = this;
  7337. var state = this._readableState;
  7338. var paused = false;
  7339. stream.on('end', function () {
  7340. debug('wrapped end');
  7341. if (state.decoder && !state.ended) {
  7342. var chunk = state.decoder.end();
  7343. if (chunk && chunk.length) _this.push(chunk);
  7344. }
  7345. _this.push(null);
  7346. });
  7347. stream.on('data', function (chunk) {
  7348. debug('wrapped data');
  7349. if (state.decoder) chunk = state.decoder.write(chunk); // don't skip over falsy values in objectMode
  7350. if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return;
  7351. var ret = _this.push(chunk);
  7352. if (!ret) {
  7353. paused = true;
  7354. stream.pause();
  7355. }
  7356. }); // proxy all the other methods.
  7357. // important when wrapping filters and duplexes.
  7358. for (var i in stream) {
  7359. if (this[i] === undefined && typeof stream[i] === 'function') {
  7360. this[i] = function methodWrap(method) {
  7361. return function methodWrapReturnFunction() {
  7362. return stream[method].apply(stream, arguments);
  7363. };
  7364. }(i);
  7365. }
  7366. } // proxy certain important events.
  7367. for (var n = 0; n < kProxyEvents.length; n++) {
  7368. stream.on(kProxyEvents[n], this.emit.bind(this, kProxyEvents[n]));
  7369. } // when we try to consume some more bytes, simply unpause the
  7370. // underlying stream.
  7371. this._read = function (n) {
  7372. debug('wrapped _read', n);
  7373. if (paused) {
  7374. paused = false;
  7375. stream.resume();
  7376. }
  7377. };
  7378. return this;
  7379. };
  7380. if (typeof Symbol === 'function') {
  7381. Readable.prototype[Symbol.asyncIterator] = function () {
  7382. if (createReadableStreamAsyncIterator === undefined) {
  7383. createReadableStreamAsyncIterator = require('./internal/streams/async_iterator');
  7384. }
  7385. return createReadableStreamAsyncIterator(this);
  7386. };
  7387. }
  7388. Object.defineProperty(Readable.prototype, 'readableHighWaterMark', {
  7389. // making it explicit this property is not enumerable
  7390. // because otherwise some prototype manipulation in
  7391. // userland will fail
  7392. enumerable: false,
  7393. get: function get() {
  7394. return this._readableState.highWaterMark;
  7395. }
  7396. });
  7397. Object.defineProperty(Readable.prototype, 'readableBuffer', {
  7398. // making it explicit this property is not enumerable
  7399. // because otherwise some prototype manipulation in
  7400. // userland will fail
  7401. enumerable: false,
  7402. get: function get() {
  7403. return this._readableState && this._readableState.buffer;
  7404. }
  7405. });
  7406. Object.defineProperty(Readable.prototype, 'readableFlowing', {
  7407. // making it explicit this property is not enumerable
  7408. // because otherwise some prototype manipulation in
  7409. // userland will fail
  7410. enumerable: false,
  7411. get: function get() {
  7412. return this._readableState.flowing;
  7413. },
  7414. set: function set(state) {
  7415. if (this._readableState) {
  7416. this._readableState.flowing = state;
  7417. }
  7418. }
  7419. }); // exposed for testing purposes only.
  7420. Readable._fromList = fromList;
  7421. Object.defineProperty(Readable.prototype, 'readableLength', {
  7422. // making it explicit this property is not enumerable
  7423. // because otherwise some prototype manipulation in
  7424. // userland will fail
  7425. enumerable: false,
  7426. get: function get() {
  7427. return this._readableState.length;
  7428. }
  7429. }); // Pluck off n bytes from an array of buffers.
  7430. // Length is the combined lengths of all the buffers in the list.
  7431. // This function is designed to be inlinable, so please take care when making
  7432. // changes to the function body.
  7433. function fromList(n, state) {
  7434. // nothing buffered
  7435. if (state.length === 0) return null;
  7436. var ret;
  7437. if (state.objectMode) ret = state.buffer.shift();else if (!n || n >= state.length) {
  7438. // read it all, truncate the list
  7439. if (state.decoder) ret = state.buffer.join('');else if (state.buffer.length === 1) ret = state.buffer.first();else ret = state.buffer.concat(state.length);
  7440. state.buffer.clear();
  7441. } else {
  7442. // read part of list
  7443. ret = state.buffer.consume(n, state.decoder);
  7444. }
  7445. return ret;
  7446. }
  7447. function endReadable(stream) {
  7448. var state = stream._readableState;
  7449. debug('endReadable', state.endEmitted);
  7450. if (!state.endEmitted) {
  7451. state.ended = true;
  7452. process.nextTick(endReadableNT, state, stream);
  7453. }
  7454. }
  7455. function endReadableNT(state, stream) {
  7456. debug('endReadableNT', state.endEmitted, state.length); // Check that we didn't get one last unshift.
  7457. if (!state.endEmitted && state.length === 0) {
  7458. state.endEmitted = true;
  7459. stream.readable = false;
  7460. stream.emit('end');
  7461. if (state.autoDestroy) {
  7462. // In case of duplex streams we need a way to detect
  7463. // if the writable side is ready for autoDestroy as well
  7464. var wState = stream._writableState;
  7465. if (!wState || wState.autoDestroy && wState.finished) {
  7466. stream.destroy();
  7467. }
  7468. }
  7469. }
  7470. }
  7471. if (typeof Symbol === 'function') {
  7472. Readable.from = function (iterable, opts) {
  7473. if (from === undefined) {
  7474. from = require('./internal/streams/from');
  7475. }
  7476. return from(Readable, iterable, opts);
  7477. };
  7478. }
  7479. function indexOf(xs, x) {
  7480. for (var i = 0, l = xs.length; i < l; i++) {
  7481. if (xs[i] === x) return i;
  7482. }
  7483. return -1;
  7484. }
  7485. }).call(this)}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  7486. },{"../errors":21,"./_stream_duplex":22,"./internal/streams/async_iterator":27,"./internal/streams/buffer_list":28,"./internal/streams/destroy":29,"./internal/streams/from":31,"./internal/streams/state":33,"./internal/streams/stream":34,"_process":11,"buffer":3,"events":5,"inherits":8,"string_decoder/":36,"util":2}],25:[function(require,module,exports){
  7487. // Copyright Joyent, Inc. and other Node contributors.
  7488. //
  7489. // Permission is hereby granted, free of charge, to any person obtaining a
  7490. // copy of this software and associated documentation files (the
  7491. // "Software"), to deal in the Software without restriction, including
  7492. // without limitation the rights to use, copy, modify, merge, publish,
  7493. // distribute, sublicense, and/or sell copies of the Software, and to permit
  7494. // persons to whom the Software is furnished to do so, subject to the
  7495. // following conditions:
  7496. //
  7497. // The above copyright notice and this permission notice shall be included
  7498. // in all copies or substantial portions of the Software.
  7499. //
  7500. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  7501. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  7502. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  7503. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  7504. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  7505. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  7506. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  7507. // a transform stream is a readable/writable stream where you do
  7508. // something with the data. Sometimes it's called a "filter",
  7509. // but that's not a great name for it, since that implies a thing where
  7510. // some bits pass through, and others are simply ignored. (That would
  7511. // be a valid example of a transform, of course.)
  7512. //
  7513. // While the output is causally related to the input, it's not a
  7514. // necessarily symmetric or synchronous transformation. For example,
  7515. // a zlib stream might take multiple plain-text writes(), and then
  7516. // emit a single compressed chunk some time in the future.
  7517. //
  7518. // Here's how this works:
  7519. //
  7520. // The Transform stream has all the aspects of the readable and writable
  7521. // stream classes. When you write(chunk), that calls _write(chunk,cb)
  7522. // internally, and returns false if there's a lot of pending writes
  7523. // buffered up. When you call read(), that calls _read(n) until
  7524. // there's enough pending readable data buffered up.
  7525. //
  7526. // In a transform stream, the written data is placed in a buffer. When
  7527. // _read(n) is called, it transforms the queued up data, calling the
  7528. // buffered _write cb's as it consumes chunks. If consuming a single
  7529. // written chunk would result in multiple output chunks, then the first
  7530. // outputted bit calls the readcb, and subsequent chunks just go into
  7531. // the read buffer, and will cause it to emit 'readable' if necessary.
  7532. //
  7533. // This way, back-pressure is actually determined by the reading side,
  7534. // since _read has to be called to start processing a new chunk. However,
  7535. // a pathological inflate type of transform can cause excessive buffering
  7536. // here. For example, imagine a stream where every byte of input is
  7537. // interpreted as an integer from 0-255, and then results in that many
  7538. // bytes of output. Writing the 4 bytes {ff,ff,ff,ff} would result in
  7539. // 1kb of data being output. In this case, you could write a very small
  7540. // amount of input, and end up with a very large amount of output. In
  7541. // such a pathological inflating mechanism, there'd be no way to tell
  7542. // the system to stop doing the transform. A single 4MB write could
  7543. // cause the system to run out of memory.
  7544. //
  7545. // However, even in such a pathological case, only a single written chunk
  7546. // would be consumed, and then the rest would wait (un-transformed) until
  7547. // the results of the previous transformed chunk were consumed.
  7548. 'use strict';
  7549. module.exports = Transform;
  7550. var _require$codes = require('../errors').codes,
  7551. ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED,
  7552. ERR_MULTIPLE_CALLBACK = _require$codes.ERR_MULTIPLE_CALLBACK,
  7553. ERR_TRANSFORM_ALREADY_TRANSFORMING = _require$codes.ERR_TRANSFORM_ALREADY_TRANSFORMING,
  7554. ERR_TRANSFORM_WITH_LENGTH_0 = _require$codes.ERR_TRANSFORM_WITH_LENGTH_0;
  7555. var Duplex = require('./_stream_duplex');
  7556. require('inherits')(Transform, Duplex);
  7557. function afterTransform(er, data) {
  7558. var ts = this._transformState;
  7559. ts.transforming = false;
  7560. var cb = ts.writecb;
  7561. if (cb === null) {
  7562. return this.emit('error', new ERR_MULTIPLE_CALLBACK());
  7563. }
  7564. ts.writechunk = null;
  7565. ts.writecb = null;
  7566. if (data != null) // single equals check for both `null` and `undefined`
  7567. this.push(data);
  7568. cb(er);
  7569. var rs = this._readableState;
  7570. rs.reading = false;
  7571. if (rs.needReadable || rs.length < rs.highWaterMark) {
  7572. this._read(rs.highWaterMark);
  7573. }
  7574. }
  7575. function Transform(options) {
  7576. if (!(this instanceof Transform)) return new Transform(options);
  7577. Duplex.call(this, options);
  7578. this._transformState = {
  7579. afterTransform: afterTransform.bind(this),
  7580. needTransform: false,
  7581. transforming: false,
  7582. writecb: null,
  7583. writechunk: null,
  7584. writeencoding: null
  7585. }; // start out asking for a readable event once data is transformed.
  7586. this._readableState.needReadable = true; // we have implemented the _read method, and done the other things
  7587. // that Readable wants before the first _read call, so unset the
  7588. // sync guard flag.
  7589. this._readableState.sync = false;
  7590. if (options) {
  7591. if (typeof options.transform === 'function') this._transform = options.transform;
  7592. if (typeof options.flush === 'function') this._flush = options.flush;
  7593. } // When the writable side finishes, then flush out anything remaining.
  7594. this.on('prefinish', prefinish);
  7595. }
  7596. function prefinish() {
  7597. var _this = this;
  7598. if (typeof this._flush === 'function' && !this._readableState.destroyed) {
  7599. this._flush(function (er, data) {
  7600. done(_this, er, data);
  7601. });
  7602. } else {
  7603. done(this, null, null);
  7604. }
  7605. }
  7606. Transform.prototype.push = function (chunk, encoding) {
  7607. this._transformState.needTransform = false;
  7608. return Duplex.prototype.push.call(this, chunk, encoding);
  7609. }; // This is the part where you do stuff!
  7610. // override this function in implementation classes.
  7611. // 'chunk' is an input chunk.
  7612. //
  7613. // Call `push(newChunk)` to pass along transformed output
  7614. // to the readable side. You may call 'push' zero or more times.
  7615. //
  7616. // Call `cb(err)` when you are done with this chunk. If you pass
  7617. // an error, then that'll put the hurt on the whole operation. If you
  7618. // never call cb(), then you'll never get another chunk.
  7619. Transform.prototype._transform = function (chunk, encoding, cb) {
  7620. cb(new ERR_METHOD_NOT_IMPLEMENTED('_transform()'));
  7621. };
  7622. Transform.prototype._write = function (chunk, encoding, cb) {
  7623. var ts = this._transformState;
  7624. ts.writecb = cb;
  7625. ts.writechunk = chunk;
  7626. ts.writeencoding = encoding;
  7627. if (!ts.transforming) {
  7628. var rs = this._readableState;
  7629. if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) this._read(rs.highWaterMark);
  7630. }
  7631. }; // Doesn't matter what the args are here.
  7632. // _transform does all the work.
  7633. // That we got here means that the readable side wants more data.
  7634. Transform.prototype._read = function (n) {
  7635. var ts = this._transformState;
  7636. if (ts.writechunk !== null && !ts.transforming) {
  7637. ts.transforming = true;
  7638. this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
  7639. } else {
  7640. // mark that we need a transform, so that any data that comes in
  7641. // will get processed, now that we've asked for it.
  7642. ts.needTransform = true;
  7643. }
  7644. };
  7645. Transform.prototype._destroy = function (err, cb) {
  7646. Duplex.prototype._destroy.call(this, err, function (err2) {
  7647. cb(err2);
  7648. });
  7649. };
  7650. function done(stream, er, data) {
  7651. if (er) return stream.emit('error', er);
  7652. if (data != null) // single equals check for both `null` and `undefined`
  7653. stream.push(data); // TODO(BridgeAR): Write a test for these two error cases
  7654. // if there's nothing in the write buffer, then that means
  7655. // that nothing more will ever be provided
  7656. if (stream._writableState.length) throw new ERR_TRANSFORM_WITH_LENGTH_0();
  7657. if (stream._transformState.transforming) throw new ERR_TRANSFORM_ALREADY_TRANSFORMING();
  7658. return stream.push(null);
  7659. }
  7660. },{"../errors":21,"./_stream_duplex":22,"inherits":8}],26:[function(require,module,exports){
  7661. (function (process,global){(function (){
  7662. // Copyright Joyent, Inc. and other Node contributors.
  7663. //
  7664. // Permission is hereby granted, free of charge, to any person obtaining a
  7665. // copy of this software and associated documentation files (the
  7666. // "Software"), to deal in the Software without restriction, including
  7667. // without limitation the rights to use, copy, modify, merge, publish,
  7668. // distribute, sublicense, and/or sell copies of the Software, and to permit
  7669. // persons to whom the Software is furnished to do so, subject to the
  7670. // following conditions:
  7671. //
  7672. // The above copyright notice and this permission notice shall be included
  7673. // in all copies or substantial portions of the Software.
  7674. //
  7675. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  7676. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  7677. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  7678. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  7679. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  7680. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  7681. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  7682. // A bit simpler than readable streams.
  7683. // Implement an async ._write(chunk, encoding, cb), and it'll handle all
  7684. // the drain event emission and buffering.
  7685. 'use strict';
  7686. module.exports = Writable;
  7687. /* <replacement> */
  7688. function WriteReq(chunk, encoding, cb) {
  7689. this.chunk = chunk;
  7690. this.encoding = encoding;
  7691. this.callback = cb;
  7692. this.next = null;
  7693. } // It seems a linked list but it is not
  7694. // there will be only 2 of these for each stream
  7695. function CorkedRequest(state) {
  7696. var _this = this;
  7697. this.next = null;
  7698. this.entry = null;
  7699. this.finish = function () {
  7700. onCorkedFinish(_this, state);
  7701. };
  7702. }
  7703. /* </replacement> */
  7704. /*<replacement>*/
  7705. var Duplex;
  7706. /*</replacement>*/
  7707. Writable.WritableState = WritableState;
  7708. /*<replacement>*/
  7709. var internalUtil = {
  7710. deprecate: require('util-deprecate')
  7711. };
  7712. /*</replacement>*/
  7713. /*<replacement>*/
  7714. var Stream = require('./internal/streams/stream');
  7715. /*</replacement>*/
  7716. var Buffer = require('buffer').Buffer;
  7717. var OurUint8Array = global.Uint8Array || function () {};
  7718. function _uint8ArrayToBuffer(chunk) {
  7719. return Buffer.from(chunk);
  7720. }
  7721. function _isUint8Array(obj) {
  7722. return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
  7723. }
  7724. var destroyImpl = require('./internal/streams/destroy');
  7725. var _require = require('./internal/streams/state'),
  7726. getHighWaterMark = _require.getHighWaterMark;
  7727. var _require$codes = require('../errors').codes,
  7728. ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE,
  7729. ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED,
  7730. ERR_MULTIPLE_CALLBACK = _require$codes.ERR_MULTIPLE_CALLBACK,
  7731. ERR_STREAM_CANNOT_PIPE = _require$codes.ERR_STREAM_CANNOT_PIPE,
  7732. ERR_STREAM_DESTROYED = _require$codes.ERR_STREAM_DESTROYED,
  7733. ERR_STREAM_NULL_VALUES = _require$codes.ERR_STREAM_NULL_VALUES,
  7734. ERR_STREAM_WRITE_AFTER_END = _require$codes.ERR_STREAM_WRITE_AFTER_END,
  7735. ERR_UNKNOWN_ENCODING = _require$codes.ERR_UNKNOWN_ENCODING;
  7736. var errorOrDestroy = destroyImpl.errorOrDestroy;
  7737. require('inherits')(Writable, Stream);
  7738. function nop() {}
  7739. function WritableState(options, stream, isDuplex) {
  7740. Duplex = Duplex || require('./_stream_duplex');
  7741. options = options || {}; // Duplex streams are both readable and writable, but share
  7742. // the same options object.
  7743. // However, some cases require setting options to different
  7744. // values for the readable and the writable sides of the duplex stream,
  7745. // e.g. options.readableObjectMode vs. options.writableObjectMode, etc.
  7746. if (typeof isDuplex !== 'boolean') isDuplex = stream instanceof Duplex; // object stream flag to indicate whether or not this stream
  7747. // contains buffers or objects.
  7748. this.objectMode = !!options.objectMode;
  7749. if (isDuplex) this.objectMode = this.objectMode || !!options.writableObjectMode; // the point at which write() starts returning false
  7750. // Note: 0 is a valid value, means that we always return false if
  7751. // the entire buffer is not flushed immediately on write()
  7752. this.highWaterMark = getHighWaterMark(this, options, 'writableHighWaterMark', isDuplex); // if _final has been called
  7753. this.finalCalled = false; // drain event flag.
  7754. this.needDrain = false; // at the start of calling end()
  7755. this.ending = false; // when end() has been called, and returned
  7756. this.ended = false; // when 'finish' is emitted
  7757. this.finished = false; // has it been destroyed
  7758. this.destroyed = false; // should we decode strings into buffers before passing to _write?
  7759. // this is here so that some node-core streams can optimize string
  7760. // handling at a lower level.
  7761. var noDecode = options.decodeStrings === false;
  7762. this.decodeStrings = !noDecode; // Crypto is kind of old and crusty. Historically, its default string
  7763. // encoding is 'binary' so we have to make this configurable.
  7764. // Everything else in the universe uses 'utf8', though.
  7765. this.defaultEncoding = options.defaultEncoding || 'utf8'; // not an actual buffer we keep track of, but a measurement
  7766. // of how much we're waiting to get pushed to some underlying
  7767. // socket or file.
  7768. this.length = 0; // a flag to see when we're in the middle of a write.
  7769. this.writing = false; // when true all writes will be buffered until .uncork() call
  7770. this.corked = 0; // a flag to be able to tell if the onwrite cb is called immediately,
  7771. // or on a later tick. We set this to true at first, because any
  7772. // actions that shouldn't happen until "later" should generally also
  7773. // not happen before the first write call.
  7774. this.sync = true; // a flag to know if we're processing previously buffered items, which
  7775. // may call the _write() callback in the same tick, so that we don't
  7776. // end up in an overlapped onwrite situation.
  7777. this.bufferProcessing = false; // the callback that's passed to _write(chunk,cb)
  7778. this.onwrite = function (er) {
  7779. onwrite(stream, er);
  7780. }; // the callback that the user supplies to write(chunk,encoding,cb)
  7781. this.writecb = null; // the amount that is being written when _write is called.
  7782. this.writelen = 0;
  7783. this.bufferedRequest = null;
  7784. this.lastBufferedRequest = null; // number of pending user-supplied write callbacks
  7785. // this must be 0 before 'finish' can be emitted
  7786. this.pendingcb = 0; // emit prefinish if the only thing we're waiting for is _write cbs
  7787. // This is relevant for synchronous Transform streams
  7788. this.prefinished = false; // True if the error was already emitted and should not be thrown again
  7789. this.errorEmitted = false; // Should close be emitted on destroy. Defaults to true.
  7790. this.emitClose = options.emitClose !== false; // Should .destroy() be called after 'finish' (and potentially 'end')
  7791. this.autoDestroy = !!options.autoDestroy; // count buffered requests
  7792. this.bufferedRequestCount = 0; // allocate the first CorkedRequest, there is always
  7793. // one allocated and free to use, and we maintain at most two
  7794. this.corkedRequestsFree = new CorkedRequest(this);
  7795. }
  7796. WritableState.prototype.getBuffer = function getBuffer() {
  7797. var current = this.bufferedRequest;
  7798. var out = [];
  7799. while (current) {
  7800. out.push(current);
  7801. current = current.next;
  7802. }
  7803. return out;
  7804. };
  7805. (function () {
  7806. try {
  7807. Object.defineProperty(WritableState.prototype, 'buffer', {
  7808. get: internalUtil.deprecate(function writableStateBufferGetter() {
  7809. return this.getBuffer();
  7810. }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.', 'DEP0003')
  7811. });
  7812. } catch (_) {}
  7813. })(); // Test _writableState for inheritance to account for Duplex streams,
  7814. // whose prototype chain only points to Readable.
  7815. var realHasInstance;
  7816. if (typeof Symbol === 'function' && Symbol.hasInstance && typeof Function.prototype[Symbol.hasInstance] === 'function') {
  7817. realHasInstance = Function.prototype[Symbol.hasInstance];
  7818. Object.defineProperty(Writable, Symbol.hasInstance, {
  7819. value: function value(object) {
  7820. if (realHasInstance.call(this, object)) return true;
  7821. if (this !== Writable) return false;
  7822. return object && object._writableState instanceof WritableState;
  7823. }
  7824. });
  7825. } else {
  7826. realHasInstance = function realHasInstance(object) {
  7827. return object instanceof this;
  7828. };
  7829. }
  7830. function Writable(options) {
  7831. Duplex = Duplex || require('./_stream_duplex'); // Writable ctor is applied to Duplexes, too.
  7832. // `realHasInstance` is necessary because using plain `instanceof`
  7833. // would return false, as no `_writableState` property is attached.
  7834. // Trying to use the custom `instanceof` for Writable here will also break the
  7835. // Node.js LazyTransform implementation, which has a non-trivial getter for
  7836. // `_writableState` that would lead to infinite recursion.
  7837. // Checking for a Stream.Duplex instance is faster here instead of inside
  7838. // the WritableState constructor, at least with V8 6.5
  7839. var isDuplex = this instanceof Duplex;
  7840. if (!isDuplex && !realHasInstance.call(Writable, this)) return new Writable(options);
  7841. this._writableState = new WritableState(options, this, isDuplex); // legacy.
  7842. this.writable = true;
  7843. if (options) {
  7844. if (typeof options.write === 'function') this._write = options.write;
  7845. if (typeof options.writev === 'function') this._writev = options.writev;
  7846. if (typeof options.destroy === 'function') this._destroy = options.destroy;
  7847. if (typeof options.final === 'function') this._final = options.final;
  7848. }
  7849. Stream.call(this);
  7850. } // Otherwise people can pipe Writable streams, which is just wrong.
  7851. Writable.prototype.pipe = function () {
  7852. errorOrDestroy(this, new ERR_STREAM_CANNOT_PIPE());
  7853. };
  7854. function writeAfterEnd(stream, cb) {
  7855. var er = new ERR_STREAM_WRITE_AFTER_END(); // TODO: defer error events consistently everywhere, not just the cb
  7856. errorOrDestroy(stream, er);
  7857. process.nextTick(cb, er);
  7858. } // Checks that a user-supplied chunk is valid, especially for the particular
  7859. // mode the stream is in. Currently this means that `null` is never accepted
  7860. // and undefined/non-string values are only allowed in object mode.
  7861. function validChunk(stream, state, chunk, cb) {
  7862. var er;
  7863. if (chunk === null) {
  7864. er = new ERR_STREAM_NULL_VALUES();
  7865. } else if (typeof chunk !== 'string' && !state.objectMode) {
  7866. er = new ERR_INVALID_ARG_TYPE('chunk', ['string', 'Buffer'], chunk);
  7867. }
  7868. if (er) {
  7869. errorOrDestroy(stream, er);
  7870. process.nextTick(cb, er);
  7871. return false;
  7872. }
  7873. return true;
  7874. }
  7875. Writable.prototype.write = function (chunk, encoding, cb) {
  7876. var state = this._writableState;
  7877. var ret = false;
  7878. var isBuf = !state.objectMode && _isUint8Array(chunk);
  7879. if (isBuf && !Buffer.isBuffer(chunk)) {
  7880. chunk = _uint8ArrayToBuffer(chunk);
  7881. }
  7882. if (typeof encoding === 'function') {
  7883. cb = encoding;
  7884. encoding = null;
  7885. }
  7886. if (isBuf) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding;
  7887. if (typeof cb !== 'function') cb = nop;
  7888. if (state.ending) writeAfterEnd(this, cb);else if (isBuf || validChunk(this, state, chunk, cb)) {
  7889. state.pendingcb++;
  7890. ret = writeOrBuffer(this, state, isBuf, chunk, encoding, cb);
  7891. }
  7892. return ret;
  7893. };
  7894. Writable.prototype.cork = function () {
  7895. this._writableState.corked++;
  7896. };
  7897. Writable.prototype.uncork = function () {
  7898. var state = this._writableState;
  7899. if (state.corked) {
  7900. state.corked--;
  7901. if (!state.writing && !state.corked && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state);
  7902. }
  7903. };
  7904. Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
  7905. // node::ParseEncoding() requires lower case.
  7906. if (typeof encoding === 'string') encoding = encoding.toLowerCase();
  7907. if (!(['hex', 'utf8', 'utf-8', 'ascii', 'binary', 'base64', 'ucs2', 'ucs-2', 'utf16le', 'utf-16le', 'raw'].indexOf((encoding + '').toLowerCase()) > -1)) throw new ERR_UNKNOWN_ENCODING(encoding);
  7908. this._writableState.defaultEncoding = encoding;
  7909. return this;
  7910. };
  7911. Object.defineProperty(Writable.prototype, 'writableBuffer', {
  7912. // making it explicit this property is not enumerable
  7913. // because otherwise some prototype manipulation in
  7914. // userland will fail
  7915. enumerable: false,
  7916. get: function get() {
  7917. return this._writableState && this._writableState.getBuffer();
  7918. }
  7919. });
  7920. function decodeChunk(state, chunk, encoding) {
  7921. if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') {
  7922. chunk = Buffer.from(chunk, encoding);
  7923. }
  7924. return chunk;
  7925. }
  7926. Object.defineProperty(Writable.prototype, 'writableHighWaterMark', {
  7927. // making it explicit this property is not enumerable
  7928. // because otherwise some prototype manipulation in
  7929. // userland will fail
  7930. enumerable: false,
  7931. get: function get() {
  7932. return this._writableState.highWaterMark;
  7933. }
  7934. }); // if we're already writing something, then just put this
  7935. // in the queue, and wait our turn. Otherwise, call _write
  7936. // If we return false, then we need a drain event, so set that flag.
  7937. function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) {
  7938. if (!isBuf) {
  7939. var newChunk = decodeChunk(state, chunk, encoding);
  7940. if (chunk !== newChunk) {
  7941. isBuf = true;
  7942. encoding = 'buffer';
  7943. chunk = newChunk;
  7944. }
  7945. }
  7946. var len = state.objectMode ? 1 : chunk.length;
  7947. state.length += len;
  7948. var ret = state.length < state.highWaterMark; // we must ensure that previous needDrain will not be reset to false.
  7949. if (!ret) state.needDrain = true;
  7950. if (state.writing || state.corked) {
  7951. var last = state.lastBufferedRequest;
  7952. state.lastBufferedRequest = {
  7953. chunk: chunk,
  7954. encoding: encoding,
  7955. isBuf: isBuf,
  7956. callback: cb,
  7957. next: null
  7958. };
  7959. if (last) {
  7960. last.next = state.lastBufferedRequest;
  7961. } else {
  7962. state.bufferedRequest = state.lastBufferedRequest;
  7963. }
  7964. state.bufferedRequestCount += 1;
  7965. } else {
  7966. doWrite(stream, state, false, len, chunk, encoding, cb);
  7967. }
  7968. return ret;
  7969. }
  7970. function doWrite(stream, state, writev, len, chunk, encoding, cb) {
  7971. state.writelen = len;
  7972. state.writecb = cb;
  7973. state.writing = true;
  7974. state.sync = true;
  7975. if (state.destroyed) state.onwrite(new ERR_STREAM_DESTROYED('write'));else if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite);
  7976. state.sync = false;
  7977. }
  7978. function onwriteError(stream, state, sync, er, cb) {
  7979. --state.pendingcb;
  7980. if (sync) {
  7981. // defer the callback if we are being called synchronously
  7982. // to avoid piling up things on the stack
  7983. process.nextTick(cb, er); // this can emit finish, and it will always happen
  7984. // after error
  7985. process.nextTick(finishMaybe, stream, state);
  7986. stream._writableState.errorEmitted = true;
  7987. errorOrDestroy(stream, er);
  7988. } else {
  7989. // the caller expect this to happen before if
  7990. // it is async
  7991. cb(er);
  7992. stream._writableState.errorEmitted = true;
  7993. errorOrDestroy(stream, er); // this can emit finish, but finish must
  7994. // always follow error
  7995. finishMaybe(stream, state);
  7996. }
  7997. }
  7998. function onwriteStateUpdate(state) {
  7999. state.writing = false;
  8000. state.writecb = null;
  8001. state.length -= state.writelen;
  8002. state.writelen = 0;
  8003. }
  8004. function onwrite(stream, er) {
  8005. var state = stream._writableState;
  8006. var sync = state.sync;
  8007. var cb = state.writecb;
  8008. if (typeof cb !== 'function') throw new ERR_MULTIPLE_CALLBACK();
  8009. onwriteStateUpdate(state);
  8010. if (er) onwriteError(stream, state, sync, er, cb);else {
  8011. // Check if we're actually ready to finish, but don't emit yet
  8012. var finished = needFinish(state) || stream.destroyed;
  8013. if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) {
  8014. clearBuffer(stream, state);
  8015. }
  8016. if (sync) {
  8017. process.nextTick(afterWrite, stream, state, finished, cb);
  8018. } else {
  8019. afterWrite(stream, state, finished, cb);
  8020. }
  8021. }
  8022. }
  8023. function afterWrite(stream, state, finished, cb) {
  8024. if (!finished) onwriteDrain(stream, state);
  8025. state.pendingcb--;
  8026. cb();
  8027. finishMaybe(stream, state);
  8028. } // Must force callback to be called on nextTick, so that we don't
  8029. // emit 'drain' before the write() consumer gets the 'false' return
  8030. // value, and has a chance to attach a 'drain' listener.
  8031. function onwriteDrain(stream, state) {
  8032. if (state.length === 0 && state.needDrain) {
  8033. state.needDrain = false;
  8034. stream.emit('drain');
  8035. }
  8036. } // if there's something in the buffer waiting, then process it
  8037. function clearBuffer(stream, state) {
  8038. state.bufferProcessing = true;
  8039. var entry = state.bufferedRequest;
  8040. if (stream._writev && entry && entry.next) {
  8041. // Fast case, write everything using _writev()
  8042. var l = state.bufferedRequestCount;
  8043. var buffer = new Array(l);
  8044. var holder = state.corkedRequestsFree;
  8045. holder.entry = entry;
  8046. var count = 0;
  8047. var allBuffers = true;
  8048. while (entry) {
  8049. buffer[count] = entry;
  8050. if (!entry.isBuf) allBuffers = false;
  8051. entry = entry.next;
  8052. count += 1;
  8053. }
  8054. buffer.allBuffers = allBuffers;
  8055. doWrite(stream, state, true, state.length, buffer, '', holder.finish); // doWrite is almost always async, defer these to save a bit of time
  8056. // as the hot path ends with doWrite
  8057. state.pendingcb++;
  8058. state.lastBufferedRequest = null;
  8059. if (holder.next) {
  8060. state.corkedRequestsFree = holder.next;
  8061. holder.next = null;
  8062. } else {
  8063. state.corkedRequestsFree = new CorkedRequest(state);
  8064. }
  8065. state.bufferedRequestCount = 0;
  8066. } else {
  8067. // Slow case, write chunks one-by-one
  8068. while (entry) {
  8069. var chunk = entry.chunk;
  8070. var encoding = entry.encoding;
  8071. var cb = entry.callback;
  8072. var len = state.objectMode ? 1 : chunk.length;
  8073. doWrite(stream, state, false, len, chunk, encoding, cb);
  8074. entry = entry.next;
  8075. state.bufferedRequestCount--; // if we didn't call the onwrite immediately, then
  8076. // it means that we need to wait until it does.
  8077. // also, that means that the chunk and cb are currently
  8078. // being processed, so move the buffer counter past them.
  8079. if (state.writing) {
  8080. break;
  8081. }
  8082. }
  8083. if (entry === null) state.lastBufferedRequest = null;
  8084. }
  8085. state.bufferedRequest = entry;
  8086. state.bufferProcessing = false;
  8087. }
  8088. Writable.prototype._write = function (chunk, encoding, cb) {
  8089. cb(new ERR_METHOD_NOT_IMPLEMENTED('_write()'));
  8090. };
  8091. Writable.prototype._writev = null;
  8092. Writable.prototype.end = function (chunk, encoding, cb) {
  8093. var state = this._writableState;
  8094. if (typeof chunk === 'function') {
  8095. cb = chunk;
  8096. chunk = null;
  8097. encoding = null;
  8098. } else if (typeof encoding === 'function') {
  8099. cb = encoding;
  8100. encoding = null;
  8101. }
  8102. if (chunk !== null && chunk !== undefined) this.write(chunk, encoding); // .end() fully uncorks
  8103. if (state.corked) {
  8104. state.corked = 1;
  8105. this.uncork();
  8106. } // ignore unnecessary end() calls.
  8107. if (!state.ending) endWritable(this, state, cb);
  8108. return this;
  8109. };
  8110. Object.defineProperty(Writable.prototype, 'writableLength', {
  8111. // making it explicit this property is not enumerable
  8112. // because otherwise some prototype manipulation in
  8113. // userland will fail
  8114. enumerable: false,
  8115. get: function get() {
  8116. return this._writableState.length;
  8117. }
  8118. });
  8119. function needFinish(state) {
  8120. return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing;
  8121. }
  8122. function callFinal(stream, state) {
  8123. stream._final(function (err) {
  8124. state.pendingcb--;
  8125. if (err) {
  8126. errorOrDestroy(stream, err);
  8127. }
  8128. state.prefinished = true;
  8129. stream.emit('prefinish');
  8130. finishMaybe(stream, state);
  8131. });
  8132. }
  8133. function prefinish(stream, state) {
  8134. if (!state.prefinished && !state.finalCalled) {
  8135. if (typeof stream._final === 'function' && !state.destroyed) {
  8136. state.pendingcb++;
  8137. state.finalCalled = true;
  8138. process.nextTick(callFinal, stream, state);
  8139. } else {
  8140. state.prefinished = true;
  8141. stream.emit('prefinish');
  8142. }
  8143. }
  8144. }
  8145. function finishMaybe(stream, state) {
  8146. var need = needFinish(state);
  8147. if (need) {
  8148. prefinish(stream, state);
  8149. if (state.pendingcb === 0) {
  8150. state.finished = true;
  8151. stream.emit('finish');
  8152. if (state.autoDestroy) {
  8153. // In case of duplex streams we need a way to detect
  8154. // if the readable side is ready for autoDestroy as well
  8155. var rState = stream._readableState;
  8156. if (!rState || rState.autoDestroy && rState.endEmitted) {
  8157. stream.destroy();
  8158. }
  8159. }
  8160. }
  8161. }
  8162. return need;
  8163. }
  8164. function endWritable(stream, state, cb) {
  8165. state.ending = true;
  8166. finishMaybe(stream, state);
  8167. if (cb) {
  8168. if (state.finished) process.nextTick(cb);else stream.once('finish', cb);
  8169. }
  8170. state.ended = true;
  8171. stream.writable = false;
  8172. }
  8173. function onCorkedFinish(corkReq, state, err) {
  8174. var entry = corkReq.entry;
  8175. corkReq.entry = null;
  8176. while (entry) {
  8177. var cb = entry.callback;
  8178. state.pendingcb--;
  8179. cb(err);
  8180. entry = entry.next;
  8181. } // reuse the free corkReq.
  8182. state.corkedRequestsFree.next = corkReq;
  8183. }
  8184. Object.defineProperty(Writable.prototype, 'destroyed', {
  8185. // making it explicit this property is not enumerable
  8186. // because otherwise some prototype manipulation in
  8187. // userland will fail
  8188. enumerable: false,
  8189. get: function get() {
  8190. if (this._writableState === undefined) {
  8191. return false;
  8192. }
  8193. return this._writableState.destroyed;
  8194. },
  8195. set: function set(value) {
  8196. // we ignore the value if the stream
  8197. // has not been initialized yet
  8198. if (!this._writableState) {
  8199. return;
  8200. } // backward compatibility, the user is explicitly
  8201. // managing destroyed
  8202. this._writableState.destroyed = value;
  8203. }
  8204. });
  8205. Writable.prototype.destroy = destroyImpl.destroy;
  8206. Writable.prototype._undestroy = destroyImpl.undestroy;
  8207. Writable.prototype._destroy = function (err, cb) {
  8208. cb(err);
  8209. };
  8210. }).call(this)}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  8211. },{"../errors":21,"./_stream_duplex":22,"./internal/streams/destroy":29,"./internal/streams/state":33,"./internal/streams/stream":34,"_process":11,"buffer":3,"inherits":8,"util-deprecate":39}],27:[function(require,module,exports){
  8212. (function (process){(function (){
  8213. 'use strict';
  8214. var _Object$setPrototypeO;
  8215. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  8216. var finished = require('./end-of-stream');
  8217. var kLastResolve = Symbol('lastResolve');
  8218. var kLastReject = Symbol('lastReject');
  8219. var kError = Symbol('error');
  8220. var kEnded = Symbol('ended');
  8221. var kLastPromise = Symbol('lastPromise');
  8222. var kHandlePromise = Symbol('handlePromise');
  8223. var kStream = Symbol('stream');
  8224. function createIterResult(value, done) {
  8225. return {
  8226. value: value,
  8227. done: done
  8228. };
  8229. }
  8230. function readAndResolve(iter) {
  8231. var resolve = iter[kLastResolve];
  8232. if (resolve !== null) {
  8233. var data = iter[kStream].read(); // we defer if data is null
  8234. // we can be expecting either 'end' or
  8235. // 'error'
  8236. if (data !== null) {
  8237. iter[kLastPromise] = null;
  8238. iter[kLastResolve] = null;
  8239. iter[kLastReject] = null;
  8240. resolve(createIterResult(data, false));
  8241. }
  8242. }
  8243. }
  8244. function onReadable(iter) {
  8245. // we wait for the next tick, because it might
  8246. // emit an error with process.nextTick
  8247. process.nextTick(readAndResolve, iter);
  8248. }
  8249. function wrapForNext(lastPromise, iter) {
  8250. return function (resolve, reject) {
  8251. lastPromise.then(function () {
  8252. if (iter[kEnded]) {
  8253. resolve(createIterResult(undefined, true));
  8254. return;
  8255. }
  8256. iter[kHandlePromise](resolve, reject);
  8257. }, reject);
  8258. };
  8259. }
  8260. var AsyncIteratorPrototype = Object.getPrototypeOf(function () {});
  8261. var ReadableStreamAsyncIteratorPrototype = Object.setPrototypeOf((_Object$setPrototypeO = {
  8262. get stream() {
  8263. return this[kStream];
  8264. },
  8265. next: function next() {
  8266. var _this = this;
  8267. // if we have detected an error in the meanwhile
  8268. // reject straight away
  8269. var error = this[kError];
  8270. if (error !== null) {
  8271. return Promise.reject(error);
  8272. }
  8273. if (this[kEnded]) {
  8274. return Promise.resolve(createIterResult(undefined, true));
  8275. }
  8276. if (this[kStream].destroyed) {
  8277. // We need to defer via nextTick because if .destroy(err) is
  8278. // called, the error will be emitted via nextTick, and
  8279. // we cannot guarantee that there is no error lingering around
  8280. // waiting to be emitted.
  8281. return new Promise(function (resolve, reject) {
  8282. process.nextTick(function () {
  8283. if (_this[kError]) {
  8284. reject(_this[kError]);
  8285. } else {
  8286. resolve(createIterResult(undefined, true));
  8287. }
  8288. });
  8289. });
  8290. } // if we have multiple next() calls
  8291. // we will wait for the previous Promise to finish
  8292. // this logic is optimized to support for await loops,
  8293. // where next() is only called once at a time
  8294. var lastPromise = this[kLastPromise];
  8295. var promise;
  8296. if (lastPromise) {
  8297. promise = new Promise(wrapForNext(lastPromise, this));
  8298. } else {
  8299. // fast path needed to support multiple this.push()
  8300. // without triggering the next() queue
  8301. var data = this[kStream].read();
  8302. if (data !== null) {
  8303. return Promise.resolve(createIterResult(data, false));
  8304. }
  8305. promise = new Promise(this[kHandlePromise]);
  8306. }
  8307. this[kLastPromise] = promise;
  8308. return promise;
  8309. }
  8310. }, _defineProperty(_Object$setPrototypeO, Symbol.asyncIterator, function () {
  8311. return this;
  8312. }), _defineProperty(_Object$setPrototypeO, "return", function _return() {
  8313. var _this2 = this;
  8314. // destroy(err, cb) is a private API
  8315. // we can guarantee we have that here, because we control the
  8316. // Readable class this is attached to
  8317. return new Promise(function (resolve, reject) {
  8318. _this2[kStream].destroy(null, function (err) {
  8319. if (err) {
  8320. reject(err);
  8321. return;
  8322. }
  8323. resolve(createIterResult(undefined, true));
  8324. });
  8325. });
  8326. }), _Object$setPrototypeO), AsyncIteratorPrototype);
  8327. var createReadableStreamAsyncIterator = function createReadableStreamAsyncIterator(stream) {
  8328. var _Object$create;
  8329. var iterator = Object.create(ReadableStreamAsyncIteratorPrototype, (_Object$create = {}, _defineProperty(_Object$create, kStream, {
  8330. value: stream,
  8331. writable: true
  8332. }), _defineProperty(_Object$create, kLastResolve, {
  8333. value: null,
  8334. writable: true
  8335. }), _defineProperty(_Object$create, kLastReject, {
  8336. value: null,
  8337. writable: true
  8338. }), _defineProperty(_Object$create, kError, {
  8339. value: null,
  8340. writable: true
  8341. }), _defineProperty(_Object$create, kEnded, {
  8342. value: stream._readableState.endEmitted,
  8343. writable: true
  8344. }), _defineProperty(_Object$create, kHandlePromise, {
  8345. value: function value(resolve, reject) {
  8346. var data = iterator[kStream].read();
  8347. if (data) {
  8348. iterator[kLastPromise] = null;
  8349. iterator[kLastResolve] = null;
  8350. iterator[kLastReject] = null;
  8351. resolve(createIterResult(data, false));
  8352. } else {
  8353. iterator[kLastResolve] = resolve;
  8354. iterator[kLastReject] = reject;
  8355. }
  8356. },
  8357. writable: true
  8358. }), _Object$create));
  8359. iterator[kLastPromise] = null;
  8360. finished(stream, function (err) {
  8361. if (err && err.code !== 'ERR_STREAM_PREMATURE_CLOSE') {
  8362. var reject = iterator[kLastReject]; // reject if we are waiting for data in the Promise
  8363. // returned by next() and store the error
  8364. if (reject !== null) {
  8365. iterator[kLastPromise] = null;
  8366. iterator[kLastResolve] = null;
  8367. iterator[kLastReject] = null;
  8368. reject(err);
  8369. }
  8370. iterator[kError] = err;
  8371. return;
  8372. }
  8373. var resolve = iterator[kLastResolve];
  8374. if (resolve !== null) {
  8375. iterator[kLastPromise] = null;
  8376. iterator[kLastResolve] = null;
  8377. iterator[kLastReject] = null;
  8378. resolve(createIterResult(undefined, true));
  8379. }
  8380. iterator[kEnded] = true;
  8381. });
  8382. stream.on('readable', onReadable.bind(null, iterator));
  8383. return iterator;
  8384. };
  8385. module.exports = createReadableStreamAsyncIterator;
  8386. }).call(this)}).call(this,require('_process'))
  8387. },{"./end-of-stream":30,"_process":11}],28:[function(require,module,exports){
  8388. 'use strict';
  8389. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  8390. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  8391. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  8392. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  8393. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  8394. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  8395. var _require = require('buffer'),
  8396. Buffer = _require.Buffer;
  8397. var _require2 = require('util'),
  8398. inspect = _require2.inspect;
  8399. var custom = inspect && inspect.custom || 'inspect';
  8400. function copyBuffer(src, target, offset) {
  8401. Buffer.prototype.copy.call(src, target, offset);
  8402. }
  8403. module.exports =
  8404. /*#__PURE__*/
  8405. function () {
  8406. function BufferList() {
  8407. _classCallCheck(this, BufferList);
  8408. this.head = null;
  8409. this.tail = null;
  8410. this.length = 0;
  8411. }
  8412. _createClass(BufferList, [{
  8413. key: "push",
  8414. value: function push(v) {
  8415. var entry = {
  8416. data: v,
  8417. next: null
  8418. };
  8419. if (this.length > 0) this.tail.next = entry;else this.head = entry;
  8420. this.tail = entry;
  8421. ++this.length;
  8422. }
  8423. }, {
  8424. key: "unshift",
  8425. value: function unshift(v) {
  8426. var entry = {
  8427. data: v,
  8428. next: this.head
  8429. };
  8430. if (this.length === 0) this.tail = entry;
  8431. this.head = entry;
  8432. ++this.length;
  8433. }
  8434. }, {
  8435. key: "shift",
  8436. value: function shift() {
  8437. if (this.length === 0) return;
  8438. var ret = this.head.data;
  8439. if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next;
  8440. --this.length;
  8441. return ret;
  8442. }
  8443. }, {
  8444. key: "clear",
  8445. value: function clear() {
  8446. this.head = this.tail = null;
  8447. this.length = 0;
  8448. }
  8449. }, {
  8450. key: "join",
  8451. value: function join(s) {
  8452. if (this.length === 0) return '';
  8453. var p = this.head;
  8454. var ret = '' + p.data;
  8455. while (p = p.next) {
  8456. ret += s + p.data;
  8457. }
  8458. return ret;
  8459. }
  8460. }, {
  8461. key: "concat",
  8462. value: function concat(n) {
  8463. if (this.length === 0) return Buffer.alloc(0);
  8464. var ret = Buffer.allocUnsafe(n >>> 0);
  8465. var p = this.head;
  8466. var i = 0;
  8467. while (p) {
  8468. copyBuffer(p.data, ret, i);
  8469. i += p.data.length;
  8470. p = p.next;
  8471. }
  8472. return ret;
  8473. } // Consumes a specified amount of bytes or characters from the buffered data.
  8474. }, {
  8475. key: "consume",
  8476. value: function consume(n, hasStrings) {
  8477. var ret;
  8478. if (n < this.head.data.length) {
  8479. // `slice` is the same for buffers and strings.
  8480. ret = this.head.data.slice(0, n);
  8481. this.head.data = this.head.data.slice(n);
  8482. } else if (n === this.head.data.length) {
  8483. // First chunk is a perfect match.
  8484. ret = this.shift();
  8485. } else {
  8486. // Result spans more than one buffer.
  8487. ret = hasStrings ? this._getString(n) : this._getBuffer(n);
  8488. }
  8489. return ret;
  8490. }
  8491. }, {
  8492. key: "first",
  8493. value: function first() {
  8494. return this.head.data;
  8495. } // Consumes a specified amount of characters from the buffered data.
  8496. }, {
  8497. key: "_getString",
  8498. value: function _getString(n) {
  8499. var p = this.head;
  8500. var c = 1;
  8501. var ret = p.data;
  8502. n -= ret.length;
  8503. while (p = p.next) {
  8504. var str = p.data;
  8505. var nb = n > str.length ? str.length : n;
  8506. if (nb === str.length) ret += str;else ret += str.slice(0, n);
  8507. n -= nb;
  8508. if (n === 0) {
  8509. if (nb === str.length) {
  8510. ++c;
  8511. if (p.next) this.head = p.next;else this.head = this.tail = null;
  8512. } else {
  8513. this.head = p;
  8514. p.data = str.slice(nb);
  8515. }
  8516. break;
  8517. }
  8518. ++c;
  8519. }
  8520. this.length -= c;
  8521. return ret;
  8522. } // Consumes a specified amount of bytes from the buffered data.
  8523. }, {
  8524. key: "_getBuffer",
  8525. value: function _getBuffer(n) {
  8526. var ret = Buffer.allocUnsafe(n);
  8527. var p = this.head;
  8528. var c = 1;
  8529. p.data.copy(ret);
  8530. n -= p.data.length;
  8531. while (p = p.next) {
  8532. var buf = p.data;
  8533. var nb = n > buf.length ? buf.length : n;
  8534. buf.copy(ret, ret.length - n, 0, nb);
  8535. n -= nb;
  8536. if (n === 0) {
  8537. if (nb === buf.length) {
  8538. ++c;
  8539. if (p.next) this.head = p.next;else this.head = this.tail = null;
  8540. } else {
  8541. this.head = p;
  8542. p.data = buf.slice(nb);
  8543. }
  8544. break;
  8545. }
  8546. ++c;
  8547. }
  8548. this.length -= c;
  8549. return ret;
  8550. } // Make sure the linked list only shows the minimal necessary information.
  8551. }, {
  8552. key: custom,
  8553. value: function value(_, options) {
  8554. return inspect(this, _objectSpread({}, options, {
  8555. // Only inspect one level.
  8556. depth: 0,
  8557. // It should not recurse.
  8558. customInspect: false
  8559. }));
  8560. }
  8561. }]);
  8562. return BufferList;
  8563. }();
  8564. },{"buffer":3,"util":2}],29:[function(require,module,exports){
  8565. (function (process){(function (){
  8566. 'use strict'; // undocumented cb() API, needed for core, not for public API
  8567. function destroy(err, cb) {
  8568. var _this = this;
  8569. var readableDestroyed = this._readableState && this._readableState.destroyed;
  8570. var writableDestroyed = this._writableState && this._writableState.destroyed;
  8571. if (readableDestroyed || writableDestroyed) {
  8572. if (cb) {
  8573. cb(err);
  8574. } else if (err) {
  8575. if (!this._writableState) {
  8576. process.nextTick(emitErrorNT, this, err);
  8577. } else if (!this._writableState.errorEmitted) {
  8578. this._writableState.errorEmitted = true;
  8579. process.nextTick(emitErrorNT, this, err);
  8580. }
  8581. }
  8582. return this;
  8583. } // we set destroyed to true before firing error callbacks in order
  8584. // to make it re-entrance safe in case destroy() is called within callbacks
  8585. if (this._readableState) {
  8586. this._readableState.destroyed = true;
  8587. } // if this is a duplex stream mark the writable part as destroyed as well
  8588. if (this._writableState) {
  8589. this._writableState.destroyed = true;
  8590. }
  8591. this._destroy(err || null, function (err) {
  8592. if (!cb && err) {
  8593. if (!_this._writableState) {
  8594. process.nextTick(emitErrorAndCloseNT, _this, err);
  8595. } else if (!_this._writableState.errorEmitted) {
  8596. _this._writableState.errorEmitted = true;
  8597. process.nextTick(emitErrorAndCloseNT, _this, err);
  8598. } else {
  8599. process.nextTick(emitCloseNT, _this);
  8600. }
  8601. } else if (cb) {
  8602. process.nextTick(emitCloseNT, _this);
  8603. cb(err);
  8604. } else {
  8605. process.nextTick(emitCloseNT, _this);
  8606. }
  8607. });
  8608. return this;
  8609. }
  8610. function emitErrorAndCloseNT(self, err) {
  8611. emitErrorNT(self, err);
  8612. emitCloseNT(self);
  8613. }
  8614. function emitCloseNT(self) {
  8615. if (self._writableState && !self._writableState.emitClose) return;
  8616. if (self._readableState && !self._readableState.emitClose) return;
  8617. self.emit('close');
  8618. }
  8619. function undestroy() {
  8620. if (this._readableState) {
  8621. this._readableState.destroyed = false;
  8622. this._readableState.reading = false;
  8623. this._readableState.ended = false;
  8624. this._readableState.endEmitted = false;
  8625. }
  8626. if (this._writableState) {
  8627. this._writableState.destroyed = false;
  8628. this._writableState.ended = false;
  8629. this._writableState.ending = false;
  8630. this._writableState.finalCalled = false;
  8631. this._writableState.prefinished = false;
  8632. this._writableState.finished = false;
  8633. this._writableState.errorEmitted = false;
  8634. }
  8635. }
  8636. function emitErrorNT(self, err) {
  8637. self.emit('error', err);
  8638. }
  8639. function errorOrDestroy(stream, err) {
  8640. // We have tests that rely on errors being emitted
  8641. // in the same tick, so changing this is semver major.
  8642. // For now when you opt-in to autoDestroy we allow
  8643. // the error to be emitted nextTick. In a future
  8644. // semver major update we should change the default to this.
  8645. var rState = stream._readableState;
  8646. var wState = stream._writableState;
  8647. if (rState && rState.autoDestroy || wState && wState.autoDestroy) stream.destroy(err);else stream.emit('error', err);
  8648. }
  8649. module.exports = {
  8650. destroy: destroy,
  8651. undestroy: undestroy,
  8652. errorOrDestroy: errorOrDestroy
  8653. };
  8654. }).call(this)}).call(this,require('_process'))
  8655. },{"_process":11}],30:[function(require,module,exports){
  8656. // Ported from https://github.com/mafintosh/end-of-stream with
  8657. // permission from the author, Mathias Buus (@mafintosh).
  8658. 'use strict';
  8659. var ERR_STREAM_PREMATURE_CLOSE = require('../../../errors').codes.ERR_STREAM_PREMATURE_CLOSE;
  8660. function once(callback) {
  8661. var called = false;
  8662. return function () {
  8663. if (called) return;
  8664. called = true;
  8665. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  8666. args[_key] = arguments[_key];
  8667. }
  8668. callback.apply(this, args);
  8669. };
  8670. }
  8671. function noop() {}
  8672. function isRequest(stream) {
  8673. return stream.setHeader && typeof stream.abort === 'function';
  8674. }
  8675. function eos(stream, opts, callback) {
  8676. if (typeof opts === 'function') return eos(stream, null, opts);
  8677. if (!opts) opts = {};
  8678. callback = once(callback || noop);
  8679. var readable = opts.readable || opts.readable !== false && stream.readable;
  8680. var writable = opts.writable || opts.writable !== false && stream.writable;
  8681. var onlegacyfinish = function onlegacyfinish() {
  8682. if (!stream.writable) onfinish();
  8683. };
  8684. var writableEnded = stream._writableState && stream._writableState.finished;
  8685. var onfinish = function onfinish() {
  8686. writable = false;
  8687. writableEnded = true;
  8688. if (!readable) callback.call(stream);
  8689. };
  8690. var readableEnded = stream._readableState && stream._readableState.endEmitted;
  8691. var onend = function onend() {
  8692. readable = false;
  8693. readableEnded = true;
  8694. if (!writable) callback.call(stream);
  8695. };
  8696. var onerror = function onerror(err) {
  8697. callback.call(stream, err);
  8698. };
  8699. var onclose = function onclose() {
  8700. var err;
  8701. if (readable && !readableEnded) {
  8702. if (!stream._readableState || !stream._readableState.ended) err = new ERR_STREAM_PREMATURE_CLOSE();
  8703. return callback.call(stream, err);
  8704. }
  8705. if (writable && !writableEnded) {
  8706. if (!stream._writableState || !stream._writableState.ended) err = new ERR_STREAM_PREMATURE_CLOSE();
  8707. return callback.call(stream, err);
  8708. }
  8709. };
  8710. var onrequest = function onrequest() {
  8711. stream.req.on('finish', onfinish);
  8712. };
  8713. if (isRequest(stream)) {
  8714. stream.on('complete', onfinish);
  8715. stream.on('abort', onclose);
  8716. if (stream.req) onrequest();else stream.on('request', onrequest);
  8717. } else if (writable && !stream._writableState) {
  8718. // legacy streams
  8719. stream.on('end', onlegacyfinish);
  8720. stream.on('close', onlegacyfinish);
  8721. }
  8722. stream.on('end', onend);
  8723. stream.on('finish', onfinish);
  8724. if (opts.error !== false) stream.on('error', onerror);
  8725. stream.on('close', onclose);
  8726. return function () {
  8727. stream.removeListener('complete', onfinish);
  8728. stream.removeListener('abort', onclose);
  8729. stream.removeListener('request', onrequest);
  8730. if (stream.req) stream.req.removeListener('finish', onfinish);
  8731. stream.removeListener('end', onlegacyfinish);
  8732. stream.removeListener('close', onlegacyfinish);
  8733. stream.removeListener('finish', onfinish);
  8734. stream.removeListener('end', onend);
  8735. stream.removeListener('error', onerror);
  8736. stream.removeListener('close', onclose);
  8737. };
  8738. }
  8739. module.exports = eos;
  8740. },{"../../../errors":21}],31:[function(require,module,exports){
  8741. module.exports = function () {
  8742. throw new Error('Readable.from is not available in the browser')
  8743. };
  8744. },{}],32:[function(require,module,exports){
  8745. // Ported from https://github.com/mafintosh/pump with
  8746. // permission from the author, Mathias Buus (@mafintosh).
  8747. 'use strict';
  8748. var eos;
  8749. function once(callback) {
  8750. var called = false;
  8751. return function () {
  8752. if (called) return;
  8753. called = true;
  8754. callback.apply(void 0, arguments);
  8755. };
  8756. }
  8757. var _require$codes = require('../../../errors').codes,
  8758. ERR_MISSING_ARGS = _require$codes.ERR_MISSING_ARGS,
  8759. ERR_STREAM_DESTROYED = _require$codes.ERR_STREAM_DESTROYED;
  8760. function noop(err) {
  8761. // Rethrow the error if it exists to avoid swallowing it
  8762. if (err) throw err;
  8763. }
  8764. function isRequest(stream) {
  8765. return stream.setHeader && typeof stream.abort === 'function';
  8766. }
  8767. function destroyer(stream, reading, writing, callback) {
  8768. callback = once(callback);
  8769. var closed = false;
  8770. stream.on('close', function () {
  8771. closed = true;
  8772. });
  8773. if (eos === undefined) eos = require('./end-of-stream');
  8774. eos(stream, {
  8775. readable: reading,
  8776. writable: writing
  8777. }, function (err) {
  8778. if (err) return callback(err);
  8779. closed = true;
  8780. callback();
  8781. });
  8782. var destroyed = false;
  8783. return function (err) {
  8784. if (closed) return;
  8785. if (destroyed) return;
  8786. destroyed = true; // request.destroy just do .end - .abort is what we want
  8787. if (isRequest(stream)) return stream.abort();
  8788. if (typeof stream.destroy === 'function') return stream.destroy();
  8789. callback(err || new ERR_STREAM_DESTROYED('pipe'));
  8790. };
  8791. }
  8792. function call(fn) {
  8793. fn();
  8794. }
  8795. function pipe(from, to) {
  8796. return from.pipe(to);
  8797. }
  8798. function popCallback(streams) {
  8799. if (!streams.length) return noop;
  8800. if (typeof streams[streams.length - 1] !== 'function') return noop;
  8801. return streams.pop();
  8802. }
  8803. function pipeline() {
  8804. for (var _len = arguments.length, streams = new Array(_len), _key = 0; _key < _len; _key++) {
  8805. streams[_key] = arguments[_key];
  8806. }
  8807. var callback = popCallback(streams);
  8808. if (Array.isArray(streams[0])) streams = streams[0];
  8809. if (streams.length < 2) {
  8810. throw new ERR_MISSING_ARGS('streams');
  8811. }
  8812. var error;
  8813. var destroys = streams.map(function (stream, i) {
  8814. var reading = i < streams.length - 1;
  8815. var writing = i > 0;
  8816. return destroyer(stream, reading, writing, function (err) {
  8817. if (!error) error = err;
  8818. if (err) destroys.forEach(call);
  8819. if (reading) return;
  8820. destroys.forEach(call);
  8821. callback(error);
  8822. });
  8823. });
  8824. return streams.reduce(pipe);
  8825. }
  8826. module.exports = pipeline;
  8827. },{"../../../errors":21,"./end-of-stream":30}],33:[function(require,module,exports){
  8828. 'use strict';
  8829. var ERR_INVALID_OPT_VALUE = require('../../../errors').codes.ERR_INVALID_OPT_VALUE;
  8830. function highWaterMarkFrom(options, isDuplex, duplexKey) {
  8831. return options.highWaterMark != null ? options.highWaterMark : isDuplex ? options[duplexKey] : null;
  8832. }
  8833. function getHighWaterMark(state, options, duplexKey, isDuplex) {
  8834. var hwm = highWaterMarkFrom(options, isDuplex, duplexKey);
  8835. if (hwm != null) {
  8836. if (!(isFinite(hwm) && Math.floor(hwm) === hwm) || hwm < 0) {
  8837. var name = isDuplex ? duplexKey : 'highWaterMark';
  8838. throw new ERR_INVALID_OPT_VALUE(name, hwm);
  8839. }
  8840. return Math.floor(hwm);
  8841. } // Default value
  8842. return state.objectMode ? 16 : 16 * 1024;
  8843. }
  8844. module.exports = {
  8845. getHighWaterMark: getHighWaterMark
  8846. };
  8847. },{"../../../errors":21}],34:[function(require,module,exports){
  8848. module.exports = require('events').EventEmitter;
  8849. },{"events":5}],35:[function(require,module,exports){
  8850. exports = module.exports = require('./lib/_stream_readable.js');
  8851. exports.Stream = exports;
  8852. exports.Readable = exports;
  8853. exports.Writable = require('./lib/_stream_writable.js');
  8854. exports.Duplex = require('./lib/_stream_duplex.js');
  8855. exports.Transform = require('./lib/_stream_transform.js');
  8856. exports.PassThrough = require('./lib/_stream_passthrough.js');
  8857. exports.finished = require('./lib/internal/streams/end-of-stream.js');
  8858. exports.pipeline = require('./lib/internal/streams/pipeline.js');
  8859. },{"./lib/_stream_duplex.js":22,"./lib/_stream_passthrough.js":23,"./lib/_stream_readable.js":24,"./lib/_stream_transform.js":25,"./lib/_stream_writable.js":26,"./lib/internal/streams/end-of-stream.js":30,"./lib/internal/streams/pipeline.js":32}],36:[function(require,module,exports){
  8860. // Copyright Joyent, Inc. and other Node contributors.
  8861. //
  8862. // Permission is hereby granted, free of charge, to any person obtaining a
  8863. // copy of this software and associated documentation files (the
  8864. // "Software"), to deal in the Software without restriction, including
  8865. // without limitation the rights to use, copy, modify, merge, publish,
  8866. // distribute, sublicense, and/or sell copies of the Software, and to permit
  8867. // persons to whom the Software is furnished to do so, subject to the
  8868. // following conditions:
  8869. //
  8870. // The above copyright notice and this permission notice shall be included
  8871. // in all copies or substantial portions of the Software.
  8872. //
  8873. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  8874. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  8875. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  8876. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  8877. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  8878. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  8879. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  8880. 'use strict';
  8881. /*<replacement>*/
  8882. var Buffer = require('safe-buffer').Buffer;
  8883. /*</replacement>*/
  8884. var isEncoding = Buffer.isEncoding || function (encoding) {
  8885. encoding = '' + encoding;
  8886. switch (encoding && encoding.toLowerCase()) {
  8887. case 'hex':case 'utf8':case 'utf-8':case 'ascii':case 'binary':case 'base64':case 'ucs2':case 'ucs-2':case 'utf16le':case 'utf-16le':case 'raw':
  8888. return true;
  8889. default:
  8890. return false;
  8891. }
  8892. };
  8893. function _normalizeEncoding(enc) {
  8894. if (!enc) return 'utf8';
  8895. var retried;
  8896. while (true) {
  8897. switch (enc) {
  8898. case 'utf8':
  8899. case 'utf-8':
  8900. return 'utf8';
  8901. case 'ucs2':
  8902. case 'ucs-2':
  8903. case 'utf16le':
  8904. case 'utf-16le':
  8905. return 'utf16le';
  8906. case 'latin1':
  8907. case 'binary':
  8908. return 'latin1';
  8909. case 'base64':
  8910. case 'ascii':
  8911. case 'hex':
  8912. return enc;
  8913. default:
  8914. if (retried) return; // undefined
  8915. enc = ('' + enc).toLowerCase();
  8916. retried = true;
  8917. }
  8918. }
  8919. };
  8920. // Do not cache `Buffer.isEncoding` when checking encoding names as some
  8921. // modules monkey-patch it to support additional encodings
  8922. function normalizeEncoding(enc) {
  8923. var nenc = _normalizeEncoding(enc);
  8924. if (typeof nenc !== 'string' && (Buffer.isEncoding === isEncoding || !isEncoding(enc))) throw new Error('Unknown encoding: ' + enc);
  8925. return nenc || enc;
  8926. }
  8927. // StringDecoder provides an interface for efficiently splitting a series of
  8928. // buffers into a series of JS strings without breaking apart multi-byte
  8929. // characters.
  8930. exports.StringDecoder = StringDecoder;
  8931. function StringDecoder(encoding) {
  8932. this.encoding = normalizeEncoding(encoding);
  8933. var nb;
  8934. switch (this.encoding) {
  8935. case 'utf16le':
  8936. this.text = utf16Text;
  8937. this.end = utf16End;
  8938. nb = 4;
  8939. break;
  8940. case 'utf8':
  8941. this.fillLast = utf8FillLast;
  8942. nb = 4;
  8943. break;
  8944. case 'base64':
  8945. this.text = base64Text;
  8946. this.end = base64End;
  8947. nb = 3;
  8948. break;
  8949. default:
  8950. this.write = simpleWrite;
  8951. this.end = simpleEnd;
  8952. return;
  8953. }
  8954. this.lastNeed = 0;
  8955. this.lastTotal = 0;
  8956. this.lastChar = Buffer.allocUnsafe(nb);
  8957. }
  8958. StringDecoder.prototype.write = function (buf) {
  8959. if (buf.length === 0) return '';
  8960. var r;
  8961. var i;
  8962. if (this.lastNeed) {
  8963. r = this.fillLast(buf);
  8964. if (r === undefined) return '';
  8965. i = this.lastNeed;
  8966. this.lastNeed = 0;
  8967. } else {
  8968. i = 0;
  8969. }
  8970. if (i < buf.length) return r ? r + this.text(buf, i) : this.text(buf, i);
  8971. return r || '';
  8972. };
  8973. StringDecoder.prototype.end = utf8End;
  8974. // Returns only complete characters in a Buffer
  8975. StringDecoder.prototype.text = utf8Text;
  8976. // Attempts to complete a partial non-UTF-8 character using bytes from a Buffer
  8977. StringDecoder.prototype.fillLast = function (buf) {
  8978. if (this.lastNeed <= buf.length) {
  8979. buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, this.lastNeed);
  8980. return this.lastChar.toString(this.encoding, 0, this.lastTotal);
  8981. }
  8982. buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, buf.length);
  8983. this.lastNeed -= buf.length;
  8984. };
  8985. // Checks the type of a UTF-8 byte, whether it's ASCII, a leading byte, or a
  8986. // continuation byte. If an invalid byte is detected, -2 is returned.
  8987. function utf8CheckByte(byte) {
  8988. if (byte <= 0x7F) return 0;else if (byte >> 5 === 0x06) return 2;else if (byte >> 4 === 0x0E) return 3;else if (byte >> 3 === 0x1E) return 4;
  8989. return byte >> 6 === 0x02 ? -1 : -2;
  8990. }
  8991. // Checks at most 3 bytes at the end of a Buffer in order to detect an
  8992. // incomplete multi-byte UTF-8 character. The total number of bytes (2, 3, or 4)
  8993. // needed to complete the UTF-8 character (if applicable) are returned.
  8994. function utf8CheckIncomplete(self, buf, i) {
  8995. var j = buf.length - 1;
  8996. if (j < i) return 0;
  8997. var nb = utf8CheckByte(buf[j]);
  8998. if (nb >= 0) {
  8999. if (nb > 0) self.lastNeed = nb - 1;
  9000. return nb;
  9001. }
  9002. if (--j < i || nb === -2) return 0;
  9003. nb = utf8CheckByte(buf[j]);
  9004. if (nb >= 0) {
  9005. if (nb > 0) self.lastNeed = nb - 2;
  9006. return nb;
  9007. }
  9008. if (--j < i || nb === -2) return 0;
  9009. nb = utf8CheckByte(buf[j]);
  9010. if (nb >= 0) {
  9011. if (nb > 0) {
  9012. if (nb === 2) nb = 0;else self.lastNeed = nb - 3;
  9013. }
  9014. return nb;
  9015. }
  9016. return 0;
  9017. }
  9018. // Validates as many continuation bytes for a multi-byte UTF-8 character as
  9019. // needed or are available. If we see a non-continuation byte where we expect
  9020. // one, we "replace" the validated continuation bytes we've seen so far with
  9021. // a single UTF-8 replacement character ('\ufffd'), to match v8's UTF-8 decoding
  9022. // behavior. The continuation byte check is included three times in the case
  9023. // where all of the continuation bytes for a character exist in the same buffer.
  9024. // It is also done this way as a slight performance increase instead of using a
  9025. // loop.
  9026. function utf8CheckExtraBytes(self, buf, p) {
  9027. if ((buf[0] & 0xC0) !== 0x80) {
  9028. self.lastNeed = 0;
  9029. return '\ufffd';
  9030. }
  9031. if (self.lastNeed > 1 && buf.length > 1) {
  9032. if ((buf[1] & 0xC0) !== 0x80) {
  9033. self.lastNeed = 1;
  9034. return '\ufffd';
  9035. }
  9036. if (self.lastNeed > 2 && buf.length > 2) {
  9037. if ((buf[2] & 0xC0) !== 0x80) {
  9038. self.lastNeed = 2;
  9039. return '\ufffd';
  9040. }
  9041. }
  9042. }
  9043. }
  9044. // Attempts to complete a multi-byte UTF-8 character using bytes from a Buffer.
  9045. function utf8FillLast(buf) {
  9046. var p = this.lastTotal - this.lastNeed;
  9047. var r = utf8CheckExtraBytes(this, buf, p);
  9048. if (r !== undefined) return r;
  9049. if (this.lastNeed <= buf.length) {
  9050. buf.copy(this.lastChar, p, 0, this.lastNeed);
  9051. return this.lastChar.toString(this.encoding, 0, this.lastTotal);
  9052. }
  9053. buf.copy(this.lastChar, p, 0, buf.length);
  9054. this.lastNeed -= buf.length;
  9055. }
  9056. // Returns all complete UTF-8 characters in a Buffer. If the Buffer ended on a
  9057. // partial character, the character's bytes are buffered until the required
  9058. // number of bytes are available.
  9059. function utf8Text(buf, i) {
  9060. var total = utf8CheckIncomplete(this, buf, i);
  9061. if (!this.lastNeed) return buf.toString('utf8', i);
  9062. this.lastTotal = total;
  9063. var end = buf.length - (total - this.lastNeed);
  9064. buf.copy(this.lastChar, 0, end);
  9065. return buf.toString('utf8', i, end);
  9066. }
  9067. // For UTF-8, a replacement character is added when ending on a partial
  9068. // character.
  9069. function utf8End(buf) {
  9070. var r = buf && buf.length ? this.write(buf) : '';
  9071. if (this.lastNeed) return r + '\ufffd';
  9072. return r;
  9073. }
  9074. // UTF-16LE typically needs two bytes per character, but even if we have an even
  9075. // number of bytes available, we need to check if we end on a leading/high
  9076. // surrogate. In that case, we need to wait for the next two bytes in order to
  9077. // decode the last character properly.
  9078. function utf16Text(buf, i) {
  9079. if ((buf.length - i) % 2 === 0) {
  9080. var r = buf.toString('utf16le', i);
  9081. if (r) {
  9082. var c = r.charCodeAt(r.length - 1);
  9083. if (c >= 0xD800 && c <= 0xDBFF) {
  9084. this.lastNeed = 2;
  9085. this.lastTotal = 4;
  9086. this.lastChar[0] = buf[buf.length - 2];
  9087. this.lastChar[1] = buf[buf.length - 1];
  9088. return r.slice(0, -1);
  9089. }
  9090. }
  9091. return r;
  9092. }
  9093. this.lastNeed = 1;
  9094. this.lastTotal = 2;
  9095. this.lastChar[0] = buf[buf.length - 1];
  9096. return buf.toString('utf16le', i, buf.length - 1);
  9097. }
  9098. // For UTF-16LE we do not explicitly append special replacement characters if we
  9099. // end on a partial character, we simply let v8 handle that.
  9100. function utf16End(buf) {
  9101. var r = buf && buf.length ? this.write(buf) : '';
  9102. if (this.lastNeed) {
  9103. var end = this.lastTotal - this.lastNeed;
  9104. return r + this.lastChar.toString('utf16le', 0, end);
  9105. }
  9106. return r;
  9107. }
  9108. function base64Text(buf, i) {
  9109. var n = (buf.length - i) % 3;
  9110. if (n === 0) return buf.toString('base64', i);
  9111. this.lastNeed = 3 - n;
  9112. this.lastTotal = 3;
  9113. if (n === 1) {
  9114. this.lastChar[0] = buf[buf.length - 1];
  9115. } else {
  9116. this.lastChar[0] = buf[buf.length - 2];
  9117. this.lastChar[1] = buf[buf.length - 1];
  9118. }
  9119. return buf.toString('base64', i, buf.length - n);
  9120. }
  9121. function base64End(buf) {
  9122. var r = buf && buf.length ? this.write(buf) : '';
  9123. if (this.lastNeed) return r + this.lastChar.toString('base64', 0, 3 - this.lastNeed);
  9124. return r;
  9125. }
  9126. // Pass bytes on through for single-byte encodings (e.g. ascii, latin1, hex)
  9127. function simpleWrite(buf) {
  9128. return buf.toString(this.encoding);
  9129. }
  9130. function simpleEnd(buf) {
  9131. return buf && buf.length ? this.write(buf) : '';
  9132. }
  9133. },{"safe-buffer":16}],37:[function(require,module,exports){
  9134. // Copyright Joyent, Inc. and other Node contributors.
  9135. //
  9136. // Permission is hereby granted, free of charge, to any person obtaining a
  9137. // copy of this software and associated documentation files (the
  9138. // "Software"), to deal in the Software without restriction, including
  9139. // without limitation the rights to use, copy, modify, merge, publish,
  9140. // distribute, sublicense, and/or sell copies of the Software, and to permit
  9141. // persons to whom the Software is furnished to do so, subject to the
  9142. // following conditions:
  9143. //
  9144. // The above copyright notice and this permission notice shall be included
  9145. // in all copies or substantial portions of the Software.
  9146. //
  9147. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  9148. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  9149. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  9150. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  9151. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  9152. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  9153. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  9154. 'use strict';
  9155. var punycode = require('punycode');
  9156. var util = require('./util');
  9157. exports.parse = urlParse;
  9158. exports.resolve = urlResolve;
  9159. exports.resolveObject = urlResolveObject;
  9160. exports.format = urlFormat;
  9161. exports.Url = Url;
  9162. function Url() {
  9163. this.protocol = null;
  9164. this.slashes = null;
  9165. this.auth = null;
  9166. this.host = null;
  9167. this.port = null;
  9168. this.hostname = null;
  9169. this.hash = null;
  9170. this.search = null;
  9171. this.query = null;
  9172. this.pathname = null;
  9173. this.path = null;
  9174. this.href = null;
  9175. }
  9176. // Reference: RFC 3986, RFC 1808, RFC 2396
  9177. // define these here so at least they only have to be
  9178. // compiled once on the first module load.
  9179. var protocolPattern = /^([a-z0-9.+-]+:)/i,
  9180. portPattern = /:[0-9]*$/,
  9181. // Special case for a simple path URL
  9182. simplePathPattern = /^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,
  9183. // RFC 2396: characters reserved for delimiting URLs.
  9184. // We actually just auto-escape these.
  9185. delims = ['<', '>', '"', '`', ' ', '\r', '\n', '\t'],
  9186. // RFC 2396: characters not allowed for various reasons.
  9187. unwise = ['{', '}', '|', '\\', '^', '`'].concat(delims),
  9188. // Allowed by RFCs, but cause of XSS attacks. Always escape these.
  9189. autoEscape = ['\''].concat(unwise),
  9190. // Characters that are never ever allowed in a hostname.
  9191. // Note that any invalid chars are also handled, but these
  9192. // are the ones that are *expected* to be seen, so we fast-path
  9193. // them.
  9194. nonHostChars = ['%', '/', '?', ';', '#'].concat(autoEscape),
  9195. hostEndingChars = ['/', '?', '#'],
  9196. hostnameMaxLen = 255,
  9197. hostnamePartPattern = /^[+a-z0-9A-Z_-]{0,63}$/,
  9198. hostnamePartStart = /^([+a-z0-9A-Z_-]{0,63})(.*)$/,
  9199. // protocols that can allow "unsafe" and "unwise" chars.
  9200. unsafeProtocol = {
  9201. 'javascript': true,
  9202. 'javascript:': true
  9203. },
  9204. // protocols that never have a hostname.
  9205. hostlessProtocol = {
  9206. 'javascript': true,
  9207. 'javascript:': true
  9208. },
  9209. // protocols that always contain a // bit.
  9210. slashedProtocol = {
  9211. 'http': true,
  9212. 'https': true,
  9213. 'ftp': true,
  9214. 'gopher': true,
  9215. 'file': true,
  9216. 'http:': true,
  9217. 'https:': true,
  9218. 'ftp:': true,
  9219. 'gopher:': true,
  9220. 'file:': true
  9221. },
  9222. querystring = require('querystring');
  9223. function urlParse(url, parseQueryString, slashesDenoteHost) {
  9224. if (url && util.isObject(url) && url instanceof Url) return url;
  9225. var u = new Url;
  9226. u.parse(url, parseQueryString, slashesDenoteHost);
  9227. return u;
  9228. }
  9229. Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
  9230. if (!util.isString(url)) {
  9231. throw new TypeError("Parameter 'url' must be a string, not " + typeof url);
  9232. }
  9233. // Copy chrome, IE, opera backslash-handling behavior.
  9234. // Back slashes before the query string get converted to forward slashes
  9235. // See: https://code.google.com/p/chromium/issues/detail?id=25916
  9236. var queryIndex = url.indexOf('?'),
  9237. splitter =
  9238. (queryIndex !== -1 && queryIndex < url.indexOf('#')) ? '?' : '#',
  9239. uSplit = url.split(splitter),
  9240. slashRegex = /\\/g;
  9241. uSplit[0] = uSplit[0].replace(slashRegex, '/');
  9242. url = uSplit.join(splitter);
  9243. var rest = url;
  9244. // trim before proceeding.
  9245. // This is to support parse stuff like " http://foo.com \n"
  9246. rest = rest.trim();
  9247. if (!slashesDenoteHost && url.split('#').length === 1) {
  9248. // Try fast path regexp
  9249. var simplePath = simplePathPattern.exec(rest);
  9250. if (simplePath) {
  9251. this.path = rest;
  9252. this.href = rest;
  9253. this.pathname = simplePath[1];
  9254. if (simplePath[2]) {
  9255. this.search = simplePath[2];
  9256. if (parseQueryString) {
  9257. this.query = querystring.parse(this.search.substr(1));
  9258. } else {
  9259. this.query = this.search.substr(1);
  9260. }
  9261. } else if (parseQueryString) {
  9262. this.search = '';
  9263. this.query = {};
  9264. }
  9265. return this;
  9266. }
  9267. }
  9268. var proto = protocolPattern.exec(rest);
  9269. if (proto) {
  9270. proto = proto[0];
  9271. var lowerProto = proto.toLowerCase();
  9272. this.protocol = lowerProto;
  9273. rest = rest.substr(proto.length);
  9274. }
  9275. // figure out if it's got a host
  9276. // user@server is *always* interpreted as a hostname, and url
  9277. // resolution will treat //foo/bar as host=foo,path=bar because that's
  9278. // how the browser resolves relative URLs.
  9279. if (slashesDenoteHost || proto || rest.match(/^\/\/[^@\/]+@[^@\/]+/)) {
  9280. var slashes = rest.substr(0, 2) === '//';
  9281. if (slashes && !(proto && hostlessProtocol[proto])) {
  9282. rest = rest.substr(2);
  9283. this.slashes = true;
  9284. }
  9285. }
  9286. if (!hostlessProtocol[proto] &&
  9287. (slashes || (proto && !slashedProtocol[proto]))) {
  9288. // there's a hostname.
  9289. // the first instance of /, ?, ;, or # ends the host.
  9290. //
  9291. // If there is an @ in the hostname, then non-host chars *are* allowed
  9292. // to the left of the last @ sign, unless some host-ending character
  9293. // comes *before* the @-sign.
  9294. // URLs are obnoxious.
  9295. //
  9296. // ex:
  9297. // http://a@b@c/ => user:a@b host:c
  9298. // http://a@b?@c => user:a host:c path:/?@c
  9299. // v0.12 TODO(isaacs): This is not quite how Chrome does things.
  9300. // Review our test case against browsers more comprehensively.
  9301. // find the first instance of any hostEndingChars
  9302. var hostEnd = -1;
  9303. for (var i = 0; i < hostEndingChars.length; i++) {
  9304. var hec = rest.indexOf(hostEndingChars[i]);
  9305. if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
  9306. hostEnd = hec;
  9307. }
  9308. // at this point, either we have an explicit point where the
  9309. // auth portion cannot go past, or the last @ char is the decider.
  9310. var auth, atSign;
  9311. if (hostEnd === -1) {
  9312. // atSign can be anywhere.
  9313. atSign = rest.lastIndexOf('@');
  9314. } else {
  9315. // atSign must be in auth portion.
  9316. // http://a@b/c@d => host:b auth:a path:/c@d
  9317. atSign = rest.lastIndexOf('@', hostEnd);
  9318. }
  9319. // Now we have a portion which is definitely the auth.
  9320. // Pull that off.
  9321. if (atSign !== -1) {
  9322. auth = rest.slice(0, atSign);
  9323. rest = rest.slice(atSign + 1);
  9324. this.auth = decodeURIComponent(auth);
  9325. }
  9326. // the host is the remaining to the left of the first non-host char
  9327. hostEnd = -1;
  9328. for (var i = 0; i < nonHostChars.length; i++) {
  9329. var hec = rest.indexOf(nonHostChars[i]);
  9330. if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
  9331. hostEnd = hec;
  9332. }
  9333. // if we still have not hit it, then the entire thing is a host.
  9334. if (hostEnd === -1)
  9335. hostEnd = rest.length;
  9336. this.host = rest.slice(0, hostEnd);
  9337. rest = rest.slice(hostEnd);
  9338. // pull out port.
  9339. this.parseHost();
  9340. // we've indicated that there is a hostname,
  9341. // so even if it's empty, it has to be present.
  9342. this.hostname = this.hostname || '';
  9343. // if hostname begins with [ and ends with ]
  9344. // assume that it's an IPv6 address.
  9345. var ipv6Hostname = this.hostname[0] === '[' &&
  9346. this.hostname[this.hostname.length - 1] === ']';
  9347. // validate a little.
  9348. if (!ipv6Hostname) {
  9349. var hostparts = this.hostname.split(/\./);
  9350. for (var i = 0, l = hostparts.length; i < l; i++) {
  9351. var part = hostparts[i];
  9352. if (!part) continue;
  9353. if (!part.match(hostnamePartPattern)) {
  9354. var newpart = '';
  9355. for (var j = 0, k = part.length; j < k; j++) {
  9356. if (part.charCodeAt(j) > 127) {
  9357. // we replace non-ASCII char with a temporary placeholder
  9358. // we need this to make sure size of hostname is not
  9359. // broken by replacing non-ASCII by nothing
  9360. newpart += 'x';
  9361. } else {
  9362. newpart += part[j];
  9363. }
  9364. }
  9365. // we test again with ASCII char only
  9366. if (!newpart.match(hostnamePartPattern)) {
  9367. var validParts = hostparts.slice(0, i);
  9368. var notHost = hostparts.slice(i + 1);
  9369. var bit = part.match(hostnamePartStart);
  9370. if (bit) {
  9371. validParts.push(bit[1]);
  9372. notHost.unshift(bit[2]);
  9373. }
  9374. if (notHost.length) {
  9375. rest = '/' + notHost.join('.') + rest;
  9376. }
  9377. this.hostname = validParts.join('.');
  9378. break;
  9379. }
  9380. }
  9381. }
  9382. }
  9383. if (this.hostname.length > hostnameMaxLen) {
  9384. this.hostname = '';
  9385. } else {
  9386. // hostnames are always lower case.
  9387. this.hostname = this.hostname.toLowerCase();
  9388. }
  9389. if (!ipv6Hostname) {
  9390. // IDNA Support: Returns a punycoded representation of "domain".
  9391. // It only converts parts of the domain name that
  9392. // have non-ASCII characters, i.e. it doesn't matter if
  9393. // you call it with a domain that already is ASCII-only.
  9394. this.hostname = punycode.toASCII(this.hostname);
  9395. }
  9396. var p = this.port ? ':' + this.port : '';
  9397. var h = this.hostname || '';
  9398. this.host = h + p;
  9399. this.href += this.host;
  9400. // strip [ and ] from the hostname
  9401. // the host field still retains them, though
  9402. if (ipv6Hostname) {
  9403. this.hostname = this.hostname.substr(1, this.hostname.length - 2);
  9404. if (rest[0] !== '/') {
  9405. rest = '/' + rest;
  9406. }
  9407. }
  9408. }
  9409. // now rest is set to the post-host stuff.
  9410. // chop off any delim chars.
  9411. if (!unsafeProtocol[lowerProto]) {
  9412. // First, make 100% sure that any "autoEscape" chars get
  9413. // escaped, even if encodeURIComponent doesn't think they
  9414. // need to be.
  9415. for (var i = 0, l = autoEscape.length; i < l; i++) {
  9416. var ae = autoEscape[i];
  9417. if (rest.indexOf(ae) === -1)
  9418. continue;
  9419. var esc = encodeURIComponent(ae);
  9420. if (esc === ae) {
  9421. esc = escape(ae);
  9422. }
  9423. rest = rest.split(ae).join(esc);
  9424. }
  9425. }
  9426. // chop off from the tail first.
  9427. var hash = rest.indexOf('#');
  9428. if (hash !== -1) {
  9429. // got a fragment string.
  9430. this.hash = rest.substr(hash);
  9431. rest = rest.slice(0, hash);
  9432. }
  9433. var qm = rest.indexOf('?');
  9434. if (qm !== -1) {
  9435. this.search = rest.substr(qm);
  9436. this.query = rest.substr(qm + 1);
  9437. if (parseQueryString) {
  9438. this.query = querystring.parse(this.query);
  9439. }
  9440. rest = rest.slice(0, qm);
  9441. } else if (parseQueryString) {
  9442. // no query string, but parseQueryString still requested
  9443. this.search = '';
  9444. this.query = {};
  9445. }
  9446. if (rest) this.pathname = rest;
  9447. if (slashedProtocol[lowerProto] &&
  9448. this.hostname && !this.pathname) {
  9449. this.pathname = '/';
  9450. }
  9451. //to support http.request
  9452. if (this.pathname || this.search) {
  9453. var p = this.pathname || '';
  9454. var s = this.search || '';
  9455. this.path = p + s;
  9456. }
  9457. // finally, reconstruct the href based on what has been validated.
  9458. this.href = this.format();
  9459. return this;
  9460. };
  9461. // format a parsed object into a url string
  9462. function urlFormat(obj) {
  9463. // ensure it's an object, and not a string url.
  9464. // If it's an obj, this is a no-op.
  9465. // this way, you can call url_format() on strings
  9466. // to clean up potentially wonky urls.
  9467. if (util.isString(obj)) obj = urlParse(obj);
  9468. if (!(obj instanceof Url)) return Url.prototype.format.call(obj);
  9469. return obj.format();
  9470. }
  9471. Url.prototype.format = function() {
  9472. var auth = this.auth || '';
  9473. if (auth) {
  9474. auth = encodeURIComponent(auth);
  9475. auth = auth.replace(/%3A/i, ':');
  9476. auth += '@';
  9477. }
  9478. var protocol = this.protocol || '',
  9479. pathname = this.pathname || '',
  9480. hash = this.hash || '',
  9481. host = false,
  9482. query = '';
  9483. if (this.host) {
  9484. host = auth + this.host;
  9485. } else if (this.hostname) {
  9486. host = auth + (this.hostname.indexOf(':') === -1 ?
  9487. this.hostname :
  9488. '[' + this.hostname + ']');
  9489. if (this.port) {
  9490. host += ':' + this.port;
  9491. }
  9492. }
  9493. if (this.query &&
  9494. util.isObject(this.query) &&
  9495. Object.keys(this.query).length) {
  9496. query = querystring.stringify(this.query);
  9497. }
  9498. var search = this.search || (query && ('?' + query)) || '';
  9499. if (protocol && protocol.substr(-1) !== ':') protocol += ':';
  9500. // only the slashedProtocols get the //. Not mailto:, xmpp:, etc.
  9501. // unless they had them to begin with.
  9502. if (this.slashes ||
  9503. (!protocol || slashedProtocol[protocol]) && host !== false) {
  9504. host = '//' + (host || '');
  9505. if (pathname && pathname.charAt(0) !== '/') pathname = '/' + pathname;
  9506. } else if (!host) {
  9507. host = '';
  9508. }
  9509. if (hash && hash.charAt(0) !== '#') hash = '#' + hash;
  9510. if (search && search.charAt(0) !== '?') search = '?' + search;
  9511. pathname = pathname.replace(/[?#]/g, function(match) {
  9512. return encodeURIComponent(match);
  9513. });
  9514. search = search.replace('#', '%23');
  9515. return protocol + host + pathname + search + hash;
  9516. };
  9517. function urlResolve(source, relative) {
  9518. return urlParse(source, false, true).resolve(relative);
  9519. }
  9520. Url.prototype.resolve = function(relative) {
  9521. return this.resolveObject(urlParse(relative, false, true)).format();
  9522. };
  9523. function urlResolveObject(source, relative) {
  9524. if (!source) return relative;
  9525. return urlParse(source, false, true).resolveObject(relative);
  9526. }
  9527. Url.prototype.resolveObject = function(relative) {
  9528. if (util.isString(relative)) {
  9529. var rel = new Url();
  9530. rel.parse(relative, false, true);
  9531. relative = rel;
  9532. }
  9533. var result = new Url();
  9534. var tkeys = Object.keys(this);
  9535. for (var tk = 0; tk < tkeys.length; tk++) {
  9536. var tkey = tkeys[tk];
  9537. result[tkey] = this[tkey];
  9538. }
  9539. // hash is always overridden, no matter what.
  9540. // even href="" will remove it.
  9541. result.hash = relative.hash;
  9542. // if the relative url is empty, then there's nothing left to do here.
  9543. if (relative.href === '') {
  9544. result.href = result.format();
  9545. return result;
  9546. }
  9547. // hrefs like //foo/bar always cut to the protocol.
  9548. if (relative.slashes && !relative.protocol) {
  9549. // take everything except the protocol from relative
  9550. var rkeys = Object.keys(relative);
  9551. for (var rk = 0; rk < rkeys.length; rk++) {
  9552. var rkey = rkeys[rk];
  9553. if (rkey !== 'protocol')
  9554. result[rkey] = relative[rkey];
  9555. }
  9556. //urlParse appends trailing / to urls like http://www.example.com
  9557. if (slashedProtocol[result.protocol] &&
  9558. result.hostname && !result.pathname) {
  9559. result.path = result.pathname = '/';
  9560. }
  9561. result.href = result.format();
  9562. return result;
  9563. }
  9564. if (relative.protocol && relative.protocol !== result.protocol) {
  9565. // if it's a known url protocol, then changing
  9566. // the protocol does weird things
  9567. // first, if it's not file:, then we MUST have a host,
  9568. // and if there was a path
  9569. // to begin with, then we MUST have a path.
  9570. // if it is file:, then the host is dropped,
  9571. // because that's known to be hostless.
  9572. // anything else is assumed to be absolute.
  9573. if (!slashedProtocol[relative.protocol]) {
  9574. var keys = Object.keys(relative);
  9575. for (var v = 0; v < keys.length; v++) {
  9576. var k = keys[v];
  9577. result[k] = relative[k];
  9578. }
  9579. result.href = result.format();
  9580. return result;
  9581. }
  9582. result.protocol = relative.protocol;
  9583. if (!relative.host && !hostlessProtocol[relative.protocol]) {
  9584. var relPath = (relative.pathname || '').split('/');
  9585. while (relPath.length && !(relative.host = relPath.shift()));
  9586. if (!relative.host) relative.host = '';
  9587. if (!relative.hostname) relative.hostname = '';
  9588. if (relPath[0] !== '') relPath.unshift('');
  9589. if (relPath.length < 2) relPath.unshift('');
  9590. result.pathname = relPath.join('/');
  9591. } else {
  9592. result.pathname = relative.pathname;
  9593. }
  9594. result.search = relative.search;
  9595. result.query = relative.query;
  9596. result.host = relative.host || '';
  9597. result.auth = relative.auth;
  9598. result.hostname = relative.hostname || relative.host;
  9599. result.port = relative.port;
  9600. // to support http.request
  9601. if (result.pathname || result.search) {
  9602. var p = result.pathname || '';
  9603. var s = result.search || '';
  9604. result.path = p + s;
  9605. }
  9606. result.slashes = result.slashes || relative.slashes;
  9607. result.href = result.format();
  9608. return result;
  9609. }
  9610. var isSourceAbs = (result.pathname && result.pathname.charAt(0) === '/'),
  9611. isRelAbs = (
  9612. relative.host ||
  9613. relative.pathname && relative.pathname.charAt(0) === '/'
  9614. ),
  9615. mustEndAbs = (isRelAbs || isSourceAbs ||
  9616. (result.host && relative.pathname)),
  9617. removeAllDots = mustEndAbs,
  9618. srcPath = result.pathname && result.pathname.split('/') || [],
  9619. relPath = relative.pathname && relative.pathname.split('/') || [],
  9620. psychotic = result.protocol && !slashedProtocol[result.protocol];
  9621. // if the url is a non-slashed url, then relative
  9622. // links like ../.. should be able
  9623. // to crawl up to the hostname, as well. This is strange.
  9624. // result.protocol has already been set by now.
  9625. // Later on, put the first path part into the host field.
  9626. if (psychotic) {
  9627. result.hostname = '';
  9628. result.port = null;
  9629. if (result.host) {
  9630. if (srcPath[0] === '') srcPath[0] = result.host;
  9631. else srcPath.unshift(result.host);
  9632. }
  9633. result.host = '';
  9634. if (relative.protocol) {
  9635. relative.hostname = null;
  9636. relative.port = null;
  9637. if (relative.host) {
  9638. if (relPath[0] === '') relPath[0] = relative.host;
  9639. else relPath.unshift(relative.host);
  9640. }
  9641. relative.host = null;
  9642. }
  9643. mustEndAbs = mustEndAbs && (relPath[0] === '' || srcPath[0] === '');
  9644. }
  9645. if (isRelAbs) {
  9646. // it's absolute.
  9647. result.host = (relative.host || relative.host === '') ?
  9648. relative.host : result.host;
  9649. result.hostname = (relative.hostname || relative.hostname === '') ?
  9650. relative.hostname : result.hostname;
  9651. result.search = relative.search;
  9652. result.query = relative.query;
  9653. srcPath = relPath;
  9654. // fall through to the dot-handling below.
  9655. } else if (relPath.length) {
  9656. // it's relative
  9657. // throw away the existing file, and take the new path instead.
  9658. if (!srcPath) srcPath = [];
  9659. srcPath.pop();
  9660. srcPath = srcPath.concat(relPath);
  9661. result.search = relative.search;
  9662. result.query = relative.query;
  9663. } else if (!util.isNullOrUndefined(relative.search)) {
  9664. // just pull out the search.
  9665. // like href='?foo'.
  9666. // Put this after the other two cases because it simplifies the booleans
  9667. if (psychotic) {
  9668. result.hostname = result.host = srcPath.shift();
  9669. //occationaly the auth can get stuck only in host
  9670. //this especially happens in cases like
  9671. //url.resolveObject('mailto:local1@domain1', 'local2@domain2')
  9672. var authInHost = result.host && result.host.indexOf('@') > 0 ?
  9673. result.host.split('@') : false;
  9674. if (authInHost) {
  9675. result.auth = authInHost.shift();
  9676. result.host = result.hostname = authInHost.shift();
  9677. }
  9678. }
  9679. result.search = relative.search;
  9680. result.query = relative.query;
  9681. //to support http.request
  9682. if (!util.isNull(result.pathname) || !util.isNull(result.search)) {
  9683. result.path = (result.pathname ? result.pathname : '') +
  9684. (result.search ? result.search : '');
  9685. }
  9686. result.href = result.format();
  9687. return result;
  9688. }
  9689. if (!srcPath.length) {
  9690. // no path at all. easy.
  9691. // we've already handled the other stuff above.
  9692. result.pathname = null;
  9693. //to support http.request
  9694. if (result.search) {
  9695. result.path = '/' + result.search;
  9696. } else {
  9697. result.path = null;
  9698. }
  9699. result.href = result.format();
  9700. return result;
  9701. }
  9702. // if a url ENDs in . or .., then it must get a trailing slash.
  9703. // however, if it ends in anything else non-slashy,
  9704. // then it must NOT get a trailing slash.
  9705. var last = srcPath.slice(-1)[0];
  9706. var hasTrailingSlash = (
  9707. (result.host || relative.host || srcPath.length > 1) &&
  9708. (last === '.' || last === '..') || last === '');
  9709. // strip single dots, resolve double dots to parent dir
  9710. // if the path tries to go above the root, `up` ends up > 0
  9711. var up = 0;
  9712. for (var i = srcPath.length; i >= 0; i--) {
  9713. last = srcPath[i];
  9714. if (last === '.') {
  9715. srcPath.splice(i, 1);
  9716. } else if (last === '..') {
  9717. srcPath.splice(i, 1);
  9718. up++;
  9719. } else if (up) {
  9720. srcPath.splice(i, 1);
  9721. up--;
  9722. }
  9723. }
  9724. // if the path is allowed to go above the root, restore leading ..s
  9725. if (!mustEndAbs && !removeAllDots) {
  9726. for (; up--; up) {
  9727. srcPath.unshift('..');
  9728. }
  9729. }
  9730. if (mustEndAbs && srcPath[0] !== '' &&
  9731. (!srcPath[0] || srcPath[0].charAt(0) !== '/')) {
  9732. srcPath.unshift('');
  9733. }
  9734. if (hasTrailingSlash && (srcPath.join('/').substr(-1) !== '/')) {
  9735. srcPath.push('');
  9736. }
  9737. var isAbsolute = srcPath[0] === '' ||
  9738. (srcPath[0] && srcPath[0].charAt(0) === '/');
  9739. // put the host back
  9740. if (psychotic) {
  9741. result.hostname = result.host = isAbsolute ? '' :
  9742. srcPath.length ? srcPath.shift() : '';
  9743. //occationaly the auth can get stuck only in host
  9744. //this especially happens in cases like
  9745. //url.resolveObject('mailto:local1@domain1', 'local2@domain2')
  9746. var authInHost = result.host && result.host.indexOf('@') > 0 ?
  9747. result.host.split('@') : false;
  9748. if (authInHost) {
  9749. result.auth = authInHost.shift();
  9750. result.host = result.hostname = authInHost.shift();
  9751. }
  9752. }
  9753. mustEndAbs = mustEndAbs || (result.host && srcPath.length);
  9754. if (mustEndAbs && !isAbsolute) {
  9755. srcPath.unshift('');
  9756. }
  9757. if (!srcPath.length) {
  9758. result.pathname = null;
  9759. result.path = null;
  9760. } else {
  9761. result.pathname = srcPath.join('/');
  9762. }
  9763. //to support request.http
  9764. if (!util.isNull(result.pathname) || !util.isNull(result.search)) {
  9765. result.path = (result.pathname ? result.pathname : '') +
  9766. (result.search ? result.search : '');
  9767. }
  9768. result.auth = relative.auth || result.auth;
  9769. result.slashes = result.slashes || relative.slashes;
  9770. result.href = result.format();
  9771. return result;
  9772. };
  9773. Url.prototype.parseHost = function() {
  9774. var host = this.host;
  9775. var port = portPattern.exec(host);
  9776. if (port) {
  9777. port = port[0];
  9778. if (port !== ':') {
  9779. this.port = port.substr(1);
  9780. }
  9781. host = host.substr(0, host.length - port.length);
  9782. }
  9783. if (host) this.hostname = host;
  9784. };
  9785. },{"./util":38,"punycode":12,"querystring":15}],38:[function(require,module,exports){
  9786. 'use strict';
  9787. module.exports = {
  9788. isString: function(arg) {
  9789. return typeof(arg) === 'string';
  9790. },
  9791. isObject: function(arg) {
  9792. return typeof(arg) === 'object' && arg !== null;
  9793. },
  9794. isNull: function(arg) {
  9795. return arg === null;
  9796. },
  9797. isNullOrUndefined: function(arg) {
  9798. return arg == null;
  9799. }
  9800. };
  9801. },{}],39:[function(require,module,exports){
  9802. (function (global){(function (){
  9803. /**
  9804. * Module exports.
  9805. */
  9806. module.exports = deprecate;
  9807. /**
  9808. * Mark that a method should not be used.
  9809. * Returns a modified function which warns once by default.
  9810. *
  9811. * If `localStorage.noDeprecation = true` is set, then it is a no-op.
  9812. *
  9813. * If `localStorage.throwDeprecation = true` is set, then deprecated functions
  9814. * will throw an Error when invoked.
  9815. *
  9816. * If `localStorage.traceDeprecation = true` is set, then deprecated functions
  9817. * will invoke `console.trace()` instead of `console.error()`.
  9818. *
  9819. * @param {Function} fn - the function to deprecate
  9820. * @param {String} msg - the string to print to the console when `fn` is invoked
  9821. * @returns {Function} a new "deprecated" version of `fn`
  9822. * @api public
  9823. */
  9824. function deprecate (fn, msg) {
  9825. if (config('noDeprecation')) {
  9826. return fn;
  9827. }
  9828. var warned = false;
  9829. function deprecated() {
  9830. if (!warned) {
  9831. if (config('throwDeprecation')) {
  9832. throw new Error(msg);
  9833. } else if (config('traceDeprecation')) {
  9834. console.trace(msg);
  9835. } else {
  9836. console.warn(msg);
  9837. }
  9838. warned = true;
  9839. }
  9840. return fn.apply(this, arguments);
  9841. }
  9842. return deprecated;
  9843. }
  9844. /**
  9845. * Checks `localStorage` for boolean values for the given `name`.
  9846. *
  9847. * @param {String} name
  9848. * @returns {Boolean}
  9849. * @api private
  9850. */
  9851. function config (name) {
  9852. // accessing global.localStorage can trigger a DOMException in sandboxed iframes
  9853. try {
  9854. if (!global.localStorage) return false;
  9855. } catch (_) {
  9856. return false;
  9857. }
  9858. var val = global.localStorage[name];
  9859. if (null == val) return false;
  9860. return String(val).toLowerCase() === 'true';
  9861. }
  9862. }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  9863. },{}],40:[function(require,module,exports){
  9864. "use strict";
  9865. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  9866. Object.defineProperty(exports, "__esModule", {
  9867. value: true
  9868. });
  9869. exports.default = void 0;
  9870. var _toDate = _interopRequireDefault(require("./lib/toDate"));
  9871. var _toFloat = _interopRequireDefault(require("./lib/toFloat"));
  9872. var _toInt = _interopRequireDefault(require("./lib/toInt"));
  9873. var _toBoolean = _interopRequireDefault(require("./lib/toBoolean"));
  9874. var _equals = _interopRequireDefault(require("./lib/equals"));
  9875. var _contains = _interopRequireDefault(require("./lib/contains"));
  9876. var _matches = _interopRequireDefault(require("./lib/matches"));
  9877. var _isEmail = _interopRequireDefault(require("./lib/isEmail"));
  9878. var _isURL = _interopRequireDefault(require("./lib/isURL"));
  9879. var _isMACAddress = _interopRequireDefault(require("./lib/isMACAddress"));
  9880. var _isIP = _interopRequireDefault(require("./lib/isIP"));
  9881. var _isIPRange = _interopRequireDefault(require("./lib/isIPRange"));
  9882. var _isFQDN = _interopRequireDefault(require("./lib/isFQDN"));
  9883. var _isDate = _interopRequireDefault(require("./lib/isDate"));
  9884. var _isBoolean = _interopRequireDefault(require("./lib/isBoolean"));
  9885. var _isLocale = _interopRequireDefault(require("./lib/isLocale"));
  9886. var _isAlpha = _interopRequireWildcard(require("./lib/isAlpha"));
  9887. var _isAlphanumeric = _interopRequireWildcard(require("./lib/isAlphanumeric"));
  9888. var _isNumeric = _interopRequireDefault(require("./lib/isNumeric"));
  9889. var _isPassportNumber = _interopRequireDefault(require("./lib/isPassportNumber"));
  9890. var _isPort = _interopRequireDefault(require("./lib/isPort"));
  9891. var _isLowercase = _interopRequireDefault(require("./lib/isLowercase"));
  9892. var _isUppercase = _interopRequireDefault(require("./lib/isUppercase"));
  9893. var _isIMEI = _interopRequireDefault(require("./lib/isIMEI"));
  9894. var _isAscii = _interopRequireDefault(require("./lib/isAscii"));
  9895. var _isFullWidth = _interopRequireDefault(require("./lib/isFullWidth"));
  9896. var _isHalfWidth = _interopRequireDefault(require("./lib/isHalfWidth"));
  9897. var _isVariableWidth = _interopRequireDefault(require("./lib/isVariableWidth"));
  9898. var _isMultibyte = _interopRequireDefault(require("./lib/isMultibyte"));
  9899. var _isSemVer = _interopRequireDefault(require("./lib/isSemVer"));
  9900. var _isSurrogatePair = _interopRequireDefault(require("./lib/isSurrogatePair"));
  9901. var _isInt = _interopRequireDefault(require("./lib/isInt"));
  9902. var _isFloat = _interopRequireWildcard(require("./lib/isFloat"));
  9903. var _isDecimal = _interopRequireDefault(require("./lib/isDecimal"));
  9904. var _isHexadecimal = _interopRequireDefault(require("./lib/isHexadecimal"));
  9905. var _isOctal = _interopRequireDefault(require("./lib/isOctal"));
  9906. var _isDivisibleBy = _interopRequireDefault(require("./lib/isDivisibleBy"));
  9907. var _isHexColor = _interopRequireDefault(require("./lib/isHexColor"));
  9908. var _isRgbColor = _interopRequireDefault(require("./lib/isRgbColor"));
  9909. var _isHSL = _interopRequireDefault(require("./lib/isHSL"));
  9910. var _isISRC = _interopRequireDefault(require("./lib/isISRC"));
  9911. var _isIBAN = _interopRequireWildcard(require("./lib/isIBAN"));
  9912. var _isBIC = _interopRequireDefault(require("./lib/isBIC"));
  9913. var _isMD = _interopRequireDefault(require("./lib/isMD5"));
  9914. var _isHash = _interopRequireDefault(require("./lib/isHash"));
  9915. var _isJWT = _interopRequireDefault(require("./lib/isJWT"));
  9916. var _isJSON = _interopRequireDefault(require("./lib/isJSON"));
  9917. var _isEmpty = _interopRequireDefault(require("./lib/isEmpty"));
  9918. var _isLength = _interopRequireDefault(require("./lib/isLength"));
  9919. var _isByteLength = _interopRequireDefault(require("./lib/isByteLength"));
  9920. var _isUUID = _interopRequireDefault(require("./lib/isUUID"));
  9921. var _isMongoId = _interopRequireDefault(require("./lib/isMongoId"));
  9922. var _isAfter = _interopRequireDefault(require("./lib/isAfter"));
  9923. var _isBefore = _interopRequireDefault(require("./lib/isBefore"));
  9924. var _isIn = _interopRequireDefault(require("./lib/isIn"));
  9925. var _isCreditCard = _interopRequireDefault(require("./lib/isCreditCard"));
  9926. var _isIdentityCard = _interopRequireDefault(require("./lib/isIdentityCard"));
  9927. var _isEAN = _interopRequireDefault(require("./lib/isEAN"));
  9928. var _isISIN = _interopRequireDefault(require("./lib/isISIN"));
  9929. var _isISBN = _interopRequireDefault(require("./lib/isISBN"));
  9930. var _isISSN = _interopRequireDefault(require("./lib/isISSN"));
  9931. var _isTaxID = _interopRequireDefault(require("./lib/isTaxID"));
  9932. var _isMobilePhone = _interopRequireWildcard(require("./lib/isMobilePhone"));
  9933. var _isEthereumAddress = _interopRequireDefault(require("./lib/isEthereumAddress"));
  9934. var _isCurrency = _interopRequireDefault(require("./lib/isCurrency"));
  9935. var _isBtcAddress = _interopRequireDefault(require("./lib/isBtcAddress"));
  9936. var _isISO = _interopRequireDefault(require("./lib/isISO8601"));
  9937. var _isRFC = _interopRequireDefault(require("./lib/isRFC3339"));
  9938. var _isISO31661Alpha = _interopRequireDefault(require("./lib/isISO31661Alpha2"));
  9939. var _isISO31661Alpha2 = _interopRequireDefault(require("./lib/isISO31661Alpha3"));
  9940. var _isISO2 = _interopRequireDefault(require("./lib/isISO4217"));
  9941. var _isBase = _interopRequireDefault(require("./lib/isBase32"));
  9942. var _isBase2 = _interopRequireDefault(require("./lib/isBase58"));
  9943. var _isBase3 = _interopRequireDefault(require("./lib/isBase64"));
  9944. var _isDataURI = _interopRequireDefault(require("./lib/isDataURI"));
  9945. var _isMagnetURI = _interopRequireDefault(require("./lib/isMagnetURI"));
  9946. var _isMimeType = _interopRequireDefault(require("./lib/isMimeType"));
  9947. var _isLatLong = _interopRequireDefault(require("./lib/isLatLong"));
  9948. var _isPostalCode = _interopRequireWildcard(require("./lib/isPostalCode"));
  9949. var _ltrim = _interopRequireDefault(require("./lib/ltrim"));
  9950. var _rtrim = _interopRequireDefault(require("./lib/rtrim"));
  9951. var _trim = _interopRequireDefault(require("./lib/trim"));
  9952. var _escape = _interopRequireDefault(require("./lib/escape"));
  9953. var _unescape = _interopRequireDefault(require("./lib/unescape"));
  9954. var _stripLow = _interopRequireDefault(require("./lib/stripLow"));
  9955. var _whitelist = _interopRequireDefault(require("./lib/whitelist"));
  9956. var _blacklist = _interopRequireDefault(require("./lib/blacklist"));
  9957. var _isWhitelisted = _interopRequireDefault(require("./lib/isWhitelisted"));
  9958. var _normalizeEmail = _interopRequireDefault(require("./lib/normalizeEmail"));
  9959. var _isSlug = _interopRequireDefault(require("./lib/isSlug"));
  9960. var _isLicensePlate = _interopRequireDefault(require("./lib/isLicensePlate"));
  9961. var _isStrongPassword = _interopRequireDefault(require("./lib/isStrongPassword"));
  9962. var _isVAT = _interopRequireDefault(require("./lib/isVAT"));
  9963. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
  9964. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  9965. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  9966. var version = '13.7.0';
  9967. var validator = {
  9968. version: version,
  9969. toDate: _toDate.default,
  9970. toFloat: _toFloat.default,
  9971. toInt: _toInt.default,
  9972. toBoolean: _toBoolean.default,
  9973. equals: _equals.default,
  9974. contains: _contains.default,
  9975. matches: _matches.default,
  9976. isEmail: _isEmail.default,
  9977. isURL: _isURL.default,
  9978. isMACAddress: _isMACAddress.default,
  9979. isIP: _isIP.default,
  9980. isIPRange: _isIPRange.default,
  9981. isFQDN: _isFQDN.default,
  9982. isBoolean: _isBoolean.default,
  9983. isIBAN: _isIBAN.default,
  9984. isBIC: _isBIC.default,
  9985. isAlpha: _isAlpha.default,
  9986. isAlphaLocales: _isAlpha.locales,
  9987. isAlphanumeric: _isAlphanumeric.default,
  9988. isAlphanumericLocales: _isAlphanumeric.locales,
  9989. isNumeric: _isNumeric.default,
  9990. isPassportNumber: _isPassportNumber.default,
  9991. isPort: _isPort.default,
  9992. isLowercase: _isLowercase.default,
  9993. isUppercase: _isUppercase.default,
  9994. isAscii: _isAscii.default,
  9995. isFullWidth: _isFullWidth.default,
  9996. isHalfWidth: _isHalfWidth.default,
  9997. isVariableWidth: _isVariableWidth.default,
  9998. isMultibyte: _isMultibyte.default,
  9999. isSemVer: _isSemVer.default,
  10000. isSurrogatePair: _isSurrogatePair.default,
  10001. isInt: _isInt.default,
  10002. isIMEI: _isIMEI.default,
  10003. isFloat: _isFloat.default,
  10004. isFloatLocales: _isFloat.locales,
  10005. isDecimal: _isDecimal.default,
  10006. isHexadecimal: _isHexadecimal.default,
  10007. isOctal: _isOctal.default,
  10008. isDivisibleBy: _isDivisibleBy.default,
  10009. isHexColor: _isHexColor.default,
  10010. isRgbColor: _isRgbColor.default,
  10011. isHSL: _isHSL.default,
  10012. isISRC: _isISRC.default,
  10013. isMD5: _isMD.default,
  10014. isHash: _isHash.default,
  10015. isJWT: _isJWT.default,
  10016. isJSON: _isJSON.default,
  10017. isEmpty: _isEmpty.default,
  10018. isLength: _isLength.default,
  10019. isLocale: _isLocale.default,
  10020. isByteLength: _isByteLength.default,
  10021. isUUID: _isUUID.default,
  10022. isMongoId: _isMongoId.default,
  10023. isAfter: _isAfter.default,
  10024. isBefore: _isBefore.default,
  10025. isIn: _isIn.default,
  10026. isCreditCard: _isCreditCard.default,
  10027. isIdentityCard: _isIdentityCard.default,
  10028. isEAN: _isEAN.default,
  10029. isISIN: _isISIN.default,
  10030. isISBN: _isISBN.default,
  10031. isISSN: _isISSN.default,
  10032. isMobilePhone: _isMobilePhone.default,
  10033. isMobilePhoneLocales: _isMobilePhone.locales,
  10034. isPostalCode: _isPostalCode.default,
  10035. isPostalCodeLocales: _isPostalCode.locales,
  10036. isEthereumAddress: _isEthereumAddress.default,
  10037. isCurrency: _isCurrency.default,
  10038. isBtcAddress: _isBtcAddress.default,
  10039. isISO8601: _isISO.default,
  10040. isRFC3339: _isRFC.default,
  10041. isISO31661Alpha2: _isISO31661Alpha.default,
  10042. isISO31661Alpha3: _isISO31661Alpha2.default,
  10043. isISO4217: _isISO2.default,
  10044. isBase32: _isBase.default,
  10045. isBase58: _isBase2.default,
  10046. isBase64: _isBase3.default,
  10047. isDataURI: _isDataURI.default,
  10048. isMagnetURI: _isMagnetURI.default,
  10049. isMimeType: _isMimeType.default,
  10050. isLatLong: _isLatLong.default,
  10051. ltrim: _ltrim.default,
  10052. rtrim: _rtrim.default,
  10053. trim: _trim.default,
  10054. escape: _escape.default,
  10055. unescape: _unescape.default,
  10056. stripLow: _stripLow.default,
  10057. whitelist: _whitelist.default,
  10058. blacklist: _blacklist.default,
  10059. isWhitelisted: _isWhitelisted.default,
  10060. normalizeEmail: _normalizeEmail.default,
  10061. toString: toString,
  10062. isSlug: _isSlug.default,
  10063. isStrongPassword: _isStrongPassword.default,
  10064. isTaxID: _isTaxID.default,
  10065. isDate: _isDate.default,
  10066. isLicensePlate: _isLicensePlate.default,
  10067. isVAT: _isVAT.default,
  10068. ibanLocales: _isIBAN.locales
  10069. };
  10070. var _default = validator;
  10071. exports.default = _default;
  10072. module.exports = exports.default;
  10073. module.exports.default = exports.default;
  10074. },{"./lib/blacklist":42,"./lib/contains":43,"./lib/equals":44,"./lib/escape":45,"./lib/isAfter":46,"./lib/isAlpha":47,"./lib/isAlphanumeric":48,"./lib/isAscii":49,"./lib/isBIC":50,"./lib/isBase32":51,"./lib/isBase58":52,"./lib/isBase64":53,"./lib/isBefore":54,"./lib/isBoolean":55,"./lib/isBtcAddress":56,"./lib/isByteLength":57,"./lib/isCreditCard":58,"./lib/isCurrency":59,"./lib/isDataURI":60,"./lib/isDate":61,"./lib/isDecimal":62,"./lib/isDivisibleBy":63,"./lib/isEAN":64,"./lib/isEmail":65,"./lib/isEmpty":66,"./lib/isEthereumAddress":67,"./lib/isFQDN":68,"./lib/isFloat":69,"./lib/isFullWidth":70,"./lib/isHSL":71,"./lib/isHalfWidth":72,"./lib/isHash":73,"./lib/isHexColor":74,"./lib/isHexadecimal":75,"./lib/isIBAN":76,"./lib/isIMEI":77,"./lib/isIP":78,"./lib/isIPRange":79,"./lib/isISBN":80,"./lib/isISIN":81,"./lib/isISO31661Alpha2":82,"./lib/isISO31661Alpha3":83,"./lib/isISO4217":84,"./lib/isISO8601":85,"./lib/isISRC":86,"./lib/isISSN":87,"./lib/isIdentityCard":88,"./lib/isIn":89,"./lib/isInt":90,"./lib/isJSON":91,"./lib/isJWT":92,"./lib/isLatLong":93,"./lib/isLength":94,"./lib/isLicensePlate":95,"./lib/isLocale":96,"./lib/isLowercase":97,"./lib/isMACAddress":98,"./lib/isMD5":99,"./lib/isMagnetURI":100,"./lib/isMimeType":101,"./lib/isMobilePhone":102,"./lib/isMongoId":103,"./lib/isMultibyte":104,"./lib/isNumeric":105,"./lib/isOctal":106,"./lib/isPassportNumber":107,"./lib/isPort":108,"./lib/isPostalCode":109,"./lib/isRFC3339":110,"./lib/isRgbColor":111,"./lib/isSemVer":112,"./lib/isSlug":113,"./lib/isStrongPassword":114,"./lib/isSurrogatePair":115,"./lib/isTaxID":116,"./lib/isURL":117,"./lib/isUUID":118,"./lib/isUppercase":119,"./lib/isVAT":120,"./lib/isVariableWidth":121,"./lib/isWhitelisted":122,"./lib/ltrim":123,"./lib/matches":124,"./lib/normalizeEmail":125,"./lib/rtrim":126,"./lib/stripLow":127,"./lib/toBoolean":128,"./lib/toDate":129,"./lib/toFloat":130,"./lib/toInt":131,"./lib/trim":132,"./lib/unescape":133,"./lib/whitelist":140}],41:[function(require,module,exports){
  10075. "use strict";
  10076. Object.defineProperty(exports, "__esModule", {
  10077. value: true
  10078. });
  10079. exports.commaDecimal = exports.dotDecimal = exports.farsiLocales = exports.arabicLocales = exports.englishLocales = exports.decimal = exports.alphanumeric = exports.alpha = void 0;
  10080. var alpha = {
  10081. 'en-US': /^[A-Z]+$/i,
  10082. 'az-AZ': /^[A-VXYZÇƏĞİıÖŞÜ]+$/i,
  10083. 'bg-BG': /^[А-Я]+$/i,
  10084. 'cs-CZ': /^[A-ZÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ]+$/i,
  10085. 'da-DK': /^[A-ZÆØÅ]+$/i,
  10086. 'de-DE': /^[A-ZÄÖÜß]+$/i,
  10087. 'el-GR': /^[Α-ώ]+$/i,
  10088. 'es-ES': /^[A-ZÁÉÍÑÓÚÜ]+$/i,
  10089. 'fa-IR': /^[ابپتثجچحخدذرزژسشصضطظعغفقکگلمنوهی]+$/i,
  10090. 'fi-FI': /^[A-ZÅÄÖ]+$/i,
  10091. 'fr-FR': /^[A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i,
  10092. 'it-IT': /^[A-ZÀÉÈÌÎÓÒÙ]+$/i,
  10093. 'nb-NO': /^[A-ZÆØÅ]+$/i,
  10094. 'nl-NL': /^[A-ZÁÉËÏÓÖÜÚ]+$/i,
  10095. 'nn-NO': /^[A-ZÆØÅ]+$/i,
  10096. 'hu-HU': /^[A-ZÁÉÍÓÖŐÚÜŰ]+$/i,
  10097. 'pl-PL': /^[A-ZĄĆĘŚŁŃÓŻŹ]+$/i,
  10098. 'pt-PT': /^[A-ZÃÁÀÂÄÇÉÊËÍÏÕÓÔÖÚÜ]+$/i,
  10099. 'ru-RU': /^[А-ЯЁ]+$/i,
  10100. 'sl-SI': /^[A-ZČĆĐŠŽ]+$/i,
  10101. 'sk-SK': /^[A-ZÁČĎÉÍŇÓŠŤÚÝŽĹŔĽÄÔ]+$/i,
  10102. 'sr-RS@latin': /^[A-ZČĆŽŠĐ]+$/i,
  10103. 'sr-RS': /^[А-ЯЂЈЉЊЋЏ]+$/i,
  10104. 'sv-SE': /^[A-ZÅÄÖ]+$/i,
  10105. 'th-TH': /^[ก-๐\s]+$/i,
  10106. 'tr-TR': /^[A-ZÇĞİıÖŞÜ]+$/i,
  10107. 'uk-UA': /^[А-ЩЬЮЯЄIЇҐі]+$/i,
  10108. 'vi-VN': /^[A-ZÀÁẠẢÃÂẦẤẬẨẪĂẰẮẶẲẴĐÈÉẸẺẼÊỀẾỆỂỄÌÍỊỈĨÒÓỌỎÕÔỒỐỘỔỖƠỜỚỢỞỠÙÚỤỦŨƯỪỨỰỬỮỲÝỴỶỸ]+$/i,
  10109. 'ku-IQ': /^[ئابپتجچحخدرڕزژسشعغفڤقکگلڵمنوۆھەیێيطؤثآإأكضصةظذ]+$/i,
  10110. ar: /^[ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/,
  10111. he: /^[א-ת]+$/,
  10112. fa: /^['آاءأؤئبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهةی']+$/i,
  10113. 'hi-IN': /^[\u0900-\u0961]+[\u0972-\u097F]*$/i
  10114. };
  10115. exports.alpha = alpha;
  10116. var alphanumeric = {
  10117. 'en-US': /^[0-9A-Z]+$/i,
  10118. 'az-AZ': /^[0-9A-VXYZÇƏĞİıÖŞÜ]+$/i,
  10119. 'bg-BG': /^[0-9А-Я]+$/i,
  10120. 'cs-CZ': /^[0-9A-ZÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ]+$/i,
  10121. 'da-DK': /^[0-9A-ZÆØÅ]+$/i,
  10122. 'de-DE': /^[0-9A-ZÄÖÜß]+$/i,
  10123. 'el-GR': /^[0-9Α-ω]+$/i,
  10124. 'es-ES': /^[0-9A-ZÁÉÍÑÓÚÜ]+$/i,
  10125. 'fi-FI': /^[0-9A-ZÅÄÖ]+$/i,
  10126. 'fr-FR': /^[0-9A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i,
  10127. 'it-IT': /^[0-9A-ZÀÉÈÌÎÓÒÙ]+$/i,
  10128. 'hu-HU': /^[0-9A-ZÁÉÍÓÖŐÚÜŰ]+$/i,
  10129. 'nb-NO': /^[0-9A-ZÆØÅ]+$/i,
  10130. 'nl-NL': /^[0-9A-ZÁÉËÏÓÖÜÚ]+$/i,
  10131. 'nn-NO': /^[0-9A-ZÆØÅ]+$/i,
  10132. 'pl-PL': /^[0-9A-ZĄĆĘŚŁŃÓŻŹ]+$/i,
  10133. 'pt-PT': /^[0-9A-ZÃÁÀÂÄÇÉÊËÍÏÕÓÔÖÚÜ]+$/i,
  10134. 'ru-RU': /^[0-9А-ЯЁ]+$/i,
  10135. 'sl-SI': /^[0-9A-ZČĆĐŠŽ]+$/i,
  10136. 'sk-SK': /^[0-9A-ZÁČĎÉÍŇÓŠŤÚÝŽĹŔĽÄÔ]+$/i,
  10137. 'sr-RS@latin': /^[0-9A-ZČĆŽŠĐ]+$/i,
  10138. 'sr-RS': /^[0-9А-ЯЂЈЉЊЋЏ]+$/i,
  10139. 'sv-SE': /^[0-9A-ZÅÄÖ]+$/i,
  10140. 'th-TH': /^[ก-๙\s]+$/i,
  10141. 'tr-TR': /^[0-9A-ZÇĞİıÖŞÜ]+$/i,
  10142. 'uk-UA': /^[0-9А-ЩЬЮЯЄIЇҐі]+$/i,
  10143. 'ku-IQ': /^[٠١٢٣٤٥٦٧٨٩0-9ئابپتجچحخدرڕزژسشعغفڤقکگلڵمنوۆھەیێيطؤثآإأكضصةظذ]+$/i,
  10144. 'vi-VN': /^[0-9A-ZÀÁẠẢÃÂẦẤẬẨẪĂẰẮẶẲẴĐÈÉẸẺẼÊỀẾỆỂỄÌÍỊỈĨÒÓỌỎÕÔỒỐỘỔỖƠỜỚỢỞỠÙÚỤỦŨƯỪỨỰỬỮỲÝỴỶỸ]+$/i,
  10145. ar: /^[٠١٢٣٤٥٦٧٨٩0-9ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/,
  10146. he: /^[0-9א-ת]+$/,
  10147. fa: /^['0-9آاءأؤئبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهةی۱۲۳۴۵۶۷۸۹۰']+$/i,
  10148. 'hi-IN': /^[\u0900-\u0963]+[\u0966-\u097F]*$/i
  10149. };
  10150. exports.alphanumeric = alphanumeric;
  10151. var decimal = {
  10152. 'en-US': '.',
  10153. ar: '٫'
  10154. };
  10155. exports.decimal = decimal;
  10156. var englishLocales = ['AU', 'GB', 'HK', 'IN', 'NZ', 'ZA', 'ZM'];
  10157. exports.englishLocales = englishLocales;
  10158. for (var locale, i = 0; i < englishLocales.length; i++) {
  10159. locale = "en-".concat(englishLocales[i]);
  10160. alpha[locale] = alpha['en-US'];
  10161. alphanumeric[locale] = alphanumeric['en-US'];
  10162. decimal[locale] = decimal['en-US'];
  10163. } // Source: http://www.localeplanet.com/java/
  10164. var arabicLocales = ['AE', 'BH', 'DZ', 'EG', 'IQ', 'JO', 'KW', 'LB', 'LY', 'MA', 'QM', 'QA', 'SA', 'SD', 'SY', 'TN', 'YE'];
  10165. exports.arabicLocales = arabicLocales;
  10166. for (var _locale, _i = 0; _i < arabicLocales.length; _i++) {
  10167. _locale = "ar-".concat(arabicLocales[_i]);
  10168. alpha[_locale] = alpha.ar;
  10169. alphanumeric[_locale] = alphanumeric.ar;
  10170. decimal[_locale] = decimal.ar;
  10171. }
  10172. var farsiLocales = ['IR', 'AF'];
  10173. exports.farsiLocales = farsiLocales;
  10174. for (var _locale2, _i2 = 0; _i2 < farsiLocales.length; _i2++) {
  10175. _locale2 = "fa-".concat(farsiLocales[_i2]);
  10176. alphanumeric[_locale2] = alphanumeric.fa;
  10177. decimal[_locale2] = decimal.ar;
  10178. } // Source: https://en.wikipedia.org/wiki/Decimal_mark
  10179. var dotDecimal = ['ar-EG', 'ar-LB', 'ar-LY'];
  10180. exports.dotDecimal = dotDecimal;
  10181. var commaDecimal = ['bg-BG', 'cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'en-ZM', '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', 'sl-SI', 'sr-RS@latin', 'sr-RS', 'sv-SE', 'tr-TR', 'uk-UA', 'vi-VN'];
  10182. exports.commaDecimal = commaDecimal;
  10183. for (var _i3 = 0; _i3 < dotDecimal.length; _i3++) {
  10184. decimal[dotDecimal[_i3]] = decimal['en-US'];
  10185. }
  10186. for (var _i4 = 0; _i4 < commaDecimal.length; _i4++) {
  10187. decimal[commaDecimal[_i4]] = ',';
  10188. }
  10189. alpha['fr-CA'] = alpha['fr-FR'];
  10190. alphanumeric['fr-CA'] = alphanumeric['fr-FR'];
  10191. alpha['pt-BR'] = alpha['pt-PT'];
  10192. alphanumeric['pt-BR'] = alphanumeric['pt-PT'];
  10193. decimal['pt-BR'] = decimal['pt-PT']; // see #862
  10194. alpha['pl-Pl'] = alpha['pl-PL'];
  10195. alphanumeric['pl-Pl'] = alphanumeric['pl-PL'];
  10196. decimal['pl-Pl'] = decimal['pl-PL']; // see #1455
  10197. alpha['fa-AF'] = alpha.fa;
  10198. },{}],42:[function(require,module,exports){
  10199. "use strict";
  10200. Object.defineProperty(exports, "__esModule", {
  10201. value: true
  10202. });
  10203. exports.default = blacklist;
  10204. var _assertString = _interopRequireDefault(require("./util/assertString"));
  10205. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10206. function blacklist(str, chars) {
  10207. (0, _assertString.default)(str);
  10208. return str.replace(new RegExp("[".concat(chars, "]+"), 'g'), '');
  10209. }
  10210. module.exports = exports.default;
  10211. module.exports.default = exports.default;
  10212. },{"./util/assertString":135}],43:[function(require,module,exports){
  10213. "use strict";
  10214. Object.defineProperty(exports, "__esModule", {
  10215. value: true
  10216. });
  10217. exports.default = contains;
  10218. var _assertString = _interopRequireDefault(require("./util/assertString"));
  10219. var _toString = _interopRequireDefault(require("./util/toString"));
  10220. var _merge = _interopRequireDefault(require("./util/merge"));
  10221. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10222. var defaulContainsOptions = {
  10223. ignoreCase: false,
  10224. minOccurrences: 1
  10225. };
  10226. function contains(str, elem, options) {
  10227. (0, _assertString.default)(str);
  10228. options = (0, _merge.default)(options, defaulContainsOptions);
  10229. if (options.ignoreCase) {
  10230. return str.toLowerCase().split((0, _toString.default)(elem).toLowerCase()).length > options.minOccurrences;
  10231. }
  10232. return str.split((0, _toString.default)(elem)).length > options.minOccurrences;
  10233. }
  10234. module.exports = exports.default;
  10235. module.exports.default = exports.default;
  10236. },{"./util/assertString":135,"./util/merge":137,"./util/toString":139}],44:[function(require,module,exports){
  10237. "use strict";
  10238. Object.defineProperty(exports, "__esModule", {
  10239. value: true
  10240. });
  10241. exports.default = equals;
  10242. var _assertString = _interopRequireDefault(require("./util/assertString"));
  10243. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10244. function equals(str, comparison) {
  10245. (0, _assertString.default)(str);
  10246. return str === comparison;
  10247. }
  10248. module.exports = exports.default;
  10249. module.exports.default = exports.default;
  10250. },{"./util/assertString":135}],45:[function(require,module,exports){
  10251. "use strict";
  10252. Object.defineProperty(exports, "__esModule", {
  10253. value: true
  10254. });
  10255. exports.default = escape;
  10256. var _assertString = _interopRequireDefault(require("./util/assertString"));
  10257. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10258. function escape(str) {
  10259. (0, _assertString.default)(str);
  10260. 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;');
  10261. }
  10262. module.exports = exports.default;
  10263. module.exports.default = exports.default;
  10264. },{"./util/assertString":135}],46:[function(require,module,exports){
  10265. "use strict";
  10266. Object.defineProperty(exports, "__esModule", {
  10267. value: true
  10268. });
  10269. exports.default = isAfter;
  10270. var _assertString = _interopRequireDefault(require("./util/assertString"));
  10271. var _toDate = _interopRequireDefault(require("./toDate"));
  10272. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10273. function isAfter(str) {
  10274. var date = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : String(new Date());
  10275. (0, _assertString.default)(str);
  10276. var comparison = (0, _toDate.default)(date);
  10277. var original = (0, _toDate.default)(str);
  10278. return !!(original && comparison && original > comparison);
  10279. }
  10280. module.exports = exports.default;
  10281. module.exports.default = exports.default;
  10282. },{"./toDate":129,"./util/assertString":135}],47:[function(require,module,exports){
  10283. "use strict";
  10284. Object.defineProperty(exports, "__esModule", {
  10285. value: true
  10286. });
  10287. exports.default = isAlpha;
  10288. exports.locales = void 0;
  10289. var _assertString = _interopRequireDefault(require("./util/assertString"));
  10290. var _alpha = require("./alpha");
  10291. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10292. function isAlpha(_str) {
  10293. var locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'en-US';
  10294. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  10295. (0, _assertString.default)(_str);
  10296. var str = _str;
  10297. var ignore = options.ignore;
  10298. if (ignore) {
  10299. if (ignore instanceof RegExp) {
  10300. str = str.replace(ignore, '');
  10301. } else if (typeof ignore === 'string') {
  10302. str = str.replace(new RegExp("[".concat(ignore.replace(/[-[\]{}()*+?.,\\^$|#\\s]/g, '\\$&'), "]"), 'g'), ''); // escape regex for ignore
  10303. } else {
  10304. throw new Error('ignore should be instance of a String or RegExp');
  10305. }
  10306. }
  10307. if (locale in _alpha.alpha) {
  10308. return _alpha.alpha[locale].test(str);
  10309. }
  10310. throw new Error("Invalid locale '".concat(locale, "'"));
  10311. }
  10312. var locales = Object.keys(_alpha.alpha);
  10313. exports.locales = locales;
  10314. },{"./alpha":41,"./util/assertString":135}],48:[function(require,module,exports){
  10315. "use strict";
  10316. Object.defineProperty(exports, "__esModule", {
  10317. value: true
  10318. });
  10319. exports.default = isAlphanumeric;
  10320. exports.locales = void 0;
  10321. var _assertString = _interopRequireDefault(require("./util/assertString"));
  10322. var _alpha = require("./alpha");
  10323. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10324. function isAlphanumeric(_str) {
  10325. var locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'en-US';
  10326. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  10327. (0, _assertString.default)(_str);
  10328. var str = _str;
  10329. var ignore = options.ignore;
  10330. if (ignore) {
  10331. if (ignore instanceof RegExp) {
  10332. str = str.replace(ignore, '');
  10333. } else if (typeof ignore === 'string') {
  10334. str = str.replace(new RegExp("[".concat(ignore.replace(/[-[\]{}()*+?.,\\^$|#\\s]/g, '\\$&'), "]"), 'g'), ''); // escape regex for ignore
  10335. } else {
  10336. throw new Error('ignore should be instance of a String or RegExp');
  10337. }
  10338. }
  10339. if (locale in _alpha.alphanumeric) {
  10340. return _alpha.alphanumeric[locale].test(str);
  10341. }
  10342. throw new Error("Invalid locale '".concat(locale, "'"));
  10343. }
  10344. var locales = Object.keys(_alpha.alphanumeric);
  10345. exports.locales = locales;
  10346. },{"./alpha":41,"./util/assertString":135}],49:[function(require,module,exports){
  10347. "use strict";
  10348. Object.defineProperty(exports, "__esModule", {
  10349. value: true
  10350. });
  10351. exports.default = isAscii;
  10352. var _assertString = _interopRequireDefault(require("./util/assertString"));
  10353. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10354. /* eslint-disable no-control-regex */
  10355. var ascii = /^[\x00-\x7F]+$/;
  10356. /* eslint-enable no-control-regex */
  10357. function isAscii(str) {
  10358. (0, _assertString.default)(str);
  10359. return ascii.test(str);
  10360. }
  10361. module.exports = exports.default;
  10362. module.exports.default = exports.default;
  10363. },{"./util/assertString":135}],50:[function(require,module,exports){
  10364. "use strict";
  10365. Object.defineProperty(exports, "__esModule", {
  10366. value: true
  10367. });
  10368. exports.default = isBIC;
  10369. var _assertString = _interopRequireDefault(require("./util/assertString"));
  10370. var _isISO31661Alpha = require("./isISO31661Alpha2");
  10371. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10372. // https://en.wikipedia.org/wiki/ISO_9362
  10373. var isBICReg = /^[A-Za-z]{6}[A-Za-z0-9]{2}([A-Za-z0-9]{3})?$/;
  10374. function isBIC(str) {
  10375. (0, _assertString.default)(str); // toUpperCase() should be removed when a new major version goes out that changes
  10376. // the regex to [A-Z] (per the spec).
  10377. if (!_isISO31661Alpha.CountryCodes.has(str.slice(4, 6).toUpperCase())) {
  10378. return false;
  10379. }
  10380. return isBICReg.test(str);
  10381. }
  10382. module.exports = exports.default;
  10383. module.exports.default = exports.default;
  10384. },{"./isISO31661Alpha2":82,"./util/assertString":135}],51:[function(require,module,exports){
  10385. "use strict";
  10386. Object.defineProperty(exports, "__esModule", {
  10387. value: true
  10388. });
  10389. exports.default = isBase32;
  10390. var _assertString = _interopRequireDefault(require("./util/assertString"));
  10391. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10392. var base32 = /^[A-Z2-7]+=*$/;
  10393. function isBase32(str) {
  10394. (0, _assertString.default)(str);
  10395. var len = str.length;
  10396. if (len % 8 === 0 && base32.test(str)) {
  10397. return true;
  10398. }
  10399. return false;
  10400. }
  10401. module.exports = exports.default;
  10402. module.exports.default = exports.default;
  10403. },{"./util/assertString":135}],52:[function(require,module,exports){
  10404. "use strict";
  10405. Object.defineProperty(exports, "__esModule", {
  10406. value: true
  10407. });
  10408. exports.default = isBase58;
  10409. var _assertString = _interopRequireDefault(require("./util/assertString"));
  10410. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10411. // Accepted chars - 123456789ABCDEFGH JKLMN PQRSTUVWXYZabcdefghijk mnopqrstuvwxyz
  10412. var base58Reg = /^[A-HJ-NP-Za-km-z1-9]*$/;
  10413. function isBase58(str) {
  10414. (0, _assertString.default)(str);
  10415. if (base58Reg.test(str)) {
  10416. return true;
  10417. }
  10418. return false;
  10419. }
  10420. module.exports = exports.default;
  10421. module.exports.default = exports.default;
  10422. },{"./util/assertString":135}],53:[function(require,module,exports){
  10423. "use strict";
  10424. Object.defineProperty(exports, "__esModule", {
  10425. value: true
  10426. });
  10427. exports.default = isBase64;
  10428. var _assertString = _interopRequireDefault(require("./util/assertString"));
  10429. var _merge = _interopRequireDefault(require("./util/merge"));
  10430. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10431. var notBase64 = /[^A-Z0-9+\/=]/i;
  10432. var urlSafeBase64 = /^[A-Z0-9_\-]*$/i;
  10433. var defaultBase64Options = {
  10434. urlSafe: false
  10435. };
  10436. function isBase64(str, options) {
  10437. (0, _assertString.default)(str);
  10438. options = (0, _merge.default)(options, defaultBase64Options);
  10439. var len = str.length;
  10440. if (options.urlSafe) {
  10441. return urlSafeBase64.test(str);
  10442. }
  10443. if (len % 4 !== 0 || notBase64.test(str)) {
  10444. return false;
  10445. }
  10446. var firstPaddingChar = str.indexOf('=');
  10447. return firstPaddingChar === -1 || firstPaddingChar === len - 1 || firstPaddingChar === len - 2 && str[len - 1] === '=';
  10448. }
  10449. module.exports = exports.default;
  10450. module.exports.default = exports.default;
  10451. },{"./util/assertString":135,"./util/merge":137}],54:[function(require,module,exports){
  10452. "use strict";
  10453. Object.defineProperty(exports, "__esModule", {
  10454. value: true
  10455. });
  10456. exports.default = isBefore;
  10457. var _assertString = _interopRequireDefault(require("./util/assertString"));
  10458. var _toDate = _interopRequireDefault(require("./toDate"));
  10459. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10460. function isBefore(str) {
  10461. var date = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : String(new Date());
  10462. (0, _assertString.default)(str);
  10463. var comparison = (0, _toDate.default)(date);
  10464. var original = (0, _toDate.default)(str);
  10465. return !!(original && comparison && original < comparison);
  10466. }
  10467. module.exports = exports.default;
  10468. module.exports.default = exports.default;
  10469. },{"./toDate":129,"./util/assertString":135}],55:[function(require,module,exports){
  10470. "use strict";
  10471. Object.defineProperty(exports, "__esModule", {
  10472. value: true
  10473. });
  10474. exports.default = isBoolean;
  10475. var _assertString = _interopRequireDefault(require("./util/assertString"));
  10476. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10477. var defaultOptions = {
  10478. loose: false
  10479. };
  10480. var strictBooleans = ['true', 'false', '1', '0'];
  10481. var looseBooleans = [].concat(strictBooleans, ['yes', 'no']);
  10482. function isBoolean(str) {
  10483. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultOptions;
  10484. (0, _assertString.default)(str);
  10485. if (options.loose) {
  10486. return looseBooleans.includes(str.toLowerCase());
  10487. }
  10488. return strictBooleans.includes(str);
  10489. }
  10490. module.exports = exports.default;
  10491. module.exports.default = exports.default;
  10492. },{"./util/assertString":135}],56:[function(require,module,exports){
  10493. "use strict";
  10494. Object.defineProperty(exports, "__esModule", {
  10495. value: true
  10496. });
  10497. exports.default = isBtcAddress;
  10498. var _assertString = _interopRequireDefault(require("./util/assertString"));
  10499. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10500. // supports Bech32 addresses
  10501. var bech32 = /^(bc1)[a-z0-9]{25,39}$/;
  10502. var base58 = /^(1|3)[A-HJ-NP-Za-km-z1-9]{25,39}$/;
  10503. function isBtcAddress(str) {
  10504. (0, _assertString.default)(str); // check for bech32
  10505. if (str.startsWith('bc1')) {
  10506. return bech32.test(str);
  10507. }
  10508. return base58.test(str);
  10509. }
  10510. module.exports = exports.default;
  10511. module.exports.default = exports.default;
  10512. },{"./util/assertString":135}],57:[function(require,module,exports){
  10513. "use strict";
  10514. Object.defineProperty(exports, "__esModule", {
  10515. value: true
  10516. });
  10517. exports.default = isByteLength;
  10518. var _assertString = _interopRequireDefault(require("./util/assertString"));
  10519. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10520. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  10521. /* eslint-disable prefer-rest-params */
  10522. function isByteLength(str, options) {
  10523. (0, _assertString.default)(str);
  10524. var min;
  10525. var max;
  10526. if (_typeof(options) === 'object') {
  10527. min = options.min || 0;
  10528. max = options.max;
  10529. } else {
  10530. // backwards compatibility: isByteLength(str, min [, max])
  10531. min = arguments[1];
  10532. max = arguments[2];
  10533. }
  10534. var len = encodeURI(str).split(/%..|./).length - 1;
  10535. return len >= min && (typeof max === 'undefined' || len <= max);
  10536. }
  10537. module.exports = exports.default;
  10538. module.exports.default = exports.default;
  10539. },{"./util/assertString":135}],58:[function(require,module,exports){
  10540. "use strict";
  10541. Object.defineProperty(exports, "__esModule", {
  10542. value: true
  10543. });
  10544. exports.default = isCreditCard;
  10545. var _assertString = _interopRequireDefault(require("./util/assertString"));
  10546. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10547. /* eslint-disable max-len */
  10548. var creditCard = /^(?:4[0-9]{12}(?:[0-9]{3,6})?|5[1-5][0-9]{14}|(222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}|6(?:011|5[0-9][0-9])[0-9]{12,15}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11}|6[27][0-9]{14}|^(81[0-9]{14,17}))$/;
  10549. /* eslint-enable max-len */
  10550. function isCreditCard(str) {
  10551. (0, _assertString.default)(str);
  10552. var sanitized = str.replace(/[- ]+/g, '');
  10553. if (!creditCard.test(sanitized)) {
  10554. return false;
  10555. }
  10556. var sum = 0;
  10557. var digit;
  10558. var tmpNum;
  10559. var shouldDouble;
  10560. for (var i = sanitized.length - 1; i >= 0; i--) {
  10561. digit = sanitized.substring(i, i + 1);
  10562. tmpNum = parseInt(digit, 10);
  10563. if (shouldDouble) {
  10564. tmpNum *= 2;
  10565. if (tmpNum >= 10) {
  10566. sum += tmpNum % 10 + 1;
  10567. } else {
  10568. sum += tmpNum;
  10569. }
  10570. } else {
  10571. sum += tmpNum;
  10572. }
  10573. shouldDouble = !shouldDouble;
  10574. }
  10575. return !!(sum % 10 === 0 ? sanitized : false);
  10576. }
  10577. module.exports = exports.default;
  10578. module.exports.default = exports.default;
  10579. },{"./util/assertString":135}],59:[function(require,module,exports){
  10580. "use strict";
  10581. Object.defineProperty(exports, "__esModule", {
  10582. value: true
  10583. });
  10584. exports.default = isCurrency;
  10585. var _merge = _interopRequireDefault(require("./util/merge"));
  10586. var _assertString = _interopRequireDefault(require("./util/assertString"));
  10587. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10588. function currencyRegex(options) {
  10589. var decimal_digits = "\\d{".concat(options.digits_after_decimal[0], "}");
  10590. options.digits_after_decimal.forEach(function (digit, index) {
  10591. if (index !== 0) decimal_digits = "".concat(decimal_digits, "|\\d{").concat(digit, "}");
  10592. });
  10593. var symbol = "(".concat(options.symbol.replace(/\W/, function (m) {
  10594. return "\\".concat(m);
  10595. }), ")").concat(options.require_symbol ? '' : '?'),
  10596. negative = '-?',
  10597. whole_dollar_amount_without_sep = '[1-9]\\d*',
  10598. whole_dollar_amount_with_sep = "[1-9]\\d{0,2}(\\".concat(options.thousands_separator, "\\d{3})*"),
  10599. valid_whole_dollar_amounts = ['0', whole_dollar_amount_without_sep, whole_dollar_amount_with_sep],
  10600. whole_dollar_amount = "(".concat(valid_whole_dollar_amounts.join('|'), ")?"),
  10601. decimal_amount = "(\\".concat(options.decimal_separator, "(").concat(decimal_digits, "))").concat(options.require_decimal ? '' : '?');
  10602. var pattern = whole_dollar_amount + (options.allow_decimal || options.require_decimal ? decimal_amount : ''); // default is negative sign before symbol, but there are two other options (besides parens)
  10603. if (options.allow_negatives && !options.parens_for_negatives) {
  10604. if (options.negative_sign_after_digits) {
  10605. pattern += negative;
  10606. } else if (options.negative_sign_before_digits) {
  10607. pattern = negative + pattern;
  10608. }
  10609. } // South African Rand, for example, uses R 123 (space) and R-123 (no space)
  10610. if (options.allow_negative_sign_placeholder) {
  10611. pattern = "( (?!\\-))?".concat(pattern);
  10612. } else if (options.allow_space_after_symbol) {
  10613. pattern = " ?".concat(pattern);
  10614. } else if (options.allow_space_after_digits) {
  10615. pattern += '( (?!$))?';
  10616. }
  10617. if (options.symbol_after_digits) {
  10618. pattern += symbol;
  10619. } else {
  10620. pattern = symbol + pattern;
  10621. }
  10622. if (options.allow_negatives) {
  10623. if (options.parens_for_negatives) {
  10624. pattern = "(\\(".concat(pattern, "\\)|").concat(pattern, ")");
  10625. } else if (!(options.negative_sign_before_digits || options.negative_sign_after_digits)) {
  10626. pattern = negative + pattern;
  10627. }
  10628. } // ensure there's a dollar and/or decimal amount, and that
  10629. // it doesn't start with a space or a negative sign followed by a space
  10630. return new RegExp("^(?!-? )(?=.*\\d)".concat(pattern, "$"));
  10631. }
  10632. var default_currency_options = {
  10633. symbol: '$',
  10634. require_symbol: false,
  10635. allow_space_after_symbol: false,
  10636. symbol_after_digits: false,
  10637. allow_negatives: true,
  10638. parens_for_negatives: false,
  10639. negative_sign_before_digits: false,
  10640. negative_sign_after_digits: false,
  10641. allow_negative_sign_placeholder: false,
  10642. thousands_separator: ',',
  10643. decimal_separator: '.',
  10644. allow_decimal: true,
  10645. require_decimal: false,
  10646. digits_after_decimal: [2],
  10647. allow_space_after_digits: false
  10648. };
  10649. function isCurrency(str, options) {
  10650. (0, _assertString.default)(str);
  10651. options = (0, _merge.default)(options, default_currency_options);
  10652. return currencyRegex(options).test(str);
  10653. }
  10654. module.exports = exports.default;
  10655. module.exports.default = exports.default;
  10656. },{"./util/assertString":135,"./util/merge":137}],60:[function(require,module,exports){
  10657. "use strict";
  10658. Object.defineProperty(exports, "__esModule", {
  10659. value: true
  10660. });
  10661. exports.default = isDataURI;
  10662. var _assertString = _interopRequireDefault(require("./util/assertString"));
  10663. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10664. var validMediaType = /^[a-z]+\/[a-z0-9\-\+]+$/i;
  10665. var validAttribute = /^[a-z\-]+=[a-z0-9\-]+$/i;
  10666. var validData = /^[a-z0-9!\$&'\(\)\*\+,;=\-\._~:@\/\?%\s]*$/i;
  10667. function isDataURI(str) {
  10668. (0, _assertString.default)(str);
  10669. var data = str.split(',');
  10670. if (data.length < 2) {
  10671. return false;
  10672. }
  10673. var attributes = data.shift().trim().split(';');
  10674. var schemeAndMediaType = attributes.shift();
  10675. if (schemeAndMediaType.substr(0, 5) !== 'data:') {
  10676. return false;
  10677. }
  10678. var mediaType = schemeAndMediaType.substr(5);
  10679. if (mediaType !== '' && !validMediaType.test(mediaType)) {
  10680. return false;
  10681. }
  10682. for (var i = 0; i < attributes.length; i++) {
  10683. if (!(i === attributes.length - 1 && attributes[i].toLowerCase() === 'base64') && !validAttribute.test(attributes[i])) {
  10684. return false;
  10685. }
  10686. }
  10687. for (var _i = 0; _i < data.length; _i++) {
  10688. if (!validData.test(data[_i])) {
  10689. return false;
  10690. }
  10691. }
  10692. return true;
  10693. }
  10694. module.exports = exports.default;
  10695. module.exports.default = exports.default;
  10696. },{"./util/assertString":135}],61:[function(require,module,exports){
  10697. "use strict";
  10698. Object.defineProperty(exports, "__esModule", {
  10699. value: true
  10700. });
  10701. exports.default = isDate;
  10702. var _merge = _interopRequireDefault(require("./util/merge"));
  10703. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10704. function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
  10705. function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
  10706. function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
  10707. function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
  10708. function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
  10709. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  10710. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  10711. var default_date_options = {
  10712. format: 'YYYY/MM/DD',
  10713. delimiters: ['/', '-'],
  10714. strictMode: false
  10715. };
  10716. function isValidFormat(format) {
  10717. 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);
  10718. }
  10719. function zip(date, format) {
  10720. var zippedArr = [],
  10721. len = Math.min(date.length, format.length);
  10722. for (var i = 0; i < len; i++) {
  10723. zippedArr.push([date[i], format[i]]);
  10724. }
  10725. return zippedArr;
  10726. }
  10727. function isDate(input, options) {
  10728. if (typeof options === 'string') {
  10729. // Allow backward compatbility for old format isDate(input [, format])
  10730. options = (0, _merge.default)({
  10731. format: options
  10732. }, default_date_options);
  10733. } else {
  10734. options = (0, _merge.default)(options, default_date_options);
  10735. }
  10736. if (typeof input === 'string' && isValidFormat(options.format)) {
  10737. var formatDelimiter = options.delimiters.find(function (delimiter) {
  10738. return options.format.indexOf(delimiter) !== -1;
  10739. });
  10740. var dateDelimiter = options.strictMode ? formatDelimiter : options.delimiters.find(function (delimiter) {
  10741. return input.indexOf(delimiter) !== -1;
  10742. });
  10743. var dateAndFormat = zip(input.split(dateDelimiter), options.format.toLowerCase().split(formatDelimiter));
  10744. var dateObj = {};
  10745. var _iterator = _createForOfIteratorHelper(dateAndFormat),
  10746. _step;
  10747. try {
  10748. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  10749. var _step$value = _slicedToArray(_step.value, 2),
  10750. dateWord = _step$value[0],
  10751. formatWord = _step$value[1];
  10752. if (dateWord.length !== formatWord.length) {
  10753. return false;
  10754. }
  10755. dateObj[formatWord.charAt(0)] = dateWord;
  10756. }
  10757. } catch (err) {
  10758. _iterator.e(err);
  10759. } finally {
  10760. _iterator.f();
  10761. }
  10762. return new Date("".concat(dateObj.m, "/").concat(dateObj.d, "/").concat(dateObj.y)).getDate() === +dateObj.d;
  10763. }
  10764. if (!options.strictMode) {
  10765. return Object.prototype.toString.call(input) === '[object Date]' && isFinite(input);
  10766. }
  10767. return false;
  10768. }
  10769. module.exports = exports.default;
  10770. module.exports.default = exports.default;
  10771. },{"./util/merge":137}],62:[function(require,module,exports){
  10772. "use strict";
  10773. Object.defineProperty(exports, "__esModule", {
  10774. value: true
  10775. });
  10776. exports.default = isDecimal;
  10777. var _merge = _interopRequireDefault(require("./util/merge"));
  10778. var _assertString = _interopRequireDefault(require("./util/assertString"));
  10779. var _includes = _interopRequireDefault(require("./util/includes"));
  10780. var _alpha = require("./alpha");
  10781. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10782. function decimalRegExp(options) {
  10783. var regExp = new RegExp("^[-+]?([0-9]+)?(\\".concat(_alpha.decimal[options.locale], "[0-9]{").concat(options.decimal_digits, "})").concat(options.force_decimal ? '' : '?', "$"));
  10784. return regExp;
  10785. }
  10786. var default_decimal_options = {
  10787. force_decimal: false,
  10788. decimal_digits: '1,',
  10789. locale: 'en-US'
  10790. };
  10791. var blacklist = ['', '-', '+'];
  10792. function isDecimal(str, options) {
  10793. (0, _assertString.default)(str);
  10794. options = (0, _merge.default)(options, default_decimal_options);
  10795. if (options.locale in _alpha.decimal) {
  10796. return !(0, _includes.default)(blacklist, str.replace(/ /g, '')) && decimalRegExp(options).test(str);
  10797. }
  10798. throw new Error("Invalid locale '".concat(options.locale, "'"));
  10799. }
  10800. module.exports = exports.default;
  10801. module.exports.default = exports.default;
  10802. },{"./alpha":41,"./util/assertString":135,"./util/includes":136,"./util/merge":137}],63:[function(require,module,exports){
  10803. "use strict";
  10804. Object.defineProperty(exports, "__esModule", {
  10805. value: true
  10806. });
  10807. exports.default = isDivisibleBy;
  10808. var _assertString = _interopRequireDefault(require("./util/assertString"));
  10809. var _toFloat = _interopRequireDefault(require("./toFloat"));
  10810. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10811. function isDivisibleBy(str, num) {
  10812. (0, _assertString.default)(str);
  10813. return (0, _toFloat.default)(str) % parseInt(num, 10) === 0;
  10814. }
  10815. module.exports = exports.default;
  10816. module.exports.default = exports.default;
  10817. },{"./toFloat":130,"./util/assertString":135}],64:[function(require,module,exports){
  10818. "use strict";
  10819. Object.defineProperty(exports, "__esModule", {
  10820. value: true
  10821. });
  10822. exports.default = isEAN;
  10823. var _assertString = _interopRequireDefault(require("./util/assertString"));
  10824. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10825. /**
  10826. * The most commonly used EAN standard is
  10827. * the thirteen-digit EAN-13, while the
  10828. * less commonly used 8-digit EAN-8 barcode was
  10829. * introduced for use on small packages.
  10830. * Also EAN/UCC-14 is used for Grouping of individual
  10831. * trade items above unit level(Intermediate, Carton or Pallet).
  10832. * For more info about EAN-14 checkout: https://www.gtin.info/itf-14-barcodes/
  10833. * EAN consists of:
  10834. * GS1 prefix, manufacturer code, product code and check digit
  10835. * Reference: https://en.wikipedia.org/wiki/International_Article_Number
  10836. * Reference: https://www.gtin.info/
  10837. */
  10838. /**
  10839. * Define EAN Lenghts; 8 for EAN-8; 13 for EAN-13; 14 for EAN-14
  10840. * and Regular Expression for valid EANs (EAN-8, EAN-13, EAN-14),
  10841. * with exact numberic matching of 8 or 13 or 14 digits [0-9]
  10842. */
  10843. var LENGTH_EAN_8 = 8;
  10844. var LENGTH_EAN_14 = 14;
  10845. var validEanRegex = /^(\d{8}|\d{13}|\d{14})$/;
  10846. /**
  10847. * Get position weight given:
  10848. * EAN length and digit index/position
  10849. *
  10850. * @param {number} length
  10851. * @param {number} index
  10852. * @return {number}
  10853. */
  10854. function getPositionWeightThroughLengthAndIndex(length, index) {
  10855. if (length === LENGTH_EAN_8 || length === LENGTH_EAN_14) {
  10856. return index % 2 === 0 ? 3 : 1;
  10857. }
  10858. return index % 2 === 0 ? 1 : 3;
  10859. }
  10860. /**
  10861. * Calculate EAN Check Digit
  10862. * Reference: https://en.wikipedia.org/wiki/International_Article_Number#Calculation_of_checksum_digit
  10863. *
  10864. * @param {string} ean
  10865. * @return {number}
  10866. */
  10867. function calculateCheckDigit(ean) {
  10868. var checksum = ean.slice(0, -1).split('').map(function (char, index) {
  10869. return Number(char) * getPositionWeightThroughLengthAndIndex(ean.length, index);
  10870. }).reduce(function (acc, partialSum) {
  10871. return acc + partialSum;
  10872. }, 0);
  10873. var remainder = 10 - checksum % 10;
  10874. return remainder < 10 ? remainder : 0;
  10875. }
  10876. /**
  10877. * Check if string is valid EAN:
  10878. * Matches EAN-8/EAN-13/EAN-14 regex
  10879. * Has valid check digit.
  10880. *
  10881. * @param {string} str
  10882. * @return {boolean}
  10883. */
  10884. function isEAN(str) {
  10885. (0, _assertString.default)(str);
  10886. var actualCheckDigit = Number(str.slice(-1));
  10887. return validEanRegex.test(str) && actualCheckDigit === calculateCheckDigit(str);
  10888. }
  10889. module.exports = exports.default;
  10890. module.exports.default = exports.default;
  10891. },{"./util/assertString":135}],65:[function(require,module,exports){
  10892. "use strict";
  10893. Object.defineProperty(exports, "__esModule", {
  10894. value: true
  10895. });
  10896. exports.default = isEmail;
  10897. var _assertString = _interopRequireDefault(require("./util/assertString"));
  10898. var _merge = _interopRequireDefault(require("./util/merge"));
  10899. var _isByteLength = _interopRequireDefault(require("./isByteLength"));
  10900. var _isFQDN = _interopRequireDefault(require("./isFQDN"));
  10901. var _isIP = _interopRequireDefault(require("./isIP"));
  10902. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10903. var default_email_options = {
  10904. allow_display_name: false,
  10905. require_display_name: false,
  10906. allow_utf8_local_part: true,
  10907. require_tld: true,
  10908. blacklisted_chars: '',
  10909. ignore_max_length: false,
  10910. host_blacklist: []
  10911. };
  10912. /* eslint-disable max-len */
  10913. /* eslint-disable no-control-regex */
  10914. var splitNameAddress = /^([^\x00-\x1F\x7F-\x9F\cX]+)</i;
  10915. var emailUserPart = /^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~]+$/i;
  10916. var gmailUserPart = /^[a-z\d]+$/;
  10917. var quotedEmailUser = /^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f]))*$/i;
  10918. var emailUserUtf8Part = /^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+$/i;
  10919. 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;
  10920. var defaultMaxEmailLength = 254;
  10921. /* eslint-enable max-len */
  10922. /* eslint-enable no-control-regex */
  10923. /**
  10924. * Validate display name according to the RFC2822: https://tools.ietf.org/html/rfc2822#appendix-A.1.2
  10925. * @param {String} display_name
  10926. */
  10927. function validateDisplayName(display_name) {
  10928. var display_name_without_quotes = display_name.replace(/^"(.+)"$/, '$1'); // display name with only spaces is not valid
  10929. if (!display_name_without_quotes.trim()) {
  10930. return false;
  10931. } // check whether display name contains illegal character
  10932. var contains_illegal = /[\.";<>]/.test(display_name_without_quotes);
  10933. if (contains_illegal) {
  10934. // if contains illegal characters,
  10935. // must to be enclosed in double-quotes, otherwise it's not a valid display name
  10936. if (display_name_without_quotes === display_name) {
  10937. return false;
  10938. } // the quotes in display name must start with character symbol \
  10939. var all_start_with_back_slash = display_name_without_quotes.split('"').length === display_name_without_quotes.split('\\"').length;
  10940. if (!all_start_with_back_slash) {
  10941. return false;
  10942. }
  10943. }
  10944. return true;
  10945. }
  10946. function isEmail(str, options) {
  10947. (0, _assertString.default)(str);
  10948. options = (0, _merge.default)(options, default_email_options);
  10949. if (options.require_display_name || options.allow_display_name) {
  10950. var display_email = str.match(splitNameAddress);
  10951. if (display_email) {
  10952. var display_name = display_email[1]; // Remove display name and angle brackets to get email address
  10953. // Can be done in the regex but will introduce a ReDOS (See #1597 for more info)
  10954. str = str.replace(display_name, '').replace(/(^<|>$)/g, ''); // sometimes need to trim the last space to get the display name
  10955. // because there may be a space between display name and email address
  10956. // eg. myname <address@gmail.com>
  10957. // the display name is `myname` instead of `myname `, so need to trim the last space
  10958. if (display_name.endsWith(' ')) {
  10959. display_name = display_name.substr(0, display_name.length - 1);
  10960. }
  10961. if (!validateDisplayName(display_name)) {
  10962. return false;
  10963. }
  10964. } else if (options.require_display_name) {
  10965. return false;
  10966. }
  10967. }
  10968. if (!options.ignore_max_length && str.length > defaultMaxEmailLength) {
  10969. return false;
  10970. }
  10971. var parts = str.split('@');
  10972. var domain = parts.pop();
  10973. var lower_domain = domain.toLowerCase();
  10974. if (options.host_blacklist.includes(lower_domain)) {
  10975. return false;
  10976. }
  10977. var user = parts.join('@');
  10978. if (options.domain_specific_validation && (lower_domain === 'gmail.com' || lower_domain === 'googlemail.com')) {
  10979. /*
  10980. Previously we removed dots for gmail addresses before validating.
  10981. This was removed because it allows `multiple..dots@gmail.com`
  10982. to be reported as valid, but it is not.
  10983. Gmail only normalizes single dots, removing them from here is pointless,
  10984. should be done in normalizeEmail
  10985. */
  10986. user = user.toLowerCase(); // Removing sub-address from username before gmail validation
  10987. var username = user.split('+')[0]; // Dots are not included in gmail length restriction
  10988. if (!(0, _isByteLength.default)(username.replace(/\./g, ''), {
  10989. min: 6,
  10990. max: 30
  10991. })) {
  10992. return false;
  10993. }
  10994. var _user_parts = username.split('.');
  10995. for (var i = 0; i < _user_parts.length; i++) {
  10996. if (!gmailUserPart.test(_user_parts[i])) {
  10997. return false;
  10998. }
  10999. }
  11000. }
  11001. if (options.ignore_max_length === false && (!(0, _isByteLength.default)(user, {
  11002. max: 64
  11003. }) || !(0, _isByteLength.default)(domain, {
  11004. max: 254
  11005. }))) {
  11006. return false;
  11007. }
  11008. if (!(0, _isFQDN.default)(domain, {
  11009. require_tld: options.require_tld
  11010. })) {
  11011. if (!options.allow_ip_domain) {
  11012. return false;
  11013. }
  11014. if (!(0, _isIP.default)(domain)) {
  11015. if (!domain.startsWith('[') || !domain.endsWith(']')) {
  11016. return false;
  11017. }
  11018. var noBracketdomain = domain.substr(1, domain.length - 2);
  11019. if (noBracketdomain.length === 0 || !(0, _isIP.default)(noBracketdomain)) {
  11020. return false;
  11021. }
  11022. }
  11023. }
  11024. if (user[0] === '"') {
  11025. user = user.slice(1, user.length - 1);
  11026. return options.allow_utf8_local_part ? quotedEmailUserUtf8.test(user) : quotedEmailUser.test(user);
  11027. }
  11028. var pattern = options.allow_utf8_local_part ? emailUserUtf8Part : emailUserPart;
  11029. var user_parts = user.split('.');
  11030. for (var _i = 0; _i < user_parts.length; _i++) {
  11031. if (!pattern.test(user_parts[_i])) {
  11032. return false;
  11033. }
  11034. }
  11035. if (options.blacklisted_chars) {
  11036. if (user.search(new RegExp("[".concat(options.blacklisted_chars, "]+"), 'g')) !== -1) return false;
  11037. }
  11038. return true;
  11039. }
  11040. module.exports = exports.default;
  11041. module.exports.default = exports.default;
  11042. },{"./isByteLength":57,"./isFQDN":68,"./isIP":78,"./util/assertString":135,"./util/merge":137}],66:[function(require,module,exports){
  11043. "use strict";
  11044. Object.defineProperty(exports, "__esModule", {
  11045. value: true
  11046. });
  11047. exports.default = isEmpty;
  11048. var _assertString = _interopRequireDefault(require("./util/assertString"));
  11049. var _merge = _interopRequireDefault(require("./util/merge"));
  11050. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11051. var default_is_empty_options = {
  11052. ignore_whitespace: false
  11053. };
  11054. function isEmpty(str, options) {
  11055. (0, _assertString.default)(str);
  11056. options = (0, _merge.default)(options, default_is_empty_options);
  11057. return (options.ignore_whitespace ? str.trim().length : str.length) === 0;
  11058. }
  11059. module.exports = exports.default;
  11060. module.exports.default = exports.default;
  11061. },{"./util/assertString":135,"./util/merge":137}],67:[function(require,module,exports){
  11062. "use strict";
  11063. Object.defineProperty(exports, "__esModule", {
  11064. value: true
  11065. });
  11066. exports.default = isEthereumAddress;
  11067. var _assertString = _interopRequireDefault(require("./util/assertString"));
  11068. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11069. var eth = /^(0x)[0-9a-f]{40}$/i;
  11070. function isEthereumAddress(str) {
  11071. (0, _assertString.default)(str);
  11072. return eth.test(str);
  11073. }
  11074. module.exports = exports.default;
  11075. module.exports.default = exports.default;
  11076. },{"./util/assertString":135}],68:[function(require,module,exports){
  11077. "use strict";
  11078. Object.defineProperty(exports, "__esModule", {
  11079. value: true
  11080. });
  11081. exports.default = isFQDN;
  11082. var _assertString = _interopRequireDefault(require("./util/assertString"));
  11083. var _merge = _interopRequireDefault(require("./util/merge"));
  11084. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11085. var default_fqdn_options = {
  11086. require_tld: true,
  11087. allow_underscores: false,
  11088. allow_trailing_dot: false,
  11089. allow_numeric_tld: false,
  11090. allow_wildcard: false
  11091. };
  11092. function isFQDN(str, options) {
  11093. (0, _assertString.default)(str);
  11094. options = (0, _merge.default)(options, default_fqdn_options);
  11095. /* Remove the optional trailing dot before checking validity */
  11096. if (options.allow_trailing_dot && str[str.length - 1] === '.') {
  11097. str = str.substring(0, str.length - 1);
  11098. }
  11099. /* Remove the optional wildcard before checking validity */
  11100. if (options.allow_wildcard === true && str.indexOf('*.') === 0) {
  11101. str = str.substring(2);
  11102. }
  11103. var parts = str.split('.');
  11104. var tld = parts[parts.length - 1];
  11105. if (options.require_tld) {
  11106. // disallow fqdns without tld
  11107. if (parts.length < 2) {
  11108. return false;
  11109. }
  11110. if (!/^([a-z\u00A1-\u00A8\u00AA-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]{2,}|xn[a-z0-9-]{2,})$/i.test(tld)) {
  11111. return false;
  11112. } // disallow spaces
  11113. if (/\s/.test(tld)) {
  11114. return false;
  11115. }
  11116. } // reject numeric TLDs
  11117. if (!options.allow_numeric_tld && /^\d+$/.test(tld)) {
  11118. return false;
  11119. }
  11120. return parts.every(function (part) {
  11121. if (part.length > 63) {
  11122. return false;
  11123. }
  11124. if (!/^[a-z_\u00a1-\uffff0-9-]+$/i.test(part)) {
  11125. return false;
  11126. } // disallow full-width chars
  11127. if (/[\uff01-\uff5e]/.test(part)) {
  11128. return false;
  11129. } // disallow parts starting or ending with hyphen
  11130. if (/^-|-$/.test(part)) {
  11131. return false;
  11132. }
  11133. if (!options.allow_underscores && /_/.test(part)) {
  11134. return false;
  11135. }
  11136. return true;
  11137. });
  11138. }
  11139. module.exports = exports.default;
  11140. module.exports.default = exports.default;
  11141. },{"./util/assertString":135,"./util/merge":137}],69:[function(require,module,exports){
  11142. "use strict";
  11143. Object.defineProperty(exports, "__esModule", {
  11144. value: true
  11145. });
  11146. exports.default = isFloat;
  11147. exports.locales = void 0;
  11148. var _assertString = _interopRequireDefault(require("./util/assertString"));
  11149. var _alpha = require("./alpha");
  11150. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11151. function isFloat(str, options) {
  11152. (0, _assertString.default)(str);
  11153. options = options || {};
  11154. var float = new RegExp("^(?:[-+])?(?:[0-9]+)?(?:\\".concat(options.locale ? _alpha.decimal[options.locale] : '.', "[0-9]*)?(?:[eE][\\+\\-]?(?:[0-9]+))?$"));
  11155. if (str === '' || str === '.' || str === '-' || str === '+') {
  11156. return false;
  11157. }
  11158. var value = parseFloat(str.replace(',', '.'));
  11159. 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);
  11160. }
  11161. var locales = Object.keys(_alpha.decimal);
  11162. exports.locales = locales;
  11163. },{"./alpha":41,"./util/assertString":135}],70:[function(require,module,exports){
  11164. "use strict";
  11165. Object.defineProperty(exports, "__esModule", {
  11166. value: true
  11167. });
  11168. exports.default = isFullWidth;
  11169. exports.fullWidth = void 0;
  11170. var _assertString = _interopRequireDefault(require("./util/assertString"));
  11171. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11172. var fullWidth = /[^\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;
  11173. exports.fullWidth = fullWidth;
  11174. function isFullWidth(str) {
  11175. (0, _assertString.default)(str);
  11176. return fullWidth.test(str);
  11177. }
  11178. },{"./util/assertString":135}],71:[function(require,module,exports){
  11179. "use strict";
  11180. Object.defineProperty(exports, "__esModule", {
  11181. value: true
  11182. });
  11183. exports.default = isHSL;
  11184. var _assertString = _interopRequireDefault(require("./util/assertString"));
  11185. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11186. 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;
  11187. 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;
  11188. function isHSL(str) {
  11189. (0, _assertString.default)(str); // Strip duplicate spaces before calling the validation regex (See #1598 for more info)
  11190. var strippedStr = str.replace(/\s+/g, ' ').replace(/\s?(hsla?\(|\)|,)\s?/ig, '$1');
  11191. if (strippedStr.indexOf(',') !== -1) {
  11192. return hslComma.test(strippedStr);
  11193. }
  11194. return hslSpace.test(strippedStr);
  11195. }
  11196. module.exports = exports.default;
  11197. module.exports.default = exports.default;
  11198. },{"./util/assertString":135}],72:[function(require,module,exports){
  11199. "use strict";
  11200. Object.defineProperty(exports, "__esModule", {
  11201. value: true
  11202. });
  11203. exports.default = isHalfWidth;
  11204. exports.halfWidth = void 0;
  11205. var _assertString = _interopRequireDefault(require("./util/assertString"));
  11206. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11207. var halfWidth = /[\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;
  11208. exports.halfWidth = halfWidth;
  11209. function isHalfWidth(str) {
  11210. (0, _assertString.default)(str);
  11211. return halfWidth.test(str);
  11212. }
  11213. },{"./util/assertString":135}],73:[function(require,module,exports){
  11214. "use strict";
  11215. Object.defineProperty(exports, "__esModule", {
  11216. value: true
  11217. });
  11218. exports.default = isHash;
  11219. var _assertString = _interopRequireDefault(require("./util/assertString"));
  11220. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11221. var lengths = {
  11222. md5: 32,
  11223. md4: 32,
  11224. sha1: 40,
  11225. sha256: 64,
  11226. sha384: 96,
  11227. sha512: 128,
  11228. ripemd128: 32,
  11229. ripemd160: 40,
  11230. tiger128: 32,
  11231. tiger160: 40,
  11232. tiger192: 48,
  11233. crc32: 8,
  11234. crc32b: 8
  11235. };
  11236. function isHash(str, algorithm) {
  11237. (0, _assertString.default)(str);
  11238. var hash = new RegExp("^[a-fA-F0-9]{".concat(lengths[algorithm], "}$"));
  11239. return hash.test(str);
  11240. }
  11241. module.exports = exports.default;
  11242. module.exports.default = exports.default;
  11243. },{"./util/assertString":135}],74:[function(require,module,exports){
  11244. "use strict";
  11245. Object.defineProperty(exports, "__esModule", {
  11246. value: true
  11247. });
  11248. exports.default = isHexColor;
  11249. var _assertString = _interopRequireDefault(require("./util/assertString"));
  11250. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11251. var hexcolor = /^#?([0-9A-F]{3}|[0-9A-F]{4}|[0-9A-F]{6}|[0-9A-F]{8})$/i;
  11252. function isHexColor(str) {
  11253. (0, _assertString.default)(str);
  11254. return hexcolor.test(str);
  11255. }
  11256. module.exports = exports.default;
  11257. module.exports.default = exports.default;
  11258. },{"./util/assertString":135}],75:[function(require,module,exports){
  11259. "use strict";
  11260. Object.defineProperty(exports, "__esModule", {
  11261. value: true
  11262. });
  11263. exports.default = isHexadecimal;
  11264. var _assertString = _interopRequireDefault(require("./util/assertString"));
  11265. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11266. var hexadecimal = /^(0x|0h)?[0-9A-F]+$/i;
  11267. function isHexadecimal(str) {
  11268. (0, _assertString.default)(str);
  11269. return hexadecimal.test(str);
  11270. }
  11271. module.exports = exports.default;
  11272. module.exports.default = exports.default;
  11273. },{"./util/assertString":135}],76:[function(require,module,exports){
  11274. "use strict";
  11275. Object.defineProperty(exports, "__esModule", {
  11276. value: true
  11277. });
  11278. exports.default = isIBAN;
  11279. exports.locales = void 0;
  11280. var _assertString = _interopRequireDefault(require("./util/assertString"));
  11281. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11282. /**
  11283. * List of country codes with
  11284. * corresponding IBAN regular expression
  11285. * Reference: https://en.wikipedia.org/wiki/International_Bank_Account_Number
  11286. */
  11287. var ibanRegexThroughCountryCode = {
  11288. AD: /^(AD[0-9]{2})\d{8}[A-Z0-9]{12}$/,
  11289. AE: /^(AE[0-9]{2})\d{3}\d{16}$/,
  11290. AL: /^(AL[0-9]{2})\d{8}[A-Z0-9]{16}$/,
  11291. AT: /^(AT[0-9]{2})\d{16}$/,
  11292. AZ: /^(AZ[0-9]{2})[A-Z0-9]{4}\d{20}$/,
  11293. BA: /^(BA[0-9]{2})\d{16}$/,
  11294. BE: /^(BE[0-9]{2})\d{12}$/,
  11295. BG: /^(BG[0-9]{2})[A-Z]{4}\d{6}[A-Z0-9]{8}$/,
  11296. BH: /^(BH[0-9]{2})[A-Z]{4}[A-Z0-9]{14}$/,
  11297. BR: /^(BR[0-9]{2})\d{23}[A-Z]{1}[A-Z0-9]{1}$/,
  11298. BY: /^(BY[0-9]{2})[A-Z0-9]{4}\d{20}$/,
  11299. CH: /^(CH[0-9]{2})\d{5}[A-Z0-9]{12}$/,
  11300. CR: /^(CR[0-9]{2})\d{18}$/,
  11301. CY: /^(CY[0-9]{2})\d{8}[A-Z0-9]{16}$/,
  11302. CZ: /^(CZ[0-9]{2})\d{20}$/,
  11303. DE: /^(DE[0-9]{2})\d{18}$/,
  11304. DK: /^(DK[0-9]{2})\d{14}$/,
  11305. DO: /^(DO[0-9]{2})[A-Z]{4}\d{20}$/,
  11306. EE: /^(EE[0-9]{2})\d{16}$/,
  11307. EG: /^(EG[0-9]{2})\d{25}$/,
  11308. ES: /^(ES[0-9]{2})\d{20}$/,
  11309. FI: /^(FI[0-9]{2})\d{14}$/,
  11310. FO: /^(FO[0-9]{2})\d{14}$/,
  11311. FR: /^(FR[0-9]{2})\d{10}[A-Z0-9]{11}\d{2}$/,
  11312. GB: /^(GB[0-9]{2})[A-Z]{4}\d{14}$/,
  11313. GE: /^(GE[0-9]{2})[A-Z0-9]{2}\d{16}$/,
  11314. GI: /^(GI[0-9]{2})[A-Z]{4}[A-Z0-9]{15}$/,
  11315. GL: /^(GL[0-9]{2})\d{14}$/,
  11316. GR: /^(GR[0-9]{2})\d{7}[A-Z0-9]{16}$/,
  11317. GT: /^(GT[0-9]{2})[A-Z0-9]{4}[A-Z0-9]{20}$/,
  11318. HR: /^(HR[0-9]{2})\d{17}$/,
  11319. HU: /^(HU[0-9]{2})\d{24}$/,
  11320. IE: /^(IE[0-9]{2})[A-Z0-9]{4}\d{14}$/,
  11321. IL: /^(IL[0-9]{2})\d{19}$/,
  11322. IQ: /^(IQ[0-9]{2})[A-Z]{4}\d{15}$/,
  11323. IR: /^(IR[0-9]{2})0\d{2}0\d{18}$/,
  11324. IS: /^(IS[0-9]{2})\d{22}$/,
  11325. IT: /^(IT[0-9]{2})[A-Z]{1}\d{10}[A-Z0-9]{12}$/,
  11326. JO: /^(JO[0-9]{2})[A-Z]{4}\d{22}$/,
  11327. KW: /^(KW[0-9]{2})[A-Z]{4}[A-Z0-9]{22}$/,
  11328. KZ: /^(KZ[0-9]{2})\d{3}[A-Z0-9]{13}$/,
  11329. LB: /^(LB[0-9]{2})\d{4}[A-Z0-9]{20}$/,
  11330. LC: /^(LC[0-9]{2})[A-Z]{4}[A-Z0-9]{24}$/,
  11331. LI: /^(LI[0-9]{2})\d{5}[A-Z0-9]{12}$/,
  11332. LT: /^(LT[0-9]{2})\d{16}$/,
  11333. LU: /^(LU[0-9]{2})\d{3}[A-Z0-9]{13}$/,
  11334. LV: /^(LV[0-9]{2})[A-Z]{4}[A-Z0-9]{13}$/,
  11335. MC: /^(MC[0-9]{2})\d{10}[A-Z0-9]{11}\d{2}$/,
  11336. MD: /^(MD[0-9]{2})[A-Z0-9]{20}$/,
  11337. ME: /^(ME[0-9]{2})\d{18}$/,
  11338. MK: /^(MK[0-9]{2})\d{3}[A-Z0-9]{10}\d{2}$/,
  11339. MR: /^(MR[0-9]{2})\d{23}$/,
  11340. MT: /^(MT[0-9]{2})[A-Z]{4}\d{5}[A-Z0-9]{18}$/,
  11341. MU: /^(MU[0-9]{2})[A-Z]{4}\d{19}[A-Z]{3}$/,
  11342. MZ: /^(MZ[0-9]{2})\d{21}$/,
  11343. NL: /^(NL[0-9]{2})[A-Z]{4}\d{10}$/,
  11344. NO: /^(NO[0-9]{2})\d{11}$/,
  11345. PK: /^(PK[0-9]{2})[A-Z0-9]{4}\d{16}$/,
  11346. PL: /^(PL[0-9]{2})\d{24}$/,
  11347. PS: /^(PS[0-9]{2})[A-Z0-9]{4}\d{21}$/,
  11348. PT: /^(PT[0-9]{2})\d{21}$/,
  11349. QA: /^(QA[0-9]{2})[A-Z]{4}[A-Z0-9]{21}$/,
  11350. RO: /^(RO[0-9]{2})[A-Z]{4}[A-Z0-9]{16}$/,
  11351. RS: /^(RS[0-9]{2})\d{18}$/,
  11352. SA: /^(SA[0-9]{2})\d{2}[A-Z0-9]{18}$/,
  11353. SC: /^(SC[0-9]{2})[A-Z]{4}\d{20}[A-Z]{3}$/,
  11354. SE: /^(SE[0-9]{2})\d{20}$/,
  11355. SI: /^(SI[0-9]{2})\d{15}$/,
  11356. SK: /^(SK[0-9]{2})\d{20}$/,
  11357. SM: /^(SM[0-9]{2})[A-Z]{1}\d{10}[A-Z0-9]{12}$/,
  11358. SV: /^(SV[0-9]{2})[A-Z0-9]{4}\d{20}$/,
  11359. TL: /^(TL[0-9]{2})\d{19}$/,
  11360. TN: /^(TN[0-9]{2})\d{20}$/,
  11361. TR: /^(TR[0-9]{2})\d{5}[A-Z0-9]{17}$/,
  11362. UA: /^(UA[0-9]{2})\d{6}[A-Z0-9]{19}$/,
  11363. VA: /^(VA[0-9]{2})\d{18}$/,
  11364. VG: /^(VG[0-9]{2})[A-Z0-9]{4}\d{16}$/,
  11365. XK: /^(XK[0-9]{2})\d{16}$/
  11366. };
  11367. /**
  11368. * Check whether string has correct universal IBAN format
  11369. * The IBAN consists of up to 34 alphanumeric characters, as follows:
  11370. * Country Code using ISO 3166-1 alpha-2, two letters
  11371. * check digits, two digits and
  11372. * Basic Bank Account Number (BBAN), up to 30 alphanumeric characters.
  11373. * NOTE: Permitted IBAN characters are: digits [0-9] and the 26 latin alphabetic [A-Z]
  11374. *
  11375. * @param {string} str - string under validation
  11376. * @return {boolean}
  11377. */
  11378. function hasValidIbanFormat(str) {
  11379. // Strip white spaces and hyphens
  11380. var strippedStr = str.replace(/[\s\-]+/gi, '').toUpperCase();
  11381. var isoCountryCode = strippedStr.slice(0, 2).toUpperCase();
  11382. return isoCountryCode in ibanRegexThroughCountryCode && ibanRegexThroughCountryCode[isoCountryCode].test(strippedStr);
  11383. }
  11384. /**
  11385. * Check whether string has valid IBAN Checksum
  11386. * by performing basic mod-97 operation and
  11387. * the remainder should equal 1
  11388. * -- Start by rearranging the IBAN by moving the four initial characters to the end of the string
  11389. * -- Replace each letter in the string with two digits, A -> 10, B = 11, Z = 35
  11390. * -- Interpret the string as a decimal integer and
  11391. * -- compute the remainder on division by 97 (mod 97)
  11392. * Reference: https://en.wikipedia.org/wiki/International_Bank_Account_Number
  11393. *
  11394. * @param {string} str
  11395. * @return {boolean}
  11396. */
  11397. function hasValidIbanChecksum(str) {
  11398. var strippedStr = str.replace(/[^A-Z0-9]+/gi, '').toUpperCase(); // Keep only digits and A-Z latin alphabetic
  11399. var rearranged = strippedStr.slice(4) + strippedStr.slice(0, 4);
  11400. var alphaCapsReplacedWithDigits = rearranged.replace(/[A-Z]/g, function (char) {
  11401. return char.charCodeAt(0) - 55;
  11402. });
  11403. var remainder = alphaCapsReplacedWithDigits.match(/\d{1,7}/g).reduce(function (acc, value) {
  11404. return Number(acc + value) % 97;
  11405. }, '');
  11406. return remainder === 1;
  11407. }
  11408. function isIBAN(str) {
  11409. (0, _assertString.default)(str);
  11410. return hasValidIbanFormat(str) && hasValidIbanChecksum(str);
  11411. }
  11412. var locales = Object.keys(ibanRegexThroughCountryCode);
  11413. exports.locales = locales;
  11414. },{"./util/assertString":135}],77:[function(require,module,exports){
  11415. "use strict";
  11416. Object.defineProperty(exports, "__esModule", {
  11417. value: true
  11418. });
  11419. exports.default = isIMEI;
  11420. var _assertString = _interopRequireDefault(require("./util/assertString"));
  11421. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11422. var imeiRegexWithoutHypens = /^[0-9]{15}$/;
  11423. var imeiRegexWithHypens = /^\d{2}-\d{6}-\d{6}-\d{1}$/;
  11424. function isIMEI(str, options) {
  11425. (0, _assertString.default)(str);
  11426. options = options || {}; // default regex for checking imei is the one without hyphens
  11427. var imeiRegex = imeiRegexWithoutHypens;
  11428. if (options.allow_hyphens) {
  11429. imeiRegex = imeiRegexWithHypens;
  11430. }
  11431. if (!imeiRegex.test(str)) {
  11432. return false;
  11433. }
  11434. str = str.replace(/-/g, '');
  11435. var sum = 0,
  11436. mul = 2,
  11437. l = 14;
  11438. for (var i = 0; i < l; i++) {
  11439. var digit = str.substring(l - i - 1, l - i);
  11440. var tp = parseInt(digit, 10) * mul;
  11441. if (tp >= 10) {
  11442. sum += tp % 10 + 1;
  11443. } else {
  11444. sum += tp;
  11445. }
  11446. if (mul === 1) {
  11447. mul += 1;
  11448. } else {
  11449. mul -= 1;
  11450. }
  11451. }
  11452. var chk = (10 - sum % 10) % 10;
  11453. if (chk !== parseInt(str.substring(14, 15), 10)) {
  11454. return false;
  11455. }
  11456. return true;
  11457. }
  11458. module.exports = exports.default;
  11459. module.exports.default = exports.default;
  11460. },{"./util/assertString":135}],78:[function(require,module,exports){
  11461. "use strict";
  11462. Object.defineProperty(exports, "__esModule", {
  11463. value: true
  11464. });
  11465. exports.default = isIP;
  11466. var _assertString = _interopRequireDefault(require("./util/assertString"));
  11467. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11468. /**
  11469. 11.3. Examples
  11470. The following addresses
  11471. fe80::1234 (on the 1st link of the node)
  11472. ff02::5678 (on the 5th link of the node)
  11473. ff08::9abc (on the 10th organization of the node)
  11474. would be represented as follows:
  11475. fe80::1234%1
  11476. ff02::5678%5
  11477. ff08::9abc%10
  11478. (Here we assume a natural translation from a zone index to the
  11479. <zone_id> part, where the Nth zone of any scope is translated into
  11480. "N".)
  11481. If we use interface names as <zone_id>, those addresses could also be
  11482. represented as follows:
  11483. fe80::1234%ne0
  11484. ff02::5678%pvc1.3
  11485. ff08::9abc%interface10
  11486. where the interface "ne0" belongs to the 1st link, "pvc1.3" belongs
  11487. to the 5th link, and "interface10" belongs to the 10th organization.
  11488. * * */
  11489. var IPv4SegmentFormat = '(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])';
  11490. var IPv4AddressFormat = "(".concat(IPv4SegmentFormat, "[.]){3}").concat(IPv4SegmentFormat);
  11491. var IPv4AddressRegExp = new RegExp("^".concat(IPv4AddressFormat, "$"));
  11492. var IPv6SegmentFormat = '(?:[0-9a-fA-F]{1,4})';
  11493. 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,})?$');
  11494. function isIP(str) {
  11495. var version = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
  11496. (0, _assertString.default)(str);
  11497. version = String(version);
  11498. if (!version) {
  11499. return isIP(str, 4) || isIP(str, 6);
  11500. }
  11501. if (version === '4') {
  11502. if (!IPv4AddressRegExp.test(str)) {
  11503. return false;
  11504. }
  11505. var parts = str.split('.').sort(function (a, b) {
  11506. return a - b;
  11507. });
  11508. return parts[3] <= 255;
  11509. }
  11510. if (version === '6') {
  11511. return !!IPv6AddressRegExp.test(str);
  11512. }
  11513. return false;
  11514. }
  11515. module.exports = exports.default;
  11516. module.exports.default = exports.default;
  11517. },{"./util/assertString":135}],79:[function(require,module,exports){
  11518. "use strict";
  11519. Object.defineProperty(exports, "__esModule", {
  11520. value: true
  11521. });
  11522. exports.default = isIPRange;
  11523. var _assertString = _interopRequireDefault(require("./util/assertString"));
  11524. var _isIP = _interopRequireDefault(require("./isIP"));
  11525. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11526. var subnetMaybe = /^\d{1,3}$/;
  11527. var v4Subnet = 32;
  11528. var v6Subnet = 128;
  11529. function isIPRange(str) {
  11530. var version = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
  11531. (0, _assertString.default)(str);
  11532. var parts = str.split('/'); // parts[0] -> ip, parts[1] -> subnet
  11533. if (parts.length !== 2) {
  11534. return false;
  11535. }
  11536. if (!subnetMaybe.test(parts[1])) {
  11537. return false;
  11538. } // Disallow preceding 0 i.e. 01, 02, ...
  11539. if (parts[1].length > 1 && parts[1].startsWith('0')) {
  11540. return false;
  11541. }
  11542. var isValidIP = (0, _isIP.default)(parts[0], version);
  11543. if (!isValidIP) {
  11544. return false;
  11545. } // Define valid subnet according to IP's version
  11546. var expectedSubnet = null;
  11547. switch (String(version)) {
  11548. case '4':
  11549. expectedSubnet = v4Subnet;
  11550. break;
  11551. case '6':
  11552. expectedSubnet = v6Subnet;
  11553. break;
  11554. default:
  11555. expectedSubnet = (0, _isIP.default)(parts[0], '6') ? v6Subnet : v4Subnet;
  11556. }
  11557. return parts[1] <= expectedSubnet && parts[1] >= 0;
  11558. }
  11559. module.exports = exports.default;
  11560. module.exports.default = exports.default;
  11561. },{"./isIP":78,"./util/assertString":135}],80:[function(require,module,exports){
  11562. "use strict";
  11563. Object.defineProperty(exports, "__esModule", {
  11564. value: true
  11565. });
  11566. exports.default = isISBN;
  11567. var _assertString = _interopRequireDefault(require("./util/assertString"));
  11568. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11569. var isbn10Maybe = /^(?:[0-9]{9}X|[0-9]{10})$/;
  11570. var isbn13Maybe = /^(?:[0-9]{13})$/;
  11571. var factor = [1, 3];
  11572. function isISBN(str) {
  11573. var version = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
  11574. (0, _assertString.default)(str);
  11575. version = String(version);
  11576. if (!version) {
  11577. return isISBN(str, 10) || isISBN(str, 13);
  11578. }
  11579. var sanitized = str.replace(/[\s-]+/g, '');
  11580. var checksum = 0;
  11581. var i;
  11582. if (version === '10') {
  11583. if (!isbn10Maybe.test(sanitized)) {
  11584. return false;
  11585. }
  11586. for (i = 0; i < 9; i++) {
  11587. checksum += (i + 1) * sanitized.charAt(i);
  11588. }
  11589. if (sanitized.charAt(9) === 'X') {
  11590. checksum += 10 * 10;
  11591. } else {
  11592. checksum += 10 * sanitized.charAt(9);
  11593. }
  11594. if (checksum % 11 === 0) {
  11595. return !!sanitized;
  11596. }
  11597. } else if (version === '13') {
  11598. if (!isbn13Maybe.test(sanitized)) {
  11599. return false;
  11600. }
  11601. for (i = 0; i < 12; i++) {
  11602. checksum += factor[i % 2] * sanitized.charAt(i);
  11603. }
  11604. if (sanitized.charAt(12) - (10 - checksum % 10) % 10 === 0) {
  11605. return !!sanitized;
  11606. }
  11607. }
  11608. return false;
  11609. }
  11610. module.exports = exports.default;
  11611. module.exports.default = exports.default;
  11612. },{"./util/assertString":135}],81:[function(require,module,exports){
  11613. "use strict";
  11614. Object.defineProperty(exports, "__esModule", {
  11615. value: true
  11616. });
  11617. exports.default = isISIN;
  11618. var _assertString = _interopRequireDefault(require("./util/assertString"));
  11619. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11620. var isin = /^[A-Z]{2}[0-9A-Z]{9}[0-9]$/; // this link details how the check digit is calculated:
  11621. // https://www.isin.org/isin-format/. it is a little bit
  11622. // odd in that it works with digits, not numbers. in order
  11623. // to make only one pass through the ISIN characters, the
  11624. // each alpha character is handled as 2 characters within
  11625. // the loop.
  11626. function isISIN(str) {
  11627. (0, _assertString.default)(str);
  11628. if (!isin.test(str)) {
  11629. return false;
  11630. }
  11631. var double = true;
  11632. var sum = 0; // convert values
  11633. for (var i = str.length - 2; i >= 0; i--) {
  11634. if (str[i] >= 'A' && str[i] <= 'Z') {
  11635. var value = str[i].charCodeAt(0) - 55;
  11636. var lo = value % 10;
  11637. var hi = Math.trunc(value / 10); // letters have two digits, so handle the low order
  11638. // and high order digits separately.
  11639. for (var _i = 0, _arr = [lo, hi]; _i < _arr.length; _i++) {
  11640. var digit = _arr[_i];
  11641. if (double) {
  11642. if (digit >= 5) {
  11643. sum += 1 + (digit - 5) * 2;
  11644. } else {
  11645. sum += digit * 2;
  11646. }
  11647. } else {
  11648. sum += digit;
  11649. }
  11650. double = !double;
  11651. }
  11652. } else {
  11653. var _digit = str[i].charCodeAt(0) - '0'.charCodeAt(0);
  11654. if (double) {
  11655. if (_digit >= 5) {
  11656. sum += 1 + (_digit - 5) * 2;
  11657. } else {
  11658. sum += _digit * 2;
  11659. }
  11660. } else {
  11661. sum += _digit;
  11662. }
  11663. double = !double;
  11664. }
  11665. }
  11666. var check = Math.trunc((sum + 9) / 10) * 10 - sum;
  11667. return +str[str.length - 1] === check;
  11668. }
  11669. module.exports = exports.default;
  11670. module.exports.default = exports.default;
  11671. },{"./util/assertString":135}],82:[function(require,module,exports){
  11672. "use strict";
  11673. Object.defineProperty(exports, "__esModule", {
  11674. value: true
  11675. });
  11676. exports.default = isISO31661Alpha2;
  11677. exports.CountryCodes = void 0;
  11678. var _assertString = _interopRequireDefault(require("./util/assertString"));
  11679. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11680. // from https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
  11681. 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']);
  11682. function isISO31661Alpha2(str) {
  11683. (0, _assertString.default)(str);
  11684. return validISO31661Alpha2CountriesCodes.has(str.toUpperCase());
  11685. }
  11686. var CountryCodes = validISO31661Alpha2CountriesCodes;
  11687. exports.CountryCodes = CountryCodes;
  11688. },{"./util/assertString":135}],83:[function(require,module,exports){
  11689. "use strict";
  11690. Object.defineProperty(exports, "__esModule", {
  11691. value: true
  11692. });
  11693. exports.default = isISO31661Alpha3;
  11694. var _assertString = _interopRequireDefault(require("./util/assertString"));
  11695. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11696. // from https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3
  11697. 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']);
  11698. function isISO31661Alpha3(str) {
  11699. (0, _assertString.default)(str);
  11700. return validISO31661Alpha3CountriesCodes.has(str.toUpperCase());
  11701. }
  11702. module.exports = exports.default;
  11703. module.exports.default = exports.default;
  11704. },{"./util/assertString":135}],84:[function(require,module,exports){
  11705. "use strict";
  11706. Object.defineProperty(exports, "__esModule", {
  11707. value: true
  11708. });
  11709. exports.default = isISO4217;
  11710. exports.CurrencyCodes = void 0;
  11711. var _assertString = _interopRequireDefault(require("./util/assertString"));
  11712. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11713. // from https://en.wikipedia.org/wiki/ISO_4217
  11714. 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', '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']);
  11715. function isISO4217(str) {
  11716. (0, _assertString.default)(str);
  11717. return validISO4217CurrencyCodes.has(str.toUpperCase());
  11718. }
  11719. var CurrencyCodes = validISO4217CurrencyCodes;
  11720. exports.CurrencyCodes = CurrencyCodes;
  11721. },{"./util/assertString":135}],85:[function(require,module,exports){
  11722. "use strict";
  11723. Object.defineProperty(exports, "__esModule", {
  11724. value: true
  11725. });
  11726. exports.default = isISO8601;
  11727. var _assertString = _interopRequireDefault(require("./util/assertString"));
  11728. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11729. /* eslint-disable max-len */
  11730. // from http://goo.gl/0ejHHW
  11731. 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)?)?)?)?$/; // same as above, except with a strict 'T' separator between date and time
  11732. 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)?)?)?)?$/;
  11733. /* eslint-enable max-len */
  11734. var isValidDate = function isValidDate(str) {
  11735. // str must have passed the ISO8601 check
  11736. // this check is meant to catch invalid dates
  11737. // like 2009-02-31
  11738. // first check for ordinal dates
  11739. var ordinalMatch = str.match(/^(\d{4})-?(\d{3})([ T]{1}\.*|$)/);
  11740. if (ordinalMatch) {
  11741. var oYear = Number(ordinalMatch[1]);
  11742. var oDay = Number(ordinalMatch[2]); // if is leap year
  11743. if (oYear % 4 === 0 && oYear % 100 !== 0 || oYear % 400 === 0) return oDay <= 366;
  11744. return oDay <= 365;
  11745. }
  11746. var match = str.match(/(\d{4})-?(\d{0,2})-?(\d*)/).map(Number);
  11747. var year = match[1];
  11748. var month = match[2];
  11749. var day = match[3];
  11750. var monthString = month ? "0".concat(month).slice(-2) : month;
  11751. var dayString = day ? "0".concat(day).slice(-2) : day; // create a date object and compare
  11752. var d = new Date("".concat(year, "-").concat(monthString || '01', "-").concat(dayString || '01'));
  11753. if (month && day) {
  11754. return d.getUTCFullYear() === year && d.getUTCMonth() + 1 === month && d.getUTCDate() === day;
  11755. }
  11756. return true;
  11757. };
  11758. function isISO8601(str) {
  11759. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  11760. (0, _assertString.default)(str);
  11761. var check = options.strictSeparator ? iso8601StrictSeparator.test(str) : iso8601.test(str);
  11762. if (check && options.strict) return isValidDate(str);
  11763. return check;
  11764. }
  11765. module.exports = exports.default;
  11766. module.exports.default = exports.default;
  11767. },{"./util/assertString":135}],86:[function(require,module,exports){
  11768. "use strict";
  11769. Object.defineProperty(exports, "__esModule", {
  11770. value: true
  11771. });
  11772. exports.default = isISRC;
  11773. var _assertString = _interopRequireDefault(require("./util/assertString"));
  11774. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11775. // see http://isrc.ifpi.org/en/isrc-standard/code-syntax
  11776. var isrc = /^[A-Z]{2}[0-9A-Z]{3}\d{2}\d{5}$/;
  11777. function isISRC(str) {
  11778. (0, _assertString.default)(str);
  11779. return isrc.test(str);
  11780. }
  11781. module.exports = exports.default;
  11782. module.exports.default = exports.default;
  11783. },{"./util/assertString":135}],87:[function(require,module,exports){
  11784. "use strict";
  11785. Object.defineProperty(exports, "__esModule", {
  11786. value: true
  11787. });
  11788. exports.default = isISSN;
  11789. var _assertString = _interopRequireDefault(require("./util/assertString"));
  11790. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11791. var issn = '^\\d{4}-?\\d{3}[\\dX]$';
  11792. function isISSN(str) {
  11793. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  11794. (0, _assertString.default)(str);
  11795. var testIssn = issn;
  11796. testIssn = options.require_hyphen ? testIssn.replace('?', '') : testIssn;
  11797. testIssn = options.case_sensitive ? new RegExp(testIssn) : new RegExp(testIssn, 'i');
  11798. if (!testIssn.test(str)) {
  11799. return false;
  11800. }
  11801. var digits = str.replace('-', '').toUpperCase();
  11802. var checksum = 0;
  11803. for (var i = 0; i < digits.length; i++) {
  11804. var digit = digits[i];
  11805. checksum += (digit === 'X' ? 10 : +digit) * (8 - i);
  11806. }
  11807. return checksum % 11 === 0;
  11808. }
  11809. module.exports = exports.default;
  11810. module.exports.default = exports.default;
  11811. },{"./util/assertString":135}],88:[function(require,module,exports){
  11812. "use strict";
  11813. Object.defineProperty(exports, "__esModule", {
  11814. value: true
  11815. });
  11816. exports.default = isIdentityCard;
  11817. var _assertString = _interopRequireDefault(require("./util/assertString"));
  11818. var _isInt = _interopRequireDefault(require("./isInt"));
  11819. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11820. var validators = {
  11821. PL: function PL(str) {
  11822. (0, _assertString.default)(str);
  11823. var weightOfDigits = {
  11824. 1: 1,
  11825. 2: 3,
  11826. 3: 7,
  11827. 4: 9,
  11828. 5: 1,
  11829. 6: 3,
  11830. 7: 7,
  11831. 8: 9,
  11832. 9: 1,
  11833. 10: 3,
  11834. 11: 0
  11835. };
  11836. if (str != null && str.length === 11 && (0, _isInt.default)(str, {
  11837. allow_leading_zeroes: true
  11838. })) {
  11839. var digits = str.split('').slice(0, -1);
  11840. var sum = digits.reduce(function (acc, digit, index) {
  11841. return acc + Number(digit) * weightOfDigits[index + 1];
  11842. }, 0);
  11843. var modulo = sum % 10;
  11844. var lastDigit = Number(str.charAt(str.length - 1));
  11845. if (modulo === 0 && lastDigit === 0 || lastDigit === 10 - modulo) {
  11846. return true;
  11847. }
  11848. }
  11849. return false;
  11850. },
  11851. ES: function ES(str) {
  11852. (0, _assertString.default)(str);
  11853. var DNI = /^[0-9X-Z][0-9]{7}[TRWAGMYFPDXBNJZSQVHLCKE]$/;
  11854. var charsValue = {
  11855. X: 0,
  11856. Y: 1,
  11857. Z: 2
  11858. };
  11859. 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']; // sanitize user input
  11860. var sanitized = str.trim().toUpperCase(); // validate the data structure
  11861. if (!DNI.test(sanitized)) {
  11862. return false;
  11863. } // validate the control digit
  11864. var number = sanitized.slice(0, -1).replace(/[X,Y,Z]/g, function (char) {
  11865. return charsValue[char];
  11866. });
  11867. return sanitized.endsWith(controlDigits[number % 23]);
  11868. },
  11869. FI: function FI(str) {
  11870. // https://dvv.fi/en/personal-identity-code#:~:text=control%20character%20for%20a-,personal,-identity%20code%20calculated
  11871. (0, _assertString.default)(str);
  11872. if (str.length !== 11) {
  11873. return false;
  11874. }
  11875. if (!str.match(/^\d{6}[\-A\+]\d{3}[0-9ABCDEFHJKLMNPRSTUVWXY]{1}$/)) {
  11876. return false;
  11877. }
  11878. var checkDigits = '0123456789ABCDEFHJKLMNPRSTUVWXY';
  11879. var idAsNumber = parseInt(str.slice(0, 6), 10) * 1000 + parseInt(str.slice(7, 10), 10);
  11880. var remainder = idAsNumber % 31;
  11881. var checkDigit = checkDigits[remainder];
  11882. return checkDigit === str.slice(10, 11);
  11883. },
  11884. IN: function IN(str) {
  11885. var DNI = /^[1-9]\d{3}\s?\d{4}\s?\d{4}$/; // multiplication table
  11886. 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]]; // permutation table
  11887. 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]]; // sanitize user input
  11888. var sanitized = str.trim(); // validate the data structure
  11889. if (!DNI.test(sanitized)) {
  11890. return false;
  11891. }
  11892. var c = 0;
  11893. var invertedArray = sanitized.replace(/\s/g, '').split('').map(Number).reverse();
  11894. invertedArray.forEach(function (val, i) {
  11895. c = d[c][p[i % 8][val]];
  11896. });
  11897. return c === 0;
  11898. },
  11899. IR: function IR(str) {
  11900. if (!str.match(/^\d{10}$/)) return false;
  11901. str = "0000".concat(str).substr(str.length - 6);
  11902. if (parseInt(str.substr(3, 6), 10) === 0) return false;
  11903. var lastNumber = parseInt(str.substr(9, 1), 10);
  11904. var sum = 0;
  11905. for (var i = 0; i < 9; i++) {
  11906. sum += parseInt(str.substr(i, 1), 10) * (10 - i);
  11907. }
  11908. sum %= 11;
  11909. return sum < 2 && lastNumber === sum || sum >= 2 && lastNumber === 11 - sum;
  11910. },
  11911. IT: function IT(str) {
  11912. if (str.length !== 9) return false;
  11913. if (str === 'CA00000AA') return false; // https://it.wikipedia.org/wiki/Carta_d%27identit%C3%A0_elettronica_italiana
  11914. return str.search(/C[A-Z][0-9]{5}[A-Z]{2}/i) > -1;
  11915. },
  11916. NO: function NO(str) {
  11917. var sanitized = str.trim();
  11918. if (isNaN(Number(sanitized))) return false;
  11919. if (sanitized.length !== 11) return false;
  11920. if (sanitized === '00000000000') return false; // https://no.wikipedia.org/wiki/F%C3%B8dselsnummer
  11921. var f = sanitized.split('').map(Number);
  11922. 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;
  11923. 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;
  11924. if (k1 !== f[9] || k2 !== f[10]) return false;
  11925. return true;
  11926. },
  11927. TH: function TH(str) {
  11928. if (!str.match(/^[1-8]\d{12}$/)) return false; // validate check digit
  11929. var sum = 0;
  11930. for (var i = 0; i < 12; i++) {
  11931. sum += parseInt(str[i], 10) * (13 - i);
  11932. }
  11933. return str[12] === ((11 - sum % 11) % 10).toString();
  11934. },
  11935. LK: function LK(str) {
  11936. var old_nic = /^[1-9]\d{8}[vx]$/i;
  11937. var new_nic = /^[1-9]\d{11}$/i;
  11938. if (str.length === 10 && old_nic.test(str)) return true;else if (str.length === 12 && new_nic.test(str)) return true;
  11939. return false;
  11940. },
  11941. 'he-IL': function heIL(str) {
  11942. var DNI = /^\d{9}$/; // sanitize user input
  11943. var sanitized = str.trim(); // validate the data structure
  11944. if (!DNI.test(sanitized)) {
  11945. return false;
  11946. }
  11947. var id = sanitized;
  11948. var sum = 0,
  11949. incNum;
  11950. for (var i = 0; i < id.length; i++) {
  11951. incNum = Number(id[i]) * (i % 2 + 1); // Multiply number by 1 or 2
  11952. sum += incNum > 9 ? incNum - 9 : incNum; // Sum the digits up and add to total
  11953. }
  11954. return sum % 10 === 0;
  11955. },
  11956. 'ar-LY': function arLY(str) {
  11957. // Libya National Identity Number NIN is 12 digits, the first digit is either 1 or 2
  11958. var NIN = /^(1|2)\d{11}$/; // sanitize user input
  11959. var sanitized = str.trim(); // validate the data structure
  11960. if (!NIN.test(sanitized)) {
  11961. return false;
  11962. }
  11963. return true;
  11964. },
  11965. 'ar-TN': function arTN(str) {
  11966. var DNI = /^\d{8}$/; // sanitize user input
  11967. var sanitized = str.trim(); // validate the data structure
  11968. if (!DNI.test(sanitized)) {
  11969. return false;
  11970. }
  11971. return true;
  11972. },
  11973. 'zh-CN': function zhCN(str) {
  11974. var provincesAndCities = ['11', // 北京
  11975. '12', // 天津
  11976. '13', // 河北
  11977. '14', // 山西
  11978. '15', // 内蒙古
  11979. '21', // 辽宁
  11980. '22', // 吉林
  11981. '23', // 黑龙江
  11982. '31', // 上海
  11983. '32', // 江苏
  11984. '33', // 浙江
  11985. '34', // 安徽
  11986. '35', // 福建
  11987. '36', // 江西
  11988. '37', // 山东
  11989. '41', // 河南
  11990. '42', // 湖北
  11991. '43', // 湖南
  11992. '44', // 广东
  11993. '45', // 广西
  11994. '46', // 海南
  11995. '50', // 重庆
  11996. '51', // 四川
  11997. '52', // 贵州
  11998. '53', // 云南
  11999. '54', // 西藏
  12000. '61', // 陕西
  12001. '62', // 甘肃
  12002. '63', // 青海
  12003. '64', // 宁夏
  12004. '65', // 新疆
  12005. '71', // 台湾
  12006. '81', // 香港
  12007. '82', // 澳门
  12008. '91' // 国外
  12009. ];
  12010. var powers = ['7', '9', '10', '5', '8', '4', '2', '1', '6', '3', '7', '9', '10', '5', '8', '4', '2'];
  12011. var parityBit = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'];
  12012. var checkAddressCode = function checkAddressCode(addressCode) {
  12013. return provincesAndCities.includes(addressCode);
  12014. };
  12015. var checkBirthDayCode = function checkBirthDayCode(birDayCode) {
  12016. var yyyy = parseInt(birDayCode.substring(0, 4), 10);
  12017. var mm = parseInt(birDayCode.substring(4, 6), 10);
  12018. var dd = parseInt(birDayCode.substring(6), 10);
  12019. var xdata = new Date(yyyy, mm - 1, dd);
  12020. if (xdata > new Date()) {
  12021. return false; // eslint-disable-next-line max-len
  12022. } else if (xdata.getFullYear() === yyyy && xdata.getMonth() === mm - 1 && xdata.getDate() === dd) {
  12023. return true;
  12024. }
  12025. return false;
  12026. };
  12027. var getParityBit = function getParityBit(idCardNo) {
  12028. var id17 = idCardNo.substring(0, 17);
  12029. var power = 0;
  12030. for (var i = 0; i < 17; i++) {
  12031. power += parseInt(id17.charAt(i), 10) * parseInt(powers[i], 10);
  12032. }
  12033. var mod = power % 11;
  12034. return parityBit[mod];
  12035. };
  12036. var checkParityBit = function checkParityBit(idCardNo) {
  12037. return getParityBit(idCardNo) === idCardNo.charAt(17).toUpperCase();
  12038. };
  12039. var check15IdCardNo = function check15IdCardNo(idCardNo) {
  12040. 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);
  12041. if (!check) return false;
  12042. var addressCode = idCardNo.substring(0, 2);
  12043. check = checkAddressCode(addressCode);
  12044. if (!check) return false;
  12045. var birDayCode = "19".concat(idCardNo.substring(6, 12));
  12046. check = checkBirthDayCode(birDayCode);
  12047. if (!check) return false;
  12048. return true;
  12049. };
  12050. var check18IdCardNo = function check18IdCardNo(idCardNo) {
  12051. 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);
  12052. if (!check) return false;
  12053. var addressCode = idCardNo.substring(0, 2);
  12054. check = checkAddressCode(addressCode);
  12055. if (!check) return false;
  12056. var birDayCode = idCardNo.substring(6, 14);
  12057. check = checkBirthDayCode(birDayCode);
  12058. if (!check) return false;
  12059. return checkParityBit(idCardNo);
  12060. };
  12061. var checkIdCardNo = function checkIdCardNo(idCardNo) {
  12062. var check = /^\d{15}|(\d{17}(\d|x|X))$/.test(idCardNo);
  12063. if (!check) return false;
  12064. if (idCardNo.length === 15) {
  12065. return check15IdCardNo(idCardNo);
  12066. }
  12067. return check18IdCardNo(idCardNo);
  12068. };
  12069. return checkIdCardNo(str);
  12070. },
  12071. 'zh-TW': function zhTW(str) {
  12072. var ALPHABET_CODES = {
  12073. A: 10,
  12074. B: 11,
  12075. C: 12,
  12076. D: 13,
  12077. E: 14,
  12078. F: 15,
  12079. G: 16,
  12080. H: 17,
  12081. I: 34,
  12082. J: 18,
  12083. K: 19,
  12084. L: 20,
  12085. M: 21,
  12086. N: 22,
  12087. O: 35,
  12088. P: 23,
  12089. Q: 24,
  12090. R: 25,
  12091. S: 26,
  12092. T: 27,
  12093. U: 28,
  12094. V: 29,
  12095. W: 32,
  12096. X: 30,
  12097. Y: 31,
  12098. Z: 33
  12099. };
  12100. var sanitized = str.trim().toUpperCase();
  12101. if (!/^[A-Z][0-9]{9}$/.test(sanitized)) return false;
  12102. return Array.from(sanitized).reduce(function (sum, number, index) {
  12103. if (index === 0) {
  12104. var code = ALPHABET_CODES[number];
  12105. return code % 10 * 9 + Math.floor(code / 10);
  12106. }
  12107. if (index === 9) {
  12108. return (10 - sum % 10 - Number(number)) % 10 === 0;
  12109. }
  12110. return sum + Number(number) * (9 - index);
  12111. }, 0);
  12112. }
  12113. };
  12114. function isIdentityCard(str, locale) {
  12115. (0, _assertString.default)(str);
  12116. if (locale in validators) {
  12117. return validators[locale](str);
  12118. } else if (locale === 'any') {
  12119. for (var key in validators) {
  12120. // https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md#ignoring-code-for-coverage-purposes
  12121. // istanbul ignore else
  12122. if (validators.hasOwnProperty(key)) {
  12123. var validator = validators[key];
  12124. if (validator(str)) {
  12125. return true;
  12126. }
  12127. }
  12128. }
  12129. return false;
  12130. }
  12131. throw new Error("Invalid locale '".concat(locale, "'"));
  12132. }
  12133. module.exports = exports.default;
  12134. module.exports.default = exports.default;
  12135. },{"./isInt":90,"./util/assertString":135}],89:[function(require,module,exports){
  12136. "use strict";
  12137. Object.defineProperty(exports, "__esModule", {
  12138. value: true
  12139. });
  12140. exports.default = isIn;
  12141. var _assertString = _interopRequireDefault(require("./util/assertString"));
  12142. var _toString = _interopRequireDefault(require("./util/toString"));
  12143. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  12144. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  12145. function isIn(str, options) {
  12146. (0, _assertString.default)(str);
  12147. var i;
  12148. if (Object.prototype.toString.call(options) === '[object Array]') {
  12149. var array = [];
  12150. for (i in options) {
  12151. // https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md#ignoring-code-for-coverage-purposes
  12152. // istanbul ignore else
  12153. if ({}.hasOwnProperty.call(options, i)) {
  12154. array[i] = (0, _toString.default)(options[i]);
  12155. }
  12156. }
  12157. return array.indexOf(str) >= 0;
  12158. } else if (_typeof(options) === 'object') {
  12159. return options.hasOwnProperty(str);
  12160. } else if (options && typeof options.indexOf === 'function') {
  12161. return options.indexOf(str) >= 0;
  12162. }
  12163. return false;
  12164. }
  12165. module.exports = exports.default;
  12166. module.exports.default = exports.default;
  12167. },{"./util/assertString":135,"./util/toString":139}],90:[function(require,module,exports){
  12168. "use strict";
  12169. Object.defineProperty(exports, "__esModule", {
  12170. value: true
  12171. });
  12172. exports.default = isInt;
  12173. var _assertString = _interopRequireDefault(require("./util/assertString"));
  12174. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  12175. var int = /^(?:[-+]?(?:0|[1-9][0-9]*))$/;
  12176. var intLeadingZeroes = /^[-+]?[0-9]+$/;
  12177. function isInt(str, options) {
  12178. (0, _assertString.default)(str);
  12179. options = options || {}; // Get the regex to use for testing, based on whether
  12180. // leading zeroes are allowed or not.
  12181. var regex = options.hasOwnProperty('allow_leading_zeroes') && !options.allow_leading_zeroes ? int : intLeadingZeroes; // Check min/max/lt/gt
  12182. var minCheckPassed = !options.hasOwnProperty('min') || str >= options.min;
  12183. var maxCheckPassed = !options.hasOwnProperty('max') || str <= options.max;
  12184. var ltCheckPassed = !options.hasOwnProperty('lt') || str < options.lt;
  12185. var gtCheckPassed = !options.hasOwnProperty('gt') || str > options.gt;
  12186. return regex.test(str) && minCheckPassed && maxCheckPassed && ltCheckPassed && gtCheckPassed;
  12187. }
  12188. module.exports = exports.default;
  12189. module.exports.default = exports.default;
  12190. },{"./util/assertString":135}],91:[function(require,module,exports){
  12191. "use strict";
  12192. Object.defineProperty(exports, "__esModule", {
  12193. value: true
  12194. });
  12195. exports.default = isJSON;
  12196. var _assertString = _interopRequireDefault(require("./util/assertString"));
  12197. var _merge = _interopRequireDefault(require("./util/merge"));
  12198. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  12199. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  12200. var default_json_options = {
  12201. allow_primitives: false
  12202. };
  12203. function isJSON(str, options) {
  12204. (0, _assertString.default)(str);
  12205. try {
  12206. options = (0, _merge.default)(options, default_json_options);
  12207. var primitives = [];
  12208. if (options.allow_primitives) {
  12209. primitives = [null, false, true];
  12210. }
  12211. var obj = JSON.parse(str);
  12212. return primitives.includes(obj) || !!obj && _typeof(obj) === 'object';
  12213. } catch (e) {
  12214. /* ignore */
  12215. }
  12216. return false;
  12217. }
  12218. module.exports = exports.default;
  12219. module.exports.default = exports.default;
  12220. },{"./util/assertString":135,"./util/merge":137}],92:[function(require,module,exports){
  12221. "use strict";
  12222. Object.defineProperty(exports, "__esModule", {
  12223. value: true
  12224. });
  12225. exports.default = isJWT;
  12226. var _assertString = _interopRequireDefault(require("./util/assertString"));
  12227. var _isBase = _interopRequireDefault(require("./isBase64"));
  12228. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  12229. function isJWT(str) {
  12230. (0, _assertString.default)(str);
  12231. var dotSplit = str.split('.');
  12232. var len = dotSplit.length;
  12233. if (len > 3 || len < 2) {
  12234. return false;
  12235. }
  12236. return dotSplit.reduce(function (acc, currElem) {
  12237. return acc && (0, _isBase.default)(currElem, {
  12238. urlSafe: true
  12239. });
  12240. }, true);
  12241. }
  12242. module.exports = exports.default;
  12243. module.exports.default = exports.default;
  12244. },{"./isBase64":53,"./util/assertString":135}],93:[function(require,module,exports){
  12245. "use strict";
  12246. Object.defineProperty(exports, "__esModule", {
  12247. value: true
  12248. });
  12249. exports.default = isLatLong;
  12250. var _assertString = _interopRequireDefault(require("./util/assertString"));
  12251. var _merge = _interopRequireDefault(require("./util/merge"));
  12252. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  12253. var lat = /^\(?[+-]?(90(\.0+)?|[1-8]?\d(\.\d+)?)$/;
  12254. var long = /^\s?[+-]?(180(\.0+)?|1[0-7]\d(\.\d+)?|\d{1,2}(\.\d+)?)\)?$/;
  12255. var latDMS = /^(([1-8]?\d)\D+([1-5]?\d|60)\D+([1-5]?\d|60)(\.\d+)?|90\D+0\D+0)\D+[NSns]?$/i;
  12256. 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;
  12257. var defaultLatLongOptions = {
  12258. checkDMS: false
  12259. };
  12260. function isLatLong(str, options) {
  12261. (0, _assertString.default)(str);
  12262. options = (0, _merge.default)(options, defaultLatLongOptions);
  12263. if (!str.includes(',')) return false;
  12264. var pair = str.split(',');
  12265. if (pair[0].startsWith('(') && !pair[1].endsWith(')') || pair[1].endsWith(')') && !pair[0].startsWith('(')) return false;
  12266. if (options.checkDMS) {
  12267. return latDMS.test(pair[0]) && longDMS.test(pair[1]);
  12268. }
  12269. return lat.test(pair[0]) && long.test(pair[1]);
  12270. }
  12271. module.exports = exports.default;
  12272. module.exports.default = exports.default;
  12273. },{"./util/assertString":135,"./util/merge":137}],94:[function(require,module,exports){
  12274. "use strict";
  12275. Object.defineProperty(exports, "__esModule", {
  12276. value: true
  12277. });
  12278. exports.default = isLength;
  12279. var _assertString = _interopRequireDefault(require("./util/assertString"));
  12280. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  12281. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  12282. /* eslint-disable prefer-rest-params */
  12283. function isLength(str, options) {
  12284. (0, _assertString.default)(str);
  12285. var min;
  12286. var max;
  12287. if (_typeof(options) === 'object') {
  12288. min = options.min || 0;
  12289. max = options.max;
  12290. } else {
  12291. // backwards compatibility: isLength(str, min [, max])
  12292. min = arguments[1] || 0;
  12293. max = arguments[2];
  12294. }
  12295. var surrogatePairs = str.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g) || [];
  12296. var len = str.length - surrogatePairs.length;
  12297. return len >= min && (typeof max === 'undefined' || len <= max);
  12298. }
  12299. module.exports = exports.default;
  12300. module.exports.default = exports.default;
  12301. },{"./util/assertString":135}],95:[function(require,module,exports){
  12302. "use strict";
  12303. Object.defineProperty(exports, "__esModule", {
  12304. value: true
  12305. });
  12306. exports.default = isLicensePlate;
  12307. var _assertString = _interopRequireDefault(require("./util/assertString"));
  12308. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  12309. var validators = {
  12310. 'cs-CZ': function csCZ(str) {
  12311. return /^(([ABCDEFHKIJKLMNPRSTUVXYZ]|[0-9])-?){5,8}$/.test(str);
  12312. },
  12313. 'de-DE': function deDE(str) {
  12314. return /^((AW|UL|AK|GA|AÖ|LF|AZ|AM|AS|ZE|AN|AB|A|KG|KH|BA|EW|BZ|HY|KM|BT|HP|B|BC|BI|BO|FN|TT|ÜB|BN|AH|BS|FR|HB|ZZ|BB|BK|BÖ|OC|OK|CW|CE|C|CO|LH|CB|KW|LC|LN|DA|DI|DE|DH|SY|NÖ|DO|DD|DU|DN|D|EI|EA|EE|FI|EM|EL|EN|PF|ED|EF|ER|AU|ZP|E|ES|NT|EU|FL|FO|FT|FF|F|FS|FD|FÜ|GE|G|GI|GF|GS|ZR|GG|GP|GR|NY|ZI|GÖ|GZ|GT|HA|HH|HM|HU|WL|HZ|WR|RN|HK|HD|HN|HS|GK|HE|HF|RZ|HI|HG|HO|HX|IK|IL|IN|J|JL|KL|KA|KS|KF|KE|KI|KT|KO|KN|KR|KC|KU|K|LD|LL|LA|L|OP|LM|LI|LB|LU|LÖ|HL|LG|MD|GN|MZ|MA|ML|MR|MY|AT|DM|MC|NZ|RM|RG|MM|ME|MB|MI|FG|DL|HC|MW|RL|MK|MG|MÜ|WS|MH|M|MS|NU|NB|ND|NM|NK|NW|NR|NI|NF|DZ|EB|OZ|TG|TO|N|OA|GM|OB|CA|EH|FW|OF|OL|OE|OG|BH|LR|OS|AA|GD|OH|KY|NP|WK|PB|PA|PE|PI|PS|P|PM|PR|RA|RV|RE|R|H|SB|WN|RS|RD|RT|BM|NE|GV|RP|SU|GL|RO|GÜ|RH|EG|RW|PN|SK|MQ|RU|SZ|RI|SL|SM|SC|HR|FZ|VS|SW|SN|CR|SE|SI|SO|LP|SG|NH|SP|IZ|ST|BF|TE|HV|OD|SR|S|AC|DW|ZW|TF|TS|TR|TÜ|UM|PZ|TP|UE|UN|UH|MN|KK|VB|V|AE|PL|RC|VG|GW|PW|VR|VK|KB|WA|WT|BE|WM|WE|AP|MO|WW|FB|WZ|WI|WB|JE|WF|WO|W|WÜ|BL|Z|GC)[- ]?[A-Z]{1,2}[- ]?\d{1,4}|(AIC|FDB|ABG|SLN|SAW|KLZ|BUL|ESB|NAB|SUL|WST|ABI|AZE|BTF|KÖT|DKB|FEU|ROT|ALZ|SMÜ|WER|AUR|NOR|DÜW|BRK|HAB|TÖL|WOR|BAD|BAR|BER|BIW|EBS|KEM|MÜB|PEG|BGL|BGD|REI|WIL|BKS|BIR|WAT|BOR|BOH|BOT|BRB|BLK|HHM|NEB|NMB|WSF|LEO|HDL|WMS|WZL|BÜS|CHA|KÖZ|ROD|WÜM|CLP|NEC|COC|ZEL|COE|CUX|DAH|LDS|DEG|DEL|RSL|DLG|DGF|LAN|HEI|MED|DON|KIB|ROK|JÜL|MON|SLE|EBE|EIC|HIG|WBS|BIT|PRÜ|LIB|EMD|WIT|ERH|HÖS|ERZ|ANA|ASZ|MAB|MEK|STL|SZB|FDS|HCH|HOR|WOL|FRG|GRA|WOS|FRI|FFB|GAP|GER|BRL|CLZ|GTH|NOH|HGW|GRZ|LÖB|NOL|WSW|DUD|HMÜ|OHA|KRU|HAL|HAM|HBS|QLB|HVL|NAU|HAS|EBN|GEO|HOH|HDH|ERK|HER|WAN|HEF|ROF|HBN|ALF|HSK|USI|NAI|REH|SAN|KÜN|ÖHR|HOL|WAR|ARN|BRG|GNT|HOG|WOH|KEH|MAI|PAR|RID|ROL|KLE|GEL|KUS|KYF|ART|SDH|LDK|DIL|MAL|VIB|LER|BNA|GHA|GRM|MTL|WUR|LEV|LIF|STE|WEL|LIP|VAI|LUP|HGN|LBZ|LWL|PCH|STB|DAN|MKK|SLÜ|MSP|TBB|MGH|MTK|BIN|MSH|EIL|HET|SGH|BID|MYK|MSE|MST|MÜR|WRN|MEI|GRH|RIE|MZG|MIL|OBB|BED|FLÖ|MOL|FRW|SEE|SRB|AIB|MOS|BCH|ILL|SOB|NMS|NEA|SEF|UFF|NEW|VOH|NDH|TDO|NWM|GDB|GVM|WIS|NOM|EIN|GAN|LAU|HEB|OHV|OSL|SFB|ERB|LOS|BSK|KEL|BSB|MEL|WTL|OAL|FÜS|MOD|OHZ|OPR|BÜR|PAF|PLÖ|CAS|GLA|REG|VIT|ECK|SIM|GOA|EMS|DIZ|GOH|RÜD|SWA|NES|KÖN|MET|LRO|BÜZ|DBR|ROS|TET|HRO|ROW|BRV|HIP|PAN|GRI|SHK|EIS|SRO|SOK|LBS|SCZ|MER|QFT|SLF|SLS|HOM|SLK|ASL|BBG|SBK|SFT|SHG|MGN|MEG|ZIG|SAD|NEN|OVI|SHA|BLB|SIG|SON|SPN|FOR|GUB|SPB|IGB|WND|STD|STA|SDL|OBG|HST|BOG|SHL|PIR|FTL|SEB|SÖM|SÜW|TIR|SAB|TUT|ANG|SDT|LÜN|LSZ|MHL|VEC|VER|VIE|OVL|ANK|OVP|SBG|UEM|UER|WLG|GMN|NVP|RDG|RÜG|DAU|FKB|WAF|WAK|SLZ|WEN|SOG|APD|WUG|GUN|ESW|WIZ|WES|DIN|BRA|BÜD|WHV|HWI|GHC|WTM|WOB|WUN|MAK|SEL|OCH|HOT|WDA)[- ]?(([A-Z][- ]?\d{1,4})|([A-Z]{2}[- ]?\d{1,3})))[- ]?(E|H)?$/.test(str);
  12315. },
  12316. 'de-LI': function deLI(str) {
  12317. return /^FL[- ]?\d{1,5}[UZ]?$/.test(str);
  12318. },
  12319. 'fi-FI': function fiFI(str) {
  12320. return /^(?=.{4,7})(([A-Z]{1,3}|[0-9]{1,3})[\s-]?([A-Z]{1,3}|[0-9]{1,5}))$/.test(str);
  12321. },
  12322. 'pt-PT': function ptPT(str) {
  12323. return /^([A-Z]{2}|[0-9]{2})[ -·]?([A-Z]{2}|[0-9]{2})[ -·]?([A-Z]{2}|[0-9]{2})$/.test(str);
  12324. },
  12325. 'sq-AL': function sqAL(str) {
  12326. return /^[A-Z]{2}[- ]?((\d{3}[- ]?(([A-Z]{2})|T))|(R[- ]?\d{3}))$/.test(str);
  12327. },
  12328. 'pt-BR': function ptBR(str) {
  12329. return /^[A-Z]{3}[ -]?[0-9][A-Z][0-9]{2}|[A-Z]{3}[ -]?[0-9]{4}$/.test(str);
  12330. }
  12331. };
  12332. function isLicensePlate(str, locale) {
  12333. (0, _assertString.default)(str);
  12334. if (locale in validators) {
  12335. return validators[locale](str);
  12336. } else if (locale === 'any') {
  12337. for (var key in validators) {
  12338. /* eslint guard-for-in: 0 */
  12339. var validator = validators[key];
  12340. if (validator(str)) {
  12341. return true;
  12342. }
  12343. }
  12344. return false;
  12345. }
  12346. throw new Error("Invalid locale '".concat(locale, "'"));
  12347. }
  12348. module.exports = exports.default;
  12349. module.exports.default = exports.default;
  12350. },{"./util/assertString":135}],96:[function(require,module,exports){
  12351. "use strict";
  12352. Object.defineProperty(exports, "__esModule", {
  12353. value: true
  12354. });
  12355. exports.default = isLocale;
  12356. var _assertString = _interopRequireDefault(require("./util/assertString"));
  12357. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  12358. var localeReg = /^[A-Za-z]{2,4}([_-]([A-Za-z]{4}|[\d]{3}))?([_-]([A-Za-z]{2}|[\d]{3}))?$/;
  12359. function isLocale(str) {
  12360. (0, _assertString.default)(str);
  12361. if (str === 'en_US_POSIX' || str === 'ca_ES_VALENCIA') {
  12362. return true;
  12363. }
  12364. return localeReg.test(str);
  12365. }
  12366. module.exports = exports.default;
  12367. module.exports.default = exports.default;
  12368. },{"./util/assertString":135}],97:[function(require,module,exports){
  12369. "use strict";
  12370. Object.defineProperty(exports, "__esModule", {
  12371. value: true
  12372. });
  12373. exports.default = isLowercase;
  12374. var _assertString = _interopRequireDefault(require("./util/assertString"));
  12375. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  12376. function isLowercase(str) {
  12377. (0, _assertString.default)(str);
  12378. return str === str.toLowerCase();
  12379. }
  12380. module.exports = exports.default;
  12381. module.exports.default = exports.default;
  12382. },{"./util/assertString":135}],98:[function(require,module,exports){
  12383. "use strict";
  12384. Object.defineProperty(exports, "__esModule", {
  12385. value: true
  12386. });
  12387. exports.default = isMACAddress;
  12388. var _assertString = _interopRequireDefault(require("./util/assertString"));
  12389. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  12390. var macAddress = /^(?:[0-9a-fA-F]{2}([-:\s]))([0-9a-fA-F]{2}\1){4}([0-9a-fA-F]{2})$/;
  12391. var macAddressNoSeparators = /^([0-9a-fA-F]){12}$/;
  12392. var macAddressWithDots = /^([0-9a-fA-F]{4}\.){2}([0-9a-fA-F]{4})$/;
  12393. function isMACAddress(str, options) {
  12394. (0, _assertString.default)(str);
  12395. /**
  12396. * @deprecated `no_colons` TODO: remove it in the next major
  12397. */
  12398. if (options && (options.no_colons || options.no_separators)) {
  12399. return macAddressNoSeparators.test(str);
  12400. }
  12401. return macAddress.test(str) || macAddressWithDots.test(str);
  12402. }
  12403. module.exports = exports.default;
  12404. module.exports.default = exports.default;
  12405. },{"./util/assertString":135}],99:[function(require,module,exports){
  12406. "use strict";
  12407. Object.defineProperty(exports, "__esModule", {
  12408. value: true
  12409. });
  12410. exports.default = isMD5;
  12411. var _assertString = _interopRequireDefault(require("./util/assertString"));
  12412. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  12413. var md5 = /^[a-f0-9]{32}$/;
  12414. function isMD5(str) {
  12415. (0, _assertString.default)(str);
  12416. return md5.test(str);
  12417. }
  12418. module.exports = exports.default;
  12419. module.exports.default = exports.default;
  12420. },{"./util/assertString":135}],100:[function(require,module,exports){
  12421. "use strict";
  12422. Object.defineProperty(exports, "__esModule", {
  12423. value: true
  12424. });
  12425. exports.default = isMagnetURI;
  12426. var _assertString = _interopRequireDefault(require("./util/assertString"));
  12427. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  12428. var magnetURI = /^magnet:\?xt(?:\.1)?=urn:(?:aich|bitprint|btih|ed2k|ed2khash|kzhash|md5|sha1|tree:tiger):[a-z0-9]{32}(?:[a-z0-9]{8})?($|&)/i;
  12429. function isMagnetURI(url) {
  12430. (0, _assertString.default)(url);
  12431. return magnetURI.test(url.trim());
  12432. }
  12433. module.exports = exports.default;
  12434. module.exports.default = exports.default;
  12435. },{"./util/assertString":135}],101:[function(require,module,exports){
  12436. "use strict";
  12437. Object.defineProperty(exports, "__esModule", {
  12438. value: true
  12439. });
  12440. exports.default = isMimeType;
  12441. var _assertString = _interopRequireDefault(require("./util/assertString"));
  12442. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  12443. /*
  12444. Checks if the provided string matches to a correct Media type format (MIME type)
  12445. This function only checks is the string format follows the
  12446. etablished rules by the according RFC specifications.
  12447. This function supports 'charset' in textual media types
  12448. (https://tools.ietf.org/html/rfc6657).
  12449. This function does not check against all the media types listed
  12450. by the IANA (https://www.iana.org/assignments/media-types/media-types.xhtml)
  12451. because of lightness purposes : it would require to include
  12452. all these MIME types in this librairy, which would weigh it
  12453. significantly. This kind of effort maybe is not worth for the use that
  12454. this function has in this entire librairy.
  12455. More informations in the RFC specifications :
  12456. - https://tools.ietf.org/html/rfc2045
  12457. - https://tools.ietf.org/html/rfc2046
  12458. - https://tools.ietf.org/html/rfc7231#section-3.1.1.1
  12459. - https://tools.ietf.org/html/rfc7231#section-3.1.1.5
  12460. */
  12461. // Match simple MIME types
  12462. // NB :
  12463. // Subtype length must not exceed 100 characters.
  12464. // This rule does not comply to the RFC specs (what is the max length ?).
  12465. var mimeTypeSimple = /^(application|audio|font|image|message|model|multipart|text|video)\/[a-zA-Z0-9\.\-\+]{1,100}$/i; // eslint-disable-line max-len
  12466. // Handle "charset" in "text/*"
  12467. 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
  12468. // Handle "boundary" in "multipart/*"
  12469. 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
  12470. function isMimeType(str) {
  12471. (0, _assertString.default)(str);
  12472. return mimeTypeSimple.test(str) || mimeTypeText.test(str) || mimeTypeMultipart.test(str);
  12473. }
  12474. module.exports = exports.default;
  12475. module.exports.default = exports.default;
  12476. },{"./util/assertString":135}],102:[function(require,module,exports){
  12477. "use strict";
  12478. Object.defineProperty(exports, "__esModule", {
  12479. value: true
  12480. });
  12481. exports.default = isMobilePhone;
  12482. exports.locales = void 0;
  12483. var _assertString = _interopRequireDefault(require("./util/assertString"));
  12484. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  12485. /* eslint-disable max-len */
  12486. var phones = {
  12487. 'am-AM': /^(\+?374|0)((10|[9|7][0-9])\d{6}$|[2-4]\d{7}$)/,
  12488. 'ar-AE': /^((\+?971)|0)?5[024568]\d{7}$/,
  12489. 'ar-BH': /^(\+?973)?(3|6)\d{7}$/,
  12490. 'ar-DZ': /^(\+?213|0)(5|6|7)\d{8}$/,
  12491. 'ar-LB': /^(\+?961)?((3|81)\d{6}|7\d{7})$/,
  12492. 'ar-EG': /^((\+?20)|0)?1[0125]\d{8}$/,
  12493. 'ar-IQ': /^(\+?964|0)?7[0-9]\d{8}$/,
  12494. 'ar-JO': /^(\+?962|0)?7[789]\d{7}$/,
  12495. 'ar-KW': /^(\+?965)[569]\d{7}$/,
  12496. 'ar-LY': /^((\+?218)|0)?(9[1-6]\d{7}|[1-8]\d{7,9})$/,
  12497. 'ar-MA': /^(?:(?:\+|00)212|0)[5-7]\d{8}$/,
  12498. 'ar-OM': /^((\+|00)968)?(9[1-9])\d{6}$/,
  12499. 'ar-PS': /^(\+?970|0)5[6|9](\d{7})$/,
  12500. 'ar-SA': /^(!?(\+?966)|0)?5\d{8}$/,
  12501. 'ar-SY': /^(!?(\+?963)|0)?9\d{8}$/,
  12502. 'ar-TN': /^(\+?216)?[2459]\d{7}$/,
  12503. 'az-AZ': /^(\+994|0)(5[015]|7[07]|99)\d{7}$/,
  12504. 'bs-BA': /^((((\+|00)3876)|06))((([0-3]|[5-6])\d{6})|(4\d{7}))$/,
  12505. 'be-BY': /^(\+?375)?(24|25|29|33|44)\d{7}$/,
  12506. 'bg-BG': /^(\+?359|0)?8[789]\d{7}$/,
  12507. 'bn-BD': /^(\+?880|0)1[13456789][0-9]{8}$/,
  12508. 'ca-AD': /^(\+376)?[346]\d{5}$/,
  12509. 'cs-CZ': /^(\+?420)? ?[1-9][0-9]{2} ?[0-9]{3} ?[0-9]{3}$/,
  12510. 'da-DK': /^(\+?45)?\s?\d{2}\s?\d{2}\s?\d{2}\s?\d{2}$/,
  12511. 'de-DE': /^((\+49|0)[1|3])([0|5][0-45-9]\d|6([23]|0\d?)|7([0-57-9]|6\d))\d{7,9}$/,
  12512. 'de-AT': /^(\+43|0)\d{1,4}\d{3,12}$/,
  12513. 'de-CH': /^(\+41|0)([1-9])\d{1,9}$/,
  12514. 'de-LU': /^(\+352)?((6\d1)\d{6})$/,
  12515. 'dv-MV': /^(\+?960)?(7[2-9]|91|9[3-9])\d{7}$/,
  12516. 'el-GR': /^(\+?30|0)?(69\d{8})$/,
  12517. 'en-AU': /^(\+?61|0)4\d{8}$/,
  12518. 'en-BM': /^(\+?1)?441(((3|7)\d{6}$)|(5[0-3][0-9]\d{4}$)|(59\d{5}))/,
  12519. 'en-GB': /^(\+?44|0)7\d{9}$/,
  12520. 'en-GG': /^(\+?44|0)1481\d{6}$/,
  12521. 'en-GH': /^(\+233|0)(20|50|24|54|27|57|26|56|23|28|55|59)\d{7}$/,
  12522. 'en-GY': /^(\+592|0)6\d{6}$/,
  12523. 'en-HK': /^(\+?852[-\s]?)?[456789]\d{3}[-\s]?\d{4}$/,
  12524. 'en-MO': /^(\+?853[-\s]?)?[6]\d{3}[-\s]?\d{4}$/,
  12525. 'en-IE': /^(\+?353|0)8[356789]\d{7}$/,
  12526. 'en-IN': /^(\+?91|0)?[6789]\d{9}$/,
  12527. 'en-KE': /^(\+?254|0)(7|1)\d{8}$/,
  12528. 'en-KI': /^((\+686|686)?)?( )?((6|7)(2|3|8)[0-9]{6})$/,
  12529. 'en-MT': /^(\+?356|0)?(99|79|77|21|27|22|25)[0-9]{6}$/,
  12530. 'en-MU': /^(\+?230|0)?\d{8}$/,
  12531. 'en-NA': /^(\+?264|0)(6|8)\d{7}$/,
  12532. 'en-NG': /^(\+?234|0)?[789]\d{9}$/,
  12533. 'en-NZ': /^(\+?64|0)[28]\d{7,9}$/,
  12534. 'en-PK': /^((00|\+)?92|0)3[0-6]\d{8}$/,
  12535. 'en-PH': /^(09|\+639)\d{9}$/,
  12536. 'en-RW': /^(\+?250|0)?[7]\d{8}$/,
  12537. 'en-SG': /^(\+65)?[3689]\d{7}$/,
  12538. 'en-SL': /^(\+?232|0)\d{8}$/,
  12539. 'en-TZ': /^(\+?255|0)?[67]\d{8}$/,
  12540. 'en-UG': /^(\+?256|0)?[7]\d{8}$/,
  12541. 'en-US': /^((\+1|1)?( |-)?)?(\([2-9][0-9]{2}\)|[2-9][0-9]{2})( |-)?([2-9][0-9]{2}( |-)?[0-9]{4})$/,
  12542. 'en-ZA': /^(\+?27|0)\d{9}$/,
  12543. 'en-ZM': /^(\+?26)?09[567]\d{7}$/,
  12544. 'en-ZW': /^(\+263)[0-9]{9}$/,
  12545. 'en-BW': /^(\+?267)?(7[1-8]{1})\d{6}$/,
  12546. 'es-AR': /^\+?549(11|[2368]\d)\d{8}$/,
  12547. 'es-BO': /^(\+?591)?(6|7)\d{7}$/,
  12548. 'es-CO': /^(\+?57)?3(0(0|1|2|4|5)|1\d|2[0-4]|5(0|1))\d{7}$/,
  12549. 'es-CL': /^(\+?56|0)[2-9]\d{1}\d{7}$/,
  12550. 'es-CR': /^(\+506)?[2-8]\d{7}$/,
  12551. 'es-CU': /^(\+53|0053)?5\d{7}/,
  12552. 'es-DO': /^(\+?1)?8[024]9\d{7}$/,
  12553. 'es-HN': /^(\+?504)?[9|8]\d{7}$/,
  12554. 'es-EC': /^(\+?593|0)([2-7]|9[2-9])\d{7}$/,
  12555. 'es-ES': /^(\+?34)?[6|7]\d{8}$/,
  12556. 'es-PE': /^(\+?51)?9\d{8}$/,
  12557. 'es-MX': /^(\+?52)?(1|01)?\d{10,11}$/,
  12558. 'es-PA': /^(\+?507)\d{7,8}$/,
  12559. 'es-PY': /^(\+?595|0)9[9876]\d{7}$/,
  12560. 'es-SV': /^(\+?503)?[67]\d{7}$/,
  12561. 'es-UY': /^(\+598|0)9[1-9][\d]{6}$/,
  12562. 'es-VE': /^(\+?58)?(2|4)\d{9}$/,
  12563. 'et-EE': /^(\+?372)?\s?(5|8[1-4])\s?([0-9]\s?){6,7}$/,
  12564. 'fa-IR': /^(\+?98[\-\s]?|0)9[0-39]\d[\-\s]?\d{3}[\-\s]?\d{4}$/,
  12565. 'fi-FI': /^(\+?358|0)\s?(4(0|1|2|4|5|6)?|50)\s?(\d\s?){4,8}\d$/,
  12566. 'fj-FJ': /^(\+?679)?\s?\d{3}\s?\d{4}$/,
  12567. 'fo-FO': /^(\+?298)?\s?\d{2}\s?\d{2}\s?\d{2}$/,
  12568. 'fr-BF': /^(\+226|0)[67]\d{7}$/,
  12569. 'fr-CM': /^(\+?237)6[0-9]{8}$/,
  12570. 'fr-FR': /^(\+?33|0)[67]\d{8}$/,
  12571. 'fr-GF': /^(\+?594|0|00594)[67]\d{8}$/,
  12572. 'fr-GP': /^(\+?590|0|00590)[67]\d{8}$/,
  12573. 'fr-MQ': /^(\+?596|0|00596)[67]\d{8}$/,
  12574. 'fr-PF': /^(\+?689)?8[789]\d{6}$/,
  12575. 'fr-RE': /^(\+?262|0|00262)[67]\d{8}$/,
  12576. 'he-IL': /^(\+972|0)([23489]|5[012345689]|77)[1-9]\d{6}$/,
  12577. 'hu-HU': /^(\+?36|06)(20|30|31|50|70)\d{7}$/,
  12578. 'id-ID': /^(\+?62|0)8(1[123456789]|2[1238]|3[1238]|5[12356789]|7[78]|9[56789]|8[123456789])([\s?|\d]{5,11})$/,
  12579. 'it-IT': /^(\+?39)?\s?3\d{2} ?\d{6,7}$/,
  12580. 'it-SM': /^((\+378)|(0549)|(\+390549)|(\+3780549))?6\d{5,9}$/,
  12581. 'ja-JP': /^(\+81[ \-]?(\(0\))?|0)[6789]0[ \-]?\d{4}[ \-]?\d{4}$/,
  12582. 'ka-GE': /^(\+?995)?(5|79)\d{7}$/,
  12583. 'kk-KZ': /^(\+?7|8)?7\d{9}$/,
  12584. 'kl-GL': /^(\+?299)?\s?\d{2}\s?\d{2}\s?\d{2}$/,
  12585. 'ko-KR': /^((\+?82)[ \-]?)?0?1([0|1|6|7|8|9]{1})[ \-]?\d{3,4}[ \-]?\d{4}$/,
  12586. 'lt-LT': /^(\+370|8)\d{8}$/,
  12587. 'lv-LV': /^(\+?371)2\d{7}$/,
  12588. 'ms-MY': /^(\+?6?01){1}(([0145]{1}(\-|\s)?\d{7,8})|([236789]{1}(\s|\-)?\d{7}))$/,
  12589. 'mz-MZ': /^(\+?258)?8[234567]\d{7}$/,
  12590. 'nb-NO': /^(\+?47)?[49]\d{7}$/,
  12591. 'ne-NP': /^(\+?977)?9[78]\d{8}$/,
  12592. 'nl-BE': /^(\+?32|0)4\d{8}$/,
  12593. 'nl-NL': /^(((\+|00)?31\(0\))|((\+|00)?31)|0)6{1}\d{8}$/,
  12594. 'nn-NO': /^(\+?47)?[49]\d{7}$/,
  12595. 'pl-PL': /^(\+?48)? ?[5-8]\d ?\d{3} ?\d{2} ?\d{2}$/,
  12596. '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[2-9]{1}\d{3}\-?\d{4}))$/,
  12597. 'pt-PT': /^(\+?351)?9[1236]\d{7}$/,
  12598. 'pt-AO': /^(\+244)\d{9}$/,
  12599. 'ro-RO': /^(\+?4?0)\s?7\d{2}(\/|\s|\.|\-)?\d{3}(\s|\.|\-)?\d{3}$/,
  12600. 'ru-RU': /^(\+?7|8)?9\d{9}$/,
  12601. 'si-LK': /^(?:0|94|\+94)?(7(0|1|2|4|5|6|7|8)( |-)?)\d{7}$/,
  12602. 'sl-SI': /^(\+386\s?|0)(\d{1}\s?\d{3}\s?\d{2}\s?\d{2}|\d{2}\s?\d{3}\s?\d{3})$/,
  12603. 'sk-SK': /^(\+?421)? ?[1-9][0-9]{2} ?[0-9]{3} ?[0-9]{3}$/,
  12604. 'sq-AL': /^(\+355|0)6[789]\d{6}$/,
  12605. 'sr-RS': /^(\+3816|06)[- \d]{5,9}$/,
  12606. 'sv-SE': /^(\+?46|0)[\s\-]?7[\s\-]?[02369]([\s\-]?\d){7}$/,
  12607. 'tg-TJ': /^(\+?992)?[5][5]\d{7}$/,
  12608. 'th-TH': /^(\+66|66|0)\d{9}$/,
  12609. 'tr-TR': /^(\+?90|0)?5\d{9}$/,
  12610. 'tk-TM': /^(\+993|993|8)\d{8}$/,
  12611. 'uk-UA': /^(\+?38|8)?0\d{9}$/,
  12612. 'uz-UZ': /^(\+?998)?(6[125-79]|7[1-69]|88|9\d)\d{7}$/,
  12613. 'vi-VN': /^((\+?84)|0)((3([2-9]))|(5([25689]))|(7([0|6-9]))|(8([1-9]))|(9([0-9])))([0-9]{7})$/,
  12614. 'zh-CN': /^((\+|00)86)?(1[3-9]|9[28])\d{9}$/,
  12615. 'zh-TW': /^(\+?886\-?|0)?9\d{8}$/,
  12616. 'dz-BT': /^(\+?975|0)?(17|16|77|02)\d{6}$/
  12617. };
  12618. /* eslint-enable max-len */
  12619. // aliases
  12620. phones['en-CA'] = phones['en-US'];
  12621. phones['fr-CA'] = phones['en-CA'];
  12622. phones['fr-BE'] = phones['nl-BE'];
  12623. phones['zh-HK'] = phones['en-HK'];
  12624. phones['zh-MO'] = phones['en-MO'];
  12625. phones['ga-IE'] = phones['en-IE'];
  12626. phones['fr-CH'] = phones['de-CH'];
  12627. phones['it-CH'] = phones['fr-CH'];
  12628. function isMobilePhone(str, locale, options) {
  12629. (0, _assertString.default)(str);
  12630. if (options && options.strictMode && !str.startsWith('+')) {
  12631. return false;
  12632. }
  12633. if (Array.isArray(locale)) {
  12634. return locale.some(function (key) {
  12635. // https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md#ignoring-code-for-coverage-purposes
  12636. // istanbul ignore else
  12637. if (phones.hasOwnProperty(key)) {
  12638. var phone = phones[key];
  12639. if (phone.test(str)) {
  12640. return true;
  12641. }
  12642. }
  12643. return false;
  12644. });
  12645. } else if (locale in phones) {
  12646. return phones[locale].test(str); // alias falsey locale as 'any'
  12647. } else if (!locale || locale === 'any') {
  12648. for (var key in phones) {
  12649. // istanbul ignore else
  12650. if (phones.hasOwnProperty(key)) {
  12651. var phone = phones[key];
  12652. if (phone.test(str)) {
  12653. return true;
  12654. }
  12655. }
  12656. }
  12657. return false;
  12658. }
  12659. throw new Error("Invalid locale '".concat(locale, "'"));
  12660. }
  12661. var locales = Object.keys(phones);
  12662. exports.locales = locales;
  12663. },{"./util/assertString":135}],103:[function(require,module,exports){
  12664. "use strict";
  12665. Object.defineProperty(exports, "__esModule", {
  12666. value: true
  12667. });
  12668. exports.default = isMongoId;
  12669. var _assertString = _interopRequireDefault(require("./util/assertString"));
  12670. var _isHexadecimal = _interopRequireDefault(require("./isHexadecimal"));
  12671. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  12672. function isMongoId(str) {
  12673. (0, _assertString.default)(str);
  12674. return (0, _isHexadecimal.default)(str) && str.length === 24;
  12675. }
  12676. module.exports = exports.default;
  12677. module.exports.default = exports.default;
  12678. },{"./isHexadecimal":75,"./util/assertString":135}],104:[function(require,module,exports){
  12679. "use strict";
  12680. Object.defineProperty(exports, "__esModule", {
  12681. value: true
  12682. });
  12683. exports.default = isMultibyte;
  12684. var _assertString = _interopRequireDefault(require("./util/assertString"));
  12685. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  12686. /* eslint-disable no-control-regex */
  12687. var multibyte = /[^\x00-\x7F]/;
  12688. /* eslint-enable no-control-regex */
  12689. function isMultibyte(str) {
  12690. (0, _assertString.default)(str);
  12691. return multibyte.test(str);
  12692. }
  12693. module.exports = exports.default;
  12694. module.exports.default = exports.default;
  12695. },{"./util/assertString":135}],105:[function(require,module,exports){
  12696. "use strict";
  12697. Object.defineProperty(exports, "__esModule", {
  12698. value: true
  12699. });
  12700. exports.default = isNumeric;
  12701. var _assertString = _interopRequireDefault(require("./util/assertString"));
  12702. var _alpha = require("./alpha");
  12703. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  12704. var numericNoSymbols = /^[0-9]+$/;
  12705. function isNumeric(str, options) {
  12706. (0, _assertString.default)(str);
  12707. if (options && options.no_symbols) {
  12708. return numericNoSymbols.test(str);
  12709. }
  12710. return new RegExp("^[+-]?([0-9]*[".concat((options || {}).locale ? _alpha.decimal[options.locale] : '.', "])?[0-9]+$")).test(str);
  12711. }
  12712. module.exports = exports.default;
  12713. module.exports.default = exports.default;
  12714. },{"./alpha":41,"./util/assertString":135}],106:[function(require,module,exports){
  12715. "use strict";
  12716. Object.defineProperty(exports, "__esModule", {
  12717. value: true
  12718. });
  12719. exports.default = isOctal;
  12720. var _assertString = _interopRequireDefault(require("./util/assertString"));
  12721. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  12722. var octal = /^(0o)?[0-7]+$/i;
  12723. function isOctal(str) {
  12724. (0, _assertString.default)(str);
  12725. return octal.test(str);
  12726. }
  12727. module.exports = exports.default;
  12728. module.exports.default = exports.default;
  12729. },{"./util/assertString":135}],107:[function(require,module,exports){
  12730. "use strict";
  12731. Object.defineProperty(exports, "__esModule", {
  12732. value: true
  12733. });
  12734. exports.default = isPassportNumber;
  12735. var _assertString = _interopRequireDefault(require("./util/assertString"));
  12736. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  12737. /**
  12738. * Reference:
  12739. * https://en.wikipedia.org/ -- Wikipedia
  12740. * https://docs.microsoft.com/en-us/microsoft-365/compliance/eu-passport-number -- EU Passport Number
  12741. * https://countrycode.org/ -- Country Codes
  12742. */
  12743. var passportRegexByCountryCode = {
  12744. AM: /^[A-Z]{2}\d{7}$/,
  12745. // ARMENIA
  12746. AR: /^[A-Z]{3}\d{6}$/,
  12747. // ARGENTINA
  12748. AT: /^[A-Z]\d{7}$/,
  12749. // AUSTRIA
  12750. AU: /^[A-Z]\d{7}$/,
  12751. // AUSTRALIA
  12752. BE: /^[A-Z]{2}\d{6}$/,
  12753. // BELGIUM
  12754. BG: /^\d{9}$/,
  12755. // BULGARIA
  12756. BR: /^[A-Z]{2}\d{6}$/,
  12757. // BRAZIL
  12758. BY: /^[A-Z]{2}\d{7}$/,
  12759. // BELARUS
  12760. CA: /^[A-Z]{2}\d{6}$/,
  12761. // CANADA
  12762. CH: /^[A-Z]\d{7}$/,
  12763. // SWITZERLAND
  12764. CN: /^G\d{8}$|^E(?![IO])[A-Z0-9]\d{7}$/,
  12765. // CHINA [G=Ordinary, E=Electronic] followed by 8-digits, or E followed by any UPPERCASE letter (except I and O) followed by 7 digits
  12766. CY: /^[A-Z](\d{6}|\d{8})$/,
  12767. // CYPRUS
  12768. CZ: /^\d{8}$/,
  12769. // CZECH REPUBLIC
  12770. DE: /^[CFGHJKLMNPRTVWXYZ0-9]{9}$/,
  12771. // GERMANY
  12772. DK: /^\d{9}$/,
  12773. // DENMARK
  12774. DZ: /^\d{9}$/,
  12775. // ALGERIA
  12776. EE: /^([A-Z]\d{7}|[A-Z]{2}\d{7})$/,
  12777. // ESTONIA (K followed by 7-digits), e-passports have 2 UPPERCASE followed by 7 digits
  12778. ES: /^[A-Z0-9]{2}([A-Z0-9]?)\d{6}$/,
  12779. // SPAIN
  12780. FI: /^[A-Z]{2}\d{7}$/,
  12781. // FINLAND
  12782. FR: /^\d{2}[A-Z]{2}\d{5}$/,
  12783. // FRANCE
  12784. GB: /^\d{9}$/,
  12785. // UNITED KINGDOM
  12786. GR: /^[A-Z]{2}\d{7}$/,
  12787. // GREECE
  12788. HR: /^\d{9}$/,
  12789. // CROATIA
  12790. HU: /^[A-Z]{2}(\d{6}|\d{7})$/,
  12791. // HUNGARY
  12792. IE: /^[A-Z0-9]{2}\d{7}$/,
  12793. // IRELAND
  12794. IN: /^[A-Z]{1}-?\d{7}$/,
  12795. // INDIA
  12796. ID: /^[A-C]\d{7}$/,
  12797. // INDONESIA
  12798. IR: /^[A-Z]\d{8}$/,
  12799. // IRAN
  12800. IS: /^(A)\d{7}$/,
  12801. // ICELAND
  12802. IT: /^[A-Z0-9]{2}\d{7}$/,
  12803. // ITALY
  12804. JP: /^[A-Z]{2}\d{7}$/,
  12805. // JAPAN
  12806. KR: /^[MS]\d{8}$/,
  12807. // SOUTH KOREA, REPUBLIC OF KOREA, [S=PS Passports, M=PM Passports]
  12808. LT: /^[A-Z0-9]{8}$/,
  12809. // LITHUANIA
  12810. LU: /^[A-Z0-9]{8}$/,
  12811. // LUXEMBURG
  12812. LV: /^[A-Z0-9]{2}\d{7}$/,
  12813. // LATVIA
  12814. LY: /^[A-Z0-9]{8}$/,
  12815. // LIBYA
  12816. MT: /^\d{7}$/,
  12817. // MALTA
  12818. MZ: /^([A-Z]{2}\d{7})|(\d{2}[A-Z]{2}\d{5})$/,
  12819. // MOZAMBIQUE
  12820. MY: /^[AHK]\d{8}$/,
  12821. // MALAYSIA
  12822. NL: /^[A-Z]{2}[A-Z0-9]{6}\d$/,
  12823. // NETHERLANDS
  12824. PL: /^[A-Z]{2}\d{7}$/,
  12825. // POLAND
  12826. PT: /^[A-Z]\d{6}$/,
  12827. // PORTUGAL
  12828. RO: /^\d{8,9}$/,
  12829. // ROMANIA
  12830. RU: /^\d{9}$/,
  12831. // RUSSIAN FEDERATION
  12832. SE: /^\d{8}$/,
  12833. // SWEDEN
  12834. SL: /^(P)[A-Z]\d{7}$/,
  12835. // SLOVANIA
  12836. SK: /^[0-9A-Z]\d{7}$/,
  12837. // SLOVAKIA
  12838. TR: /^[A-Z]\d{8}$/,
  12839. // TURKEY
  12840. UA: /^[A-Z]{2}\d{6}$/,
  12841. // UKRAINE
  12842. US: /^\d{9}$/ // UNITED STATES
  12843. };
  12844. /**
  12845. * Check if str is a valid passport number
  12846. * relative to provided ISO Country Code.
  12847. *
  12848. * @param {string} str
  12849. * @param {string} countryCode
  12850. * @return {boolean}
  12851. */
  12852. function isPassportNumber(str, countryCode) {
  12853. (0, _assertString.default)(str);
  12854. /** Remove All Whitespaces, Convert to UPPERCASE */
  12855. var normalizedStr = str.replace(/\s/g, '').toUpperCase();
  12856. return countryCode.toUpperCase() in passportRegexByCountryCode && passportRegexByCountryCode[countryCode].test(normalizedStr);
  12857. }
  12858. module.exports = exports.default;
  12859. module.exports.default = exports.default;
  12860. },{"./util/assertString":135}],108:[function(require,module,exports){
  12861. "use strict";
  12862. Object.defineProperty(exports, "__esModule", {
  12863. value: true
  12864. });
  12865. exports.default = isPort;
  12866. var _isInt = _interopRequireDefault(require("./isInt"));
  12867. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  12868. function isPort(str) {
  12869. return (0, _isInt.default)(str, {
  12870. min: 0,
  12871. max: 65535
  12872. });
  12873. }
  12874. module.exports = exports.default;
  12875. module.exports.default = exports.default;
  12876. },{"./isInt":90}],109:[function(require,module,exports){
  12877. "use strict";
  12878. Object.defineProperty(exports, "__esModule", {
  12879. value: true
  12880. });
  12881. exports.default = isPostalCode;
  12882. exports.locales = void 0;
  12883. var _assertString = _interopRequireDefault(require("./util/assertString"));
  12884. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  12885. // common patterns
  12886. var threeDigit = /^\d{3}$/;
  12887. var fourDigit = /^\d{4}$/;
  12888. var fiveDigit = /^\d{5}$/;
  12889. var sixDigit = /^\d{6}$/;
  12890. var patterns = {
  12891. AD: /^AD\d{3}$/,
  12892. AT: fourDigit,
  12893. AU: fourDigit,
  12894. AZ: /^AZ\d{4}$/,
  12895. BE: fourDigit,
  12896. BG: fourDigit,
  12897. BR: /^\d{5}-\d{3}$/,
  12898. BY: /2[1-4]{1}\d{4}$/,
  12899. CA: /^[ABCEGHJKLMNPRSTVXY]\d[ABCEGHJ-NPRSTV-Z][\s\-]?\d[ABCEGHJ-NPRSTV-Z]\d$/i,
  12900. CH: fourDigit,
  12901. 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}$/,
  12902. CZ: /^\d{3}\s?\d{2}$/,
  12903. DE: fiveDigit,
  12904. DK: fourDigit,
  12905. DO: fiveDigit,
  12906. DZ: fiveDigit,
  12907. EE: fiveDigit,
  12908. ES: /^(5[0-2]{1}|[0-4]{1}\d{1})\d{3}$/,
  12909. FI: fiveDigit,
  12910. FR: /^\d{2}\s?\d{3}$/,
  12911. GB: /^(gir\s?0aa|[a-z]{1,2}\d[\da-z]?\s?(\d[a-z]{2})?)$/i,
  12912. GR: /^\d{3}\s?\d{2}$/,
  12913. HR: /^([1-5]\d{4}$)/,
  12914. HT: /^HT\d{4}$/,
  12915. HU: fourDigit,
  12916. ID: fiveDigit,
  12917. IE: /^(?!.*(?:o))[A-Za-z]\d[\dw]\s\w{4}$/i,
  12918. IL: /^(\d{5}|\d{7})$/,
  12919. IN: /^((?!10|29|35|54|55|65|66|86|87|88|89)[1-9][0-9]{5})$/,
  12920. IR: /\b(?!(\d)\1{3})[13-9]{4}[1346-9][013-9]{5}\b/,
  12921. IS: threeDigit,
  12922. IT: fiveDigit,
  12923. JP: /^\d{3}\-\d{4}$/,
  12924. KE: fiveDigit,
  12925. KR: /^(\d{5}|\d{6})$/,
  12926. LI: /^(948[5-9]|949[0-7])$/,
  12927. LT: /^LT\-\d{5}$/,
  12928. LU: fourDigit,
  12929. LV: /^LV\-\d{4}$/,
  12930. LK: fiveDigit,
  12931. MX: fiveDigit,
  12932. MT: /^[A-Za-z]{3}\s{0,1}\d{4}$/,
  12933. MY: fiveDigit,
  12934. NL: /^\d{4}\s?[a-z]{2}$/i,
  12935. NO: fourDigit,
  12936. NP: /^(10|21|22|32|33|34|44|45|56|57)\d{3}$|^(977)$/i,
  12937. NZ: fourDigit,
  12938. PL: /^\d{2}\-\d{3}$/,
  12939. PR: /^00[679]\d{2}([ -]\d{4})?$/,
  12940. PT: /^\d{4}\-\d{3}?$/,
  12941. RO: sixDigit,
  12942. RU: sixDigit,
  12943. SA: fiveDigit,
  12944. SE: /^[1-9]\d{2}\s?\d{2}$/,
  12945. SG: sixDigit,
  12946. SI: fourDigit,
  12947. SK: /^\d{3}\s?\d{2}$/,
  12948. TH: fiveDigit,
  12949. TN: fourDigit,
  12950. TW: /^\d{3}(\d{2})?$/,
  12951. UA: fiveDigit,
  12952. US: /^\d{5}(-\d{4})?$/,
  12953. ZA: fourDigit,
  12954. ZM: fiveDigit
  12955. };
  12956. var locales = Object.keys(patterns);
  12957. exports.locales = locales;
  12958. function isPostalCode(str, locale) {
  12959. (0, _assertString.default)(str);
  12960. if (locale in patterns) {
  12961. return patterns[locale].test(str);
  12962. } else if (locale === 'any') {
  12963. for (var key in patterns) {
  12964. // https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md#ignoring-code-for-coverage-purposes
  12965. // istanbul ignore else
  12966. if (patterns.hasOwnProperty(key)) {
  12967. var pattern = patterns[key];
  12968. if (pattern.test(str)) {
  12969. return true;
  12970. }
  12971. }
  12972. }
  12973. return false;
  12974. }
  12975. throw new Error("Invalid locale '".concat(locale, "'"));
  12976. }
  12977. },{"./util/assertString":135}],110:[function(require,module,exports){
  12978. "use strict";
  12979. Object.defineProperty(exports, "__esModule", {
  12980. value: true
  12981. });
  12982. exports.default = isRFC3339;
  12983. var _assertString = _interopRequireDefault(require("./util/assertString"));
  12984. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  12985. /* Based on https://tools.ietf.org/html/rfc3339#section-5.6 */
  12986. var dateFullYear = /[0-9]{4}/;
  12987. var dateMonth = /(0[1-9]|1[0-2])/;
  12988. var dateMDay = /([12]\d|0[1-9]|3[01])/;
  12989. var timeHour = /([01][0-9]|2[0-3])/;
  12990. var timeMinute = /[0-5][0-9]/;
  12991. var timeSecond = /([0-5][0-9]|60)/;
  12992. var timeSecFrac = /(\.[0-9]+)?/;
  12993. var timeNumOffset = new RegExp("[-+]".concat(timeHour.source, ":").concat(timeMinute.source));
  12994. var timeOffset = new RegExp("([zZ]|".concat(timeNumOffset.source, ")"));
  12995. var partialTime = new RegExp("".concat(timeHour.source, ":").concat(timeMinute.source, ":").concat(timeSecond.source).concat(timeSecFrac.source));
  12996. var fullDate = new RegExp("".concat(dateFullYear.source, "-").concat(dateMonth.source, "-").concat(dateMDay.source));
  12997. var fullTime = new RegExp("".concat(partialTime.source).concat(timeOffset.source));
  12998. var rfc3339 = new RegExp("^".concat(fullDate.source, "[ tT]").concat(fullTime.source, "$"));
  12999. function isRFC3339(str) {
  13000. (0, _assertString.default)(str);
  13001. return rfc3339.test(str);
  13002. }
  13003. module.exports = exports.default;
  13004. module.exports.default = exports.default;
  13005. },{"./util/assertString":135}],111:[function(require,module,exports){
  13006. "use strict";
  13007. Object.defineProperty(exports, "__esModule", {
  13008. value: true
  13009. });
  13010. exports.default = isRgbColor;
  13011. var _assertString = _interopRequireDefault(require("./util/assertString"));
  13012. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  13013. 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])\)$/;
  13014. 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)?)\)$/;
  13015. var rgbColorPercent = /^rgb\((([0-9]%|[1-9][0-9]%|100%),){2}([0-9]%|[1-9][0-9]%|100%)\)/;
  13016. var rgbaColorPercent = /^rgba\((([0-9]%|[1-9][0-9]%|100%),){3}(0?\.\d|1(\.0)?|0(\.0)?)\)/;
  13017. function isRgbColor(str) {
  13018. var includePercentValues = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
  13019. (0, _assertString.default)(str);
  13020. if (!includePercentValues) {
  13021. return rgbColor.test(str) || rgbaColor.test(str);
  13022. }
  13023. return rgbColor.test(str) || rgbaColor.test(str) || rgbColorPercent.test(str) || rgbaColorPercent.test(str);
  13024. }
  13025. module.exports = exports.default;
  13026. module.exports.default = exports.default;
  13027. },{"./util/assertString":135}],112:[function(require,module,exports){
  13028. "use strict";
  13029. Object.defineProperty(exports, "__esModule", {
  13030. value: true
  13031. });
  13032. exports.default = isSemVer;
  13033. var _assertString = _interopRequireDefault(require("./util/assertString"));
  13034. var _multilineRegex = _interopRequireDefault(require("./util/multilineRegex"));
  13035. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  13036. /**
  13037. * Regular Expression to match
  13038. * semantic versioning (SemVer)
  13039. * built from multi-line, multi-parts regexp
  13040. * Reference: https://semver.org/
  13041. */
  13042. var semanticVersioningRegex = (0, _multilineRegex.default)(['^(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');
  13043. function isSemVer(str) {
  13044. (0, _assertString.default)(str);
  13045. return semanticVersioningRegex.test(str);
  13046. }
  13047. module.exports = exports.default;
  13048. module.exports.default = exports.default;
  13049. },{"./util/assertString":135,"./util/multilineRegex":138}],113:[function(require,module,exports){
  13050. "use strict";
  13051. Object.defineProperty(exports, "__esModule", {
  13052. value: true
  13053. });
  13054. exports.default = isSlug;
  13055. var _assertString = _interopRequireDefault(require("./util/assertString"));
  13056. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  13057. var charsetRegex = /^[^\s-_](?!.*?[-_]{2,})[a-z0-9-\\][^\s]*[^-_\s]$/;
  13058. function isSlug(str) {
  13059. (0, _assertString.default)(str);
  13060. return charsetRegex.test(str);
  13061. }
  13062. module.exports = exports.default;
  13063. module.exports.default = exports.default;
  13064. },{"./util/assertString":135}],114:[function(require,module,exports){
  13065. "use strict";
  13066. Object.defineProperty(exports, "__esModule", {
  13067. value: true
  13068. });
  13069. exports.default = isStrongPassword;
  13070. var _merge = _interopRequireDefault(require("./util/merge"));
  13071. var _assertString = _interopRequireDefault(require("./util/assertString"));
  13072. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  13073. var upperCaseRegex = /^[A-Z]$/;
  13074. var lowerCaseRegex = /^[a-z]$/;
  13075. var numberRegex = /^[0-9]$/;
  13076. var symbolRegex = /^[-#!$@%^&*()_+|~=`{}\[\]:";'<>?,.\/ ]$/;
  13077. var defaultOptions = {
  13078. minLength: 8,
  13079. minLowercase: 1,
  13080. minUppercase: 1,
  13081. minNumbers: 1,
  13082. minSymbols: 1,
  13083. returnScore: false,
  13084. pointsPerUnique: 1,
  13085. pointsPerRepeat: 0.5,
  13086. pointsForContainingLower: 10,
  13087. pointsForContainingUpper: 10,
  13088. pointsForContainingNumber: 10,
  13089. pointsForContainingSymbol: 10
  13090. };
  13091. /* Counts number of occurrences of each char in a string
  13092. * could be moved to util/ ?
  13093. */
  13094. function countChars(str) {
  13095. var result = {};
  13096. Array.from(str).forEach(function (char) {
  13097. var curVal = result[char];
  13098. if (curVal) {
  13099. result[char] += 1;
  13100. } else {
  13101. result[char] = 1;
  13102. }
  13103. });
  13104. return result;
  13105. }
  13106. /* Return information about a password */
  13107. function analyzePassword(password) {
  13108. var charMap = countChars(password);
  13109. var analysis = {
  13110. length: password.length,
  13111. uniqueChars: Object.keys(charMap).length,
  13112. uppercaseCount: 0,
  13113. lowercaseCount: 0,
  13114. numberCount: 0,
  13115. symbolCount: 0
  13116. };
  13117. Object.keys(charMap).forEach(function (char) {
  13118. /* istanbul ignore else */
  13119. if (upperCaseRegex.test(char)) {
  13120. analysis.uppercaseCount += charMap[char];
  13121. } else if (lowerCaseRegex.test(char)) {
  13122. analysis.lowercaseCount += charMap[char];
  13123. } else if (numberRegex.test(char)) {
  13124. analysis.numberCount += charMap[char];
  13125. } else if (symbolRegex.test(char)) {
  13126. analysis.symbolCount += charMap[char];
  13127. }
  13128. });
  13129. return analysis;
  13130. }
  13131. function scorePassword(analysis, scoringOptions) {
  13132. var points = 0;
  13133. points += analysis.uniqueChars * scoringOptions.pointsPerUnique;
  13134. points += (analysis.length - analysis.uniqueChars) * scoringOptions.pointsPerRepeat;
  13135. if (analysis.lowercaseCount > 0) {
  13136. points += scoringOptions.pointsForContainingLower;
  13137. }
  13138. if (analysis.uppercaseCount > 0) {
  13139. points += scoringOptions.pointsForContainingUpper;
  13140. }
  13141. if (analysis.numberCount > 0) {
  13142. points += scoringOptions.pointsForContainingNumber;
  13143. }
  13144. if (analysis.symbolCount > 0) {
  13145. points += scoringOptions.pointsForContainingSymbol;
  13146. }
  13147. return points;
  13148. }
  13149. function isStrongPassword(str) {
  13150. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  13151. (0, _assertString.default)(str);
  13152. var analysis = analyzePassword(str);
  13153. options = (0, _merge.default)(options || {}, defaultOptions);
  13154. if (options.returnScore) {
  13155. return scorePassword(analysis, options);
  13156. }
  13157. return analysis.length >= options.minLength && analysis.lowercaseCount >= options.minLowercase && analysis.uppercaseCount >= options.minUppercase && analysis.numberCount >= options.minNumbers && analysis.symbolCount >= options.minSymbols;
  13158. }
  13159. module.exports = exports.default;
  13160. module.exports.default = exports.default;
  13161. },{"./util/assertString":135,"./util/merge":137}],115:[function(require,module,exports){
  13162. "use strict";
  13163. Object.defineProperty(exports, "__esModule", {
  13164. value: true
  13165. });
  13166. exports.default = isSurrogatePair;
  13167. var _assertString = _interopRequireDefault(require("./util/assertString"));
  13168. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  13169. var surrogatePair = /[\uD800-\uDBFF][\uDC00-\uDFFF]/;
  13170. function isSurrogatePair(str) {
  13171. (0, _assertString.default)(str);
  13172. return surrogatePair.test(str);
  13173. }
  13174. module.exports = exports.default;
  13175. module.exports.default = exports.default;
  13176. },{"./util/assertString":135}],116:[function(require,module,exports){
  13177. "use strict";
  13178. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  13179. Object.defineProperty(exports, "__esModule", {
  13180. value: true
  13181. });
  13182. exports.default = isTaxID;
  13183. var _assertString = _interopRequireDefault(require("./util/assertString"));
  13184. var algorithms = _interopRequireWildcard(require("./util/algorithms"));
  13185. var _isDate = _interopRequireDefault(require("./isDate"));
  13186. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
  13187. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  13188. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  13189. function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
  13190. function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
  13191. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  13192. function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
  13193. function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
  13194. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  13195. /**
  13196. * TIN Validation
  13197. * Validates Tax Identification Numbers (TINs) from the US, EU member states and the United Kingdom.
  13198. *
  13199. * EU-UK:
  13200. * National TIN validity is calculated using public algorithms as made available by DG TAXUD.
  13201. *
  13202. * See `https://ec.europa.eu/taxation_customs/tin/specs/FS-TIN%20Algorithms-Public.docx` for more information.
  13203. *
  13204. * US:
  13205. * An Employer Identification Number (EIN), also known as a Federal Tax Identification Number,
  13206. * is used to identify a business entity.
  13207. *
  13208. * NOTES:
  13209. * - Prefix 47 is being reserved for future use
  13210. * - Prefixes 26, 27, 45, 46 and 47 were previously assigned by the Philadelphia campus.
  13211. *
  13212. * See `http://www.irs.gov/Businesses/Small-Businesses-&-Self-Employed/How-EINs-are-Assigned-and-Valid-EIN-Prefixes`
  13213. * for more information.
  13214. */
  13215. // Locale functions
  13216. /*
  13217. * bg-BG validation function
  13218. * (Edinen graždanski nomer (EGN/ЕГН), persons only)
  13219. * Checks if birth date (first six digits) is valid and calculates check (last) digit
  13220. */
  13221. function bgBgCheck(tin) {
  13222. // Extract full year, normalize month and check birth date validity
  13223. var century_year = tin.slice(0, 2);
  13224. var month = parseInt(tin.slice(2, 4), 10);
  13225. if (month > 40) {
  13226. month -= 40;
  13227. century_year = "20".concat(century_year);
  13228. } else if (month > 20) {
  13229. month -= 20;
  13230. century_year = "18".concat(century_year);
  13231. } else {
  13232. century_year = "19".concat(century_year);
  13233. }
  13234. if (month < 10) {
  13235. month = "0".concat(month);
  13236. }
  13237. var date = "".concat(century_year, "/").concat(month, "/").concat(tin.slice(4, 6));
  13238. if (!(0, _isDate.default)(date, 'YYYY/MM/DD')) {
  13239. return false;
  13240. } // split digits into an array for further processing
  13241. var digits = tin.split('').map(function (a) {
  13242. return parseInt(a, 10);
  13243. }); // Calculate checksum by multiplying digits with fixed values
  13244. var multip_lookup = [2, 4, 8, 5, 10, 9, 7, 3, 6];
  13245. var checksum = 0;
  13246. for (var i = 0; i < multip_lookup.length; i++) {
  13247. checksum += digits[i] * multip_lookup[i];
  13248. }
  13249. checksum = checksum % 11 === 10 ? 0 : checksum % 11;
  13250. return checksum === digits[9];
  13251. }
  13252. /*
  13253. * cs-CZ validation function
  13254. * (Rodné číslo (RČ), persons only)
  13255. * Checks if birth date (first six digits) is valid and divisibility by 11
  13256. * Material not in DG TAXUD document sourced from:
  13257. * -`https://lorenc.info/3MA381/overeni-spravnosti-rodneho-cisla.htm`
  13258. * -`https://www.mvcr.cz/clanek/rady-a-sluzby-dokumenty-rodne-cislo.aspx`
  13259. */
  13260. function csCzCheck(tin) {
  13261. tin = tin.replace(/\W/, ''); // Extract full year from TIN length
  13262. var full_year = parseInt(tin.slice(0, 2), 10);
  13263. if (tin.length === 10) {
  13264. if (full_year < 54) {
  13265. full_year = "20".concat(full_year);
  13266. } else {
  13267. full_year = "19".concat(full_year);
  13268. }
  13269. } else {
  13270. if (tin.slice(6) === '000') {
  13271. return false;
  13272. } // Three-zero serial not assigned before 1954
  13273. if (full_year < 54) {
  13274. full_year = "19".concat(full_year);
  13275. } else {
  13276. return false; // No 18XX years seen in any of the resources
  13277. }
  13278. } // Add missing zero if needed
  13279. if (full_year.length === 3) {
  13280. full_year = [full_year.slice(0, 2), '0', full_year.slice(2)].join('');
  13281. } // Extract month from TIN and normalize
  13282. var month = parseInt(tin.slice(2, 4), 10);
  13283. if (month > 50) {
  13284. month -= 50;
  13285. }
  13286. if (month > 20) {
  13287. // Month-plus-twenty was only introduced in 2004
  13288. if (parseInt(full_year, 10) < 2004) {
  13289. return false;
  13290. }
  13291. month -= 20;
  13292. }
  13293. if (month < 10) {
  13294. month = "0".concat(month);
  13295. } // Check date validity
  13296. var date = "".concat(full_year, "/").concat(month, "/").concat(tin.slice(4, 6));
  13297. if (!(0, _isDate.default)(date, 'YYYY/MM/DD')) {
  13298. return false;
  13299. } // Verify divisibility by 11
  13300. if (tin.length === 10) {
  13301. if (parseInt(tin, 10) % 11 !== 0) {
  13302. // Some numbers up to and including 1985 are still valid if
  13303. // check (last) digit equals 0 and modulo of first 9 digits equals 10
  13304. var checkdigit = parseInt(tin.slice(0, 9), 10) % 11;
  13305. if (parseInt(full_year, 10) < 1986 && checkdigit === 10) {
  13306. if (parseInt(tin.slice(9), 10) !== 0) {
  13307. return false;
  13308. }
  13309. } else {
  13310. return false;
  13311. }
  13312. }
  13313. }
  13314. return true;
  13315. }
  13316. /*
  13317. * de-AT validation function
  13318. * (Abgabenkontonummer, persons/entities)
  13319. * Verify TIN validity by calling luhnCheck()
  13320. */
  13321. function deAtCheck(tin) {
  13322. return algorithms.luhnCheck(tin);
  13323. }
  13324. /*
  13325. * de-DE validation function
  13326. * (Steueridentifikationsnummer (Steuer-IdNr.), persons only)
  13327. * Tests for single duplicate/triplicate value, then calculates ISO 7064 check (last) digit
  13328. * Partial implementation of spec (same result with both algorithms always)
  13329. */
  13330. function deDeCheck(tin) {
  13331. // Split digits into an array for further processing
  13332. var digits = tin.split('').map(function (a) {
  13333. return parseInt(a, 10);
  13334. }); // Fill array with strings of number positions
  13335. var occurences = [];
  13336. for (var i = 0; i < digits.length - 1; i++) {
  13337. occurences.push('');
  13338. for (var j = 0; j < digits.length - 1; j++) {
  13339. if (digits[i] === digits[j]) {
  13340. occurences[i] += j;
  13341. }
  13342. }
  13343. } // Remove digits with one occurence and test for only one duplicate/triplicate
  13344. occurences = occurences.filter(function (a) {
  13345. return a.length > 1;
  13346. });
  13347. if (occurences.length !== 2 && occurences.length !== 3) {
  13348. return false;
  13349. } // In case of triplicate value only two digits are allowed next to each other
  13350. if (occurences[0].length === 3) {
  13351. var trip_locations = occurences[0].split('').map(function (a) {
  13352. return parseInt(a, 10);
  13353. });
  13354. var recurrent = 0; // Amount of neighbour occurences
  13355. for (var _i = 0; _i < trip_locations.length - 1; _i++) {
  13356. if (trip_locations[_i] + 1 === trip_locations[_i + 1]) {
  13357. recurrent += 1;
  13358. }
  13359. }
  13360. if (recurrent === 2) {
  13361. return false;
  13362. }
  13363. }
  13364. return algorithms.iso7064Check(tin);
  13365. }
  13366. /*
  13367. * dk-DK validation function
  13368. * (CPR-nummer (personnummer), persons only)
  13369. * Checks if birth date (first six digits) is valid and assigned to century (seventh) digit,
  13370. * and calculates check (last) digit
  13371. */
  13372. function dkDkCheck(tin) {
  13373. tin = tin.replace(/\W/, ''); // Extract year, check if valid for given century digit and add century
  13374. var year = parseInt(tin.slice(4, 6), 10);
  13375. var century_digit = tin.slice(6, 7);
  13376. switch (century_digit) {
  13377. case '0':
  13378. case '1':
  13379. case '2':
  13380. case '3':
  13381. year = "19".concat(year);
  13382. break;
  13383. case '4':
  13384. case '9':
  13385. if (year < 37) {
  13386. year = "20".concat(year);
  13387. } else {
  13388. year = "19".concat(year);
  13389. }
  13390. break;
  13391. default:
  13392. if (year < 37) {
  13393. year = "20".concat(year);
  13394. } else if (year > 58) {
  13395. year = "18".concat(year);
  13396. } else {
  13397. return false;
  13398. }
  13399. break;
  13400. } // Add missing zero if needed
  13401. if (year.length === 3) {
  13402. year = [year.slice(0, 2), '0', year.slice(2)].join('');
  13403. } // Check date validity
  13404. var date = "".concat(year, "/").concat(tin.slice(2, 4), "/").concat(tin.slice(0, 2));
  13405. if (!(0, _isDate.default)(date, 'YYYY/MM/DD')) {
  13406. return false;
  13407. } // Split digits into an array for further processing
  13408. var digits = tin.split('').map(function (a) {
  13409. return parseInt(a, 10);
  13410. });
  13411. var checksum = 0;
  13412. var weight = 4; // Multiply by weight and add to checksum
  13413. for (var i = 0; i < 9; i++) {
  13414. checksum += digits[i] * weight;
  13415. weight -= 1;
  13416. if (weight === 1) {
  13417. weight = 7;
  13418. }
  13419. }
  13420. checksum %= 11;
  13421. if (checksum === 1) {
  13422. return false;
  13423. }
  13424. return checksum === 0 ? digits[9] === 0 : digits[9] === 11 - checksum;
  13425. }
  13426. /*
  13427. * el-CY validation function
  13428. * (Arithmos Forologikou Mitroou (AFM/ΑΦΜ), persons only)
  13429. * Verify TIN validity by calculating ASCII value of check (last) character
  13430. */
  13431. function elCyCheck(tin) {
  13432. // split digits into an array for further processing
  13433. var digits = tin.slice(0, 8).split('').map(function (a) {
  13434. return parseInt(a, 10);
  13435. });
  13436. var checksum = 0; // add digits in even places
  13437. for (var i = 1; i < digits.length; i += 2) {
  13438. checksum += digits[i];
  13439. } // add digits in odd places
  13440. for (var _i2 = 0; _i2 < digits.length; _i2 += 2) {
  13441. if (digits[_i2] < 2) {
  13442. checksum += 1 - digits[_i2];
  13443. } else {
  13444. checksum += 2 * (digits[_i2] - 2) + 5;
  13445. if (digits[_i2] > 4) {
  13446. checksum += 2;
  13447. }
  13448. }
  13449. }
  13450. return String.fromCharCode(checksum % 26 + 65) === tin.charAt(8);
  13451. }
  13452. /*
  13453. * el-GR validation function
  13454. * (Arithmos Forologikou Mitroou (AFM/ΑΦΜ), persons/entities)
  13455. * Verify TIN validity by calculating check (last) digit
  13456. * Algorithm not in DG TAXUD document- sourced from:
  13457. * - `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`
  13458. */
  13459. function elGrCheck(tin) {
  13460. // split digits into an array for further processing
  13461. var digits = tin.split('').map(function (a) {
  13462. return parseInt(a, 10);
  13463. });
  13464. var checksum = 0;
  13465. for (var i = 0; i < 8; i++) {
  13466. checksum += digits[i] * Math.pow(2, 8 - i);
  13467. }
  13468. return checksum % 11 % 10 === digits[8];
  13469. }
  13470. /*
  13471. * en-GB validation function (should go here if needed)
  13472. * (National Insurance Number (NINO) or Unique Taxpayer Reference (UTR),
  13473. * persons/entities respectively)
  13474. */
  13475. /*
  13476. * en-IE validation function
  13477. * (Personal Public Service Number (PPS No), persons only)
  13478. * Verify TIN validity by calculating check (second to last) character
  13479. */
  13480. function enIeCheck(tin) {
  13481. var checksum = algorithms.reverseMultiplyAndSum(tin.split('').slice(0, 7).map(function (a) {
  13482. return parseInt(a, 10);
  13483. }), 8);
  13484. if (tin.length === 9 && tin[8] !== 'W') {
  13485. checksum += (tin[8].charCodeAt(0) - 64) * 9;
  13486. }
  13487. checksum %= 23;
  13488. if (checksum === 0) {
  13489. return tin[7].toUpperCase() === 'W';
  13490. }
  13491. return tin[7].toUpperCase() === String.fromCharCode(64 + checksum);
  13492. } // Valid US IRS campus prefixes
  13493. var enUsCampusPrefix = {
  13494. andover: ['10', '12'],
  13495. atlanta: ['60', '67'],
  13496. austin: ['50', '53'],
  13497. 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'],
  13498. cincinnati: ['30', '32', '35', '36', '37', '38', '61'],
  13499. fresno: ['15', '24'],
  13500. internet: ['20', '26', '27', '45', '46', '47'],
  13501. kansas: ['40', '44'],
  13502. memphis: ['94', '95'],
  13503. ogden: ['80', '90'],
  13504. 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'],
  13505. sba: ['31']
  13506. }; // Return an array of all US IRS campus prefixes
  13507. function enUsGetPrefixes() {
  13508. var prefixes = [];
  13509. for (var location in enUsCampusPrefix) {
  13510. // https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md#ignoring-code-for-coverage-purposes
  13511. // istanbul ignore else
  13512. if (enUsCampusPrefix.hasOwnProperty(location)) {
  13513. prefixes.push.apply(prefixes, _toConsumableArray(enUsCampusPrefix[location]));
  13514. }
  13515. }
  13516. return prefixes;
  13517. }
  13518. /*
  13519. * en-US validation function
  13520. * Verify that the TIN starts with a valid IRS campus prefix
  13521. */
  13522. function enUsCheck(tin) {
  13523. return enUsGetPrefixes().indexOf(tin.substr(0, 2)) !== -1;
  13524. }
  13525. /*
  13526. * es-ES validation function
  13527. * (Documento Nacional de Identidad (DNI)
  13528. * or Número de Identificación de Extranjero (NIE), persons only)
  13529. * Verify TIN validity by calculating check (last) character
  13530. */
  13531. function esEsCheck(tin) {
  13532. // Split characters into an array for further processing
  13533. var chars = tin.toUpperCase().split(''); // Replace initial letter if needed
  13534. if (isNaN(parseInt(chars[0], 10)) && chars.length > 1) {
  13535. var lead_replace = 0;
  13536. switch (chars[0]) {
  13537. case 'Y':
  13538. lead_replace = 1;
  13539. break;
  13540. case 'Z':
  13541. lead_replace = 2;
  13542. break;
  13543. default:
  13544. }
  13545. chars.splice(0, 1, lead_replace); // Fill with zeros if smaller than proper
  13546. } else {
  13547. while (chars.length < 9) {
  13548. chars.unshift(0);
  13549. }
  13550. } // Calculate checksum and check according to lookup
  13551. 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'];
  13552. chars = chars.join('');
  13553. var checksum = parseInt(chars.slice(0, 8), 10) % 23;
  13554. return chars[8] === lookup[checksum];
  13555. }
  13556. /*
  13557. * et-EE validation function
  13558. * (Isikukood (IK), persons only)
  13559. * Checks if birth date (century digit and six following) is valid and calculates check (last) digit
  13560. * Material not in DG TAXUD document sourced from:
  13561. * - `https://www.oecd.org/tax/automatic-exchange/crs-implementation-and-assistance/tax-identification-numbers/Estonia-TIN.pdf`
  13562. */
  13563. function etEeCheck(tin) {
  13564. // Extract year and add century
  13565. var full_year = tin.slice(1, 3);
  13566. var century_digit = tin.slice(0, 1);
  13567. switch (century_digit) {
  13568. case '1':
  13569. case '2':
  13570. full_year = "18".concat(full_year);
  13571. break;
  13572. case '3':
  13573. case '4':
  13574. full_year = "19".concat(full_year);
  13575. break;
  13576. default:
  13577. full_year = "20".concat(full_year);
  13578. break;
  13579. } // Check date validity
  13580. var date = "".concat(full_year, "/").concat(tin.slice(3, 5), "/").concat(tin.slice(5, 7));
  13581. if (!(0, _isDate.default)(date, 'YYYY/MM/DD')) {
  13582. return false;
  13583. } // Split digits into an array for further processing
  13584. var digits = tin.split('').map(function (a) {
  13585. return parseInt(a, 10);
  13586. });
  13587. var checksum = 0;
  13588. var weight = 1; // Multiply by weight and add to checksum
  13589. for (var i = 0; i < 10; i++) {
  13590. checksum += digits[i] * weight;
  13591. weight += 1;
  13592. if (weight === 10) {
  13593. weight = 1;
  13594. }
  13595. } // Do again if modulo 11 of checksum is 10
  13596. if (checksum % 11 === 10) {
  13597. checksum = 0;
  13598. weight = 3;
  13599. for (var _i3 = 0; _i3 < 10; _i3++) {
  13600. checksum += digits[_i3] * weight;
  13601. weight += 1;
  13602. if (weight === 10) {
  13603. weight = 1;
  13604. }
  13605. }
  13606. if (checksum % 11 === 10) {
  13607. return digits[10] === 0;
  13608. }
  13609. }
  13610. return checksum % 11 === digits[10];
  13611. }
  13612. /*
  13613. * fi-FI validation function
  13614. * (Henkilötunnus (HETU), persons only)
  13615. * Checks if birth date (first six digits plus century symbol) is valid
  13616. * and calculates check (last) digit
  13617. */
  13618. function fiFiCheck(tin) {
  13619. // Extract year and add century
  13620. var full_year = tin.slice(4, 6);
  13621. var century_symbol = tin.slice(6, 7);
  13622. switch (century_symbol) {
  13623. case '+':
  13624. full_year = "18".concat(full_year);
  13625. break;
  13626. case '-':
  13627. full_year = "19".concat(full_year);
  13628. break;
  13629. default:
  13630. full_year = "20".concat(full_year);
  13631. break;
  13632. } // Check date validity
  13633. var date = "".concat(full_year, "/").concat(tin.slice(2, 4), "/").concat(tin.slice(0, 2));
  13634. if (!(0, _isDate.default)(date, 'YYYY/MM/DD')) {
  13635. return false;
  13636. } // Calculate check character
  13637. var checksum = parseInt(tin.slice(0, 6) + tin.slice(7, 10), 10) % 31;
  13638. if (checksum < 10) {
  13639. return checksum === parseInt(tin.slice(10), 10);
  13640. }
  13641. checksum -= 10;
  13642. var letters_lookup = ['A', 'B', 'C', 'D', 'E', 'F', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y'];
  13643. return letters_lookup[checksum] === tin.slice(10);
  13644. }
  13645. /*
  13646. * fr/nl-BE validation function
  13647. * (Numéro national (N.N.), persons only)
  13648. * Checks if birth date (first six digits) is valid and calculates check (last two) digits
  13649. */
  13650. function frBeCheck(tin) {
  13651. // Zero month/day value is acceptable
  13652. if (tin.slice(2, 4) !== '00' || tin.slice(4, 6) !== '00') {
  13653. // Extract date from first six digits of TIN
  13654. var date = "".concat(tin.slice(0, 2), "/").concat(tin.slice(2, 4), "/").concat(tin.slice(4, 6));
  13655. if (!(0, _isDate.default)(date, 'YY/MM/DD')) {
  13656. return false;
  13657. }
  13658. }
  13659. var checksum = 97 - parseInt(tin.slice(0, 9), 10) % 97;
  13660. var checkdigits = parseInt(tin.slice(9, 11), 10);
  13661. if (checksum !== checkdigits) {
  13662. checksum = 97 - parseInt("2".concat(tin.slice(0, 9)), 10) % 97;
  13663. if (checksum !== checkdigits) {
  13664. return false;
  13665. }
  13666. }
  13667. return true;
  13668. }
  13669. /*
  13670. * fr-FR validation function
  13671. * (Numéro fiscal de référence (numéro SPI), persons only)
  13672. * Verify TIN validity by calculating check (last three) digits
  13673. */
  13674. function frFrCheck(tin) {
  13675. tin = tin.replace(/\s/g, '');
  13676. var checksum = parseInt(tin.slice(0, 10), 10) % 511;
  13677. var checkdigits = parseInt(tin.slice(10, 13), 10);
  13678. return checksum === checkdigits;
  13679. }
  13680. /*
  13681. * fr/lb-LU validation function
  13682. * (numéro d’identification personnelle, persons only)
  13683. * Verify birth date validity and run Luhn and Verhoeff checks
  13684. */
  13685. function frLuCheck(tin) {
  13686. // Extract date and check validity
  13687. var date = "".concat(tin.slice(0, 4), "/").concat(tin.slice(4, 6), "/").concat(tin.slice(6, 8));
  13688. if (!(0, _isDate.default)(date, 'YYYY/MM/DD')) {
  13689. return false;
  13690. } // Run Luhn check
  13691. if (!algorithms.luhnCheck(tin.slice(0, 12))) {
  13692. return false;
  13693. } // Remove Luhn check digit and run Verhoeff check
  13694. return algorithms.verhoeffCheck("".concat(tin.slice(0, 11)).concat(tin[12]));
  13695. }
  13696. /*
  13697. * hr-HR validation function
  13698. * (Osobni identifikacijski broj (OIB), persons/entities)
  13699. * Verify TIN validity by calling iso7064Check(digits)
  13700. */
  13701. function hrHrCheck(tin) {
  13702. return algorithms.iso7064Check(tin);
  13703. }
  13704. /*
  13705. * hu-HU validation function
  13706. * (Adóazonosító jel, persons only)
  13707. * Verify TIN validity by calculating check (last) digit
  13708. */
  13709. function huHuCheck(tin) {
  13710. // split digits into an array for further processing
  13711. var digits = tin.split('').map(function (a) {
  13712. return parseInt(a, 10);
  13713. });
  13714. var checksum = 8;
  13715. for (var i = 1; i < 9; i++) {
  13716. checksum += digits[i] * (i + 1);
  13717. }
  13718. return checksum % 11 === digits[9];
  13719. }
  13720. /*
  13721. * lt-LT validation function (should go here if needed)
  13722. * (Asmens kodas, persons/entities respectively)
  13723. * Current validation check is alias of etEeCheck- same format applies
  13724. */
  13725. /*
  13726. * it-IT first/last name validity check
  13727. * Accepts it-IT TIN-encoded names as a three-element character array and checks their validity
  13728. * Due to lack of clarity between resources ("Are only Italian consonants used?
  13729. * What happens if a person has X in their name?" etc.) only two test conditions
  13730. * have been implemented:
  13731. * Vowels may only be followed by other vowels or an X character
  13732. * and X characters after vowels may only be followed by other X characters.
  13733. */
  13734. function itItNameCheck(name) {
  13735. // true at the first occurence of a vowel
  13736. var vowelflag = false; // true at the first occurence of an X AFTER vowel
  13737. // (to properly handle last names with X as consonant)
  13738. var xflag = false;
  13739. for (var i = 0; i < 3; i++) {
  13740. if (!vowelflag && /[AEIOU]/.test(name[i])) {
  13741. vowelflag = true;
  13742. } else if (!xflag && vowelflag && name[i] === 'X') {
  13743. xflag = true;
  13744. } else if (i > 0) {
  13745. if (vowelflag && !xflag) {
  13746. if (!/[AEIOU]/.test(name[i])) {
  13747. return false;
  13748. }
  13749. }
  13750. if (xflag) {
  13751. if (!/X/.test(name[i])) {
  13752. return false;
  13753. }
  13754. }
  13755. }
  13756. }
  13757. return true;
  13758. }
  13759. /*
  13760. * it-IT validation function
  13761. * (Codice fiscale (TIN-IT), persons only)
  13762. * Verify name, birth date and codice catastale validity
  13763. * and calculate check character.
  13764. * Material not in DG-TAXUD document sourced from:
  13765. * `https://en.wikipedia.org/wiki/Italian_fiscal_code`
  13766. */
  13767. function itItCheck(tin) {
  13768. // Capitalize and split characters into an array for further processing
  13769. var chars = tin.toUpperCase().split(''); // Check first and last name validity calling itItNameCheck()
  13770. if (!itItNameCheck(chars.slice(0, 3))) {
  13771. return false;
  13772. }
  13773. if (!itItNameCheck(chars.slice(3, 6))) {
  13774. return false;
  13775. } // Convert letters in number spaces back to numbers if any
  13776. var number_locations = [6, 7, 9, 10, 12, 13, 14];
  13777. var number_replace = {
  13778. L: '0',
  13779. M: '1',
  13780. N: '2',
  13781. P: '3',
  13782. Q: '4',
  13783. R: '5',
  13784. S: '6',
  13785. T: '7',
  13786. U: '8',
  13787. V: '9'
  13788. };
  13789. for (var _i4 = 0, _number_locations = number_locations; _i4 < _number_locations.length; _i4++) {
  13790. var i = _number_locations[_i4];
  13791. if (chars[i] in number_replace) {
  13792. chars.splice(i, 1, number_replace[chars[i]]);
  13793. }
  13794. } // Extract month and day, and check date validity
  13795. var month_replace = {
  13796. A: '01',
  13797. B: '02',
  13798. C: '03',
  13799. D: '04',
  13800. E: '05',
  13801. H: '06',
  13802. L: '07',
  13803. M: '08',
  13804. P: '09',
  13805. R: '10',
  13806. S: '11',
  13807. T: '12'
  13808. };
  13809. var month = month_replace[chars[8]];
  13810. var day = parseInt(chars[9] + chars[10], 10);
  13811. if (day > 40) {
  13812. day -= 40;
  13813. }
  13814. if (day < 10) {
  13815. day = "0".concat(day);
  13816. }
  13817. var date = "".concat(chars[6]).concat(chars[7], "/").concat(month, "/").concat(day);
  13818. if (!(0, _isDate.default)(date, 'YY/MM/DD')) {
  13819. return false;
  13820. } // Calculate check character by adding up even and odd characters as numbers
  13821. var checksum = 0;
  13822. for (var _i5 = 1; _i5 < chars.length - 1; _i5 += 2) {
  13823. var char_to_int = parseInt(chars[_i5], 10);
  13824. if (isNaN(char_to_int)) {
  13825. char_to_int = chars[_i5].charCodeAt(0) - 65;
  13826. }
  13827. checksum += char_to_int;
  13828. }
  13829. var odd_convert = {
  13830. // Maps of characters at odd places
  13831. A: 1,
  13832. B: 0,
  13833. C: 5,
  13834. D: 7,
  13835. E: 9,
  13836. F: 13,
  13837. G: 15,
  13838. H: 17,
  13839. I: 19,
  13840. J: 21,
  13841. K: 2,
  13842. L: 4,
  13843. M: 18,
  13844. N: 20,
  13845. O: 11,
  13846. P: 3,
  13847. Q: 6,
  13848. R: 8,
  13849. S: 12,
  13850. T: 14,
  13851. U: 16,
  13852. V: 10,
  13853. W: 22,
  13854. X: 25,
  13855. Y: 24,
  13856. Z: 23,
  13857. 0: 1,
  13858. 1: 0
  13859. };
  13860. for (var _i6 = 0; _i6 < chars.length - 1; _i6 += 2) {
  13861. var _char_to_int = 0;
  13862. if (chars[_i6] in odd_convert) {
  13863. _char_to_int = odd_convert[chars[_i6]];
  13864. } else {
  13865. var multiplier = parseInt(chars[_i6], 10);
  13866. _char_to_int = 2 * multiplier + 1;
  13867. if (multiplier > 4) {
  13868. _char_to_int += 2;
  13869. }
  13870. }
  13871. checksum += _char_to_int;
  13872. }
  13873. if (String.fromCharCode(65 + checksum % 26) !== chars[15]) {
  13874. return false;
  13875. }
  13876. return true;
  13877. }
  13878. /*
  13879. * lv-LV validation function
  13880. * (Personas kods (PK), persons only)
  13881. * Check validity of birth date and calculate check (last) digit
  13882. * Support only for old format numbers (not starting with '32', issued before 2017/07/01)
  13883. * Material not in DG TAXUD document sourced from:
  13884. * `https://boot.ritakafija.lv/forums/index.php?/topic/88314-personas-koda-algoritms-%C4%8Deksumma/`
  13885. */
  13886. function lvLvCheck(tin) {
  13887. tin = tin.replace(/\W/, ''); // Extract date from TIN
  13888. var day = tin.slice(0, 2);
  13889. if (day !== '32') {
  13890. // No date/checksum check if new format
  13891. var month = tin.slice(2, 4);
  13892. if (month !== '00') {
  13893. // No date check if unknown month
  13894. var full_year = tin.slice(4, 6);
  13895. switch (tin[6]) {
  13896. case '0':
  13897. full_year = "18".concat(full_year);
  13898. break;
  13899. case '1':
  13900. full_year = "19".concat(full_year);
  13901. break;
  13902. default:
  13903. full_year = "20".concat(full_year);
  13904. break;
  13905. } // Check date validity
  13906. var date = "".concat(full_year, "/").concat(tin.slice(2, 4), "/").concat(day);
  13907. if (!(0, _isDate.default)(date, 'YYYY/MM/DD')) {
  13908. return false;
  13909. }
  13910. } // Calculate check digit
  13911. var checksum = 1101;
  13912. var multip_lookup = [1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
  13913. for (var i = 0; i < tin.length - 1; i++) {
  13914. checksum -= parseInt(tin[i], 10) * multip_lookup[i];
  13915. }
  13916. return parseInt(tin[10], 10) === checksum % 11;
  13917. }
  13918. return true;
  13919. }
  13920. /*
  13921. * mt-MT validation function
  13922. * (Identity Card Number or Unique Taxpayer Reference, persons/entities)
  13923. * Verify Identity Card Number structure (no other tests found)
  13924. */
  13925. function mtMtCheck(tin) {
  13926. if (tin.length !== 9) {
  13927. // No tests for UTR
  13928. var chars = tin.toUpperCase().split(''); // Fill with zeros if smaller than proper
  13929. while (chars.length < 8) {
  13930. chars.unshift(0);
  13931. } // Validate format according to last character
  13932. switch (tin[7]) {
  13933. case 'A':
  13934. case 'P':
  13935. if (parseInt(chars[6], 10) === 0) {
  13936. return false;
  13937. }
  13938. break;
  13939. default:
  13940. {
  13941. var first_part = parseInt(chars.join('').slice(0, 5), 10);
  13942. if (first_part > 32000) {
  13943. return false;
  13944. }
  13945. var second_part = parseInt(chars.join('').slice(5, 7), 10);
  13946. if (first_part === second_part) {
  13947. return false;
  13948. }
  13949. }
  13950. }
  13951. }
  13952. return true;
  13953. }
  13954. /*
  13955. * nl-NL validation function
  13956. * (Burgerservicenummer (BSN) or Rechtspersonen Samenwerkingsverbanden Informatie Nummer (RSIN),
  13957. * persons/entities respectively)
  13958. * Verify TIN validity by calculating check (last) digit (variant of MOD 11)
  13959. */
  13960. function nlNlCheck(tin) {
  13961. return algorithms.reverseMultiplyAndSum(tin.split('').slice(0, 8).map(function (a) {
  13962. return parseInt(a, 10);
  13963. }), 9) % 11 === parseInt(tin[8], 10);
  13964. }
  13965. /*
  13966. * pl-PL validation function
  13967. * (Powszechny Elektroniczny System Ewidencji Ludności (PESEL)
  13968. * or Numer identyfikacji podatkowej (NIP), persons/entities)
  13969. * Verify TIN validity by validating birth date (PESEL) and calculating check (last) digit
  13970. */
  13971. function plPlCheck(tin) {
  13972. // NIP
  13973. if (tin.length === 10) {
  13974. // Calculate last digit by multiplying with lookup
  13975. var lookup = [6, 5, 7, 2, 3, 4, 5, 6, 7];
  13976. var _checksum = 0;
  13977. for (var i = 0; i < lookup.length; i++) {
  13978. _checksum += parseInt(tin[i], 10) * lookup[i];
  13979. }
  13980. _checksum %= 11;
  13981. if (_checksum === 10) {
  13982. return false;
  13983. }
  13984. return _checksum === parseInt(tin[9], 10);
  13985. } // PESEL
  13986. // Extract full year using month
  13987. var full_year = tin.slice(0, 2);
  13988. var month = parseInt(tin.slice(2, 4), 10);
  13989. if (month > 80) {
  13990. full_year = "18".concat(full_year);
  13991. month -= 80;
  13992. } else if (month > 60) {
  13993. full_year = "22".concat(full_year);
  13994. month -= 60;
  13995. } else if (month > 40) {
  13996. full_year = "21".concat(full_year);
  13997. month -= 40;
  13998. } else if (month > 20) {
  13999. full_year = "20".concat(full_year);
  14000. month -= 20;
  14001. } else {
  14002. full_year = "19".concat(full_year);
  14003. } // Add leading zero to month if needed
  14004. if (month < 10) {
  14005. month = "0".concat(month);
  14006. } // Check date validity
  14007. var date = "".concat(full_year, "/").concat(month, "/").concat(tin.slice(4, 6));
  14008. if (!(0, _isDate.default)(date, 'YYYY/MM/DD')) {
  14009. return false;
  14010. } // Calculate last digit by mulitplying with odd one-digit numbers except 5
  14011. var checksum = 0;
  14012. var multiplier = 1;
  14013. for (var _i7 = 0; _i7 < tin.length - 1; _i7++) {
  14014. checksum += parseInt(tin[_i7], 10) * multiplier % 10;
  14015. multiplier += 2;
  14016. if (multiplier > 10) {
  14017. multiplier = 1;
  14018. } else if (multiplier === 5) {
  14019. multiplier += 2;
  14020. }
  14021. }
  14022. checksum = 10 - checksum % 10;
  14023. return checksum === parseInt(tin[10], 10);
  14024. }
  14025. /*
  14026. * pt-BR validation function
  14027. * (Cadastro de Pessoas Físicas (CPF, persons)
  14028. * Cadastro Nacional de Pessoas Jurídicas (CNPJ, entities)
  14029. * Both inputs will be validated
  14030. */
  14031. function ptBrCheck(tin) {
  14032. if (tin.length === 11) {
  14033. var _sum;
  14034. var remainder;
  14035. _sum = 0;
  14036. if ( // Reject known invalid CPFs
  14037. tin === '11111111111' || tin === '22222222222' || tin === '33333333333' || tin === '44444444444' || tin === '55555555555' || tin === '66666666666' || tin === '77777777777' || tin === '88888888888' || tin === '99999999999' || tin === '00000000000') return false;
  14038. for (var i = 1; i <= 9; i++) {
  14039. _sum += parseInt(tin.substring(i - 1, i), 10) * (11 - i);
  14040. }
  14041. remainder = _sum * 10 % 11;
  14042. if (remainder === 10) remainder = 0;
  14043. if (remainder !== parseInt(tin.substring(9, 10), 10)) return false;
  14044. _sum = 0;
  14045. for (var _i8 = 1; _i8 <= 10; _i8++) {
  14046. _sum += parseInt(tin.substring(_i8 - 1, _i8), 10) * (12 - _i8);
  14047. }
  14048. remainder = _sum * 10 % 11;
  14049. if (remainder === 10) remainder = 0;
  14050. if (remainder !== parseInt(tin.substring(10, 11), 10)) return false;
  14051. return true;
  14052. }
  14053. if ( // Reject know invalid CNPJs
  14054. tin === '00000000000000' || tin === '11111111111111' || tin === '22222222222222' || tin === '33333333333333' || tin === '44444444444444' || tin === '55555555555555' || tin === '66666666666666' || tin === '77777777777777' || tin === '88888888888888' || tin === '99999999999999') {
  14055. return false;
  14056. }
  14057. var length = tin.length - 2;
  14058. var identifiers = tin.substring(0, length);
  14059. var verificators = tin.substring(length);
  14060. var sum = 0;
  14061. var pos = length - 7;
  14062. for (var _i9 = length; _i9 >= 1; _i9--) {
  14063. sum += identifiers.charAt(length - _i9) * pos;
  14064. pos -= 1;
  14065. if (pos < 2) {
  14066. pos = 9;
  14067. }
  14068. }
  14069. var result = sum % 11 < 2 ? 0 : 11 - sum % 11;
  14070. if (result !== parseInt(verificators.charAt(0), 10)) {
  14071. return false;
  14072. }
  14073. length += 1;
  14074. identifiers = tin.substring(0, length);
  14075. sum = 0;
  14076. pos = length - 7;
  14077. for (var _i10 = length; _i10 >= 1; _i10--) {
  14078. sum += identifiers.charAt(length - _i10) * pos;
  14079. pos -= 1;
  14080. if (pos < 2) {
  14081. pos = 9;
  14082. }
  14083. }
  14084. result = sum % 11 < 2 ? 0 : 11 - sum % 11;
  14085. if (result !== parseInt(verificators.charAt(1), 10)) {
  14086. return false;
  14087. }
  14088. return true;
  14089. }
  14090. /*
  14091. * pt-PT validation function
  14092. * (Número de identificação fiscal (NIF), persons/entities)
  14093. * Verify TIN validity by calculating check (last) digit (variant of MOD 11)
  14094. */
  14095. function ptPtCheck(tin) {
  14096. var checksum = 11 - algorithms.reverseMultiplyAndSum(tin.split('').slice(0, 8).map(function (a) {
  14097. return parseInt(a, 10);
  14098. }), 9) % 11;
  14099. if (checksum > 9) {
  14100. return parseInt(tin[8], 10) === 0;
  14101. }
  14102. return checksum === parseInt(tin[8], 10);
  14103. }
  14104. /*
  14105. * ro-RO validation function
  14106. * (Cod Numeric Personal (CNP) or Cod de înregistrare fiscală (CIF),
  14107. * persons only)
  14108. * Verify CNP validity by calculating check (last) digit (test not found for CIF)
  14109. * Material not in DG TAXUD document sourced from:
  14110. * `https://en.wikipedia.org/wiki/National_identification_number#Romania`
  14111. */
  14112. function roRoCheck(tin) {
  14113. if (tin.slice(0, 4) !== '9000') {
  14114. // No test found for this format
  14115. // Extract full year using century digit if possible
  14116. var full_year = tin.slice(1, 3);
  14117. switch (tin[0]) {
  14118. case '1':
  14119. case '2':
  14120. full_year = "19".concat(full_year);
  14121. break;
  14122. case '3':
  14123. case '4':
  14124. full_year = "18".concat(full_year);
  14125. break;
  14126. case '5':
  14127. case '6':
  14128. full_year = "20".concat(full_year);
  14129. break;
  14130. default:
  14131. } // Check date validity
  14132. var date = "".concat(full_year, "/").concat(tin.slice(3, 5), "/").concat(tin.slice(5, 7));
  14133. if (date.length === 8) {
  14134. if (!(0, _isDate.default)(date, 'YY/MM/DD')) {
  14135. return false;
  14136. }
  14137. } else if (!(0, _isDate.default)(date, 'YYYY/MM/DD')) {
  14138. return false;
  14139. } // Calculate check digit
  14140. var digits = tin.split('').map(function (a) {
  14141. return parseInt(a, 10);
  14142. });
  14143. var multipliers = [2, 7, 9, 1, 4, 6, 3, 5, 8, 2, 7, 9];
  14144. var checksum = 0;
  14145. for (var i = 0; i < multipliers.length; i++) {
  14146. checksum += digits[i] * multipliers[i];
  14147. }
  14148. if (checksum % 11 === 10) {
  14149. return digits[12] === 1;
  14150. }
  14151. return digits[12] === checksum % 11;
  14152. }
  14153. return true;
  14154. }
  14155. /*
  14156. * sk-SK validation function
  14157. * (Rodné číslo (RČ) or bezvýznamové identifikačné číslo (BIČ), persons only)
  14158. * Checks validity of pre-1954 birth numbers (rodné číslo) only
  14159. * Due to the introduction of the pseudo-random BIČ it is not possible to test
  14160. * post-1954 birth numbers without knowing whether they are BIČ or RČ beforehand
  14161. */
  14162. function skSkCheck(tin) {
  14163. if (tin.length === 9) {
  14164. tin = tin.replace(/\W/, '');
  14165. if (tin.slice(6) === '000') {
  14166. return false;
  14167. } // Three-zero serial not assigned before 1954
  14168. // Extract full year from TIN length
  14169. var full_year = parseInt(tin.slice(0, 2), 10);
  14170. if (full_year > 53) {
  14171. return false;
  14172. }
  14173. if (full_year < 10) {
  14174. full_year = "190".concat(full_year);
  14175. } else {
  14176. full_year = "19".concat(full_year);
  14177. } // Extract month from TIN and normalize
  14178. var month = parseInt(tin.slice(2, 4), 10);
  14179. if (month > 50) {
  14180. month -= 50;
  14181. }
  14182. if (month < 10) {
  14183. month = "0".concat(month);
  14184. } // Check date validity
  14185. var date = "".concat(full_year, "/").concat(month, "/").concat(tin.slice(4, 6));
  14186. if (!(0, _isDate.default)(date, 'YYYY/MM/DD')) {
  14187. return false;
  14188. }
  14189. }
  14190. return true;
  14191. }
  14192. /*
  14193. * sl-SI validation function
  14194. * (Davčna številka, persons/entities)
  14195. * Verify TIN validity by calculating check (last) digit (variant of MOD 11)
  14196. */
  14197. function slSiCheck(tin) {
  14198. var checksum = 11 - algorithms.reverseMultiplyAndSum(tin.split('').slice(0, 7).map(function (a) {
  14199. return parseInt(a, 10);
  14200. }), 8) % 11;
  14201. if (checksum === 10) {
  14202. return parseInt(tin[7], 10) === 0;
  14203. }
  14204. return checksum === parseInt(tin[7], 10);
  14205. }
  14206. /*
  14207. * sv-SE validation function
  14208. * (Personnummer or samordningsnummer, persons only)
  14209. * Checks validity of birth date and calls luhnCheck() to validate check (last) digit
  14210. */
  14211. function svSeCheck(tin) {
  14212. // Make copy of TIN and normalize to two-digit year form
  14213. var tin_copy = tin.slice(0);
  14214. if (tin.length > 11) {
  14215. tin_copy = tin_copy.slice(2);
  14216. } // Extract date of birth
  14217. var full_year = '';
  14218. var month = tin_copy.slice(2, 4);
  14219. var day = parseInt(tin_copy.slice(4, 6), 10);
  14220. if (tin.length > 11) {
  14221. full_year = tin.slice(0, 4);
  14222. } else {
  14223. full_year = tin.slice(0, 2);
  14224. if (tin.length === 11 && day < 60) {
  14225. // Extract full year from centenarian symbol
  14226. // Should work just fine until year 10000 or so
  14227. var current_year = new Date().getFullYear().toString();
  14228. var current_century = parseInt(current_year.slice(0, 2), 10);
  14229. current_year = parseInt(current_year, 10);
  14230. if (tin[6] === '-') {
  14231. if (parseInt("".concat(current_century).concat(full_year), 10) > current_year) {
  14232. full_year = "".concat(current_century - 1).concat(full_year);
  14233. } else {
  14234. full_year = "".concat(current_century).concat(full_year);
  14235. }
  14236. } else {
  14237. full_year = "".concat(current_century - 1).concat(full_year);
  14238. if (current_year - parseInt(full_year, 10) < 100) {
  14239. return false;
  14240. }
  14241. }
  14242. }
  14243. } // Normalize day and check date validity
  14244. if (day > 60) {
  14245. day -= 60;
  14246. }
  14247. if (day < 10) {
  14248. day = "0".concat(day);
  14249. }
  14250. var date = "".concat(full_year, "/").concat(month, "/").concat(day);
  14251. if (date.length === 8) {
  14252. if (!(0, _isDate.default)(date, 'YY/MM/DD')) {
  14253. return false;
  14254. }
  14255. } else if (!(0, _isDate.default)(date, 'YYYY/MM/DD')) {
  14256. return false;
  14257. }
  14258. return algorithms.luhnCheck(tin.replace(/\W/, ''));
  14259. } // Locale lookup objects
  14260. /*
  14261. * Tax id regex formats for various locales
  14262. *
  14263. * Where not explicitly specified in DG-TAXUD document both
  14264. * uppercase and lowercase letters are acceptable.
  14265. */
  14266. var taxIdFormat = {
  14267. 'bg-BG': /^\d{10}$/,
  14268. 'cs-CZ': /^\d{6}\/{0,1}\d{3,4}$/,
  14269. 'de-AT': /^\d{9}$/,
  14270. 'de-DE': /^[1-9]\d{10}$/,
  14271. 'dk-DK': /^\d{6}-{0,1}\d{4}$/,
  14272. 'el-CY': /^[09]\d{7}[A-Z]$/,
  14273. 'el-GR': /^([0-4]|[7-9])\d{8}$/,
  14274. 'en-GB': /^\d{10}$|^(?!GB|NK|TN|ZZ)(?![DFIQUV])[A-Z](?![DFIQUVO])[A-Z]\d{6}[ABCD ]$/i,
  14275. 'en-IE': /^\d{7}[A-W][A-IW]{0,1}$/i,
  14276. 'en-US': /^\d{2}[- ]{0,1}\d{7}$/,
  14277. 'es-ES': /^(\d{0,8}|[XYZKLM]\d{7})[A-HJ-NP-TV-Z]$/i,
  14278. 'et-EE': /^[1-6]\d{6}(00[1-9]|0[1-9][0-9]|[1-6][0-9]{2}|70[0-9]|710)\d$/,
  14279. 'fi-FI': /^\d{6}[-+A]\d{3}[0-9A-FHJ-NPR-Y]$/i,
  14280. 'fr-BE': /^\d{11}$/,
  14281. 'fr-FR': /^[0-3]\d{12}$|^[0-3]\d\s\d{2}(\s\d{3}){3}$/,
  14282. // Conforms both to official spec and provided example
  14283. 'fr-LU': /^\d{13}$/,
  14284. 'hr-HR': /^\d{11}$/,
  14285. 'hu-HU': /^8\d{9}$/,
  14286. '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,
  14287. 'lv-LV': /^\d{6}-{0,1}\d{5}$/,
  14288. // Conforms both to DG TAXUD spec and original research
  14289. 'mt-MT': /^\d{3,7}[APMGLHBZ]$|^([1-8])\1\d{7}$/i,
  14290. 'nl-NL': /^\d{9}$/,
  14291. 'pl-PL': /^\d{10,11}$/,
  14292. 'pt-BR': /(?:^\d{11}$)|(?:^\d{14}$)/,
  14293. 'pt-PT': /^\d{9}$/,
  14294. 'ro-RO': /^\d{13}$/,
  14295. 'sk-SK': /^\d{6}\/{0,1}\d{3,4}$/,
  14296. 'sl-SI': /^[1-9]\d{7}$/,
  14297. 'sv-SE': /^(\d{6}[-+]{0,1}\d{4}|(18|19|20)\d{6}[-+]{0,1}\d{4})$/
  14298. }; // taxIdFormat locale aliases
  14299. taxIdFormat['lb-LU'] = taxIdFormat['fr-LU'];
  14300. taxIdFormat['lt-LT'] = taxIdFormat['et-EE'];
  14301. taxIdFormat['nl-BE'] = taxIdFormat['fr-BE']; // Algorithmic tax id check functions for various locales
  14302. var taxIdCheck = {
  14303. 'bg-BG': bgBgCheck,
  14304. 'cs-CZ': csCzCheck,
  14305. 'de-AT': deAtCheck,
  14306. 'de-DE': deDeCheck,
  14307. 'dk-DK': dkDkCheck,
  14308. 'el-CY': elCyCheck,
  14309. 'el-GR': elGrCheck,
  14310. 'en-IE': enIeCheck,
  14311. 'en-US': enUsCheck,
  14312. 'es-ES': esEsCheck,
  14313. 'et-EE': etEeCheck,
  14314. 'fi-FI': fiFiCheck,
  14315. 'fr-BE': frBeCheck,
  14316. 'fr-FR': frFrCheck,
  14317. 'fr-LU': frLuCheck,
  14318. 'hr-HR': hrHrCheck,
  14319. 'hu-HU': huHuCheck,
  14320. 'it-IT': itItCheck,
  14321. 'lv-LV': lvLvCheck,
  14322. 'mt-MT': mtMtCheck,
  14323. 'nl-NL': nlNlCheck,
  14324. 'pl-PL': plPlCheck,
  14325. 'pt-BR': ptBrCheck,
  14326. 'pt-PT': ptPtCheck,
  14327. 'ro-RO': roRoCheck,
  14328. 'sk-SK': skSkCheck,
  14329. 'sl-SI': slSiCheck,
  14330. 'sv-SE': svSeCheck
  14331. }; // taxIdCheck locale aliases
  14332. taxIdCheck['lb-LU'] = taxIdCheck['fr-LU'];
  14333. taxIdCheck['lt-LT'] = taxIdCheck['et-EE'];
  14334. taxIdCheck['nl-BE'] = taxIdCheck['fr-BE']; // Regexes for locales where characters should be omitted before checking format
  14335. var allsymbols = /[-\\\/!@#$%\^&\*\(\)\+\=\[\]]+/g;
  14336. var sanitizeRegexes = {
  14337. 'de-AT': allsymbols,
  14338. 'de-DE': /[\/\\]/g,
  14339. 'fr-BE': allsymbols
  14340. }; // sanitizeRegexes locale aliases
  14341. sanitizeRegexes['nl-BE'] = sanitizeRegexes['fr-BE'];
  14342. /*
  14343. * Validator function
  14344. * Return true if the passed string is a valid tax identification number
  14345. * for the specified locale.
  14346. * Throw an error exception if the locale is not supported.
  14347. */
  14348. function isTaxID(str) {
  14349. var locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'en-US';
  14350. (0, _assertString.default)(str); // Copy TIN to avoid replacement if sanitized
  14351. var strcopy = str.slice(0);
  14352. if (locale in taxIdFormat) {
  14353. if (locale in sanitizeRegexes) {
  14354. strcopy = strcopy.replace(sanitizeRegexes[locale], '');
  14355. }
  14356. if (!taxIdFormat[locale].test(strcopy)) {
  14357. return false;
  14358. }
  14359. if (locale in taxIdCheck) {
  14360. return taxIdCheck[locale](strcopy);
  14361. } // Fallthrough; not all locales have algorithmic checks
  14362. return true;
  14363. }
  14364. throw new Error("Invalid locale '".concat(locale, "'"));
  14365. }
  14366. module.exports = exports.default;
  14367. module.exports.default = exports.default;
  14368. },{"./isDate":61,"./util/algorithms":134,"./util/assertString":135}],117:[function(require,module,exports){
  14369. "use strict";
  14370. Object.defineProperty(exports, "__esModule", {
  14371. value: true
  14372. });
  14373. exports.default = isURL;
  14374. var _assertString = _interopRequireDefault(require("./util/assertString"));
  14375. var _isFQDN = _interopRequireDefault(require("./isFQDN"));
  14376. var _isIP = _interopRequireDefault(require("./isIP"));
  14377. var _merge = _interopRequireDefault(require("./util/merge"));
  14378. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  14379. function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
  14380. function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
  14381. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  14382. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  14383. function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
  14384. function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
  14385. /*
  14386. options for isURL method
  14387. require_protocol - if set as true isURL will return false if protocol is not present in the URL
  14388. require_valid_protocol - isURL will check if the URL's protocol is present in the protocols option
  14389. protocols - valid protocols can be modified with this option
  14390. require_host - if set as false isURL will not check if host is present in the URL
  14391. require_port - if set as true isURL will check if port is present in the URL
  14392. allow_protocol_relative_urls - if set as true protocol relative URLs will be allowed
  14393. validate_length - if set as false isURL will skip string length validation (IE maximum is 2083)
  14394. */
  14395. var default_url_options = {
  14396. protocols: ['http', 'https', 'ftp'],
  14397. require_tld: true,
  14398. require_protocol: false,
  14399. require_host: true,
  14400. require_port: false,
  14401. require_valid_protocol: true,
  14402. allow_underscores: false,
  14403. allow_trailing_dot: false,
  14404. allow_protocol_relative_urls: false,
  14405. allow_fragments: true,
  14406. allow_query_components: true,
  14407. validate_length: true
  14408. };
  14409. var wrapped_ipv6 = /^\[([^\]]+)\](?::([0-9]+))?$/;
  14410. function isRegExp(obj) {
  14411. return Object.prototype.toString.call(obj) === '[object RegExp]';
  14412. }
  14413. function checkHost(host, matches) {
  14414. for (var i = 0; i < matches.length; i++) {
  14415. var match = matches[i];
  14416. if (host === match || isRegExp(match) && match.test(host)) {
  14417. return true;
  14418. }
  14419. }
  14420. return false;
  14421. }
  14422. function isURL(url, options) {
  14423. (0, _assertString.default)(url);
  14424. if (!url || /[\s<>]/.test(url)) {
  14425. return false;
  14426. }
  14427. if (url.indexOf('mailto:') === 0) {
  14428. return false;
  14429. }
  14430. options = (0, _merge.default)(options, default_url_options);
  14431. if (options.validate_length && url.length >= 2083) {
  14432. return false;
  14433. }
  14434. if (!options.allow_fragments && url.includes('#')) {
  14435. return false;
  14436. }
  14437. if (!options.allow_query_components && (url.includes('?') || url.includes('&'))) {
  14438. return false;
  14439. }
  14440. var protocol, auth, host, hostname, port, port_str, split, ipv6;
  14441. split = url.split('#');
  14442. url = split.shift();
  14443. split = url.split('?');
  14444. url = split.shift();
  14445. split = url.split('://');
  14446. if (split.length > 1) {
  14447. protocol = split.shift().toLowerCase();
  14448. if (options.require_valid_protocol && options.protocols.indexOf(protocol) === -1) {
  14449. return false;
  14450. }
  14451. } else if (options.require_protocol) {
  14452. return false;
  14453. } else if (url.substr(0, 2) === '//') {
  14454. if (!options.allow_protocol_relative_urls) {
  14455. return false;
  14456. }
  14457. split[0] = url.substr(2);
  14458. }
  14459. url = split.join('://');
  14460. if (url === '') {
  14461. return false;
  14462. }
  14463. split = url.split('/');
  14464. url = split.shift();
  14465. if (url === '' && !options.require_host) {
  14466. return true;
  14467. }
  14468. split = url.split('@');
  14469. if (split.length > 1) {
  14470. if (options.disallow_auth) {
  14471. return false;
  14472. }
  14473. if (split[0] === '') {
  14474. return false;
  14475. }
  14476. auth = split.shift();
  14477. if (auth.indexOf(':') >= 0 && auth.split(':').length > 2) {
  14478. return false;
  14479. }
  14480. var _auth$split = auth.split(':'),
  14481. _auth$split2 = _slicedToArray(_auth$split, 2),
  14482. user = _auth$split2[0],
  14483. password = _auth$split2[1];
  14484. if (user === '' && password === '') {
  14485. return false;
  14486. }
  14487. }
  14488. hostname = split.join('@');
  14489. port_str = null;
  14490. ipv6 = null;
  14491. var ipv6_match = hostname.match(wrapped_ipv6);
  14492. if (ipv6_match) {
  14493. host = '';
  14494. ipv6 = ipv6_match[1];
  14495. port_str = ipv6_match[2] || null;
  14496. } else {
  14497. split = hostname.split(':');
  14498. host = split.shift();
  14499. if (split.length) {
  14500. port_str = split.join(':');
  14501. }
  14502. }
  14503. if (port_str !== null && port_str.length > 0) {
  14504. port = parseInt(port_str, 10);
  14505. if (!/^[0-9]+$/.test(port_str) || port <= 0 || port > 65535) {
  14506. return false;
  14507. }
  14508. } else if (options.require_port) {
  14509. return false;
  14510. }
  14511. if (options.host_whitelist) {
  14512. return checkHost(host, options.host_whitelist);
  14513. }
  14514. if (!(0, _isIP.default)(host) && !(0, _isFQDN.default)(host, options) && (!ipv6 || !(0, _isIP.default)(ipv6, 6))) {
  14515. return false;
  14516. }
  14517. host = host || ipv6;
  14518. if (options.host_blacklist && checkHost(host, options.host_blacklist)) {
  14519. return false;
  14520. }
  14521. return true;
  14522. }
  14523. module.exports = exports.default;
  14524. module.exports.default = exports.default;
  14525. },{"./isFQDN":68,"./isIP":78,"./util/assertString":135,"./util/merge":137}],118:[function(require,module,exports){
  14526. "use strict";
  14527. Object.defineProperty(exports, "__esModule", {
  14528. value: true
  14529. });
  14530. exports.default = isUUID;
  14531. var _assertString = _interopRequireDefault(require("./util/assertString"));
  14532. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  14533. var uuid = {
  14534. 1: /^[0-9A-F]{8}-[0-9A-F]{4}-1[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,
  14535. 2: /^[0-9A-F]{8}-[0-9A-F]{4}-2[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,
  14536. 3: /^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,
  14537. 4: /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
  14538. 5: /^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
  14539. all: /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i
  14540. };
  14541. function isUUID(str, version) {
  14542. (0, _assertString.default)(str);
  14543. var pattern = uuid[![undefined, null].includes(version) ? version : 'all'];
  14544. return !!pattern && pattern.test(str);
  14545. }
  14546. module.exports = exports.default;
  14547. module.exports.default = exports.default;
  14548. },{"./util/assertString":135}],119:[function(require,module,exports){
  14549. "use strict";
  14550. Object.defineProperty(exports, "__esModule", {
  14551. value: true
  14552. });
  14553. exports.default = isUppercase;
  14554. var _assertString = _interopRequireDefault(require("./util/assertString"));
  14555. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  14556. function isUppercase(str) {
  14557. (0, _assertString.default)(str);
  14558. return str === str.toUpperCase();
  14559. }
  14560. module.exports = exports.default;
  14561. module.exports.default = exports.default;
  14562. },{"./util/assertString":135}],120:[function(require,module,exports){
  14563. "use strict";
  14564. Object.defineProperty(exports, "__esModule", {
  14565. value: true
  14566. });
  14567. exports.default = isVAT;
  14568. exports.vatMatchers = void 0;
  14569. var _assertString = _interopRequireDefault(require("./util/assertString"));
  14570. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  14571. var vatMatchers = {
  14572. GB: /^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}))$/,
  14573. IT: /^(IT)?[0-9]{11}$/,
  14574. NL: /^(NL)?[0-9]{9}B[0-9]{2}$/
  14575. };
  14576. exports.vatMatchers = vatMatchers;
  14577. function isVAT(str, countryCode) {
  14578. (0, _assertString.default)(str);
  14579. (0, _assertString.default)(countryCode);
  14580. if (countryCode in vatMatchers) {
  14581. return vatMatchers[countryCode].test(str);
  14582. }
  14583. throw new Error("Invalid country code: '".concat(countryCode, "'"));
  14584. }
  14585. },{"./util/assertString":135}],121:[function(require,module,exports){
  14586. "use strict";
  14587. Object.defineProperty(exports, "__esModule", {
  14588. value: true
  14589. });
  14590. exports.default = isVariableWidth;
  14591. var _assertString = _interopRequireDefault(require("./util/assertString"));
  14592. var _isFullWidth = require("./isFullWidth");
  14593. var _isHalfWidth = require("./isHalfWidth");
  14594. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  14595. function isVariableWidth(str) {
  14596. (0, _assertString.default)(str);
  14597. return _isFullWidth.fullWidth.test(str) && _isHalfWidth.halfWidth.test(str);
  14598. }
  14599. module.exports = exports.default;
  14600. module.exports.default = exports.default;
  14601. },{"./isFullWidth":70,"./isHalfWidth":72,"./util/assertString":135}],122:[function(require,module,exports){
  14602. "use strict";
  14603. Object.defineProperty(exports, "__esModule", {
  14604. value: true
  14605. });
  14606. exports.default = isWhitelisted;
  14607. var _assertString = _interopRequireDefault(require("./util/assertString"));
  14608. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  14609. function isWhitelisted(str, chars) {
  14610. (0, _assertString.default)(str);
  14611. for (var i = str.length - 1; i >= 0; i--) {
  14612. if (chars.indexOf(str[i]) === -1) {
  14613. return false;
  14614. }
  14615. }
  14616. return true;
  14617. }
  14618. module.exports = exports.default;
  14619. module.exports.default = exports.default;
  14620. },{"./util/assertString":135}],123:[function(require,module,exports){
  14621. "use strict";
  14622. Object.defineProperty(exports, "__esModule", {
  14623. value: true
  14624. });
  14625. exports.default = ltrim;
  14626. var _assertString = _interopRequireDefault(require("./util/assertString"));
  14627. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  14628. function ltrim(str, chars) {
  14629. (0, _assertString.default)(str); // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Escaping
  14630. var pattern = chars ? new RegExp("^[".concat(chars.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), "]+"), 'g') : /^\s+/g;
  14631. return str.replace(pattern, '');
  14632. }
  14633. module.exports = exports.default;
  14634. module.exports.default = exports.default;
  14635. },{"./util/assertString":135}],124:[function(require,module,exports){
  14636. "use strict";
  14637. Object.defineProperty(exports, "__esModule", {
  14638. value: true
  14639. });
  14640. exports.default = matches;
  14641. var _assertString = _interopRequireDefault(require("./util/assertString"));
  14642. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  14643. function matches(str, pattern, modifiers) {
  14644. (0, _assertString.default)(str);
  14645. if (Object.prototype.toString.call(pattern) !== '[object RegExp]') {
  14646. pattern = new RegExp(pattern, modifiers);
  14647. }
  14648. return pattern.test(str);
  14649. }
  14650. module.exports = exports.default;
  14651. module.exports.default = exports.default;
  14652. },{"./util/assertString":135}],125:[function(require,module,exports){
  14653. "use strict";
  14654. Object.defineProperty(exports, "__esModule", {
  14655. value: true
  14656. });
  14657. exports.default = normalizeEmail;
  14658. var _merge = _interopRequireDefault(require("./util/merge"));
  14659. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  14660. var default_normalize_email_options = {
  14661. // The following options apply to all email addresses
  14662. // Lowercases the local part of the email address.
  14663. // Please note this may violate RFC 5321 as per http://stackoverflow.com/a/9808332/192024).
  14664. // The domain is always lowercased, as per RFC 1035
  14665. all_lowercase: true,
  14666. // The following conversions are specific to GMail
  14667. // Lowercases the local part of the GMail address (known to be case-insensitive)
  14668. gmail_lowercase: true,
  14669. // Removes dots from the local part of the email address, as that's ignored by GMail
  14670. gmail_remove_dots: true,
  14671. // Removes the subaddress (e.g. "+foo") from the email address
  14672. gmail_remove_subaddress: true,
  14673. // Conversts the googlemail.com domain to gmail.com
  14674. gmail_convert_googlemaildotcom: true,
  14675. // The following conversions are specific to Outlook.com / Windows Live / Hotmail
  14676. // Lowercases the local part of the Outlook.com address (known to be case-insensitive)
  14677. outlookdotcom_lowercase: true,
  14678. // Removes the subaddress (e.g. "+foo") from the email address
  14679. outlookdotcom_remove_subaddress: true,
  14680. // The following conversions are specific to Yahoo
  14681. // Lowercases the local part of the Yahoo address (known to be case-insensitive)
  14682. yahoo_lowercase: true,
  14683. // Removes the subaddress (e.g. "-foo") from the email address
  14684. yahoo_remove_subaddress: true,
  14685. // The following conversions are specific to Yandex
  14686. // Lowercases the local part of the Yandex address (known to be case-insensitive)
  14687. yandex_lowercase: true,
  14688. // The following conversions are specific to iCloud
  14689. // Lowercases the local part of the iCloud address (known to be case-insensitive)
  14690. icloud_lowercase: true,
  14691. // Removes the subaddress (e.g. "+foo") from the email address
  14692. icloud_remove_subaddress: true
  14693. }; // List of domains used by iCloud
  14694. var icloud_domains = ['icloud.com', 'me.com']; // List of domains used by Outlook.com and its predecessors
  14695. // This list is likely incomplete.
  14696. // Partial reference:
  14697. // https://blogs.office.com/2013/04/17/outlook-com-gets-two-step-verification-sign-in-by-alias-and-new-international-domains/
  14698. 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']; // List of domains used by Yahoo Mail
  14699. // This list is likely incomplete
  14700. var yahoo_domains = ['rocketmail.com', 'yahoo.ca', 'yahoo.co.uk', 'yahoo.com', 'yahoo.de', 'yahoo.fr', 'yahoo.in', 'yahoo.it', 'ymail.com']; // List of domains used by yandex.ru
  14701. var yandex_domains = ['yandex.ru', 'yandex.ua', 'yandex.kz', 'yandex.com', 'yandex.by', 'ya.ru']; // replace single dots, but not multiple consecutive dots
  14702. function dotsReplacer(match) {
  14703. if (match.length > 1) {
  14704. return match;
  14705. }
  14706. return '';
  14707. }
  14708. function normalizeEmail(email, options) {
  14709. options = (0, _merge.default)(options, default_normalize_email_options);
  14710. var raw_parts = email.split('@');
  14711. var domain = raw_parts.pop();
  14712. var user = raw_parts.join('@');
  14713. var parts = [user, domain]; // The domain is always lowercased, as it's case-insensitive per RFC 1035
  14714. parts[1] = parts[1].toLowerCase();
  14715. if (parts[1] === 'gmail.com' || parts[1] === 'googlemail.com') {
  14716. // Address is GMail
  14717. if (options.gmail_remove_subaddress) {
  14718. parts[0] = parts[0].split('+')[0];
  14719. }
  14720. if (options.gmail_remove_dots) {
  14721. // this does not replace consecutive dots like example..email@gmail.com
  14722. parts[0] = parts[0].replace(/\.+/g, dotsReplacer);
  14723. }
  14724. if (!parts[0].length) {
  14725. return false;
  14726. }
  14727. if (options.all_lowercase || options.gmail_lowercase) {
  14728. parts[0] = parts[0].toLowerCase();
  14729. }
  14730. parts[1] = options.gmail_convert_googlemaildotcom ? 'gmail.com' : parts[1];
  14731. } else if (icloud_domains.indexOf(parts[1]) >= 0) {
  14732. // Address is iCloud
  14733. if (options.icloud_remove_subaddress) {
  14734. parts[0] = parts[0].split('+')[0];
  14735. }
  14736. if (!parts[0].length) {
  14737. return false;
  14738. }
  14739. if (options.all_lowercase || options.icloud_lowercase) {
  14740. parts[0] = parts[0].toLowerCase();
  14741. }
  14742. } else if (outlookdotcom_domains.indexOf(parts[1]) >= 0) {
  14743. // Address is Outlook.com
  14744. if (options.outlookdotcom_remove_subaddress) {
  14745. parts[0] = parts[0].split('+')[0];
  14746. }
  14747. if (!parts[0].length) {
  14748. return false;
  14749. }
  14750. if (options.all_lowercase || options.outlookdotcom_lowercase) {
  14751. parts[0] = parts[0].toLowerCase();
  14752. }
  14753. } else if (yahoo_domains.indexOf(parts[1]) >= 0) {
  14754. // Address is Yahoo
  14755. if (options.yahoo_remove_subaddress) {
  14756. var components = parts[0].split('-');
  14757. parts[0] = components.length > 1 ? components.slice(0, -1).join('-') : components[0];
  14758. }
  14759. if (!parts[0].length) {
  14760. return false;
  14761. }
  14762. if (options.all_lowercase || options.yahoo_lowercase) {
  14763. parts[0] = parts[0].toLowerCase();
  14764. }
  14765. } else if (yandex_domains.indexOf(parts[1]) >= 0) {
  14766. if (options.all_lowercase || options.yandex_lowercase) {
  14767. parts[0] = parts[0].toLowerCase();
  14768. }
  14769. parts[1] = 'yandex.ru'; // all yandex domains are equal, 1st preferred
  14770. } else if (options.all_lowercase) {
  14771. // Any other address
  14772. parts[0] = parts[0].toLowerCase();
  14773. }
  14774. return parts.join('@');
  14775. }
  14776. module.exports = exports.default;
  14777. module.exports.default = exports.default;
  14778. },{"./util/merge":137}],126:[function(require,module,exports){
  14779. "use strict";
  14780. Object.defineProperty(exports, "__esModule", {
  14781. value: true
  14782. });
  14783. exports.default = rtrim;
  14784. var _assertString = _interopRequireDefault(require("./util/assertString"));
  14785. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  14786. function rtrim(str, chars) {
  14787. (0, _assertString.default)(str);
  14788. if (chars) {
  14789. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Escaping
  14790. var pattern = new RegExp("[".concat(chars.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), "]+$"), 'g');
  14791. return str.replace(pattern, '');
  14792. } // Use a faster and more safe than regex trim method https://blog.stevenlevithan.com/archives/faster-trim-javascript
  14793. var strIndex = str.length - 1;
  14794. while (/\s/.test(str.charAt(strIndex))) {
  14795. strIndex -= 1;
  14796. }
  14797. return str.slice(0, strIndex + 1);
  14798. }
  14799. module.exports = exports.default;
  14800. module.exports.default = exports.default;
  14801. },{"./util/assertString":135}],127:[function(require,module,exports){
  14802. "use strict";
  14803. Object.defineProperty(exports, "__esModule", {
  14804. value: true
  14805. });
  14806. exports.default = stripLow;
  14807. var _assertString = _interopRequireDefault(require("./util/assertString"));
  14808. var _blacklist = _interopRequireDefault(require("./blacklist"));
  14809. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  14810. function stripLow(str, keep_new_lines) {
  14811. (0, _assertString.default)(str);
  14812. var chars = keep_new_lines ? '\\x00-\\x09\\x0B\\x0C\\x0E-\\x1F\\x7F' : '\\x00-\\x1F\\x7F';
  14813. return (0, _blacklist.default)(str, chars);
  14814. }
  14815. module.exports = exports.default;
  14816. module.exports.default = exports.default;
  14817. },{"./blacklist":42,"./util/assertString":135}],128:[function(require,module,exports){
  14818. "use strict";
  14819. Object.defineProperty(exports, "__esModule", {
  14820. value: true
  14821. });
  14822. exports.default = toBoolean;
  14823. var _assertString = _interopRequireDefault(require("./util/assertString"));
  14824. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  14825. function toBoolean(str, strict) {
  14826. (0, _assertString.default)(str);
  14827. if (strict) {
  14828. return str === '1' || /^true$/i.test(str);
  14829. }
  14830. return str !== '0' && !/^false$/i.test(str) && str !== '';
  14831. }
  14832. module.exports = exports.default;
  14833. module.exports.default = exports.default;
  14834. },{"./util/assertString":135}],129:[function(require,module,exports){
  14835. "use strict";
  14836. Object.defineProperty(exports, "__esModule", {
  14837. value: true
  14838. });
  14839. exports.default = toDate;
  14840. var _assertString = _interopRequireDefault(require("./util/assertString"));
  14841. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  14842. function toDate(date) {
  14843. (0, _assertString.default)(date);
  14844. date = Date.parse(date);
  14845. return !isNaN(date) ? new Date(date) : null;
  14846. }
  14847. module.exports = exports.default;
  14848. module.exports.default = exports.default;
  14849. },{"./util/assertString":135}],130:[function(require,module,exports){
  14850. "use strict";
  14851. Object.defineProperty(exports, "__esModule", {
  14852. value: true
  14853. });
  14854. exports.default = toFloat;
  14855. var _isFloat = _interopRequireDefault(require("./isFloat"));
  14856. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  14857. function toFloat(str) {
  14858. if (!(0, _isFloat.default)(str)) return NaN;
  14859. return parseFloat(str);
  14860. }
  14861. module.exports = exports.default;
  14862. module.exports.default = exports.default;
  14863. },{"./isFloat":69}],131:[function(require,module,exports){
  14864. "use strict";
  14865. Object.defineProperty(exports, "__esModule", {
  14866. value: true
  14867. });
  14868. exports.default = toInt;
  14869. var _assertString = _interopRequireDefault(require("./util/assertString"));
  14870. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  14871. function toInt(str, radix) {
  14872. (0, _assertString.default)(str);
  14873. return parseInt(str, radix || 10);
  14874. }
  14875. module.exports = exports.default;
  14876. module.exports.default = exports.default;
  14877. },{"./util/assertString":135}],132:[function(require,module,exports){
  14878. "use strict";
  14879. Object.defineProperty(exports, "__esModule", {
  14880. value: true
  14881. });
  14882. exports.default = trim;
  14883. var _rtrim = _interopRequireDefault(require("./rtrim"));
  14884. var _ltrim = _interopRequireDefault(require("./ltrim"));
  14885. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  14886. function trim(str, chars) {
  14887. return (0, _rtrim.default)((0, _ltrim.default)(str, chars), chars);
  14888. }
  14889. module.exports = exports.default;
  14890. module.exports.default = exports.default;
  14891. },{"./ltrim":123,"./rtrim":126}],133:[function(require,module,exports){
  14892. "use strict";
  14893. Object.defineProperty(exports, "__esModule", {
  14894. value: true
  14895. });
  14896. exports.default = unescape;
  14897. var _assertString = _interopRequireDefault(require("./util/assertString"));
  14898. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  14899. function unescape(str) {
  14900. (0, _assertString.default)(str);
  14901. 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, '&'); // &amp; replacement has to be the last one to prevent
  14902. // bugs with intermediate strings containing escape sequences
  14903. // See: https://github.com/validatorjs/validator.js/issues/1827
  14904. }
  14905. module.exports = exports.default;
  14906. module.exports.default = exports.default;
  14907. },{"./util/assertString":135}],134:[function(require,module,exports){
  14908. "use strict";
  14909. Object.defineProperty(exports, "__esModule", {
  14910. value: true
  14911. });
  14912. exports.iso7064Check = iso7064Check;
  14913. exports.luhnCheck = luhnCheck;
  14914. exports.reverseMultiplyAndSum = reverseMultiplyAndSum;
  14915. exports.verhoeffCheck = verhoeffCheck;
  14916. /**
  14917. * Algorithmic validation functions
  14918. * May be used as is or implemented in the workflow of other validators.
  14919. */
  14920. /*
  14921. * ISO 7064 validation function
  14922. * Called with a string of numbers (incl. check digit)
  14923. * to validate according to ISO 7064 (MOD 11, 10).
  14924. */
  14925. function iso7064Check(str) {
  14926. var checkvalue = 10;
  14927. for (var i = 0; i < str.length - 1; i++) {
  14928. checkvalue = (parseInt(str[i], 10) + checkvalue) % 10 === 0 ? 10 * 2 % 11 : (parseInt(str[i], 10) + checkvalue) % 10 * 2 % 11;
  14929. }
  14930. checkvalue = checkvalue === 1 ? 0 : 11 - checkvalue;
  14931. return checkvalue === parseInt(str[10], 10);
  14932. }
  14933. /*
  14934. * Luhn (mod 10) validation function
  14935. * Called with a string of numbers (incl. check digit)
  14936. * to validate according to the Luhn algorithm.
  14937. */
  14938. function luhnCheck(str) {
  14939. var checksum = 0;
  14940. var second = false;
  14941. for (var i = str.length - 1; i >= 0; i--) {
  14942. if (second) {
  14943. var product = parseInt(str[i], 10) * 2;
  14944. if (product > 9) {
  14945. // sum digits of product and add to checksum
  14946. checksum += product.toString().split('').map(function (a) {
  14947. return parseInt(a, 10);
  14948. }).reduce(function (a, b) {
  14949. return a + b;
  14950. }, 0);
  14951. } else {
  14952. checksum += product;
  14953. }
  14954. } else {
  14955. checksum += parseInt(str[i], 10);
  14956. }
  14957. second = !second;
  14958. }
  14959. return checksum % 10 === 0;
  14960. }
  14961. /*
  14962. * Reverse TIN multiplication and summation helper function
  14963. * Called with an array of single-digit integers and a base multiplier
  14964. * to calculate the sum of the digits multiplied in reverse.
  14965. * Normally used in variations of MOD 11 algorithmic checks.
  14966. */
  14967. function reverseMultiplyAndSum(digits, base) {
  14968. var total = 0;
  14969. for (var i = 0; i < digits.length; i++) {
  14970. total += digits[i] * (base - i);
  14971. }
  14972. return total;
  14973. }
  14974. /*
  14975. * Verhoeff validation helper function
  14976. * Called with a string of numbers
  14977. * to validate according to the Verhoeff algorithm.
  14978. */
  14979. function verhoeffCheck(str) {
  14980. 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]];
  14981. 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]]; // Copy (to prevent replacement) and reverse
  14982. var str_copy = str.split('').reverse().join('');
  14983. var checksum = 0;
  14984. for (var i = 0; i < str_copy.length; i++) {
  14985. checksum = d_table[checksum][p_table[i % 8][parseInt(str_copy[i], 10)]];
  14986. }
  14987. return checksum === 0;
  14988. }
  14989. },{}],135:[function(require,module,exports){
  14990. "use strict";
  14991. Object.defineProperty(exports, "__esModule", {
  14992. value: true
  14993. });
  14994. exports.default = assertString;
  14995. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  14996. function assertString(input) {
  14997. var isString = typeof input === 'string' || input instanceof String;
  14998. if (!isString) {
  14999. var invalidType = _typeof(input);
  15000. if (input === null) invalidType = 'null';else if (invalidType === 'object') invalidType = input.constructor.name;
  15001. throw new TypeError("Expected a string but received a ".concat(invalidType));
  15002. }
  15003. }
  15004. module.exports = exports.default;
  15005. module.exports.default = exports.default;
  15006. },{}],136:[function(require,module,exports){
  15007. "use strict";
  15008. Object.defineProperty(exports, "__esModule", {
  15009. value: true
  15010. });
  15011. exports.default = void 0;
  15012. var includes = function includes(arr, val) {
  15013. return arr.some(function (arrVal) {
  15014. return val === arrVal;
  15015. });
  15016. };
  15017. var _default = includes;
  15018. exports.default = _default;
  15019. module.exports = exports.default;
  15020. module.exports.default = exports.default;
  15021. },{}],137:[function(require,module,exports){
  15022. "use strict";
  15023. Object.defineProperty(exports, "__esModule", {
  15024. value: true
  15025. });
  15026. exports.default = merge;
  15027. function merge() {
  15028. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  15029. var defaults = arguments.length > 1 ? arguments[1] : undefined;
  15030. for (var key in defaults) {
  15031. if (typeof obj[key] === 'undefined') {
  15032. obj[key] = defaults[key];
  15033. }
  15034. }
  15035. return obj;
  15036. }
  15037. module.exports = exports.default;
  15038. module.exports.default = exports.default;
  15039. },{}],138:[function(require,module,exports){
  15040. "use strict";
  15041. Object.defineProperty(exports, "__esModule", {
  15042. value: true
  15043. });
  15044. exports.default = multilineRegexp;
  15045. /**
  15046. * Build RegExp object from an array
  15047. * of multiple/multi-line regexp parts
  15048. *
  15049. * @param {string[]} parts
  15050. * @param {string} flags
  15051. * @return {object} - RegExp object
  15052. */
  15053. function multilineRegexp(parts, flags) {
  15054. var regexpAsStringLiteral = parts.join('');
  15055. return new RegExp(regexpAsStringLiteral, flags);
  15056. }
  15057. module.exports = exports.default;
  15058. module.exports.default = exports.default;
  15059. },{}],139:[function(require,module,exports){
  15060. "use strict";
  15061. Object.defineProperty(exports, "__esModule", {
  15062. value: true
  15063. });
  15064. exports.default = toString;
  15065. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  15066. function toString(input) {
  15067. if (_typeof(input) === 'object' && input !== null) {
  15068. if (typeof input.toString === 'function') {
  15069. input = input.toString();
  15070. } else {
  15071. input = '[object Object]';
  15072. }
  15073. } else if (input === null || typeof input === 'undefined' || isNaN(input) && !input.length) {
  15074. input = '';
  15075. }
  15076. return String(input);
  15077. }
  15078. module.exports = exports.default;
  15079. module.exports.default = exports.default;
  15080. },{}],140:[function(require,module,exports){
  15081. "use strict";
  15082. Object.defineProperty(exports, "__esModule", {
  15083. value: true
  15084. });
  15085. exports.default = whitelist;
  15086. var _assertString = _interopRequireDefault(require("./util/assertString"));
  15087. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  15088. function whitelist(str, chars) {
  15089. (0, _assertString.default)(str);
  15090. return str.replace(new RegExp("[^".concat(chars, "]+"), 'g'), '');
  15091. }
  15092. module.exports = exports.default;
  15093. module.exports.default = exports.default;
  15094. },{"./util/assertString":135}],141:[function(require,module,exports){
  15095. module.exports = extend
  15096. var hasOwnProperty = Object.prototype.hasOwnProperty;
  15097. function extend() {
  15098. var target = {}
  15099. for (var i = 0; i < arguments.length; i++) {
  15100. var source = arguments[i]
  15101. for (var key in source) {
  15102. if (hasOwnProperty.call(source, key)) {
  15103. target[key] = source[key]
  15104. }
  15105. }
  15106. }
  15107. return target
  15108. }
  15109. },{}],142:[function(require,module,exports){
  15110. "use strict";
  15111. module.exports = {
  15112. INVALID_TYPE: "Expected type {0} but found type {1}",
  15113. INVALID_FORMAT: "Object didn't pass validation for format {0}: {1}",
  15114. ENUM_MISMATCH: "No enum match for: {0}",
  15115. ENUM_CASE_MISMATCH: "Enum does not match case for: {0}",
  15116. ANY_OF_MISSING: "Data does not match any schemas from 'anyOf'",
  15117. ONE_OF_MISSING: "Data does not match any schemas from 'oneOf'",
  15118. ONE_OF_MULTIPLE: "Data is valid against more than one schema from 'oneOf'",
  15119. NOT_PASSED: "Data matches schema from 'not'",
  15120. // Array errors
  15121. ARRAY_LENGTH_SHORT: "Array is too short ({0}), minimum {1}",
  15122. ARRAY_LENGTH_LONG: "Array is too long ({0}), maximum {1}",
  15123. ARRAY_UNIQUE: "Array items are not unique (indexes {0} and {1})",
  15124. ARRAY_ADDITIONAL_ITEMS: "Additional items not allowed",
  15125. // Numeric errors
  15126. MULTIPLE_OF: "Value {0} is not a multiple of {1}",
  15127. MINIMUM: "Value {0} is less than minimum {1}",
  15128. MINIMUM_EXCLUSIVE: "Value {0} is equal or less than exclusive minimum {1}",
  15129. MAXIMUM: "Value {0} is greater than maximum {1}",
  15130. MAXIMUM_EXCLUSIVE: "Value {0} is equal or greater than exclusive maximum {1}",
  15131. // Object errors
  15132. OBJECT_PROPERTIES_MINIMUM: "Too few properties defined ({0}), minimum {1}",
  15133. OBJECT_PROPERTIES_MAXIMUM: "Too many properties defined ({0}), maximum {1}",
  15134. OBJECT_MISSING_REQUIRED_PROPERTY: "Missing required property: {0}",
  15135. OBJECT_ADDITIONAL_PROPERTIES: "Additional properties not allowed: {0}",
  15136. OBJECT_DEPENDENCY_KEY: "Dependency failed - key must exist: {0} (due to key: {1})",
  15137. // String errors
  15138. MIN_LENGTH: "String is too short ({0} chars), minimum {1}",
  15139. MAX_LENGTH: "String is too long ({0} chars), maximum {1}",
  15140. PATTERN: "String does not match pattern {0}: {1}",
  15141. // Schema validation errors
  15142. KEYWORD_TYPE_EXPECTED: "Keyword '{0}' is expected to be of type '{1}'",
  15143. KEYWORD_UNDEFINED_STRICT: "Keyword '{0}' must be defined in strict mode",
  15144. KEYWORD_UNEXPECTED: "Keyword '{0}' is not expected to appear in the schema",
  15145. KEYWORD_MUST_BE: "Keyword '{0}' must be {1}",
  15146. KEYWORD_DEPENDENCY: "Keyword '{0}' requires keyword '{1}'",
  15147. KEYWORD_PATTERN: "Keyword '{0}' is not a valid RegExp pattern: {1}",
  15148. KEYWORD_VALUE_TYPE: "Each element of keyword '{0}' array must be a '{1}'",
  15149. UNKNOWN_FORMAT: "There is no validation function for format '{0}'",
  15150. CUSTOM_MODE_FORCE_PROPERTIES: "{0} must define at least one property if present",
  15151. // Remote errors
  15152. REF_UNRESOLVED: "Reference has not been resolved during compilation: {0}",
  15153. UNRESOLVABLE_REFERENCE: "Reference could not be resolved: {0}",
  15154. SCHEMA_NOT_REACHABLE: "Validator was not able to read schema with uri: {0}",
  15155. SCHEMA_TYPE_EXPECTED: "Schema is expected to be of type 'object'",
  15156. SCHEMA_NOT_AN_OBJECT: "Schema is not an object: {0}",
  15157. ASYNC_TIMEOUT: "{0} asynchronous task(s) have timed out after {1} ms",
  15158. PARENT_SCHEMA_VALIDATION_FAILED: "Schema failed to validate against its parent schema, see inner errors for details.",
  15159. REMOTE_NOT_VALID: "Remote reference didn't compile successfully: {0}"
  15160. };
  15161. },{}],143:[function(require,module,exports){
  15162. /*jshint maxlen: false*/
  15163. var validator = require("validator");
  15164. var FormatValidators = {
  15165. "date": function (date) {
  15166. if (typeof date !== "string") {
  15167. return true;
  15168. }
  15169. // full-date from http://tools.ietf.org/html/rfc3339#section-5.6
  15170. var matches = /^([0-9]{4})-([0-9]{2})-([0-9]{2})$/.exec(date);
  15171. if (matches === null) {
  15172. return false;
  15173. }
  15174. // var year = matches[1];
  15175. // var month = matches[2];
  15176. // var day = matches[3];
  15177. if (matches[2] < "01" || matches[2] > "12" || matches[3] < "01" || matches[3] > "31") {
  15178. return false;
  15179. }
  15180. return true;
  15181. },
  15182. "date-time": function (dateTime) {
  15183. if (typeof dateTime !== "string") {
  15184. return true;
  15185. }
  15186. // date-time from http://tools.ietf.org/html/rfc3339#section-5.6
  15187. var s = dateTime.toLowerCase().split("t");
  15188. if (!FormatValidators.date(s[0])) {
  15189. return false;
  15190. }
  15191. var matches = /^([0-9]{2}):([0-9]{2}):([0-9]{2})(.[0-9]+)?(z|([+-][0-9]{2}:[0-9]{2}))$/.exec(s[1]);
  15192. if (matches === null) {
  15193. return false;
  15194. }
  15195. // var hour = matches[1];
  15196. // var minute = matches[2];
  15197. // var second = matches[3];
  15198. // var fraction = matches[4];
  15199. // var timezone = matches[5];
  15200. if (matches[1] > "23" || matches[2] > "59" || matches[3] > "59") {
  15201. return false;
  15202. }
  15203. return true;
  15204. },
  15205. "email": function (email) {
  15206. if (typeof email !== "string") {
  15207. return true;
  15208. }
  15209. return validator.isEmail(email, { "require_tld": true });
  15210. },
  15211. "hostname": function (hostname) {
  15212. if (typeof hostname !== "string") {
  15213. return true;
  15214. }
  15215. /*
  15216. http://json-schema.org/latest/json-schema-validation.html#anchor114
  15217. A string instance is valid against this attribute if it is a valid
  15218. representation for an Internet host name, as defined by RFC 1034, section 3.1 [RFC1034].
  15219. http://tools.ietf.org/html/rfc1034#section-3.5
  15220. <digit> ::= any one of the ten digits 0 through 9
  15221. var digit = /[0-9]/;
  15222. <letter> ::= any one of the 52 alphabetic characters A through Z in upper case and a through z in lower case
  15223. var letter = /[a-zA-Z]/;
  15224. <let-dig> ::= <letter> | <digit>
  15225. var letDig = /[0-9a-zA-Z]/;
  15226. <let-dig-hyp> ::= <let-dig> | "-"
  15227. var letDigHyp = /[-0-9a-zA-Z]/;
  15228. <ldh-str> ::= <let-dig-hyp> | <let-dig-hyp> <ldh-str>
  15229. var ldhStr = /[-0-9a-zA-Z]+/;
  15230. <label> ::= <letter> [ [ <ldh-str> ] <let-dig> ]
  15231. var label = /[a-zA-Z](([-0-9a-zA-Z]+)?[0-9a-zA-Z])?/;
  15232. <subdomain> ::= <label> | <subdomain> "." <label>
  15233. var subdomain = /^[a-zA-Z](([-0-9a-zA-Z]+)?[0-9a-zA-Z])?(\.[a-zA-Z](([-0-9a-zA-Z]+)?[0-9a-zA-Z])?)*$/;
  15234. <domain> ::= <subdomain> | " "
  15235. var domain = null;
  15236. */
  15237. var valid = /^[a-zA-Z](([-0-9a-zA-Z]+)?[0-9a-zA-Z])?(\.[a-zA-Z](([-0-9a-zA-Z]+)?[0-9a-zA-Z])?)*$/.test(hostname);
  15238. if (valid) {
  15239. // the sum of all label octets and label lengths is limited to 255.
  15240. if (hostname.length > 255) { return false; }
  15241. // Each node has a label, which is zero to 63 octets in length
  15242. var labels = hostname.split(".");
  15243. for (var i = 0; i < labels.length; i++) { if (labels[i].length > 63) { return false; } }
  15244. }
  15245. return valid;
  15246. },
  15247. "host-name": function (hostname) {
  15248. return FormatValidators.hostname.call(this, hostname);
  15249. },
  15250. "ipv4": function (ipv4) {
  15251. if (typeof ipv4 !== "string") { return true; }
  15252. return validator.isIP(ipv4, 4);
  15253. },
  15254. "ipv6": function (ipv6) {
  15255. if (typeof ipv6 !== "string") { return true; }
  15256. return validator.isIP(ipv6, 6);
  15257. },
  15258. "regex": function (str) {
  15259. try {
  15260. RegExp(str);
  15261. return true;
  15262. } catch (e) {
  15263. return false;
  15264. }
  15265. },
  15266. "uri": function (uri) {
  15267. if (this.options.strictUris) {
  15268. return FormatValidators["strict-uri"].apply(this, arguments);
  15269. }
  15270. // https://github.com/zaggino/z-schema/issues/18
  15271. // RegExp from http://tools.ietf.org/html/rfc3986#appendix-B
  15272. return typeof uri !== "string" || RegExp("^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?").test(uri);
  15273. },
  15274. "strict-uri": function (uri) {
  15275. return typeof uri !== "string" || validator.isURL(uri);
  15276. }
  15277. };
  15278. module.exports = FormatValidators;
  15279. },{"validator":40}],144:[function(require,module,exports){
  15280. "use strict";
  15281. var FormatValidators = require("./FormatValidators"),
  15282. Report = require("./Report"),
  15283. Utils = require("./Utils");
  15284. var shouldSkipValidate = function (options, errors) {
  15285. return options &&
  15286. Array.isArray(options.includeErrors) &&
  15287. options.includeErrors.length > 0 &&
  15288. !errors.some(function (err) { return options.includeErrors.includes(err);});
  15289. };
  15290. var JsonValidators = {
  15291. multipleOf: function (report, schema, json) {
  15292. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.1.1.2
  15293. if (shouldSkipValidate(this.validateOptions, ["MULTIPLE_OF"])) {
  15294. return;
  15295. }
  15296. if (typeof json !== "number") {
  15297. return;
  15298. }
  15299. var stringMultipleOf = String(schema.multipleOf);
  15300. var scale = Math.pow(10, stringMultipleOf.length - stringMultipleOf.indexOf(".") - 1);
  15301. if (Utils.whatIs((json * scale) / (schema.multipleOf * scale)) !== "integer") {
  15302. report.addError("MULTIPLE_OF", [json, schema.multipleOf], null, schema);
  15303. }
  15304. },
  15305. maximum: function (report, schema, json) {
  15306. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.1.2.2
  15307. if (shouldSkipValidate(this.validateOptions, ["MAXIMUM", "MAXIMUM_EXCLUSIVE"])) {
  15308. return;
  15309. }
  15310. if (typeof json !== "number") {
  15311. return;
  15312. }
  15313. if (schema.exclusiveMaximum !== true) {
  15314. if (json > schema.maximum) {
  15315. report.addError("MAXIMUM", [json, schema.maximum], null, schema);
  15316. }
  15317. } else {
  15318. if (json >= schema.maximum) {
  15319. report.addError("MAXIMUM_EXCLUSIVE", [json, schema.maximum], null, schema);
  15320. }
  15321. }
  15322. },
  15323. exclusiveMaximum: function () {
  15324. // covered in maximum
  15325. },
  15326. minimum: function (report, schema, json) {
  15327. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.1.3.2
  15328. if (shouldSkipValidate(this.validateOptions, ["MINIMUM", "MINIMUM_EXCLUSIVE"])) {
  15329. return;
  15330. }
  15331. if (typeof json !== "number") {
  15332. return;
  15333. }
  15334. if (schema.exclusiveMinimum !== true) {
  15335. if (json < schema.minimum) {
  15336. report.addError("MINIMUM", [json, schema.minimum], null, schema);
  15337. }
  15338. } else {
  15339. if (json <= schema.minimum) {
  15340. report.addError("MINIMUM_EXCLUSIVE", [json, schema.minimum], null, schema);
  15341. }
  15342. }
  15343. },
  15344. exclusiveMinimum: function () {
  15345. // covered in minimum
  15346. },
  15347. maxLength: function (report, schema, json) {
  15348. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.2.1.2
  15349. if (shouldSkipValidate(this.validateOptions, ["MAX_LENGTH"])) {
  15350. return;
  15351. }
  15352. if (typeof json !== "string") {
  15353. return;
  15354. }
  15355. if (Utils.ucs2decode(json).length > schema.maxLength) {
  15356. report.addError("MAX_LENGTH", [json.length, schema.maxLength], null, schema);
  15357. }
  15358. },
  15359. minLength: function (report, schema, json) {
  15360. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.2.2.2
  15361. if (shouldSkipValidate(this.validateOptions, ["MIN_LENGTH"])) {
  15362. return;
  15363. }
  15364. if (typeof json !== "string") {
  15365. return;
  15366. }
  15367. if (Utils.ucs2decode(json).length < schema.minLength) {
  15368. report.addError("MIN_LENGTH", [json.length, schema.minLength], null, schema);
  15369. }
  15370. },
  15371. pattern: function (report, schema, json) {
  15372. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.2.3.2
  15373. if (shouldSkipValidate(this.validateOptions, ["PATTERN"])) {
  15374. return;
  15375. }
  15376. if (typeof json !== "string") {
  15377. return;
  15378. }
  15379. if (RegExp(schema.pattern).test(json) === false) {
  15380. report.addError("PATTERN", [schema.pattern, json], null, schema);
  15381. }
  15382. },
  15383. additionalItems: function (report, schema, json) {
  15384. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.3.1.2
  15385. if (shouldSkipValidate(this.validateOptions, ["ARRAY_ADDITIONAL_ITEMS"])) {
  15386. return;
  15387. }
  15388. if (!Array.isArray(json)) {
  15389. return;
  15390. }
  15391. // if the value of "additionalItems" is boolean value false and the value of "items" is an array,
  15392. // the json is valid if its size is less than, or equal to, the size of "items".
  15393. if (schema.additionalItems === false && Array.isArray(schema.items)) {
  15394. if (json.length > schema.items.length) {
  15395. report.addError("ARRAY_ADDITIONAL_ITEMS", null, null, schema);
  15396. }
  15397. }
  15398. },
  15399. items: function () { /*report, schema, json*/
  15400. // covered in additionalItems
  15401. },
  15402. maxItems: function (report, schema, json) {
  15403. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.3.2.2
  15404. if (shouldSkipValidate(this.validateOptions, ["ARRAY_LENGTH_LONG"])) {
  15405. return;
  15406. }
  15407. if (!Array.isArray(json)) {
  15408. return;
  15409. }
  15410. if (json.length > schema.maxItems) {
  15411. report.addError("ARRAY_LENGTH_LONG", [json.length, schema.maxItems], null, schema);
  15412. }
  15413. },
  15414. minItems: function (report, schema, json) {
  15415. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.3.3.2
  15416. if (shouldSkipValidate(this.validateOptions, ["ARRAY_LENGTH_SHORT"])) {
  15417. return;
  15418. }
  15419. if (!Array.isArray(json)) {
  15420. return;
  15421. }
  15422. if (json.length < schema.minItems) {
  15423. report.addError("ARRAY_LENGTH_SHORT", [json.length, schema.minItems], null, schema);
  15424. }
  15425. },
  15426. uniqueItems: function (report, schema, json) {
  15427. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.3.4.2
  15428. if (shouldSkipValidate(this.validateOptions, ["ARRAY_UNIQUE"])) {
  15429. return;
  15430. }
  15431. if (!Array.isArray(json)) {
  15432. return;
  15433. }
  15434. if (schema.uniqueItems === true) {
  15435. var matches = [];
  15436. if (Utils.isUniqueArray(json, matches) === false) {
  15437. report.addError("ARRAY_UNIQUE", matches, null, schema);
  15438. }
  15439. }
  15440. },
  15441. maxProperties: function (report, schema, json) {
  15442. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.4.1.2
  15443. if (shouldSkipValidate(this.validateOptions, ["OBJECT_PROPERTIES_MAXIMUM"])) {
  15444. return;
  15445. }
  15446. if (Utils.whatIs(json) !== "object") {
  15447. return;
  15448. }
  15449. var keysCount = Object.keys(json).length;
  15450. if (keysCount > schema.maxProperties) {
  15451. report.addError("OBJECT_PROPERTIES_MAXIMUM", [keysCount, schema.maxProperties], null, schema);
  15452. }
  15453. },
  15454. minProperties: function (report, schema, json) {
  15455. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.4.2.2
  15456. if (shouldSkipValidate(this.validateOptions, ["OBJECT_PROPERTIES_MINIMUM"])) {
  15457. return;
  15458. }
  15459. if (Utils.whatIs(json) !== "object") {
  15460. return;
  15461. }
  15462. var keysCount = Object.keys(json).length;
  15463. if (keysCount < schema.minProperties) {
  15464. report.addError("OBJECT_PROPERTIES_MINIMUM", [keysCount, schema.minProperties], null, schema);
  15465. }
  15466. },
  15467. required: function (report, schema, json) {
  15468. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.4.3.2
  15469. if (shouldSkipValidate(this.validateOptions, ["OBJECT_MISSING_REQUIRED_PROPERTY"])) {
  15470. return;
  15471. }
  15472. if (Utils.whatIs(json) !== "object") {
  15473. return;
  15474. }
  15475. var idx = schema.required.length;
  15476. while (idx--) {
  15477. var requiredPropertyName = schema.required[idx];
  15478. if (json[requiredPropertyName] === undefined) {
  15479. report.addError("OBJECT_MISSING_REQUIRED_PROPERTY", [requiredPropertyName], null, schema);
  15480. }
  15481. }
  15482. },
  15483. additionalProperties: function (report, schema, json) {
  15484. // covered in properties and patternProperties
  15485. if (schema.properties === undefined && schema.patternProperties === undefined) {
  15486. return JsonValidators.properties.call(this, report, schema, json);
  15487. }
  15488. },
  15489. patternProperties: function (report, schema, json) {
  15490. // covered in properties
  15491. if (schema.properties === undefined) {
  15492. return JsonValidators.properties.call(this, report, schema, json);
  15493. }
  15494. },
  15495. properties: function (report, schema, json) {
  15496. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.4.4.2
  15497. if (shouldSkipValidate(this.validateOptions, ["OBJECT_ADDITIONAL_PROPERTIES"])) {
  15498. return;
  15499. }
  15500. if (Utils.whatIs(json) !== "object") {
  15501. return;
  15502. }
  15503. var properties = schema.properties !== undefined ? schema.properties : {};
  15504. var patternProperties = schema.patternProperties !== undefined ? schema.patternProperties : {};
  15505. if (schema.additionalProperties === false) {
  15506. // The property set of the json to validate.
  15507. var s = Object.keys(json);
  15508. // The property set from "properties".
  15509. var p = Object.keys(properties);
  15510. // The property set from "patternProperties".
  15511. var pp = Object.keys(patternProperties);
  15512. // remove from "s" all elements of "p", if any;
  15513. s = Utils.difference(s, p);
  15514. // for each regex in "pp", remove all elements of "s" which this regex matches.
  15515. var idx = pp.length;
  15516. while (idx--) {
  15517. var regExp = RegExp(pp[idx]),
  15518. idx2 = s.length;
  15519. while (idx2--) {
  15520. if (regExp.test(s[idx2]) === true) {
  15521. s.splice(idx2, 1);
  15522. }
  15523. }
  15524. }
  15525. // Validation of the json succeeds if, after these two steps, set "s" is empty.
  15526. if (s.length > 0) {
  15527. // assumeAdditional can be an array of allowed properties
  15528. var idx3 = this.options.assumeAdditional.length;
  15529. if (idx3) {
  15530. while (idx3--) {
  15531. var io = s.indexOf(this.options.assumeAdditional[idx3]);
  15532. if (io !== -1) {
  15533. s.splice(io, 1);
  15534. }
  15535. }
  15536. }
  15537. var idx4 = s.length;
  15538. if (idx4) {
  15539. while (idx4--) {
  15540. report.addError("OBJECT_ADDITIONAL_PROPERTIES", [s[idx4]], null, schema);
  15541. }
  15542. }
  15543. }
  15544. }
  15545. },
  15546. dependencies: function (report, schema, json) {
  15547. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.4.5.2
  15548. if (shouldSkipValidate(this.validateOptions, ["OBJECT_DEPENDENCY_KEY"])) {
  15549. return;
  15550. }
  15551. if (Utils.whatIs(json) !== "object") {
  15552. return;
  15553. }
  15554. var keys = Object.keys(schema.dependencies),
  15555. idx = keys.length;
  15556. while (idx--) {
  15557. // iterate all dependencies
  15558. var dependencyName = keys[idx];
  15559. if (json[dependencyName]) {
  15560. var dependencyDefinition = schema.dependencies[dependencyName];
  15561. if (Utils.whatIs(dependencyDefinition) === "object") {
  15562. // if dependency is a schema, validate against this schema
  15563. exports.validate.call(this, report, dependencyDefinition, json);
  15564. } else { // Array
  15565. // if dependency is an array, object needs to have all properties in this array
  15566. var idx2 = dependencyDefinition.length;
  15567. while (idx2--) {
  15568. var requiredPropertyName = dependencyDefinition[idx2];
  15569. if (json[requiredPropertyName] === undefined) {
  15570. report.addError("OBJECT_DEPENDENCY_KEY", [requiredPropertyName, dependencyName], null, schema);
  15571. }
  15572. }
  15573. }
  15574. }
  15575. }
  15576. },
  15577. enum: function (report, schema, json) {
  15578. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.5.1.2
  15579. if (shouldSkipValidate(this.validateOptions, ["ENUM_CASE_MISMATCH", "ENUM_MISMATCH"])) {
  15580. return;
  15581. }
  15582. var match = false,
  15583. caseInsensitiveMatch = false,
  15584. idx = schema.enum.length;
  15585. while (idx--) {
  15586. if (Utils.areEqual(json, schema.enum[idx])) {
  15587. match = true;
  15588. break;
  15589. } else if (Utils.areEqual(json, schema.enum[idx]), { caseInsensitiveComparison: true }) {
  15590. caseInsensitiveMatch = true;
  15591. }
  15592. }
  15593. if (match === false) {
  15594. var error = caseInsensitiveMatch && this.options.enumCaseInsensitiveComparison ? "ENUM_CASE_MISMATCH" : "ENUM_MISMATCH";
  15595. report.addError(error, [json], null, schema);
  15596. }
  15597. },
  15598. type: function (report, schema, json) {
  15599. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.5.2.2
  15600. if (shouldSkipValidate(this.validateOptions, ["INVALID_TYPE"])) {
  15601. return;
  15602. }
  15603. var jsonType = Utils.whatIs(json);
  15604. if (typeof schema.type === "string") {
  15605. if (jsonType !== schema.type && (jsonType !== "integer" || schema.type !== "number")) {
  15606. report.addError("INVALID_TYPE", [schema.type, jsonType], null, schema);
  15607. }
  15608. } else {
  15609. if (schema.type.indexOf(jsonType) === -1 && (jsonType !== "integer" || schema.type.indexOf("number") === -1)) {
  15610. report.addError("INVALID_TYPE", [schema.type, jsonType], null, schema);
  15611. }
  15612. }
  15613. },
  15614. allOf: function (report, schema, json) {
  15615. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.5.3.2
  15616. var idx = schema.allOf.length;
  15617. while (idx--) {
  15618. var validateResult = exports.validate.call(this, report, schema.allOf[idx], json);
  15619. if (this.options.breakOnFirstError && validateResult === false) {
  15620. break;
  15621. }
  15622. }
  15623. },
  15624. anyOf: function (report, schema, json) {
  15625. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.5.4.2
  15626. var subReports = [],
  15627. passed = false,
  15628. idx = schema.anyOf.length;
  15629. while (idx-- && passed === false) {
  15630. var subReport = new Report(report);
  15631. subReports.push(subReport);
  15632. passed = exports.validate.call(this, subReport, schema.anyOf[idx], json);
  15633. }
  15634. if (passed === false) {
  15635. report.addError("ANY_OF_MISSING", undefined, subReports, schema);
  15636. }
  15637. },
  15638. oneOf: function (report, schema, json) {
  15639. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.5.5.2
  15640. var passes = 0,
  15641. subReports = [],
  15642. idx = schema.oneOf.length;
  15643. while (idx--) {
  15644. var subReport = new Report(report, { maxErrors: 1 });
  15645. subReports.push(subReport);
  15646. if (exports.validate.call(this, subReport, schema.oneOf[idx], json) === true) {
  15647. passes++;
  15648. }
  15649. }
  15650. if (passes === 0) {
  15651. report.addError("ONE_OF_MISSING", undefined, subReports, schema);
  15652. } else if (passes > 1) {
  15653. report.addError("ONE_OF_MULTIPLE", null, null, schema);
  15654. }
  15655. },
  15656. not: function (report, schema, json) {
  15657. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.5.6.2
  15658. var subReport = new Report(report);
  15659. if (exports.validate.call(this, subReport, schema.not, json) === true) {
  15660. report.addError("NOT_PASSED", null, null, schema);
  15661. }
  15662. },
  15663. definitions: function () { /*report, schema, json*/
  15664. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.5.7.2
  15665. // nothing to do here
  15666. },
  15667. format: function (report, schema, json) {
  15668. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.7.2
  15669. var formatValidatorFn = FormatValidators[schema.format];
  15670. if (typeof formatValidatorFn === "function") {
  15671. if (shouldSkipValidate(this.validateOptions, ["INVALID_FORMAT"])) {
  15672. return;
  15673. }
  15674. if (formatValidatorFn.length === 2) {
  15675. // async - need to clone the path here, because it will change by the time async function reports back
  15676. var pathBeforeAsync = Utils.clone(report.path);
  15677. report.addAsyncTask(formatValidatorFn, [json], function (result) {
  15678. if (result !== true) {
  15679. var backup = report.path;
  15680. report.path = pathBeforeAsync;
  15681. report.addError("INVALID_FORMAT", [schema.format, json], null, schema);
  15682. report.path = backup;
  15683. }
  15684. });
  15685. } else {
  15686. // sync
  15687. if (formatValidatorFn.call(this, json) !== true) {
  15688. report.addError("INVALID_FORMAT", [schema.format, json], null, schema);
  15689. }
  15690. }
  15691. } else if (this.options.ignoreUnknownFormats !== true) {
  15692. report.addError("UNKNOWN_FORMAT", [schema.format], null, schema);
  15693. }
  15694. }
  15695. };
  15696. var recurseArray = function (report, schema, json) {
  15697. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.8.2
  15698. var idx = json.length;
  15699. // If "items" is an array, this situation, the schema depends on the index:
  15700. // if the index is less than, or equal to, the size of "items",
  15701. // the child instance must be valid against the corresponding schema in the "items" array;
  15702. // otherwise, it must be valid against the schema defined by "additionalItems".
  15703. if (Array.isArray(schema.items)) {
  15704. while (idx--) {
  15705. // equal to doesn't make sense here
  15706. if (idx < schema.items.length) {
  15707. report.path.push(idx);
  15708. exports.validate.call(this, report, schema.items[idx], json[idx]);
  15709. report.path.pop();
  15710. } else {
  15711. // might be boolean, so check that it's an object
  15712. if (typeof schema.additionalItems === "object") {
  15713. report.path.push(idx);
  15714. exports.validate.call(this, report, schema.additionalItems, json[idx]);
  15715. report.path.pop();
  15716. }
  15717. }
  15718. }
  15719. } else if (typeof schema.items === "object") {
  15720. // If items is a schema, then the child instance must be valid against this schema,
  15721. // regardless of its index, and regardless of the value of "additionalItems".
  15722. while (idx--) {
  15723. report.path.push(idx);
  15724. exports.validate.call(this, report, schema.items, json[idx]);
  15725. report.path.pop();
  15726. }
  15727. }
  15728. };
  15729. var recurseObject = function (report, schema, json) {
  15730. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.8.3
  15731. // If "additionalProperties" is absent, it is considered present with an empty schema as a value.
  15732. // In addition, boolean value true is considered equivalent to an empty schema.
  15733. var additionalProperties = schema.additionalProperties;
  15734. if (additionalProperties === true || additionalProperties === undefined) {
  15735. additionalProperties = {};
  15736. }
  15737. // p - The property set from "properties".
  15738. var p = schema.properties ? Object.keys(schema.properties) : [];
  15739. // pp - The property set from "patternProperties". Elements of this set will be called regexes for convenience.
  15740. var pp = schema.patternProperties ? Object.keys(schema.patternProperties) : [];
  15741. // m - The property name of the child.
  15742. var keys = Object.keys(json),
  15743. idx = keys.length;
  15744. while (idx--) {
  15745. var m = keys[idx],
  15746. propertyValue = json[m];
  15747. // s - The set of schemas for the child instance.
  15748. var s = [];
  15749. // 1. If set "p" contains value "m", then the corresponding schema in "properties" is added to "s".
  15750. if (p.indexOf(m) !== -1) {
  15751. s.push(schema.properties[m]);
  15752. }
  15753. // 2. For each regex in "pp", if it matches "m" successfully, the corresponding schema in "patternProperties" is added to "s".
  15754. var idx2 = pp.length;
  15755. while (idx2--) {
  15756. var regexString = pp[idx2];
  15757. if (RegExp(regexString).test(m) === true) {
  15758. s.push(schema.patternProperties[regexString]);
  15759. }
  15760. }
  15761. // 3. The schema defined by "additionalProperties" is added to "s" if and only if, at this stage, "s" is empty.
  15762. if (s.length === 0 && additionalProperties !== false) {
  15763. s.push(additionalProperties);
  15764. }
  15765. // we are passing tests even without this assert because this is covered by properties check
  15766. // if s is empty in this stage, no additionalProperties are allowed
  15767. // report.expect(s.length !== 0, 'E001', m);
  15768. // Instance property value must pass all schemas from s
  15769. idx2 = s.length;
  15770. while (idx2--) {
  15771. report.path.push(m);
  15772. exports.validate.call(this, report, s[idx2], propertyValue);
  15773. report.path.pop();
  15774. }
  15775. }
  15776. };
  15777. exports.JsonValidators = JsonValidators;
  15778. /**
  15779. *
  15780. * @param {Report} report
  15781. * @param {*} schema
  15782. * @param {*} json
  15783. */
  15784. exports.validate = function (report, schema, json) {
  15785. report.commonErrorMessage = "JSON_OBJECT_VALIDATION_FAILED";
  15786. // check if schema is an object
  15787. var to = Utils.whatIs(schema);
  15788. if (to !== "object") {
  15789. report.addError("SCHEMA_NOT_AN_OBJECT", [to], null, schema);
  15790. return false;
  15791. }
  15792. // check if schema is empty, everything is valid against empty schema
  15793. var keys = Object.keys(schema);
  15794. if (keys.length === 0) {
  15795. return true;
  15796. }
  15797. // this method can be called recursively, so we need to remember our root
  15798. var isRoot = false;
  15799. if (!report.rootSchema) {
  15800. report.rootSchema = schema;
  15801. isRoot = true;
  15802. }
  15803. // follow schema.$ref keys
  15804. if (schema.$ref !== undefined) {
  15805. // avoid infinite loop with maxRefs
  15806. var maxRefs = 99;
  15807. while (schema.$ref && maxRefs > 0) {
  15808. if (!schema.__$refResolved) {
  15809. report.addError("REF_UNRESOLVED", [schema.$ref], null, schema);
  15810. break;
  15811. } else if (schema.__$refResolved === schema) {
  15812. break;
  15813. } else {
  15814. schema = schema.__$refResolved;
  15815. keys = Object.keys(schema);
  15816. }
  15817. maxRefs--;
  15818. }
  15819. if (maxRefs === 0) {
  15820. throw new Error("Circular dependency by $ref references!");
  15821. }
  15822. }
  15823. // type checking first
  15824. var jsonType = Utils.whatIs(json);
  15825. if (schema.type) {
  15826. keys.splice(keys.indexOf("type"), 1);
  15827. JsonValidators.type.call(this, report, schema, json);
  15828. if (report.errors.length && this.options.breakOnFirstError) {
  15829. return false;
  15830. }
  15831. }
  15832. // now iterate all the keys in schema and execute validation methods
  15833. var idx = keys.length;
  15834. while (idx--) {
  15835. if (JsonValidators[keys[idx]]) {
  15836. JsonValidators[keys[idx]].call(this, report, schema, json);
  15837. if (report.errors.length && this.options.breakOnFirstError) { break; }
  15838. }
  15839. }
  15840. if (report.errors.length === 0 || this.options.breakOnFirstError === false) {
  15841. if (jsonType === "array") {
  15842. recurseArray.call(this, report, schema, json);
  15843. } else if (jsonType === "object") {
  15844. recurseObject.call(this, report, schema, json);
  15845. }
  15846. }
  15847. if (typeof this.options.customValidator === "function") {
  15848. this.options.customValidator.call(this, report, schema, json);
  15849. }
  15850. // we don't need the root pointer anymore
  15851. if (isRoot) {
  15852. report.rootSchema = undefined;
  15853. }
  15854. // return valid just to be able to break at some code points
  15855. return report.errors.length === 0;
  15856. };
  15857. },{"./FormatValidators":143,"./Report":146,"./Utils":150}],145:[function(require,module,exports){
  15858. // Number.isFinite polyfill
  15859. // http://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.isfinite
  15860. if (typeof Number.isFinite !== "function") {
  15861. Number.isFinite = function isFinite(value) {
  15862. // 1. If Type(number) is not Number, return false.
  15863. if (typeof value !== "number") {
  15864. return false;
  15865. }
  15866. // 2. If number is NaN, +∞, or −∞, return false.
  15867. if (value !== value || value === Infinity || value === -Infinity) {
  15868. return false;
  15869. }
  15870. // 3. Otherwise, return true.
  15871. return true;
  15872. };
  15873. }
  15874. },{}],146:[function(require,module,exports){
  15875. (function (process){(function (){
  15876. "use strict";
  15877. var get = require("lodash.get");
  15878. var Errors = require("./Errors");
  15879. var Utils = require("./Utils");
  15880. /**
  15881. * @class
  15882. *
  15883. * @param {Report|object} parentOrOptions
  15884. * @param {object} [reportOptions]
  15885. */
  15886. function Report(parentOrOptions, reportOptions) {
  15887. this.parentReport = parentOrOptions instanceof Report ?
  15888. parentOrOptions :
  15889. undefined;
  15890. this.options = parentOrOptions instanceof Report ?
  15891. parentOrOptions.options :
  15892. parentOrOptions || {};
  15893. this.reportOptions = reportOptions || {};
  15894. this.errors = [];
  15895. /**
  15896. * @type {string[]}
  15897. */
  15898. this.path = [];
  15899. this.asyncTasks = [];
  15900. this.rootSchema = undefined;
  15901. this.commonErrorMessage = undefined;
  15902. this.json = undefined;
  15903. }
  15904. /**
  15905. * @returns {boolean}
  15906. */
  15907. Report.prototype.isValid = function () {
  15908. if (this.asyncTasks.length > 0) {
  15909. throw new Error("Async tasks pending, can't answer isValid");
  15910. }
  15911. return this.errors.length === 0;
  15912. };
  15913. /**
  15914. *
  15915. * @param {*} fn
  15916. * @param {*} args
  15917. * @param {*} asyncTaskResultProcessFn
  15918. */
  15919. Report.prototype.addAsyncTask = function (fn, args, asyncTaskResultProcessFn) {
  15920. this.asyncTasks.push([fn, args, asyncTaskResultProcessFn]);
  15921. };
  15922. Report.prototype.getAncestor = function (id) {
  15923. if (!this.parentReport) {
  15924. return undefined;
  15925. }
  15926. if (this.parentReport.getSchemaId() === id) {
  15927. return this.parentReport;
  15928. }
  15929. return this.parentReport.getAncestor(id);
  15930. };
  15931. /**
  15932. *
  15933. * @param {*} timeout
  15934. * @param {function(*, *)} callback
  15935. *
  15936. * @returns {void}
  15937. */
  15938. Report.prototype.processAsyncTasks = function (timeout, callback) {
  15939. var validationTimeout = timeout || 2000,
  15940. tasksCount = this.asyncTasks.length,
  15941. idx = tasksCount,
  15942. timedOut = false,
  15943. self = this;
  15944. function finish() {
  15945. process.nextTick(function () {
  15946. var valid = self.errors.length === 0,
  15947. err = valid ? null : self.errors;
  15948. callback(err, valid);
  15949. });
  15950. }
  15951. function respond(asyncTaskResultProcessFn) {
  15952. return function (asyncTaskResult) {
  15953. if (timedOut) { return; }
  15954. asyncTaskResultProcessFn(asyncTaskResult);
  15955. if (--tasksCount === 0) {
  15956. finish();
  15957. }
  15958. };
  15959. }
  15960. // finish if tasks are completed or there are any errors and breaking on first error was requested
  15961. if (tasksCount === 0 || (this.errors.length > 0 && this.options.breakOnFirstError)) {
  15962. finish();
  15963. return;
  15964. }
  15965. while (idx--) {
  15966. var task = this.asyncTasks[idx];
  15967. task[0].apply(null, task[1].concat(respond(task[2])));
  15968. }
  15969. setTimeout(function () {
  15970. if (tasksCount > 0) {
  15971. timedOut = true;
  15972. self.addError("ASYNC_TIMEOUT", [tasksCount, validationTimeout]);
  15973. callback(self.errors, false);
  15974. }
  15975. }, validationTimeout);
  15976. };
  15977. /**
  15978. *
  15979. * @param {*} returnPathAsString
  15980. *
  15981. * @return {string[]|string}
  15982. */
  15983. Report.prototype.getPath = function (returnPathAsString) {
  15984. /**
  15985. * @type {string[]|string}
  15986. */
  15987. var path = [];
  15988. if (this.parentReport) {
  15989. path = path.concat(this.parentReport.path);
  15990. }
  15991. path = path.concat(this.path);
  15992. if (returnPathAsString !== true) {
  15993. // Sanitize the path segments (http://tools.ietf.org/html/rfc6901#section-4)
  15994. path = "#/" + path.map(function (segment) {
  15995. segment = segment.toString();
  15996. if (Utils.isAbsoluteUri(segment)) {
  15997. return "uri(" + segment + ")";
  15998. }
  15999. return segment.replace(/\~/g, "~0").replace(/\//g, "~1");
  16000. }).join("/");
  16001. }
  16002. return path;
  16003. };
  16004. Report.prototype.getSchemaId = function () {
  16005. if (!this.rootSchema) {
  16006. return null;
  16007. }
  16008. // get the error path as an array
  16009. var path = [];
  16010. if (this.parentReport) {
  16011. path = path.concat(this.parentReport.path);
  16012. }
  16013. path = path.concat(this.path);
  16014. // try to find id in the error path
  16015. while (path.length > 0) {
  16016. var obj = get(this.rootSchema, path);
  16017. if (obj && obj.id) { return obj.id; }
  16018. path.pop();
  16019. }
  16020. // return id of the root
  16021. return this.rootSchema.id;
  16022. };
  16023. /**
  16024. *
  16025. * @param {*} errorCode
  16026. * @param {*} params
  16027. *
  16028. * @return {boolean}
  16029. */
  16030. Report.prototype.hasError = function (errorCode, params) {
  16031. var idx = this.errors.length;
  16032. while (idx--) {
  16033. if (this.errors[idx].code === errorCode) {
  16034. // assume match
  16035. var match = true;
  16036. // check the params too
  16037. var idx2 = this.errors[idx].params.length;
  16038. while (idx2--) {
  16039. if (this.errors[idx].params[idx2] !== params[idx2]) {
  16040. match = false;
  16041. }
  16042. }
  16043. // if match, return true
  16044. if (match) { return match; }
  16045. }
  16046. }
  16047. return false;
  16048. };
  16049. /**
  16050. *
  16051. * @param {*} errorCode
  16052. * @param {*} params
  16053. * @param {Report[]|Report} [subReports]
  16054. * @param {*} [schema]
  16055. *
  16056. * @return {void}
  16057. */
  16058. Report.prototype.addError = function (errorCode, params, subReports, schema) {
  16059. if (!errorCode) { throw new Error("No errorCode passed into addError()"); }
  16060. this.addCustomError(errorCode, Errors[errorCode], params, subReports, schema);
  16061. };
  16062. Report.prototype.getJson = function () {
  16063. var self = this;
  16064. while (self.json === undefined) {
  16065. self = self.parentReport;
  16066. if (self === undefined) {
  16067. return undefined;
  16068. }
  16069. }
  16070. return self.json;
  16071. };
  16072. /**
  16073. *
  16074. * @param {*} errorCode
  16075. * @param {*} errorMessage
  16076. * @param {*[]} params
  16077. * @param {Report[]|Report} subReports
  16078. * @param {*} schema
  16079. *
  16080. * @returns {void}
  16081. */
  16082. Report.prototype.addCustomError = function (errorCode, errorMessage, params, subReports, schema) {
  16083. if (this.errors.length >= this.reportOptions.maxErrors) {
  16084. return;
  16085. }
  16086. if (!errorMessage) { throw new Error("No errorMessage known for code " + errorCode); }
  16087. params = params || [];
  16088. var idx = params.length;
  16089. while (idx--) {
  16090. var whatIs = Utils.whatIs(params[idx]);
  16091. var param = (whatIs === "object" || whatIs === "null") ? JSON.stringify(params[idx]) : params[idx];
  16092. errorMessage = errorMessage.replace("{" + idx + "}", param);
  16093. }
  16094. var err = {
  16095. code: errorCode,
  16096. params: params,
  16097. message: errorMessage,
  16098. path: this.getPath(this.options.reportPathAsArray),
  16099. schemaId: this.getSchemaId()
  16100. };
  16101. err[Utils.schemaSymbol] = schema;
  16102. err[Utils.jsonSymbol] = this.getJson();
  16103. if (schema && typeof schema === "string") {
  16104. err.description = schema;
  16105. } else if (schema && typeof schema === "object") {
  16106. if (schema.title) {
  16107. err.title = schema.title;
  16108. }
  16109. if (schema.description) {
  16110. err.description = schema.description;
  16111. }
  16112. }
  16113. if (subReports != null) {
  16114. if (!Array.isArray(subReports)) {
  16115. subReports = [subReports];
  16116. }
  16117. err.inner = [];
  16118. idx = subReports.length;
  16119. while (idx--) {
  16120. var subReport = subReports[idx],
  16121. idx2 = subReport.errors.length;
  16122. while (idx2--) {
  16123. err.inner.push(subReport.errors[idx2]);
  16124. }
  16125. }
  16126. if (err.inner.length === 0) {
  16127. err.inner = undefined;
  16128. }
  16129. }
  16130. this.errors.push(err);
  16131. };
  16132. module.exports = Report;
  16133. }).call(this)}).call(this,require('_process'))
  16134. },{"./Errors":142,"./Utils":150,"_process":11,"lodash.get":9}],147:[function(require,module,exports){
  16135. "use strict";
  16136. var isequal = require("lodash.isequal");
  16137. var Report = require("./Report");
  16138. var SchemaCompilation = require("./SchemaCompilation");
  16139. var SchemaValidation = require("./SchemaValidation");
  16140. var Utils = require("./Utils");
  16141. function decodeJSONPointer(str) {
  16142. // http://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-07#section-3
  16143. return decodeURIComponent(str).replace(/~[0-1]/g, function (x) {
  16144. return x === "~1" ? "/" : "~";
  16145. });
  16146. }
  16147. function getRemotePath(uri) {
  16148. var io = uri.indexOf("#");
  16149. return io === -1 ? uri : uri.slice(0, io);
  16150. }
  16151. function getQueryPath(uri) {
  16152. var io = uri.indexOf("#");
  16153. var res = io === -1 ? undefined : uri.slice(io + 1);
  16154. // WARN: do not slice slash, #/ means take root and go down from it
  16155. // if (res && res[0] === "/") { res = res.slice(1); }
  16156. return res;
  16157. }
  16158. function findId(schema, id) {
  16159. // process only arrays and objects
  16160. if (typeof schema !== "object" || schema === null) {
  16161. return;
  16162. }
  16163. // no id means root so return itself
  16164. if (!id) {
  16165. return schema;
  16166. }
  16167. if (schema.id) {
  16168. if (schema.id === id || schema.id[0] === "#" && schema.id.substring(1) === id) {
  16169. return schema;
  16170. }
  16171. }
  16172. var idx, result;
  16173. if (Array.isArray(schema)) {
  16174. idx = schema.length;
  16175. while (idx--) {
  16176. result = findId(schema[idx], id);
  16177. if (result) { return result; }
  16178. }
  16179. } else {
  16180. var keys = Object.keys(schema);
  16181. idx = keys.length;
  16182. while (idx--) {
  16183. var k = keys[idx];
  16184. if (k.indexOf("__$") === 0) {
  16185. continue;
  16186. }
  16187. result = findId(schema[k], id);
  16188. if (result) { return result; }
  16189. }
  16190. }
  16191. }
  16192. /**
  16193. *
  16194. * @param {*} uri
  16195. * @param {*} schema
  16196. *
  16197. * @returns {void}
  16198. */
  16199. exports.cacheSchemaByUri = function (uri, schema) {
  16200. var remotePath = getRemotePath(uri);
  16201. if (remotePath) {
  16202. this.cache[remotePath] = schema;
  16203. }
  16204. };
  16205. /**
  16206. *
  16207. * @param {*} uri
  16208. *
  16209. * @returns {void}
  16210. */
  16211. exports.removeFromCacheByUri = function (uri) {
  16212. var remotePath = getRemotePath(uri);
  16213. if (remotePath) {
  16214. delete this.cache[remotePath];
  16215. }
  16216. };
  16217. /**
  16218. *
  16219. * @param {*} uri
  16220. *
  16221. * @returns {boolean}
  16222. */
  16223. exports.checkCacheForUri = function (uri) {
  16224. var remotePath = getRemotePath(uri);
  16225. return remotePath ? this.cache[remotePath] != null : false;
  16226. };
  16227. exports.getSchema = function (report, schema) {
  16228. if (typeof schema === "object") {
  16229. schema = exports.getSchemaByReference.call(this, report, schema);
  16230. }
  16231. if (typeof schema === "string") {
  16232. schema = exports.getSchemaByUri.call(this, report, schema);
  16233. }
  16234. return schema;
  16235. };
  16236. exports.getSchemaByReference = function (report, key) {
  16237. var i = this.referenceCache.length;
  16238. while (i--) {
  16239. if (isequal(this.referenceCache[i][0], key)) {
  16240. return this.referenceCache[i][1];
  16241. }
  16242. }
  16243. // not found
  16244. var schema = Utils.cloneDeep(key);
  16245. this.referenceCache.push([key, schema]);
  16246. return schema;
  16247. };
  16248. exports.getSchemaByUri = function (report, uri, root) {
  16249. var remotePath = getRemotePath(uri),
  16250. queryPath = getQueryPath(uri),
  16251. result = remotePath ? this.cache[remotePath] : root;
  16252. if (result && remotePath) {
  16253. // we need to avoid compiling schemas in a recursive loop
  16254. var compileRemote = result !== root;
  16255. // now we need to compile and validate resolved schema (in case it's not already)
  16256. if (compileRemote) {
  16257. report.path.push(remotePath);
  16258. var remoteReport;
  16259. var anscestorReport = report.getAncestor(result.id);
  16260. if (anscestorReport) {
  16261. remoteReport = anscestorReport;
  16262. } else {
  16263. remoteReport = new Report(report);
  16264. if (SchemaCompilation.compileSchema.call(this, remoteReport, result)) {
  16265. var savedOptions = this.options;
  16266. try {
  16267. // If custom validationOptions were provided to setRemoteReference(),
  16268. // use them instead of the default options
  16269. this.options = result.__$validationOptions || this.options;
  16270. SchemaValidation.validateSchema.call(this, remoteReport, result);
  16271. } finally {
  16272. this.options = savedOptions;
  16273. }
  16274. }
  16275. }
  16276. var remoteReportIsValid = remoteReport.isValid();
  16277. if (!remoteReportIsValid) {
  16278. report.addError("REMOTE_NOT_VALID", [uri], remoteReport);
  16279. }
  16280. report.path.pop();
  16281. if (!remoteReportIsValid) {
  16282. return undefined;
  16283. }
  16284. }
  16285. }
  16286. if (result && queryPath) {
  16287. var parts = queryPath.split("/");
  16288. for (var idx = 0, lim = parts.length; result && idx < lim; idx++) {
  16289. var key = decodeJSONPointer(parts[idx]);
  16290. if (idx === 0) { // it's an id
  16291. result = findId(result, key);
  16292. } else { // it's a path behind id
  16293. result = result[key];
  16294. }
  16295. }
  16296. }
  16297. return result;
  16298. };
  16299. exports.getRemotePath = getRemotePath;
  16300. },{"./Report":146,"./SchemaCompilation":148,"./SchemaValidation":149,"./Utils":150,"lodash.isequal":10}],148:[function(require,module,exports){
  16301. "use strict";
  16302. var Report = require("./Report");
  16303. var SchemaCache = require("./SchemaCache");
  16304. var Utils = require("./Utils");
  16305. function mergeReference(scope, ref) {
  16306. if (Utils.isAbsoluteUri(ref)) {
  16307. return ref;
  16308. }
  16309. var joinedScope = scope.join(""),
  16310. isScopeAbsolute = Utils.isAbsoluteUri(joinedScope),
  16311. isScopeRelative = Utils.isRelativeUri(joinedScope),
  16312. isRefRelative = Utils.isRelativeUri(ref),
  16313. toRemove;
  16314. if (isScopeAbsolute && isRefRelative) {
  16315. toRemove = joinedScope.match(/\/[^\/]*$/);
  16316. if (toRemove) {
  16317. joinedScope = joinedScope.slice(0, toRemove.index + 1);
  16318. }
  16319. } else if (isScopeRelative && isRefRelative) {
  16320. joinedScope = "";
  16321. } else {
  16322. toRemove = joinedScope.match(/[^#/]+$/);
  16323. if (toRemove) {
  16324. joinedScope = joinedScope.slice(0, toRemove.index);
  16325. }
  16326. }
  16327. var res = joinedScope + ref;
  16328. res = res.replace(/##/, "#");
  16329. return res;
  16330. }
  16331. function collectReferences(obj, results, scope, path) {
  16332. results = results || [];
  16333. scope = scope || [];
  16334. path = path || [];
  16335. if (typeof obj !== "object" || obj === null) {
  16336. return results;
  16337. }
  16338. if (typeof obj.id === "string") {
  16339. scope.push(obj.id);
  16340. }
  16341. if (typeof obj.$ref === "string" && typeof obj.__$refResolved === "undefined") {
  16342. results.push({
  16343. ref: mergeReference(scope, obj.$ref),
  16344. key: "$ref",
  16345. obj: obj,
  16346. path: path.slice(0)
  16347. });
  16348. }
  16349. if (typeof obj.$schema === "string" && typeof obj.__$schemaResolved === "undefined") {
  16350. results.push({
  16351. ref: mergeReference(scope, obj.$schema),
  16352. key: "$schema",
  16353. obj: obj,
  16354. path: path.slice(0)
  16355. });
  16356. }
  16357. var idx;
  16358. if (Array.isArray(obj)) {
  16359. idx = obj.length;
  16360. while (idx--) {
  16361. path.push(idx.toString());
  16362. collectReferences(obj[idx], results, scope, path);
  16363. path.pop();
  16364. }
  16365. } else {
  16366. var keys = Object.keys(obj);
  16367. idx = keys.length;
  16368. while (idx--) {
  16369. // do not recurse through resolved references and other z-schema props
  16370. if (keys[idx].indexOf("__$") === 0) { continue; }
  16371. path.push(keys[idx]);
  16372. collectReferences(obj[keys[idx]], results, scope, path);
  16373. path.pop();
  16374. }
  16375. }
  16376. if (typeof obj.id === "string") {
  16377. scope.pop();
  16378. }
  16379. return results;
  16380. }
  16381. var compileArrayOfSchemasLoop = function (mainReport, arr) {
  16382. var idx = arr.length,
  16383. compiledCount = 0;
  16384. while (idx--) {
  16385. // try to compile each schema separately
  16386. var report = new Report(mainReport);
  16387. var isValid = exports.compileSchema.call(this, report, arr[idx]);
  16388. if (isValid) { compiledCount++; }
  16389. // copy errors to report
  16390. mainReport.errors = mainReport.errors.concat(report.errors);
  16391. }
  16392. return compiledCount;
  16393. };
  16394. function findId(arr, id) {
  16395. var idx = arr.length;
  16396. while (idx--) {
  16397. if (arr[idx].id === id) {
  16398. return arr[idx];
  16399. }
  16400. }
  16401. return null;
  16402. }
  16403. var compileArrayOfSchemas = function (report, arr) {
  16404. var compiled = 0,
  16405. lastLoopCompiled;
  16406. do {
  16407. // remove all UNRESOLVABLE_REFERENCE errors before compiling array again
  16408. var idx = report.errors.length;
  16409. while (idx--) {
  16410. if (report.errors[idx].code === "UNRESOLVABLE_REFERENCE") {
  16411. report.errors.splice(idx, 1);
  16412. }
  16413. }
  16414. // remember how many were compiled in the last loop
  16415. lastLoopCompiled = compiled;
  16416. // count how many are compiled now
  16417. compiled = compileArrayOfSchemasLoop.call(this, report, arr);
  16418. // fix __$missingReferences if possible
  16419. idx = arr.length;
  16420. while (idx--) {
  16421. var sch = arr[idx];
  16422. if (sch.__$missingReferences) {
  16423. var idx2 = sch.__$missingReferences.length;
  16424. while (idx2--) {
  16425. var refObj = sch.__$missingReferences[idx2];
  16426. var response = findId(arr, refObj.ref);
  16427. if (response) {
  16428. // this might create circular references
  16429. refObj.obj["__" + refObj.key + "Resolved"] = response;
  16430. // it's resolved now so delete it
  16431. sch.__$missingReferences.splice(idx2, 1);
  16432. }
  16433. }
  16434. if (sch.__$missingReferences.length === 0) {
  16435. delete sch.__$missingReferences;
  16436. }
  16437. }
  16438. }
  16439. // keep repeating if not all compiled and at least one more was compiled in the last loop
  16440. } while (compiled !== arr.length && compiled !== lastLoopCompiled);
  16441. return report.isValid();
  16442. };
  16443. exports.compileSchema = function (report, schema) {
  16444. report.commonErrorMessage = "SCHEMA_COMPILATION_FAILED";
  16445. // if schema is a string, assume it's a uri
  16446. if (typeof schema === "string") {
  16447. var loadedSchema = SchemaCache.getSchemaByUri.call(this, report, schema);
  16448. if (!loadedSchema) {
  16449. report.addError("SCHEMA_NOT_REACHABLE", [schema]);
  16450. return false;
  16451. }
  16452. schema = loadedSchema;
  16453. }
  16454. // if schema is an array, assume it's an array of schemas
  16455. if (Array.isArray(schema)) {
  16456. return compileArrayOfSchemas.call(this, report, schema);
  16457. }
  16458. // if we have an id than it should be cached already (if this instance has compiled it)
  16459. if (schema.__$compiled && schema.id && SchemaCache.checkCacheForUri.call(this, schema.id) === false) {
  16460. schema.__$compiled = undefined;
  16461. }
  16462. // do not re-compile schemas
  16463. if (schema.__$compiled) {
  16464. return true;
  16465. }
  16466. if (schema.id && typeof schema.id === "string") {
  16467. // add this to our schemaCache (before compilation in case we have references including id)
  16468. SchemaCache.cacheSchemaByUri.call(this, schema.id, schema);
  16469. }
  16470. // this method can be called recursively, so we need to remember our root
  16471. var isRoot = false;
  16472. if (!report.rootSchema) {
  16473. report.rootSchema = schema;
  16474. isRoot = true;
  16475. }
  16476. // delete all __$missingReferences from previous compilation attempts
  16477. var isValidExceptReferences = report.isValid();
  16478. delete schema.__$missingReferences;
  16479. // collect all references that need to be resolved - $ref and $schema
  16480. var refs = collectReferences.call(this, schema),
  16481. idx = refs.length;
  16482. while (idx--) {
  16483. // resolve all the collected references into __xxxResolved pointer
  16484. var refObj = refs[idx];
  16485. var response = SchemaCache.getSchemaByUri.call(this, report, refObj.ref, schema);
  16486. // we can try to use custom schemaReader if available
  16487. if (!response) {
  16488. var schemaReader = this.getSchemaReader();
  16489. if (schemaReader) {
  16490. // it's supposed to return a valid schema
  16491. var s = schemaReader(refObj.ref);
  16492. if (s) {
  16493. // it needs to have the id
  16494. s.id = refObj.ref;
  16495. // try to compile the schema
  16496. var subreport = new Report(report);
  16497. if (!exports.compileSchema.call(this, subreport, s)) {
  16498. // copy errors to report
  16499. report.errors = report.errors.concat(subreport.errors);
  16500. } else {
  16501. response = SchemaCache.getSchemaByUri.call(this, report, refObj.ref, schema);
  16502. }
  16503. }
  16504. }
  16505. }
  16506. if (!response) {
  16507. var hasNotValid = report.hasError("REMOTE_NOT_VALID", [refObj.ref]);
  16508. var isAbsolute = Utils.isAbsoluteUri(refObj.ref);
  16509. var isDownloaded = false;
  16510. var ignoreUnresolvableRemotes = this.options.ignoreUnresolvableReferences === true;
  16511. if (isAbsolute) {
  16512. // we shouldn't add UNRESOLVABLE_REFERENCE for schemas we already have downloaded
  16513. // and set through setRemoteReference method
  16514. isDownloaded = SchemaCache.checkCacheForUri.call(this, refObj.ref);
  16515. }
  16516. if (hasNotValid) {
  16517. // already has REMOTE_NOT_VALID error for this one
  16518. } else if (ignoreUnresolvableRemotes && isAbsolute) {
  16519. // ignoreUnresolvableRemotes is on and remote isAbsolute
  16520. } else if (isDownloaded) {
  16521. // remote is downloaded, so no UNRESOLVABLE_REFERENCE
  16522. } else {
  16523. Array.prototype.push.apply(report.path, refObj.path);
  16524. report.addError("UNRESOLVABLE_REFERENCE", [refObj.ref]);
  16525. report.path = report.path.slice(0, -refObj.path.length);
  16526. // pusblish unresolved references out
  16527. if (isValidExceptReferences) {
  16528. schema.__$missingReferences = schema.__$missingReferences || [];
  16529. schema.__$missingReferences.push(refObj);
  16530. }
  16531. }
  16532. }
  16533. // this might create circular references
  16534. refObj.obj["__" + refObj.key + "Resolved"] = response;
  16535. }
  16536. var isValid = report.isValid();
  16537. if (isValid) {
  16538. schema.__$compiled = true;
  16539. } else {
  16540. if (schema.id && typeof schema.id === "string") {
  16541. // remove this schema from schemaCache because it failed to compile
  16542. SchemaCache.removeFromCacheByUri.call(this, schema.id);
  16543. }
  16544. }
  16545. // we don't need the root pointer anymore
  16546. if (isRoot) {
  16547. report.rootSchema = undefined;
  16548. }
  16549. return isValid;
  16550. };
  16551. },{"./Report":146,"./SchemaCache":147,"./Utils":150}],149:[function(require,module,exports){
  16552. "use strict";
  16553. var FormatValidators = require("./FormatValidators"),
  16554. JsonValidation = require("./JsonValidation"),
  16555. Report = require("./Report"),
  16556. Utils = require("./Utils");
  16557. var SchemaValidators = {
  16558. $ref: function (report, schema) {
  16559. // http://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-07
  16560. // http://tools.ietf.org/html/draft-pbryan-zyp-json-ref-03
  16561. if (typeof schema.$ref !== "string") {
  16562. report.addError("KEYWORD_TYPE_EXPECTED", ["$ref", "string"]);
  16563. }
  16564. },
  16565. $schema: function (report, schema) {
  16566. // http://json-schema.org/latest/json-schema-core.html#rfc.section.6
  16567. if (typeof schema.$schema !== "string") {
  16568. report.addError("KEYWORD_TYPE_EXPECTED", ["$schema", "string"]);
  16569. }
  16570. },
  16571. multipleOf: function (report, schema) {
  16572. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.1.1.1
  16573. if (typeof schema.multipleOf !== "number") {
  16574. report.addError("KEYWORD_TYPE_EXPECTED", ["multipleOf", "number"]);
  16575. } else if (schema.multipleOf <= 0) {
  16576. report.addError("KEYWORD_MUST_BE", ["multipleOf", "strictly greater than 0"]);
  16577. }
  16578. },
  16579. maximum: function (report, schema) {
  16580. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.1.2.1
  16581. if (typeof schema.maximum !== "number") {
  16582. report.addError("KEYWORD_TYPE_EXPECTED", ["maximum", "number"]);
  16583. }
  16584. },
  16585. exclusiveMaximum: function (report, schema) {
  16586. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.1.2.1
  16587. if (typeof schema.exclusiveMaximum !== "boolean") {
  16588. report.addError("KEYWORD_TYPE_EXPECTED", ["exclusiveMaximum", "boolean"]);
  16589. } else if (schema.maximum === undefined) {
  16590. report.addError("KEYWORD_DEPENDENCY", ["exclusiveMaximum", "maximum"]);
  16591. }
  16592. },
  16593. minimum: function (report, schema) {
  16594. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.1.3.1
  16595. if (typeof schema.minimum !== "number") {
  16596. report.addError("KEYWORD_TYPE_EXPECTED", ["minimum", "number"]);
  16597. }
  16598. },
  16599. exclusiveMinimum: function (report, schema) {
  16600. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.1.3.1
  16601. if (typeof schema.exclusiveMinimum !== "boolean") {
  16602. report.addError("KEYWORD_TYPE_EXPECTED", ["exclusiveMinimum", "boolean"]);
  16603. } else if (schema.minimum === undefined) {
  16604. report.addError("KEYWORD_DEPENDENCY", ["exclusiveMinimum", "minimum"]);
  16605. }
  16606. },
  16607. maxLength: function (report, schema) {
  16608. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.2.1.1
  16609. if (Utils.whatIs(schema.maxLength) !== "integer") {
  16610. report.addError("KEYWORD_TYPE_EXPECTED", ["maxLength", "integer"]);
  16611. } else if (schema.maxLength < 0) {
  16612. report.addError("KEYWORD_MUST_BE", ["maxLength", "greater than, or equal to 0"]);
  16613. }
  16614. },
  16615. minLength: function (report, schema) {
  16616. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.2.2.1
  16617. if (Utils.whatIs(schema.minLength) !== "integer") {
  16618. report.addError("KEYWORD_TYPE_EXPECTED", ["minLength", "integer"]);
  16619. } else if (schema.minLength < 0) {
  16620. report.addError("KEYWORD_MUST_BE", ["minLength", "greater than, or equal to 0"]);
  16621. }
  16622. },
  16623. pattern: function (report, schema) {
  16624. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.2.3.1
  16625. if (typeof schema.pattern !== "string") {
  16626. report.addError("KEYWORD_TYPE_EXPECTED", ["pattern", "string"]);
  16627. } else {
  16628. try {
  16629. RegExp(schema.pattern);
  16630. } catch (e) {
  16631. report.addError("KEYWORD_PATTERN", ["pattern", schema.pattern]);
  16632. }
  16633. }
  16634. },
  16635. additionalItems: function (report, schema) {
  16636. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.3.1.1
  16637. var type = Utils.whatIs(schema.additionalItems);
  16638. if (type !== "boolean" && type !== "object") {
  16639. report.addError("KEYWORD_TYPE_EXPECTED", ["additionalItems", ["boolean", "object"]]);
  16640. } else if (type === "object") {
  16641. report.path.push("additionalItems");
  16642. exports.validateSchema.call(this, report, schema.additionalItems);
  16643. report.path.pop();
  16644. }
  16645. },
  16646. items: function (report, schema) {
  16647. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.3.1.1
  16648. var type = Utils.whatIs(schema.items);
  16649. if (type === "object") {
  16650. report.path.push("items");
  16651. exports.validateSchema.call(this, report, schema.items);
  16652. report.path.pop();
  16653. } else if (type === "array") {
  16654. var idx = schema.items.length;
  16655. while (idx--) {
  16656. report.path.push("items");
  16657. report.path.push(idx.toString());
  16658. exports.validateSchema.call(this, report, schema.items[idx]);
  16659. report.path.pop();
  16660. report.path.pop();
  16661. }
  16662. } else {
  16663. report.addError("KEYWORD_TYPE_EXPECTED", ["items", ["array", "object"]]);
  16664. }
  16665. // custom - strict mode
  16666. if (this.options.forceAdditional === true && schema.additionalItems === undefined && Array.isArray(schema.items)) {
  16667. report.addError("KEYWORD_UNDEFINED_STRICT", ["additionalItems"]);
  16668. }
  16669. // custome - assume defined false mode
  16670. if (this.options.assumeAdditional && schema.additionalItems === undefined && Array.isArray(schema.items)) {
  16671. schema.additionalItems = false;
  16672. }
  16673. },
  16674. maxItems: function (report, schema) {
  16675. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.3.2.1
  16676. if (typeof schema.maxItems !== "number") {
  16677. report.addError("KEYWORD_TYPE_EXPECTED", ["maxItems", "integer"]);
  16678. } else if (schema.maxItems < 0) {
  16679. report.addError("KEYWORD_MUST_BE", ["maxItems", "greater than, or equal to 0"]);
  16680. }
  16681. },
  16682. minItems: function (report, schema) {
  16683. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.3.3.1
  16684. if (Utils.whatIs(schema.minItems) !== "integer") {
  16685. report.addError("KEYWORD_TYPE_EXPECTED", ["minItems", "integer"]);
  16686. } else if (schema.minItems < 0) {
  16687. report.addError("KEYWORD_MUST_BE", ["minItems", "greater than, or equal to 0"]);
  16688. }
  16689. },
  16690. uniqueItems: function (report, schema) {
  16691. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.3.4.1
  16692. if (typeof schema.uniqueItems !== "boolean") {
  16693. report.addError("KEYWORD_TYPE_EXPECTED", ["uniqueItems", "boolean"]);
  16694. }
  16695. },
  16696. maxProperties: function (report, schema) {
  16697. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.4.1.1
  16698. if (Utils.whatIs(schema.maxProperties) !== "integer") {
  16699. report.addError("KEYWORD_TYPE_EXPECTED", ["maxProperties", "integer"]);
  16700. } else if (schema.maxProperties < 0) {
  16701. report.addError("KEYWORD_MUST_BE", ["maxProperties", "greater than, or equal to 0"]);
  16702. }
  16703. },
  16704. minProperties: function (report, schema) {
  16705. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.4.2.1
  16706. if (Utils.whatIs(schema.minProperties) !== "integer") {
  16707. report.addError("KEYWORD_TYPE_EXPECTED", ["minProperties", "integer"]);
  16708. } else if (schema.minProperties < 0) {
  16709. report.addError("KEYWORD_MUST_BE", ["minProperties", "greater than, or equal to 0"]);
  16710. }
  16711. },
  16712. required: function (report, schema) {
  16713. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.4.3.1
  16714. if (Utils.whatIs(schema.required) !== "array") {
  16715. report.addError("KEYWORD_TYPE_EXPECTED", ["required", "array"]);
  16716. } else if (schema.required.length === 0) {
  16717. report.addError("KEYWORD_MUST_BE", ["required", "an array with at least one element"]);
  16718. } else {
  16719. var idx = schema.required.length;
  16720. while (idx--) {
  16721. if (typeof schema.required[idx] !== "string") {
  16722. report.addError("KEYWORD_VALUE_TYPE", ["required", "string"]);
  16723. }
  16724. }
  16725. if (Utils.isUniqueArray(schema.required) === false) {
  16726. report.addError("KEYWORD_MUST_BE", ["required", "an array with unique items"]);
  16727. }
  16728. }
  16729. },
  16730. additionalProperties: function (report, schema) {
  16731. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.4.4.1
  16732. var type = Utils.whatIs(schema.additionalProperties);
  16733. if (type !== "boolean" && type !== "object") {
  16734. report.addError("KEYWORD_TYPE_EXPECTED", ["additionalProperties", ["boolean", "object"]]);
  16735. } else if (type === "object") {
  16736. report.path.push("additionalProperties");
  16737. exports.validateSchema.call(this, report, schema.additionalProperties);
  16738. report.path.pop();
  16739. }
  16740. },
  16741. properties: function (report, schema) {
  16742. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.4.4.1
  16743. if (Utils.whatIs(schema.properties) !== "object") {
  16744. report.addError("KEYWORD_TYPE_EXPECTED", ["properties", "object"]);
  16745. return;
  16746. }
  16747. var keys = Object.keys(schema.properties),
  16748. idx = keys.length;
  16749. while (idx--) {
  16750. var key = keys[idx],
  16751. val = schema.properties[key];
  16752. report.path.push("properties");
  16753. report.path.push(key);
  16754. exports.validateSchema.call(this, report, val);
  16755. report.path.pop();
  16756. report.path.pop();
  16757. }
  16758. // custom - strict mode
  16759. if (this.options.forceAdditional === true && schema.additionalProperties === undefined) {
  16760. report.addError("KEYWORD_UNDEFINED_STRICT", ["additionalProperties"]);
  16761. }
  16762. // custome - assume defined false mode
  16763. if (this.options.assumeAdditional && schema.additionalProperties === undefined) {
  16764. schema.additionalProperties = false;
  16765. }
  16766. // custom - forceProperties
  16767. if (this.options.forceProperties === true && keys.length === 0) {
  16768. report.addError("CUSTOM_MODE_FORCE_PROPERTIES", ["properties"]);
  16769. }
  16770. },
  16771. patternProperties: function (report, schema) {
  16772. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.4.4.1
  16773. if (Utils.whatIs(schema.patternProperties) !== "object") {
  16774. report.addError("KEYWORD_TYPE_EXPECTED", ["patternProperties", "object"]);
  16775. return;
  16776. }
  16777. var keys = Object.keys(schema.patternProperties),
  16778. idx = keys.length;
  16779. while (idx--) {
  16780. var key = keys[idx],
  16781. val = schema.patternProperties[key];
  16782. try {
  16783. RegExp(key);
  16784. } catch (e) {
  16785. report.addError("KEYWORD_PATTERN", ["patternProperties", key]);
  16786. }
  16787. report.path.push("patternProperties");
  16788. report.path.push(key.toString());
  16789. exports.validateSchema.call(this, report, val);
  16790. report.path.pop();
  16791. report.path.pop();
  16792. }
  16793. // custom - forceProperties
  16794. if (this.options.forceProperties === true && keys.length === 0) {
  16795. report.addError("CUSTOM_MODE_FORCE_PROPERTIES", ["patternProperties"]);
  16796. }
  16797. },
  16798. dependencies: function (report, schema) {
  16799. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.4.5.1
  16800. if (Utils.whatIs(schema.dependencies) !== "object") {
  16801. report.addError("KEYWORD_TYPE_EXPECTED", ["dependencies", "object"]);
  16802. } else {
  16803. var keys = Object.keys(schema.dependencies),
  16804. idx = keys.length;
  16805. while (idx--) {
  16806. var schemaKey = keys[idx],
  16807. schemaDependency = schema.dependencies[schemaKey],
  16808. type = Utils.whatIs(schemaDependency);
  16809. if (type === "object") {
  16810. report.path.push("dependencies");
  16811. report.path.push(schemaKey);
  16812. exports.validateSchema.call(this, report, schemaDependency);
  16813. report.path.pop();
  16814. report.path.pop();
  16815. } else if (type === "array") {
  16816. var idx2 = schemaDependency.length;
  16817. if (idx2 === 0) {
  16818. report.addError("KEYWORD_MUST_BE", ["dependencies", "not empty array"]);
  16819. }
  16820. while (idx2--) {
  16821. if (typeof schemaDependency[idx2] !== "string") {
  16822. report.addError("KEYWORD_VALUE_TYPE", ["dependensices", "string"]);
  16823. }
  16824. }
  16825. if (Utils.isUniqueArray(schemaDependency) === false) {
  16826. report.addError("KEYWORD_MUST_BE", ["dependencies", "an array with unique items"]);
  16827. }
  16828. } else {
  16829. report.addError("KEYWORD_VALUE_TYPE", ["dependencies", "object or array"]);
  16830. }
  16831. }
  16832. }
  16833. },
  16834. enum: function (report, schema) {
  16835. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.5.1.1
  16836. if (Array.isArray(schema.enum) === false) {
  16837. report.addError("KEYWORD_TYPE_EXPECTED", ["enum", "array"]);
  16838. } else if (schema.enum.length === 0) {
  16839. report.addError("KEYWORD_MUST_BE", ["enum", "an array with at least one element"]);
  16840. } else if (Utils.isUniqueArray(schema.enum) === false) {
  16841. report.addError("KEYWORD_MUST_BE", ["enum", "an array with unique elements"]);
  16842. }
  16843. },
  16844. type: function (report, schema) {
  16845. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.5.2.1
  16846. var primitiveTypes = ["array", "boolean", "integer", "number", "null", "object", "string"],
  16847. primitiveTypeStr = primitiveTypes.join(","),
  16848. isArray = Array.isArray(schema.type);
  16849. if (isArray) {
  16850. var idx = schema.type.length;
  16851. while (idx--) {
  16852. if (primitiveTypes.indexOf(schema.type[idx]) === -1) {
  16853. report.addError("KEYWORD_TYPE_EXPECTED", ["type", primitiveTypeStr]);
  16854. }
  16855. }
  16856. if (Utils.isUniqueArray(schema.type) === false) {
  16857. report.addError("KEYWORD_MUST_BE", ["type", "an object with unique properties"]);
  16858. }
  16859. } else if (typeof schema.type === "string") {
  16860. if (primitiveTypes.indexOf(schema.type) === -1) {
  16861. report.addError("KEYWORD_TYPE_EXPECTED", ["type", primitiveTypeStr]);
  16862. }
  16863. } else {
  16864. report.addError("KEYWORD_TYPE_EXPECTED", ["type", ["string", "array"]]);
  16865. }
  16866. if (this.options.noEmptyStrings === true) {
  16867. if (schema.type === "string" || isArray && schema.type.indexOf("string") !== -1) {
  16868. if (schema.minLength === undefined &&
  16869. schema.enum === undefined &&
  16870. schema.format === undefined) {
  16871. schema.minLength = 1;
  16872. }
  16873. }
  16874. }
  16875. if (this.options.noEmptyArrays === true) {
  16876. if (schema.type === "array" || isArray && schema.type.indexOf("array") !== -1) {
  16877. if (schema.minItems === undefined) {
  16878. schema.minItems = 1;
  16879. }
  16880. }
  16881. }
  16882. if (this.options.forceProperties === true) {
  16883. if (schema.type === "object" || isArray && schema.type.indexOf("object") !== -1) {
  16884. if (schema.properties === undefined && schema.patternProperties === undefined) {
  16885. report.addError("KEYWORD_UNDEFINED_STRICT", ["properties"]);
  16886. }
  16887. }
  16888. }
  16889. if (this.options.forceItems === true) {
  16890. if (schema.type === "array" || isArray && schema.type.indexOf("array") !== -1) {
  16891. if (schema.items === undefined) {
  16892. report.addError("KEYWORD_UNDEFINED_STRICT", ["items"]);
  16893. }
  16894. }
  16895. }
  16896. if (this.options.forceMinItems === true) {
  16897. if (schema.type === "array" || isArray && schema.type.indexOf("array") !== -1) {
  16898. if (schema.minItems === undefined) {
  16899. report.addError("KEYWORD_UNDEFINED_STRICT", ["minItems"]);
  16900. }
  16901. }
  16902. }
  16903. if (this.options.forceMaxItems === true) {
  16904. if (schema.type === "array" || isArray && schema.type.indexOf("array") !== -1) {
  16905. if (schema.maxItems === undefined) {
  16906. report.addError("KEYWORD_UNDEFINED_STRICT", ["maxItems"]);
  16907. }
  16908. }
  16909. }
  16910. if (this.options.forceMinLength === true) {
  16911. if (schema.type === "string" || isArray && schema.type.indexOf("string") !== -1) {
  16912. if (schema.minLength === undefined &&
  16913. schema.format === undefined &&
  16914. schema.enum === undefined &&
  16915. schema.pattern === undefined) {
  16916. report.addError("KEYWORD_UNDEFINED_STRICT", ["minLength"]);
  16917. }
  16918. }
  16919. }
  16920. if (this.options.forceMaxLength === true) {
  16921. if (schema.type === "string" || isArray && schema.type.indexOf("string") !== -1) {
  16922. if (schema.maxLength === undefined &&
  16923. schema.format === undefined &&
  16924. schema.enum === undefined &&
  16925. schema.pattern === undefined) {
  16926. report.addError("KEYWORD_UNDEFINED_STRICT", ["maxLength"]);
  16927. }
  16928. }
  16929. }
  16930. },
  16931. allOf: function (report, schema) {
  16932. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.5.3.1
  16933. if (Array.isArray(schema.allOf) === false) {
  16934. report.addError("KEYWORD_TYPE_EXPECTED", ["allOf", "array"]);
  16935. } else if (schema.allOf.length === 0) {
  16936. report.addError("KEYWORD_MUST_BE", ["allOf", "an array with at least one element"]);
  16937. } else {
  16938. var idx = schema.allOf.length;
  16939. while (idx--) {
  16940. report.path.push("allOf");
  16941. report.path.push(idx.toString());
  16942. exports.validateSchema.call(this, report, schema.allOf[idx]);
  16943. report.path.pop();
  16944. report.path.pop();
  16945. }
  16946. }
  16947. },
  16948. anyOf: function (report, schema) {
  16949. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.5.4.1
  16950. if (Array.isArray(schema.anyOf) === false) {
  16951. report.addError("KEYWORD_TYPE_EXPECTED", ["anyOf", "array"]);
  16952. } else if (schema.anyOf.length === 0) {
  16953. report.addError("KEYWORD_MUST_BE", ["anyOf", "an array with at least one element"]);
  16954. } else {
  16955. var idx = schema.anyOf.length;
  16956. while (idx--) {
  16957. report.path.push("anyOf");
  16958. report.path.push(idx.toString());
  16959. exports.validateSchema.call(this, report, schema.anyOf[idx]);
  16960. report.path.pop();
  16961. report.path.pop();
  16962. }
  16963. }
  16964. },
  16965. oneOf: function (report, schema) {
  16966. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.5.5.1
  16967. if (Array.isArray(schema.oneOf) === false) {
  16968. report.addError("KEYWORD_TYPE_EXPECTED", ["oneOf", "array"]);
  16969. } else if (schema.oneOf.length === 0) {
  16970. report.addError("KEYWORD_MUST_BE", ["oneOf", "an array with at least one element"]);
  16971. } else {
  16972. var idx = schema.oneOf.length;
  16973. while (idx--) {
  16974. report.path.push("oneOf");
  16975. report.path.push(idx.toString());
  16976. exports.validateSchema.call(this, report, schema.oneOf[idx]);
  16977. report.path.pop();
  16978. report.path.pop();
  16979. }
  16980. }
  16981. },
  16982. not: function (report, schema) {
  16983. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.5.6.1
  16984. if (Utils.whatIs(schema.not) !== "object") {
  16985. report.addError("KEYWORD_TYPE_EXPECTED", ["not", "object"]);
  16986. } else {
  16987. report.path.push("not");
  16988. exports.validateSchema.call(this, report, schema.not);
  16989. report.path.pop();
  16990. }
  16991. },
  16992. definitions: function (report, schema) {
  16993. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.5.7.1
  16994. if (Utils.whatIs(schema.definitions) !== "object") {
  16995. report.addError("KEYWORD_TYPE_EXPECTED", ["definitions", "object"]);
  16996. } else {
  16997. var keys = Object.keys(schema.definitions),
  16998. idx = keys.length;
  16999. while (idx--) {
  17000. var key = keys[idx],
  17001. val = schema.definitions[key];
  17002. report.path.push("definitions");
  17003. report.path.push(key);
  17004. exports.validateSchema.call(this, report, val);
  17005. report.path.pop();
  17006. report.path.pop();
  17007. }
  17008. }
  17009. },
  17010. format: function (report, schema) {
  17011. if (typeof schema.format !== "string") {
  17012. report.addError("KEYWORD_TYPE_EXPECTED", ["format", "string"]);
  17013. } else {
  17014. if (FormatValidators[schema.format] === undefined && this.options.ignoreUnknownFormats !== true) {
  17015. report.addError("UNKNOWN_FORMAT", [schema.format]);
  17016. }
  17017. }
  17018. },
  17019. id: function (report, schema) {
  17020. // http://json-schema.org/latest/json-schema-core.html#rfc.section.7.2
  17021. if (typeof schema.id !== "string") {
  17022. report.addError("KEYWORD_TYPE_EXPECTED", ["id", "string"]);
  17023. }
  17024. },
  17025. title: function (report, schema) {
  17026. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.6.1
  17027. if (typeof schema.title !== "string") {
  17028. report.addError("KEYWORD_TYPE_EXPECTED", ["title", "string"]);
  17029. }
  17030. },
  17031. description: function (report, schema) {
  17032. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.6.1
  17033. if (typeof schema.description !== "string") {
  17034. report.addError("KEYWORD_TYPE_EXPECTED", ["description", "string"]);
  17035. }
  17036. },
  17037. "default": function (/* report, schema */) {
  17038. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.6.2
  17039. // There are no restrictions placed on the value of this keyword.
  17040. }
  17041. };
  17042. /**
  17043. *
  17044. * @param {Report} report
  17045. * @param {*[]} arr
  17046. *
  17047. * @returns {boolean}
  17048. */
  17049. var validateArrayOfSchemas = function (report, arr) {
  17050. var idx = arr.length;
  17051. while (idx--) {
  17052. exports.validateSchema.call(this, report, arr[idx]);
  17053. }
  17054. return report.isValid();
  17055. };
  17056. /**
  17057. *
  17058. * @param {Report} report
  17059. * @param {*} schema
  17060. */
  17061. exports.validateSchema = function (report, schema) {
  17062. report.commonErrorMessage = "SCHEMA_VALIDATION_FAILED";
  17063. // if schema is an array, assume it's an array of schemas
  17064. if (Array.isArray(schema)) {
  17065. return validateArrayOfSchemas.call(this, report, schema);
  17066. }
  17067. // do not revalidate schema that has already been validated once
  17068. if (schema.__$validated) {
  17069. return true;
  17070. }
  17071. // if $schema is present, this schema should validate against that $schema
  17072. var hasParentSchema = schema.$schema && schema.id !== schema.$schema;
  17073. if (hasParentSchema) {
  17074. if (schema.__$schemaResolved && schema.__$schemaResolved !== schema) {
  17075. var subReport = new Report(report);
  17076. var valid = JsonValidation.validate.call(this, subReport, schema.__$schemaResolved, schema);
  17077. if (valid === false) {
  17078. report.addError("PARENT_SCHEMA_VALIDATION_FAILED", null, subReport);
  17079. }
  17080. } else {
  17081. if (this.options.ignoreUnresolvableReferences !== true) {
  17082. report.addError("REF_UNRESOLVED", [schema.$schema]);
  17083. }
  17084. }
  17085. }
  17086. if (this.options.noTypeless === true) {
  17087. // issue #36 - inherit type to anyOf, oneOf, allOf if noTypeless is defined
  17088. if (schema.type !== undefined) {
  17089. var schemas = [];
  17090. if (Array.isArray(schema.anyOf)) { schemas = schemas.concat(schema.anyOf); }
  17091. if (Array.isArray(schema.oneOf)) { schemas = schemas.concat(schema.oneOf); }
  17092. if (Array.isArray(schema.allOf)) { schemas = schemas.concat(schema.allOf); }
  17093. schemas.forEach(function (sch) {
  17094. if (!sch.type) { sch.type = schema.type; }
  17095. });
  17096. }
  17097. // end issue #36
  17098. if (schema.enum === undefined &&
  17099. schema.type === undefined &&
  17100. schema.anyOf === undefined &&
  17101. schema.oneOf === undefined &&
  17102. schema.not === undefined &&
  17103. schema.$ref === undefined) {
  17104. report.addError("KEYWORD_UNDEFINED_STRICT", ["type"]);
  17105. }
  17106. }
  17107. var keys = Object.keys(schema),
  17108. idx = keys.length;
  17109. while (idx--) {
  17110. var key = keys[idx];
  17111. if (key.indexOf("__") === 0) { continue; }
  17112. if (SchemaValidators[key] !== undefined) {
  17113. SchemaValidators[key].call(this, report, schema);
  17114. } else if (!hasParentSchema) {
  17115. if (this.options.noExtraKeywords === true) {
  17116. report.addError("KEYWORD_UNEXPECTED", [key]);
  17117. }
  17118. }
  17119. }
  17120. if (this.options.pedanticCheck === true) {
  17121. if (schema.enum) {
  17122. // break recursion
  17123. var tmpSchema = Utils.clone(schema);
  17124. delete tmpSchema.enum;
  17125. delete tmpSchema.default;
  17126. report.path.push("enum");
  17127. idx = schema.enum.length;
  17128. while (idx--) {
  17129. report.path.push(idx.toString());
  17130. JsonValidation.validate.call(this, report, tmpSchema, schema.enum[idx]);
  17131. report.path.pop();
  17132. }
  17133. report.path.pop();
  17134. }
  17135. if (schema.default) {
  17136. report.path.push("default");
  17137. JsonValidation.validate.call(this, report, schema, schema.default);
  17138. report.path.pop();
  17139. }
  17140. }
  17141. var isValid = report.isValid();
  17142. if (isValid) {
  17143. schema.__$validated = true;
  17144. }
  17145. return isValid;
  17146. };
  17147. },{"./FormatValidators":143,"./JsonValidation":144,"./Report":146,"./Utils":150}],150:[function(require,module,exports){
  17148. "use strict";
  17149. exports.jsonSymbol = Symbol.for("z-schema/json");
  17150. exports.schemaSymbol = Symbol.for("z-schema/schema");
  17151. /**
  17152. * @param {object} obj
  17153. *
  17154. * @returns {string[]}
  17155. */
  17156. var sortedKeys = exports.sortedKeys = function (obj) {
  17157. return Object.keys(obj).sort();
  17158. };
  17159. /**
  17160. *
  17161. * @param {string} uri
  17162. *
  17163. * @returns {boolean}
  17164. */
  17165. exports.isAbsoluteUri = function (uri) {
  17166. return /^https?:\/\//.test(uri);
  17167. };
  17168. /**
  17169. *
  17170. * @param {string} uri
  17171. *
  17172. * @returns {boolean}
  17173. */
  17174. exports.isRelativeUri = function (uri) {
  17175. // relative URIs that end with a hash sign, issue #56
  17176. return /.+#/.test(uri);
  17177. };
  17178. exports.whatIs = function (what) {
  17179. var to = typeof what;
  17180. if (to === "object") {
  17181. if (what === null) {
  17182. return "null";
  17183. }
  17184. if (Array.isArray(what)) {
  17185. return "array";
  17186. }
  17187. return "object"; // typeof what === 'object' && what === Object(what) && !Array.isArray(what);
  17188. }
  17189. if (to === "number") {
  17190. if (Number.isFinite(what)) {
  17191. if (what % 1 === 0) {
  17192. return "integer";
  17193. } else {
  17194. return "number";
  17195. }
  17196. }
  17197. if (Number.isNaN(what)) {
  17198. return "not-a-number";
  17199. }
  17200. return "unknown-number";
  17201. }
  17202. return to; // undefined, boolean, string, function
  17203. };
  17204. /**
  17205. *
  17206. * @param {*} json1
  17207. * @param {*} json2
  17208. * @param {*} [options]
  17209. *
  17210. * @returns {boolean}
  17211. */
  17212. exports.areEqual = function areEqual(json1, json2, options) {
  17213. options = options || {};
  17214. var caseInsensitiveComparison = options.caseInsensitiveComparison || false;
  17215. // http://json-schema.org/latest/json-schema-core.html#rfc.section.3.6
  17216. // Two JSON values are said to be equal if and only if:
  17217. // both are nulls; or
  17218. // both are booleans, and have the same value; or
  17219. // both are strings, and have the same value; or
  17220. // both are numbers, and have the same mathematical value; or
  17221. if (json1 === json2) {
  17222. return true;
  17223. }
  17224. if (
  17225. caseInsensitiveComparison === true &&
  17226. typeof json1 === "string" && typeof json2 === "string" &&
  17227. json1.toUpperCase() === json2.toUpperCase()) {
  17228. return true;
  17229. }
  17230. var i, len;
  17231. // both are arrays, and:
  17232. if (Array.isArray(json1) && Array.isArray(json2)) {
  17233. // have the same number of items; and
  17234. if (json1.length !== json2.length) {
  17235. return false;
  17236. }
  17237. // items at the same index are equal according to this definition; or
  17238. len = json1.length;
  17239. for (i = 0; i < len; i++) {
  17240. if (!areEqual(json1[i], json2[i], { caseInsensitiveComparison: caseInsensitiveComparison })) {
  17241. return false;
  17242. }
  17243. }
  17244. return true;
  17245. }
  17246. // both are objects, and:
  17247. if (exports.whatIs(json1) === "object" && exports.whatIs(json2) === "object") {
  17248. // have the same set of property names; and
  17249. var keys1 = sortedKeys(json1);
  17250. var keys2 = sortedKeys(json2);
  17251. if (!areEqual(keys1, keys2, { caseInsensitiveComparison: caseInsensitiveComparison })) {
  17252. return false;
  17253. }
  17254. // values for a same property name are equal according to this definition.
  17255. len = keys1.length;
  17256. for (i = 0; i < len; i++) {
  17257. if (!areEqual(json1[keys1[i]], json2[keys1[i]], { caseInsensitiveComparison: caseInsensitiveComparison })) {
  17258. return false;
  17259. }
  17260. }
  17261. return true;
  17262. }
  17263. return false;
  17264. };
  17265. /**
  17266. *
  17267. * @param {*[]} arr
  17268. * @param {number[]} [indexes]
  17269. *
  17270. * @returns {boolean}
  17271. */
  17272. exports.isUniqueArray = function (arr, indexes) {
  17273. var i, j, l = arr.length;
  17274. for (i = 0; i < l; i++) {
  17275. for (j = i + 1; j < l; j++) {
  17276. if (exports.areEqual(arr[i], arr[j])) {
  17277. if (indexes) { indexes.push(i, j); }
  17278. return false;
  17279. }
  17280. }
  17281. }
  17282. return true;
  17283. };
  17284. /**
  17285. *
  17286. * @param {*} bigSet
  17287. * @param {*} subSet
  17288. *
  17289. * @returns {*[]}
  17290. */
  17291. exports.difference = function (bigSet, subSet) {
  17292. var arr = [],
  17293. idx = bigSet.length;
  17294. while (idx--) {
  17295. if (subSet.indexOf(bigSet[idx]) === -1) {
  17296. arr.push(bigSet[idx]);
  17297. }
  17298. }
  17299. return arr;
  17300. };
  17301. // NOT a deep version of clone
  17302. exports.clone = function (src) {
  17303. if (typeof src === "undefined") { return void 0; }
  17304. if (typeof src !== "object" || src === null) { return src; }
  17305. var res, idx;
  17306. if (Array.isArray(src)) {
  17307. res = [];
  17308. idx = src.length;
  17309. while (idx--) {
  17310. res[idx] = src[idx];
  17311. }
  17312. } else {
  17313. res = {};
  17314. var keys = Object.keys(src);
  17315. idx = keys.length;
  17316. while (idx--) {
  17317. var key = keys[idx];
  17318. res[key] = src[key];
  17319. }
  17320. }
  17321. return res;
  17322. };
  17323. exports.cloneDeep = function (src) {
  17324. var vidx = 0, visited = new Map(), cloned = [];
  17325. function cloneDeep(src) {
  17326. if (typeof src !== "object" || src === null) { return src; }
  17327. var res, idx, cidx;
  17328. cidx = visited.get(src);
  17329. if (cidx !== undefined) { return cloned[cidx]; }
  17330. visited.set(src, vidx++);
  17331. if (Array.isArray(src)) {
  17332. res = [];
  17333. cloned.push(res);
  17334. idx = src.length;
  17335. while (idx--) {
  17336. res[idx] = cloneDeep(src[idx]);
  17337. }
  17338. } else {
  17339. res = {};
  17340. cloned.push(res);
  17341. var keys = Object.keys(src);
  17342. idx = keys.length;
  17343. while (idx--) {
  17344. var key = keys[idx];
  17345. res[key] = cloneDeep(src[key]);
  17346. }
  17347. }
  17348. return res;
  17349. }
  17350. return cloneDeep(src);
  17351. };
  17352. /*
  17353. following function comes from punycode.js library
  17354. see: https://github.com/bestiejs/punycode.js
  17355. */
  17356. /*jshint -W016*/
  17357. /**
  17358. * Creates an array containing the numeric code points of each Unicode
  17359. * character in the string. While JavaScript uses UCS-2 internally,
  17360. * this function will convert a pair of surrogate halves (each of which
  17361. * UCS-2 exposes as separate characters) into a single code point,
  17362. * matching UTF-16.
  17363. * @see `punycode.ucs2.encode`
  17364. * @see <https://mathiasbynens.be/notes/javascript-encoding>
  17365. * @memberOf punycode.ucs2
  17366. * @name decode
  17367. * @param {String} string The Unicode input string (UCS-2).
  17368. * @returns {Array} The new array of code points.
  17369. */
  17370. exports.ucs2decode = function (string) {
  17371. var output = [],
  17372. counter = 0,
  17373. length = string.length,
  17374. value,
  17375. extra;
  17376. while (counter < length) {
  17377. value = string.charCodeAt(counter++);
  17378. if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
  17379. // high surrogate, and there is a next character
  17380. extra = string.charCodeAt(counter++);
  17381. if ((extra & 0xFC00) == 0xDC00) { // low surrogate
  17382. output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
  17383. } else {
  17384. // unmatched surrogate; only append this code unit, in case the next
  17385. // code unit is the high surrogate of a surrogate pair
  17386. output.push(value);
  17387. counter--;
  17388. }
  17389. } else {
  17390. output.push(value);
  17391. }
  17392. }
  17393. return output;
  17394. };
  17395. /*jshint +W016*/
  17396. },{}],151:[function(require,module,exports){
  17397. (function (process){(function (){
  17398. "use strict";
  17399. require("./Polyfills");
  17400. var get = require("lodash.get");
  17401. var Report = require("./Report");
  17402. var FormatValidators = require("./FormatValidators");
  17403. var JsonValidation = require("./JsonValidation");
  17404. var SchemaCache = require("./SchemaCache");
  17405. var SchemaCompilation = require("./SchemaCompilation");
  17406. var SchemaValidation = require("./SchemaValidation");
  17407. var Utils = require("./Utils");
  17408. var Draft4Schema = require("./schemas/schema.json");
  17409. var Draft4HyperSchema = require("./schemas/hyper-schema.json");
  17410. /**
  17411. * default options
  17412. */
  17413. var defaultOptions = {
  17414. // default timeout for all async tasks
  17415. asyncTimeout: 2000,
  17416. // force additionalProperties and additionalItems to be defined on "object" and "array" types
  17417. forceAdditional: false,
  17418. // assume additionalProperties and additionalItems are defined as "false" where appropriate
  17419. assumeAdditional: false,
  17420. // do case insensitive comparison for enums
  17421. enumCaseInsensitiveComparison: false,
  17422. // force items to be defined on "array" types
  17423. forceItems: false,
  17424. // force minItems to be defined on "array" types
  17425. forceMinItems: false,
  17426. // force maxItems to be defined on "array" types
  17427. forceMaxItems: false,
  17428. // force minLength to be defined on "string" types
  17429. forceMinLength: false,
  17430. // force maxLength to be defined on "string" types
  17431. forceMaxLength: false,
  17432. // force properties or patternProperties to be defined on "object" types
  17433. forceProperties: false,
  17434. // ignore references that cannot be resolved (remote schemas) // TODO: make sure this is only for remote schemas, not local ones
  17435. ignoreUnresolvableReferences: false,
  17436. // disallow usage of keywords that this validator can't handle
  17437. noExtraKeywords: false,
  17438. // disallow usage of schema's without "type" defined
  17439. noTypeless: false,
  17440. // disallow zero length strings in validated objects
  17441. noEmptyStrings: false,
  17442. // disallow zero length arrays in validated objects
  17443. noEmptyArrays: false,
  17444. // forces "uri" format to be in fully rfc3986 compliant
  17445. strictUris: false,
  17446. // turn on some of the above
  17447. strictMode: false,
  17448. // report error paths as an array of path segments to get to the offending node
  17449. reportPathAsArray: false,
  17450. // stop validation as soon as an error is found
  17451. breakOnFirstError: false,
  17452. // check if schema follows best practices and common sense
  17453. pedanticCheck: false,
  17454. // ignore unknown formats (do not report them as an error)
  17455. ignoreUnknownFormats: false,
  17456. // function to be called on every schema
  17457. customValidator: null
  17458. };
  17459. function normalizeOptions(options) {
  17460. var normalized;
  17461. // options
  17462. if (typeof options === "object") {
  17463. var keys = Object.keys(options),
  17464. idx = keys.length,
  17465. key;
  17466. // check that the options are correctly configured
  17467. while (idx--) {
  17468. key = keys[idx];
  17469. if (defaultOptions[key] === undefined) {
  17470. throw new Error("Unexpected option passed to constructor: " + key);
  17471. }
  17472. }
  17473. // copy the default options into passed options
  17474. keys = Object.keys(defaultOptions);
  17475. idx = keys.length;
  17476. while (idx--) {
  17477. key = keys[idx];
  17478. if (options[key] === undefined) {
  17479. options[key] = Utils.clone(defaultOptions[key]);
  17480. }
  17481. }
  17482. normalized = options;
  17483. } else {
  17484. normalized = Utils.clone(defaultOptions);
  17485. }
  17486. if (normalized.strictMode === true) {
  17487. normalized.forceAdditional = true;
  17488. normalized.forceItems = true;
  17489. normalized.forceMaxLength = true;
  17490. normalized.forceProperties = true;
  17491. normalized.noExtraKeywords = true;
  17492. normalized.noTypeless = true;
  17493. normalized.noEmptyStrings = true;
  17494. normalized.noEmptyArrays = true;
  17495. }
  17496. return normalized;
  17497. }
  17498. /**
  17499. * @class
  17500. *
  17501. * @param {*} [options]
  17502. */
  17503. function ZSchema(options) {
  17504. this.cache = {};
  17505. this.referenceCache = [];
  17506. this.validateOptions = {};
  17507. this.options = normalizeOptions(options);
  17508. // Disable strict validation for the built-in schemas
  17509. var metaschemaOptions = normalizeOptions({ });
  17510. this.setRemoteReference("http://json-schema.org/draft-04/schema", Draft4Schema, metaschemaOptions);
  17511. this.setRemoteReference("http://json-schema.org/draft-04/hyper-schema", Draft4HyperSchema, metaschemaOptions);
  17512. }
  17513. /**
  17514. * instance methods
  17515. *
  17516. * @param {*} schema
  17517. *
  17518. * @returns {boolean}
  17519. */
  17520. ZSchema.prototype.compileSchema = function (schema) {
  17521. var report = new Report(this.options);
  17522. schema = SchemaCache.getSchema.call(this, report, schema);
  17523. SchemaCompilation.compileSchema.call(this, report, schema);
  17524. this.lastReport = report;
  17525. return report.isValid();
  17526. };
  17527. /**
  17528. *
  17529. * @param {*} schema
  17530. *
  17531. * @returns {boolean}
  17532. */
  17533. ZSchema.prototype.validateSchema = function (schema) {
  17534. if (Array.isArray(schema) && schema.length === 0) {
  17535. throw new Error(".validateSchema was called with an empty array");
  17536. }
  17537. var report = new Report(this.options);
  17538. schema = SchemaCache.getSchema.call(this, report, schema);
  17539. var compiled = SchemaCompilation.compileSchema.call(this, report, schema);
  17540. if (compiled) { SchemaValidation.validateSchema.call(this, report, schema); }
  17541. this.lastReport = report;
  17542. return report.isValid();
  17543. };
  17544. /**
  17545. *
  17546. * @param {*} json
  17547. * @param {*} schema
  17548. * @param {*} [options]
  17549. * @param {function(*, *)} [callback]
  17550. *
  17551. * @returns {boolean}
  17552. */
  17553. ZSchema.prototype.validate = function (json, schema, options, callback) {
  17554. if (Utils.whatIs(options) === "function") {
  17555. callback = options;
  17556. options = {};
  17557. }
  17558. if (!options) { options = {}; }
  17559. this.validateOptions = options;
  17560. var whatIs = Utils.whatIs(schema);
  17561. if (whatIs !== "string" && whatIs !== "object") {
  17562. var e = new Error("Invalid .validate call - schema must be a string or object but " + whatIs + " was passed!");
  17563. if (callback) {
  17564. process.nextTick(function () {
  17565. callback(e, false);
  17566. });
  17567. return;
  17568. }
  17569. throw e;
  17570. }
  17571. var foundError = false;
  17572. var report = new Report(this.options);
  17573. report.json = json;
  17574. if (typeof schema === "string") {
  17575. var schemaName = schema;
  17576. schema = SchemaCache.getSchema.call(this, report, schemaName);
  17577. if (!schema) {
  17578. throw new Error("Schema with id '" + schemaName + "' wasn't found in the validator cache!");
  17579. }
  17580. } else {
  17581. schema = SchemaCache.getSchema.call(this, report, schema);
  17582. }
  17583. var compiled = false;
  17584. if (!foundError) {
  17585. compiled = SchemaCompilation.compileSchema.call(this, report, schema);
  17586. }
  17587. if (!compiled) {
  17588. this.lastReport = report;
  17589. foundError = true;
  17590. }
  17591. var validated = false;
  17592. if (!foundError) {
  17593. validated = SchemaValidation.validateSchema.call(this, report, schema);
  17594. }
  17595. if (!validated) {
  17596. this.lastReport = report;
  17597. foundError = true;
  17598. }
  17599. if (options.schemaPath) {
  17600. report.rootSchema = schema;
  17601. schema = get(schema, options.schemaPath);
  17602. if (!schema) {
  17603. throw new Error("Schema path '" + options.schemaPath + "' wasn't found in the schema!");
  17604. }
  17605. }
  17606. if (!foundError) {
  17607. JsonValidation.validate.call(this, report, schema, json);
  17608. }
  17609. if (callback) {
  17610. report.processAsyncTasks(this.options.asyncTimeout, callback);
  17611. return;
  17612. } else if (report.asyncTasks.length > 0) {
  17613. throw new Error("This validation has async tasks and cannot be done in sync mode, please provide callback argument.");
  17614. }
  17615. // assign lastReport so errors are retrievable in sync mode
  17616. this.lastReport = report;
  17617. return report.isValid();
  17618. };
  17619. ZSchema.prototype.getLastError = function () {
  17620. if (this.lastReport.errors.length === 0) {
  17621. return null;
  17622. }
  17623. var e = new Error();
  17624. e.name = "z-schema validation error";
  17625. e.message = this.lastReport.commonErrorMessage;
  17626. e.details = this.lastReport.errors;
  17627. return e;
  17628. };
  17629. ZSchema.prototype.getLastErrors = function () {
  17630. return this.lastReport && this.lastReport.errors.length > 0 ? this.lastReport.errors : null;
  17631. };
  17632. ZSchema.prototype.getMissingReferences = function (arr) {
  17633. arr = arr || this.lastReport.errors;
  17634. var res = [],
  17635. idx = arr.length;
  17636. while (idx--) {
  17637. var error = arr[idx];
  17638. if (error.code === "UNRESOLVABLE_REFERENCE") {
  17639. var reference = error.params[0];
  17640. if (res.indexOf(reference) === -1) {
  17641. res.push(reference);
  17642. }
  17643. }
  17644. if (error.inner) {
  17645. res = res.concat(this.getMissingReferences(error.inner));
  17646. }
  17647. }
  17648. return res;
  17649. };
  17650. ZSchema.prototype.getMissingRemoteReferences = function () {
  17651. var missingReferences = this.getMissingReferences(),
  17652. missingRemoteReferences = [],
  17653. idx = missingReferences.length;
  17654. while (idx--) {
  17655. var remoteReference = SchemaCache.getRemotePath(missingReferences[idx]);
  17656. if (remoteReference && missingRemoteReferences.indexOf(remoteReference) === -1) {
  17657. missingRemoteReferences.push(remoteReference);
  17658. }
  17659. }
  17660. return missingRemoteReferences;
  17661. };
  17662. ZSchema.prototype.setRemoteReference = function (uri, schema, validationOptions) {
  17663. if (typeof schema === "string") {
  17664. schema = JSON.parse(schema);
  17665. } else {
  17666. schema = Utils.cloneDeep(schema);
  17667. }
  17668. if (validationOptions) {
  17669. schema.__$validationOptions = normalizeOptions(validationOptions);
  17670. }
  17671. SchemaCache.cacheSchemaByUri.call(this, uri, schema);
  17672. };
  17673. ZSchema.prototype.getResolvedSchema = function (schema) {
  17674. var report = new Report(this.options);
  17675. schema = SchemaCache.getSchema.call(this, report, schema);
  17676. // clone before making any modifications
  17677. schema = Utils.cloneDeep(schema);
  17678. var visited = [];
  17679. // clean-up the schema and resolve references
  17680. var cleanup = function (schema) {
  17681. var key,
  17682. typeOf = Utils.whatIs(schema);
  17683. if (typeOf !== "object" && typeOf !== "array") {
  17684. return;
  17685. }
  17686. if (schema.___$visited) {
  17687. return;
  17688. }
  17689. schema.___$visited = true;
  17690. visited.push(schema);
  17691. if (schema.$ref && schema.__$refResolved) {
  17692. var from = schema.__$refResolved;
  17693. var to = schema;
  17694. delete schema.$ref;
  17695. delete schema.__$refResolved;
  17696. for (key in from) {
  17697. if (from.hasOwnProperty(key)) {
  17698. to[key] = from[key];
  17699. }
  17700. }
  17701. }
  17702. for (key in schema) {
  17703. if (schema.hasOwnProperty(key)) {
  17704. if (key.indexOf("__$") === 0) {
  17705. delete schema[key];
  17706. } else {
  17707. cleanup(schema[key]);
  17708. }
  17709. }
  17710. }
  17711. };
  17712. cleanup(schema);
  17713. visited.forEach(function (s) {
  17714. delete s.___$visited;
  17715. });
  17716. this.lastReport = report;
  17717. if (report.isValid()) {
  17718. return schema;
  17719. } else {
  17720. throw this.getLastError();
  17721. }
  17722. };
  17723. /**
  17724. *
  17725. * @param {*} schemaReader
  17726. *
  17727. * @returns {void}
  17728. */
  17729. ZSchema.prototype.setSchemaReader = function (schemaReader) {
  17730. return ZSchema.setSchemaReader(schemaReader);
  17731. };
  17732. ZSchema.prototype.getSchemaReader = function () {
  17733. return ZSchema.schemaReader;
  17734. };
  17735. ZSchema.schemaReader = undefined;
  17736. /*
  17737. static methods
  17738. */
  17739. ZSchema.setSchemaReader = function (schemaReader) {
  17740. ZSchema.schemaReader = schemaReader;
  17741. };
  17742. ZSchema.registerFormat = function (formatName, validatorFunction) {
  17743. FormatValidators[formatName] = validatorFunction;
  17744. };
  17745. ZSchema.unregisterFormat = function (formatName) {
  17746. delete FormatValidators[formatName];
  17747. };
  17748. ZSchema.getRegisteredFormats = function () {
  17749. return Object.keys(FormatValidators);
  17750. };
  17751. ZSchema.getDefaultOptions = function () {
  17752. return Utils.cloneDeep(defaultOptions);
  17753. };
  17754. ZSchema.schemaSymbol = Utils.schemaSymbol;
  17755. ZSchema.jsonSymbol = Utils.jsonSymbol;
  17756. module.exports = ZSchema;
  17757. }).call(this)}).call(this,require('_process'))
  17758. },{"./FormatValidators":143,"./JsonValidation":144,"./Polyfills":145,"./Report":146,"./SchemaCache":147,"./SchemaCompilation":148,"./SchemaValidation":149,"./Utils":150,"./schemas/hyper-schema.json":152,"./schemas/schema.json":153,"_process":11,"lodash.get":9}],152:[function(require,module,exports){
  17759. module.exports={
  17760. "$schema": "http://json-schema.org/draft-04/hyper-schema#",
  17761. "id": "http://json-schema.org/draft-04/hyper-schema#",
  17762. "title": "JSON Hyper-Schema",
  17763. "allOf": [
  17764. {
  17765. "$ref": "http://json-schema.org/draft-04/schema#"
  17766. }
  17767. ],
  17768. "properties": {
  17769. "additionalItems": {
  17770. "anyOf": [
  17771. {
  17772. "type": "boolean"
  17773. },
  17774. {
  17775. "$ref": "#"
  17776. }
  17777. ]
  17778. },
  17779. "additionalProperties": {
  17780. "anyOf": [
  17781. {
  17782. "type": "boolean"
  17783. },
  17784. {
  17785. "$ref": "#"
  17786. }
  17787. ]
  17788. },
  17789. "dependencies": {
  17790. "additionalProperties": {
  17791. "anyOf": [
  17792. {
  17793. "$ref": "#"
  17794. },
  17795. {
  17796. "type": "array"
  17797. }
  17798. ]
  17799. }
  17800. },
  17801. "items": {
  17802. "anyOf": [
  17803. {
  17804. "$ref": "#"
  17805. },
  17806. {
  17807. "$ref": "#/definitions/schemaArray"
  17808. }
  17809. ]
  17810. },
  17811. "definitions": {
  17812. "additionalProperties": {
  17813. "$ref": "#"
  17814. }
  17815. },
  17816. "patternProperties": {
  17817. "additionalProperties": {
  17818. "$ref": "#"
  17819. }
  17820. },
  17821. "properties": {
  17822. "additionalProperties": {
  17823. "$ref": "#"
  17824. }
  17825. },
  17826. "allOf": {
  17827. "$ref": "#/definitions/schemaArray"
  17828. },
  17829. "anyOf": {
  17830. "$ref": "#/definitions/schemaArray"
  17831. },
  17832. "oneOf": {
  17833. "$ref": "#/definitions/schemaArray"
  17834. },
  17835. "not": {
  17836. "$ref": "#"
  17837. },
  17838. "links": {
  17839. "type": "array",
  17840. "items": {
  17841. "$ref": "#/definitions/linkDescription"
  17842. }
  17843. },
  17844. "fragmentResolution": {
  17845. "type": "string"
  17846. },
  17847. "media": {
  17848. "type": "object",
  17849. "properties": {
  17850. "type": {
  17851. "description": "A media type, as described in RFC 2046",
  17852. "type": "string"
  17853. },
  17854. "binaryEncoding": {
  17855. "description": "A content encoding scheme, as described in RFC 2045",
  17856. "type": "string"
  17857. }
  17858. }
  17859. },
  17860. "pathStart": {
  17861. "description": "Instances' URIs must start with this value for this schema to apply to them",
  17862. "type": "string",
  17863. "format": "uri"
  17864. }
  17865. },
  17866. "definitions": {
  17867. "schemaArray": {
  17868. "type": "array",
  17869. "items": {
  17870. "$ref": "#"
  17871. }
  17872. },
  17873. "linkDescription": {
  17874. "title": "Link Description Object",
  17875. "type": "object",
  17876. "required": [ "href", "rel" ],
  17877. "properties": {
  17878. "href": {
  17879. "description": "a URI template, as defined by RFC 6570, with the addition of the $, ( and ) characters for pre-processing",
  17880. "type": "string"
  17881. },
  17882. "rel": {
  17883. "description": "relation to the target resource of the link",
  17884. "type": "string"
  17885. },
  17886. "title": {
  17887. "description": "a title for the link",
  17888. "type": "string"
  17889. },
  17890. "targetSchema": {
  17891. "description": "JSON Schema describing the link target",
  17892. "$ref": "#"
  17893. },
  17894. "mediaType": {
  17895. "description": "media type (as defined by RFC 2046) describing the link target",
  17896. "type": "string"
  17897. },
  17898. "method": {
  17899. "description": "method for requesting the target of the link (e.g. for HTTP this might be \"GET\" or \"DELETE\")",
  17900. "type": "string"
  17901. },
  17902. "encType": {
  17903. "description": "The media type in which to submit data along with the request",
  17904. "type": "string",
  17905. "default": "application/json"
  17906. },
  17907. "schema": {
  17908. "description": "Schema describing the data to submit along with the request",
  17909. "$ref": "#"
  17910. }
  17911. }
  17912. }
  17913. }
  17914. }
  17915. },{}],153:[function(require,module,exports){
  17916. module.exports={
  17917. "id": "http://json-schema.org/draft-04/schema#",
  17918. "$schema": "http://json-schema.org/draft-04/schema#",
  17919. "description": "Core schema meta-schema",
  17920. "definitions": {
  17921. "schemaArray": {
  17922. "type": "array",
  17923. "minItems": 1,
  17924. "items": { "$ref": "#" }
  17925. },
  17926. "positiveInteger": {
  17927. "type": "integer",
  17928. "minimum": 0
  17929. },
  17930. "positiveIntegerDefault0": {
  17931. "allOf": [ { "$ref": "#/definitions/positiveInteger" }, { "default": 0 } ]
  17932. },
  17933. "simpleTypes": {
  17934. "enum": [ "array", "boolean", "integer", "null", "number", "object", "string" ]
  17935. },
  17936. "stringArray": {
  17937. "type": "array",
  17938. "items": { "type": "string" },
  17939. "minItems": 1,
  17940. "uniqueItems": true
  17941. }
  17942. },
  17943. "type": "object",
  17944. "properties": {
  17945. "id": {
  17946. "type": "string",
  17947. "format": "uri"
  17948. },
  17949. "$schema": {
  17950. "type": "string",
  17951. "format": "uri"
  17952. },
  17953. "title": {
  17954. "type": "string"
  17955. },
  17956. "description": {
  17957. "type": "string"
  17958. },
  17959. "default": {},
  17960. "multipleOf": {
  17961. "type": "number",
  17962. "minimum": 0,
  17963. "exclusiveMinimum": true
  17964. },
  17965. "maximum": {
  17966. "type": "number"
  17967. },
  17968. "exclusiveMaximum": {
  17969. "type": "boolean",
  17970. "default": false
  17971. },
  17972. "minimum": {
  17973. "type": "number"
  17974. },
  17975. "exclusiveMinimum": {
  17976. "type": "boolean",
  17977. "default": false
  17978. },
  17979. "maxLength": { "$ref": "#/definitions/positiveInteger" },
  17980. "minLength": { "$ref": "#/definitions/positiveIntegerDefault0" },
  17981. "pattern": {
  17982. "type": "string",
  17983. "format": "regex"
  17984. },
  17985. "additionalItems": {
  17986. "anyOf": [
  17987. { "type": "boolean" },
  17988. { "$ref": "#" }
  17989. ],
  17990. "default": {}
  17991. },
  17992. "items": {
  17993. "anyOf": [
  17994. { "$ref": "#" },
  17995. { "$ref": "#/definitions/schemaArray" }
  17996. ],
  17997. "default": {}
  17998. },
  17999. "maxItems": { "$ref": "#/definitions/positiveInteger" },
  18000. "minItems": { "$ref": "#/definitions/positiveIntegerDefault0" },
  18001. "uniqueItems": {
  18002. "type": "boolean",
  18003. "default": false
  18004. },
  18005. "maxProperties": { "$ref": "#/definitions/positiveInteger" },
  18006. "minProperties": { "$ref": "#/definitions/positiveIntegerDefault0" },
  18007. "required": { "$ref": "#/definitions/stringArray" },
  18008. "additionalProperties": {
  18009. "anyOf": [
  18010. { "type": "boolean" },
  18011. { "$ref": "#" }
  18012. ],
  18013. "default": {}
  18014. },
  18015. "definitions": {
  18016. "type": "object",
  18017. "additionalProperties": { "$ref": "#" },
  18018. "default": {}
  18019. },
  18020. "properties": {
  18021. "type": "object",
  18022. "additionalProperties": { "$ref": "#" },
  18023. "default": {}
  18024. },
  18025. "patternProperties": {
  18026. "type": "object",
  18027. "additionalProperties": { "$ref": "#" },
  18028. "default": {}
  18029. },
  18030. "dependencies": {
  18031. "type": "object",
  18032. "additionalProperties": {
  18033. "anyOf": [
  18034. { "$ref": "#" },
  18035. { "$ref": "#/definitions/stringArray" }
  18036. ]
  18037. }
  18038. },
  18039. "enum": {
  18040. "type": "array",
  18041. "minItems": 1,
  18042. "uniqueItems": true
  18043. },
  18044. "type": {
  18045. "anyOf": [
  18046. { "$ref": "#/definitions/simpleTypes" },
  18047. {
  18048. "type": "array",
  18049. "items": { "$ref": "#/definitions/simpleTypes" },
  18050. "minItems": 1,
  18051. "uniqueItems": true
  18052. }
  18053. ]
  18054. },
  18055. "format": { "type": "string" },
  18056. "allOf": { "$ref": "#/definitions/schemaArray" },
  18057. "anyOf": { "$ref": "#/definitions/schemaArray" },
  18058. "oneOf": { "$ref": "#/definitions/schemaArray" },
  18059. "not": { "$ref": "#" }
  18060. },
  18061. "dependencies": {
  18062. "exclusiveMaximum": [ "maximum" ],
  18063. "exclusiveMinimum": [ "minimum" ]
  18064. },
  18065. "default": {}
  18066. }
  18067. },{}],154:[function(require,module,exports){
  18068. "use strict";
  18069. module.exports = {
  18070. description: "assumeAdditional - Assume additional properties/items in schemas are defined to false",
  18071. options: {
  18072. assumeAdditional: true
  18073. },
  18074. tests: [
  18075. {
  18076. schema: {
  18077. "type": "object",
  18078. "properties": {
  18079. "hello": {
  18080. "type": "string"
  18081. }
  18082. }
  18083. },
  18084. data: {
  18085. hello: "world"
  18086. },
  18087. description: "should pass validation when only defined properties are used",
  18088. valid: true
  18089. },
  18090. {
  18091. schema: {
  18092. "type": "object",
  18093. "properties": {
  18094. "hello": {
  18095. "type": "string"
  18096. }
  18097. }
  18098. },
  18099. data: {
  18100. hello: "world",
  18101. good: "morning"
  18102. },
  18103. description: "should fail validation when other than defined properties are used",
  18104. valid: false
  18105. },
  18106. {
  18107. schema: {
  18108. "type": "object",
  18109. "properties": {
  18110. "hello": {
  18111. "type": "string"
  18112. }
  18113. }
  18114. },
  18115. data: {
  18116. hello: "world",
  18117. good: "morning",
  18118. night: "night"
  18119. },
  18120. description: "should fail validation with multiple errors when several other than defined properties are used",
  18121. valid: false,
  18122. after: function(errs) {
  18123. expect(errs.length).toBe(2);
  18124. expect(errs[0].message).toBe('Additional properties not allowed: good');
  18125. expect(errs[1].message).toBe('Additional properties not allowed: night');
  18126. }
  18127. },
  18128. {
  18129. schema: {
  18130. "type": "array",
  18131. "items": [
  18132. { "type": "string" },
  18133. { "type": "string" },
  18134. { "type": "string" }
  18135. ]
  18136. },
  18137. data: [
  18138. "aaa",
  18139. "bbb",
  18140. "ccc"
  18141. ],
  18142. description: "should pass validation when only allowed items are used",
  18143. valid: true
  18144. },
  18145. {
  18146. schema: {
  18147. "type": "array",
  18148. "items": [
  18149. { "type": "string" },
  18150. { "type": "string" },
  18151. { "type": "string" }
  18152. ]
  18153. },
  18154. data: [
  18155. "aaa",
  18156. "bbb",
  18157. "ccc",
  18158. null
  18159. ],
  18160. description: "should fail validation when other than allowed items are used",
  18161. valid: false
  18162. }
  18163. ]
  18164. };
  18165. },{}],155:[function(require,module,exports){
  18166. "use strict";
  18167. module.exports = {
  18168. description: "registerFormat - Custom formats support",
  18169. setup: function (validator, Class) {
  18170. Class.registerFormat("xstring", function (str) {
  18171. return str === "xxx";
  18172. });
  18173. Class.registerFormat("emptystring", function (str) {
  18174. return typeof str === "string" && str.length === 0 && str === "";
  18175. });
  18176. Class.registerFormat("fillHello", function (obj) {
  18177. obj.hello = "world";
  18178. return true;
  18179. });
  18180. },
  18181. schema: {
  18182. "type": "string",
  18183. "format": "xstring"
  18184. },
  18185. tests: [
  18186. {
  18187. description: "should pass custom format validation",
  18188. data: "xxx",
  18189. valid: true
  18190. },
  18191. {
  18192. description: "should fail custom format validation",
  18193. data: "xxxx",
  18194. valid: false
  18195. },
  18196. {
  18197. description: "should fail when using unknown format",
  18198. data: "xxx",
  18199. schema: {
  18200. "type": "string",
  18201. "format": "xstring2"
  18202. },
  18203. valid: false
  18204. },
  18205. {
  18206. description: "should pass validating empty string",
  18207. data: "",
  18208. schema: {
  18209. "type": "string",
  18210. "format": "emptystring"
  18211. },
  18212. valid: true
  18213. },
  18214. {
  18215. description: "should be able to modify object using format",
  18216. data: {},
  18217. schema: {
  18218. "type": "object",
  18219. "format": "fillHello"
  18220. },
  18221. valid: true,
  18222. after: function (err, valid, obj) {
  18223. expect(obj.hello).toBe("world");
  18224. }
  18225. }
  18226. ]
  18227. };
  18228. },{}],156:[function(require,module,exports){
  18229. "use strict";
  18230. module.exports = {
  18231. description: "registerFormat - Custom formats async support",
  18232. async: true,
  18233. options: {
  18234. asyncTimeout: 500
  18235. },
  18236. setup: function (validator, Class) {
  18237. Class.registerFormat("xstring", function (str, callback) {
  18238. setTimeout(function () {
  18239. callback(str === "xxx");
  18240. }, 1);
  18241. });
  18242. Class.registerFormat("shouldTimeout", function (str, callback) {
  18243. return typeof callback === "function";
  18244. });
  18245. },
  18246. schema: {
  18247. "type": "string",
  18248. "format": "xstring"
  18249. },
  18250. tests: [
  18251. {
  18252. description: "should pass custom format async validation",
  18253. data: "xxx",
  18254. valid: true
  18255. },
  18256. {
  18257. description: "should fail custom format async validation",
  18258. data: "xxxx",
  18259. valid: false
  18260. },
  18261. {
  18262. description: "should timeout if callback is not called in default limit",
  18263. data: "xxx",
  18264. schema: {
  18265. "type": "string",
  18266. "format": "shouldTimeout"
  18267. },
  18268. valid: false,
  18269. after: function (err, valid) {
  18270. expect(valid).toBe(false);
  18271. expect(err.length).toBe(1);
  18272. expect(err[0].code).toBe("ASYNC_TIMEOUT");
  18273. }
  18274. },
  18275. {
  18276. description: "should execute callback even if no async format is found",
  18277. data: "xxx",
  18278. schema: {
  18279. "type": "string"
  18280. },
  18281. valid: true
  18282. }
  18283. ]
  18284. };
  18285. },{}],157:[function(require,module,exports){
  18286. "use strict";
  18287. //Implement new 'shouldFail' keyword
  18288. function customValidatorFn(report, schema, json) {
  18289. if (schema.shouldFail === true) {
  18290. report.addCustomError("SHOULD_FAIL", "Forced fail", [], null, schema.description);
  18291. }
  18292. }
  18293. module.exports = {
  18294. description: "customValidator - Function to be called on every schema",
  18295. options: {
  18296. customValidator: customValidatorFn
  18297. },
  18298. schema: {
  18299. "type": "object",
  18300. "properties": {
  18301. "a": {
  18302. "type": "integer"
  18303. },
  18304. "b": {
  18305. shouldFail: false
  18306. }
  18307. },
  18308. "additionalProperties": {
  18309. shouldFail: true
  18310. }
  18311. },
  18312. tests: [
  18313. {
  18314. description: "should pass custom validation",
  18315. data: {
  18316. a: 0,
  18317. b: null
  18318. },
  18319. valid: true
  18320. },
  18321. {
  18322. description: "should fail on standard error",
  18323. data: {
  18324. a: "incorrect type",
  18325. b: null
  18326. },
  18327. valid: false,
  18328. after: function (err) {
  18329. expect(err[0].code).toBe("INVALID_TYPE");
  18330. }
  18331. },
  18332. {
  18333. description: "should fail on custom error",
  18334. data: {
  18335. c: null
  18336. },
  18337. valid: false,
  18338. after: function (err) {
  18339. expect(err[0].code).toBe("SHOULD_FAIL");
  18340. expect(err[0].message).toBe("Forced fail");
  18341. }
  18342. }
  18343. ]
  18344. };
  18345. },{}],158:[function(require,module,exports){
  18346. "use strict";
  18347. module.exports = {
  18348. description: "reportPathAsArray - Report error paths as an array of path segments",
  18349. options: {
  18350. reportPathAsArray: true
  18351. },
  18352. tests: [
  18353. {
  18354. description: "should fail validation and report error paths as an array of path segments",
  18355. schema: {
  18356. "type": "object",
  18357. "properties": {
  18358. "name": {
  18359. "type": "invalid"
  18360. }
  18361. }
  18362. },
  18363. valid: false,
  18364. validateSchemaOnly: true,
  18365. after: function (err) {
  18366. expect(err[0].path).toEqual(["properties", "name"]);
  18367. }
  18368. }
  18369. ]
  18370. };
  18371. },{}],159:[function(require,module,exports){
  18372. "use strict";
  18373. module.exports = {
  18374. description: "Report error paths as a JSON Pointer string",
  18375. tests: [
  18376. {
  18377. description: "should fail validation and report error paths a JSON Pointer string",
  18378. schema: {
  18379. "type": "object",
  18380. "properties": {
  18381. "~name/age": {
  18382. "type": "invalid"
  18383. }
  18384. }
  18385. },
  18386. valid: false,
  18387. validateSchemaOnly: true,
  18388. after: function (err) {
  18389. expect(err[0].path).toEqual("#/properties/~0name~1age");
  18390. }
  18391. }
  18392. ]
  18393. };
  18394. },{}],160:[function(require,module,exports){
  18395. "use strict";
  18396. module.exports = {
  18397. description: "Report error paths with integer array indices",
  18398. options: {
  18399. reportPathAsArray: true
  18400. },
  18401. tests: [
  18402. {
  18403. description: "should fail validation and error path should contain integer array index",
  18404. schema: {
  18405. "type": "object",
  18406. "properties": {
  18407. "list": {
  18408. "type": "array",
  18409. "items": {
  18410. "type": "string"
  18411. }
  18412. }
  18413. }
  18414. },
  18415. data: {
  18416. "list": [
  18417. 123
  18418. ]
  18419. },
  18420. valid: false,
  18421. validateSchemaOnly: false,
  18422. after: function (err) {
  18423. expect(err[0].path).toEqual(["list", 0]);
  18424. }
  18425. }
  18426. ]
  18427. };
  18428. },{}],161:[function(require,module,exports){
  18429. "use strict";
  18430. module.exports = {
  18431. description: "forceAdditional - Force additional properties/items in schemas",
  18432. options: {
  18433. forceAdditional: true
  18434. },
  18435. validateSchemaOnly: true,
  18436. tests: [
  18437. {
  18438. schema: {
  18439. "type": "object",
  18440. "properties": {
  18441. "hello": {
  18442. "type": "string"
  18443. }
  18444. },
  18445. "additionalProperties": false
  18446. },
  18447. description: "should pass schema validation when additionalProperties are defined on objects",
  18448. valid: true
  18449. },
  18450. {
  18451. schema: {
  18452. "type": "object",
  18453. "properties": {
  18454. "hello": {
  18455. "type": "string"
  18456. }
  18457. }
  18458. },
  18459. description: "should fail schema validation when additionalProperties are not defined on objects",
  18460. valid: false
  18461. },
  18462. {
  18463. schema: {
  18464. "type": "array",
  18465. "items": [
  18466. {
  18467. "type": "string"
  18468. }
  18469. ],
  18470. "additionalItems": false
  18471. },
  18472. description: "should pass schema validation when additionalItems are defined on arrays",
  18473. valid: true
  18474. },
  18475. {
  18476. schema: {
  18477. "type": "array",
  18478. "items": [
  18479. {
  18480. "type": "string"
  18481. }
  18482. ]
  18483. },
  18484. description: "should fail schema validation when additionalItems are not defined on arrays",
  18485. valid: false
  18486. },
  18487. {
  18488. schema: {
  18489. "type": "array",
  18490. "items": {
  18491. "type": "string"
  18492. }
  18493. },
  18494. description: "should pass schema validation without additionalItems because they doesn't matter when items is a schema",
  18495. valid: true
  18496. }
  18497. ]
  18498. };
  18499. },{}],162:[function(require,module,exports){
  18500. "use strict";
  18501. module.exports = {
  18502. description: "forceItems - Force items to be defined on arrays",
  18503. options: {
  18504. forceItems: true
  18505. },
  18506. validateSchemaOnly: true,
  18507. tests: [
  18508. {
  18509. schema: {
  18510. "type": "array",
  18511. "items": {}
  18512. },
  18513. description: "should pass schema validation because items are defined",
  18514. valid: true
  18515. },
  18516. {
  18517. schema: {
  18518. "type": "array"
  18519. },
  18520. description: "should fail schema validation because items are not defined",
  18521. valid: false
  18522. }
  18523. ]
  18524. };
  18525. },{}],163:[function(require,module,exports){
  18526. "use strict";
  18527. module.exports = {
  18528. description: "forceMaxItems - Force maxItems to be defined on arrays",
  18529. options: {
  18530. forceMaxItems: true
  18531. },
  18532. validateSchemaOnly: true,
  18533. tests: [
  18534. {
  18535. schema: {
  18536. "type": "array",
  18537. "maxItems": 20
  18538. },
  18539. description: "should pass schema validation because maxItems is defined",
  18540. valid: true
  18541. },
  18542. {
  18543. schema: {
  18544. "type": "array"
  18545. },
  18546. description: "should fail schema validation because maxItems is not defined",
  18547. valid: false
  18548. }
  18549. ]
  18550. };
  18551. },{}],164:[function(require,module,exports){
  18552. "use strict";
  18553. module.exports = {
  18554. description: "forceMaxLength - Force maxLength to be defined on strings",
  18555. options: {
  18556. forceMaxLength: true
  18557. },
  18558. validateSchemaOnly: true,
  18559. tests: [
  18560. {
  18561. schema: {
  18562. "type": "string",
  18563. "maxLength": 20
  18564. },
  18565. description: "should pass schema validation because maxLength is defined",
  18566. valid: true
  18567. },
  18568. {
  18569. schema: {
  18570. "type": "string"
  18571. },
  18572. description: "should fail schema validation because maxLength is not defined",
  18573. valid: false
  18574. }
  18575. ]
  18576. };
  18577. },{}],165:[function(require,module,exports){
  18578. "use strict";
  18579. module.exports = {
  18580. description: "forceMinItems - Force minItems to be defined on arrays",
  18581. options: {
  18582. forceMinItems: true
  18583. },
  18584. validateSchemaOnly: true,
  18585. tests: [
  18586. {
  18587. schema: {
  18588. "type": "array",
  18589. "minItems": 20
  18590. },
  18591. description: "should pass schema validation because minItems is defined",
  18592. valid: true
  18593. },
  18594. {
  18595. schema: {
  18596. "type": "array"
  18597. },
  18598. description: "should fail schema validation because minItems is not defined",
  18599. valid: false
  18600. }
  18601. ]
  18602. };
  18603. },{}],166:[function(require,module,exports){
  18604. "use strict";
  18605. module.exports = {
  18606. description: "forceMinLength - Force minLength to be defined on strings",
  18607. options: {
  18608. forceMinLength: true
  18609. },
  18610. validateSchemaOnly: true,
  18611. tests: [
  18612. {
  18613. schema: {
  18614. "type": "string",
  18615. "minLength": 20
  18616. },
  18617. description: "should pass schema validation because minLength is defined",
  18618. valid: true
  18619. },
  18620. {
  18621. schema: {
  18622. "type": "string"
  18623. },
  18624. description: "should fail schema validation because minLength is not defined",
  18625. valid: false
  18626. }
  18627. ]
  18628. };
  18629. },{}],167:[function(require,module,exports){
  18630. "use strict";
  18631. module.exports = {
  18632. description: "forceProperties - Force properties to be defined on objects",
  18633. options: {
  18634. forceProperties: true
  18635. },
  18636. validateSchemaOnly: true,
  18637. tests: [
  18638. {
  18639. schema: {
  18640. "type": "object",
  18641. "properties": {
  18642. "test": {}
  18643. }
  18644. },
  18645. description: "should pass schema validation because properties are defined",
  18646. valid: true
  18647. },
  18648. {
  18649. schema: {
  18650. "type": "object",
  18651. "patternProperties": {
  18652. "te(s|t)": {}
  18653. }
  18654. },
  18655. description: "should pass schema validation because patternProperties are defined",
  18656. valid: true
  18657. },
  18658. {
  18659. schema: {
  18660. "type": "object"
  18661. },
  18662. description: "should fail schema validation because properties are not defined",
  18663. valid: false
  18664. },
  18665. {
  18666. schema: {
  18667. "type": "object",
  18668. "properties": {}
  18669. },
  18670. description: "should fail schema validation because properties are present but doesn't define any properties",
  18671. valid: false
  18672. },
  18673. {
  18674. schema: {
  18675. "type": "object",
  18676. "patternProperties": {}
  18677. },
  18678. description: "should fail schema validation because patternProperties are present but doesn't define any properties",
  18679. valid: false
  18680. }
  18681. ]
  18682. };
  18683. },{}],168:[function(require,module,exports){
  18684. "use strict";
  18685. module.exports = {
  18686. description: "ignoreUnresolvableReferences - Ignore remote references in schemas",
  18687. options: {
  18688. ignoreUnresolvableReferences: true
  18689. },
  18690. validateSchemaOnly: true,
  18691. tests: [
  18692. {
  18693. schema: {
  18694. "$schema": "http://doesnt-exists.org/draft-04/schema",
  18695. },
  18696. description: "should pass schema validation because link is to http schema",
  18697. valid: true
  18698. },
  18699. {
  18700. schema: {
  18701. "definitions": {
  18702. "a": {"type": "integer"},
  18703. "b": {"$ref": "#/definitions/a"},
  18704. "c": {"$ref": "#/definitions/b"}
  18705. },
  18706. "$ref": "#/definitions/c"
  18707. },
  18708. description: "should pass schema validation because definitions are resolvable",
  18709. valid: true
  18710. },
  18711. {
  18712. schema: {
  18713. "definitions": {
  18714. "a": {"type": "integer"},
  18715. "b": {"$ref": "#/definitions/aaa"},
  18716. "c": {"$ref": "#/definitions/b"}
  18717. },
  18718. "$ref": "#/definitions/c"
  18719. },
  18720. description: "should fail schema validation because definitions are not resolvable",
  18721. valid: false
  18722. }
  18723. ]
  18724. };
  18725. },{}],169:[function(require,module,exports){
  18726. "use strict";
  18727. module.exports = {
  18728. description: "includeErrors - Validate only against specified errors",
  18729. options: {
  18730. breakOnFirstError: false,
  18731. assumeAdditional: true
  18732. },
  18733. tests: [
  18734. {
  18735. schema: {
  18736. "type": "object",
  18737. "properties": {
  18738. "hello": {
  18739. "type": "number"
  18740. }
  18741. }
  18742. },
  18743. data: {
  18744. hello: "world"
  18745. },
  18746. validateOptions: {
  18747. includeErrors: ["INVALID_TYPE"]
  18748. },
  18749. description: "should fail validation when the specified error is present",
  18750. valid: false
  18751. },
  18752. {
  18753. schema: {
  18754. "type": "object",
  18755. "properties": {
  18756. "hello": {
  18757. "type": "number"
  18758. }
  18759. }
  18760. },
  18761. data: {
  18762. hello: "world"
  18763. },
  18764. validateOptions: {
  18765. includeErrors: ["OBJECT_ADDITIONAL_PROPERTIES"]
  18766. },
  18767. description: "should pass validation when the specified error is not present",
  18768. valid: true
  18769. },
  18770. {
  18771. schema: {
  18772. "type": "object",
  18773. "properties": {
  18774. "hello": {
  18775. "type": "number"
  18776. }
  18777. }
  18778. },
  18779. data: {
  18780. hello: "world",
  18781. extra: "extra"
  18782. },
  18783. validateOptions: {
  18784. includeErrors: ["INVALID_TYPE"]
  18785. },
  18786. description: "should fail validation when the specified error is present only for that error",
  18787. valid: false,
  18788. after: function(errs) {
  18789. expect(errs.length).toBe(1);
  18790. expect(errs[0].code).toBe("INVALID_TYPE");
  18791. }
  18792. },
  18793. {
  18794. schema: {
  18795. "type": "object",
  18796. "properties": {
  18797. "hello": {
  18798. "type": "number"
  18799. }
  18800. }
  18801. },
  18802. data: {
  18803. hello: "world",
  18804. extra: "extra"
  18805. },
  18806. description: "should fail validation for all errors when no `includeErrors` array is provided.",
  18807. valid: false,
  18808. after: function(errs) {
  18809. expect(errs.length).toBe(2);
  18810. }
  18811. },
  18812. {
  18813. schema: {
  18814. "type": "object",
  18815. "properties": {
  18816. "hello": {
  18817. "type": "number"
  18818. }
  18819. }
  18820. },
  18821. data: {
  18822. hello: "world",
  18823. extra: "extra"
  18824. },
  18825. validateOptions: {
  18826. includeErrors: []
  18827. },
  18828. description: "should fail validation for all errors when empty array is provided.",
  18829. valid: false,
  18830. after: function(errs) {
  18831. expect(errs.length).toBe(2);
  18832. }
  18833. }
  18834. ]
  18835. };
  18836. },{}],170:[function(require,module,exports){
  18837. "use strict";
  18838. module.exports = {
  18839. description: "InvalidId - check if schema with invalid id can be processed",
  18840. validateSchemaOnly: true,
  18841. tests: [
  18842. {
  18843. schema: {
  18844. "id": {}
  18845. },
  18846. description: "should fail schema validation because id has incorrect value",
  18847. valid: false
  18848. }
  18849. ]
  18850. };
  18851. },{}],171:[function(require,module,exports){
  18852. "use strict";
  18853. module.exports = {
  18854. description: "Issue #101 - Cannot read property '__$compiled' of undefined",
  18855. async: true,
  18856. options: {
  18857. asyncTimeout: 500
  18858. },
  18859. schema: null,
  18860. tests: [
  18861. {
  18862. description: "should fail with correct error",
  18863. data: null,
  18864. valid: false,
  18865. after: function (err) {
  18866. expect(err.message).toBe("Invalid .validate call - schema must be a string or object but null was passed!");
  18867. }
  18868. }
  18869. ]
  18870. };
  18871. },{}],172:[function(require,module,exports){
  18872. "use strict";
  18873. module.exports = {
  18874. description: "Issue #102 - circular references",
  18875. tests: [
  18876. {
  18877. description: "should pass without an error",
  18878. schema: {},
  18879. data: {},
  18880. valid: true,
  18881. after: function (err, valid, data, validator) {
  18882. var resolvedSchema = validator.getResolvedSchema("http://json-schema.org/draft-04/schema#");
  18883. }
  18884. }
  18885. ]
  18886. };
  18887. },{}],173:[function(require,module,exports){
  18888. "use strict";
  18889. module.exports = {
  18890. description: "Issue #103 - Validate async fails silently",
  18891. options: {
  18892. asyncTimeout: 500
  18893. },
  18894. schema: {
  18895. required: ["recType", "luValue"],
  18896. properties: {
  18897. luValue: {
  18898. type: "string"
  18899. },
  18900. useAsIs: {
  18901. type: "integer"
  18902. },
  18903. valueText: {
  18904. type: "string"
  18905. },
  18906. sequence: {
  18907. type: "integer",
  18908. minimum: 0
  18909. },
  18910. description: {
  18911. type: "string"
  18912. },
  18913. valueInt: {
  18914. type: "integer"
  18915. },
  18916. recType: {
  18917. type: "string",
  18918. enum: []
  18919. },
  18920. recProps: {
  18921. type: "object",
  18922. properties: {},
  18923. additionalProperties: false
  18924. },
  18925. control: {
  18926. "$ref": "control"
  18927. }
  18928. },
  18929. additionalProperties: false,
  18930. type: "object",
  18931. title: "lookup schema for bankCodeType"
  18932. },
  18933. tests: [
  18934. {
  18935. async: false,
  18936. description: "should fail with correct error - sync",
  18937. validateSchemaOnly: true,
  18938. valid: false,
  18939. after: function (errs) {
  18940. expect(errs.length).toBe(1);
  18941. }
  18942. },
  18943. {
  18944. async: true,
  18945. description: "should fail with correct error - async",
  18946. validateSchemaOnly: true,
  18947. valid: false,
  18948. after: function (errs) {
  18949. expect(errs.length).toBe(1);
  18950. }
  18951. }
  18952. ]
  18953. };
  18954. },{}],174:[function(require,module,exports){
  18955. "use strict";
  18956. module.exports = {
  18957. description: "Issue #106 - validateSchema method returns true if you pass an empty array",
  18958. tests: [
  18959. {
  18960. description: "should fail with an error",
  18961. schema: [],
  18962. validateSchemaOnly: true,
  18963. failWithException: true
  18964. }
  18965. ]
  18966. };
  18967. },{}],175:[function(require,module,exports){
  18968. "use strict";
  18969. module.exports = {
  18970. description: "Issue #107 - add Support for Controlling Remote Schema Reading",
  18971. setup: function (validator, ZSchema) {
  18972. ZSchema.setSchemaReader(function (uri) {
  18973. return {
  18974. type: "string"
  18975. };
  18976. });
  18977. },
  18978. tests: [
  18979. {
  18980. description: "should pass validation",
  18981. schema: {
  18982. "$ref": "schema-1"
  18983. },
  18984. data: "i'm a string",
  18985. valid: true
  18986. }
  18987. ]
  18988. };
  18989. },{}],176:[function(require,module,exports){
  18990. "use strict";
  18991. module.exports = {
  18992. description: "Issue #12 - validation should fail when missing a reference",
  18993. tests: [
  18994. {
  18995. description: "should pass validation",
  18996. schema: {
  18997. "id": "http://my.site/myschema#",
  18998. "$ref": "#/definitions/schema2",
  18999. "definitions": {
  19000. "schema1": {
  19001. "id": "schema1",
  19002. "type": "integer"
  19003. },
  19004. "schema2": {
  19005. "type": "array",
  19006. "items": {
  19007. "$ref": "schema1"
  19008. }
  19009. }
  19010. }
  19011. },
  19012. data: [1, 2, 3],
  19013. valid: true
  19014. },
  19015. {
  19016. description: "should fail validation",
  19017. schema: {
  19018. "id": "http://my.site/myschema#",
  19019. "$ref": "#/definitions/schema2",
  19020. "definitions": {
  19021. "schema1": {
  19022. "id": "schema1",
  19023. "type": "integer"
  19024. },
  19025. "schema2": {
  19026. "type": "array",
  19027. "items": {
  19028. "$ref": "schema1"
  19029. }
  19030. }
  19031. }
  19032. },
  19033. data: ["1", null, 3],
  19034. valid: false
  19035. },
  19036. {
  19037. description: "should fail compilation with unresolvable reference",
  19038. schema: {
  19039. id: "schemaA",
  19040. type: "object",
  19041. properties: {
  19042. a: {
  19043. type: "integer"
  19044. },
  19045. b: {
  19046. type: "string"
  19047. },
  19048. c: {
  19049. $ref: "schemaB"
  19050. }
  19051. },
  19052. required: ["a"]
  19053. },
  19054. validateSchemaOnly: true,
  19055. valid: false,
  19056. after: function (err) {
  19057. expect(err[0].code).toBe("UNRESOLVABLE_REFERENCE");
  19058. }
  19059. }
  19060. ]
  19061. };
  19062. },{}],177:[function(require,module,exports){
  19063. "use strict";
  19064. module.exports = {
  19065. description: "Issue #121 - ignoreUnknownFormats",
  19066. options: {
  19067. ignoreUnknownFormats: true
  19068. },
  19069. tests: [
  19070. {
  19071. description: "should not fail when ignoring unknown formats",
  19072. schema: {
  19073. type: "string",
  19074. format: "unknown"
  19075. },
  19076. valid: true,
  19077. validateSchemaOnly: true
  19078. }
  19079. ]
  19080. };
  19081. },{}],178:[function(require,module,exports){
  19082. "use strict";
  19083. var REF_NAME = "int.json";
  19084. module.exports = {
  19085. description: "Issue #126 - do not add UNRESOLVABLE_REFERENCE error when set through setRemoteReference",
  19086. tests: [
  19087. {
  19088. description: "should fail compilation with unresolvable reference",
  19089. setup: function (validator) {
  19090. validator.setRemoteReference(REF_NAME, {
  19091. "$schema": "http://json-schema.org/draft-04/schema#",
  19092. "id": REF_NAME,
  19093. "type": "object",
  19094. "required": [
  19095. "number"
  19096. ],
  19097. "properties": {
  19098. "number": {
  19099. "$ref": "data-types.json#/definitions/number"
  19100. }
  19101. }
  19102. });
  19103. },
  19104. schema: {
  19105. "$schema": "http://json-schema.org/draft-04/schema#",
  19106. "id": "ints.json",
  19107. "type": "array",
  19108. "items": {
  19109. "$ref": REF_NAME
  19110. }
  19111. },
  19112. validateSchemaOnly: true,
  19113. valid: false,
  19114. after: function (err, valid, data, validator) {
  19115. err.forEach(function (e) {
  19116. if (e.params.indexOf(REF_NAME) !== -1) {
  19117. expect(e.code).not.toBe("UNRESOLVABLE_REFERENCE");
  19118. }
  19119. });
  19120. expect(validator.getMissingRemoteReferences().length).toBe(1);
  19121. }
  19122. }
  19123. ]
  19124. };
  19125. },{}],179:[function(require,module,exports){
  19126. "use strict";
  19127. module.exports = {
  19128. description: "Issue #13 - compile multiple schemas tied together with an id",
  19129. tests: [
  19130. {
  19131. description: "mainSchema should fail compilation on its own",
  19132. schema: {
  19133. id: "mainSchema",
  19134. type: "object",
  19135. properties: {
  19136. a: {"$ref": "schemaA"},
  19137. b: {"$ref": "schemaB"},
  19138. c: {"enum": ["C"]}
  19139. }
  19140. },
  19141. validateSchemaOnly: true,
  19142. valid: false
  19143. },
  19144. {
  19145. description: "mainSchema should pass compilation if schemaA and schemaB were already compiled, order #1",
  19146. schema: [
  19147. {
  19148. id: "schemaA",
  19149. type: "integer"
  19150. },
  19151. {
  19152. id: "schemaB",
  19153. type: "string"
  19154. },
  19155. {
  19156. id: "mainSchema",
  19157. type: "object",
  19158. properties: {
  19159. a: {"$ref": "schemaA"},
  19160. b: {"$ref": "schemaB"},
  19161. c: {"enum": ["C"]}
  19162. }
  19163. }
  19164. ],
  19165. validateSchemaOnly: true,
  19166. valid: true
  19167. },
  19168. {
  19169. description: "mainSchema should pass compilation if schemaA and schemaB were already compiled, order #2",
  19170. schema: [
  19171. {
  19172. id: "mainSchema",
  19173. type: "object",
  19174. properties: {
  19175. a: {"$ref": "schemaA"},
  19176. b: {"$ref": "schemaB"},
  19177. c: {"enum": ["C"]}
  19178. }
  19179. },
  19180. {
  19181. id: "schemaA",
  19182. type: "integer"
  19183. },
  19184. {
  19185. id: "schemaB",
  19186. type: "string"
  19187. }
  19188. ],
  19189. validateSchemaOnly: true,
  19190. valid: true
  19191. },
  19192. {
  19193. description: "compilation should never end up in infinite loop #1",
  19194. schema: [
  19195. {
  19196. id: "mainSchema",
  19197. type: "object",
  19198. properties: {
  19199. a: {"$ref": "schemaA"},
  19200. b: {"$ref": "schemaB"},
  19201. c: {"enum": ["C"]}
  19202. }
  19203. },
  19204. {
  19205. id: "schemaB",
  19206. type: "string"
  19207. }
  19208. ],
  19209. validateSchemaOnly: true,
  19210. valid: false
  19211. },
  19212. {
  19213. description: "compilation should never end up in infinite loop #2",
  19214. schema: [
  19215. {
  19216. id: "schemaB",
  19217. type: "string"
  19218. },
  19219. {
  19220. id: "mainSchema",
  19221. type: "object",
  19222. properties: {
  19223. a: {"$ref": "schemaA"},
  19224. b: {"$ref": "schemaB"},
  19225. c: {"enum": ["C"]}
  19226. }
  19227. }
  19228. ],
  19229. validateSchemaOnly: true,
  19230. valid: false
  19231. },
  19232. {
  19233. description: "should validate object successfully",
  19234. schema: [
  19235. {
  19236. id: "schemaA",
  19237. type: "integer"
  19238. },
  19239. {
  19240. id: "schemaB",
  19241. type: "string"
  19242. },
  19243. {
  19244. id: "mainSchema",
  19245. type: "object",
  19246. properties: {
  19247. a: {"$ref": "schemaA"},
  19248. b: {"$ref": "schemaB"},
  19249. c: {"enum": ["C"]}
  19250. }
  19251. }
  19252. ],
  19253. schemaIndex: 2,
  19254. data: {
  19255. a: 1,
  19256. b: "str",
  19257. c: "C"
  19258. },
  19259. valid: true
  19260. },
  19261. {
  19262. description: "should fail validating object",
  19263. schema: [
  19264. {
  19265. id: "schemaA",
  19266. type: "integer"
  19267. },
  19268. {
  19269. id: "schemaB",
  19270. type: "string"
  19271. },
  19272. {
  19273. id: "mainSchema",
  19274. type: "object",
  19275. properties: {
  19276. a: {"$ref": "schemaA"},
  19277. b: {"$ref": "schemaB"},
  19278. c: {"enum": ["C"]}
  19279. }
  19280. }
  19281. ],
  19282. schemaIndex: 2,
  19283. data: {
  19284. a: "str",
  19285. b: 1,
  19286. c: "C"
  19287. },
  19288. valid: false,
  19289. after: function (err) {
  19290. expect(err[0].code).toBe("INVALID_TYPE");
  19291. expect(err[1].code).toBe("INVALID_TYPE");
  19292. }
  19293. }
  19294. ]
  19295. };
  19296. },{}],180:[function(require,module,exports){
  19297. "use strict";
  19298. module.exports = {
  19299. description: "Issue #130 - Improve escaping of slashes in path",
  19300. tests: [
  19301. {
  19302. description: "should pass",
  19303. schema: {
  19304. "$schema": "http://json-schema.org/draft-04/schema#",
  19305. "title": "Schema to test names that would otherwise conflict with the path handling",
  19306. "type": "object",
  19307. "properties": {
  19308. "this/that": {
  19309. "type": "object",
  19310. "properties": {
  19311. "t/h/e/ /o/t/h/e/r": {
  19312. "type": "object",
  19313. "properties": {
  19314. "man": {
  19315. "type": "string"
  19316. }
  19317. },
  19318. "required": ["man"]
  19319. }
  19320. },
  19321. "required": ["t/h/e/ /o/t/h/e/r"]
  19322. }
  19323. }
  19324. },
  19325. data: {
  19326. "this/that": {
  19327. "t/h/e/ /o/t/h/e/r": {}
  19328. }
  19329. },
  19330. valid: false,
  19331. after: function (err) {
  19332. err.forEach(function (e) {
  19333. expect(e.path).toBe("#/this~1that/t~1h~1e~1 ~1o~1t~1h~1e~1r");
  19334. });
  19335. }
  19336. }
  19337. ]
  19338. };
  19339. },{}],181:[function(require,module,exports){
  19340. "use strict";
  19341. module.exports = {
  19342. description: "Issue #131 - Top-level errors obscure deeper errors",
  19343. tests: [
  19344. {
  19345. description: "should pass",
  19346. options: {
  19347. breakOnFirstError: false
  19348. },
  19349. schema: {
  19350. "title": "Nested requirements don't work",
  19351. "type": "object",
  19352. "properties": {
  19353. "required": {
  19354. "type": "string"
  19355. },
  19356. "nested": {
  19357. "type": "object",
  19358. "properties": {
  19359. "required": {
  19360. "type": "string"
  19361. }
  19362. },
  19363. "required": ["required"]
  19364. }
  19365. },
  19366. "required" : ["required"]
  19367. },
  19368. data: { "nested": { } },
  19369. valid: false,
  19370. after: function (err) {
  19371. expect(err.length).toBe(2);
  19372. if (err.length === 2) {
  19373. expect(err[0].code).toBe("OBJECT_MISSING_REQUIRED_PROPERTY");
  19374. expect(err[1].code).toBe("OBJECT_MISSING_REQUIRED_PROPERTY");
  19375. }
  19376. }
  19377. }
  19378. ]
  19379. };
  19380. },{}],182:[function(require,module,exports){
  19381. "use strict";
  19382. var schema1 = {
  19383. "definitions": {
  19384. "thing": {
  19385. "$ref": "#/definitions/thing" // <--- circular reference to self
  19386. }
  19387. }
  19388. };
  19389. var schema2 = {
  19390. "definitions": {
  19391. "person": {
  19392. "type": "object",
  19393. "properties": {
  19394. "name": {
  19395. "type": "string"
  19396. },
  19397. "spouse": {
  19398. "$ref": "#/definitions/person" // <--- circular reference to ancestor
  19399. }
  19400. }
  19401. }
  19402. }
  19403. };
  19404. var schema3 = {
  19405. "definitions": {
  19406. "parent": {
  19407. "type": "object",
  19408. "properties": {
  19409. "name": {
  19410. "type": "string"
  19411. },
  19412. "children": {
  19413. "type": "array",
  19414. "items": {
  19415. "$ref": "#/definitions/child" // <--- indirect circular reference
  19416. }
  19417. }
  19418. }
  19419. },
  19420. "child": {
  19421. "type": "object",
  19422. "properties": {
  19423. "name": {
  19424. "type": "string"
  19425. },
  19426. "parents": {
  19427. "type": "array",
  19428. "items": {
  19429. "$ref": "#/definitions/parent" // <--- indirect circular reference
  19430. }
  19431. }
  19432. }
  19433. }
  19434. }
  19435. };
  19436. module.exports = {
  19437. description: "Issue #137 - circular dependencies between schemas",
  19438. tests: [
  19439. {
  19440. description: "should pass validation #1",
  19441. schema: schema1,
  19442. validateSchemaOnly: true,
  19443. valid: true
  19444. },
  19445. {
  19446. description: "should pass validation #2",
  19447. schema: schema2,
  19448. validateSchemaOnly: true,
  19449. valid: true
  19450. },
  19451. {
  19452. description: "should pass validation #3",
  19453. schema: schema3,
  19454. validateSchemaOnly: true,
  19455. valid: true
  19456. }
  19457. ]
  19458. };
  19459. },{}],183:[function(require,module,exports){
  19460. module.exports = {
  19461. description: "Issue #139 - add schema id if present to erro message via addError method",
  19462. tests: [
  19463. {
  19464. description: "should fail",
  19465. options: {
  19466. strictMode: true
  19467. },
  19468. schema: {
  19469. id: "dummy",
  19470. type: "object",
  19471. description: "This is a dummy schema",
  19472. properties: {
  19473. recType: {
  19474. type: "string"
  19475. },
  19476. startDate: {
  19477. type: ["object", "string"],
  19478. format: "date"
  19479. },
  19480. endDate: {
  19481. type: ["object", "string"],
  19482. format: "date"
  19483. },
  19484. noteList: {
  19485. type: "array",
  19486. items: {
  19487. $ref: "note"
  19488. }
  19489. },
  19490. isBlocked: {
  19491. type: "boolean"
  19492. },
  19493. roleA: {
  19494. $ref: "dbRef"
  19495. },
  19496. roleB: {
  19497. $ref: "dbRef"
  19498. },
  19499. recProps: {
  19500. type: "object"
  19501. }
  19502. },
  19503. additionalProperties: false,
  19504. required: ["recType", "roleA", "roleB"]
  19505. },
  19506. valid: false,
  19507. after: function (err) {
  19508. expect(err.length).toBe(3);
  19509. err.forEach(function (e) {
  19510. expect(e.code).toBe("UNRESOLVABLE_REFERENCE");
  19511. expect(e.schemaId).toBe("dummy");
  19512. });
  19513. }
  19514. }
  19515. ]
  19516. };
  19517. },{}],184:[function(require,module,exports){
  19518. "use strict";
  19519. module.exports = {
  19520. description: "Issue #142 - assumeAdditional complains about $ref",
  19521. tests: [
  19522. {
  19523. description: "should pass",
  19524. options: {
  19525. assumeAdditional: ["$ref"]
  19526. },
  19527. schema: "http://json-schema.org/draft-04/schema",
  19528. data: { $ref: "#" },
  19529. valid: true
  19530. }
  19531. ]
  19532. };
  19533. },{}],185:[function(require,module,exports){
  19534. "use strict";
  19535. module.exports = {
  19536. description: "Issue #146 - Only the first failure in an `allOf` block is returned",
  19537. tests: [
  19538. {
  19539. description: "should pass",
  19540. options: {
  19541. breakOnFirstError: false
  19542. },
  19543. schema: {
  19544. properties: {
  19545. password: {
  19546. allOf: [
  19547. { type: "string", minLength: 8 },
  19548. { type: "string", pattern: "[A-Z]+" }
  19549. ]
  19550. }
  19551. }
  19552. },
  19553. data: { password: "short" },
  19554. valid: false,
  19555. after: function (err) {
  19556. expect(err.length).toBe(2);
  19557. }
  19558. }
  19559. ]
  19560. };
  19561. },{}],186:[function(require,module,exports){
  19562. "use strict";
  19563. module.exports = {
  19564. description: "Issue #151 - minProperties for object type doesn't work",
  19565. tests: [
  19566. {
  19567. description: "should fail",
  19568. schema: {
  19569. "type": "object",
  19570. "properties": {
  19571. "props": {
  19572. "type": "object",
  19573. "minProperties": 1
  19574. }
  19575. }
  19576. },
  19577. data: {
  19578. "props": {}
  19579. },
  19580. valid: false,
  19581. after: function (err) {
  19582. expect(err[0].code).toBe("OBJECT_PROPERTIES_MINIMUM");
  19583. }
  19584. }
  19585. ]
  19586. };
  19587. },{}],187:[function(require,module,exports){
  19588. "use strict";
  19589. module.exports = {
  19590. description: "Issue #16 - schemas should be validated by references in $schema property",
  19591. tests: [
  19592. {
  19593. description: "should pass validation",
  19594. schema: {
  19595. $schema: "http://json-schema.org/draft-04/hyper-schema#",
  19596. links: []
  19597. },
  19598. validateSchemaOnly: true,
  19599. valid: true
  19600. },
  19601. {
  19602. description: "should fail validation",
  19603. schema: {
  19604. $schema: "http://json-schema.org/draft-04/hyper-schema#",
  19605. links: null
  19606. },
  19607. validateSchemaOnly: true,
  19608. valid: false
  19609. }
  19610. ]
  19611. };
  19612. },{}],188:[function(require,module,exports){
  19613. "use strict";
  19614. var ref1 = "http://www.example.org/schema1/#";
  19615. var ref2 = "http://www.example.org/schema2/#";
  19616. var schema1 = {
  19617. "$schema": "http://json-schema.org/draft-04/schema#",
  19618. "id": ref1,
  19619. "properties": {
  19620. "prop1": {
  19621. "$ref": ref2
  19622. }
  19623. }
  19624. };
  19625. var schema2 = {
  19626. "$schema": "http://json-schema.org/draft-04/schema#",
  19627. "id": ref2,
  19628. "properties": {
  19629. "prop1": {
  19630. "$ref": ref1
  19631. }
  19632. }
  19633. };
  19634. module.exports = {
  19635. description: "Issue #47 - references to draft4 subschema are not working",
  19636. setup: function (validator) {
  19637. validator.setRemoteReference(ref1, schema1);
  19638. validator.setRemoteReference(ref2, schema2);
  19639. },
  19640. tests: [
  19641. {
  19642. description: "should pass validation #1",
  19643. schema: schema1,
  19644. data: {},
  19645. valid: true
  19646. }
  19647. ]
  19648. };
  19649. },{}],189:[function(require,module,exports){
  19650. "use strict";
  19651. var testAsync = true;
  19652. module.exports = {
  19653. description: "Issue #209 - async validator returns wrong path",
  19654. async: true,
  19655. options: {
  19656. asyncTimeout: 2000
  19657. },
  19658. setup: function (validator, Class) {
  19659. if (testAsync) {
  19660. // asynchronous validator
  19661. Class.registerFormat("string-length", function (str, callback) {
  19662. setTimeout(function () {
  19663. callback(str.length > 10);
  19664. }, 1);
  19665. });
  19666. } else {
  19667. // same as above but synchronous (comment out the validator above and try with this instead)
  19668. Class.registerFormat("string-length", function (str) {
  19669. return str.length > 10;
  19670. });
  19671. }
  19672. },
  19673. schema: {
  19674. description: "Some schema",
  19675. type: "object",
  19676. properties: {
  19677. userId: {
  19678. type: "string",
  19679. format: "string-length"
  19680. }
  19681. },
  19682. required: ["userId"]
  19683. },
  19684. tests: [
  19685. {
  19686. description: "Wrong path in custom format async validator",
  19687. data: { userId: "1" },
  19688. valid: false,
  19689. after: function (err) {
  19690. expect(err[0].path).toEqual("#/userId");
  19691. }
  19692. }
  19693. ]
  19694. };
  19695. },{}],190:[function(require,module,exports){
  19696. "use strict";
  19697. module.exports = {
  19698. description: "Issue #22 - recursive references",
  19699. tests: [
  19700. {
  19701. description: "should pass validation",
  19702. schema: {
  19703. type: "object",
  19704. additionalProperties: false,
  19705. properties: {
  19706. "is_and": { type: "boolean" },
  19707. "filters": {
  19708. type: "array",
  19709. additionalItems: false,
  19710. items: {
  19711. oneOf: [
  19712. { $ref: "#" },
  19713. { $ref: "#/definitions/last" }
  19714. ]
  19715. }
  19716. }
  19717. },
  19718. definitions: {
  19719. "last": {
  19720. type: "object",
  19721. additionalProperties: false,
  19722. properties: {
  19723. "text": { type: "string" },
  19724. "is_last": { type: "boolean" },
  19725. "filters": { type: "array", additionalItems: false }
  19726. }
  19727. }
  19728. }
  19729. },
  19730. data: {
  19731. "is_and": false,
  19732. "filters": [
  19733. {
  19734. "is_and": false,
  19735. "filters": [
  19736. {
  19737. "is_and": true,
  19738. "filters": [
  19739. {
  19740. "is_and": true,
  19741. "filters": [
  19742. {
  19743. "is_and": true,
  19744. "filters": [
  19745. {
  19746. "is_and": true,
  19747. "filters": [
  19748. {
  19749. "text": "ABC",
  19750. "is_last": true,
  19751. "filters": []
  19752. }
  19753. ]
  19754. }
  19755. ]
  19756. }
  19757. ]
  19758. }
  19759. ]
  19760. }
  19761. ]
  19762. }
  19763. ]
  19764. },
  19765. valid: true
  19766. }
  19767. ]
  19768. };
  19769. },{}],191:[function(require,module,exports){
  19770. "use strict";
  19771. module.exports = {
  19772. description: "Issue #222 - Object.keys() does not guarantee order",
  19773. tests: [
  19774. {
  19775. description: "should pass",
  19776. schema: {
  19777. "type":"object",
  19778. "oneOf": [
  19779. {
  19780. "type": "object",
  19781. "properties": {
  19782. "code": {
  19783. "type": "string"
  19784. },
  19785. "libelle": {
  19786. "type": "string"
  19787. }
  19788. },
  19789. "enum": [
  19790. {
  19791. "code": "null",
  19792. "libelle": "null"
  19793. }
  19794. ]
  19795. },
  19796. {
  19797. "type": "object",
  19798. "properties": {
  19799. "code": {
  19800. "type": "string"
  19801. },
  19802. "libelle": {
  19803. "type": "string"
  19804. }
  19805. },
  19806. "enum": [
  19807. {
  19808. "code": "0",
  19809. "libelle": "Choice 1"
  19810. }
  19811. ]
  19812. },
  19813. {
  19814. "type": "object",
  19815. "properties": {
  19816. "code": {
  19817. "type": "string"
  19818. },
  19819. "libelle": {
  19820. "type": "string"
  19821. }
  19822. },
  19823. "enum": [
  19824. {
  19825. "code": "1",
  19826. "libelle": "Choice 2"
  19827. }
  19828. ]
  19829. },
  19830. {
  19831. "type": "object",
  19832. "properties": {
  19833. "code": {
  19834. "type": "string"
  19835. },
  19836. "libelle": {
  19837. "type": "string"
  19838. }
  19839. },
  19840. "enum": [
  19841. {
  19842. "code": "2",
  19843. "libelle": "Choice 3"
  19844. }
  19845. ]
  19846. }
  19847. ]
  19848. },
  19849. data: {
  19850. "code": "2",
  19851. "libelle": "Choice 3"
  19852. },
  19853. valid: true
  19854. }
  19855. ]
  19856. };
  19857. },{}],192:[function(require,module,exports){
  19858. "use strict";
  19859. module.exports = {
  19860. description: "Issue #229 - Paths in errors are incorrect due to Issue #209 fix",
  19861. tests: [
  19862. {
  19863. description: "should fail with correct error path",
  19864. schema: {
  19865. "allOf": [
  19866. {
  19867. "properties": {
  19868. "setup": {
  19869. "description": "Account Research Setup",
  19870. "properties": {
  19871. "excessiveCredit": {
  19872. "properties": {
  19873. "negativeBatch": {
  19874. "type": "number",
  19875. "minimum": 0,
  19876. "maximum": 999999999.99,
  19877. "title": "Negative Batch $"
  19878. },
  19879. "amountOfCreditsInBatch": {
  19880. "type": "number",
  19881. "minimum": 0,
  19882. "maximum": 999999999.99,
  19883. "title": "Amount of Credits in a Batch $"
  19884. },
  19885. "numberOfCreditsInBatch": {
  19886. "type": "number",
  19887. "minimum": 1,
  19888. "maximum": 999,
  19889. "title": "Number of Credits in a Batch"
  19890. }
  19891. }
  19892. }
  19893. }
  19894. }
  19895. }
  19896. }
  19897. ]
  19898. },
  19899. data: {
  19900. "setup": {
  19901. "excessiveCredit": {
  19902. "amountOfCreditsInBatch": -15000.21,
  19903. "negativeBatch": 25001,
  19904. "numberOfCreditsInBatch": 155
  19905. }
  19906. }
  19907. },
  19908. valid: false,
  19909. after: function (err) {
  19910. expect(err.length).toBe(1);
  19911. expect(err[0].code).toBe('MINIMUM');
  19912. expect(err[0].path).toBe('#/setup/excessiveCredit/amountOfCreditsInBatch');
  19913. }
  19914. }
  19915. ]
  19916. };
  19917. },{}],193:[function(require,module,exports){
  19918. "use strict";
  19919. module.exports = {
  19920. description: "Issue #25 - hostname format behaviour",
  19921. tests: [
  19922. {
  19923. description: "should pass validation",
  19924. schema: {
  19925. "$schema": "http://json-schema.org/draft-04/schema#",
  19926. "type": "object",
  19927. "properties": {
  19928. "ipAddress": {
  19929. "type": "string",
  19930. "oneOf": [
  19931. {
  19932. "format": "hostname"
  19933. },
  19934. {
  19935. "format": "ipv4"
  19936. },
  19937. {
  19938. "format": "ipv6"
  19939. }
  19940. ]
  19941. }
  19942. }
  19943. },
  19944. data: {
  19945. "ipAddress": "127.0.0.1"
  19946. },
  19947. valid: true
  19948. }
  19949. ]
  19950. };
  19951. },{}],194:[function(require,module,exports){
  19952. "use strict";
  19953. module.exports = {
  19954. description: "Issue #250 - Floating point precision is lost",
  19955. tests: [
  19956. {
  19957. description: "should pass the multipleOf",
  19958. schema: {
  19959. "properties": {
  19960. "number": {
  19961. "multipleOf": 0.01
  19962. }
  19963. }
  19964. },
  19965. data: {
  19966. "number": 20.29
  19967. },
  19968. valid: true
  19969. }
  19970. ]
  19971. };
  19972. },{}],195:[function(require,module,exports){
  19973. "use strict";
  19974. module.exports = {
  19975. description: "Issue #26 - noTypeless behaviour",
  19976. options: {
  19977. noTypeless: true
  19978. },
  19979. tests: [
  19980. {
  19981. description: "should pass validation",
  19982. schema: {
  19983. "oneOf": [
  19984. { $ref: "#/definitions/str" },
  19985. { $ref: "#/definitions/num" }
  19986. ],
  19987. "definitions": {
  19988. "str": {
  19989. "type": "string"
  19990. },
  19991. "num": {
  19992. "type": "number"
  19993. }
  19994. }
  19995. },
  19996. data: "string",
  19997. valid: true
  19998. },
  19999. {
  20000. description: "should fail validation",
  20001. schema: {
  20002. "oneOf": [
  20003. { $ref: "#/definitions/str" },
  20004. { $ref: "#/definitions/num" }
  20005. ],
  20006. "definitions": {
  20007. "str": {
  20008. "type": "string"
  20009. },
  20010. "num": {
  20011. "type": "number"
  20012. }
  20013. }
  20014. },
  20015. data: true,
  20016. valid: false
  20017. },
  20018. {
  20019. description: "should fail validation because one of the definitions doesn't have a type",
  20020. schema: {
  20021. "oneOf": [
  20022. { $ref: "#/definitions/str" },
  20023. { $ref: "#/definitions/num" }
  20024. ],
  20025. "definitions": {
  20026. "str": {
  20027. "type": "string"
  20028. },
  20029. "num": {
  20030. }
  20031. }
  20032. },
  20033. data: "string",
  20034. valid: false,
  20035. after: function (errors) {
  20036. expect(errors[0].code).toBe("KEYWORD_UNDEFINED_STRICT");
  20037. }
  20038. },
  20039. {
  20040. description: "should pass validation because type is defined by parent",
  20041. schema: {
  20042. type: "object",
  20043. properties: {
  20044. "prop1": { type: "string" },
  20045. "prop2": { type: "string" }
  20046. },
  20047. anyOf: [
  20048. { required: ["prop1"] },
  20049. { required: ["prop2"] }
  20050. ]
  20051. },
  20052. data: {
  20053. prop1: "str"
  20054. },
  20055. valid: true
  20056. }
  20057. ]
  20058. };
  20059. },{}],196:[function(require,module,exports){
  20060. "use strict";
  20061. module.exports = {
  20062. description: "Issue #37 - pass schema as an uri to load from cache",
  20063. tests: [
  20064. {
  20065. description: "should pass validation",
  20066. schema: "http://json-schema.org/draft-04/schema",
  20067. data: {
  20068. type: "string"
  20069. },
  20070. valid: true
  20071. },
  20072. {
  20073. description: "should pass validation",
  20074. schema: "http://json-schema.org/draft-04/schema",
  20075. data: {
  20076. type: 1
  20077. },
  20078. valid: false
  20079. }
  20080. ]
  20081. };
  20082. },{}],197:[function(require,module,exports){
  20083. "use strict";
  20084. module.exports = {
  20085. description: "Issue #40 - validator ends up in infinite loop",
  20086. tests: [
  20087. {
  20088. description: "should pass validation",
  20089. schema: {
  20090. "$schema": "http://json-schema.org/draft-04/schema#",
  20091. "title": "Product set",
  20092. "is_start": "boolean",
  20093. "hierarchy": {
  20094. "$ref": "#/definitions/recursion"
  20095. },
  20096. "definitions": {
  20097. "recursion": {
  20098. "type": "object",
  20099. "additionalProperties": false,
  20100. "properties": {
  20101. "is_and": {
  20102. "type": "boolean"
  20103. },
  20104. "filters": {
  20105. "type": "array",
  20106. "additionalItems": false,
  20107. "items": {
  20108. "$ref": "#/definitions/recursion"
  20109. }
  20110. }
  20111. }
  20112. }
  20113. }
  20114. },
  20115. data: {
  20116. "is_start": true,
  20117. "hierarchy": {
  20118. "is_and": false,
  20119. "filters": [
  20120. {
  20121. "is_and": false,
  20122. "filters": [
  20123. {
  20124. "is_and": true,
  20125. "filters": [
  20126. {
  20127. "is_and": true,
  20128. "filters": [
  20129. {
  20130. "is_and": true,
  20131. "filters": [
  20132. {
  20133. "is_and": true,
  20134. "filters": [
  20135. {
  20136. "is_and": true,
  20137. "filters": []
  20138. }
  20139. ]
  20140. }
  20141. ]
  20142. }
  20143. ]
  20144. }
  20145. ]
  20146. }
  20147. ]
  20148. }
  20149. ]
  20150. }
  20151. },
  20152. valid: true
  20153. }
  20154. ]
  20155. };
  20156. },{}],198:[function(require,module,exports){
  20157. "use strict";
  20158. module.exports = {
  20159. description: "Issue #41 - invalid schema",
  20160. tests: [
  20161. {
  20162. description: "should fail schema validation",
  20163. schema: {
  20164. "$schema": "http://json-schema.org/draft-04/schema#",
  20165. "id": "http://jsonschema.net#",
  20166. "type": "array",
  20167. "required": false,
  20168. "items": {
  20169. "id": "http://jsonschema.net/5#",
  20170. "type": "object",
  20171. "required": false,
  20172. "properties": {
  20173. "identifiers": {
  20174. "id": "http://jsonschema.net/5/identifiers#",
  20175. "type": "array",
  20176. "required": false,
  20177. "items": {
  20178. "id": "http://jsonschema.net/5/identifiers/0#",
  20179. "type": "object",
  20180. "required": false,
  20181. "properties": {
  20182. "identifier": {
  20183. "id": "http://jsonschema.net/5/identifiers/0/identifier#",
  20184. "type": "string",
  20185. "required": false
  20186. }
  20187. }
  20188. }
  20189. },
  20190. "vital": {
  20191. "id": "http://jsonschema.net/5/vital#",
  20192. "type": "object",
  20193. "required": false,
  20194. "properties": {
  20195. "name": {
  20196. "id": "http://jsonschema.net/5/vital/name#",
  20197. "type": "string",
  20198. "required": false
  20199. },
  20200. "code": {
  20201. "id": "http://jsonschema.net/5/vital/code#",
  20202. "type": "string",
  20203. "required": false
  20204. },
  20205. "code_system_name": {
  20206. "id": "http://jsonschema.net/5/vital/code_system_name#",
  20207. "type": "string",
  20208. "required": false
  20209. }
  20210. }
  20211. },
  20212. "status": {
  20213. "id": "http://jsonschema.net/5/status#",
  20214. "type": "string",
  20215. "required": false
  20216. },
  20217. "date": {
  20218. "id": "http://jsonschema.net/5/date#",
  20219. "type": "array",
  20220. "required": false,
  20221. "items": {
  20222. "id": "http://jsonschema.net/5/date/0#",
  20223. "type": "object",
  20224. "required": false,
  20225. "properties": {
  20226. "date": {
  20227. "id": "http://jsonschema.net/5/date/0/date#",
  20228. "type": "string",
  20229. "required": false
  20230. },
  20231. "precision": {
  20232. "id": "http://jsonschema.net/5/date/0/precision#",
  20233. "type": "string",
  20234. "required": false
  20235. }
  20236. }
  20237. }
  20238. },
  20239. "interpretations": {
  20240. "id": "http://jsonschema.net/5/interpretations#",
  20241. "type": "array",
  20242. "required": false,
  20243. "items": {
  20244. "id": "http://jsonschema.net/5/interpretations/0#",
  20245. "type": "string",
  20246. "required": false
  20247. }
  20248. },
  20249. "value": {
  20250. "id": "http://jsonschema.net/5/value#",
  20251. "type": "integer",
  20252. "required": false
  20253. },
  20254. "unit": {
  20255. "id": "http://jsonschema.net/5/unit#",
  20256. "type": "string",
  20257. "required": false
  20258. }
  20259. }
  20260. }
  20261. },
  20262. validateSchemaOnly: true,
  20263. valid: false
  20264. }
  20265. ]
  20266. };
  20267. },{}],199:[function(require,module,exports){
  20268. "use strict";
  20269. module.exports = {
  20270. description: "Issue #43 - maximum call stack size exceeded error",
  20271. tests: [
  20272. {
  20273. description: "should compile both schemas",
  20274. schema: [
  20275. {
  20276. "id": "schemaA",
  20277. "$schema": "http://json-schema.org/draft-04/schema#",
  20278. "description": "Data type fields (section 4.3.3)",
  20279. "type": "object",
  20280. "oneOf": [
  20281. {
  20282. "required": ["type"]
  20283. },
  20284. {
  20285. "required": ["$ref"]
  20286. }
  20287. ],
  20288. "properties": {
  20289. "type": {
  20290. "type": "string"
  20291. },
  20292. "$ref": {
  20293. "type": "string"
  20294. },
  20295. "format": {
  20296. "type": "string"
  20297. },
  20298. "defaultValue": {
  20299. "not": {
  20300. "type": ["array", "object", "null"]
  20301. }
  20302. },
  20303. "enum": {
  20304. "type": "array",
  20305. "items": {
  20306. "type": "string"
  20307. },
  20308. "uniqueItems": true,
  20309. "minItems": 1
  20310. },
  20311. "minimum": {
  20312. "type": "string"
  20313. },
  20314. "maximum": {
  20315. "type": "string"
  20316. },
  20317. "items": {
  20318. "$ref": "#/definitions/itemsObject"
  20319. },
  20320. "uniqueItems": {
  20321. "type": "boolean"
  20322. }
  20323. },
  20324. "dependencies": {
  20325. "format": {
  20326. "oneOf": [
  20327. {
  20328. "properties": {
  20329. "type": {
  20330. "enum": ["integer"]
  20331. },
  20332. "format": {
  20333. "enum": ["int32", "int64"]
  20334. }
  20335. }
  20336. },
  20337. {
  20338. "properties": {
  20339. "type": {
  20340. "enum": ["number"]
  20341. },
  20342. "format": {
  20343. "enum": ["float", "double"]
  20344. }
  20345. }
  20346. },
  20347. {
  20348. "properties": {
  20349. "type": {
  20350. "enum": ["string"]
  20351. },
  20352. "format": {
  20353. "enum": ["byte", "date", "date-time"]
  20354. }
  20355. }
  20356. }
  20357. ]
  20358. }
  20359. },
  20360. "definitions": {
  20361. "itemsObject": {
  20362. "oneOf": [
  20363. {
  20364. "type": "object",
  20365. "required": ["$ref"],
  20366. "properties": {
  20367. "$ref": {
  20368. "type": "string"
  20369. }
  20370. },
  20371. "additionalProperties": false
  20372. },
  20373. {
  20374. "allOf": [
  20375. {
  20376. "$ref": "#"
  20377. },
  20378. {
  20379. "required": ["type"],
  20380. "properties": {
  20381. "type": {},
  20382. "format": {}
  20383. },
  20384. "additionalProperties": false
  20385. }
  20386. ]
  20387. }
  20388. ]
  20389. }
  20390. }
  20391. },
  20392. {
  20393. "id": "schemaB",
  20394. "$schema": "http://json-schema.org/draft-04/schema#",
  20395. "type": "object",
  20396. "required": ["id", "properties"],
  20397. "properties": {
  20398. "id": {
  20399. "type": "string"
  20400. },
  20401. "description": {
  20402. "type": "string"
  20403. },
  20404. "properties": {
  20405. "type": "object",
  20406. "additionalProperties": {
  20407. "$ref": "#/definitions/propertyObject"
  20408. }
  20409. },
  20410. "subTypes": {
  20411. "type": "array",
  20412. "items": {
  20413. "type": "string"
  20414. },
  20415. "uniqueItems": true
  20416. },
  20417. "discriminator": {
  20418. "type": "string"
  20419. }
  20420. },
  20421. "dependencies": {
  20422. "subTypes": ["discriminator"]
  20423. },
  20424. "definitions": {
  20425. "propertyObject": {
  20426. "allOf": [
  20427. {
  20428. "not": {
  20429. "$ref": "#"
  20430. }
  20431. },
  20432. {
  20433. "$ref": "schemaA"
  20434. }
  20435. ]
  20436. }
  20437. }
  20438. }
  20439. ],
  20440. validateSchemaOnly: true,
  20441. valid: true
  20442. }
  20443. ]
  20444. };
  20445. },{}],200:[function(require,module,exports){
  20446. "use strict";
  20447. module.exports = {
  20448. description: "Issue #44 - unresolvable reference due to hash sign",
  20449. tests: [
  20450. {
  20451. description: "should pass validation #1",
  20452. schema: [
  20453. {
  20454. id: "schemaA",
  20455. type: "string"
  20456. },
  20457. {
  20458. id: "schemaB",
  20459. properties: {
  20460. a: {
  20461. "$ref": "schemaA"
  20462. }
  20463. }
  20464. }
  20465. ],
  20466. validateSchemaOnly: true,
  20467. valid: true
  20468. },
  20469. {
  20470. description: "should pass validation #2",
  20471. schema: [
  20472. {
  20473. id: "schemaA",
  20474. type: "string"
  20475. },
  20476. {
  20477. id: "schemaB",
  20478. properties: {
  20479. a: {
  20480. "$ref": "schemaA#"
  20481. }
  20482. }
  20483. }
  20484. ],
  20485. validateSchemaOnly: true,
  20486. valid: true
  20487. }
  20488. ]
  20489. };
  20490. },{}],201:[function(require,module,exports){
  20491. "use strict";
  20492. var resourceObject = {
  20493. "id": "resourceObject.json",
  20494. "$schema": "http://json-schema.org/draft-04/schema#",
  20495. "type": "object",
  20496. "required": ["path"],
  20497. "properties": {
  20498. "path": {
  20499. "type": "string",
  20500. "format": "uri"
  20501. },
  20502. "description": {
  20503. "type": "string"
  20504. }
  20505. },
  20506. "additionalProperties": false
  20507. };
  20508. var infoObject = {
  20509. "id": "infoObject.json",
  20510. "$schema": "http://json-schema.org/draft-04/schema#",
  20511. "description": "info object (section 5.1.3)",
  20512. "type": "object",
  20513. "required": ["title", "description"],
  20514. "properties": {
  20515. "title": {
  20516. "type": "string"
  20517. },
  20518. "description": {
  20519. "type": "string"
  20520. },
  20521. "termsOfServiceUrl": {
  20522. "type": "string",
  20523. "format": "uri"
  20524. },
  20525. "contact": {
  20526. "type": "string",
  20527. "format": "email"
  20528. },
  20529. "license": {
  20530. "type": "string"
  20531. },
  20532. "licenseUrl": {
  20533. "type": "string",
  20534. "format": "uri"
  20535. }
  20536. },
  20537. "additionalProperties": false
  20538. };
  20539. var oauth2GrantType = {
  20540. "id": "oauth2GrantType.json",
  20541. "$schema": "http://json-schema.org/draft-04/schema#",
  20542. "type": "object",
  20543. "minProperties": 1,
  20544. "properties": {
  20545. "implicit": {
  20546. "$ref": "#/definitions/implicit"
  20547. },
  20548. "authorization_code": {
  20549. "$ref": "#/definitions/authorizationCode"
  20550. }
  20551. },
  20552. "definitions": {
  20553. "implicit": {
  20554. "type": "object",
  20555. "required": ["loginEndpoint"],
  20556. "properties": {
  20557. "loginEndpoint": {
  20558. "$ref": "#/definitions/loginEndpoint"
  20559. },
  20560. "tokenName": {
  20561. "type": "string"
  20562. }
  20563. },
  20564. "additionalProperties": false
  20565. },
  20566. "authorizationCode": {
  20567. "type": "object",
  20568. "required": ["tokenEndpoint", "tokenRequestEndpoint"],
  20569. "properties": {
  20570. "tokenEndpoint": {
  20571. "$ref": "#/definitions/tokenEndpoint"
  20572. },
  20573. "tokenRequestEndpoint": {
  20574. "$ref": "#/definitions/tokenRequestEndpoint"
  20575. }
  20576. },
  20577. "additionalProperties": false
  20578. },
  20579. "loginEndpoint": {
  20580. "type": "object",
  20581. "required": ["url"],
  20582. "properties": {
  20583. "url": {
  20584. "type": "string",
  20585. "format": "uri"
  20586. }
  20587. },
  20588. "additionalProperties": false
  20589. },
  20590. "tokenEndpoint": {
  20591. "type": "object",
  20592. "required": ["url"],
  20593. "properties": {
  20594. "url": {
  20595. "type": "string",
  20596. "format": "uri"
  20597. },
  20598. "tokenName": {
  20599. "type": "string"
  20600. }
  20601. },
  20602. "additionalProperties": false
  20603. },
  20604. "tokenRequestEndpoint": {
  20605. "type": "object",
  20606. "required": ["url"],
  20607. "properties": {
  20608. "url": {
  20609. "type": "string",
  20610. "format": "uri"
  20611. },
  20612. "clientIdName": {
  20613. "type": "string"
  20614. },
  20615. "clientSecretName": {
  20616. "type": "string"
  20617. }
  20618. },
  20619. "additionalProperties": false
  20620. }
  20621. }
  20622. };
  20623. var authorizationObject = {
  20624. "id": "authorizationObject.json",
  20625. "$schema": "http://json-schema.org/draft-04/schema#",
  20626. "type": "object",
  20627. "additionalProperties": {
  20628. "oneOf": [
  20629. {
  20630. "$ref": "#/definitions/basicAuth"
  20631. },
  20632. {
  20633. "$ref": "#/definitions/apiKey"
  20634. },
  20635. {
  20636. "$ref": "#/definitions/oauth2"
  20637. }
  20638. ]
  20639. },
  20640. "definitions": {
  20641. "basicAuth": {
  20642. "required": ["type"],
  20643. "properties": {
  20644. "type": {
  20645. "enum": ["basicAuth"]
  20646. }
  20647. },
  20648. "additionalProperties": false
  20649. },
  20650. "apiKey": {
  20651. "required": ["type", "passAs", "keyname"],
  20652. "properties": {
  20653. "type": {
  20654. "enum": ["apiKey"]
  20655. },
  20656. "passAs": {
  20657. "enum": ["header", "query"]
  20658. },
  20659. "keyname": {
  20660. "type": "string"
  20661. }
  20662. },
  20663. "additionalProperties": false
  20664. },
  20665. "oauth2": {
  20666. "type": "object",
  20667. "required": ["type", "grantTypes"],
  20668. "properties": {
  20669. "type": {
  20670. "enum": ["oauth2"]
  20671. },
  20672. "scopes": {
  20673. "type": "array",
  20674. "items": {
  20675. "$ref": "#/definitions/oauth2Scope"
  20676. }
  20677. },
  20678. "grantTypes": {
  20679. "$ref": "oauth2GrantType.json"
  20680. }
  20681. },
  20682. "additionalProperties": false
  20683. },
  20684. "oauth2Scope": {
  20685. "type": "object",
  20686. "required": ["scope"],
  20687. "properties": {
  20688. "scope": {
  20689. "type": "string"
  20690. },
  20691. "description": {
  20692. "type": "string"
  20693. }
  20694. },
  20695. "additionalProperties": false
  20696. }
  20697. }
  20698. };
  20699. var resourceListing = {
  20700. "id": "resourceListing.json",
  20701. "$schema": "http://json-schema.org/draft-04/schema#",
  20702. "type": "object",
  20703. "required": ["swaggerVersion", "apis"],
  20704. "properties": {
  20705. "swaggerVersion": {
  20706. "enum": ["1.2"]
  20707. },
  20708. "apis": {
  20709. "type": "array",
  20710. "items": {
  20711. "$ref": "resourceObject.json"
  20712. }
  20713. },
  20714. "apiVersion": {
  20715. "type": "string"
  20716. },
  20717. "info": {
  20718. "$ref": "infoObject.json"
  20719. },
  20720. "authorizations": {
  20721. "$ref": "authorizationObject.json"
  20722. }
  20723. }
  20724. };
  20725. var schemaCombinations = {
  20726. "authorizationObject.json": [
  20727. oauth2GrantType,
  20728. authorizationObject
  20729. ],
  20730. "infoObject.json": [
  20731. infoObject
  20732. ],
  20733. "oauth2GrantType.json": [
  20734. oauth2GrantType
  20735. ],
  20736. "resourceObject.json": [
  20737. resourceObject
  20738. ],
  20739. "resourceListing.json": [
  20740. resourceObject,
  20741. infoObject,
  20742. oauth2GrantType,
  20743. authorizationObject,
  20744. resourceListing
  20745. ]
  20746. };
  20747. module.exports = {
  20748. description: "Issue #45 - recompiling schemas results in 'Reference could not be resolved'",
  20749. tests: [
  20750. {
  20751. description: "should pass schema validation #1",
  20752. schema: schemaCombinations["authorizationObject.json"],
  20753. validateSchemaOnly: true,
  20754. valid: true
  20755. },
  20756. {
  20757. description: "should pass schema validation #2",
  20758. schema: schemaCombinations["infoObject.json"],
  20759. validateSchemaOnly: true,
  20760. valid: true
  20761. },
  20762. {
  20763. description: "should pass schema validation #3",
  20764. schema: schemaCombinations["oauth2GrantType.json"],
  20765. validateSchemaOnly: true,
  20766. valid: true
  20767. },
  20768. {
  20769. description: "should pass schema validation #4",
  20770. schema: schemaCombinations["resourceObject.json"],
  20771. validateSchemaOnly: true,
  20772. valid: true
  20773. },
  20774. {
  20775. description: "should pass schema validation #5",
  20776. schema: schemaCombinations["resourceListing.json"],
  20777. validateSchemaOnly: true,
  20778. valid: true
  20779. }
  20780. ]
  20781. };
  20782. },{}],202:[function(require,module,exports){
  20783. "use strict";
  20784. var draft4 = require("./files/Issue47/draft4.json");
  20785. var modifiedSchema = require("./files/Issue47/swagger_draft_modified.json");
  20786. var realSchema = require("./files/Issue47/swagger_draft.json");
  20787. var json = require("./files/Issue47/sample.json");
  20788. module.exports = {
  20789. description: "Issue #47 - references to draft4 subschema are not working",
  20790. setup: function (validator) {
  20791. validator.setRemoteReference("http://json-schema.orgx/draft-04/schema", draft4);
  20792. },
  20793. tests: [
  20794. {
  20795. description: "should pass validation #1",
  20796. schema: modifiedSchema,
  20797. data: json,
  20798. valid: true
  20799. },
  20800. {
  20801. description: "should pass validation #1",
  20802. schema: realSchema,
  20803. data: json,
  20804. valid: true
  20805. }
  20806. ]
  20807. };
  20808. },{"./files/Issue47/draft4.json":226,"./files/Issue47/sample.json":227,"./files/Issue47/swagger_draft.json":228,"./files/Issue47/swagger_draft_modified.json":229}],203:[function(require,module,exports){
  20809. "use strict";
  20810. module.exports = {
  20811. description: "Issue #48 - email validation too strict",
  20812. schema: {
  20813. type: "string",
  20814. format: "email"
  20815. },
  20816. tests: [
  20817. {
  20818. description: "should pass validation #1",
  20819. data: "zaggino@gmail.com",
  20820. valid: true
  20821. },
  20822. {
  20823. description: "should pass validation #2",
  20824. data: "foo@bar.baz",
  20825. valid: true
  20826. },
  20827. {
  20828. description: "should fail validation #1",
  20829. data: "foobar.baz",
  20830. valid: false
  20831. },
  20832. {
  20833. description: "should fail validation #2",
  20834. data: "foo@bar",
  20835. valid: false
  20836. }
  20837. ]
  20838. };
  20839. },{}],204:[function(require,module,exports){
  20840. "use strict";
  20841. module.exports = {
  20842. description: "Issue #49 - pattern validations",
  20843. tests: [
  20844. {
  20845. description: "should pass validation",
  20846. schema: {
  20847. type: "string",
  20848. pattern: "^[0-9]{1}[0-9]{3}(\\s)?[A-Za-z]{2}$"
  20849. },
  20850. data: "0000 aa",
  20851. valid: true
  20852. }
  20853. ]
  20854. };
  20855. },{}],205:[function(require,module,exports){
  20856. "use strict";
  20857. module.exports = {
  20858. description: "Issue #53 - Include description (if any) in errors",
  20859. tests: [
  20860. {
  20861. description: "should fail validation and return error description",
  20862. schema: {
  20863. type: "string",
  20864. pattern: "^[0-9]{1}[0-9]{3}(\\s)?[A-Za-z]{2}$",
  20865. description: "Four numbers followed by an optional space and then two letters."
  20866. },
  20867. data: "000 a",
  20868. valid: false,
  20869. after: function (err) {
  20870. expect(err[0].description).toBe("Four numbers followed by an optional space and then two letters.");
  20871. }
  20872. }
  20873. ]
  20874. };
  20875. },{}],206:[function(require,module,exports){
  20876. "use strict";
  20877. module.exports = {
  20878. description: "Issue #56 - unresolvable reference due to hash sign",
  20879. tests: [
  20880. {
  20881. description: "should pass validation #1",
  20882. schema: [
  20883. {
  20884. id: "schemaA#",
  20885. type: "string"
  20886. },
  20887. {
  20888. id: "schemaB#",
  20889. properties: {
  20890. a: {
  20891. "$ref": "schemaA#"
  20892. }
  20893. }
  20894. }
  20895. ],
  20896. validateSchemaOnly: true,
  20897. valid: true
  20898. },
  20899. {
  20900. description: "should pass validation #2",
  20901. schema: [
  20902. {
  20903. id: "http://virtual/schemaA#",
  20904. type: "string"
  20905. },
  20906. {
  20907. id: "http://virtual/schemaB#",
  20908. properties: {
  20909. a: {
  20910. "$ref": "schemaA#"
  20911. }
  20912. }
  20913. }
  20914. ],
  20915. validateSchemaOnly: true,
  20916. valid: true
  20917. },
  20918. {
  20919. description: "should pass validation #3",
  20920. schema: [
  20921. {
  20922. id: "http://virtual/schemaA#",
  20923. type: "string",
  20924. "definitions": {
  20925. "stringDefinition": {
  20926. "type": "string"
  20927. }
  20928. }
  20929. },
  20930. {
  20931. id: "http://virtual/schemaB#",
  20932. properties: {
  20933. a: {
  20934. "$ref": "schemaA#/definitions/stringDefinition"
  20935. }
  20936. }
  20937. }
  20938. ],
  20939. validateSchemaOnly: true,
  20940. valid: true
  20941. }
  20942. ]
  20943. };
  20944. },{}],207:[function(require,module,exports){
  20945. "use strict";
  20946. var dataTypeBaseJson = {
  20947. "id": "http://wordnik.github.io/schemas/v1.2/dataTypeBase.json#",
  20948. "$schema": "http://json-schema.org/draft-04/schema#",
  20949. "description": "Data type fields (section 4.3.3)",
  20950. "type": "object",
  20951. "oneOf": [
  20952. {
  20953. "required": [
  20954. "type"
  20955. ]
  20956. },
  20957. {
  20958. "required": [
  20959. "$ref"
  20960. ]
  20961. }
  20962. ],
  20963. "properties": {
  20964. "type": {
  20965. "type": "string"
  20966. },
  20967. "$ref": {
  20968. "type": "string"
  20969. },
  20970. "format": {
  20971. "type": "string"
  20972. },
  20973. "defaultValue": {
  20974. "not": {
  20975. "type": [
  20976. "array",
  20977. "object",
  20978. "null"
  20979. ]
  20980. }
  20981. },
  20982. "enum": {
  20983. "type": "array",
  20984. "items": {
  20985. "type": "string"
  20986. },
  20987. "uniqueItems": true,
  20988. "minItems": 1
  20989. },
  20990. "minimum": {
  20991. "type": "string"
  20992. },
  20993. "maximum": {
  20994. "type": "string"
  20995. },
  20996. "items": {
  20997. "$ref": "#/definitions/itemsObject"
  20998. },
  20999. "uniqueItems": {
  21000. "type": "boolean"
  21001. }
  21002. },
  21003. "dependencies": {
  21004. "format": {
  21005. "oneOf": [
  21006. {
  21007. "properties": {
  21008. "type": {
  21009. "enum": [
  21010. "integer"
  21011. ]
  21012. },
  21013. "format": {
  21014. "enum": [
  21015. "int32",
  21016. "int64"
  21017. ]
  21018. }
  21019. }
  21020. },
  21021. {
  21022. "properties": {
  21023. "type": {
  21024. "enum": [
  21025. "number"
  21026. ]
  21027. },
  21028. "format": {
  21029. "enum": [
  21030. "float",
  21031. "double"
  21032. ]
  21033. }
  21034. }
  21035. },
  21036. {
  21037. "properties": {
  21038. "type": {
  21039. "enum": [
  21040. "string"
  21041. ]
  21042. },
  21043. "format": {
  21044. "enum": [
  21045. "byte",
  21046. "date",
  21047. "date-time"
  21048. ]
  21049. }
  21050. }
  21051. }
  21052. ]
  21053. }
  21054. },
  21055. "definitions": {
  21056. "itemsObject": {
  21057. "oneOf": [
  21058. {
  21059. "type": "object",
  21060. "required": [
  21061. "$ref"
  21062. ],
  21063. "properties": {
  21064. "$ref": {
  21065. "type": "string"
  21066. }
  21067. },
  21068. "additionalProperties": false
  21069. },
  21070. {
  21071. "allOf": [
  21072. {
  21073. "$ref": "#"
  21074. },
  21075. {
  21076. "required": [
  21077. "type"
  21078. ],
  21079. "properties": {
  21080. "type": {},
  21081. "format": {}
  21082. },
  21083. "additionalProperties": false
  21084. }
  21085. ]
  21086. }
  21087. ]
  21088. }
  21089. }
  21090. };
  21091. var modelsObjectJson = {
  21092. "id": "http://wordnik.github.io/schemas/v1.2/modelsObject.json#",
  21093. "$schema": "http://json-schema.org/draft-04/schema#",
  21094. "type": "object",
  21095. "required": [
  21096. "id",
  21097. "properties"
  21098. ],
  21099. "properties": {
  21100. "id": {
  21101. "type": "string"
  21102. },
  21103. "description": {
  21104. "type": "string"
  21105. },
  21106. "properties": {
  21107. "type": "object",
  21108. "additionalProperties": {
  21109. "$ref": "#/definitions/propertyObject"
  21110. }
  21111. },
  21112. "subTypes": {
  21113. "type": "array",
  21114. "items": {
  21115. "type": "string"
  21116. },
  21117. "uniqueItems": true
  21118. },
  21119. "discriminator": {
  21120. "type": "string"
  21121. }
  21122. },
  21123. "dependencies": {
  21124. "subTypes": [
  21125. "discriminator"
  21126. ]
  21127. },
  21128. "definitions": {
  21129. "propertyObject": {
  21130. "allOf": [
  21131. {
  21132. "not": {
  21133. "$ref": "#"
  21134. }
  21135. },
  21136. {
  21137. "$ref": "dataTypeBase.json#"
  21138. }
  21139. ]
  21140. }
  21141. }
  21142. };
  21143. var oauth2GrantTypeJson = {
  21144. "id": "http://wordnik.github.io/schemas/v1.2/oauth2GrantType.json#",
  21145. "$schema": "http://json-schema.org/draft-04/schema#",
  21146. "type": "object",
  21147. "minProperties": 1,
  21148. "properties": {
  21149. "implicit": {
  21150. "$ref": "#/definitions/implicit"
  21151. },
  21152. "authorization_code": {
  21153. "$ref": "#/definitions/authorizationCode"
  21154. }
  21155. },
  21156. "definitions": {
  21157. "implicit": {
  21158. "type": "object",
  21159. "required": [
  21160. "loginEndpoint"
  21161. ],
  21162. "properties": {
  21163. "loginEndpoint": {
  21164. "$ref": "#/definitions/loginEndpoint"
  21165. },
  21166. "tokenName": {
  21167. "type": "string"
  21168. }
  21169. },
  21170. "additionalProperties": false
  21171. },
  21172. "authorizationCode": {
  21173. "type": "object",
  21174. "required": [
  21175. "tokenEndpoint",
  21176. "tokenRequestEndpoint"
  21177. ],
  21178. "properties": {
  21179. "tokenEndpoint": {
  21180. "$ref": "#/definitions/tokenEndpoint"
  21181. },
  21182. "tokenRequestEndpoint": {
  21183. "$ref": "#/definitions/tokenRequestEndpoint"
  21184. }
  21185. },
  21186. "additionalProperties": false
  21187. },
  21188. "loginEndpoint": {
  21189. "type": "object",
  21190. "required": [
  21191. "url"
  21192. ],
  21193. "properties": {
  21194. "url": {
  21195. "type": "string",
  21196. "format": "uri"
  21197. }
  21198. },
  21199. "additionalProperties": false
  21200. },
  21201. "tokenEndpoint": {
  21202. "type": "object",
  21203. "required": [
  21204. "url"
  21205. ],
  21206. "properties": {
  21207. "url": {
  21208. "type": "string",
  21209. "format": "uri"
  21210. },
  21211. "tokenName": {
  21212. "type": "string"
  21213. }
  21214. },
  21215. "additionalProperties": false
  21216. },
  21217. "tokenRequestEndpoint": {
  21218. "type": "object",
  21219. "required": [
  21220. "url"
  21221. ],
  21222. "properties": {
  21223. "url": {
  21224. "type": "string",
  21225. "format": "uri"
  21226. },
  21227. "clientIdName": {
  21228. "type": "string"
  21229. },
  21230. "clientSecretName": {
  21231. "type": "string"
  21232. }
  21233. },
  21234. "additionalProperties": false
  21235. }
  21236. }
  21237. };
  21238. var authorizationObjectJson = {
  21239. "id": "http://wordnik.github.io/schemas/v1.2/authorizationObject.json#",
  21240. "$schema": "http://json-schema.org/draft-04/schema#",
  21241. "type": "object",
  21242. "additionalProperties": {
  21243. "oneOf": [
  21244. {
  21245. "$ref": "#/definitions/basicAuth"
  21246. },
  21247. {
  21248. "$ref": "#/definitions/apiKey"
  21249. },
  21250. {
  21251. "$ref": "#/definitions/oauth2"
  21252. }
  21253. ]
  21254. },
  21255. "definitions": {
  21256. "basicAuth": {
  21257. "required": [
  21258. "type"
  21259. ],
  21260. "properties": {
  21261. "type": {
  21262. "enum": [
  21263. "basicAuth"
  21264. ]
  21265. }
  21266. },
  21267. "additionalProperties": false
  21268. },
  21269. "apiKey": {
  21270. "required": [
  21271. "type",
  21272. "passAs",
  21273. "keyname"
  21274. ],
  21275. "properties": {
  21276. "type": {
  21277. "enum": [
  21278. "apiKey"
  21279. ]
  21280. },
  21281. "passAs": {
  21282. "enum": [
  21283. "header",
  21284. "query"
  21285. ]
  21286. },
  21287. "keyname": {
  21288. "type": "string"
  21289. }
  21290. },
  21291. "additionalProperties": false
  21292. },
  21293. "oauth2": {
  21294. "type": "object",
  21295. "required": [
  21296. "type",
  21297. "grantTypes"
  21298. ],
  21299. "properties": {
  21300. "type": {
  21301. "enum": [
  21302. "oauth2"
  21303. ]
  21304. },
  21305. "scopes": {
  21306. "type": "array",
  21307. "items": {
  21308. "$ref": "#/definitions/oauth2Scope"
  21309. }
  21310. },
  21311. "grantTypes": {
  21312. "$ref": "oauth2GrantType.json#"
  21313. }
  21314. },
  21315. "additionalProperties": false
  21316. },
  21317. "oauth2Scope": {
  21318. "type": "object",
  21319. "required": [
  21320. "scope"
  21321. ],
  21322. "properties": {
  21323. "scope": {
  21324. "type": "string"
  21325. },
  21326. "description": {
  21327. "type": "string"
  21328. }
  21329. },
  21330. "additionalProperties": false
  21331. }
  21332. }
  21333. };
  21334. var parameterObjectJson = {
  21335. "id": "http://wordnik.github.io/schemas/v1.2/parameterObject.json#",
  21336. "$schema": "http://json-schema.org/draft-04/schema#",
  21337. "type": "object",
  21338. "allOf": [
  21339. {
  21340. "$ref": "dataTypeBase.json#"
  21341. },
  21342. {
  21343. "required": [
  21344. "paramType",
  21345. "name"
  21346. ],
  21347. "properties": {
  21348. "paramType": {
  21349. "enum": [
  21350. "path",
  21351. "query",
  21352. "body",
  21353. "header",
  21354. "form"
  21355. ]
  21356. },
  21357. "name": {
  21358. "type": "string"
  21359. },
  21360. "description": {
  21361. "type": "string"
  21362. },
  21363. "required": {
  21364. "type": "boolean"
  21365. },
  21366. "allowMultiple": {
  21367. "type": "boolean"
  21368. }
  21369. }
  21370. },
  21371. {
  21372. "description": "type File requires special paramType and consumes",
  21373. "oneOf": [
  21374. {
  21375. "properties": {
  21376. "type": {
  21377. "not": {
  21378. "enum": [
  21379. "File"
  21380. ]
  21381. }
  21382. }
  21383. }
  21384. },
  21385. {
  21386. "properties": {
  21387. "type": {
  21388. "enum": [
  21389. "File"
  21390. ]
  21391. },
  21392. "paramType": {
  21393. "enum": [
  21394. "form"
  21395. ]
  21396. },
  21397. "consumes": {
  21398. "enum": [
  21399. "multipart/form-data"
  21400. ]
  21401. }
  21402. }
  21403. }
  21404. ]
  21405. }
  21406. ]
  21407. };
  21408. var operationObjectJson = {
  21409. "id": "http://wordnik.github.io/schemas/v1.2/operationObject.json#",
  21410. "$schema": "http://json-schema.org/draft-04/schema#",
  21411. "type": "object",
  21412. "allOf": [
  21413. {
  21414. "$ref": "dataTypeBase.json#"
  21415. },
  21416. {
  21417. "required": [
  21418. "method",
  21419. "nickname",
  21420. "parameters"
  21421. ],
  21422. "properties": {
  21423. "method": {
  21424. "enum": [
  21425. "GET",
  21426. "POST",
  21427. "PUT",
  21428. "PATCH",
  21429. "DELETE",
  21430. "OPTIONS"
  21431. ]
  21432. },
  21433. "summary": {
  21434. "type": "string",
  21435. "maxLength": 120
  21436. },
  21437. "notes": {
  21438. "type": "string"
  21439. },
  21440. "nickname": {
  21441. "type": "string",
  21442. "pattern": "^[a-zA-Z0-9_]+$"
  21443. },
  21444. "authorizations": {
  21445. "type": "object",
  21446. "additionalProperties": {
  21447. "type": "array",
  21448. "items": {
  21449. "$ref": "authorizationObject.json#/definitions/oauth2Scope"
  21450. }
  21451. }
  21452. },
  21453. "parameters": {
  21454. "type": "array",
  21455. "items": {
  21456. "$ref": "parameterObject.json#"
  21457. }
  21458. },
  21459. "responseMessages": {
  21460. "type": "array",
  21461. "items": {
  21462. "$ref": "#/definitions/responseMessageObject"
  21463. }
  21464. },
  21465. "produces": {
  21466. "$ref": "#/definitions/mimeTypeArray"
  21467. },
  21468. "consumes": {
  21469. "$ref": "#/definitions/mimeTypeArray"
  21470. },
  21471. "deprecated": {
  21472. "enum": [
  21473. "true",
  21474. "false"
  21475. ]
  21476. }
  21477. }
  21478. }
  21479. ],
  21480. "definitions": {
  21481. "responseMessageObject": {
  21482. "type": "object",
  21483. "required": [
  21484. "code",
  21485. "message"
  21486. ],
  21487. "properties": {
  21488. "code": {
  21489. "$ref": "#/definitions/rfc2616section10"
  21490. },
  21491. "message": {
  21492. "type": "string"
  21493. },
  21494. "responseModel": {
  21495. "type": "string"
  21496. }
  21497. }
  21498. },
  21499. "rfc2616section10": {
  21500. "type": "integer",
  21501. "minimum": 100,
  21502. "maximum": 600,
  21503. "exclusiveMaximum": true
  21504. },
  21505. "mimeTypeArray": {
  21506. "type": "array",
  21507. "items": {
  21508. "type": "string",
  21509. "format": "mime-type"
  21510. }
  21511. }
  21512. }
  21513. };
  21514. var apiDeclarationJson = {
  21515. "id": "http://wordnik.github.io/schemas/v1.2/apiDeclaration.json#",
  21516. "$schema": "http://json-schema.org/draft-04/schema#",
  21517. "type": "object",
  21518. "required": [
  21519. "swaggerVersion",
  21520. "basePath",
  21521. "apis"
  21522. ],
  21523. "properties": {
  21524. "swaggerVersion": {
  21525. "enum": [
  21526. "1.2"
  21527. ]
  21528. },
  21529. "apiVersion": {
  21530. "type": "string"
  21531. },
  21532. "basePath": {
  21533. "type": "string",
  21534. "format": "uri",
  21535. "pattern": "^https?://"
  21536. },
  21537. "resourcePath": {
  21538. "type": "string",
  21539. "format": "uri",
  21540. "pattern": "^/"
  21541. },
  21542. "apis": {
  21543. "type": "array",
  21544. "items": {
  21545. "$ref": "#/definitions/apiObject"
  21546. }
  21547. },
  21548. "models": {
  21549. "type": "object",
  21550. "additionalProperties": {
  21551. "$ref": "modelsObject.json#"
  21552. }
  21553. },
  21554. "produces": {
  21555. "$ref": "#/definitions/mimeTypeArray"
  21556. },
  21557. "consumes": {
  21558. "$ref": "#/definitions/mimeTypeArray"
  21559. },
  21560. "authorizations": {
  21561. "$ref": "authorizationObject.json#"
  21562. }
  21563. },
  21564. "additionalProperties": false,
  21565. "definitions": {
  21566. "apiObject": {
  21567. "type": "object",
  21568. "required": [
  21569. "path",
  21570. "operations"
  21571. ],
  21572. "properties": {
  21573. "path": {
  21574. "type": "string",
  21575. "format": "uri-template",
  21576. "pattern": "^/"
  21577. },
  21578. "description": {
  21579. "type": "string"
  21580. },
  21581. "operations": {
  21582. "type": "array",
  21583. "items": {
  21584. "$ref": "operationObject.json#"
  21585. }
  21586. }
  21587. },
  21588. "additionalProperties": false
  21589. },
  21590. "mimeTypeArray": {
  21591. "type": "array",
  21592. "items": {
  21593. "type": "string",
  21594. "format": "mime-type"
  21595. }
  21596. }
  21597. }
  21598. };
  21599. module.exports = {
  21600. description: "Issue #57 - maximum call stack exceeded error",
  21601. setup: function (validator, Class) {
  21602. Class.registerFormat("mime-type", function () {
  21603. return true;
  21604. });
  21605. Class.registerFormat("uri-template", function () {
  21606. return true;
  21607. });
  21608. },
  21609. tests: [
  21610. {
  21611. description: "should pass validation #1",
  21612. schema: [
  21613. dataTypeBaseJson,
  21614. modelsObjectJson,
  21615. oauth2GrantTypeJson,
  21616. authorizationObjectJson,
  21617. parameterObjectJson,
  21618. operationObjectJson,
  21619. apiDeclarationJson
  21620. ],
  21621. validateSchemaOnly: true,
  21622. valid: true
  21623. }
  21624. ]
  21625. };
  21626. },{}],208:[function(require,module,exports){
  21627. "use strict";
  21628. module.exports = {
  21629. description: "Issue #58 - getMissingReferences should return all missing references",
  21630. tests: [
  21631. {
  21632. description: "should fail validation",
  21633. schema: {
  21634. "id": "root.json",
  21635. "person": {
  21636. "id": "personDetails",
  21637. "type": "object",
  21638. "properties": {
  21639. "firstName": {
  21640. "type": "string"
  21641. },
  21642. "lastName": {
  21643. "type": "string"
  21644. }
  21645. },
  21646. "required": ["firstName", "lastName"]
  21647. },
  21648. "addr": {
  21649. "id": "addressDetails",
  21650. "type": "object",
  21651. "properties": {
  21652. "street": {
  21653. "type": "string"
  21654. },
  21655. "city": {
  21656. "type": "string"
  21657. }
  21658. },
  21659. "required": ["street", "city"]
  21660. },
  21661. "peraddr": {
  21662. "id": "personWithAddress",
  21663. "allOf": [{
  21664. "$ref": "#personDetails"
  21665. }, {
  21666. "$ref": "#addressDetails"
  21667. }, {
  21668. "$ref": "#/yy"
  21669. }, {
  21670. "$ref": "#xx"
  21671. }]
  21672. }
  21673. },
  21674. validateSchemaOnly: true,
  21675. valid: false,
  21676. after: function (err, valid, data, validator) {
  21677. var missingReferences = validator.getMissingReferences();
  21678. expect(missingReferences.length).toBe(2);
  21679. expect(missingReferences.indexOf("#xx")).not.toBe(-1);
  21680. expect(missingReferences.indexOf("#/yy")).not.toBe(-1);
  21681. var missingRemoteReferences = validator.getMissingRemoteReferences();
  21682. expect(missingRemoteReferences.length).toBe(0);
  21683. }
  21684. }
  21685. ]
  21686. };
  21687. },{}],209:[function(require,module,exports){
  21688. /*jshint -W101*/
  21689. "use strict";
  21690. module.exports = {
  21691. description: "Issue #63 - unresolvable reference due to hash sign in id",
  21692. tests: [
  21693. {
  21694. description: "should pass validation #1",
  21695. schema: {
  21696. "properties": {
  21697. "statementpost": {
  21698. "id": "#statementpost",
  21699. "type": [
  21700. "object"
  21701. ]
  21702. },
  21703. "statement": {
  21704. "id": "#statement",
  21705. "type": "object",
  21706. }
  21707. }
  21708. },
  21709. validateSchemaOnly: true,
  21710. valid: true
  21711. },
  21712. {
  21713. description: "should pass validation #2",
  21714. schema: {
  21715. "properties": {
  21716. "uuid": {
  21717. "id": "#uuid",
  21718. "type": "string",
  21719. "pattern": "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{8}"
  21720. },
  21721. "mbox": {
  21722. "id": "#mbox",
  21723. "type": "object",
  21724. "properties": {
  21725. "mbox": {
  21726. "required": true,
  21727. "type": "string",
  21728. "format": "uri",
  21729. "pattern": "^mailto:"
  21730. }
  21731. },
  21732. "patternProperties": {
  21733. "^(mbox_sha1sum|account|openid)$": {
  21734. "type": "null"
  21735. }
  21736. }
  21737. },
  21738. "mbox_sha1sum": {
  21739. "id": "#mbox_sha1sum",
  21740. "type": "object",
  21741. "properties": {
  21742. "mbox_sha1sum": {
  21743. "required": true,
  21744. "type": "string"
  21745. }
  21746. },
  21747. "patternProperties": {
  21748. "^(mbox|account|openid)$": {
  21749. "type": "null"
  21750. }
  21751. }
  21752. },
  21753. "account": {
  21754. "id": "#account",
  21755. "type": "object",
  21756. "properties": {
  21757. "account": {
  21758. "required": true,
  21759. "type": "object",
  21760. "properties": {
  21761. "homePage": {
  21762. "type": "string",
  21763. "format": "uri",
  21764. "required": true
  21765. },
  21766. "name": {
  21767. "type": "string",
  21768. "required": true
  21769. }
  21770. },
  21771. "additionalProperties": false
  21772. }
  21773. },
  21774. "patternProperties": {
  21775. "^(mbox_sha1sum|mbox|openid)$": {
  21776. "type": "null"
  21777. }
  21778. }
  21779. },
  21780. "openid": {
  21781. "id": "#openid",
  21782. "type": "object",
  21783. "properties": {
  21784. "openid": {
  21785. "required": true,
  21786. "type": "string",
  21787. "format": "uri"
  21788. }
  21789. },
  21790. "patternProperties": {
  21791. "^(mbox_sha1sum|account|mbox)$": {
  21792. "type": "null"
  21793. }
  21794. }
  21795. },
  21796. "inversefunctional": {
  21797. "id": "#inversefunctional",
  21798. "type": [
  21799. {
  21800. "$ref": "#mbox"
  21801. },
  21802. {
  21803. "$ref": "#mbox_sha1sum"
  21804. },
  21805. {
  21806. "$ref": "#account"
  21807. },
  21808. {
  21809. "$ref": "#openid"
  21810. }
  21811. ]
  21812. },
  21813. "agent": {
  21814. "id": "#agent",
  21815. "type": [
  21816. {
  21817. "$ref": "#inversefunctional"
  21818. }
  21819. ],
  21820. "properties": {
  21821. "name": {
  21822. "type": "string"
  21823. },
  21824. "objectType": {
  21825. "enum": ["Agent"]
  21826. },
  21827. "mbox": {},
  21828. "mbox_sha1sum": {},
  21829. "account": {},
  21830. "openid": {}
  21831. },
  21832. "additionalProperties": false
  21833. },
  21834. "groupBasics": {
  21835. "id": "#groupBasics",
  21836. "type": "object",
  21837. "properties": {
  21838. "name": {
  21839. "type": "string"
  21840. },
  21841. "objectType": {
  21842. "enum": ["Group"],
  21843. "required": true
  21844. },
  21845. "member": {
  21846. "type": "array",
  21847. "items": {
  21848. "$ref": "#agent"
  21849. }
  21850. }
  21851. }
  21852. },
  21853. "anonymousgroup": {
  21854. "id": "#anonymousgroup",
  21855. "properties": {
  21856. "member": {
  21857. "required": true
  21858. },
  21859. "name": {},
  21860. "objectType": {}
  21861. },
  21862. "additionalProperties": false
  21863. },
  21864. "identifiedgroup": {
  21865. "id": "#identifiedgroup",
  21866. "extends": {
  21867. "$ref": "#inversefunctional"
  21868. },
  21869. "properties": {
  21870. "name": {},
  21871. "objectType": {},
  21872. "member": {},
  21873. "mbox": {},
  21874. "mbox_sha1sum": {},
  21875. "account": {},
  21876. "openid": {}
  21877. },
  21878. "additionalProperties": false
  21879. },
  21880. "group": {
  21881. "id": "#group",
  21882. "extends": {
  21883. "$ref": "#groupBasics"
  21884. },
  21885. "type": [
  21886. {
  21887. "$ref": "#anonymousgroup"
  21888. },
  21889. {
  21890. "$ref": "#identifiedgroup"
  21891. }
  21892. ]
  21893. },
  21894. "languagemap": {
  21895. "id": "#languagemap",
  21896. "type": "object",
  21897. "patternProperties": {
  21898. "^(([a-zA-Z]{2,8}((-[a-zA-Z]{3}){0,3})(-[a-zA-Z]{4})?((-[a-zA-Z]{2})|(-\\d{3}))?(-[a-zA-Z\\d]{4,8})*(-[a-zA-Z\\d](-[a-zA-Z\\d]{1,8})+)*)|x(-[a-zA-Z\\d]{1,8})+|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-tsu|i-tay|sgn-BE-FR|sgn-BE-NL|sgn-CH-DE)$": {
  21899. "type": "string"
  21900. }
  21901. },
  21902. "additionalProperties": false
  21903. },
  21904. "extensions": {
  21905. "id": "#extensions",
  21906. "patternProperties": {
  21907. "^[a-zA-Z][a-zA-Z+.-]*:": {
  21908. "type": "any"
  21909. }
  21910. },
  21911. "additionalProperties": false
  21912. },
  21913. "activity": {
  21914. "id": "#activity",
  21915. "type": "object",
  21916. "properties": {
  21917. "id": {
  21918. "type": "string",
  21919. "format": "uri",
  21920. "required": true
  21921. },
  21922. "objectType": {
  21923. "enum": ["Activity"]
  21924. },
  21925. "definition": {
  21926. "type": "object",
  21927. "properties": {
  21928. "name": {
  21929. "$ref": "#languagemap"
  21930. },
  21931. "description": {
  21932. "$ref": "#languagemap"
  21933. },
  21934. "type": {
  21935. "type": "string",
  21936. "format": "uri"
  21937. },
  21938. "interactionType": {
  21939. "enum": [
  21940. "true-false",
  21941. "choice",
  21942. "fill-in",
  21943. "long-fill-in",
  21944. "matching",
  21945. "performance",
  21946. "sequencing",
  21947. "likert",
  21948. "numeric",
  21949. "other"
  21950. ]
  21951. },
  21952. "correctResponsesPattern": {
  21953. "type": "array",
  21954. "items": {
  21955. "type": "string"
  21956. }
  21957. },
  21958. "extensions": {
  21959. "$ref": "#extensions"
  21960. }
  21961. },
  21962. "patternProperties": {
  21963. "^(choices|scale|source|target|steps)$": {
  21964. "type": "object",
  21965. "properties": {
  21966. "id": {
  21967. "type": "string",
  21968. "required": true
  21969. },
  21970. "description": {
  21971. "$ref": "#languagemap"
  21972. }
  21973. },
  21974. "additionalProperties": false
  21975. }
  21976. },
  21977. "additionalProperties": false
  21978. }
  21979. },
  21980. "additionalProperties": false
  21981. },
  21982. "objectagent": {
  21983. "id": "#objectagent",
  21984. "type": [
  21985. {
  21986. "$ref": "#agent"
  21987. }
  21988. ],
  21989. "properties": {
  21990. "objectType": {
  21991. "required": true
  21992. }
  21993. }
  21994. },
  21995. "statementref": {
  21996. "id": "#statementref",
  21997. "type": "object",
  21998. "properties": {
  21999. "objectType": {
  22000. "enum": ["StatementRef"],
  22001. "required": true
  22002. },
  22003. "id": {
  22004. "type": [
  22005. {
  22006. "$ref": "#uuid"
  22007. }
  22008. ],
  22009. "required": true
  22010. }
  22011. },
  22012. "additionalProperties": false
  22013. },
  22014. "substatement": {
  22015. "id": "#substatement",
  22016. "type": [
  22017. {
  22018. "$ref": "#statement"
  22019. }
  22020. ],
  22021. "properties": {
  22022. "objectType": {
  22023. "enum": ["SubStatement"],
  22024. "required": true
  22025. },
  22026. "object": {
  22027. "disallow": [
  22028. {
  22029. "properties": {
  22030. "objectType": {
  22031. "enum": ["SubStatement"]
  22032. }
  22033. }
  22034. }
  22035. ]
  22036. }
  22037. },
  22038. "patternProperties": {
  22039. "^(id|stored|authority|voided)$": {
  22040. "type": "null"
  22041. }
  22042. }
  22043. },
  22044. "statement": {
  22045. "id": "#statement",
  22046. "type": "object",
  22047. "properties": {
  22048. "id": {
  22049. "$ref": "#uuid"
  22050. },
  22051. "actor": {
  22052. "type": [
  22053. {
  22054. "$ref": "#agent"
  22055. },
  22056. {
  22057. "$ref": "#group"
  22058. }
  22059. ],
  22060. "required": true
  22061. },
  22062. "verb": {
  22063. "required": true,
  22064. "type": "object",
  22065. "properties": {
  22066. "id": {
  22067. "required": true,
  22068. "type": "string",
  22069. "format": "uri"
  22070. },
  22071. "display": {
  22072. "$ref": "#languagemap"
  22073. }
  22074. },
  22075. "additionalProperties": false
  22076. },
  22077. "object": {
  22078. "type": [
  22079. {
  22080. "$ref": "#activity"
  22081. },
  22082. {
  22083. "$ref": "#objectagent"
  22084. },
  22085. {
  22086. "$ref": "#group"
  22087. },
  22088. {
  22089. "$ref": "#statementref"
  22090. },
  22091. {
  22092. "$ref": "#substatement"
  22093. }
  22094. ],
  22095. "required": true
  22096. },
  22097. "objectType": {},
  22098. "result": {
  22099. "type": "object",
  22100. "properties": {
  22101. "score": {
  22102. "type": "object",
  22103. "properties": {
  22104. "scaled": {
  22105. "type": "number",
  22106. "minimum": 0,
  22107. "maximum": 1
  22108. },
  22109. "raw": {
  22110. "type": "number"
  22111. },
  22112. "min": {
  22113. "type": "number"
  22114. },
  22115. "max": {
  22116. "type": "number"
  22117. }
  22118. }
  22119. },
  22120. "success": {
  22121. "type": "boolean"
  22122. },
  22123. "completion": {
  22124. "type": "boolean"
  22125. },
  22126. "response": {
  22127. "type": "string"
  22128. },
  22129. "duration": {
  22130. "type": "string"
  22131. },
  22132. "extensions": {
  22133. "$ref": "#extensions"
  22134. }
  22135. },
  22136. "additionalProperties": false
  22137. },
  22138. "context": {
  22139. "type": "object",
  22140. "properties": {
  22141. "registration": {
  22142. "$ref": "#uuid"
  22143. },
  22144. "instructor": {
  22145. "type": [
  22146. {
  22147. "$ref": "#agent"
  22148. },
  22149. {
  22150. "$ref": "#group"
  22151. }
  22152. ]
  22153. },
  22154. "team": {
  22155. "type": [
  22156. {
  22157. "$ref": "#agent"
  22158. },
  22159. {
  22160. "$ref": "#group"
  22161. }
  22162. ]
  22163. },
  22164. "contextActivities": {
  22165. "type": "object",
  22166. "properties": {
  22167. "parent": {
  22168. "$ref": "#activity"
  22169. },
  22170. "grouping": {
  22171. "$ref": "#activity"
  22172. },
  22173. "other": {
  22174. "$ref": "#activity"
  22175. }
  22176. },
  22177. "additionalProperties": false
  22178. },
  22179. "revision": {
  22180. "type": "string"
  22181. },
  22182. "platform": {
  22183. "type": "string"
  22184. },
  22185. "language": {
  22186. "type": "string"
  22187. },
  22188. "statement": {
  22189. "$ref": "#statementref"
  22190. },
  22191. "extensions": {
  22192. "$ref": "#extensions"
  22193. }
  22194. },
  22195. "additionalProperties": false
  22196. },
  22197. "timestamp": {
  22198. "type": "string"
  22199. },
  22200. "stored": {
  22201. "type": "string"
  22202. },
  22203. "authority": {
  22204. "type": [
  22205. {
  22206. "$ref": "#agent"
  22207. },
  22208. {
  22209. "type": [
  22210. {
  22211. "$ref": "#anonymousgroup"
  22212. }
  22213. ],
  22214. "properties": {
  22215. "member": {
  22216. "type": "array",
  22217. "minItems": 2,
  22218. "maxItems": 2
  22219. }
  22220. }
  22221. }
  22222. ]
  22223. },
  22224. "voided": {
  22225. "type": "boolean"
  22226. }
  22227. },
  22228. "additionalProperties": false
  22229. }
  22230. }
  22231. },
  22232. data: {
  22233. "id": "fd41c918-b88b-4b20-a0a5-a4c32391aaa0",
  22234. "actor": {
  22235. "objectType": "Blowup",
  22236. "name": "Project Tin Can API",
  22237. "mbox": "mailto:user@example.com"
  22238. },
  22239. "verb": {
  22240. "id": "http://adlnet.gov/expapi/verbs/created",
  22241. "display": {
  22242. "en-US": "created"
  22243. }
  22244. },
  22245. "object": {
  22246. "id": "http://example.adlnet.gov/xapi/example/simplestatement",
  22247. "definition": {
  22248. "name": {
  22249. "en-US": "simple statement"
  22250. },
  22251. "description": {
  22252. "en-US": "A simple Experience API statement. Note that the LRS does not need to have any prior information about the Actor (learner), the verb, or the Activity/object."
  22253. }
  22254. }
  22255. }
  22256. },
  22257. valid: false
  22258. }
  22259. ]
  22260. };
  22261. },{}],210:[function(require,module,exports){
  22262. "use strict";
  22263. module.exports = {
  22264. description: "Issue #64 - fix inconsistent error paths for missing reference errors",
  22265. tests: [
  22266. {
  22267. description: "should fail validation and report correct error path",
  22268. schema: {
  22269. type: "object",
  22270. properties: {
  22271. name: {
  22272. type: "string"
  22273. },
  22274. friends: {
  22275. type: "array",
  22276. items: {
  22277. $ref: "Person.json"
  22278. }
  22279. }
  22280. }
  22281. },
  22282. valid: false,
  22283. validateSchemaOnly: true,
  22284. after: function (err) {
  22285. expect(err[0].path).toEqual("#/properties/friends/items");
  22286. }
  22287. }
  22288. ]
  22289. };
  22290. },{}],211:[function(require,module,exports){
  22291. "use strict";
  22292. module.exports = {
  22293. description: "Issue #67 - references problem",
  22294. tests: [
  22295. {
  22296. description: "should pass validation #1",
  22297. setup: function (validator, Class) {
  22298. Class.registerFormat("not-blank", function () {
  22299. return true;
  22300. });
  22301. },
  22302. schema: [
  22303. {
  22304. "$schema": "http://json-schema.org/draft-04/schema#",
  22305. "id": "NaturalNumber",
  22306. "type": "integer",
  22307. "minimum": 1
  22308. },
  22309. {
  22310. "$schema": "http://json-schema.org/draft-04/schema#",
  22311. "id": "WholeNumber",
  22312. "type": "integer"
  22313. },
  22314. {
  22315. "$schema": "http://json-schema.org/draft-04/schema#",
  22316. "id": "NotEmptyString",
  22317. "type": "string",
  22318. "minLength": 1
  22319. },
  22320. {
  22321. "$schema": "http://json-schema.org/draft-04/schema#",
  22322. "id": "NotBlankString",
  22323. "allOf": [
  22324. {
  22325. "$ref": "NotEmptyString"
  22326. },
  22327. {
  22328. "type": "string",
  22329. "format": "not-blank"
  22330. }
  22331. ]
  22332. }
  22333. ],
  22334. validateSchemaOnly: true,
  22335. valid: true
  22336. }
  22337. ]
  22338. };
  22339. },{}],212:[function(require,module,exports){
  22340. "use strict";
  22341. module.exports = {
  22342. description: "Issue #71 - additionalProperties problem",
  22343. tests: [
  22344. {
  22345. description: "should have two errors #1",
  22346. schema: {
  22347. type: "object",
  22348. minProperties: 1,
  22349. additionalProperties: false,
  22350. properties: {
  22351. foo: {
  22352. type: "object",
  22353. minProperties: 1
  22354. }
  22355. }
  22356. },
  22357. data: { foo: {}, bar: 1 },
  22358. valid: false,
  22359. after: function (errors) {
  22360. expect(errors.length).toBe(2);
  22361. }
  22362. },
  22363. {
  22364. description: "should have two errors #2",
  22365. schema: {
  22366. type: "object",
  22367. minProperties: 1,
  22368. additionalProperties: false,
  22369. properties: {
  22370. foo: {
  22371. type: "object",
  22372. minProperties: 1,
  22373. additionalProperties: false,
  22374. properties: {
  22375. foo: {}
  22376. }
  22377. }
  22378. }
  22379. },
  22380. data: { foo: {}, bar: 1 },
  22381. valid: false,
  22382. after: function (errors) {
  22383. expect(errors.length).toBe(2);
  22384. }
  22385. },
  22386. {
  22387. description: "should have more than one error with breakOnFirstError false #1",
  22388. options: {
  22389. breakOnFirstError: false
  22390. },
  22391. schema: {
  22392. type: "object",
  22393. minProperties: 1,
  22394. additionalProperties: false,
  22395. properties: {
  22396. foo: {
  22397. type: "object",
  22398. minProperties: 1
  22399. }
  22400. }
  22401. },
  22402. data: { foo: {}, bar: 1 },
  22403. valid: false,
  22404. after: function (errors) {
  22405. expect(errors.length).toBeGreaterThan(1);
  22406. }
  22407. },
  22408. {
  22409. description: "should have more than one error with breakOnFirstError false #2",
  22410. options: {
  22411. breakOnFirstError: false
  22412. },
  22413. schema: {
  22414. type: "object",
  22415. minProperties: 1,
  22416. additionalProperties: false,
  22417. properties: {
  22418. foo: {
  22419. type: "object",
  22420. minProperties: 1,
  22421. additionalProperties: false,
  22422. properties: {
  22423. foo: {}
  22424. }
  22425. }
  22426. }
  22427. },
  22428. data: { foo: {}, bar: 1 },
  22429. valid: false,
  22430. after: function (errors) {
  22431. expect(errors.length).toBeGreaterThan(1);
  22432. }
  22433. }
  22434. ]
  22435. };
  22436. },{}],213:[function(require,module,exports){
  22437. "use strict";
  22438. module.exports = {
  22439. description: "Issue #73 - getLastError method should return an instance of native Error",
  22440. tests: [
  22441. {
  22442. description: "should pass the basic test",
  22443. schema: {
  22444. id: "schemaA",
  22445. type: "object",
  22446. properties: {
  22447. a: {
  22448. type: "integer"
  22449. },
  22450. b: {
  22451. type: "string"
  22452. },
  22453. c: {
  22454. $ref: "schemaB"
  22455. }
  22456. },
  22457. required: ["a"]
  22458. },
  22459. validateSchemaOnly: true,
  22460. valid: false,
  22461. after: function (err, valid, data, validator) {
  22462. var e = validator.getLastError();
  22463. expect(e instanceof Error).toBe(true);
  22464. expect(e.message).toBe("SCHEMA_COMPILATION_FAILED");
  22465. }
  22466. },
  22467. {
  22468. description: "should pass the basic test",
  22469. data: { "b": true },
  22470. schema: {
  22471. id: "schemaA",
  22472. type: "object",
  22473. properties: {
  22474. a: {
  22475. type: "integer"
  22476. },
  22477. b: {
  22478. type: "string"
  22479. }
  22480. },
  22481. required: ["a"]
  22482. },
  22483. valid: false,
  22484. after: function (err, valid, data, validator) {
  22485. var e = validator.getLastError();
  22486. expect(e instanceof Error).toBe(true);
  22487. expect(e.message).toBe("JSON_OBJECT_VALIDATION_FAILED");
  22488. }
  22489. }
  22490. ]
  22491. };
  22492. },{}],214:[function(require,module,exports){
  22493. "use strict";
  22494. module.exports = {
  22495. description: "Issue #76 - circular dependencies between schemas",
  22496. tests: [
  22497. {
  22498. description: "should pass validation",
  22499. schema: [
  22500. {
  22501. id: "id",
  22502. type: "number"
  22503. },
  22504. {
  22505. id: "user",
  22506. type: "object",
  22507. properties: {
  22508. id: {
  22509. $ref: "id"
  22510. },
  22511. posts: {
  22512. type: "array",
  22513. items: {
  22514. $ref: "post"
  22515. }
  22516. }
  22517. }
  22518. },
  22519. {
  22520. id: "post",
  22521. type: "object",
  22522. properties: {
  22523. id: {
  22524. $ref: "id"
  22525. },
  22526. author: {
  22527. $ref: "user"
  22528. }
  22529. }
  22530. }
  22531. ],
  22532. schemaIndex: 2,
  22533. data: {
  22534. id: 11,
  22535. author: {
  22536. id: 1,
  22537. posts: [
  22538. {
  22539. id: 11,
  22540. author: {
  22541. id: 1
  22542. }
  22543. },
  22544. {
  22545. id: 12,
  22546. author: {
  22547. id: 1
  22548. }
  22549. },
  22550. {
  22551. id: 13,
  22552. author: {
  22553. id: 1
  22554. }
  22555. }
  22556. ]
  22557. }
  22558. },
  22559. valid: true
  22560. }
  22561. ]
  22562. };
  22563. },{}],215:[function(require,module,exports){
  22564. "use strict";
  22565. var innerSchema = {
  22566. type: "integer"
  22567. };
  22568. var originalSchema = {
  22569. type: "object",
  22570. properties: {
  22571. inner: innerSchema
  22572. }
  22573. };
  22574. var getKeys = function (obj) {
  22575. var arr = [];
  22576. for (var key in obj) {
  22577. if (obj.hasOwnProperty(key)) {
  22578. arr.push(key);
  22579. }
  22580. }
  22581. return arr;
  22582. };
  22583. var originalSchemaKeys = getKeys(originalSchema);
  22584. var innerSchemaKeys = getKeys(innerSchema);
  22585. module.exports = {
  22586. description: "Issue #85 - zschema shouldn't have side effects on the schema object",
  22587. tests: [
  22588. {
  22589. description: "should pass validation",
  22590. schema: originalSchema,
  22591. data: {
  22592. inner: 5
  22593. },
  22594. valid: true,
  22595. after: function () {
  22596. expect(getKeys(originalSchema).length).toBe(originalSchemaKeys.length);
  22597. expect(getKeys(innerSchemaKeys).length).toBe(innerSchemaKeys.length);
  22598. }
  22599. }
  22600. ]
  22601. };
  22602. },{}],216:[function(require,module,exports){
  22603. "use strict";
  22604. var schema1 = {
  22605. "id": "long-string",
  22606. "type": "string",
  22607. "maxLength": 4096
  22608. };
  22609. var schema2 = {
  22610. "id": "person-object",
  22611. "type": "object",
  22612. "properties": {
  22613. "name": {
  22614. "$ref": "long-string"
  22615. }
  22616. }
  22617. };
  22618. var expectedResult = {
  22619. "id": "person-object",
  22620. "type": "object",
  22621. "properties": {
  22622. "name": {
  22623. "id": "long-string",
  22624. "type": "string",
  22625. "maxLength": 4096
  22626. }
  22627. }
  22628. };
  22629. module.exports = {
  22630. description: "Issue #94 - get a resolved schema for documentation purposes",
  22631. tests: [
  22632. {
  22633. description: "should pass validation",
  22634. schema: [schema1, schema2],
  22635. validateSchemaOnly: true,
  22636. valid: true,
  22637. after: function (err, valid, data, validator) {
  22638. var newSch = validator.getResolvedSchema("person-object");
  22639. expect(JSON.stringify(newSch)).toBe(JSON.stringify(expectedResult));
  22640. }
  22641. }
  22642. ]
  22643. };
  22644. },{}],217:[function(require,module,exports){
  22645. "use strict";
  22646. module.exports = {
  22647. description: "Issue #96 - email format validation false negatives",
  22648. schema: {
  22649. type: "string",
  22650. format: "email"
  22651. },
  22652. tests: [
  22653. {
  22654. description: "should pass validation #1",
  22655. data: "my_email@gmail.com",
  22656. valid: true
  22657. }
  22658. ]
  22659. };
  22660. },{}],218:[function(require,module,exports){
  22661. "use strict";
  22662. module.exports = {
  22663. description: "Issue #98 - oneOf",
  22664. tests: [
  22665. {
  22666. description: "should return only one error for each branch",
  22667. schema: {
  22668. "type": "object",
  22669. "oneOf": [
  22670. {
  22671. "type": "object",
  22672. "required": ["a", "b"]
  22673. },
  22674. {
  22675. "type": "object",
  22676. "required": ["c", "d"]
  22677. }
  22678. ]
  22679. },
  22680. data: {},
  22681. valid: false,
  22682. after: function (err, valid, data, validator) {
  22683. expect(err.length).toBe(1);
  22684. expect(err[0].code).toBe("ONE_OF_MISSING");
  22685. expect(err[0].inner.length).toBe(2);
  22686. }
  22687. }
  22688. ]
  22689. };
  22690. },{}],219:[function(require,module,exports){
  22691. "use strict";
  22692. module.exports = {
  22693. description: "compile a schema array and validate against one of the schemas - README sample",
  22694. tests: [
  22695. {
  22696. description: "should validate object successfully",
  22697. schema: [
  22698. {
  22699. id: "personDetails",
  22700. type: "object",
  22701. properties: {
  22702. firstName: {
  22703. type: "string"
  22704. },
  22705. lastName: {
  22706. type: "string"
  22707. }
  22708. },
  22709. required: ["firstName", "lastName"]
  22710. },
  22711. {
  22712. id: "addressDetails",
  22713. type: "object",
  22714. properties: {
  22715. street: {
  22716. type: "string"
  22717. },
  22718. city: {
  22719. type: "string"
  22720. }
  22721. },
  22722. required: ["street", "city"]
  22723. },
  22724. {
  22725. id: "personWithAddress",
  22726. allOf: [
  22727. {
  22728. $ref: "personDetails"
  22729. },
  22730. {
  22731. $ref: "addressDetails"
  22732. }
  22733. ]
  22734. }
  22735. ],
  22736. schemaIndex: 2,
  22737. data: {
  22738. firstName: "Martin",
  22739. lastName: "Zagora",
  22740. street: "George St",
  22741. city: "Sydney"
  22742. },
  22743. valid: true
  22744. }
  22745. ]
  22746. };
  22747. },{}],220:[function(require,module,exports){
  22748. "use strict";
  22749. module.exports = {
  22750. description: "noEmptyArrays - Don't allow empty arrays to validate as arrays",
  22751. options: {
  22752. noEmptyArrays: true
  22753. },
  22754. schema: {
  22755. "type": "array"
  22756. },
  22757. tests: [
  22758. {
  22759. description: "should pass validation when having one item array",
  22760. data: ["item"],
  22761. valid: true
  22762. },
  22763. {
  22764. description: "should fail validation when having empty array",
  22765. data: [],
  22766. valid: false
  22767. }
  22768. ]
  22769. };
  22770. },{}],221:[function(require,module,exports){
  22771. "use strict";
  22772. module.exports = {
  22773. description: "noEmptyStrings - Don't allow empty strings to validate as strings",
  22774. options: {
  22775. noEmptyStrings: true
  22776. },
  22777. schema: {
  22778. "type": "string"
  22779. },
  22780. tests: [
  22781. {
  22782. description: "should pass validation when using a proper string",
  22783. data: "hello",
  22784. valid: true
  22785. },
  22786. {
  22787. description: "should fail validation when using an empty string",
  22788. data: "",
  22789. valid: false
  22790. }
  22791. ]
  22792. };
  22793. },{}],222:[function(require,module,exports){
  22794. "use strict";
  22795. module.exports = {
  22796. description: "noExtraKeywords - Forbid unrecognized keywords to be defined in schemas",
  22797. options: {
  22798. noExtraKeywords: true
  22799. },
  22800. validateSchemaOnly: true,
  22801. tests: [
  22802. {
  22803. schema: {},
  22804. description: "should pass schema validation",
  22805. valid: true
  22806. },
  22807. {
  22808. schema: {
  22809. "random_keyword": "string"
  22810. },
  22811. description: "should fail schema validation, because 'random_keyword' is not known keyword",
  22812. valid: false
  22813. },
  22814. {
  22815. schema: {
  22816. "$schema": "http://json-schema.org/draft-04/schema#",
  22817. "random_keyword": "string"
  22818. },
  22819. description: "should pass schema validation, because schema is validated by $schema, even though it has 'random_keyword'",
  22820. valid: true
  22821. },
  22822. {
  22823. schema: {
  22824. "$schema": "http://json-schema.org/draft-04/schema#",
  22825. "title": 1
  22826. },
  22827. description: "should fail schema validation, because schema is validated by $schema and number is not valid for title",
  22828. valid: false,
  22829. after: function (err, valid) {
  22830. expect(valid).toBe(false);
  22831. expect(err[0].code).toBe("PARENT_SCHEMA_VALIDATION_FAILED");
  22832. }
  22833. }
  22834. ]
  22835. };
  22836. },{}],223:[function(require,module,exports){
  22837. "use strict";
  22838. module.exports = {
  22839. description: "noTypeless - Don't allow schemas without type specified",
  22840. validateSchemaOnly: true,
  22841. options: {
  22842. noTypeless: true
  22843. },
  22844. tests: [
  22845. {
  22846. description: "should pass validation when using a type in schema",
  22847. schema: {
  22848. "type": "string"
  22849. },
  22850. valid: true
  22851. },
  22852. {
  22853. description: "should fail validation when not using a type in schema",
  22854. schema: {},
  22855. valid: false
  22856. }
  22857. ]
  22858. };
  22859. },{}],224:[function(require,module,exports){
  22860. "use strict";
  22861. module.exports = {
  22862. description: "pedanticCheck - check if schema follow best practices and common sense",
  22863. options: {
  22864. pedanticCheck: true,
  22865. breakOnFirstError: false
  22866. },
  22867. validateSchemaOnly: true,
  22868. tests: [
  22869. {
  22870. schema: {
  22871. "type": "string",
  22872. "default": true
  22873. },
  22874. description: "should fail schema validation because default has incorrect value",
  22875. valid: false
  22876. },
  22877. {
  22878. schema: {
  22879. "type": "string",
  22880. "enum": ["OK", false]
  22881. },
  22882. description: "should fail schema validation because enum has incorrect value",
  22883. valid: false
  22884. },
  22885. {
  22886. schema: {
  22887. "type": "string",
  22888. "enum": ["OK", false],
  22889. "default": true
  22890. },
  22891. description: "should fail schema validation because both enum and default has incorrect values",
  22892. valid: false
  22893. }
  22894. ]
  22895. };
  22896. },{}],225:[function(require,module,exports){
  22897. "use strict";
  22898. module.exports = {
  22899. description: "strictUris - validates URIs as absolute and disallow URI references",
  22900. options: {
  22901. strictUris: true
  22902. },
  22903. tests: [
  22904. {
  22905. schema: {
  22906. "type": "string",
  22907. "format": "uri"
  22908. },
  22909. data: "http://json-schema.org/draft-04/schema",
  22910. description: "should pass validation because it is an absolute URI",
  22911. valid: true
  22912. },
  22913. {
  22914. schema: {
  22915. "type": "string",
  22916. "format": "uri"
  22917. },
  22918. data: "schemaA",
  22919. description: "should fail validation because it is only a valid URI reference",
  22920. valid: false
  22921. }
  22922. ]
  22923. };
  22924. },{}],226:[function(require,module,exports){
  22925. module.exports={
  22926. "id": "http://json-schema.org/draft-04/schema#",
  22927. "$schema": "http://json-schema.org/draft-04/schema#",
  22928. "description": "Core schema meta-schema",
  22929. "definitions": {
  22930. "schemaArray": {
  22931. "type": "array",
  22932. "minItems": 1,
  22933. "items": { "$ref": "#" }
  22934. },
  22935. "positiveInteger": {
  22936. "type": "integer",
  22937. "minimum": 0
  22938. },
  22939. "positiveIntegerDefault0": {
  22940. "allOf": [ { "$ref": "#/definitions/positiveInteger" }, { "default": 0 } ]
  22941. },
  22942. "simpleTypes": {
  22943. "enum": [ "array", "boolean", "integer", "null", "number", "object", "string" ]
  22944. },
  22945. "stringArray": {
  22946. "type": "array",
  22947. "items": { "type": "string" },
  22948. "minItems": 1,
  22949. "uniqueItems": true
  22950. }
  22951. },
  22952. "type": "object",
  22953. "properties": {
  22954. "id": {
  22955. "type": "string",
  22956. "format": "uri"
  22957. },
  22958. "$schema": {
  22959. "type": "string",
  22960. "format": "uri"
  22961. },
  22962. "title": {
  22963. "type": "string"
  22964. },
  22965. "description": {
  22966. "type": "string"
  22967. },
  22968. "default": {},
  22969. "multipleOf": {
  22970. "type": "number",
  22971. "minimum": 0,
  22972. "exclusiveMinimum": true
  22973. },
  22974. "maximum": {
  22975. "type": "number"
  22976. },
  22977. "exclusiveMaximum": {
  22978. "type": "boolean",
  22979. "default": false
  22980. },
  22981. "minimum": {
  22982. "type": "number"
  22983. },
  22984. "exclusiveMinimum": {
  22985. "type": "boolean",
  22986. "default": false
  22987. },
  22988. "maxLength": { "$ref": "#/definitions/positiveInteger" },
  22989. "minLength": { "$ref": "#/definitions/positiveIntegerDefault0" },
  22990. "pattern": {
  22991. "type": "string",
  22992. "format": "regex"
  22993. },
  22994. "additionalItems": {
  22995. "anyOf": [
  22996. { "type": "boolean" },
  22997. { "$ref": "#" }
  22998. ],
  22999. "default": {}
  23000. },
  23001. "items": {
  23002. "anyOf": [
  23003. { "$ref": "#" },
  23004. { "$ref": "#/definitions/schemaArray" }
  23005. ],
  23006. "default": {}
  23007. },
  23008. "maxItems": { "$ref": "#/definitions/positiveInteger" },
  23009. "minItems": { "$ref": "#/definitions/positiveIntegerDefault0" },
  23010. "uniqueItems": {
  23011. "type": "boolean",
  23012. "default": false
  23013. },
  23014. "maxProperties": { "$ref": "#/definitions/positiveInteger" },
  23015. "minProperties": { "$ref": "#/definitions/positiveIntegerDefault0" },
  23016. "required": { "$ref": "#/definitions/stringArray" },
  23017. "additionalProperties": {
  23018. "anyOf": [
  23019. { "type": "boolean" },
  23020. { "$ref": "#" }
  23021. ],
  23022. "default": {}
  23023. },
  23024. "definitions": {
  23025. "type": "object",
  23026. "additionalProperties": { "$ref": "#" },
  23027. "default": {}
  23028. },
  23029. "properties": {
  23030. "type": "object",
  23031. "additionalProperties": { "$ref": "#" },
  23032. "default": {}
  23033. },
  23034. "patternProperties": {
  23035. "type": "object",
  23036. "additionalProperties": { "$ref": "#" },
  23037. "default": {}
  23038. },
  23039. "dependencies": {
  23040. "type": "object",
  23041. "additionalProperties": {
  23042. "anyOf": [
  23043. { "$ref": "#" },
  23044. { "$ref": "#/definitions/stringArray" }
  23045. ]
  23046. }
  23047. },
  23048. "enum": {
  23049. "type": "array",
  23050. "minItems": 1,
  23051. "uniqueItems": true
  23052. },
  23053. "type": {
  23054. "anyOf": [
  23055. { "$ref": "#/definitions/simpleTypes" },
  23056. {
  23057. "type": "array",
  23058. "items": { "$ref": "#/definitions/simpleTypes" },
  23059. "minItems": 1,
  23060. "uniqueItems": true
  23061. }
  23062. ]
  23063. },
  23064. "allOf": { "$ref": "#/definitions/schemaArray" },
  23065. "anyOf": { "$ref": "#/definitions/schemaArray" },
  23066. "oneOf": { "$ref": "#/definitions/schemaArray" },
  23067. "not": { "$ref": "#" }
  23068. },
  23069. "dependencies": {
  23070. "exclusiveMaximum": [ "maximum" ],
  23071. "exclusiveMinimum": [ "minimum" ]
  23072. },
  23073. "default": {}
  23074. }
  23075. },{}],227:[function(require,module,exports){
  23076. module.exports={
  23077. "swagger": 2,
  23078. "info": {
  23079. "version": "1.0.0",
  23080. "title": "Swagger Petstore",
  23081. "contact": {
  23082. "name": "wordnik api team",
  23083. "url": "http://developer.wordnik.com"
  23084. },
  23085. "license": {
  23086. "name": "Creative Commons 4.0 International",
  23087. "url": "http://creativecommons.org/licenses/by/4.0/"
  23088. }
  23089. },
  23090. "host": "http://petstore.swagger.wordnik.com",
  23091. "basePath": "/api",
  23092. "schemes": [
  23093. "http"
  23094. ],
  23095. "paths": {
  23096. "/pets": {
  23097. "get": {
  23098. "tags": [
  23099. "Pet Operations"
  23100. ],
  23101. "summary": "finds pets in the system",
  23102. "responses": {
  23103. "200": {
  23104. "description": "pet response",
  23105. "schema": {
  23106. "type": "array",
  23107. "items": {
  23108. "$ref": "#/models/Pet"
  23109. }
  23110. },
  23111. "headers": [
  23112. {
  23113. "x-expires": {
  23114. "type": "string"
  23115. }
  23116. }
  23117. ]
  23118. },
  23119. "default": {
  23120. "description": "unexpected error",
  23121. "schema": {
  23122. "$ref": "#/models/Error"
  23123. }
  23124. }
  23125. }
  23126. }
  23127. }
  23128. },
  23129. "schemas": {
  23130. "Pet": {
  23131. "required": [
  23132. "id",
  23133. "name"
  23134. ],
  23135. "properties": {
  23136. "id": {
  23137. "type": "integer",
  23138. "format": "int64"
  23139. },
  23140. "name": {
  23141. "type": "string"
  23142. },
  23143. "tag": {
  23144. "type": "string"
  23145. }
  23146. }
  23147. },
  23148. "Error": {
  23149. "required": [
  23150. "code",
  23151. "message"
  23152. ],
  23153. "properties": {
  23154. "code": {
  23155. "type": "integer",
  23156. "format": "int32"
  23157. },
  23158. "message": {
  23159. "type": "string"
  23160. }
  23161. }
  23162. }
  23163. }
  23164. }
  23165. },{}],228:[function(require,module,exports){
  23166. module.exports={
  23167. "title": "A JSON Schema for Swagger 2.0 API.",
  23168. "$schema": "http://json-schema.org/draft-04/schema#",
  23169. "type": "object",
  23170. "required": [ "swagger", "info", "paths" ],
  23171. "definitions": {
  23172. "info": {
  23173. "type": "object",
  23174. "description": "General information about the API.",
  23175. "required": [ "version", "title" ],
  23176. "additionalProperties": false,
  23177. "patternProperties": {
  23178. "^x-": {
  23179. "$ref": "#/definitions/vendorExtension"
  23180. }
  23181. },
  23182. "properties": {
  23183. "version": {
  23184. "type": "string",
  23185. "description": "A semantic version number of the API."
  23186. },
  23187. "title": {
  23188. "type": "string",
  23189. "description": "A unique and precise title of the API."
  23190. },
  23191. "description": {
  23192. "type": "string",
  23193. "description": "A longer description of the API. Should be different from the title."
  23194. },
  23195. "termsOfService": {
  23196. "type": "string",
  23197. "description": "The terms of service for the API."
  23198. },
  23199. "contact": {
  23200. "type": "object",
  23201. "description": "Contact information for the owners of the API.",
  23202. "additionalProperties": false,
  23203. "properties": {
  23204. "name": {
  23205. "type": "string",
  23206. "description": "The identifying name of the contact person/organization."
  23207. },
  23208. "url": {
  23209. "type": "string",
  23210. "description": "The URL pointing to the contact information.",
  23211. "format": "uri"
  23212. },
  23213. "email": {
  23214. "type": "string",
  23215. "description": "The email address of the contact person/organization.",
  23216. "format": "email"
  23217. }
  23218. }
  23219. },
  23220. "license": {
  23221. "type": "object",
  23222. "required": [ "name" ],
  23223. "additionalProperties": false,
  23224. "properties": {
  23225. "name": {
  23226. "type": "string",
  23227. "description": "The name of the license type. It's encouraged to use an OSI compatible license."
  23228. },
  23229. "url": {
  23230. "type": "string",
  23231. "description": "The URL pointing to the license.",
  23232. "format": "uri"
  23233. }
  23234. }
  23235. }
  23236. }
  23237. },
  23238. "example": {
  23239. "type": "object",
  23240. "patternProperties": {
  23241. "^[a-z0-9-]+/[a-z0-9-+]+$": {}
  23242. },
  23243. "additionalProperties": false
  23244. },
  23245. "mimeType": {
  23246. "type": "string",
  23247. "pattern": "^[a-z0-9-]+/[a-z0-9-+]+$",
  23248. "description": "The MIME type of the HTTP message."
  23249. },
  23250. "operation": {
  23251. "type": "object",
  23252. "required": [ "responses" ],
  23253. "additionalProperties": false,
  23254. "patternProperties": {
  23255. "^x-": {
  23256. "$ref": "#/definitions/vendorExtension"
  23257. }
  23258. },
  23259. "properties": {
  23260. "tags": {
  23261. "type": "array",
  23262. "items": {
  23263. "type": "string"
  23264. }
  23265. },
  23266. "summary": {
  23267. "type": "string",
  23268. "description": "A brief summary of the operation."
  23269. },
  23270. "description": {
  23271. "type": "string",
  23272. "description": "A longer description of the operation."
  23273. },
  23274. "operationId": {
  23275. "type": "string",
  23276. "description": "A friendly name of the operation"
  23277. },
  23278. "produces": {
  23279. "type": "array",
  23280. "description": "A list of MIME types the API can produce.",
  23281. "additionalItems": false,
  23282. "items": {
  23283. "$ref": "#/definitions/mimeType"
  23284. }
  23285. },
  23286. "parameters": {
  23287. "type": "array",
  23288. "description": "The parameters needed to send a valid API call.",
  23289. "minItems": 1,
  23290. "additionalItems": false,
  23291. "items": {
  23292. "$ref": "#/definitions/parameter"
  23293. }
  23294. },
  23295. "responses": {
  23296. "$ref": "#/definitions/responses"
  23297. },
  23298. "schemes": {
  23299. "type": "array",
  23300. "description": "The transfer protocol of the API.",
  23301. "items": {
  23302. "type": "string",
  23303. "enum": [ "http", "https", "ws", "wss" ]
  23304. }
  23305. }
  23306. }
  23307. },
  23308. "responses": {
  23309. "type": "object",
  23310. "description": "Response objects names can either be any valid HTTP status code or 'default'.",
  23311. "minProperties": 1,
  23312. "additionalProperties": false,
  23313. "patternProperties": {
  23314. "^([0-9]+)$|^(default)$": {
  23315. "$ref": "#/definitions/response"
  23316. },
  23317. "^x-": {
  23318. "$ref": "#/definitions/vendorExtension"
  23319. }
  23320. }
  23321. },
  23322. "response": {
  23323. "type": "object",
  23324. "required": [ "description" ],
  23325. "properties": {
  23326. "description": {
  23327. "type": "string"
  23328. },
  23329. "schema": {
  23330. "$ref": "#/definitions/schema"
  23331. },
  23332. "headers": {
  23333. "type": "array",
  23334. "items": {
  23335. "$ref": "#/definitions/schema"
  23336. }
  23337. },
  23338. "examples": {
  23339. "$ref": "#/definitions/example"
  23340. }
  23341. },
  23342. "additionalProperties": false
  23343. },
  23344. "vendorExtension": {
  23345. "description": "Any property starting with x- is valid.",
  23346. "additionalProperties": true,
  23347. "additionalItems": true
  23348. },
  23349. "parameter": {
  23350. "type": "object",
  23351. "required": [ "name", "in"],
  23352. "patternProperties": {
  23353. "^x-": {
  23354. "$ref": "#/definitions/vendorExtension"
  23355. }
  23356. },
  23357. "properties": {
  23358. "name": {
  23359. "type": "string",
  23360. "description": "The name of the parameter."
  23361. },
  23362. "in": {
  23363. "type": "string",
  23364. "description": "Determines the location of the parameter.",
  23365. "enum": [ "query", "header", "path", "formData", "body" ],
  23366. "default": "query"
  23367. },
  23368. "description": {
  23369. "type": "string",
  23370. "description": "A brief description of the parameter. This could contain examples of use."
  23371. },
  23372. "required": {
  23373. "type": "boolean",
  23374. "description": "Determines whether or not this parameter is required or optional."
  23375. },
  23376. "schema": {
  23377. "$ref": "#/definitions/schema"
  23378. }
  23379. }
  23380. },
  23381. "schema": {
  23382. "type": "object",
  23383. "description": "A deterministic version of a JSON Schema object.",
  23384. "patternProperties": {
  23385. "^x-": {
  23386. "$ref": "#/definitions/vendorExtension"
  23387. }
  23388. },
  23389. "properties": {
  23390. "$ref": { "type": "string" },
  23391. "format": { "type": "string" },
  23392. "title": { "$ref": "http://json-schema.org/draft-04/schema#/properties/title" },
  23393. "description": { "$ref": "http://json-schema.org/draft-04/schema#/properties/description" },
  23394. "default": { "$ref": "http://json-schema.org/draft-04/schema#/properties/default" },
  23395. "multipleOf": { "$ref": "http://json-schema.org/draft-04/schema#/properties/multipleOf" },
  23396. "maximum": { "$ref": "http://json-schema.org/draft-04/schema#/properties/maximum" },
  23397. "exclusiveMaximum": { "$ref": "http://json-schema.org/draft-04/schema#/properties/exclusiveMaximum" },
  23398. "minimum": { "$ref": "http://json-schema.org/draft-04/schema#/properties/minimum" },
  23399. "exclusiveMinimum": { "$ref": "http://json-schema.org/draft-04/schema#/properties/exclusiveMinimum" },
  23400. "maxLength": { "$ref": "http://json-schema.org/draft-04/schema#/definitions/positiveInteger" },
  23401. "minLength": { "$ref": "http://json-schema.org/draft-04/schema#/definitions/positiveIntegerDefault0" },
  23402. "pattern": { "$ref": "http://json-schema.org/draft-04/schema#/properties/pattern" },
  23403. "discriminator": { "type": "string" },
  23404. "xml": { "$ref": "#/definitions/xml"},
  23405. "items": {
  23406. "anyOf": [
  23407. { "$ref": "#/definitions/schema" },
  23408. {
  23409. "type": "array",
  23410. "minItems": 1,
  23411. "items": { "$ref": "#/definitions/schema" }
  23412. }
  23413. ],
  23414. "default": { }
  23415. },
  23416. "maxItems": { "$ref": "http://json-schema.org/draft-04/schema#/definitions/positiveInteger" },
  23417. "minItems": { "$ref": "http://json-schema.org/draft-04/schema#/definitions/positiveIntegerDefault0" },
  23418. "uniqueItems": { "$ref": "http://json-schema.org/draft-04/schema#/properties/uniqueItems" },
  23419. "maxProperties": { "$ref": "http://json-schema.org/draft-04/schema#/definitions/positiveInteger" },
  23420. "minProperties": { "$ref": "http://json-schema.org/draft-04/schema#/definitions/positiveIntegerDefault0" },
  23421. "required": { "$ref": "http://json-schema.org/draft-04/schema#/definitions/stringArray" },
  23422. "definitions": {
  23423. "type": "object",
  23424. "additionalProperties": { "$ref": "#/definitions/schema" },
  23425. "default": { }
  23426. },
  23427. "properties": {
  23428. "type": "object",
  23429. "additionalProperties": { "$ref": "#/definitions/schema" },
  23430. "default": { }
  23431. },
  23432. "enum": { "$ref": "http://json-schema.org/draft-04/schema#/properties/enum" },
  23433. "type": { "$ref": "http://json-schema.org/draft-04/schema#/properties/type" },
  23434. "allOf": {
  23435. "type": "array",
  23436. "minItems": 1,
  23437. "items": { "$ref": "#/definitions/schema" }
  23438. }
  23439. }
  23440. },
  23441. "xml": {
  23442. "properties": {
  23443. "namespace": { "type": "string" },
  23444. "prefix": { "type": "string" },
  23445. "attribute": { "type": "boolean" },
  23446. "wrapped": { "type": "boolean" }
  23447. },
  23448. "additionalProperties": false
  23449. }
  23450. },
  23451. "additionalProperties": false,
  23452. "patternProperties": {
  23453. "^x-": {
  23454. "$ref": "#/definitions/vendorExtension"
  23455. }
  23456. },
  23457. "properties": {
  23458. "swagger": {
  23459. "type": "number",
  23460. "enum": [ 2.0 ],
  23461. "description": "The Swagger version of this document."
  23462. },
  23463. "info": {
  23464. "$ref": "#/definitions/info"
  23465. },
  23466. "host": {
  23467. "type": "string",
  23468. "format": "uri",
  23469. "description": "The fully qualified URI to the host of the API."
  23470. },
  23471. "basePath": {
  23472. "type": "string",
  23473. "pattern": "^/",
  23474. "description": "The base path to the API. Example: '/api'."
  23475. },
  23476. "schemes": {
  23477. "type": "array",
  23478. "description": "The transfer protocol of the API.",
  23479. "items": {
  23480. "type": "string",
  23481. "enum": [ "http", "https", "ws", "wss" ]
  23482. }
  23483. },
  23484. "consumes": {
  23485. "type": "array",
  23486. "description": "A list of MIME types accepted by the API.",
  23487. "items": {
  23488. "$ref": "#/definitions/mimeType"
  23489. }
  23490. },
  23491. "produces": {
  23492. "type": "array",
  23493. "description": "A list of MIME types the API can produce.",
  23494. "items": {
  23495. "$ref": "#/definitions/mimeType"
  23496. }
  23497. },
  23498. "paths": {
  23499. "type": "object",
  23500. "description": "Relative paths to the individual endpoints. They should be relative to the 'basePath'.",
  23501. "patternProperties": {
  23502. "^x-": {
  23503. "$ref": "#/definitions/vendorExtension"
  23504. }
  23505. },
  23506. "additionalProperties": {
  23507. "type": "object",
  23508. "minProperties": 1,
  23509. "additionalProperties": false,
  23510. "patternProperties": {
  23511. "^x-": {
  23512. "$ref": "#/definitions/vendorExtension"
  23513. }
  23514. },
  23515. "properties": {
  23516. "get": {
  23517. "$ref": "#/definitions/operation"
  23518. },
  23519. "put": {
  23520. "$ref": "#/definitions/operation"
  23521. },
  23522. "post": {
  23523. "$ref": "#/definitions/operation"
  23524. },
  23525. "delete": {
  23526. "$ref": "#/definitions/operation"
  23527. },
  23528. "options": {
  23529. "$ref": "#/definitions/operation"
  23530. },
  23531. "head": {
  23532. "$ref": "#/definitions/operation"
  23533. },
  23534. "patch": {
  23535. "$ref": "#/definitions/operation"
  23536. },
  23537. "parameters": {
  23538. "type": "array",
  23539. "items": {
  23540. "$ref": "#/definitions/parameter"
  23541. }
  23542. }
  23543. }
  23544. }
  23545. },
  23546. "schemas": {
  23547. "type": "object",
  23548. "description": "One or more JSON objects describing the schemas being consumed and produced by the API.",
  23549. "additionalProperties": {
  23550. "$ref": "#/definitions/schema"
  23551. }
  23552. },
  23553. "security": {
  23554. "type": "array"
  23555. }
  23556. }
  23557. }
  23558. },{}],229:[function(require,module,exports){
  23559. module.exports={
  23560. "title": "A JSON Schema for Swagger 2.0 API.",
  23561. "$schema": "http://json-schema.org/draft-04/schema#",
  23562. "type": "object",
  23563. "required": [ "swagger", "info", "paths" ],
  23564. "definitions": {
  23565. "info": {
  23566. "type": "object",
  23567. "description": "General information about the API.",
  23568. "required": [ "version", "title" ],
  23569. "additionalProperties": false,
  23570. "patternProperties": {
  23571. "^x-": {
  23572. "$ref": "#/definitions/vendorExtension"
  23573. }
  23574. },
  23575. "properties": {
  23576. "version": {
  23577. "type": "string",
  23578. "description": "A semantic version number of the API."
  23579. },
  23580. "title": {
  23581. "type": "string",
  23582. "description": "A unique and precise title of the API."
  23583. },
  23584. "description": {
  23585. "type": "string",
  23586. "description": "A longer description of the API. Should be different from the title."
  23587. },
  23588. "termsOfService": {
  23589. "type": "string",
  23590. "description": "The terms of service for the API."
  23591. },
  23592. "contact": {
  23593. "type": "object",
  23594. "description": "Contact information for the owners of the API.",
  23595. "additionalProperties": false,
  23596. "properties": {
  23597. "name": {
  23598. "type": "string",
  23599. "description": "The identifying name of the contact person/organization."
  23600. },
  23601. "url": {
  23602. "type": "string",
  23603. "description": "The URL pointing to the contact information.",
  23604. "format": "uri"
  23605. },
  23606. "email": {
  23607. "type": "string",
  23608. "description": "The email address of the contact person/organization.",
  23609. "format": "email"
  23610. }
  23611. }
  23612. },
  23613. "license": {
  23614. "type": "object",
  23615. "required": [ "name" ],
  23616. "additionalProperties": false,
  23617. "properties": {
  23618. "name": {
  23619. "type": "string",
  23620. "description": "The name of the license type. It's encouraged to use an OSI compatible license."
  23621. },
  23622. "url": {
  23623. "type": "string",
  23624. "description": "The URL pointing to the license.",
  23625. "format": "uri"
  23626. }
  23627. }
  23628. }
  23629. }
  23630. },
  23631. "example": {
  23632. "type": "object",
  23633. "patternProperties": {
  23634. "^[a-z0-9-]+/[a-z0-9-+]+$": {}
  23635. },
  23636. "additionalProperties": false
  23637. },
  23638. "mimeType": {
  23639. "type": "string",
  23640. "pattern": "^[a-z0-9-]+/[a-z0-9-+]+$",
  23641. "description": "The MIME type of the HTTP message."
  23642. },
  23643. "operation": {
  23644. "type": "object",
  23645. "required": [ "responses" ],
  23646. "additionalProperties": false,
  23647. "patternProperties": {
  23648. "^x-": {
  23649. "$ref": "#/definitions/vendorExtension"
  23650. }
  23651. },
  23652. "properties": {
  23653. "tags": {
  23654. "type": "array",
  23655. "items": {
  23656. "type": "string"
  23657. }
  23658. },
  23659. "summary": {
  23660. "type": "string",
  23661. "description": "A brief summary of the operation."
  23662. },
  23663. "description": {
  23664. "type": "string",
  23665. "description": "A longer description of the operation."
  23666. },
  23667. "operationId": {
  23668. "type": "string",
  23669. "description": "A friendly name of the operation"
  23670. },
  23671. "produces": {
  23672. "type": "array",
  23673. "description": "A list of MIME types the API can produce.",
  23674. "additionalItems": false,
  23675. "items": {
  23676. "$ref": "#/definitions/mimeType"
  23677. }
  23678. },
  23679. "parameters": {
  23680. "type": "array",
  23681. "description": "The parameters needed to send a valid API call.",
  23682. "minItems": 1,
  23683. "additionalItems": false,
  23684. "items": {
  23685. "$ref": "#/definitions/parameter"
  23686. }
  23687. },
  23688. "responses": {
  23689. "$ref": "#/definitions/responses"
  23690. },
  23691. "schemes": {
  23692. "type": "array",
  23693. "description": "The transfer protocol of the API.",
  23694. "items": {
  23695. "type": "string",
  23696. "enum": [ "http", "https", "ws", "wss" ]
  23697. }
  23698. }
  23699. }
  23700. },
  23701. "responses": {
  23702. "type": "object",
  23703. "description": "Response objects names can either be any valid HTTP status code or 'default'.",
  23704. "minProperties": 1,
  23705. "additionalProperties": false,
  23706. "patternProperties": {
  23707. "^([0-9]+)$|^(default)$": {
  23708. "$ref": "#/definitions/response"
  23709. },
  23710. "^x-": {
  23711. "$ref": "#/definitions/vendorExtension"
  23712. }
  23713. }
  23714. },
  23715. "response": {
  23716. "type": "object",
  23717. "required": [ "description" ],
  23718. "properties": {
  23719. "description": {
  23720. "type": "string"
  23721. },
  23722. "schema": {
  23723. "$ref": "#/definitions/schema"
  23724. },
  23725. "headers": {
  23726. "type": "array",
  23727. "items": {
  23728. "$ref": "#/definitions/schema"
  23729. }
  23730. },
  23731. "examples": {
  23732. "$ref": "#/definitions/example"
  23733. }
  23734. },
  23735. "additionalProperties": false
  23736. },
  23737. "vendorExtension": {
  23738. "description": "Any property starting with x- is valid.",
  23739. "additionalProperties": true,
  23740. "additionalItems": true
  23741. },
  23742. "parameter": {
  23743. "type": "object",
  23744. "required": [ "name", "in"],
  23745. "patternProperties": {
  23746. "^x-": {
  23747. "$ref": "#/definitions/vendorExtension"
  23748. }
  23749. },
  23750. "properties": {
  23751. "name": {
  23752. "type": "string",
  23753. "description": "The name of the parameter."
  23754. },
  23755. "in": {
  23756. "type": "string",
  23757. "description": "Determines the location of the parameter.",
  23758. "enum": [ "query", "header", "path", "formData", "body" ],
  23759. "default": "query"
  23760. },
  23761. "description": {
  23762. "type": "string",
  23763. "description": "A brief description of the parameter. This could contain examples of use."
  23764. },
  23765. "required": {
  23766. "type": "boolean",
  23767. "description": "Determines whether or not this parameter is required or optional."
  23768. },
  23769. "schema": {
  23770. "$ref": "#/definitions/schema"
  23771. }
  23772. }
  23773. },
  23774. "schema": {
  23775. "type": "object",
  23776. "description": "A deterministic version of a JSON Schema object.",
  23777. "patternProperties": {
  23778. "^x-": {
  23779. "$ref": "#/definitions/vendorExtension"
  23780. }
  23781. },
  23782. "properties": {
  23783. "$ref": { "type": "string" },
  23784. "format": { "type": "string" },
  23785. "title": { "$ref": "http://json-schema.orgx/draft-04/schema#/properties/title" },
  23786. "description": { "$ref": "http://json-schema.orgx/draft-04/schema#/properties/description" },
  23787. "default": { "$ref": "http://json-schema.orgx/draft-04/schema#/properties/default" },
  23788. "multipleOf": { "$ref": "http://json-schema.orgx/draft-04/schema#/properties/multipleOf" },
  23789. "maximum": { "$ref": "http://json-schema.orgx/draft-04/schema#/properties/maximum" },
  23790. "exclusiveMaximum": { "$ref": "http://json-schema.orgx/draft-04/schema#/properties/exclusiveMaximum" },
  23791. "minimum": { "$ref": "http://json-schema.orgx/draft-04/schema#/properties/minimum" },
  23792. "exclusiveMinimum": { "$ref": "http://json-schema.orgx/draft-04/schema#/properties/exclusiveMinimum" },
  23793. "maxLength": { "$ref": "http://json-schema.orgx/draft-04/schema#/definitions/positiveInteger" },
  23794. "minLength": { "$ref": "http://json-schema.orgx/draft-04/schema#/definitions/positiveIntegerDefault0" },
  23795. "pattern": { "$ref": "http://json-schema.orgx/draft-04/schema#/properties/pattern" },
  23796. "discriminator": { "type": "string" },
  23797. "xml": { "$ref": "#/definitions/xml"},
  23798. "items": {
  23799. "anyOf": [
  23800. { "$ref": "#/definitions/schema" },
  23801. {
  23802. "type": "array",
  23803. "minItems": 1,
  23804. "items": { "$ref": "#/definitions/schema" }
  23805. }
  23806. ],
  23807. "default": { }
  23808. },
  23809. "maxItems": { "$ref": "http://json-schema.orgx/draft-04/schema#/definitions/positiveInteger" },
  23810. "minItems": { "$ref": "http://json-schema.orgx/draft-04/schema#/definitions/positiveIntegerDefault0" },
  23811. "uniqueItems": { "$ref": "http://json-schema.orgx/draft-04/schema#/properties/uniqueItems" },
  23812. "maxProperties": { "$ref": "http://json-schema.orgx/draft-04/schema#/definitions/positiveInteger" },
  23813. "minProperties": { "$ref": "http://json-schema.orgx/draft-04/schema#/definitions/positiveIntegerDefault0" },
  23814. "required": { "$ref": "http://json-schema.orgx/draft-04/schema#/definitions/stringArray" },
  23815. "definitions": {
  23816. "type": "object",
  23817. "additionalProperties": { "$ref": "#/definitions/schema" },
  23818. "default": { }
  23819. },
  23820. "properties": {
  23821. "type": "object",
  23822. "additionalProperties": { "$ref": "#/definitions/schema" },
  23823. "default": { }
  23824. },
  23825. "enum": { "$ref": "http://json-schema.orgx/draft-04/schema#/properties/enum" },
  23826. "type": { "$ref": "http://json-schema.orgx/draft-04/schema#/properties/type" },
  23827. "allOf": {
  23828. "type": "array",
  23829. "minItems": 1,
  23830. "items": { "$ref": "#/definitions/schema" }
  23831. }
  23832. }
  23833. },
  23834. "xml": {
  23835. "properties": {
  23836. "namespace": { "type": "string" },
  23837. "prefix": { "type": "string" },
  23838. "attribute": { "type": "boolean" },
  23839. "wrapped": { "type": "boolean" }
  23840. },
  23841. "additionalProperties": false
  23842. }
  23843. },
  23844. "additionalProperties": false,
  23845. "patternProperties": {
  23846. "^x-": {
  23847. "$ref": "#/definitions/vendorExtension"
  23848. }
  23849. },
  23850. "properties": {
  23851. "swagger": {
  23852. "type": "number",
  23853. "enum": [ 2.0 ],
  23854. "description": "The Swagger version of this document."
  23855. },
  23856. "info": {
  23857. "$ref": "#/definitions/info"
  23858. },
  23859. "host": {
  23860. "type": "string",
  23861. "format": "uri",
  23862. "description": "The fully qualified URI to the host of the API."
  23863. },
  23864. "basePath": {
  23865. "type": "string",
  23866. "pattern": "^/",
  23867. "description": "The base path to the API. Example: '/api'."
  23868. },
  23869. "schemes": {
  23870. "type": "array",
  23871. "description": "The transfer protocol of the API.",
  23872. "items": {
  23873. "type": "string",
  23874. "enum": [ "http", "https", "ws", "wss" ]
  23875. }
  23876. },
  23877. "consumes": {
  23878. "type": "array",
  23879. "description": "A list of MIME types accepted by the API.",
  23880. "items": {
  23881. "$ref": "#/definitions/mimeType"
  23882. }
  23883. },
  23884. "produces": {
  23885. "type": "array",
  23886. "description": "A list of MIME types the API can produce.",
  23887. "items": {
  23888. "$ref": "#/definitions/mimeType"
  23889. }
  23890. },
  23891. "paths": {
  23892. "type": "object",
  23893. "description": "Relative paths to the individual endpoints. They should be relative to the 'basePath'.",
  23894. "patternProperties": {
  23895. "^x-": {
  23896. "$ref": "#/definitions/vendorExtension"
  23897. }
  23898. },
  23899. "additionalProperties": {
  23900. "type": "object",
  23901. "minProperties": 1,
  23902. "additionalProperties": false,
  23903. "patternProperties": {
  23904. "^x-": {
  23905. "$ref": "#/definitions/vendorExtension"
  23906. }
  23907. },
  23908. "properties": {
  23909. "get": {
  23910. "$ref": "#/definitions/operation"
  23911. },
  23912. "put": {
  23913. "$ref": "#/definitions/operation"
  23914. },
  23915. "post": {
  23916. "$ref": "#/definitions/operation"
  23917. },
  23918. "delete": {
  23919. "$ref": "#/definitions/operation"
  23920. },
  23921. "options": {
  23922. "$ref": "#/definitions/operation"
  23923. },
  23924. "head": {
  23925. "$ref": "#/definitions/operation"
  23926. },
  23927. "patch": {
  23928. "$ref": "#/definitions/operation"
  23929. },
  23930. "parameters": {
  23931. "type": "array",
  23932. "items": {
  23933. "$ref": "#/definitions/parameter"
  23934. }
  23935. }
  23936. }
  23937. }
  23938. },
  23939. "schemas": {
  23940. "type": "object",
  23941. "description": "One or more JSON objects describing the schemas being consumed and produced by the API.",
  23942. "additionalProperties": {
  23943. "$ref": "#/definitions/schema"
  23944. }
  23945. },
  23946. "security": {
  23947. "type": "array"
  23948. }
  23949. }
  23950. }
  23951. },{}],230:[function(require,module,exports){
  23952. 'use strict';
  23953. module.exports = {
  23954. description: "getRegisteredFormats - return an array of format names",
  23955. setup: function (validator, Class) {
  23956. Class.registerFormat('phone', function (str) {
  23957. return true;
  23958. });
  23959. },
  23960. tests: [
  23961. {
  23962. description: "should pass validation for new format",
  23963. valid: true,
  23964. data: '01234567',
  23965. schema: {
  23966. "type": "string",
  23967. "format": "phone"
  23968. }
  23969. }
  23970. ]
  23971. };
  23972. },{}],231:[function(require,module,exports){
  23973. arguments[4][226][0].apply(exports,arguments)
  23974. },{"dup":226}],232:[function(require,module,exports){
  23975. module.exports={
  23976. "type": "integer"
  23977. }
  23978. },{}],233:[function(require,module,exports){
  23979. arguments[4][232][0].apply(exports,arguments)
  23980. },{"dup":232}],234:[function(require,module,exports){
  23981. module.exports={
  23982. "integer": {
  23983. "type": "integer"
  23984. },
  23985. "refToInteger": {
  23986. "$ref": "#/integer"
  23987. }
  23988. }
  23989. },{}],235:[function(require,module,exports){
  23990. module.exports=[
  23991. {
  23992. "description": "additionalItems as schema",
  23993. "schema": {
  23994. "items": [{}],
  23995. "additionalItems": {"type": "integer"}
  23996. },
  23997. "tests": [
  23998. {
  23999. "description": "additional items match schema",
  24000. "data": [ null, 2, 3, 4 ],
  24001. "valid": true
  24002. },
  24003. {
  24004. "description": "additional items do not match schema",
  24005. "data": [ null, 2, 3, "foo" ],
  24006. "valid": false
  24007. }
  24008. ]
  24009. },
  24010. {
  24011. "description": "items is schema, no additionalItems",
  24012. "schema": {
  24013. "items": {},
  24014. "additionalItems": false
  24015. },
  24016. "tests": [
  24017. {
  24018. "description": "all items match schema",
  24019. "data": [ 1, 2, 3, 4, 5 ],
  24020. "valid": true
  24021. }
  24022. ]
  24023. },
  24024. {
  24025. "description": "array of items with no additionalItems",
  24026. "schema": {
  24027. "items": [{}, {}, {}],
  24028. "additionalItems": false
  24029. },
  24030. "tests": [
  24031. {
  24032. "description": "no additional items present",
  24033. "data": [ 1, 2, 3 ],
  24034. "valid": true
  24035. },
  24036. {
  24037. "description": "additional items are not permitted",
  24038. "data": [ 1, 2, 3, 4 ],
  24039. "valid": false
  24040. }
  24041. ]
  24042. },
  24043. {
  24044. "description": "additionalItems as false without items",
  24045. "schema": {"additionalItems": false},
  24046. "tests": [
  24047. {
  24048. "description":
  24049. "items defaults to empty schema so everything is valid",
  24050. "data": [ 1, 2, 3, 4, 5 ],
  24051. "valid": true
  24052. },
  24053. {
  24054. "description": "ignores non-arrays",
  24055. "data": {"foo" : "bar"},
  24056. "valid": true
  24057. }
  24058. ]
  24059. },
  24060. {
  24061. "description": "additionalItems are allowed by default",
  24062. "schema": {"items": [{"type": "integer"}]},
  24063. "tests": [
  24064. {
  24065. "description": "only the first item is validated",
  24066. "data": [1, "foo", false],
  24067. "valid": true
  24068. }
  24069. ]
  24070. }
  24071. ]
  24072. },{}],236:[function(require,module,exports){
  24073. module.exports=[
  24074. {
  24075. "description":
  24076. "additionalProperties being false does not allow other properties",
  24077. "schema": {
  24078. "properties": {"foo": {}, "bar": {}},
  24079. "patternProperties": { "^v": {} },
  24080. "additionalProperties": false
  24081. },
  24082. "tests": [
  24083. {
  24084. "description": "no additional properties is valid",
  24085. "data": {"foo": 1},
  24086. "valid": true
  24087. },
  24088. {
  24089. "description": "an additional property is invalid",
  24090. "data": {"foo" : 1, "bar" : 2, "quux" : "boom"},
  24091. "valid": false
  24092. },
  24093. {
  24094. "description": "ignores non-objects",
  24095. "data": [1, 2, 3],
  24096. "valid": true
  24097. },
  24098. {
  24099. "description": "patternProperties are not additional properties",
  24100. "data": {"foo":1, "vroom": 2},
  24101. "valid": true
  24102. }
  24103. ]
  24104. },
  24105. {
  24106. "description":
  24107. "additionalProperties allows a schema which should validate",
  24108. "schema": {
  24109. "properties": {"foo": {}, "bar": {}},
  24110. "additionalProperties": {"type": "boolean"}
  24111. },
  24112. "tests": [
  24113. {
  24114. "description": "no additional properties is valid",
  24115. "data": {"foo": 1},
  24116. "valid": true
  24117. },
  24118. {
  24119. "description": "an additional valid property is valid",
  24120. "data": {"foo" : 1, "bar" : 2, "quux" : true},
  24121. "valid": true
  24122. },
  24123. {
  24124. "description": "an additional invalid property is invalid",
  24125. "data": {"foo" : 1, "bar" : 2, "quux" : 12},
  24126. "valid": false
  24127. }
  24128. ]
  24129. },
  24130. {
  24131. "description":
  24132. "additionalProperties can exist by itself",
  24133. "schema": {
  24134. "additionalProperties": {"type": "boolean"}
  24135. },
  24136. "tests": [
  24137. {
  24138. "description": "an additional valid property is valid",
  24139. "data": {"foo" : true},
  24140. "valid": true
  24141. },
  24142. {
  24143. "description": "an additional invalid property is invalid",
  24144. "data": {"foo" : 1},
  24145. "valid": false
  24146. }
  24147. ]
  24148. },
  24149. {
  24150. "description": "additionalProperties are allowed by default",
  24151. "schema": {"properties": {"foo": {}, "bar": {}}},
  24152. "tests": [
  24153. {
  24154. "description": "additional properties are allowed",
  24155. "data": {"foo": 1, "bar": 2, "quux": true},
  24156. "valid": true
  24157. }
  24158. ]
  24159. }
  24160. ]
  24161. },{}],237:[function(require,module,exports){
  24162. module.exports=[
  24163. {
  24164. "description": "allOf",
  24165. "schema": {
  24166. "allOf": [
  24167. {
  24168. "properties": {
  24169. "bar": {"type": "integer"}
  24170. },
  24171. "required": ["bar"]
  24172. },
  24173. {
  24174. "properties": {
  24175. "foo": {"type": "string"}
  24176. },
  24177. "required": ["foo"]
  24178. }
  24179. ]
  24180. },
  24181. "tests": [
  24182. {
  24183. "description": "allOf",
  24184. "data": {"foo": "baz", "bar": 2},
  24185. "valid": true
  24186. },
  24187. {
  24188. "description": "mismatch second",
  24189. "data": {"foo": "baz"},
  24190. "valid": false
  24191. },
  24192. {
  24193. "description": "mismatch first",
  24194. "data": {"bar": 2},
  24195. "valid": false
  24196. },
  24197. {
  24198. "description": "wrong type",
  24199. "data": {"foo": "baz", "bar": "quux"},
  24200. "valid": false
  24201. }
  24202. ]
  24203. },
  24204. {
  24205. "description": "allOf with base schema",
  24206. "schema": {
  24207. "properties": {"bar": {"type": "integer"}},
  24208. "required": ["bar"],
  24209. "allOf" : [
  24210. {
  24211. "properties": {
  24212. "foo": {"type": "string"}
  24213. },
  24214. "required": ["foo"]
  24215. },
  24216. {
  24217. "properties": {
  24218. "baz": {"type": "null"}
  24219. },
  24220. "required": ["baz"]
  24221. }
  24222. ]
  24223. },
  24224. "tests": [
  24225. {
  24226. "description": "valid",
  24227. "data": {"foo": "quux", "bar": 2, "baz": null},
  24228. "valid": true
  24229. },
  24230. {
  24231. "description": "mismatch base schema",
  24232. "data": {"foo": "quux", "baz": null},
  24233. "valid": false
  24234. },
  24235. {
  24236. "description": "mismatch first allOf",
  24237. "data": {"bar": 2, "baz": null},
  24238. "valid": false
  24239. },
  24240. {
  24241. "description": "mismatch second allOf",
  24242. "data": {"foo": "quux", "bar": 2},
  24243. "valid": false
  24244. },
  24245. {
  24246. "description": "mismatch both",
  24247. "data": {"bar": 2},
  24248. "valid": false
  24249. }
  24250. ]
  24251. },
  24252. {
  24253. "description": "allOf simple types",
  24254. "schema": {
  24255. "allOf": [
  24256. {"maximum": 30},
  24257. {"minimum": 20}
  24258. ]
  24259. },
  24260. "tests": [
  24261. {
  24262. "description": "valid",
  24263. "data": 25,
  24264. "valid": true
  24265. },
  24266. {
  24267. "description": "mismatch one",
  24268. "data": 35,
  24269. "valid": false
  24270. }
  24271. ]
  24272. }
  24273. ]
  24274. },{}],238:[function(require,module,exports){
  24275. module.exports=[
  24276. {
  24277. "description": "anyOf",
  24278. "schema": {
  24279. "anyOf": [
  24280. {
  24281. "type": "integer"
  24282. },
  24283. {
  24284. "minimum": 2
  24285. }
  24286. ]
  24287. },
  24288. "tests": [
  24289. {
  24290. "description": "first anyOf valid",
  24291. "data": 1,
  24292. "valid": true
  24293. },
  24294. {
  24295. "description": "second anyOf valid",
  24296. "data": 2.5,
  24297. "valid": true
  24298. },
  24299. {
  24300. "description": "both anyOf valid",
  24301. "data": 3,
  24302. "valid": true
  24303. },
  24304. {
  24305. "description": "neither anyOf valid",
  24306. "data": 1.5,
  24307. "valid": false
  24308. }
  24309. ]
  24310. },
  24311. {
  24312. "description": "anyOf with base schema",
  24313. "schema": {
  24314. "type": "string",
  24315. "anyOf" : [
  24316. {
  24317. "maxLength": 2
  24318. },
  24319. {
  24320. "minLength": 4
  24321. }
  24322. ]
  24323. },
  24324. "tests": [
  24325. {
  24326. "description": "mismatch base schema",
  24327. "data": 3,
  24328. "valid": false
  24329. },
  24330. {
  24331. "description": "one anyOf valid",
  24332. "data": "foobar",
  24333. "valid": true
  24334. },
  24335. {
  24336. "description": "both anyOf invalid",
  24337. "data": "foo",
  24338. "valid": false
  24339. }
  24340. ]
  24341. }
  24342. ]
  24343. },{}],239:[function(require,module,exports){
  24344. module.exports=[
  24345. {
  24346. "description": "invalid type for default",
  24347. "schema": {
  24348. "properties": {
  24349. "foo": {
  24350. "type": "integer",
  24351. "default": []
  24352. }
  24353. }
  24354. },
  24355. "tests": [
  24356. {
  24357. "description": "valid when property is specified",
  24358. "data": {"foo": 13},
  24359. "valid": true
  24360. },
  24361. {
  24362. "description": "still valid when the invalid default is used",
  24363. "data": {},
  24364. "valid": true
  24365. }
  24366. ]
  24367. },
  24368. {
  24369. "description": "invalid string value for default",
  24370. "schema": {
  24371. "properties": {
  24372. "bar": {
  24373. "type": "string",
  24374. "minLength": 4,
  24375. "default": "bad"
  24376. }
  24377. }
  24378. },
  24379. "tests": [
  24380. {
  24381. "description": "valid when property is specified",
  24382. "data": {"bar": "good"},
  24383. "valid": true
  24384. },
  24385. {
  24386. "description": "still valid when the invalid default is used",
  24387. "data": {},
  24388. "valid": true
  24389. }
  24390. ]
  24391. }
  24392. ]
  24393. },{}],240:[function(require,module,exports){
  24394. module.exports=[
  24395. {
  24396. "description": "valid definition",
  24397. "schema": {"$ref": "http://json-schema.org/draft-04/schema#"},
  24398. "tests": [
  24399. {
  24400. "description": "valid definition schema",
  24401. "data": {
  24402. "definitions": {
  24403. "foo": {"type": "integer"}
  24404. }
  24405. },
  24406. "valid": true
  24407. }
  24408. ]
  24409. },
  24410. {
  24411. "description": "invalid definition",
  24412. "schema": {"$ref": "http://json-schema.org/draft-04/schema#"},
  24413. "tests": [
  24414. {
  24415. "description": "invalid definition schema",
  24416. "data": {
  24417. "definitions": {
  24418. "foo": {"type": 1}
  24419. }
  24420. },
  24421. "valid": false
  24422. }
  24423. ]
  24424. }
  24425. ]
  24426. },{}],241:[function(require,module,exports){
  24427. module.exports=[
  24428. {
  24429. "description": "dependencies",
  24430. "schema": {
  24431. "dependencies": {"bar": ["foo"]}
  24432. },
  24433. "tests": [
  24434. {
  24435. "description": "neither",
  24436. "data": {},
  24437. "valid": true
  24438. },
  24439. {
  24440. "description": "nondependant",
  24441. "data": {"foo": 1},
  24442. "valid": true
  24443. },
  24444. {
  24445. "description": "with dependency",
  24446. "data": {"foo": 1, "bar": 2},
  24447. "valid": true
  24448. },
  24449. {
  24450. "description": "missing dependency",
  24451. "data": {"bar": 2},
  24452. "valid": false
  24453. },
  24454. {
  24455. "description": "ignores non-objects",
  24456. "data": "foo",
  24457. "valid": true
  24458. }
  24459. ]
  24460. },
  24461. {
  24462. "description": "multiple dependencies",
  24463. "schema": {
  24464. "dependencies": {"quux": ["foo", "bar"]}
  24465. },
  24466. "tests": [
  24467. {
  24468. "description": "neither",
  24469. "data": {},
  24470. "valid": true
  24471. },
  24472. {
  24473. "description": "nondependants",
  24474. "data": {"foo": 1, "bar": 2},
  24475. "valid": true
  24476. },
  24477. {
  24478. "description": "with dependencies",
  24479. "data": {"foo": 1, "bar": 2, "quux": 3},
  24480. "valid": true
  24481. },
  24482. {
  24483. "description": "missing dependency",
  24484. "data": {"foo": 1, "quux": 2},
  24485. "valid": false
  24486. },
  24487. {
  24488. "description": "missing other dependency",
  24489. "data": {"bar": 1, "quux": 2},
  24490. "valid": false
  24491. },
  24492. {
  24493. "description": "missing both dependencies",
  24494. "data": {"quux": 1},
  24495. "valid": false
  24496. }
  24497. ]
  24498. },
  24499. {
  24500. "description": "multiple dependencies subschema",
  24501. "schema": {
  24502. "dependencies": {
  24503. "bar": {
  24504. "properties": {
  24505. "foo": {"type": "integer"},
  24506. "bar": {"type": "integer"}
  24507. }
  24508. }
  24509. }
  24510. },
  24511. "tests": [
  24512. {
  24513. "description": "valid",
  24514. "data": {"foo": 1, "bar": 2},
  24515. "valid": true
  24516. },
  24517. {
  24518. "description": "no dependency",
  24519. "data": {"foo": "quux"},
  24520. "valid": true
  24521. },
  24522. {
  24523. "description": "wrong type",
  24524. "data": {"foo": "quux", "bar": 2},
  24525. "valid": false
  24526. },
  24527. {
  24528. "description": "wrong type other",
  24529. "data": {"foo": 2, "bar": "quux"},
  24530. "valid": false
  24531. },
  24532. {
  24533. "description": "wrong type both",
  24534. "data": {"foo": "quux", "bar": "quux"},
  24535. "valid": false
  24536. }
  24537. ]
  24538. }
  24539. ]
  24540. },{}],242:[function(require,module,exports){
  24541. module.exports=[
  24542. {
  24543. "description": "simple enum validation",
  24544. "schema": {"enum": [1, 2, 3]},
  24545. "tests": [
  24546. {
  24547. "description": "one of the enum is valid",
  24548. "data": 1,
  24549. "valid": true
  24550. },
  24551. {
  24552. "description": "something else is invalid",
  24553. "data": 4,
  24554. "valid": false
  24555. }
  24556. ]
  24557. },
  24558. {
  24559. "description": "heterogeneous enum validation",
  24560. "schema": {"enum": [6, "foo", [], true, {"foo": 12}]},
  24561. "tests": [
  24562. {
  24563. "description": "one of the enum is valid",
  24564. "data": [],
  24565. "valid": true
  24566. },
  24567. {
  24568. "description": "something else is invalid",
  24569. "data": null,
  24570. "valid": false
  24571. },
  24572. {
  24573. "description": "objects are deep compared",
  24574. "data": {"foo": false},
  24575. "valid": false
  24576. }
  24577. ]
  24578. },
  24579. {
  24580. "description": "enums in properties",
  24581. "schema": {
  24582. "type":"object",
  24583. "properties": {
  24584. "foo": {"enum":["foo"]},
  24585. "bar": {"enum":["bar"]}
  24586. },
  24587. "required": ["bar"]
  24588. },
  24589. "tests": [
  24590. {
  24591. "description": "both properties are valid",
  24592. "data": {"foo":"foo", "bar":"bar"},
  24593. "valid": true
  24594. },
  24595. {
  24596. "description": "missing optional property is valid",
  24597. "data": {"bar":"bar"},
  24598. "valid": true
  24599. },
  24600. {
  24601. "description": "missing required property is invalid",
  24602. "data": {"foo":"foo"},
  24603. "valid": false
  24604. },
  24605. {
  24606. "description": "missing all properties is invalid",
  24607. "data": {},
  24608. "valid": false
  24609. }
  24610. ]
  24611. }
  24612. ]
  24613. },{}],243:[function(require,module,exports){
  24614. module.exports=[
  24615. {
  24616. "description": "a schema given for items",
  24617. "schema": {
  24618. "items": {"type": "integer"}
  24619. },
  24620. "tests": [
  24621. {
  24622. "description": "valid items",
  24623. "data": [ 1, 2, 3 ],
  24624. "valid": true
  24625. },
  24626. {
  24627. "description": "wrong type of items",
  24628. "data": [1, "x"],
  24629. "valid": false
  24630. },
  24631. {
  24632. "description": "ignores non-arrays",
  24633. "data": {"foo" : "bar"},
  24634. "valid": true
  24635. }
  24636. ]
  24637. },
  24638. {
  24639. "description": "an array of schemas for items",
  24640. "schema": {
  24641. "items": [
  24642. {"type": "integer"},
  24643. {"type": "string"}
  24644. ]
  24645. },
  24646. "tests": [
  24647. {
  24648. "description": "correct types",
  24649. "data": [ 1, "foo" ],
  24650. "valid": true
  24651. },
  24652. {
  24653. "description": "wrong types",
  24654. "data": [ "foo", 1 ],
  24655. "valid": false
  24656. }
  24657. ]
  24658. }
  24659. ]
  24660. },{}],244:[function(require,module,exports){
  24661. module.exports=[
  24662. {
  24663. "description": "maxItems validation",
  24664. "schema": {"maxItems": 2},
  24665. "tests": [
  24666. {
  24667. "description": "shorter is valid",
  24668. "data": [1],
  24669. "valid": true
  24670. },
  24671. {
  24672. "description": "exact length is valid",
  24673. "data": [1, 2],
  24674. "valid": true
  24675. },
  24676. {
  24677. "description": "too long is invalid",
  24678. "data": [1, 2, 3],
  24679. "valid": false
  24680. },
  24681. {
  24682. "description": "ignores non-arrays",
  24683. "data": "foobar",
  24684. "valid": true
  24685. }
  24686. ]
  24687. }
  24688. ]
  24689. },{}],245:[function(require,module,exports){
  24690. module.exports=[
  24691. {
  24692. "description": "maxLength validation",
  24693. "schema": {"maxLength": 2},
  24694. "tests": [
  24695. {
  24696. "description": "shorter is valid",
  24697. "data": "f",
  24698. "valid": true
  24699. },
  24700. {
  24701. "description": "exact length is valid",
  24702. "data": "fo",
  24703. "valid": true
  24704. },
  24705. {
  24706. "description": "too long is invalid",
  24707. "data": "foo",
  24708. "valid": false
  24709. },
  24710. {
  24711. "description": "ignores non-strings",
  24712. "data": 100,
  24713. "valid": true
  24714. },
  24715. {
  24716. "description": "two supplementary Unicode code points is long enough",
  24717. "data": "\uD83D\uDCA9\uD83D\uDCA9",
  24718. "valid": true
  24719. }
  24720. ]
  24721. }
  24722. ]
  24723. },{}],246:[function(require,module,exports){
  24724. module.exports=[
  24725. {
  24726. "description": "maxProperties validation",
  24727. "schema": {"maxProperties": 2},
  24728. "tests": [
  24729. {
  24730. "description": "shorter is valid",
  24731. "data": {"foo": 1},
  24732. "valid": true
  24733. },
  24734. {
  24735. "description": "exact length is valid",
  24736. "data": {"foo": 1, "bar": 2},
  24737. "valid": true
  24738. },
  24739. {
  24740. "description": "too long is invalid",
  24741. "data": {"foo": 1, "bar": 2, "baz": 3},
  24742. "valid": false
  24743. },
  24744. {
  24745. "description": "ignores non-objects",
  24746. "data": "foobar",
  24747. "valid": true
  24748. }
  24749. ]
  24750. }
  24751. ]
  24752. },{}],247:[function(require,module,exports){
  24753. module.exports=[
  24754. {
  24755. "description": "maximum validation",
  24756. "schema": {"maximum": 3.0},
  24757. "tests": [
  24758. {
  24759. "description": "below the maximum is valid",
  24760. "data": 2.6,
  24761. "valid": true
  24762. },
  24763. {
  24764. "description": "above the maximum is invalid",
  24765. "data": 3.5,
  24766. "valid": false
  24767. },
  24768. {
  24769. "description": "ignores non-numbers",
  24770. "data": "x",
  24771. "valid": true
  24772. }
  24773. ]
  24774. },
  24775. {
  24776. "description": "exclusiveMaximum validation",
  24777. "schema": {
  24778. "maximum": 3.0,
  24779. "exclusiveMaximum": true
  24780. },
  24781. "tests": [
  24782. {
  24783. "description": "below the maximum is still valid",
  24784. "data": 2.2,
  24785. "valid": true
  24786. },
  24787. {
  24788. "description": "boundary point is invalid",
  24789. "data": 3.0,
  24790. "valid": false
  24791. }
  24792. ]
  24793. }
  24794. ]
  24795. },{}],248:[function(require,module,exports){
  24796. module.exports=[
  24797. {
  24798. "description": "minItems validation",
  24799. "schema": {"minItems": 1},
  24800. "tests": [
  24801. {
  24802. "description": "longer is valid",
  24803. "data": [1, 2],
  24804. "valid": true
  24805. },
  24806. {
  24807. "description": "exact length is valid",
  24808. "data": [1],
  24809. "valid": true
  24810. },
  24811. {
  24812. "description": "too short is invalid",
  24813. "data": [],
  24814. "valid": false
  24815. },
  24816. {
  24817. "description": "ignores non-arrays",
  24818. "data": "",
  24819. "valid": true
  24820. }
  24821. ]
  24822. }
  24823. ]
  24824. },{}],249:[function(require,module,exports){
  24825. module.exports=[
  24826. {
  24827. "description": "minLength validation",
  24828. "schema": {"minLength": 2},
  24829. "tests": [
  24830. {
  24831. "description": "longer is valid",
  24832. "data": "foo",
  24833. "valid": true
  24834. },
  24835. {
  24836. "description": "exact length is valid",
  24837. "data": "fo",
  24838. "valid": true
  24839. },
  24840. {
  24841. "description": "too short is invalid",
  24842. "data": "f",
  24843. "valid": false
  24844. },
  24845. {
  24846. "description": "ignores non-strings",
  24847. "data": 1,
  24848. "valid": true
  24849. },
  24850. {
  24851. "description": "one supplementary Unicode code point is not long enough",
  24852. "data": "\uD83D\uDCA9",
  24853. "valid": false
  24854. }
  24855. ]
  24856. }
  24857. ]
  24858. },{}],250:[function(require,module,exports){
  24859. module.exports=[
  24860. {
  24861. "description": "minProperties validation",
  24862. "schema": {"minProperties": 1},
  24863. "tests": [
  24864. {
  24865. "description": "longer is valid",
  24866. "data": {"foo": 1, "bar": 2},
  24867. "valid": true
  24868. },
  24869. {
  24870. "description": "exact length is valid",
  24871. "data": {"foo": 1},
  24872. "valid": true
  24873. },
  24874. {
  24875. "description": "too short is invalid",
  24876. "data": {},
  24877. "valid": false
  24878. },
  24879. {
  24880. "description": "ignores non-objects",
  24881. "data": "",
  24882. "valid": true
  24883. }
  24884. ]
  24885. }
  24886. ]
  24887. },{}],251:[function(require,module,exports){
  24888. module.exports=[
  24889. {
  24890. "description": "minimum validation",
  24891. "schema": {"minimum": 1.1},
  24892. "tests": [
  24893. {
  24894. "description": "above the minimum is valid",
  24895. "data": 2.6,
  24896. "valid": true
  24897. },
  24898. {
  24899. "description": "below the minimum is invalid",
  24900. "data": 0.6,
  24901. "valid": false
  24902. },
  24903. {
  24904. "description": "ignores non-numbers",
  24905. "data": "x",
  24906. "valid": true
  24907. }
  24908. ]
  24909. },
  24910. {
  24911. "description": "exclusiveMinimum validation",
  24912. "schema": {
  24913. "minimum": 1.1,
  24914. "exclusiveMinimum": true
  24915. },
  24916. "tests": [
  24917. {
  24918. "description": "above the minimum is still valid",
  24919. "data": 1.2,
  24920. "valid": true
  24921. },
  24922. {
  24923. "description": "boundary point is invalid",
  24924. "data": 1.1,
  24925. "valid": false
  24926. }
  24927. ]
  24928. }
  24929. ]
  24930. },{}],252:[function(require,module,exports){
  24931. module.exports=[
  24932. {
  24933. "description": "by int",
  24934. "schema": {"multipleOf": 2},
  24935. "tests": [
  24936. {
  24937. "description": "int by int",
  24938. "data": 10,
  24939. "valid": true
  24940. },
  24941. {
  24942. "description": "int by int fail",
  24943. "data": 7,
  24944. "valid": false
  24945. },
  24946. {
  24947. "description": "ignores non-numbers",
  24948. "data": "foo",
  24949. "valid": true
  24950. }
  24951. ]
  24952. },
  24953. {
  24954. "description": "by number",
  24955. "schema": {"multipleOf": 1.5},
  24956. "tests": [
  24957. {
  24958. "description": "zero is multiple of anything",
  24959. "data": 0,
  24960. "valid": true
  24961. },
  24962. {
  24963. "description": "4.5 is multiple of 1.5",
  24964. "data": 4.5,
  24965. "valid": true
  24966. },
  24967. {
  24968. "description": "35 is not multiple of 1.5",
  24969. "data": 35,
  24970. "valid": false
  24971. }
  24972. ]
  24973. },
  24974. {
  24975. "description": "by small number",
  24976. "schema": {"multipleOf": 0.0001},
  24977. "tests": [
  24978. {
  24979. "description": "0.0075 is multiple of 0.0001",
  24980. "data": 0.0075,
  24981. "valid": true
  24982. },
  24983. {
  24984. "description": "0.00751 is not multiple of 0.0001",
  24985. "data": 0.00751,
  24986. "valid": false
  24987. }
  24988. ]
  24989. }
  24990. ]
  24991. },{}],253:[function(require,module,exports){
  24992. module.exports=[
  24993. {
  24994. "description": "not",
  24995. "schema": {
  24996. "not": {"type": "integer"}
  24997. },
  24998. "tests": [
  24999. {
  25000. "description": "allowed",
  25001. "data": "foo",
  25002. "valid": true
  25003. },
  25004. {
  25005. "description": "disallowed",
  25006. "data": 1,
  25007. "valid": false
  25008. }
  25009. ]
  25010. },
  25011. {
  25012. "description": "not multiple types",
  25013. "schema": {
  25014. "not": {"type": ["integer", "boolean"]}
  25015. },
  25016. "tests": [
  25017. {
  25018. "description": "valid",
  25019. "data": "foo",
  25020. "valid": true
  25021. },
  25022. {
  25023. "description": "mismatch",
  25024. "data": 1,
  25025. "valid": false
  25026. },
  25027. {
  25028. "description": "other mismatch",
  25029. "data": true,
  25030. "valid": false
  25031. }
  25032. ]
  25033. },
  25034. {
  25035. "description": "not more complex schema",
  25036. "schema": {
  25037. "not": {
  25038. "type": "object",
  25039. "properties": {
  25040. "foo": {
  25041. "type": "string"
  25042. }
  25043. }
  25044. }
  25045. },
  25046. "tests": [
  25047. {
  25048. "description": "match",
  25049. "data": 1,
  25050. "valid": true
  25051. },
  25052. {
  25053. "description": "other match",
  25054. "data": {"foo": 1},
  25055. "valid": true
  25056. },
  25057. {
  25058. "description": "mismatch",
  25059. "data": {"foo": "bar"},
  25060. "valid": false
  25061. }
  25062. ]
  25063. },
  25064. {
  25065. "description": "forbidden property",
  25066. "schema": {
  25067. "properties": {
  25068. "foo": {
  25069. "not": {}
  25070. }
  25071. }
  25072. },
  25073. "tests": [
  25074. {
  25075. "description": "property present",
  25076. "data": {"foo": 1, "bar": 2},
  25077. "valid": false
  25078. },
  25079. {
  25080. "description": "property absent",
  25081. "data": {"bar": 1, "baz": 2},
  25082. "valid": true
  25083. }
  25084. ]
  25085. }
  25086. ]
  25087. },{}],254:[function(require,module,exports){
  25088. module.exports=[
  25089. {
  25090. "description": "oneOf",
  25091. "schema": {
  25092. "oneOf": [
  25093. {
  25094. "type": "integer"
  25095. },
  25096. {
  25097. "minimum": 2
  25098. }
  25099. ]
  25100. },
  25101. "tests": [
  25102. {
  25103. "description": "first oneOf valid",
  25104. "data": 1,
  25105. "valid": true
  25106. },
  25107. {
  25108. "description": "second oneOf valid",
  25109. "data": 2.5,
  25110. "valid": true
  25111. },
  25112. {
  25113. "description": "both oneOf valid",
  25114. "data": 3,
  25115. "valid": false
  25116. },
  25117. {
  25118. "description": "neither oneOf valid",
  25119. "data": 1.5,
  25120. "valid": false
  25121. }
  25122. ]
  25123. },
  25124. {
  25125. "description": "oneOf with base schema",
  25126. "schema": {
  25127. "type": "string",
  25128. "oneOf" : [
  25129. {
  25130. "minLength": 2
  25131. },
  25132. {
  25133. "maxLength": 4
  25134. }
  25135. ]
  25136. },
  25137. "tests": [
  25138. {
  25139. "description": "mismatch base schema",
  25140. "data": 3,
  25141. "valid": false
  25142. },
  25143. {
  25144. "description": "one oneOf valid",
  25145. "data": "foobar",
  25146. "valid": true
  25147. },
  25148. {
  25149. "description": "both oneOf valid",
  25150. "data": "foo",
  25151. "valid": false
  25152. }
  25153. ]
  25154. }
  25155. ]
  25156. },{}],255:[function(require,module,exports){
  25157. module.exports=[
  25158. {
  25159. "description": "integer",
  25160. "schema": {"type": "integer"},
  25161. "tests": [
  25162. {
  25163. "description": "a bignum is an integer",
  25164. "data": 12345678910111213141516171819202122232425262728293031,
  25165. "valid": true
  25166. }
  25167. ]
  25168. },
  25169. {
  25170. "description": "number",
  25171. "schema": {"type": "number"},
  25172. "tests": [
  25173. {
  25174. "description": "a bignum is a number",
  25175. "data": 98249283749234923498293171823948729348710298301928331,
  25176. "valid": true
  25177. }
  25178. ]
  25179. },
  25180. {
  25181. "description": "integer",
  25182. "schema": {"type": "integer"},
  25183. "tests": [
  25184. {
  25185. "description": "a negative bignum is an integer",
  25186. "data": -12345678910111213141516171819202122232425262728293031,
  25187. "valid": true
  25188. }
  25189. ]
  25190. },
  25191. {
  25192. "description": "number",
  25193. "schema": {"type": "number"},
  25194. "tests": [
  25195. {
  25196. "description": "a negative bignum is a number",
  25197. "data": -98249283749234923498293171823948729348710298301928331,
  25198. "valid": true
  25199. }
  25200. ]
  25201. },
  25202. {
  25203. "description": "string",
  25204. "schema": {"type": "string"},
  25205. "tests": [
  25206. {
  25207. "description": "a bignum is not a string",
  25208. "data": 98249283749234923498293171823948729348710298301928331,
  25209. "valid": false
  25210. }
  25211. ]
  25212. },
  25213. {
  25214. "description": "integer comparison",
  25215. "schema": {"maximum": 18446744073709551615},
  25216. "tests": [
  25217. {
  25218. "description": "comparison works for high numbers",
  25219. "data": 18446744073709551600,
  25220. "valid": true
  25221. }
  25222. ]
  25223. },
  25224. {
  25225. "description": "float comparison with high precision",
  25226. "schema": {
  25227. "maximum": 972783798187987123879878123.18878137,
  25228. "exclusiveMaximum": true
  25229. },
  25230. "tests": [
  25231. {
  25232. "description": "comparison works for high numbers",
  25233. "data": 972783798187987123879878123.188781371,
  25234. "valid": false
  25235. }
  25236. ]
  25237. },
  25238. {
  25239. "description": "integer comparison",
  25240. "schema": {"minimum": -18446744073709551615},
  25241. "tests": [
  25242. {
  25243. "description": "comparison works for very negative numbers",
  25244. "data": -18446744073709551600,
  25245. "valid": true
  25246. }
  25247. ]
  25248. },
  25249. {
  25250. "description": "float comparison with high precision on negative numbers",
  25251. "schema": {
  25252. "minimum": -972783798187987123879878123.18878137,
  25253. "exclusiveMinimum": true
  25254. },
  25255. "tests": [
  25256. {
  25257. "description": "comparison works for very negative numbers",
  25258. "data": -972783798187987123879878123.188781371,
  25259. "valid": false
  25260. }
  25261. ]
  25262. }
  25263. ]
  25264. },{}],256:[function(require,module,exports){
  25265. module.exports=[
  25266. {
  25267. "description": "validation of date-time strings",
  25268. "schema": {"format": "date-time"},
  25269. "tests": [
  25270. {
  25271. "description": "a valid date-time string",
  25272. "data": "1963-06-19T08:30:06.283185Z",
  25273. "valid": true
  25274. },
  25275. {
  25276. "description": "an invalid date-time string",
  25277. "data": "06/19/1963 08:30:06 PST",
  25278. "valid": false
  25279. },
  25280. {
  25281. "description": "only RFC3339 not all of ISO 8601 are valid",
  25282. "data": "2013-350T01:01:01",
  25283. "valid": false
  25284. }
  25285. ]
  25286. },
  25287. {
  25288. "description": "validation of URIs",
  25289. "schema": {"format": "uri"},
  25290. "tests": [
  25291. {
  25292. "description": "a valid URI",
  25293. "data": "http://foo.bar/?baz=qux#quux",
  25294. "valid": true
  25295. },
  25296. {
  25297. "description": "an invalid URI",
  25298. "data": "\\\\WINDOWS\\fileshare",
  25299. "valid": false
  25300. },
  25301. {
  25302. "description": "an invalid URI though valid URI reference",
  25303. "data": "abc",
  25304. "valid": false
  25305. }
  25306. ]
  25307. },
  25308. {
  25309. "description": "validation of e-mail addresses",
  25310. "schema": {"format": "email"},
  25311. "tests": [
  25312. {
  25313. "description": "a valid e-mail address",
  25314. "data": "joe.bloggs@example.com",
  25315. "valid": true
  25316. },
  25317. {
  25318. "description": "an invalid e-mail address",
  25319. "data": "2962",
  25320. "valid": false
  25321. }
  25322. ]
  25323. },
  25324. {
  25325. "description": "validation of IP addresses",
  25326. "schema": {"format": "ipv4"},
  25327. "tests": [
  25328. {
  25329. "description": "a valid IP address",
  25330. "data": "192.168.0.1",
  25331. "valid": true
  25332. },
  25333. {
  25334. "description": "an IP address with too many components",
  25335. "data": "127.0.0.0.1",
  25336. "valid": false
  25337. },
  25338. {
  25339. "description": "an IP address with out-of-range values",
  25340. "data": "256.256.256.256",
  25341. "valid": false
  25342. },
  25343. {
  25344. "description": "an IP address without 4 components",
  25345. "data": "127.0",
  25346. "valid": false
  25347. },
  25348. {
  25349. "description": "an IP address as an integer",
  25350. "data": "0x7f000001",
  25351. "valid": false
  25352. }
  25353. ]
  25354. },
  25355. {
  25356. "description": "validation of IPv6 addresses",
  25357. "schema": {"format": "ipv6"},
  25358. "tests": [
  25359. {
  25360. "description": "a valid IPv6 address",
  25361. "data": "::1",
  25362. "valid": true
  25363. },
  25364. {
  25365. "description": "an IPv6 address with out-of-range values",
  25366. "data": "12345::",
  25367. "valid": false
  25368. },
  25369. {
  25370. "description": "an IPv6 address with too many components",
  25371. "data": "1:1:1:1:1:1:1:1:1:1:1:1:1:1:1:1",
  25372. "valid": false
  25373. },
  25374. {
  25375. "description": "an IPv6 address containing illegal characters",
  25376. "data": "::laptop",
  25377. "valid": false
  25378. }
  25379. ]
  25380. },
  25381. {
  25382. "description": "validation of host names",
  25383. "schema": {"format": "hostname"},
  25384. "tests": [
  25385. {
  25386. "description": "a valid host name",
  25387. "data": "www.example.com",
  25388. "valid": true
  25389. },
  25390. {
  25391. "description": "a host name starting with an illegal character",
  25392. "data": "-a-host-name-that-starts-with--",
  25393. "valid": false
  25394. },
  25395. {
  25396. "description": "a host name containing illegal characters",
  25397. "data": "not_a_valid_host_name",
  25398. "valid": false
  25399. },
  25400. {
  25401. "description": "a host name with a component too long",
  25402. "data": "a-vvvvvvvvvvvvvvvveeeeeeeeeeeeeeeerrrrrrrrrrrrrrrryyyyyyyyyyyyyyyy-long-host-name-component",
  25403. "valid": false
  25404. }
  25405. ]
  25406. }
  25407. ]
  25408. },{}],257:[function(require,module,exports){
  25409. module.exports=[
  25410. {
  25411. "description": "pattern validation",
  25412. "schema": {"pattern": "^a*$"},
  25413. "tests": [
  25414. {
  25415. "description": "a matching pattern is valid",
  25416. "data": "aaa",
  25417. "valid": true
  25418. },
  25419. {
  25420. "description": "a non-matching pattern is invalid",
  25421. "data": "abc",
  25422. "valid": false
  25423. },
  25424. {
  25425. "description": "ignores non-strings",
  25426. "data": true,
  25427. "valid": true
  25428. }
  25429. ]
  25430. }
  25431. ]
  25432. },{}],258:[function(require,module,exports){
  25433. module.exports=[
  25434. {
  25435. "description":
  25436. "patternProperties validates properties matching a regex",
  25437. "schema": {
  25438. "patternProperties": {
  25439. "f.*o": {"type": "integer"}
  25440. }
  25441. },
  25442. "tests": [
  25443. {
  25444. "description": "a single valid match is valid",
  25445. "data": {"foo": 1},
  25446. "valid": true
  25447. },
  25448. {
  25449. "description": "multiple valid matches is valid",
  25450. "data": {"foo": 1, "foooooo" : 2},
  25451. "valid": true
  25452. },
  25453. {
  25454. "description": "a single invalid match is invalid",
  25455. "data": {"foo": "bar", "fooooo": 2},
  25456. "valid": false
  25457. },
  25458. {
  25459. "description": "multiple invalid matches is invalid",
  25460. "data": {"foo": "bar", "foooooo" : "baz"},
  25461. "valid": false
  25462. },
  25463. {
  25464. "description": "ignores non-objects",
  25465. "data": 12,
  25466. "valid": true
  25467. }
  25468. ]
  25469. },
  25470. {
  25471. "description": "multiple simultaneous patternProperties are validated",
  25472. "schema": {
  25473. "patternProperties": {
  25474. "a*": {"type": "integer"},
  25475. "aaa*": {"maximum": 20}
  25476. }
  25477. },
  25478. "tests": [
  25479. {
  25480. "description": "a single valid match is valid",
  25481. "data": {"a": 21},
  25482. "valid": true
  25483. },
  25484. {
  25485. "description": "a simultaneous match is valid",
  25486. "data": {"aaaa": 18},
  25487. "valid": true
  25488. },
  25489. {
  25490. "description": "multiple matches is valid",
  25491. "data": {"a": 21, "aaaa": 18},
  25492. "valid": true
  25493. },
  25494. {
  25495. "description": "an invalid due to one is invalid",
  25496. "data": {"a": "bar"},
  25497. "valid": false
  25498. },
  25499. {
  25500. "description": "an invalid due to the other is invalid",
  25501. "data": {"aaaa": 31},
  25502. "valid": false
  25503. },
  25504. {
  25505. "description": "an invalid due to both is invalid",
  25506. "data": {"aaa": "foo", "aaaa": 31},
  25507. "valid": false
  25508. }
  25509. ]
  25510. },
  25511. {
  25512. "description": "regexes are not anchored by default and are case sensitive",
  25513. "schema": {
  25514. "patternProperties": {
  25515. "[0-9]{2,}": { "type": "boolean" },
  25516. "X_": { "type": "string" }
  25517. }
  25518. },
  25519. "tests": [
  25520. {
  25521. "description": "non recognized members are ignored",
  25522. "data": { "answer 1": "42" },
  25523. "valid": true
  25524. },
  25525. {
  25526. "description": "recognized members are accounted for",
  25527. "data": { "a31b": null },
  25528. "valid": false
  25529. },
  25530. {
  25531. "description": "regexes are case sensitive",
  25532. "data": { "a_x_3": 3 },
  25533. "valid": true
  25534. },
  25535. {
  25536. "description": "regexes are case sensitive, 2",
  25537. "data": { "a_X_3": 3 },
  25538. "valid": false
  25539. }
  25540. ]
  25541. }
  25542. ]
  25543. },{}],259:[function(require,module,exports){
  25544. module.exports=[
  25545. {
  25546. "description": "object properties validation",
  25547. "schema": {
  25548. "properties": {
  25549. "foo": {"type": "integer"},
  25550. "bar": {"type": "string"}
  25551. }
  25552. },
  25553. "tests": [
  25554. {
  25555. "description": "both properties present and valid is valid",
  25556. "data": {"foo": 1, "bar": "baz"},
  25557. "valid": true
  25558. },
  25559. {
  25560. "description": "one property invalid is invalid",
  25561. "data": {"foo": 1, "bar": {}},
  25562. "valid": false
  25563. },
  25564. {
  25565. "description": "both properties invalid is invalid",
  25566. "data": {"foo": [], "bar": {}},
  25567. "valid": false
  25568. },
  25569. {
  25570. "description": "doesn't invalidate other properties",
  25571. "data": {"quux": []},
  25572. "valid": true
  25573. },
  25574. {
  25575. "description": "ignores non-objects",
  25576. "data": [],
  25577. "valid": true
  25578. }
  25579. ]
  25580. },
  25581. {
  25582. "description":
  25583. "properties, patternProperties, additionalProperties interaction",
  25584. "schema": {
  25585. "properties": {
  25586. "foo": {"type": "array", "maxItems": 3},
  25587. "bar": {"type": "array"}
  25588. },
  25589. "patternProperties": {"f.o": {"minItems": 2}},
  25590. "additionalProperties": {"type": "integer"}
  25591. },
  25592. "tests": [
  25593. {
  25594. "description": "property validates property",
  25595. "data": {"foo": [1, 2]},
  25596. "valid": true
  25597. },
  25598. {
  25599. "description": "property invalidates property",
  25600. "data": {"foo": [1, 2, 3, 4]},
  25601. "valid": false
  25602. },
  25603. {
  25604. "description": "patternProperty invalidates property",
  25605. "data": {"foo": []},
  25606. "valid": false
  25607. },
  25608. {
  25609. "description": "patternProperty validates nonproperty",
  25610. "data": {"fxo": [1, 2]},
  25611. "valid": true
  25612. },
  25613. {
  25614. "description": "patternProperty invalidates nonproperty",
  25615. "data": {"fxo": []},
  25616. "valid": false
  25617. },
  25618. {
  25619. "description": "additionalProperty ignores property",
  25620. "data": {"bar": []},
  25621. "valid": true
  25622. },
  25623. {
  25624. "description": "additionalProperty validates others",
  25625. "data": {"quux": 3},
  25626. "valid": true
  25627. },
  25628. {
  25629. "description": "additionalProperty invalidates others",
  25630. "data": {"quux": "foo"},
  25631. "valid": false
  25632. }
  25633. ]
  25634. }
  25635. ]
  25636. },{}],260:[function(require,module,exports){
  25637. module.exports=[
  25638. {
  25639. "description": "root pointer ref",
  25640. "schema": {
  25641. "properties": {
  25642. "foo": {"$ref": "#"}
  25643. },
  25644. "additionalProperties": false
  25645. },
  25646. "tests": [
  25647. {
  25648. "description": "match",
  25649. "data": {"foo": false},
  25650. "valid": true
  25651. },
  25652. {
  25653. "description": "recursive match",
  25654. "data": {"foo": {"foo": false}},
  25655. "valid": true
  25656. },
  25657. {
  25658. "description": "mismatch",
  25659. "data": {"bar": false},
  25660. "valid": false
  25661. },
  25662. {
  25663. "description": "recursive mismatch",
  25664. "data": {"foo": {"bar": false}},
  25665. "valid": false
  25666. }
  25667. ]
  25668. },
  25669. {
  25670. "description": "relative pointer ref to object",
  25671. "schema": {
  25672. "properties": {
  25673. "foo": {"type": "integer"},
  25674. "bar": {"$ref": "#/properties/foo"}
  25675. }
  25676. },
  25677. "tests": [
  25678. {
  25679. "description": "match",
  25680. "data": {"bar": 3},
  25681. "valid": true
  25682. },
  25683. {
  25684. "description": "mismatch",
  25685. "data": {"bar": true},
  25686. "valid": false
  25687. }
  25688. ]
  25689. },
  25690. {
  25691. "description": "relative pointer ref to array",
  25692. "schema": {
  25693. "items": [
  25694. {"type": "integer"},
  25695. {"$ref": "#/items/0"}
  25696. ]
  25697. },
  25698. "tests": [
  25699. {
  25700. "description": "match array",
  25701. "data": [1, 2],
  25702. "valid": true
  25703. },
  25704. {
  25705. "description": "mismatch array",
  25706. "data": [1, "foo"],
  25707. "valid": false
  25708. }
  25709. ]
  25710. },
  25711. {
  25712. "description": "escaped pointer ref",
  25713. "schema": {
  25714. "tilda~field": {"type": "integer"},
  25715. "slash/field": {"type": "integer"},
  25716. "percent%field": {"type": "integer"},
  25717. "properties": {
  25718. "tilda": {"$ref": "#/tilda~0field"},
  25719. "slash": {"$ref": "#/slash~1field"},
  25720. "percent": {"$ref": "#/percent%25field"}
  25721. }
  25722. },
  25723. "tests": [
  25724. {
  25725. "description": "slash",
  25726. "data": {"slash": "aoeu"},
  25727. "valid": false
  25728. },
  25729. {
  25730. "description": "tilda",
  25731. "data": {"tilda": "aoeu"},
  25732. "valid": false
  25733. },
  25734. {
  25735. "description": "percent",
  25736. "data": {"percent": "aoeu"},
  25737. "valid": false
  25738. }
  25739. ]
  25740. },
  25741. {
  25742. "description": "nested refs",
  25743. "schema": {
  25744. "definitions": {
  25745. "a": {"type": "integer"},
  25746. "b": {"$ref": "#/definitions/a"},
  25747. "c": {"$ref": "#/definitions/b"}
  25748. },
  25749. "$ref": "#/definitions/c"
  25750. },
  25751. "tests": [
  25752. {
  25753. "description": "nested ref valid",
  25754. "data": 5,
  25755. "valid": true
  25756. },
  25757. {
  25758. "description": "nested ref invalid",
  25759. "data": "a",
  25760. "valid": false
  25761. }
  25762. ]
  25763. },
  25764. {
  25765. "description": "remote ref, containing refs itself",
  25766. "schema": {"$ref": "http://json-schema.org/draft-04/schema#"},
  25767. "tests": [
  25768. {
  25769. "description": "remote ref valid",
  25770. "data": {"minLength": 1},
  25771. "valid": true
  25772. },
  25773. {
  25774. "description": "remote ref invalid",
  25775. "data": {"minLength": -1},
  25776. "valid": false
  25777. }
  25778. ]
  25779. }
  25780. ]
  25781. },{}],261:[function(require,module,exports){
  25782. module.exports=[
  25783. {
  25784. "description": "remote ref",
  25785. "schema": {"$ref": "http://localhost:1234/integer.json"},
  25786. "tests": [
  25787. {
  25788. "description": "remote ref valid",
  25789. "data": 1,
  25790. "valid": true
  25791. },
  25792. {
  25793. "description": "remote ref invalid",
  25794. "data": "a",
  25795. "valid": false
  25796. }
  25797. ]
  25798. },
  25799. {
  25800. "description": "fragment within remote ref",
  25801. "schema": {"$ref": "http://localhost:1234/subSchemas.json#/integer"},
  25802. "tests": [
  25803. {
  25804. "description": "remote fragment valid",
  25805. "data": 1,
  25806. "valid": true
  25807. },
  25808. {
  25809. "description": "remote fragment invalid",
  25810. "data": "a",
  25811. "valid": false
  25812. }
  25813. ]
  25814. },
  25815. {
  25816. "description": "ref within remote ref",
  25817. "schema": {
  25818. "$ref": "http://localhost:1234/subSchemas.json#/refToInteger"
  25819. },
  25820. "tests": [
  25821. {
  25822. "description": "ref within ref valid",
  25823. "data": 1,
  25824. "valid": true
  25825. },
  25826. {
  25827. "description": "ref within ref invalid",
  25828. "data": "a",
  25829. "valid": false
  25830. }
  25831. ]
  25832. },
  25833. {
  25834. "description": "change resolution scope",
  25835. "schema": {
  25836. "id": "http://localhost:1234/",
  25837. "items": {
  25838. "id": "folder/",
  25839. "items": {"$ref": "folderInteger.json"}
  25840. }
  25841. },
  25842. "tests": [
  25843. {
  25844. "description": "changed scope ref valid",
  25845. "data": [[1]],
  25846. "valid": true
  25847. },
  25848. {
  25849. "description": "changed scope ref invalid",
  25850. "data": [["a"]],
  25851. "valid": false
  25852. }
  25853. ]
  25854. }
  25855. ]
  25856. },{}],262:[function(require,module,exports){
  25857. module.exports=[
  25858. {
  25859. "description": "required validation",
  25860. "schema": {
  25861. "properties": {
  25862. "foo": {},
  25863. "bar": {}
  25864. },
  25865. "required": ["foo"]
  25866. },
  25867. "tests": [
  25868. {
  25869. "description": "present required property is valid",
  25870. "data": {"foo": 1},
  25871. "valid": true
  25872. },
  25873. {
  25874. "description": "non-present required property is invalid",
  25875. "data": {"bar": 1},
  25876. "valid": false
  25877. }
  25878. ]
  25879. },
  25880. {
  25881. "description": "required default validation",
  25882. "schema": {
  25883. "properties": {
  25884. "foo": {}
  25885. }
  25886. },
  25887. "tests": [
  25888. {
  25889. "description": "not required by default",
  25890. "data": {},
  25891. "valid": true
  25892. }
  25893. ]
  25894. }
  25895. ]
  25896. },{}],263:[function(require,module,exports){
  25897. module.exports=[
  25898. {
  25899. "description": "integer type matches integers",
  25900. "schema": {"type": "integer"},
  25901. "tests": [
  25902. {
  25903. "description": "an integer is an integer",
  25904. "data": 1,
  25905. "valid": true
  25906. },
  25907. {
  25908. "description": "a float is not an integer",
  25909. "data": 1.1,
  25910. "valid": false
  25911. },
  25912. {
  25913. "description": "a string is not an integer",
  25914. "data": "foo",
  25915. "valid": false
  25916. },
  25917. {
  25918. "description": "an object is not an integer",
  25919. "data": {},
  25920. "valid": false
  25921. },
  25922. {
  25923. "description": "an array is not an integer",
  25924. "data": [],
  25925. "valid": false
  25926. },
  25927. {
  25928. "description": "a boolean is not an integer",
  25929. "data": true,
  25930. "valid": false
  25931. },
  25932. {
  25933. "description": "null is not an integer",
  25934. "data": null,
  25935. "valid": false
  25936. }
  25937. ]
  25938. },
  25939. {
  25940. "description": "number type matches numbers",
  25941. "schema": {"type": "number"},
  25942. "tests": [
  25943. {
  25944. "description": "an integer is a number",
  25945. "data": 1,
  25946. "valid": true
  25947. },
  25948. {
  25949. "description": "a float is a number",
  25950. "data": 1.1,
  25951. "valid": true
  25952. },
  25953. {
  25954. "description": "a string is not a number",
  25955. "data": "foo",
  25956. "valid": false
  25957. },
  25958. {
  25959. "description": "an object is not a number",
  25960. "data": {},
  25961. "valid": false
  25962. },
  25963. {
  25964. "description": "an array is not a number",
  25965. "data": [],
  25966. "valid": false
  25967. },
  25968. {
  25969. "description": "a boolean is not a number",
  25970. "data": true,
  25971. "valid": false
  25972. },
  25973. {
  25974. "description": "null is not a number",
  25975. "data": null,
  25976. "valid": false
  25977. }
  25978. ]
  25979. },
  25980. {
  25981. "description": "string type matches strings",
  25982. "schema": {"type": "string"},
  25983. "tests": [
  25984. {
  25985. "description": "1 is not a string",
  25986. "data": 1,
  25987. "valid": false
  25988. },
  25989. {
  25990. "description": "a float is not a string",
  25991. "data": 1.1,
  25992. "valid": false
  25993. },
  25994. {
  25995. "description": "a string is a string",
  25996. "data": "foo",
  25997. "valid": true
  25998. },
  25999. {
  26000. "description": "an object is not a string",
  26001. "data": {},
  26002. "valid": false
  26003. },
  26004. {
  26005. "description": "an array is not a string",
  26006. "data": [],
  26007. "valid": false
  26008. },
  26009. {
  26010. "description": "a boolean is not a string",
  26011. "data": true,
  26012. "valid": false
  26013. },
  26014. {
  26015. "description": "null is not a string",
  26016. "data": null,
  26017. "valid": false
  26018. }
  26019. ]
  26020. },
  26021. {
  26022. "description": "object type matches objects",
  26023. "schema": {"type": "object"},
  26024. "tests": [
  26025. {
  26026. "description": "an integer is not an object",
  26027. "data": 1,
  26028. "valid": false
  26029. },
  26030. {
  26031. "description": "a float is not an object",
  26032. "data": 1.1,
  26033. "valid": false
  26034. },
  26035. {
  26036. "description": "a string is not an object",
  26037. "data": "foo",
  26038. "valid": false
  26039. },
  26040. {
  26041. "description": "an object is an object",
  26042. "data": {},
  26043. "valid": true
  26044. },
  26045. {
  26046. "description": "an array is not an object",
  26047. "data": [],
  26048. "valid": false
  26049. },
  26050. {
  26051. "description": "a boolean is not an object",
  26052. "data": true,
  26053. "valid": false
  26054. },
  26055. {
  26056. "description": "null is not an object",
  26057. "data": null,
  26058. "valid": false
  26059. }
  26060. ]
  26061. },
  26062. {
  26063. "description": "array type matches arrays",
  26064. "schema": {"type": "array"},
  26065. "tests": [
  26066. {
  26067. "description": "an integer is not an array",
  26068. "data": 1,
  26069. "valid": false
  26070. },
  26071. {
  26072. "description": "a float is not an array",
  26073. "data": 1.1,
  26074. "valid": false
  26075. },
  26076. {
  26077. "description": "a string is not an array",
  26078. "data": "foo",
  26079. "valid": false
  26080. },
  26081. {
  26082. "description": "an object is not an array",
  26083. "data": {},
  26084. "valid": false
  26085. },
  26086. {
  26087. "description": "an array is not an array",
  26088. "data": [],
  26089. "valid": true
  26090. },
  26091. {
  26092. "description": "a boolean is not an array",
  26093. "data": true,
  26094. "valid": false
  26095. },
  26096. {
  26097. "description": "null is not an array",
  26098. "data": null,
  26099. "valid": false
  26100. }
  26101. ]
  26102. },
  26103. {
  26104. "description": "boolean type matches booleans",
  26105. "schema": {"type": "boolean"},
  26106. "tests": [
  26107. {
  26108. "description": "an integer is not a boolean",
  26109. "data": 1,
  26110. "valid": false
  26111. },
  26112. {
  26113. "description": "a float is not a boolean",
  26114. "data": 1.1,
  26115. "valid": false
  26116. },
  26117. {
  26118. "description": "a string is not a boolean",
  26119. "data": "foo",
  26120. "valid": false
  26121. },
  26122. {
  26123. "description": "an object is not a boolean",
  26124. "data": {},
  26125. "valid": false
  26126. },
  26127. {
  26128. "description": "an array is not a boolean",
  26129. "data": [],
  26130. "valid": false
  26131. },
  26132. {
  26133. "description": "a boolean is not a boolean",
  26134. "data": true,
  26135. "valid": true
  26136. },
  26137. {
  26138. "description": "null is not a boolean",
  26139. "data": null,
  26140. "valid": false
  26141. }
  26142. ]
  26143. },
  26144. {
  26145. "description": "null type matches only the null object",
  26146. "schema": {"type": "null"},
  26147. "tests": [
  26148. {
  26149. "description": "an integer is not null",
  26150. "data": 1,
  26151. "valid": false
  26152. },
  26153. {
  26154. "description": "a float is not null",
  26155. "data": 1.1,
  26156. "valid": false
  26157. },
  26158. {
  26159. "description": "a string is not null",
  26160. "data": "foo",
  26161. "valid": false
  26162. },
  26163. {
  26164. "description": "an object is not null",
  26165. "data": {},
  26166. "valid": false
  26167. },
  26168. {
  26169. "description": "an array is not null",
  26170. "data": [],
  26171. "valid": false
  26172. },
  26173. {
  26174. "description": "a boolean is not null",
  26175. "data": true,
  26176. "valid": false
  26177. },
  26178. {
  26179. "description": "null is null",
  26180. "data": null,
  26181. "valid": true
  26182. }
  26183. ]
  26184. },
  26185. {
  26186. "description": "multiple types can be specified in an array",
  26187. "schema": {"type": ["integer", "string"]},
  26188. "tests": [
  26189. {
  26190. "description": "an integer is valid",
  26191. "data": 1,
  26192. "valid": true
  26193. },
  26194. {
  26195. "description": "a string is valid",
  26196. "data": "foo",
  26197. "valid": true
  26198. },
  26199. {
  26200. "description": "a float is invalid",
  26201. "data": 1.1,
  26202. "valid": false
  26203. },
  26204. {
  26205. "description": "an object is invalid",
  26206. "data": {},
  26207. "valid": false
  26208. },
  26209. {
  26210. "description": "an array is invalid",
  26211. "data": [],
  26212. "valid": false
  26213. },
  26214. {
  26215. "description": "a boolean is invalid",
  26216. "data": true,
  26217. "valid": false
  26218. },
  26219. {
  26220. "description": "null is invalid",
  26221. "data": null,
  26222. "valid": false
  26223. }
  26224. ]
  26225. }
  26226. ]
  26227. },{}],264:[function(require,module,exports){
  26228. module.exports=[
  26229. {
  26230. "description": "uniqueItems validation",
  26231. "schema": {"uniqueItems": true},
  26232. "tests": [
  26233. {
  26234. "description": "unique array of integers is valid",
  26235. "data": [1, 2],
  26236. "valid": true
  26237. },
  26238. {
  26239. "description": "non-unique array of integers is invalid",
  26240. "data": [1, 1],
  26241. "valid": false
  26242. },
  26243. {
  26244. "description": "numbers are unique if mathematically unequal",
  26245. "data": [1.0, 1.00, 1],
  26246. "valid": false
  26247. },
  26248. {
  26249. "description": "unique array of objects is valid",
  26250. "data": [{"foo": "bar"}, {"foo": "baz"}],
  26251. "valid": true
  26252. },
  26253. {
  26254. "description": "non-unique array of objects is invalid",
  26255. "data": [{"foo": "bar"}, {"foo": "bar"}],
  26256. "valid": false
  26257. },
  26258. {
  26259. "description": "unique array of nested objects is valid",
  26260. "data": [
  26261. {"foo": {"bar" : {"baz" : true}}},
  26262. {"foo": {"bar" : {"baz" : false}}}
  26263. ],
  26264. "valid": true
  26265. },
  26266. {
  26267. "description": "non-unique array of nested objects is invalid",
  26268. "data": [
  26269. {"foo": {"bar" : {"baz" : true}}},
  26270. {"foo": {"bar" : {"baz" : true}}}
  26271. ],
  26272. "valid": false
  26273. },
  26274. {
  26275. "description": "unique array of arrays is valid",
  26276. "data": [["foo"], ["bar"]],
  26277. "valid": true
  26278. },
  26279. {
  26280. "description": "non-unique array of arrays is invalid",
  26281. "data": [["foo"], ["foo"]],
  26282. "valid": false
  26283. },
  26284. {
  26285. "description": "1 and true are unique",
  26286. "data": [1, true],
  26287. "valid": true
  26288. },
  26289. {
  26290. "description": "0 and false are unique",
  26291. "data": [0, false],
  26292. "valid": true
  26293. },
  26294. {
  26295. "description": "unique heterogeneous types are valid",
  26296. "data": [{}, [1], true, null, 1],
  26297. "valid": true
  26298. },
  26299. {
  26300. "description": "non-unique heterogeneous types are invalid",
  26301. "data": [{}, [1], true, null, {}, 1],
  26302. "valid": false
  26303. }
  26304. ]
  26305. }
  26306. ]
  26307. },{}],265:[function(require,module,exports){
  26308. "use strict";
  26309. var isBrowser = typeof window !== "undefined";
  26310. var ZSchema = require("../../src/ZSchema");
  26311. if (!isBrowser) {
  26312. var request = require("https").request;
  26313. }
  26314. function validateWithAutomaticDownloads(validator, data, schema, callback) {
  26315. var lastResult;
  26316. function finish() {
  26317. callback(validator.getLastErrors(), lastResult);
  26318. }
  26319. function validate() {
  26320. lastResult = validator.validate(data, schema);
  26321. var missingReferences = validator.getMissingRemoteReferences();
  26322. if (missingReferences.length > 0) {
  26323. var finished = 0;
  26324. missingReferences.forEach(function (url) {
  26325. request(url, function (response) {
  26326. var body = "";
  26327. response.on("data", function (chunk) { data += chunk; });
  26328. response.on("end", function () {
  26329. validator.setRemoteReference(url, JSON.parse(body));
  26330. finished++;
  26331. if (finished === missingReferences.length) {
  26332. validate();
  26333. }
  26334. });
  26335. });
  26336. });
  26337. } else {
  26338. finish();
  26339. }
  26340. }
  26341. validate();
  26342. }
  26343. describe("Automatic schema loading", function () {
  26344. it("should download schemas and validate successfully", function (done) {
  26345. if (isBrowser) {
  26346. // skip this test in browsers
  26347. expect(1).toBe(1);
  26348. done();
  26349. return;
  26350. }
  26351. var validator = new ZSchema();
  26352. var schema = { "$ref": "http://json-schema.org/draft-04/schema#" };
  26353. var data = { "minLength": 1 };
  26354. validateWithAutomaticDownloads(validator, data, schema, function (err, valid) {
  26355. expect(valid).toBe(true);
  26356. expect(err).toBe(null);
  26357. done();
  26358. });
  26359. });
  26360. it("should download schemas and fail validating", function (done) {
  26361. if (typeof window !== "undefined") {
  26362. // skip this test in browsers
  26363. expect(1).toBe(1);
  26364. done();
  26365. return;
  26366. }
  26367. var validator = new ZSchema();
  26368. var schema = { "$ref": "http://json-schema.org/draft-04/schema#" };
  26369. var data = { "minLength": -1 };
  26370. validateWithAutomaticDownloads(validator, data, schema, function (err, valid) {
  26371. expect(valid).toBe(false);
  26372. expect(err[0].code).toBe("MINIMUM");
  26373. done();
  26374. });
  26375. });
  26376. });
  26377. },{"../../src/ZSchema":151,"https":6}],266:[function(require,module,exports){
  26378. "use strict";
  26379. var ZSchema = require("../../src/ZSchema");
  26380. function setRemoteReferences(validator) {
  26381. validator.setRemoteReference("http://json-schema.org/draft-04/schema",
  26382. require("../files/draft-04-schema.json"));
  26383. validator.setRemoteReference("http://localhost:1234/integer.json",
  26384. require("../jsonSchemaTestSuite/remotes/integer.json"));
  26385. validator.setRemoteReference("http://localhost:1234/subSchemas.json",
  26386. require("../jsonSchemaTestSuite/remotes/subSchemas.json"));
  26387. validator.setRemoteReference("http://localhost:1234/folder/folderInteger.json",
  26388. require("../jsonSchemaTestSuite/remotes/folder/folderInteger.json"));
  26389. }
  26390. describe("Basic", function () {
  26391. it("ZSchema constructor should take one argument - options", function () {
  26392. expect(ZSchema.length).toBe(1);
  26393. });
  26394. it("Work in progress test...", function () {
  26395. var validator = new ZSchema();
  26396. setRemoteReferences(validator);
  26397. var schema = [
  26398. {
  26399. id: "schemaA",
  26400. type: "integer"
  26401. },
  26402. {
  26403. id: "schemaB",
  26404. type: "string"
  26405. },
  26406. {
  26407. id: "mainSchema",
  26408. type: "object",
  26409. properties: {
  26410. a: { "$ref": "schemaA" },
  26411. b: { "$ref": "schemaB" },
  26412. c: { "enum": ["C"] }
  26413. }
  26414. }
  26415. ];
  26416. var data = {
  26417. a: 1,
  26418. b: "str",
  26419. c: "C"
  26420. };
  26421. var validSchema = validator.validateSchema(schema);
  26422. expect(validSchema).toBe(true);
  26423. if (!validSchema) {
  26424. console.log(validator.getLastErrors());
  26425. return;
  26426. }
  26427. var valid = validator.validate(data, schema[2]);
  26428. expect(valid).toBe(true);
  26429. if (!valid) {
  26430. console.log(validator.getLastErrors());
  26431. return;
  26432. }
  26433. });
  26434. });
  26435. },{"../../src/ZSchema":151,"../files/draft-04-schema.json":231,"../jsonSchemaTestSuite/remotes/folder/folderInteger.json":232,"../jsonSchemaTestSuite/remotes/integer.json":233,"../jsonSchemaTestSuite/remotes/subSchemas.json":234}],267:[function(require,module,exports){
  26436. "use strict";
  26437. var ZSchema = require("../../src/ZSchema");
  26438. function setRemoteReferences(validator) {
  26439. validator.setRemoteReference("http://json-schema.org/draft-04/schema",
  26440. require("../files/draft-04-schema.json"));
  26441. validator.setRemoteReference("http://localhost:1234/integer.json",
  26442. require("../jsonSchemaTestSuite/remotes/integer.json"));
  26443. validator.setRemoteReference("http://localhost:1234/subSchemas.json",
  26444. require("../jsonSchemaTestSuite/remotes/subSchemas.json"));
  26445. validator.setRemoteReference("http://localhost:1234/folder/folderInteger.json",
  26446. require("../jsonSchemaTestSuite/remotes/folder/folderInteger.json"));
  26447. }
  26448. var jsonSchemaTestSuiteFiles = [
  26449. require("../jsonSchemaTestSuite/tests/draft4/additionalItems.json"),
  26450. require("../jsonSchemaTestSuite/tests/draft4/additionalProperties.json"),
  26451. require("../jsonSchemaTestSuite/tests/draft4/allOf.json"),
  26452. require("../jsonSchemaTestSuite/tests/draft4/anyOf.json"),
  26453. require("../jsonSchemaTestSuite/tests/draft4/default.json"),
  26454. require("../jsonSchemaTestSuite/tests/draft4/definitions.json"),
  26455. require("../jsonSchemaTestSuite/tests/draft4/dependencies.json"),
  26456. require("../jsonSchemaTestSuite/tests/draft4/enum.json"),
  26457. require("../jsonSchemaTestSuite/tests/draft4/items.json"),
  26458. require("../jsonSchemaTestSuite/tests/draft4/maximum.json"),
  26459. require("../jsonSchemaTestSuite/tests/draft4/maxItems.json"),
  26460. require("../jsonSchemaTestSuite/tests/draft4/maxLength.json"),
  26461. require("../jsonSchemaTestSuite/tests/draft4/maxProperties.json"),
  26462. require("../jsonSchemaTestSuite/tests/draft4/minimum.json"),
  26463. require("../jsonSchemaTestSuite/tests/draft4/minItems.json"),
  26464. require("../jsonSchemaTestSuite/tests/draft4/minLength.json"),
  26465. require("../jsonSchemaTestSuite/tests/draft4/minProperties.json"),
  26466. require("../jsonSchemaTestSuite/tests/draft4/multipleOf.json"),
  26467. require("../jsonSchemaTestSuite/tests/draft4/not.json"),
  26468. require("../jsonSchemaTestSuite/tests/draft4/oneOf.json"),
  26469. require("../jsonSchemaTestSuite/tests/draft4/pattern.json"),
  26470. require("../jsonSchemaTestSuite/tests/draft4/patternProperties.json"),
  26471. require("../jsonSchemaTestSuite/tests/draft4/properties.json"),
  26472. require("../jsonSchemaTestSuite/tests/draft4/ref.json"),
  26473. require("../jsonSchemaTestSuite/tests/draft4/refRemote.json"),
  26474. require("../jsonSchemaTestSuite/tests/draft4/required.json"),
  26475. require("../jsonSchemaTestSuite/tests/draft4/type.json"),
  26476. require("../jsonSchemaTestSuite/tests/draft4/uniqueItems.json"),
  26477. // optional
  26478. require("../jsonSchemaTestSuite/tests/draft4/optional/bignum.json"),
  26479. require("../jsonSchemaTestSuite/tests/draft4/optional/format.json")
  26480. // zeroTerminatedFloats.json is excluded because JavaScript doesn't distinguish between different types of numeric values
  26481. // require("../jsonSchemaTestSuite/tests/draft4/optional/zeroTerminatedFloats.json")
  26482. ];
  26483. var testExcludes = [
  26484. "an invalid URI",
  26485. "an invalid URI though valid URI reference"
  26486. ];
  26487. describe("JsonSchemaTestSuite", function () {
  26488. it("should contain 30 files", function () {
  26489. expect(jsonSchemaTestSuiteFiles.length).toBe(30);
  26490. });
  26491. jsonSchemaTestSuiteFiles.forEach(function (testDefinitions, fileIndex) {
  26492. testDefinitions.forEach(function (testDefinition) {
  26493. testDefinition.tests.forEach(function (test) {
  26494. if (testExcludes.indexOf(test.description) !== -1) { return; }
  26495. it("[" + fileIndex + "]" + testDefinition.description + " - " + test.description + ": " + JSON.stringify(test.data), function () {
  26496. var validator = new ZSchema();
  26497. setRemoteReferences(validator);
  26498. var valid = validator.validate(test.data, testDefinition.schema);
  26499. expect(valid).toBe(test.valid);
  26500. if (valid !== test.valid) {
  26501. if (!valid) {
  26502. var errors = validator.getLastErrors();
  26503. expect(errors).toBe(null);
  26504. }
  26505. }
  26506. });
  26507. });
  26508. });
  26509. });
  26510. });
  26511. },{"../../src/ZSchema":151,"../files/draft-04-schema.json":231,"../jsonSchemaTestSuite/remotes/folder/folderInteger.json":232,"../jsonSchemaTestSuite/remotes/integer.json":233,"../jsonSchemaTestSuite/remotes/subSchemas.json":234,"../jsonSchemaTestSuite/tests/draft4/additionalItems.json":235,"../jsonSchemaTestSuite/tests/draft4/additionalProperties.json":236,"../jsonSchemaTestSuite/tests/draft4/allOf.json":237,"../jsonSchemaTestSuite/tests/draft4/anyOf.json":238,"../jsonSchemaTestSuite/tests/draft4/default.json":239,"../jsonSchemaTestSuite/tests/draft4/definitions.json":240,"../jsonSchemaTestSuite/tests/draft4/dependencies.json":241,"../jsonSchemaTestSuite/tests/draft4/enum.json":242,"../jsonSchemaTestSuite/tests/draft4/items.json":243,"../jsonSchemaTestSuite/tests/draft4/maxItems.json":244,"../jsonSchemaTestSuite/tests/draft4/maxLength.json":245,"../jsonSchemaTestSuite/tests/draft4/maxProperties.json":246,"../jsonSchemaTestSuite/tests/draft4/maximum.json":247,"../jsonSchemaTestSuite/tests/draft4/minItems.json":248,"../jsonSchemaTestSuite/tests/draft4/minLength.json":249,"../jsonSchemaTestSuite/tests/draft4/minProperties.json":250,"../jsonSchemaTestSuite/tests/draft4/minimum.json":251,"../jsonSchemaTestSuite/tests/draft4/multipleOf.json":252,"../jsonSchemaTestSuite/tests/draft4/not.json":253,"../jsonSchemaTestSuite/tests/draft4/oneOf.json":254,"../jsonSchemaTestSuite/tests/draft4/optional/bignum.json":255,"../jsonSchemaTestSuite/tests/draft4/optional/format.json":256,"../jsonSchemaTestSuite/tests/draft4/pattern.json":257,"../jsonSchemaTestSuite/tests/draft4/patternProperties.json":258,"../jsonSchemaTestSuite/tests/draft4/properties.json":259,"../jsonSchemaTestSuite/tests/draft4/ref.json":260,"../jsonSchemaTestSuite/tests/draft4/refRemote.json":261,"../jsonSchemaTestSuite/tests/draft4/required.json":262,"../jsonSchemaTestSuite/tests/draft4/type.json":263,"../jsonSchemaTestSuite/tests/draft4/uniqueItems.json":264}],268:[function(require,module,exports){
  26512. "use strict";
  26513. var ZSchema = require("../../src/ZSchema");
  26514. describe("Using multiple instances of Z-Schema", function () {
  26515. it("Should pass all tests", function () {
  26516. var schema = {
  26517. "$schema": "http://json-schema.org/draft-04/schema#",
  26518. "type": "object",
  26519. "properties": {
  26520. "options": {
  26521. "enum": ["a", "b", "c"]
  26522. }
  26523. }
  26524. };
  26525. var v;
  26526. v = new ZSchema({ strictMode: true });
  26527. // Should fail because "additionalProperties" is missing
  26528. expect(v.validateSchema(schema)).toBe(false, "1st");
  26529. v = new ZSchema();
  26530. expect(v.validateSchema(schema)).toBe(true, "2nd");
  26531. v = new ZSchema({ strictMode: true });
  26532. expect(v.validateSchema(schema)).toBe(false, "3rd");
  26533. });
  26534. });
  26535. },{"../../src/ZSchema":151}],269:[function(require,module,exports){
  26536. /*jshint -W030 */
  26537. "use strict";
  26538. var ZSchema = require("../../src/ZSchema");
  26539. var testSuiteFiles = [
  26540. require("../ZSchemaTestSuite/CustomFormats.js"),
  26541. require("../ZSchemaTestSuite/CustomFormatsAsync.js"),
  26542. require("../ZSchemaTestSuite/ForceAdditional.js"),
  26543. require("../ZSchemaTestSuite/ForceItems.js"),
  26544. require("../ZSchemaTestSuite/ForceMinLength.js"),
  26545. require("../ZSchemaTestSuite/ForceMaxLength.js"),
  26546. require("../ZSchemaTestSuite/ForceMinItems.js"),
  26547. require("../ZSchemaTestSuite/ForceMaxItems.js"),
  26548. require("../ZSchemaTestSuite/ForceProperties.js"),
  26549. require("../ZSchemaTestSuite/IgnoreUnresolvableReferences.js"),
  26550. require("../ZSchemaTestSuite/AssumeAdditional.js"),
  26551. require("../ZSchemaTestSuite/NoEmptyArrays.js"),
  26552. require("../ZSchemaTestSuite/NoEmptyStrings.js"),
  26553. require("../ZSchemaTestSuite/NoTypeless.js"),
  26554. require("../ZSchemaTestSuite/NoExtraKeywords.js"),
  26555. require("../ZSchemaTestSuite/StrictUris.js"),
  26556. require("../ZSchemaTestSuite/MultipleSchemas.js"),
  26557. require("../ZSchemaTestSuite/ErrorPathAsArray.js"),
  26558. require("../ZSchemaTestSuite/ErrorPathAsJSONPointer.js"),
  26559. require("../ZSchemaTestSuite/ErrorPathContainsIntegerIndex.js"),
  26560. require("../ZSchemaTestSuite/PedanticCheck.js"),
  26561. require("../ZSchemaTestSuite/getRegisteredFormats.js"),
  26562. require("../ZSchemaTestSuite/InvalidId.js"),
  26563. require("../ZSchemaTestSuite/IncludeErrors.js"),
  26564. require("../ZSchemaTestSuite/CustomValidator.js"),
  26565. // issues
  26566. require("../ZSchemaTestSuite/Issue12.js"),
  26567. require("../ZSchemaTestSuite/Issue13.js"),
  26568. require("../ZSchemaTestSuite/Issue16.js"),
  26569. require("../ZSchemaTestSuite/Issue22.js"),
  26570. require("../ZSchemaTestSuite/Issue25.js"),
  26571. require("../ZSchemaTestSuite/Issue26.js"),
  26572. require("../ZSchemaTestSuite/Issue37.js"),
  26573. require("../ZSchemaTestSuite/Issue40.js"),
  26574. require("../ZSchemaTestSuite/Issue41.js"),
  26575. require("../ZSchemaTestSuite/Issue43.js"),
  26576. require("../ZSchemaTestSuite/Issue44.js"),
  26577. require("../ZSchemaTestSuite/Issue45.js"),
  26578. require("../ZSchemaTestSuite/Issue47.js"),
  26579. require("../ZSchemaTestSuite/Issue48.js"),
  26580. require("../ZSchemaTestSuite/Issue49.js"),
  26581. require("../ZSchemaTestSuite/Issue53.js"),
  26582. require("../ZSchemaTestSuite/Issue56.js"),
  26583. require("../ZSchemaTestSuite/Issue57.js"),
  26584. require("../ZSchemaTestSuite/Issue58.js"),
  26585. require("../ZSchemaTestSuite/Issue63.js"),
  26586. require("../ZSchemaTestSuite/Issue64.js"),
  26587. require("../ZSchemaTestSuite/Issue67.js"),
  26588. require("../ZSchemaTestSuite/Issue71.js"),
  26589. require("../ZSchemaTestSuite/Issue73.js"),
  26590. require("../ZSchemaTestSuite/Issue76.js"),
  26591. require("../ZSchemaTestSuite/Issue85.js"),
  26592. require("../ZSchemaTestSuite/Issue94.js"),
  26593. require("../ZSchemaTestSuite/Issue96.js"),
  26594. require("../ZSchemaTestSuite/Issue98.js"),
  26595. require("../ZSchemaTestSuite/Issue101.js"),
  26596. require("../ZSchemaTestSuite/Issue102.js"),
  26597. require("../ZSchemaTestSuite/Issue103.js"),
  26598. require("../ZSchemaTestSuite/Issue106.js"),
  26599. require("../ZSchemaTestSuite/Issue107.js"),
  26600. require("../ZSchemaTestSuite/Issue121.js"),
  26601. require("../ZSchemaTestSuite/Issue126.js"),
  26602. require("../ZSchemaTestSuite/Issue130.js"),
  26603. require("../ZSchemaTestSuite/Issue131.js"),
  26604. require("../ZSchemaTestSuite/Issue137.js"),
  26605. require("../ZSchemaTestSuite/Issue139.js"),
  26606. require("../ZSchemaTestSuite/Issue142.js"),
  26607. require("../ZSchemaTestSuite/Issue146.js"),
  26608. require("../ZSchemaTestSuite/Issue151.js"),
  26609. require("../ZSchemaTestSuite/Issue199.js"),
  26610. require("../ZSchemaTestSuite/Issue209.js"),
  26611. require("../ZSchemaTestSuite/Issue222.js"),
  26612. require("../ZSchemaTestSuite/Issue229.js"),
  26613. require("../ZSchemaTestSuite/Issue250.js"),
  26614. undefined
  26615. ];
  26616. describe("ZSchemaTestSuite", function () {
  26617. var idx = testSuiteFiles.length;
  26618. while (idx--) {
  26619. if (testSuiteFiles[idx] == null) {
  26620. testSuiteFiles.splice(idx, 1);
  26621. }
  26622. }
  26623. testSuiteFiles.forEach(function (testSuite) {
  26624. testSuite.tests.forEach(function (test) {
  26625. var data = test.data;
  26626. if (typeof data === "undefined") {
  26627. data = testSuite.data;
  26628. }
  26629. var validateOptions = test.validateOptions;
  26630. if (typeof validateOptions === "undefined") {
  26631. validateOptions = testSuite.validateOptions;
  26632. }
  26633. var async = test.async || testSuite.async || false,
  26634. options = test.options || testSuite.options || undefined,
  26635. setup = test.setup || testSuite.setup,
  26636. schema = test.schema || testSuite.schema,
  26637. schemaIndex = test.schemaIndex || testSuite.schemaIndex || 0,
  26638. after = test.after || testSuite.after,
  26639. validateSchemaOnly = test.validateSchemaOnly || testSuite.validateSchemaOnly,
  26640. failWithException = test.failWithException || testSuite.failWithException;
  26641. !async && it(testSuite.description + ", " + test.description, function () {
  26642. ZSchema.setSchemaReader(null);
  26643. var validator = new ZSchema(options);
  26644. var caughtErr;
  26645. if (setup) { setup(validator, ZSchema); }
  26646. var valid;
  26647. try {
  26648. valid = validator.validateSchema(schema);
  26649. } catch (err) {
  26650. if (!failWithException) {
  26651. throw err;
  26652. }
  26653. caughtErr = err;
  26654. }
  26655. if (valid && !validateSchemaOnly) {
  26656. if (Array.isArray(schema)) {
  26657. schema = schema[schemaIndex];
  26658. }
  26659. try {
  26660. valid = validator.validate(data, schema, validateOptions);
  26661. } catch (err) {
  26662. if (!failWithException) {
  26663. throw err;
  26664. }
  26665. caughtErr = err;
  26666. }
  26667. }
  26668. var err = caughtErr || validator.getLastErrors();
  26669. if (failWithException) {
  26670. expect(caughtErr).toBeTruthy();
  26671. } else {
  26672. expect(typeof valid).toBe("boolean", "returned response is not a boolean");
  26673. expect(valid).toBe(test.valid, "test result doesn't match expected test result");
  26674. }
  26675. if (test.valid === true) {
  26676. expect(err).toBe(null, "errors are not undefined when test is valid");
  26677. }
  26678. if (after) {
  26679. after(err, valid, data, validator);
  26680. }
  26681. });
  26682. async && it(testSuite.description + ", " + test.description, function (done) {
  26683. var validator = new ZSchema(options);
  26684. if (setup) { setup(validator, ZSchema); }
  26685. // see http://blog.izs.me/post/59142742143/designing-apis-for-asynchrony
  26686. var zalgo = false;
  26687. var result = validator.validate(data, schema, function (err, valid) {
  26688. // make sure callback wasn't called synchronously
  26689. expect(zalgo).toBe(true, "callback was fired in synchronous way");
  26690. expect(typeof valid).toBe("boolean", "returned response is not a boolean");
  26691. expect(valid).toBe(test.valid, "test result doesn't match expected test result");
  26692. if (test.valid === true) {
  26693. expect(err).toBe(null, "errors are not undefined when test is valid");
  26694. }
  26695. if (after) {
  26696. after(err, valid, data);
  26697. }
  26698. done();
  26699. });
  26700. // never return anything when callback is specified
  26701. expect(result).toBe(undefined, "validator returned something else than undefined in callback mode");
  26702. zalgo = true;
  26703. });
  26704. });
  26705. });
  26706. });
  26707. },{"../../src/ZSchema":151,"../ZSchemaTestSuite/AssumeAdditional.js":154,"../ZSchemaTestSuite/CustomFormats.js":155,"../ZSchemaTestSuite/CustomFormatsAsync.js":156,"../ZSchemaTestSuite/CustomValidator.js":157,"../ZSchemaTestSuite/ErrorPathAsArray.js":158,"../ZSchemaTestSuite/ErrorPathAsJSONPointer.js":159,"../ZSchemaTestSuite/ErrorPathContainsIntegerIndex.js":160,"../ZSchemaTestSuite/ForceAdditional.js":161,"../ZSchemaTestSuite/ForceItems.js":162,"../ZSchemaTestSuite/ForceMaxItems.js":163,"../ZSchemaTestSuite/ForceMaxLength.js":164,"../ZSchemaTestSuite/ForceMinItems.js":165,"../ZSchemaTestSuite/ForceMinLength.js":166,"../ZSchemaTestSuite/ForceProperties.js":167,"../ZSchemaTestSuite/IgnoreUnresolvableReferences.js":168,"../ZSchemaTestSuite/IncludeErrors.js":169,"../ZSchemaTestSuite/InvalidId.js":170,"../ZSchemaTestSuite/Issue101.js":171,"../ZSchemaTestSuite/Issue102.js":172,"../ZSchemaTestSuite/Issue103.js":173,"../ZSchemaTestSuite/Issue106.js":174,"../ZSchemaTestSuite/Issue107.js":175,"../ZSchemaTestSuite/Issue12.js":176,"../ZSchemaTestSuite/Issue121.js":177,"../ZSchemaTestSuite/Issue126.js":178,"../ZSchemaTestSuite/Issue13.js":179,"../ZSchemaTestSuite/Issue130.js":180,"../ZSchemaTestSuite/Issue131.js":181,"../ZSchemaTestSuite/Issue137.js":182,"../ZSchemaTestSuite/Issue139.js":183,"../ZSchemaTestSuite/Issue142.js":184,"../ZSchemaTestSuite/Issue146.js":185,"../ZSchemaTestSuite/Issue151.js":186,"../ZSchemaTestSuite/Issue16.js":187,"../ZSchemaTestSuite/Issue199.js":188,"../ZSchemaTestSuite/Issue209.js":189,"../ZSchemaTestSuite/Issue22.js":190,"../ZSchemaTestSuite/Issue222.js":191,"../ZSchemaTestSuite/Issue229.js":192,"../ZSchemaTestSuite/Issue25.js":193,"../ZSchemaTestSuite/Issue250.js":194,"../ZSchemaTestSuite/Issue26.js":195,"../ZSchemaTestSuite/Issue37.js":196,"../ZSchemaTestSuite/Issue40.js":197,"../ZSchemaTestSuite/Issue41.js":198,"../ZSchemaTestSuite/Issue43.js":199,"../ZSchemaTestSuite/Issue44.js":200,"../ZSchemaTestSuite/Issue45.js":201,"../ZSchemaTestSuite/Issue47.js":202,"../ZSchemaTestSuite/Issue48.js":203,"../ZSchemaTestSuite/Issue49.js":204,"../ZSchemaTestSuite/Issue53.js":205,"../ZSchemaTestSuite/Issue56.js":206,"../ZSchemaTestSuite/Issue57.js":207,"../ZSchemaTestSuite/Issue58.js":208,"../ZSchemaTestSuite/Issue63.js":209,"../ZSchemaTestSuite/Issue64.js":210,"../ZSchemaTestSuite/Issue67.js":211,"../ZSchemaTestSuite/Issue71.js":212,"../ZSchemaTestSuite/Issue73.js":213,"../ZSchemaTestSuite/Issue76.js":214,"../ZSchemaTestSuite/Issue85.js":215,"../ZSchemaTestSuite/Issue94.js":216,"../ZSchemaTestSuite/Issue96.js":217,"../ZSchemaTestSuite/Issue98.js":218,"../ZSchemaTestSuite/MultipleSchemas.js":219,"../ZSchemaTestSuite/NoEmptyArrays.js":220,"../ZSchemaTestSuite/NoEmptyStrings.js":221,"../ZSchemaTestSuite/NoExtraKeywords.js":222,"../ZSchemaTestSuite/NoTypeless.js":223,"../ZSchemaTestSuite/PedanticCheck.js":224,"../ZSchemaTestSuite/StrictUris.js":225,"../ZSchemaTestSuite/getRegisteredFormats.js":230}],270:[function(require,module,exports){
  26708. "use strict";
  26709. var ZSchema = require("../../src/ZSchema");
  26710. var validator = new ZSchema();
  26711. var schema = {
  26712. "type": [
  26713. "object"
  26714. ],
  26715. "definitions": {
  26716. "car": {
  26717. "title": "Car",
  26718. "description": "It's a car",
  26719. "stability": "prototype",
  26720. "strictProperties": true,
  26721. "type": [
  26722. "object"
  26723. ],
  26724. "definitions": {
  26725. "id": {
  26726. "description": "unique identifier of car",
  26727. "readOnly": true,
  26728. "type": [
  26729. "string"
  26730. ]
  26731. },
  26732. "car": {
  26733. "description": "Car object",
  26734. "type": [
  26735. "object"
  26736. ],
  26737. "properties": {
  26738. "brand": {
  26739. "description": "Car brand",
  26740. "type": [
  26741. "string"
  26742. ]
  26743. },
  26744. "engine": {
  26745. "description": "Car engine",
  26746. "type": [
  26747. "string"
  26748. ]
  26749. }
  26750. }
  26751. },
  26752. "cars": {
  26753. "description": "Collection of cars",
  26754. "type": [
  26755. "array"
  26756. ],
  26757. "items": {
  26758. "$ref": "#/definitions/car/definitions/car"
  26759. }
  26760. },
  26761. "identity": {
  26762. "$ref": "#/definitions/car/definitions/id"
  26763. }
  26764. },
  26765. "links": [],
  26766. "properties": {
  26767. "id": {
  26768. "$ref": "#/definitions/car/definitions/id"
  26769. }
  26770. }
  26771. }
  26772. },
  26773. "properties": {
  26774. "car": {
  26775. "$ref": "#/definitions/car"
  26776. }
  26777. },
  26778. "description": "Car API",
  26779. "id": "cars",
  26780. "links": [{
  26781. "href": "https://example.com/schema",
  26782. "rel": "self"
  26783. }],
  26784. "title": "Car API"
  26785. };
  26786. describe("Using path to schema as a third argument", function () {
  26787. it("Should pass the test", function () {
  26788. var cars = [
  26789. {
  26790. "brand": "Lexus",
  26791. "engine": "big"
  26792. }
  26793. ];
  26794. var valid = validator.validate(cars, schema, { schemaPath: "definitions.car.definitions.cars" });
  26795. expect(valid).toBe(true);
  26796. expect(validator.getLastError()).toBe(null);
  26797. });
  26798. });
  26799. },{"../../src/ZSchema":151}]},{},[265,266,267,268,270,269]);