Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590
  1. // Version: 1.0.0 - March 24, 2021 22:27:48
  2. 'use strict';
  3. var path$1 = require('path');
  4. var moment = require('moment');
  5. var crossfilterreq = require('crossfilter2');
  6. var crypto = require('crypto');
  7. var childProcess = require('child_process');
  8. var fs$1 = require('fs');
  9. var readline = require('readline');
  10. var os = require('os');
  11. var tty = require('tty');
  12. var require$$0 = require('util');
  13. var require$$0$1 = require('events');
  14. var assert = require('assert');
  15. function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
  16. var path__default = /*#__PURE__*/_interopDefaultLegacy(path$1);
  17. var moment__default = /*#__PURE__*/_interopDefaultLegacy(moment);
  18. var crossfilterreq__default = /*#__PURE__*/_interopDefaultLegacy(crossfilterreq);
  19. var crypto__default = /*#__PURE__*/_interopDefaultLegacy(crypto);
  20. var childProcess__default = /*#__PURE__*/_interopDefaultLegacy(childProcess);
  21. var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs$1);
  22. var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);
  23. var os__default = /*#__PURE__*/_interopDefaultLegacy(os);
  24. var tty__default = /*#__PURE__*/_interopDefaultLegacy(tty);
  25. var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
  26. var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$1);
  27. var assert__default = /*#__PURE__*/_interopDefaultLegacy(assert);
  28. var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
  29. function createCommonjsModule(fn, basedir, module) {
  30. return module = {
  31. path: basedir,
  32. exports: {},
  33. require: function (path, base) {
  34. return commonjsRequire(path, (base === undefined || base === null) ? module.path : base);
  35. }
  36. }, fn(module, module.exports), module.exports;
  37. }
  38. function commonjsRegister (path, loader) {
  39. DYNAMIC_REQUIRE_LOADERS[path] = loader;
  40. }
  41. const DYNAMIC_REQUIRE_LOADERS = Object.create(null);
  42. const DYNAMIC_REQUIRE_CACHE = Object.create(null);
  43. const DEFAULT_PARENT_MODULE = {
  44. id: '<' + 'rollup>', exports: {}, parent: undefined, filename: null, loaded: false, children: [], paths: []
  45. };
  46. const CHECKED_EXTENSIONS = ['', '.js', '.json'];
  47. function normalize (path) {
  48. path = path.replace(/\\/g, '/');
  49. const parts = path.split('/');
  50. const slashed = parts[0] === '';
  51. for (let i = 1; i < parts.length; i++) {
  52. if (parts[i] === '.' || parts[i] === '') {
  53. parts.splice(i--, 1);
  54. }
  55. }
  56. for (let i = 1; i < parts.length; i++) {
  57. if (parts[i] !== '..') continue;
  58. if (i > 0 && parts[i - 1] !== '..' && parts[i - 1] !== '.') {
  59. parts.splice(--i, 2);
  60. i--;
  61. }
  62. }
  63. path = parts.join('/');
  64. if (slashed && path[0] !== '/')
  65. path = '/' + path;
  66. else if (path.length === 0)
  67. path = '.';
  68. return path;
  69. }
  70. function join () {
  71. if (arguments.length === 0)
  72. return '.';
  73. let joined;
  74. for (let i = 0; i < arguments.length; ++i) {
  75. let arg = arguments[i];
  76. if (arg.length > 0) {
  77. if (joined === undefined)
  78. joined = arg;
  79. else
  80. joined += '/' + arg;
  81. }
  82. }
  83. if (joined === undefined)
  84. return '.';
  85. return joined;
  86. }
  87. function isPossibleNodeModulesPath (modulePath) {
  88. let c0 = modulePath[0];
  89. if (c0 === '/' || c0 === '\\') return false;
  90. let c1 = modulePath[1], c2 = modulePath[2];
  91. if ((c0 === '.' && (!c1 || c1 === '/' || c1 === '\\')) ||
  92. (c0 === '.' && c1 === '.' && (!c2 || c2 === '/' || c2 === '\\'))) return false;
  93. if (c1 === ':' && (c2 === '/' || c2 === '\\'))
  94. return false;
  95. return true;
  96. }
  97. function dirname (path) {
  98. if (path.length === 0)
  99. return '.';
  100. let i = path.length - 1;
  101. while (i > 0) {
  102. const c = path.charCodeAt(i);
  103. if ((c === 47 || c === 92) && i !== path.length - 1)
  104. break;
  105. i--;
  106. }
  107. if (i > 0)
  108. return path.substr(0, i);
  109. if (path.chartCodeAt(0) === 47 || path.chartCodeAt(0) === 92)
  110. return path.charAt(0);
  111. return '.';
  112. }
  113. function commonjsResolveImpl (path, originalModuleDir, testCache) {
  114. const shouldTryNodeModules = isPossibleNodeModulesPath(path);
  115. path = normalize(path);
  116. let relPath;
  117. if (path[0] === '/') {
  118. originalModuleDir = '/';
  119. }
  120. while (true) {
  121. if (!shouldTryNodeModules) {
  122. relPath = originalModuleDir ? normalize(originalModuleDir + '/' + path) : path;
  123. } else if (originalModuleDir) {
  124. relPath = normalize(originalModuleDir + '/node_modules/' + path);
  125. } else {
  126. relPath = normalize(join('node_modules', path));
  127. }
  128. if (relPath.endsWith('/..')) {
  129. break; // Travelled too far up, avoid infinite loop
  130. }
  131. for (let extensionIndex = 0; extensionIndex < CHECKED_EXTENSIONS.length; extensionIndex++) {
  132. const resolvedPath = relPath + CHECKED_EXTENSIONS[extensionIndex];
  133. if (DYNAMIC_REQUIRE_CACHE[resolvedPath]) {
  134. return resolvedPath;
  135. } if (DYNAMIC_REQUIRE_LOADERS[resolvedPath]) {
  136. return resolvedPath;
  137. } }
  138. if (!shouldTryNodeModules) break;
  139. const nextDir = normalize(originalModuleDir + '/..');
  140. if (nextDir === originalModuleDir) break;
  141. originalModuleDir = nextDir;
  142. }
  143. return null;
  144. }
  145. function commonjsResolve (path, originalModuleDir) {
  146. const resolvedPath = commonjsResolveImpl(path, originalModuleDir);
  147. if (resolvedPath !== null) {
  148. return resolvedPath;
  149. }
  150. return require.resolve(path);
  151. }
  152. function commonjsRequire (path, originalModuleDir) {
  153. const resolvedPath = commonjsResolveImpl(path, originalModuleDir);
  154. if (resolvedPath !== null) {
  155. let cachedModule = DYNAMIC_REQUIRE_CACHE[resolvedPath];
  156. if (cachedModule) return cachedModule.exports;
  157. const loader = DYNAMIC_REQUIRE_LOADERS[resolvedPath];
  158. if (loader) {
  159. DYNAMIC_REQUIRE_CACHE[resolvedPath] = cachedModule = {
  160. id: resolvedPath,
  161. filename: resolvedPath,
  162. path: dirname(resolvedPath),
  163. exports: {},
  164. parent: DEFAULT_PARENT_MODULE,
  165. loaded: false,
  166. children: [],
  167. paths: [],
  168. require: function (path, base) {
  169. return commonjsRequire(path, (base === undefined || base === null) ? cachedModule.path : base);
  170. }
  171. };
  172. try {
  173. loader.call(commonjsGlobal, cachedModule, cachedModule.exports);
  174. } catch (error) {
  175. delete DYNAMIC_REQUIRE_CACHE[resolvedPath];
  176. throw error;
  177. }
  178. cachedModule.loaded = true;
  179. return cachedModule.exports;
  180. } }
  181. return require(path);
  182. }
  183. commonjsRequire.cache = DYNAMIC_REQUIRE_CACHE;
  184. commonjsRequire.resolve = commonjsResolve;
  185. /**
  186. * This method returns the first argument it receives.
  187. *
  188. * @static
  189. * @since 0.1.0
  190. * @memberOf _
  191. * @category Util
  192. * @param {*} value Any value.
  193. * @returns {*} Returns `value`.
  194. * @example
  195. *
  196. * var object = { 'a': 1 };
  197. *
  198. * console.log(_.identity(object) === object);
  199. * // => true
  200. */
  201. function identity(value) {
  202. return value;
  203. }
  204. var identity_1 = identity;
  205. /** Detect free variable `global` from Node.js. */
  206. var freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal;
  207. var _freeGlobal = freeGlobal;
  208. /** Detect free variable `self`. */
  209. var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
  210. /** Used as a reference to the global object. */
  211. var root = _freeGlobal || freeSelf || Function('return this')();
  212. var _root = root;
  213. /** Built-in value references. */
  214. var Symbol$1 = _root.Symbol;
  215. var _Symbol = Symbol$1;
  216. /** Used for built-in method references. */
  217. var objectProto$h = Object.prototype;
  218. /** Used to check objects for own properties. */
  219. var hasOwnProperty$e = objectProto$h.hasOwnProperty;
  220. /**
  221. * Used to resolve the
  222. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  223. * of values.
  224. */
  225. var nativeObjectToString$1 = objectProto$h.toString;
  226. /** Built-in value references. */
  227. var symToStringTag$1 = _Symbol ? _Symbol.toStringTag : undefined;
  228. /**
  229. * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
  230. *
  231. * @private
  232. * @param {*} value The value to query.
  233. * @returns {string} Returns the raw `toStringTag`.
  234. */
  235. function getRawTag(value) {
  236. var isOwn = hasOwnProperty$e.call(value, symToStringTag$1),
  237. tag = value[symToStringTag$1];
  238. try {
  239. value[symToStringTag$1] = undefined;
  240. var unmasked = true;
  241. } catch (e) {}
  242. var result = nativeObjectToString$1.call(value);
  243. if (unmasked) {
  244. if (isOwn) {
  245. value[symToStringTag$1] = tag;
  246. } else {
  247. delete value[symToStringTag$1];
  248. }
  249. }
  250. return result;
  251. }
  252. var _getRawTag = getRawTag;
  253. /** Used for built-in method references. */
  254. var objectProto$g = Object.prototype;
  255. /**
  256. * Used to resolve the
  257. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  258. * of values.
  259. */
  260. var nativeObjectToString = objectProto$g.toString;
  261. /**
  262. * Converts `value` to a string using `Object.prototype.toString`.
  263. *
  264. * @private
  265. * @param {*} value The value to convert.
  266. * @returns {string} Returns the converted string.
  267. */
  268. function objectToString(value) {
  269. return nativeObjectToString.call(value);
  270. }
  271. var _objectToString = objectToString;
  272. /** `Object#toString` result references. */
  273. var nullTag = '[object Null]',
  274. undefinedTag = '[object Undefined]';
  275. /** Built-in value references. */
  276. var symToStringTag = _Symbol ? _Symbol.toStringTag : undefined;
  277. /**
  278. * The base implementation of `getTag` without fallbacks for buggy environments.
  279. *
  280. * @private
  281. * @param {*} value The value to query.
  282. * @returns {string} Returns the `toStringTag`.
  283. */
  284. function baseGetTag(value) {
  285. if (value == null) {
  286. return value === undefined ? undefinedTag : nullTag;
  287. }
  288. return (symToStringTag && symToStringTag in Object(value))
  289. ? _getRawTag(value)
  290. : _objectToString(value);
  291. }
  292. var _baseGetTag = baseGetTag;
  293. /**
  294. * Checks if `value` is the
  295. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  296. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  297. *
  298. * @static
  299. * @memberOf _
  300. * @since 0.1.0
  301. * @category Lang
  302. * @param {*} value The value to check.
  303. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  304. * @example
  305. *
  306. * _.isObject({});
  307. * // => true
  308. *
  309. * _.isObject([1, 2, 3]);
  310. * // => true
  311. *
  312. * _.isObject(_.noop);
  313. * // => true
  314. *
  315. * _.isObject(null);
  316. * // => false
  317. */
  318. function isObject$1(value) {
  319. var type = typeof value;
  320. return value != null && (type == 'object' || type == 'function');
  321. }
  322. var isObject_1 = isObject$1;
  323. /** `Object#toString` result references. */
  324. var asyncTag = '[object AsyncFunction]',
  325. funcTag$2 = '[object Function]',
  326. genTag$1 = '[object GeneratorFunction]',
  327. proxyTag = '[object Proxy]';
  328. /**
  329. * Checks if `value` is classified as a `Function` object.
  330. *
  331. * @static
  332. * @memberOf _
  333. * @since 0.1.0
  334. * @category Lang
  335. * @param {*} value The value to check.
  336. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  337. * @example
  338. *
  339. * _.isFunction(_);
  340. * // => true
  341. *
  342. * _.isFunction(/abc/);
  343. * // => false
  344. */
  345. function isFunction(value) {
  346. if (!isObject_1(value)) {
  347. return false;
  348. }
  349. // The use of `Object#toString` avoids issues with the `typeof` operator
  350. // in Safari 9 which returns 'object' for typed arrays and other constructors.
  351. var tag = _baseGetTag(value);
  352. return tag == funcTag$2 || tag == genTag$1 || tag == asyncTag || tag == proxyTag;
  353. }
  354. var isFunction_1 = isFunction;
  355. /** Used to detect overreaching core-js shims. */
  356. var coreJsData = _root['__core-js_shared__'];
  357. var _coreJsData = coreJsData;
  358. /** Used to detect methods masquerading as native. */
  359. var maskSrcKey = (function() {
  360. var uid = /[^.]+$/.exec(_coreJsData && _coreJsData.keys && _coreJsData.keys.IE_PROTO || '');
  361. return uid ? ('Symbol(src)_1.' + uid) : '';
  362. }());
  363. /**
  364. * Checks if `func` has its source masked.
  365. *
  366. * @private
  367. * @param {Function} func The function to check.
  368. * @returns {boolean} Returns `true` if `func` is masked, else `false`.
  369. */
  370. function isMasked(func) {
  371. return !!maskSrcKey && (maskSrcKey in func);
  372. }
  373. var _isMasked = isMasked;
  374. /** Used for built-in method references. */
  375. var funcProto$2 = Function.prototype;
  376. /** Used to resolve the decompiled source of functions. */
  377. var funcToString$2 = funcProto$2.toString;
  378. /**
  379. * Converts `func` to its source code.
  380. *
  381. * @private
  382. * @param {Function} func The function to convert.
  383. * @returns {string} Returns the source code.
  384. */
  385. function toSource(func) {
  386. if (func != null) {
  387. try {
  388. return funcToString$2.call(func);
  389. } catch (e) {}
  390. try {
  391. return (func + '');
  392. } catch (e) {}
  393. }
  394. return '';
  395. }
  396. var _toSource = toSource;
  397. /**
  398. * Used to match `RegExp`
  399. * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
  400. */
  401. var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
  402. /** Used to detect host constructors (Safari). */
  403. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  404. /** Used for built-in method references. */
  405. var funcProto$1 = Function.prototype,
  406. objectProto$f = Object.prototype;
  407. /** Used to resolve the decompiled source of functions. */
  408. var funcToString$1 = funcProto$1.toString;
  409. /** Used to check objects for own properties. */
  410. var hasOwnProperty$d = objectProto$f.hasOwnProperty;
  411. /** Used to detect if a method is native. */
  412. var reIsNative = RegExp('^' +
  413. funcToString$1.call(hasOwnProperty$d).replace(reRegExpChar, '\\$&')
  414. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  415. );
  416. /**
  417. * The base implementation of `_.isNative` without bad shim checks.
  418. *
  419. * @private
  420. * @param {*} value The value to check.
  421. * @returns {boolean} Returns `true` if `value` is a native function,
  422. * else `false`.
  423. */
  424. function baseIsNative(value) {
  425. if (!isObject_1(value) || _isMasked(value)) {
  426. return false;
  427. }
  428. var pattern = isFunction_1(value) ? reIsNative : reIsHostCtor;
  429. return pattern.test(_toSource(value));
  430. }
  431. var _baseIsNative = baseIsNative;
  432. /**
  433. * Gets the value at `key` of `object`.
  434. *
  435. * @private
  436. * @param {Object} [object] The object to query.
  437. * @param {string} key The key of the property to get.
  438. * @returns {*} Returns the property value.
  439. */
  440. function getValue(object, key) {
  441. return object == null ? undefined : object[key];
  442. }
  443. var _getValue = getValue;
  444. /**
  445. * Gets the native function at `key` of `object`.
  446. *
  447. * @private
  448. * @param {Object} object The object to query.
  449. * @param {string} key The key of the method to get.
  450. * @returns {*} Returns the function if it's native, else `undefined`.
  451. */
  452. function getNative(object, key) {
  453. var value = _getValue(object, key);
  454. return _baseIsNative(value) ? value : undefined;
  455. }
  456. var _getNative = getNative;
  457. /* Built-in method references that are verified to be native. */
  458. var WeakMap$1 = _getNative(_root, 'WeakMap');
  459. var _WeakMap = WeakMap$1;
  460. /** Used to store function metadata. */
  461. var metaMap = _WeakMap && new _WeakMap;
  462. var _metaMap = metaMap;
  463. /**
  464. * The base implementation of `setData` without support for hot loop shorting.
  465. *
  466. * @private
  467. * @param {Function} func The function to associate metadata with.
  468. * @param {*} data The metadata.
  469. * @returns {Function} Returns `func`.
  470. */
  471. var baseSetData = !_metaMap ? identity_1 : function(func, data) {
  472. _metaMap.set(func, data);
  473. return func;
  474. };
  475. var _baseSetData = baseSetData;
  476. /** Built-in value references. */
  477. var objectCreate = Object.create;
  478. /**
  479. * The base implementation of `_.create` without support for assigning
  480. * properties to the created object.
  481. *
  482. * @private
  483. * @param {Object} proto The object to inherit from.
  484. * @returns {Object} Returns the new object.
  485. */
  486. var baseCreate = (function() {
  487. function object() {}
  488. return function(proto) {
  489. if (!isObject_1(proto)) {
  490. return {};
  491. }
  492. if (objectCreate) {
  493. return objectCreate(proto);
  494. }
  495. object.prototype = proto;
  496. var result = new object;
  497. object.prototype = undefined;
  498. return result;
  499. };
  500. }());
  501. var _baseCreate = baseCreate;
  502. /**
  503. * Creates a function that produces an instance of `Ctor` regardless of
  504. * whether it was invoked as part of a `new` expression or by `call` or `apply`.
  505. *
  506. * @private
  507. * @param {Function} Ctor The constructor to wrap.
  508. * @returns {Function} Returns the new wrapped function.
  509. */
  510. function createCtor(Ctor) {
  511. return function() {
  512. // Use a `switch` statement to work with class constructors. See
  513. // http://ecma-international.org/ecma-262/7.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
  514. // for more details.
  515. var args = arguments;
  516. switch (args.length) {
  517. case 0: return new Ctor;
  518. case 1: return new Ctor(args[0]);
  519. case 2: return new Ctor(args[0], args[1]);
  520. case 3: return new Ctor(args[0], args[1], args[2]);
  521. case 4: return new Ctor(args[0], args[1], args[2], args[3]);
  522. case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
  523. case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]);
  524. case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
  525. }
  526. var thisBinding = _baseCreate(Ctor.prototype),
  527. result = Ctor.apply(thisBinding, args);
  528. // Mimic the constructor's `return` behavior.
  529. // See https://es5.github.io/#x13.2.2 for more details.
  530. return isObject_1(result) ? result : thisBinding;
  531. };
  532. }
  533. var _createCtor = createCtor;
  534. /** Used to compose bitmasks for function metadata. */
  535. var WRAP_BIND_FLAG$6 = 1;
  536. /**
  537. * Creates a function that wraps `func` to invoke it with the optional `this`
  538. * binding of `thisArg`.
  539. *
  540. * @private
  541. * @param {Function} func The function to wrap.
  542. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  543. * @param {*} [thisArg] The `this` binding of `func`.
  544. * @returns {Function} Returns the new wrapped function.
  545. */
  546. function createBind(func, bitmask, thisArg) {
  547. var isBind = bitmask & WRAP_BIND_FLAG$6,
  548. Ctor = _createCtor(func);
  549. function wrapper() {
  550. var fn = (this && this !== _root && this instanceof wrapper) ? Ctor : func;
  551. return fn.apply(isBind ? thisArg : this, arguments);
  552. }
  553. return wrapper;
  554. }
  555. var _createBind = createBind;
  556. /**
  557. * A faster alternative to `Function#apply`, this function invokes `func`
  558. * with the `this` binding of `thisArg` and the arguments of `args`.
  559. *
  560. * @private
  561. * @param {Function} func The function to invoke.
  562. * @param {*} thisArg The `this` binding of `func`.
  563. * @param {Array} args The arguments to invoke `func` with.
  564. * @returns {*} Returns the result of `func`.
  565. */
  566. function apply(func, thisArg, args) {
  567. switch (args.length) {
  568. case 0: return func.call(thisArg);
  569. case 1: return func.call(thisArg, args[0]);
  570. case 2: return func.call(thisArg, args[0], args[1]);
  571. case 3: return func.call(thisArg, args[0], args[1], args[2]);
  572. }
  573. return func.apply(thisArg, args);
  574. }
  575. var _apply = apply;
  576. /* Built-in method references for those with the same name as other `lodash` methods. */
  577. var nativeMax$3 = Math.max;
  578. /**
  579. * Creates an array that is the composition of partially applied arguments,
  580. * placeholders, and provided arguments into a single array of arguments.
  581. *
  582. * @private
  583. * @param {Array} args The provided arguments.
  584. * @param {Array} partials The arguments to prepend to those provided.
  585. * @param {Array} holders The `partials` placeholder indexes.
  586. * @params {boolean} [isCurried] Specify composing for a curried function.
  587. * @returns {Array} Returns the new array of composed arguments.
  588. */
  589. function composeArgs(args, partials, holders, isCurried) {
  590. var argsIndex = -1,
  591. argsLength = args.length,
  592. holdersLength = holders.length,
  593. leftIndex = -1,
  594. leftLength = partials.length,
  595. rangeLength = nativeMax$3(argsLength - holdersLength, 0),
  596. result = Array(leftLength + rangeLength),
  597. isUncurried = !isCurried;
  598. while (++leftIndex < leftLength) {
  599. result[leftIndex] = partials[leftIndex];
  600. }
  601. while (++argsIndex < holdersLength) {
  602. if (isUncurried || argsIndex < argsLength) {
  603. result[holders[argsIndex]] = args[argsIndex];
  604. }
  605. }
  606. while (rangeLength--) {
  607. result[leftIndex++] = args[argsIndex++];
  608. }
  609. return result;
  610. }
  611. var _composeArgs = composeArgs;
  612. /* Built-in method references for those with the same name as other `lodash` methods. */
  613. var nativeMax$2 = Math.max;
  614. /**
  615. * This function is like `composeArgs` except that the arguments composition
  616. * is tailored for `_.partialRight`.
  617. *
  618. * @private
  619. * @param {Array} args The provided arguments.
  620. * @param {Array} partials The arguments to append to those provided.
  621. * @param {Array} holders The `partials` placeholder indexes.
  622. * @params {boolean} [isCurried] Specify composing for a curried function.
  623. * @returns {Array} Returns the new array of composed arguments.
  624. */
  625. function composeArgsRight(args, partials, holders, isCurried) {
  626. var argsIndex = -1,
  627. argsLength = args.length,
  628. holdersIndex = -1,
  629. holdersLength = holders.length,
  630. rightIndex = -1,
  631. rightLength = partials.length,
  632. rangeLength = nativeMax$2(argsLength - holdersLength, 0),
  633. result = Array(rangeLength + rightLength),
  634. isUncurried = !isCurried;
  635. while (++argsIndex < rangeLength) {
  636. result[argsIndex] = args[argsIndex];
  637. }
  638. var offset = argsIndex;
  639. while (++rightIndex < rightLength) {
  640. result[offset + rightIndex] = partials[rightIndex];
  641. }
  642. while (++holdersIndex < holdersLength) {
  643. if (isUncurried || argsIndex < argsLength) {
  644. result[offset + holders[holdersIndex]] = args[argsIndex++];
  645. }
  646. }
  647. return result;
  648. }
  649. var _composeArgsRight = composeArgsRight;
  650. /**
  651. * Gets the number of `placeholder` occurrences in `array`.
  652. *
  653. * @private
  654. * @param {Array} array The array to inspect.
  655. * @param {*} placeholder The placeholder to search for.
  656. * @returns {number} Returns the placeholder count.
  657. */
  658. function countHolders(array, placeholder) {
  659. var length = array.length,
  660. result = 0;
  661. while (length--) {
  662. if (array[length] === placeholder) {
  663. ++result;
  664. }
  665. }
  666. return result;
  667. }
  668. var _countHolders = countHolders;
  669. /**
  670. * The function whose prototype chain sequence wrappers inherit from.
  671. *
  672. * @private
  673. */
  674. function baseLodash() {
  675. // No operation performed.
  676. }
  677. var _baseLodash = baseLodash;
  678. /** Used as references for the maximum length and index of an array. */
  679. var MAX_ARRAY_LENGTH = 4294967295;
  680. /**
  681. * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
  682. *
  683. * @private
  684. * @constructor
  685. * @param {*} value The value to wrap.
  686. */
  687. function LazyWrapper(value) {
  688. this.__wrapped__ = value;
  689. this.__actions__ = [];
  690. this.__dir__ = 1;
  691. this.__filtered__ = false;
  692. this.__iteratees__ = [];
  693. this.__takeCount__ = MAX_ARRAY_LENGTH;
  694. this.__views__ = [];
  695. }
  696. // Ensure `LazyWrapper` is an instance of `baseLodash`.
  697. LazyWrapper.prototype = _baseCreate(_baseLodash.prototype);
  698. LazyWrapper.prototype.constructor = LazyWrapper;
  699. var _LazyWrapper = LazyWrapper;
  700. /**
  701. * This method returns `undefined`.
  702. *
  703. * @static
  704. * @memberOf _
  705. * @since 2.3.0
  706. * @category Util
  707. * @example
  708. *
  709. * _.times(2, _.noop);
  710. * // => [undefined, undefined]
  711. */
  712. function noop() {
  713. // No operation performed.
  714. }
  715. var noop_1 = noop;
  716. /**
  717. * Gets metadata for `func`.
  718. *
  719. * @private
  720. * @param {Function} func The function to query.
  721. * @returns {*} Returns the metadata for `func`.
  722. */
  723. var getData = !_metaMap ? noop_1 : function(func) {
  724. return _metaMap.get(func);
  725. };
  726. var _getData = getData;
  727. /** Used to lookup unminified function names. */
  728. var realNames = {};
  729. var _realNames = realNames;
  730. /** Used for built-in method references. */
  731. var objectProto$e = Object.prototype;
  732. /** Used to check objects for own properties. */
  733. var hasOwnProperty$c = objectProto$e.hasOwnProperty;
  734. /**
  735. * Gets the name of `func`.
  736. *
  737. * @private
  738. * @param {Function} func The function to query.
  739. * @returns {string} Returns the function name.
  740. */
  741. function getFuncName(func) {
  742. var result = (func.name + ''),
  743. array = _realNames[result],
  744. length = hasOwnProperty$c.call(_realNames, result) ? array.length : 0;
  745. while (length--) {
  746. var data = array[length],
  747. otherFunc = data.func;
  748. if (otherFunc == null || otherFunc == func) {
  749. return data.name;
  750. }
  751. }
  752. return result;
  753. }
  754. var _getFuncName = getFuncName;
  755. /**
  756. * The base constructor for creating `lodash` wrapper objects.
  757. *
  758. * @private
  759. * @param {*} value The value to wrap.
  760. * @param {boolean} [chainAll] Enable explicit method chain sequences.
  761. */
  762. function LodashWrapper(value, chainAll) {
  763. this.__wrapped__ = value;
  764. this.__actions__ = [];
  765. this.__chain__ = !!chainAll;
  766. this.__index__ = 0;
  767. this.__values__ = undefined;
  768. }
  769. LodashWrapper.prototype = _baseCreate(_baseLodash.prototype);
  770. LodashWrapper.prototype.constructor = LodashWrapper;
  771. var _LodashWrapper = LodashWrapper;
  772. /**
  773. * Checks if `value` is classified as an `Array` object.
  774. *
  775. * @static
  776. * @memberOf _
  777. * @since 0.1.0
  778. * @category Lang
  779. * @param {*} value The value to check.
  780. * @returns {boolean} Returns `true` if `value` is an array, else `false`.
  781. * @example
  782. *
  783. * _.isArray([1, 2, 3]);
  784. * // => true
  785. *
  786. * _.isArray(document.body.children);
  787. * // => false
  788. *
  789. * _.isArray('abc');
  790. * // => false
  791. *
  792. * _.isArray(_.noop);
  793. * // => false
  794. */
  795. var isArray$3 = Array.isArray;
  796. var isArray_1 = isArray$3;
  797. /**
  798. * Checks if `value` is object-like. A value is object-like if it's not `null`
  799. * and has a `typeof` result of "object".
  800. *
  801. * @static
  802. * @memberOf _
  803. * @since 4.0.0
  804. * @category Lang
  805. * @param {*} value The value to check.
  806. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  807. * @example
  808. *
  809. * _.isObjectLike({});
  810. * // => true
  811. *
  812. * _.isObjectLike([1, 2, 3]);
  813. * // => true
  814. *
  815. * _.isObjectLike(_.noop);
  816. * // => false
  817. *
  818. * _.isObjectLike(null);
  819. * // => false
  820. */
  821. function isObjectLike(value) {
  822. return value != null && typeof value == 'object';
  823. }
  824. var isObjectLike_1 = isObjectLike;
  825. /**
  826. * Copies the values of `source` to `array`.
  827. *
  828. * @private
  829. * @param {Array} source The array to copy values from.
  830. * @param {Array} [array=[]] The array to copy values to.
  831. * @returns {Array} Returns `array`.
  832. */
  833. function copyArray(source, array) {
  834. var index = -1,
  835. length = source.length;
  836. array || (array = Array(length));
  837. while (++index < length) {
  838. array[index] = source[index];
  839. }
  840. return array;
  841. }
  842. var _copyArray = copyArray;
  843. /**
  844. * Creates a clone of `wrapper`.
  845. *
  846. * @private
  847. * @param {Object} wrapper The wrapper to clone.
  848. * @returns {Object} Returns the cloned wrapper.
  849. */
  850. function wrapperClone(wrapper) {
  851. if (wrapper instanceof _LazyWrapper) {
  852. return wrapper.clone();
  853. }
  854. var result = new _LodashWrapper(wrapper.__wrapped__, wrapper.__chain__);
  855. result.__actions__ = _copyArray(wrapper.__actions__);
  856. result.__index__ = wrapper.__index__;
  857. result.__values__ = wrapper.__values__;
  858. return result;
  859. }
  860. var _wrapperClone = wrapperClone;
  861. /** Used for built-in method references. */
  862. var objectProto$d = Object.prototype;
  863. /** Used to check objects for own properties. */
  864. var hasOwnProperty$b = objectProto$d.hasOwnProperty;
  865. /**
  866. * Creates a `lodash` object which wraps `value` to enable implicit method
  867. * chain sequences. Methods that operate on and return arrays, collections,
  868. * and functions can be chained together. Methods that retrieve a single value
  869. * or may return a primitive value will automatically end the chain sequence
  870. * and return the unwrapped value. Otherwise, the value must be unwrapped
  871. * with `_#value`.
  872. *
  873. * Explicit chain sequences, which must be unwrapped with `_#value`, may be
  874. * enabled using `_.chain`.
  875. *
  876. * The execution of chained methods is lazy, that is, it's deferred until
  877. * `_#value` is implicitly or explicitly called.
  878. *
  879. * Lazy evaluation allows several methods to support shortcut fusion.
  880. * Shortcut fusion is an optimization to merge iteratee calls; this avoids
  881. * the creation of intermediate arrays and can greatly reduce the number of
  882. * iteratee executions. Sections of a chain sequence qualify for shortcut
  883. * fusion if the section is applied to an array and iteratees accept only
  884. * one argument. The heuristic for whether a section qualifies for shortcut
  885. * fusion is subject to change.
  886. *
  887. * Chaining is supported in custom builds as long as the `_#value` method is
  888. * directly or indirectly included in the build.
  889. *
  890. * In addition to lodash methods, wrappers have `Array` and `String` methods.
  891. *
  892. * The wrapper `Array` methods are:
  893. * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift`
  894. *
  895. * The wrapper `String` methods are:
  896. * `replace` and `split`
  897. *
  898. * The wrapper methods that support shortcut fusion are:
  899. * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`,
  900. * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`,
  901. * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray`
  902. *
  903. * The chainable wrapper methods are:
  904. * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, `at`,
  905. * `before`, `bind`, `bindAll`, `bindKey`, `castArray`, `chain`, `chunk`,
  906. * `commit`, `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`,
  907. * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`,
  908. * `difference`, `differenceBy`, `differenceWith`, `drop`, `dropRight`,
  909. * `dropRightWhile`, `dropWhile`, `extend`, `extendWith`, `fill`, `filter`,
  910. * `flatMap`, `flatMapDeep`, `flatMapDepth`, `flatten`, `flattenDeep`,
  911. * `flattenDepth`, `flip`, `flow`, `flowRight`, `fromPairs`, `functions`,
  912. * `functionsIn`, `groupBy`, `initial`, `intersection`, `intersectionBy`,
  913. * `intersectionWith`, `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`,
  914. * `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`,
  915. * `memoize`, `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`,
  916. * `nthArg`, `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`,
  917. * `overEvery`, `overSome`, `partial`, `partialRight`, `partition`, `pick`,
  918. * `pickBy`, `plant`, `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy`,
  919. * `pullAllWith`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`, `reject`,
  920. * `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`, `shuffle`,
  921. * `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`, `takeRight`,
  922. * `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`, `toArray`,
  923. * `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`, `unary`,
  924. * `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`,
  925. * `unshift`, `unzip`, `unzipWith`, `update`, `updateWith`, `values`,
  926. * `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`,
  927. * `zipObject`, `zipObjectDeep`, and `zipWith`
  928. *
  929. * The wrapper methods that are **not** chainable by default are:
  930. * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
  931. * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `conformsTo`, `deburr`,
  932. * `defaultTo`, `divide`, `each`, `eachRight`, `endsWith`, `eq`, `escape`,
  933. * `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, `findLast`,
  934. * `findLastIndex`, `findLastKey`, `first`, `floor`, `forEach`, `forEachRight`,
  935. * `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `get`, `gt`, `gte`, `has`,
  936. * `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`, `invoke`,
  937. * `isArguments`, `isArray`, `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`,
  938. * `isBoolean`, `isBuffer`, `isDate`, `isElement`, `isEmpty`, `isEqual`,
  939. * `isEqualWith`, `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`,
  940. * `isMap`, `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`,
  941. * `isNumber`, `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`,
  942. * `isSafeInteger`, `isSet`, `isString`, `isUndefined`, `isTypedArray`,
  943. * `isWeakMap`, `isWeakSet`, `join`, `kebabCase`, `last`, `lastIndexOf`,
  944. * `lowerCase`, `lowerFirst`, `lt`, `lte`, `max`, `maxBy`, `mean`, `meanBy`,
  945. * `min`, `minBy`, `multiply`, `noConflict`, `noop`, `now`, `nth`, `pad`,
  946. * `padEnd`, `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`,
  947. * `repeat`, `result`, `round`, `runInContext`, `sample`, `shift`, `size`,
  948. * `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`,
  949. * `sortedLastIndexBy`, `startCase`, `startsWith`, `stubArray`, `stubFalse`,
  950. * `stubObject`, `stubString`, `stubTrue`, `subtract`, `sum`, `sumBy`,
  951. * `template`, `times`, `toFinite`, `toInteger`, `toJSON`, `toLength`,
  952. * `toLower`, `toNumber`, `toSafeInteger`, `toString`, `toUpper`, `trim`,
  953. * `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueId`, `upperCase`,
  954. * `upperFirst`, `value`, and `words`
  955. *
  956. * @name _
  957. * @constructor
  958. * @category Seq
  959. * @param {*} value The value to wrap in a `lodash` instance.
  960. * @returns {Object} Returns the new `lodash` wrapper instance.
  961. * @example
  962. *
  963. * function square(n) {
  964. * return n * n;
  965. * }
  966. *
  967. * var wrapped = _([1, 2, 3]);
  968. *
  969. * // Returns an unwrapped value.
  970. * wrapped.reduce(_.add);
  971. * // => 6
  972. *
  973. * // Returns a wrapped value.
  974. * var squares = wrapped.map(square);
  975. *
  976. * _.isArray(squares);
  977. * // => false
  978. *
  979. * _.isArray(squares.value());
  980. * // => true
  981. */
  982. function lodash(value) {
  983. if (isObjectLike_1(value) && !isArray_1(value) && !(value instanceof _LazyWrapper)) {
  984. if (value instanceof _LodashWrapper) {
  985. return value;
  986. }
  987. if (hasOwnProperty$b.call(value, '__wrapped__')) {
  988. return _wrapperClone(value);
  989. }
  990. }
  991. return new _LodashWrapper(value);
  992. }
  993. // Ensure wrappers are instances of `baseLodash`.
  994. lodash.prototype = _baseLodash.prototype;
  995. lodash.prototype.constructor = lodash;
  996. var wrapperLodash = lodash;
  997. /**
  998. * Checks if `func` has a lazy counterpart.
  999. *
  1000. * @private
  1001. * @param {Function} func The function to check.
  1002. * @returns {boolean} Returns `true` if `func` has a lazy counterpart,
  1003. * else `false`.
  1004. */
  1005. function isLaziable(func) {
  1006. var funcName = _getFuncName(func),
  1007. other = wrapperLodash[funcName];
  1008. if (typeof other != 'function' || !(funcName in _LazyWrapper.prototype)) {
  1009. return false;
  1010. }
  1011. if (func === other) {
  1012. return true;
  1013. }
  1014. var data = _getData(other);
  1015. return !!data && func === data[0];
  1016. }
  1017. var _isLaziable = isLaziable;
  1018. /** Used to detect hot functions by number of calls within a span of milliseconds. */
  1019. var HOT_COUNT = 800,
  1020. HOT_SPAN = 16;
  1021. /* Built-in method references for those with the same name as other `lodash` methods. */
  1022. var nativeNow = Date.now;
  1023. /**
  1024. * Creates a function that'll short out and invoke `identity` instead
  1025. * of `func` when it's called `HOT_COUNT` or more times in `HOT_SPAN`
  1026. * milliseconds.
  1027. *
  1028. * @private
  1029. * @param {Function} func The function to restrict.
  1030. * @returns {Function} Returns the new shortable function.
  1031. */
  1032. function shortOut(func) {
  1033. var count = 0,
  1034. lastCalled = 0;
  1035. return function() {
  1036. var stamp = nativeNow(),
  1037. remaining = HOT_SPAN - (stamp - lastCalled);
  1038. lastCalled = stamp;
  1039. if (remaining > 0) {
  1040. if (++count >= HOT_COUNT) {
  1041. return arguments[0];
  1042. }
  1043. } else {
  1044. count = 0;
  1045. }
  1046. return func.apply(undefined, arguments);
  1047. };
  1048. }
  1049. var _shortOut = shortOut;
  1050. /**
  1051. * Sets metadata for `func`.
  1052. *
  1053. * **Note:** If this function becomes hot, i.e. is invoked a lot in a short
  1054. * period of time, it will trip its breaker and transition to an identity
  1055. * function to avoid garbage collection pauses in V8. See
  1056. * [V8 issue 2070](https://bugs.chromium.org/p/v8/issues/detail?id=2070)
  1057. * for more details.
  1058. *
  1059. * @private
  1060. * @param {Function} func The function to associate metadata with.
  1061. * @param {*} data The metadata.
  1062. * @returns {Function} Returns `func`.
  1063. */
  1064. var setData = _shortOut(_baseSetData);
  1065. var _setData = setData;
  1066. /** Used to match wrap detail comments. */
  1067. var reWrapDetails = /\{\n\/\* \[wrapped with (.+)\] \*/,
  1068. reSplitDetails = /,? & /;
  1069. /**
  1070. * Extracts wrapper details from the `source` body comment.
  1071. *
  1072. * @private
  1073. * @param {string} source The source to inspect.
  1074. * @returns {Array} Returns the wrapper details.
  1075. */
  1076. function getWrapDetails(source) {
  1077. var match = source.match(reWrapDetails);
  1078. return match ? match[1].split(reSplitDetails) : [];
  1079. }
  1080. var _getWrapDetails = getWrapDetails;
  1081. /** Used to match wrap detail comments. */
  1082. var reWrapComment = /\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/;
  1083. /**
  1084. * Inserts wrapper `details` in a comment at the top of the `source` body.
  1085. *
  1086. * @private
  1087. * @param {string} source The source to modify.
  1088. * @returns {Array} details The details to insert.
  1089. * @returns {string} Returns the modified source.
  1090. */
  1091. function insertWrapDetails(source, details) {
  1092. var length = details.length;
  1093. if (!length) {
  1094. return source;
  1095. }
  1096. var lastIndex = length - 1;
  1097. details[lastIndex] = (length > 1 ? '& ' : '') + details[lastIndex];
  1098. details = details.join(length > 2 ? ', ' : ' ');
  1099. return source.replace(reWrapComment, '{\n/* [wrapped with ' + details + '] */\n');
  1100. }
  1101. var _insertWrapDetails = insertWrapDetails;
  1102. /**
  1103. * Creates a function that returns `value`.
  1104. *
  1105. * @static
  1106. * @memberOf _
  1107. * @since 2.4.0
  1108. * @category Util
  1109. * @param {*} value The value to return from the new function.
  1110. * @returns {Function} Returns the new constant function.
  1111. * @example
  1112. *
  1113. * var objects = _.times(2, _.constant({ 'a': 1 }));
  1114. *
  1115. * console.log(objects);
  1116. * // => [{ 'a': 1 }, { 'a': 1 }]
  1117. *
  1118. * console.log(objects[0] === objects[1]);
  1119. * // => true
  1120. */
  1121. function constant(value) {
  1122. return function() {
  1123. return value;
  1124. };
  1125. }
  1126. var constant_1 = constant;
  1127. var defineProperty = (function() {
  1128. try {
  1129. var func = _getNative(Object, 'defineProperty');
  1130. func({}, '', {});
  1131. return func;
  1132. } catch (e) {}
  1133. }());
  1134. var _defineProperty = defineProperty;
  1135. /**
  1136. * The base implementation of `setToString` without support for hot loop shorting.
  1137. *
  1138. * @private
  1139. * @param {Function} func The function to modify.
  1140. * @param {Function} string The `toString` result.
  1141. * @returns {Function} Returns `func`.
  1142. */
  1143. var baseSetToString = !_defineProperty ? identity_1 : function(func, string) {
  1144. return _defineProperty(func, 'toString', {
  1145. 'configurable': true,
  1146. 'enumerable': false,
  1147. 'value': constant_1(string),
  1148. 'writable': true
  1149. });
  1150. };
  1151. var _baseSetToString = baseSetToString;
  1152. /**
  1153. * Sets the `toString` method of `func` to return `string`.
  1154. *
  1155. * @private
  1156. * @param {Function} func The function to modify.
  1157. * @param {Function} string The `toString` result.
  1158. * @returns {Function} Returns `func`.
  1159. */
  1160. var setToString = _shortOut(_baseSetToString);
  1161. var _setToString = setToString;
  1162. /**
  1163. * A specialized version of `_.forEach` for arrays without support for
  1164. * iteratee shorthands.
  1165. *
  1166. * @private
  1167. * @param {Array} [array] The array to iterate over.
  1168. * @param {Function} iteratee The function invoked per iteration.
  1169. * @returns {Array} Returns `array`.
  1170. */
  1171. function arrayEach(array, iteratee) {
  1172. var index = -1,
  1173. length = array == null ? 0 : array.length;
  1174. while (++index < length) {
  1175. if (iteratee(array[index], index, array) === false) {
  1176. break;
  1177. }
  1178. }
  1179. return array;
  1180. }
  1181. var _arrayEach = arrayEach;
  1182. /**
  1183. * The base implementation of `_.findIndex` and `_.findLastIndex` without
  1184. * support for iteratee shorthands.
  1185. *
  1186. * @private
  1187. * @param {Array} array The array to inspect.
  1188. * @param {Function} predicate The function invoked per iteration.
  1189. * @param {number} fromIndex The index to search from.
  1190. * @param {boolean} [fromRight] Specify iterating from right to left.
  1191. * @returns {number} Returns the index of the matched value, else `-1`.
  1192. */
  1193. function baseFindIndex(array, predicate, fromIndex, fromRight) {
  1194. var length = array.length,
  1195. index = fromIndex + (fromRight ? 1 : -1);
  1196. while ((fromRight ? index-- : ++index < length)) {
  1197. if (predicate(array[index], index, array)) {
  1198. return index;
  1199. }
  1200. }
  1201. return -1;
  1202. }
  1203. var _baseFindIndex = baseFindIndex;
  1204. /**
  1205. * The base implementation of `_.isNaN` without support for number objects.
  1206. *
  1207. * @private
  1208. * @param {*} value The value to check.
  1209. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  1210. */
  1211. function baseIsNaN(value) {
  1212. return value !== value;
  1213. }
  1214. var _baseIsNaN = baseIsNaN;
  1215. /**
  1216. * A specialized version of `_.indexOf` which performs strict equality
  1217. * comparisons of values, i.e. `===`.
  1218. *
  1219. * @private
  1220. * @param {Array} array The array to inspect.
  1221. * @param {*} value The value to search for.
  1222. * @param {number} fromIndex The index to search from.
  1223. * @returns {number} Returns the index of the matched value, else `-1`.
  1224. */
  1225. function strictIndexOf(array, value, fromIndex) {
  1226. var index = fromIndex - 1,
  1227. length = array.length;
  1228. while (++index < length) {
  1229. if (array[index] === value) {
  1230. return index;
  1231. }
  1232. }
  1233. return -1;
  1234. }
  1235. var _strictIndexOf = strictIndexOf;
  1236. /**
  1237. * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
  1238. *
  1239. * @private
  1240. * @param {Array} array The array to inspect.
  1241. * @param {*} value The value to search for.
  1242. * @param {number} fromIndex The index to search from.
  1243. * @returns {number} Returns the index of the matched value, else `-1`.
  1244. */
  1245. function baseIndexOf(array, value, fromIndex) {
  1246. return value === value
  1247. ? _strictIndexOf(array, value, fromIndex)
  1248. : _baseFindIndex(array, _baseIsNaN, fromIndex);
  1249. }
  1250. var _baseIndexOf = baseIndexOf;
  1251. /**
  1252. * A specialized version of `_.includes` for arrays without support for
  1253. * specifying an index to search from.
  1254. *
  1255. * @private
  1256. * @param {Array} [array] The array to inspect.
  1257. * @param {*} target The value to search for.
  1258. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  1259. */
  1260. function arrayIncludes(array, value) {
  1261. var length = array == null ? 0 : array.length;
  1262. return !!length && _baseIndexOf(array, value, 0) > -1;
  1263. }
  1264. var _arrayIncludes = arrayIncludes;
  1265. /** Used to compose bitmasks for function metadata. */
  1266. var WRAP_BIND_FLAG$5 = 1,
  1267. WRAP_BIND_KEY_FLAG$4 = 2,
  1268. WRAP_CURRY_FLAG$4 = 8,
  1269. WRAP_CURRY_RIGHT_FLAG$2 = 16,
  1270. WRAP_PARTIAL_FLAG$2 = 32,
  1271. WRAP_PARTIAL_RIGHT_FLAG$2 = 64,
  1272. WRAP_ARY_FLAG$3 = 128,
  1273. WRAP_REARG_FLAG$2 = 256,
  1274. WRAP_FLIP_FLAG$1 = 512;
  1275. /** Used to associate wrap methods with their bit flags. */
  1276. var wrapFlags = [
  1277. ['ary', WRAP_ARY_FLAG$3],
  1278. ['bind', WRAP_BIND_FLAG$5],
  1279. ['bindKey', WRAP_BIND_KEY_FLAG$4],
  1280. ['curry', WRAP_CURRY_FLAG$4],
  1281. ['curryRight', WRAP_CURRY_RIGHT_FLAG$2],
  1282. ['flip', WRAP_FLIP_FLAG$1],
  1283. ['partial', WRAP_PARTIAL_FLAG$2],
  1284. ['partialRight', WRAP_PARTIAL_RIGHT_FLAG$2],
  1285. ['rearg', WRAP_REARG_FLAG$2]
  1286. ];
  1287. /**
  1288. * Updates wrapper `details` based on `bitmask` flags.
  1289. *
  1290. * @private
  1291. * @returns {Array} details The details to modify.
  1292. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  1293. * @returns {Array} Returns `details`.
  1294. */
  1295. function updateWrapDetails(details, bitmask) {
  1296. _arrayEach(wrapFlags, function(pair) {
  1297. var value = '_.' + pair[0];
  1298. if ((bitmask & pair[1]) && !_arrayIncludes(details, value)) {
  1299. details.push(value);
  1300. }
  1301. });
  1302. return details.sort();
  1303. }
  1304. var _updateWrapDetails = updateWrapDetails;
  1305. /**
  1306. * Sets the `toString` method of `wrapper` to mimic the source of `reference`
  1307. * with wrapper details in a comment at the top of the source body.
  1308. *
  1309. * @private
  1310. * @param {Function} wrapper The function to modify.
  1311. * @param {Function} reference The reference function.
  1312. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  1313. * @returns {Function} Returns `wrapper`.
  1314. */
  1315. function setWrapToString(wrapper, reference, bitmask) {
  1316. var source = (reference + '');
  1317. return _setToString(wrapper, _insertWrapDetails(source, _updateWrapDetails(_getWrapDetails(source), bitmask)));
  1318. }
  1319. var _setWrapToString = setWrapToString;
  1320. /** Used to compose bitmasks for function metadata. */
  1321. var WRAP_BIND_FLAG$4 = 1,
  1322. WRAP_BIND_KEY_FLAG$3 = 2,
  1323. WRAP_CURRY_BOUND_FLAG$1 = 4,
  1324. WRAP_CURRY_FLAG$3 = 8,
  1325. WRAP_PARTIAL_FLAG$1 = 32,
  1326. WRAP_PARTIAL_RIGHT_FLAG$1 = 64;
  1327. /**
  1328. * Creates a function that wraps `func` to continue currying.
  1329. *
  1330. * @private
  1331. * @param {Function} func The function to wrap.
  1332. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  1333. * @param {Function} wrapFunc The function to create the `func` wrapper.
  1334. * @param {*} placeholder The placeholder value.
  1335. * @param {*} [thisArg] The `this` binding of `func`.
  1336. * @param {Array} [partials] The arguments to prepend to those provided to
  1337. * the new function.
  1338. * @param {Array} [holders] The `partials` placeholder indexes.
  1339. * @param {Array} [argPos] The argument positions of the new function.
  1340. * @param {number} [ary] The arity cap of `func`.
  1341. * @param {number} [arity] The arity of `func`.
  1342. * @returns {Function} Returns the new wrapped function.
  1343. */
  1344. function createRecurry(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) {
  1345. var isCurry = bitmask & WRAP_CURRY_FLAG$3,
  1346. newHolders = isCurry ? holders : undefined,
  1347. newHoldersRight = isCurry ? undefined : holders,
  1348. newPartials = isCurry ? partials : undefined,
  1349. newPartialsRight = isCurry ? undefined : partials;
  1350. bitmask |= (isCurry ? WRAP_PARTIAL_FLAG$1 : WRAP_PARTIAL_RIGHT_FLAG$1);
  1351. bitmask &= ~(isCurry ? WRAP_PARTIAL_RIGHT_FLAG$1 : WRAP_PARTIAL_FLAG$1);
  1352. if (!(bitmask & WRAP_CURRY_BOUND_FLAG$1)) {
  1353. bitmask &= ~(WRAP_BIND_FLAG$4 | WRAP_BIND_KEY_FLAG$3);
  1354. }
  1355. var newData = [
  1356. func, bitmask, thisArg, newPartials, newHolders, newPartialsRight,
  1357. newHoldersRight, argPos, ary, arity
  1358. ];
  1359. var result = wrapFunc.apply(undefined, newData);
  1360. if (_isLaziable(func)) {
  1361. _setData(result, newData);
  1362. }
  1363. result.placeholder = placeholder;
  1364. return _setWrapToString(result, func, bitmask);
  1365. }
  1366. var _createRecurry = createRecurry;
  1367. /**
  1368. * Gets the argument placeholder value for `func`.
  1369. *
  1370. * @private
  1371. * @param {Function} func The function to inspect.
  1372. * @returns {*} Returns the placeholder value.
  1373. */
  1374. function getHolder(func) {
  1375. var object = func;
  1376. return object.placeholder;
  1377. }
  1378. var _getHolder = getHolder;
  1379. /** Used as references for various `Number` constants. */
  1380. var MAX_SAFE_INTEGER$1 = 9007199254740991;
  1381. /** Used to detect unsigned integer values. */
  1382. var reIsUint = /^(?:0|[1-9]\d*)$/;
  1383. /**
  1384. * Checks if `value` is a valid array-like index.
  1385. *
  1386. * @private
  1387. * @param {*} value The value to check.
  1388. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  1389. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  1390. */
  1391. function isIndex(value, length) {
  1392. var type = typeof value;
  1393. length = length == null ? MAX_SAFE_INTEGER$1 : length;
  1394. return !!length &&
  1395. (type == 'number' ||
  1396. (type != 'symbol' && reIsUint.test(value))) &&
  1397. (value > -1 && value % 1 == 0 && value < length);
  1398. }
  1399. var _isIndex = isIndex;
  1400. /* Built-in method references for those with the same name as other `lodash` methods. */
  1401. var nativeMin$1 = Math.min;
  1402. /**
  1403. * Reorder `array` according to the specified indexes where the element at
  1404. * the first index is assigned as the first element, the element at
  1405. * the second index is assigned as the second element, and so on.
  1406. *
  1407. * @private
  1408. * @param {Array} array The array to reorder.
  1409. * @param {Array} indexes The arranged array indexes.
  1410. * @returns {Array} Returns `array`.
  1411. */
  1412. function reorder(array, indexes) {
  1413. var arrLength = array.length,
  1414. length = nativeMin$1(indexes.length, arrLength),
  1415. oldArray = _copyArray(array);
  1416. while (length--) {
  1417. var index = indexes[length];
  1418. array[length] = _isIndex(index, arrLength) ? oldArray[index] : undefined;
  1419. }
  1420. return array;
  1421. }
  1422. var _reorder = reorder;
  1423. /** Used as the internal argument placeholder. */
  1424. var PLACEHOLDER$1 = '__lodash_placeholder__';
  1425. /**
  1426. * Replaces all `placeholder` elements in `array` with an internal placeholder
  1427. * and returns an array of their indexes.
  1428. *
  1429. * @private
  1430. * @param {Array} array The array to modify.
  1431. * @param {*} placeholder The placeholder to replace.
  1432. * @returns {Array} Returns the new array of placeholder indexes.
  1433. */
  1434. function replaceHolders(array, placeholder) {
  1435. var index = -1,
  1436. length = array.length,
  1437. resIndex = 0,
  1438. result = [];
  1439. while (++index < length) {
  1440. var value = array[index];
  1441. if (value === placeholder || value === PLACEHOLDER$1) {
  1442. array[index] = PLACEHOLDER$1;
  1443. result[resIndex++] = index;
  1444. }
  1445. }
  1446. return result;
  1447. }
  1448. var _replaceHolders = replaceHolders;
  1449. /** Used to compose bitmasks for function metadata. */
  1450. var WRAP_BIND_FLAG$3 = 1,
  1451. WRAP_BIND_KEY_FLAG$2 = 2,
  1452. WRAP_CURRY_FLAG$2 = 8,
  1453. WRAP_CURRY_RIGHT_FLAG$1 = 16,
  1454. WRAP_ARY_FLAG$2 = 128,
  1455. WRAP_FLIP_FLAG = 512;
  1456. /**
  1457. * Creates a function that wraps `func` to invoke it with optional `this`
  1458. * binding of `thisArg`, partial application, and currying.
  1459. *
  1460. * @private
  1461. * @param {Function|string} func The function or method name to wrap.
  1462. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  1463. * @param {*} [thisArg] The `this` binding of `func`.
  1464. * @param {Array} [partials] The arguments to prepend to those provided to
  1465. * the new function.
  1466. * @param {Array} [holders] The `partials` placeholder indexes.
  1467. * @param {Array} [partialsRight] The arguments to append to those provided
  1468. * to the new function.
  1469. * @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
  1470. * @param {Array} [argPos] The argument positions of the new function.
  1471. * @param {number} [ary] The arity cap of `func`.
  1472. * @param {number} [arity] The arity of `func`.
  1473. * @returns {Function} Returns the new wrapped function.
  1474. */
  1475. function createHybrid(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
  1476. var isAry = bitmask & WRAP_ARY_FLAG$2,
  1477. isBind = bitmask & WRAP_BIND_FLAG$3,
  1478. isBindKey = bitmask & WRAP_BIND_KEY_FLAG$2,
  1479. isCurried = bitmask & (WRAP_CURRY_FLAG$2 | WRAP_CURRY_RIGHT_FLAG$1),
  1480. isFlip = bitmask & WRAP_FLIP_FLAG,
  1481. Ctor = isBindKey ? undefined : _createCtor(func);
  1482. function wrapper() {
  1483. var length = arguments.length,
  1484. args = Array(length),
  1485. index = length;
  1486. while (index--) {
  1487. args[index] = arguments[index];
  1488. }
  1489. if (isCurried) {
  1490. var placeholder = _getHolder(wrapper),
  1491. holdersCount = _countHolders(args, placeholder);
  1492. }
  1493. if (partials) {
  1494. args = _composeArgs(args, partials, holders, isCurried);
  1495. }
  1496. if (partialsRight) {
  1497. args = _composeArgsRight(args, partialsRight, holdersRight, isCurried);
  1498. }
  1499. length -= holdersCount;
  1500. if (isCurried && length < arity) {
  1501. var newHolders = _replaceHolders(args, placeholder);
  1502. return _createRecurry(
  1503. func, bitmask, createHybrid, wrapper.placeholder, thisArg,
  1504. args, newHolders, argPos, ary, arity - length
  1505. );
  1506. }
  1507. var thisBinding = isBind ? thisArg : this,
  1508. fn = isBindKey ? thisBinding[func] : func;
  1509. length = args.length;
  1510. if (argPos) {
  1511. args = _reorder(args, argPos);
  1512. } else if (isFlip && length > 1) {
  1513. args.reverse();
  1514. }
  1515. if (isAry && ary < length) {
  1516. args.length = ary;
  1517. }
  1518. if (this && this !== _root && this instanceof wrapper) {
  1519. fn = Ctor || _createCtor(fn);
  1520. }
  1521. return fn.apply(thisBinding, args);
  1522. }
  1523. return wrapper;
  1524. }
  1525. var _createHybrid = createHybrid;
  1526. /**
  1527. * Creates a function that wraps `func` to enable currying.
  1528. *
  1529. * @private
  1530. * @param {Function} func The function to wrap.
  1531. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  1532. * @param {number} arity The arity of `func`.
  1533. * @returns {Function} Returns the new wrapped function.
  1534. */
  1535. function createCurry(func, bitmask, arity) {
  1536. var Ctor = _createCtor(func);
  1537. function wrapper() {
  1538. var length = arguments.length,
  1539. args = Array(length),
  1540. index = length,
  1541. placeholder = _getHolder(wrapper);
  1542. while (index--) {
  1543. args[index] = arguments[index];
  1544. }
  1545. var holders = (length < 3 && args[0] !== placeholder && args[length - 1] !== placeholder)
  1546. ? []
  1547. : _replaceHolders(args, placeholder);
  1548. length -= holders.length;
  1549. if (length < arity) {
  1550. return _createRecurry(
  1551. func, bitmask, _createHybrid, wrapper.placeholder, undefined,
  1552. args, holders, undefined, undefined, arity - length);
  1553. }
  1554. var fn = (this && this !== _root && this instanceof wrapper) ? Ctor : func;
  1555. return _apply(fn, this, args);
  1556. }
  1557. return wrapper;
  1558. }
  1559. var _createCurry = createCurry;
  1560. /** Used to compose bitmasks for function metadata. */
  1561. var WRAP_BIND_FLAG$2 = 1;
  1562. /**
  1563. * Creates a function that wraps `func` to invoke it with the `this` binding
  1564. * of `thisArg` and `partials` prepended to the arguments it receives.
  1565. *
  1566. * @private
  1567. * @param {Function} func The function to wrap.
  1568. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  1569. * @param {*} thisArg The `this` binding of `func`.
  1570. * @param {Array} partials The arguments to prepend to those provided to
  1571. * the new function.
  1572. * @returns {Function} Returns the new wrapped function.
  1573. */
  1574. function createPartial(func, bitmask, thisArg, partials) {
  1575. var isBind = bitmask & WRAP_BIND_FLAG$2,
  1576. Ctor = _createCtor(func);
  1577. function wrapper() {
  1578. var argsIndex = -1,
  1579. argsLength = arguments.length,
  1580. leftIndex = -1,
  1581. leftLength = partials.length,
  1582. args = Array(leftLength + argsLength),
  1583. fn = (this && this !== _root && this instanceof wrapper) ? Ctor : func;
  1584. while (++leftIndex < leftLength) {
  1585. args[leftIndex] = partials[leftIndex];
  1586. }
  1587. while (argsLength--) {
  1588. args[leftIndex++] = arguments[++argsIndex];
  1589. }
  1590. return _apply(fn, isBind ? thisArg : this, args);
  1591. }
  1592. return wrapper;
  1593. }
  1594. var _createPartial = createPartial;
  1595. /** Used as the internal argument placeholder. */
  1596. var PLACEHOLDER = '__lodash_placeholder__';
  1597. /** Used to compose bitmasks for function metadata. */
  1598. var WRAP_BIND_FLAG$1 = 1,
  1599. WRAP_BIND_KEY_FLAG$1 = 2,
  1600. WRAP_CURRY_BOUND_FLAG = 4,
  1601. WRAP_CURRY_FLAG$1 = 8,
  1602. WRAP_ARY_FLAG$1 = 128,
  1603. WRAP_REARG_FLAG$1 = 256;
  1604. /* Built-in method references for those with the same name as other `lodash` methods. */
  1605. var nativeMin = Math.min;
  1606. /**
  1607. * Merges the function metadata of `source` into `data`.
  1608. *
  1609. * Merging metadata reduces the number of wrappers used to invoke a function.
  1610. * This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
  1611. * may be applied regardless of execution order. Methods like `_.ary` and
  1612. * `_.rearg` modify function arguments, making the order in which they are
  1613. * executed important, preventing the merging of metadata. However, we make
  1614. * an exception for a safe combined case where curried functions have `_.ary`
  1615. * and or `_.rearg` applied.
  1616. *
  1617. * @private
  1618. * @param {Array} data The destination metadata.
  1619. * @param {Array} source The source metadata.
  1620. * @returns {Array} Returns `data`.
  1621. */
  1622. function mergeData(data, source) {
  1623. var bitmask = data[1],
  1624. srcBitmask = source[1],
  1625. newBitmask = bitmask | srcBitmask,
  1626. isCommon = newBitmask < (WRAP_BIND_FLAG$1 | WRAP_BIND_KEY_FLAG$1 | WRAP_ARY_FLAG$1);
  1627. var isCombo =
  1628. ((srcBitmask == WRAP_ARY_FLAG$1) && (bitmask == WRAP_CURRY_FLAG$1)) ||
  1629. ((srcBitmask == WRAP_ARY_FLAG$1) && (bitmask == WRAP_REARG_FLAG$1) && (data[7].length <= source[8])) ||
  1630. ((srcBitmask == (WRAP_ARY_FLAG$1 | WRAP_REARG_FLAG$1)) && (source[7].length <= source[8]) && (bitmask == WRAP_CURRY_FLAG$1));
  1631. // Exit early if metadata can't be merged.
  1632. if (!(isCommon || isCombo)) {
  1633. return data;
  1634. }
  1635. // Use source `thisArg` if available.
  1636. if (srcBitmask & WRAP_BIND_FLAG$1) {
  1637. data[2] = source[2];
  1638. // Set when currying a bound function.
  1639. newBitmask |= bitmask & WRAP_BIND_FLAG$1 ? 0 : WRAP_CURRY_BOUND_FLAG;
  1640. }
  1641. // Compose partial arguments.
  1642. var value = source[3];
  1643. if (value) {
  1644. var partials = data[3];
  1645. data[3] = partials ? _composeArgs(partials, value, source[4]) : value;
  1646. data[4] = partials ? _replaceHolders(data[3], PLACEHOLDER) : source[4];
  1647. }
  1648. // Compose partial right arguments.
  1649. value = source[5];
  1650. if (value) {
  1651. partials = data[5];
  1652. data[5] = partials ? _composeArgsRight(partials, value, source[6]) : value;
  1653. data[6] = partials ? _replaceHolders(data[5], PLACEHOLDER) : source[6];
  1654. }
  1655. // Use source `argPos` if available.
  1656. value = source[7];
  1657. if (value) {
  1658. data[7] = value;
  1659. }
  1660. // Use source `ary` if it's smaller.
  1661. if (srcBitmask & WRAP_ARY_FLAG$1) {
  1662. data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
  1663. }
  1664. // Use source `arity` if one is not provided.
  1665. if (data[9] == null) {
  1666. data[9] = source[9];
  1667. }
  1668. // Use source `func` and merge bitmasks.
  1669. data[0] = source[0];
  1670. data[1] = newBitmask;
  1671. return data;
  1672. }
  1673. var _mergeData = mergeData;
  1674. /** Used to match a single whitespace character. */
  1675. var reWhitespace = /\s/;
  1676. /**
  1677. * Used by `_.trim` and `_.trimEnd` to get the index of the last non-whitespace
  1678. * character of `string`.
  1679. *
  1680. * @private
  1681. * @param {string} string The string to inspect.
  1682. * @returns {number} Returns the index of the last non-whitespace character.
  1683. */
  1684. function trimmedEndIndex(string) {
  1685. var index = string.length;
  1686. while (index-- && reWhitespace.test(string.charAt(index))) {}
  1687. return index;
  1688. }
  1689. var _trimmedEndIndex = trimmedEndIndex;
  1690. /** Used to match leading whitespace. */
  1691. var reTrimStart = /^\s+/;
  1692. /**
  1693. * The base implementation of `_.trim`.
  1694. *
  1695. * @private
  1696. * @param {string} string The string to trim.
  1697. * @returns {string} Returns the trimmed string.
  1698. */
  1699. function baseTrim(string) {
  1700. return string
  1701. ? string.slice(0, _trimmedEndIndex(string) + 1).replace(reTrimStart, '')
  1702. : string;
  1703. }
  1704. var _baseTrim = baseTrim;
  1705. /** `Object#toString` result references. */
  1706. var symbolTag$3 = '[object Symbol]';
  1707. /**
  1708. * Checks if `value` is classified as a `Symbol` primitive or object.
  1709. *
  1710. * @static
  1711. * @memberOf _
  1712. * @since 4.0.0
  1713. * @category Lang
  1714. * @param {*} value The value to check.
  1715. * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
  1716. * @example
  1717. *
  1718. * _.isSymbol(Symbol.iterator);
  1719. * // => true
  1720. *
  1721. * _.isSymbol('abc');
  1722. * // => false
  1723. */
  1724. function isSymbol(value) {
  1725. return typeof value == 'symbol' ||
  1726. (isObjectLike_1(value) && _baseGetTag(value) == symbolTag$3);
  1727. }
  1728. var isSymbol_1 = isSymbol;
  1729. /** Used as references for various `Number` constants. */
  1730. var NAN = 0 / 0;
  1731. /** Used to detect bad signed hexadecimal string values. */
  1732. var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
  1733. /** Used to detect binary string values. */
  1734. var reIsBinary = /^0b[01]+$/i;
  1735. /** Used to detect octal string values. */
  1736. var reIsOctal = /^0o[0-7]+$/i;
  1737. /** Built-in method references without a dependency on `root`. */
  1738. var freeParseInt = parseInt;
  1739. /**
  1740. * Converts `value` to a number.
  1741. *
  1742. * @static
  1743. * @memberOf _
  1744. * @since 4.0.0
  1745. * @category Lang
  1746. * @param {*} value The value to process.
  1747. * @returns {number} Returns the number.
  1748. * @example
  1749. *
  1750. * _.toNumber(3.2);
  1751. * // => 3.2
  1752. *
  1753. * _.toNumber(Number.MIN_VALUE);
  1754. * // => 5e-324
  1755. *
  1756. * _.toNumber(Infinity);
  1757. * // => Infinity
  1758. *
  1759. * _.toNumber('3.2');
  1760. * // => 3.2
  1761. */
  1762. function toNumber(value) {
  1763. if (typeof value == 'number') {
  1764. return value;
  1765. }
  1766. if (isSymbol_1(value)) {
  1767. return NAN;
  1768. }
  1769. if (isObject_1(value)) {
  1770. var other = typeof value.valueOf == 'function' ? value.valueOf() : value;
  1771. value = isObject_1(other) ? (other + '') : other;
  1772. }
  1773. if (typeof value != 'string') {
  1774. return value === 0 ? value : +value;
  1775. }
  1776. value = _baseTrim(value);
  1777. var isBinary = reIsBinary.test(value);
  1778. return (isBinary || reIsOctal.test(value))
  1779. ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
  1780. : (reIsBadHex.test(value) ? NAN : +value);
  1781. }
  1782. var toNumber_1 = toNumber;
  1783. /** Used as references for various `Number` constants. */
  1784. var INFINITY$2 = 1 / 0,
  1785. MAX_INTEGER = 1.7976931348623157e+308;
  1786. /**
  1787. * Converts `value` to a finite number.
  1788. *
  1789. * @static
  1790. * @memberOf _
  1791. * @since 4.12.0
  1792. * @category Lang
  1793. * @param {*} value The value to convert.
  1794. * @returns {number} Returns the converted number.
  1795. * @example
  1796. *
  1797. * _.toFinite(3.2);
  1798. * // => 3.2
  1799. *
  1800. * _.toFinite(Number.MIN_VALUE);
  1801. * // => 5e-324
  1802. *
  1803. * _.toFinite(Infinity);
  1804. * // => 1.7976931348623157e+308
  1805. *
  1806. * _.toFinite('3.2');
  1807. * // => 3.2
  1808. */
  1809. function toFinite(value) {
  1810. if (!value) {
  1811. return value === 0 ? value : 0;
  1812. }
  1813. value = toNumber_1(value);
  1814. if (value === INFINITY$2 || value === -INFINITY$2) {
  1815. var sign = (value < 0 ? -1 : 1);
  1816. return sign * MAX_INTEGER;
  1817. }
  1818. return value === value ? value : 0;
  1819. }
  1820. var toFinite_1 = toFinite;
  1821. /**
  1822. * Converts `value` to an integer.
  1823. *
  1824. * **Note:** This method is loosely based on
  1825. * [`ToInteger`](http://www.ecma-international.org/ecma-262/7.0/#sec-tointeger).
  1826. *
  1827. * @static
  1828. * @memberOf _
  1829. * @since 4.0.0
  1830. * @category Lang
  1831. * @param {*} value The value to convert.
  1832. * @returns {number} Returns the converted integer.
  1833. * @example
  1834. *
  1835. * _.toInteger(3.2);
  1836. * // => 3
  1837. *
  1838. * _.toInteger(Number.MIN_VALUE);
  1839. * // => 0
  1840. *
  1841. * _.toInteger(Infinity);
  1842. * // => 1.7976931348623157e+308
  1843. *
  1844. * _.toInteger('3.2');
  1845. * // => 3
  1846. */
  1847. function toInteger(value) {
  1848. var result = toFinite_1(value),
  1849. remainder = result % 1;
  1850. return result === result ? (remainder ? result - remainder : result) : 0;
  1851. }
  1852. var toInteger_1 = toInteger;
  1853. /** Error message constants. */
  1854. var FUNC_ERROR_TEXT$1 = 'Expected a function';
  1855. /** Used to compose bitmasks for function metadata. */
  1856. var WRAP_BIND_FLAG = 1,
  1857. WRAP_BIND_KEY_FLAG = 2,
  1858. WRAP_CURRY_FLAG = 8,
  1859. WRAP_CURRY_RIGHT_FLAG = 16,
  1860. WRAP_PARTIAL_FLAG = 32,
  1861. WRAP_PARTIAL_RIGHT_FLAG = 64;
  1862. /* Built-in method references for those with the same name as other `lodash` methods. */
  1863. var nativeMax$1 = Math.max;
  1864. /**
  1865. * Creates a function that either curries or invokes `func` with optional
  1866. * `this` binding and partially applied arguments.
  1867. *
  1868. * @private
  1869. * @param {Function|string} func The function or method name to wrap.
  1870. * @param {number} bitmask The bitmask flags.
  1871. * 1 - `_.bind`
  1872. * 2 - `_.bindKey`
  1873. * 4 - `_.curry` or `_.curryRight` of a bound function
  1874. * 8 - `_.curry`
  1875. * 16 - `_.curryRight`
  1876. * 32 - `_.partial`
  1877. * 64 - `_.partialRight`
  1878. * 128 - `_.rearg`
  1879. * 256 - `_.ary`
  1880. * 512 - `_.flip`
  1881. * @param {*} [thisArg] The `this` binding of `func`.
  1882. * @param {Array} [partials] The arguments to be partially applied.
  1883. * @param {Array} [holders] The `partials` placeholder indexes.
  1884. * @param {Array} [argPos] The argument positions of the new function.
  1885. * @param {number} [ary] The arity cap of `func`.
  1886. * @param {number} [arity] The arity of `func`.
  1887. * @returns {Function} Returns the new wrapped function.
  1888. */
  1889. function createWrap(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
  1890. var isBindKey = bitmask & WRAP_BIND_KEY_FLAG;
  1891. if (!isBindKey && typeof func != 'function') {
  1892. throw new TypeError(FUNC_ERROR_TEXT$1);
  1893. }
  1894. var length = partials ? partials.length : 0;
  1895. if (!length) {
  1896. bitmask &= ~(WRAP_PARTIAL_FLAG | WRAP_PARTIAL_RIGHT_FLAG);
  1897. partials = holders = undefined;
  1898. }
  1899. ary = ary === undefined ? ary : nativeMax$1(toInteger_1(ary), 0);
  1900. arity = arity === undefined ? arity : toInteger_1(arity);
  1901. length -= holders ? holders.length : 0;
  1902. if (bitmask & WRAP_PARTIAL_RIGHT_FLAG) {
  1903. var partialsRight = partials,
  1904. holdersRight = holders;
  1905. partials = holders = undefined;
  1906. }
  1907. var data = isBindKey ? undefined : _getData(func);
  1908. var newData = [
  1909. func, bitmask, thisArg, partials, holders, partialsRight, holdersRight,
  1910. argPos, ary, arity
  1911. ];
  1912. if (data) {
  1913. _mergeData(newData, data);
  1914. }
  1915. func = newData[0];
  1916. bitmask = newData[1];
  1917. thisArg = newData[2];
  1918. partials = newData[3];
  1919. holders = newData[4];
  1920. arity = newData[9] = newData[9] === undefined
  1921. ? (isBindKey ? 0 : func.length)
  1922. : nativeMax$1(newData[9] - length, 0);
  1923. if (!arity && bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG)) {
  1924. bitmask &= ~(WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG);
  1925. }
  1926. if (!bitmask || bitmask == WRAP_BIND_FLAG) {
  1927. var result = _createBind(func, bitmask, thisArg);
  1928. } else if (bitmask == WRAP_CURRY_FLAG || bitmask == WRAP_CURRY_RIGHT_FLAG) {
  1929. result = _createCurry(func, bitmask, arity);
  1930. } else if ((bitmask == WRAP_PARTIAL_FLAG || bitmask == (WRAP_BIND_FLAG | WRAP_PARTIAL_FLAG)) && !holders.length) {
  1931. result = _createPartial(func, bitmask, thisArg, partials);
  1932. } else {
  1933. result = _createHybrid.apply(undefined, newData);
  1934. }
  1935. var setter = data ? _baseSetData : _setData;
  1936. return _setWrapToString(setter(result, newData), func, bitmask);
  1937. }
  1938. var _createWrap = createWrap;
  1939. commonjsRegister("/$$rollup_base$$/node_modules/lodash/curry.js", function (module, exports) {
  1940. var createWrap = _createWrap;
  1941. /** Used to compose bitmasks for function metadata. */
  1942. var WRAP_CURRY_FLAG = 8;
  1943. /**
  1944. * Creates a function that accepts arguments of `func` and either invokes
  1945. * `func` returning its result, if at least `arity` number of arguments have
  1946. * been provided, or returns a function that accepts the remaining `func`
  1947. * arguments, and so on. The arity of `func` may be specified if `func.length`
  1948. * is not sufficient.
  1949. *
  1950. * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
  1951. * may be used as a placeholder for provided arguments.
  1952. *
  1953. * **Note:** This method doesn't set the "length" property of curried functions.
  1954. *
  1955. * @static
  1956. * @memberOf _
  1957. * @since 2.0.0
  1958. * @category Function
  1959. * @param {Function} func The function to curry.
  1960. * @param {number} [arity=func.length] The arity of `func`.
  1961. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  1962. * @returns {Function} Returns the new curried function.
  1963. * @example
  1964. *
  1965. * var abc = function(a, b, c) {
  1966. * return [a, b, c];
  1967. * };
  1968. *
  1969. * var curried = _.curry(abc);
  1970. *
  1971. * curried(1)(2)(3);
  1972. * // => [1, 2, 3]
  1973. *
  1974. * curried(1, 2)(3);
  1975. * // => [1, 2, 3]
  1976. *
  1977. * curried(1, 2, 3);
  1978. * // => [1, 2, 3]
  1979. *
  1980. * // Curried with placeholders.
  1981. * curried(1)(_, 3)(2);
  1982. * // => [1, 2, 3]
  1983. */
  1984. function curry(func, arity, guard) {
  1985. arity = guard ? undefined : arity;
  1986. var result = createWrap(func, WRAP_CURRY_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
  1987. result.placeholder = curry.placeholder;
  1988. return result;
  1989. }
  1990. // Assign default placeholders.
  1991. curry.placeholder = {};
  1992. module.exports = curry;
  1993. });
  1994. commonjsRegister("/$$rollup_base$$/node_modules/lodash/curryRight.js", function (module, exports) {
  1995. var createWrap = _createWrap;
  1996. /** Used to compose bitmasks for function metadata. */
  1997. var WRAP_CURRY_RIGHT_FLAG = 16;
  1998. /**
  1999. * This method is like `_.curry` except that arguments are applied to `func`
  2000. * in the manner of `_.partialRight` instead of `_.partial`.
  2001. *
  2002. * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
  2003. * builds, may be used as a placeholder for provided arguments.
  2004. *
  2005. * **Note:** This method doesn't set the "length" property of curried functions.
  2006. *
  2007. * @static
  2008. * @memberOf _
  2009. * @since 3.0.0
  2010. * @category Function
  2011. * @param {Function} func The function to curry.
  2012. * @param {number} [arity=func.length] The arity of `func`.
  2013. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  2014. * @returns {Function} Returns the new curried function.
  2015. * @example
  2016. *
  2017. * var abc = function(a, b, c) {
  2018. * return [a, b, c];
  2019. * };
  2020. *
  2021. * var curried = _.curryRight(abc);
  2022. *
  2023. * curried(3)(2)(1);
  2024. * // => [1, 2, 3]
  2025. *
  2026. * curried(2, 3)(1);
  2027. * // => [1, 2, 3]
  2028. *
  2029. * curried(1, 2, 3);
  2030. * // => [1, 2, 3]
  2031. *
  2032. * // Curried with placeholders.
  2033. * curried(3)(1, _)(2);
  2034. * // => [1, 2, 3]
  2035. */
  2036. function curryRight(func, arity, guard) {
  2037. arity = guard ? undefined : arity;
  2038. var result = createWrap(func, WRAP_CURRY_RIGHT_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
  2039. result.placeholder = curryRight.placeholder;
  2040. return result;
  2041. }
  2042. // Assign default placeholders.
  2043. curryRight.placeholder = {};
  2044. module.exports = curryRight;
  2045. });
  2046. /** Used to map aliases to their real names. */
  2047. var _mapping = createCommonjsModule(function (module, exports) {
  2048. exports.aliasToReal = {
  2049. // Lodash aliases.
  2050. 'each': 'forEach',
  2051. 'eachRight': 'forEachRight',
  2052. 'entries': 'toPairs',
  2053. 'entriesIn': 'toPairsIn',
  2054. 'extend': 'assignIn',
  2055. 'extendAll': 'assignInAll',
  2056. 'extendAllWith': 'assignInAllWith',
  2057. 'extendWith': 'assignInWith',
  2058. 'first': 'head',
  2059. // Methods that are curried variants of others.
  2060. 'conforms': 'conformsTo',
  2061. 'matches': 'isMatch',
  2062. 'property': 'get',
  2063. // Ramda aliases.
  2064. '__': 'placeholder',
  2065. 'F': 'stubFalse',
  2066. 'T': 'stubTrue',
  2067. 'all': 'every',
  2068. 'allPass': 'overEvery',
  2069. 'always': 'constant',
  2070. 'any': 'some',
  2071. 'anyPass': 'overSome',
  2072. 'apply': 'spread',
  2073. 'assoc': 'set',
  2074. 'assocPath': 'set',
  2075. 'complement': 'negate',
  2076. 'compose': 'flowRight',
  2077. 'contains': 'includes',
  2078. 'dissoc': 'unset',
  2079. 'dissocPath': 'unset',
  2080. 'dropLast': 'dropRight',
  2081. 'dropLastWhile': 'dropRightWhile',
  2082. 'equals': 'isEqual',
  2083. 'identical': 'eq',
  2084. 'indexBy': 'keyBy',
  2085. 'init': 'initial',
  2086. 'invertObj': 'invert',
  2087. 'juxt': 'over',
  2088. 'omitAll': 'omit',
  2089. 'nAry': 'ary',
  2090. 'path': 'get',
  2091. 'pathEq': 'matchesProperty',
  2092. 'pathOr': 'getOr',
  2093. 'paths': 'at',
  2094. 'pickAll': 'pick',
  2095. 'pipe': 'flow',
  2096. 'pluck': 'map',
  2097. 'prop': 'get',
  2098. 'propEq': 'matchesProperty',
  2099. 'propOr': 'getOr',
  2100. 'props': 'at',
  2101. 'symmetricDifference': 'xor',
  2102. 'symmetricDifferenceBy': 'xorBy',
  2103. 'symmetricDifferenceWith': 'xorWith',
  2104. 'takeLast': 'takeRight',
  2105. 'takeLastWhile': 'takeRightWhile',
  2106. 'unapply': 'rest',
  2107. 'unnest': 'flatten',
  2108. 'useWith': 'overArgs',
  2109. 'where': 'conformsTo',
  2110. 'whereEq': 'isMatch',
  2111. 'zipObj': 'zipObject'
  2112. };
  2113. /** Used to map ary to method names. */
  2114. exports.aryMethod = {
  2115. '1': [
  2116. 'assignAll', 'assignInAll', 'attempt', 'castArray', 'ceil', 'create',
  2117. 'curry', 'curryRight', 'defaultsAll', 'defaultsDeepAll', 'floor', 'flow',
  2118. 'flowRight', 'fromPairs', 'invert', 'iteratee', 'memoize', 'method', 'mergeAll',
  2119. 'methodOf', 'mixin', 'nthArg', 'over', 'overEvery', 'overSome','rest', 'reverse',
  2120. 'round', 'runInContext', 'spread', 'template', 'trim', 'trimEnd', 'trimStart',
  2121. 'uniqueId', 'words', 'zipAll'
  2122. ],
  2123. '2': [
  2124. 'add', 'after', 'ary', 'assign', 'assignAllWith', 'assignIn', 'assignInAllWith',
  2125. 'at', 'before', 'bind', 'bindAll', 'bindKey', 'chunk', 'cloneDeepWith',
  2126. 'cloneWith', 'concat', 'conformsTo', 'countBy', 'curryN', 'curryRightN',
  2127. 'debounce', 'defaults', 'defaultsDeep', 'defaultTo', 'delay', 'difference',
  2128. 'divide', 'drop', 'dropRight', 'dropRightWhile', 'dropWhile', 'endsWith', 'eq',
  2129. 'every', 'filter', 'find', 'findIndex', 'findKey', 'findLast', 'findLastIndex',
  2130. 'findLastKey', 'flatMap', 'flatMapDeep', 'flattenDepth', 'forEach',
  2131. 'forEachRight', 'forIn', 'forInRight', 'forOwn', 'forOwnRight', 'get',
  2132. 'groupBy', 'gt', 'gte', 'has', 'hasIn', 'includes', 'indexOf', 'intersection',
  2133. 'invertBy', 'invoke', 'invokeMap', 'isEqual', 'isMatch', 'join', 'keyBy',
  2134. 'lastIndexOf', 'lt', 'lte', 'map', 'mapKeys', 'mapValues', 'matchesProperty',
  2135. 'maxBy', 'meanBy', 'merge', 'mergeAllWith', 'minBy', 'multiply', 'nth', 'omit',
  2136. 'omitBy', 'overArgs', 'pad', 'padEnd', 'padStart', 'parseInt', 'partial',
  2137. 'partialRight', 'partition', 'pick', 'pickBy', 'propertyOf', 'pull', 'pullAll',
  2138. 'pullAt', 'random', 'range', 'rangeRight', 'rearg', 'reject', 'remove',
  2139. 'repeat', 'restFrom', 'result', 'sampleSize', 'some', 'sortBy', 'sortedIndex',
  2140. 'sortedIndexOf', 'sortedLastIndex', 'sortedLastIndexOf', 'sortedUniqBy',
  2141. 'split', 'spreadFrom', 'startsWith', 'subtract', 'sumBy', 'take', 'takeRight',
  2142. 'takeRightWhile', 'takeWhile', 'tap', 'throttle', 'thru', 'times', 'trimChars',
  2143. 'trimCharsEnd', 'trimCharsStart', 'truncate', 'union', 'uniqBy', 'uniqWith',
  2144. 'unset', 'unzipWith', 'without', 'wrap', 'xor', 'zip', 'zipObject',
  2145. 'zipObjectDeep'
  2146. ],
  2147. '3': [
  2148. 'assignInWith', 'assignWith', 'clamp', 'differenceBy', 'differenceWith',
  2149. 'findFrom', 'findIndexFrom', 'findLastFrom', 'findLastIndexFrom', 'getOr',
  2150. 'includesFrom', 'indexOfFrom', 'inRange', 'intersectionBy', 'intersectionWith',
  2151. 'invokeArgs', 'invokeArgsMap', 'isEqualWith', 'isMatchWith', 'flatMapDepth',
  2152. 'lastIndexOfFrom', 'mergeWith', 'orderBy', 'padChars', 'padCharsEnd',
  2153. 'padCharsStart', 'pullAllBy', 'pullAllWith', 'rangeStep', 'rangeStepRight',
  2154. 'reduce', 'reduceRight', 'replace', 'set', 'slice', 'sortedIndexBy',
  2155. 'sortedLastIndexBy', 'transform', 'unionBy', 'unionWith', 'update', 'xorBy',
  2156. 'xorWith', 'zipWith'
  2157. ],
  2158. '4': [
  2159. 'fill', 'setWith', 'updateWith'
  2160. ]
  2161. };
  2162. /** Used to map ary to rearg configs. */
  2163. exports.aryRearg = {
  2164. '2': [1, 0],
  2165. '3': [2, 0, 1],
  2166. '4': [3, 2, 0, 1]
  2167. };
  2168. /** Used to map method names to their iteratee ary. */
  2169. exports.iterateeAry = {
  2170. 'dropRightWhile': 1,
  2171. 'dropWhile': 1,
  2172. 'every': 1,
  2173. 'filter': 1,
  2174. 'find': 1,
  2175. 'findFrom': 1,
  2176. 'findIndex': 1,
  2177. 'findIndexFrom': 1,
  2178. 'findKey': 1,
  2179. 'findLast': 1,
  2180. 'findLastFrom': 1,
  2181. 'findLastIndex': 1,
  2182. 'findLastIndexFrom': 1,
  2183. 'findLastKey': 1,
  2184. 'flatMap': 1,
  2185. 'flatMapDeep': 1,
  2186. 'flatMapDepth': 1,
  2187. 'forEach': 1,
  2188. 'forEachRight': 1,
  2189. 'forIn': 1,
  2190. 'forInRight': 1,
  2191. 'forOwn': 1,
  2192. 'forOwnRight': 1,
  2193. 'map': 1,
  2194. 'mapKeys': 1,
  2195. 'mapValues': 1,
  2196. 'partition': 1,
  2197. 'reduce': 2,
  2198. 'reduceRight': 2,
  2199. 'reject': 1,
  2200. 'remove': 1,
  2201. 'some': 1,
  2202. 'takeRightWhile': 1,
  2203. 'takeWhile': 1,
  2204. 'times': 1,
  2205. 'transform': 2
  2206. };
  2207. /** Used to map method names to iteratee rearg configs. */
  2208. exports.iterateeRearg = {
  2209. 'mapKeys': [1],
  2210. 'reduceRight': [1, 0]
  2211. };
  2212. /** Used to map method names to rearg configs. */
  2213. exports.methodRearg = {
  2214. 'assignInAllWith': [1, 0],
  2215. 'assignInWith': [1, 2, 0],
  2216. 'assignAllWith': [1, 0],
  2217. 'assignWith': [1, 2, 0],
  2218. 'differenceBy': [1, 2, 0],
  2219. 'differenceWith': [1, 2, 0],
  2220. 'getOr': [2, 1, 0],
  2221. 'intersectionBy': [1, 2, 0],
  2222. 'intersectionWith': [1, 2, 0],
  2223. 'isEqualWith': [1, 2, 0],
  2224. 'isMatchWith': [2, 1, 0],
  2225. 'mergeAllWith': [1, 0],
  2226. 'mergeWith': [1, 2, 0],
  2227. 'padChars': [2, 1, 0],
  2228. 'padCharsEnd': [2, 1, 0],
  2229. 'padCharsStart': [2, 1, 0],
  2230. 'pullAllBy': [2, 1, 0],
  2231. 'pullAllWith': [2, 1, 0],
  2232. 'rangeStep': [1, 2, 0],
  2233. 'rangeStepRight': [1, 2, 0],
  2234. 'setWith': [3, 1, 2, 0],
  2235. 'sortedIndexBy': [2, 1, 0],
  2236. 'sortedLastIndexBy': [2, 1, 0],
  2237. 'unionBy': [1, 2, 0],
  2238. 'unionWith': [1, 2, 0],
  2239. 'updateWith': [3, 1, 2, 0],
  2240. 'xorBy': [1, 2, 0],
  2241. 'xorWith': [1, 2, 0],
  2242. 'zipWith': [1, 2, 0]
  2243. };
  2244. /** Used to map method names to spread configs. */
  2245. exports.methodSpread = {
  2246. 'assignAll': { 'start': 0 },
  2247. 'assignAllWith': { 'start': 0 },
  2248. 'assignInAll': { 'start': 0 },
  2249. 'assignInAllWith': { 'start': 0 },
  2250. 'defaultsAll': { 'start': 0 },
  2251. 'defaultsDeepAll': { 'start': 0 },
  2252. 'invokeArgs': { 'start': 2 },
  2253. 'invokeArgsMap': { 'start': 2 },
  2254. 'mergeAll': { 'start': 0 },
  2255. 'mergeAllWith': { 'start': 0 },
  2256. 'partial': { 'start': 1 },
  2257. 'partialRight': { 'start': 1 },
  2258. 'without': { 'start': 1 },
  2259. 'zipAll': { 'start': 0 }
  2260. };
  2261. /** Used to identify methods which mutate arrays or objects. */
  2262. exports.mutate = {
  2263. 'array': {
  2264. 'fill': true,
  2265. 'pull': true,
  2266. 'pullAll': true,
  2267. 'pullAllBy': true,
  2268. 'pullAllWith': true,
  2269. 'pullAt': true,
  2270. 'remove': true,
  2271. 'reverse': true
  2272. },
  2273. 'object': {
  2274. 'assign': true,
  2275. 'assignAll': true,
  2276. 'assignAllWith': true,
  2277. 'assignIn': true,
  2278. 'assignInAll': true,
  2279. 'assignInAllWith': true,
  2280. 'assignInWith': true,
  2281. 'assignWith': true,
  2282. 'defaults': true,
  2283. 'defaultsAll': true,
  2284. 'defaultsDeep': true,
  2285. 'defaultsDeepAll': true,
  2286. 'merge': true,
  2287. 'mergeAll': true,
  2288. 'mergeAllWith': true,
  2289. 'mergeWith': true,
  2290. },
  2291. 'set': {
  2292. 'set': true,
  2293. 'setWith': true,
  2294. 'unset': true,
  2295. 'update': true,
  2296. 'updateWith': true
  2297. }
  2298. };
  2299. /** Used to map real names to their aliases. */
  2300. exports.realToAlias = (function() {
  2301. var hasOwnProperty = Object.prototype.hasOwnProperty,
  2302. object = exports.aliasToReal,
  2303. result = {};
  2304. for (var key in object) {
  2305. var value = object[key];
  2306. if (hasOwnProperty.call(result, value)) {
  2307. result[value].push(key);
  2308. } else {
  2309. result[value] = [key];
  2310. }
  2311. }
  2312. return result;
  2313. }());
  2314. /** Used to map method names to other names. */
  2315. exports.remap = {
  2316. 'assignAll': 'assign',
  2317. 'assignAllWith': 'assignWith',
  2318. 'assignInAll': 'assignIn',
  2319. 'assignInAllWith': 'assignInWith',
  2320. 'curryN': 'curry',
  2321. 'curryRightN': 'curryRight',
  2322. 'defaultsAll': 'defaults',
  2323. 'defaultsDeepAll': 'defaultsDeep',
  2324. 'findFrom': 'find',
  2325. 'findIndexFrom': 'findIndex',
  2326. 'findLastFrom': 'findLast',
  2327. 'findLastIndexFrom': 'findLastIndex',
  2328. 'getOr': 'get',
  2329. 'includesFrom': 'includes',
  2330. 'indexOfFrom': 'indexOf',
  2331. 'invokeArgs': 'invoke',
  2332. 'invokeArgsMap': 'invokeMap',
  2333. 'lastIndexOfFrom': 'lastIndexOf',
  2334. 'mergeAll': 'merge',
  2335. 'mergeAllWith': 'mergeWith',
  2336. 'padChars': 'pad',
  2337. 'padCharsEnd': 'padEnd',
  2338. 'padCharsStart': 'padStart',
  2339. 'propertyOf': 'get',
  2340. 'rangeStep': 'range',
  2341. 'rangeStepRight': 'rangeRight',
  2342. 'restFrom': 'rest',
  2343. 'spreadFrom': 'spread',
  2344. 'trimChars': 'trim',
  2345. 'trimCharsEnd': 'trimEnd',
  2346. 'trimCharsStart': 'trimStart',
  2347. 'zipAll': 'zip'
  2348. };
  2349. /** Used to track methods that skip fixing their arity. */
  2350. exports.skipFixed = {
  2351. 'castArray': true,
  2352. 'flow': true,
  2353. 'flowRight': true,
  2354. 'iteratee': true,
  2355. 'mixin': true,
  2356. 'rearg': true,
  2357. 'runInContext': true
  2358. };
  2359. /** Used to track methods that skip rearranging arguments. */
  2360. exports.skipRearg = {
  2361. 'add': true,
  2362. 'assign': true,
  2363. 'assignIn': true,
  2364. 'bind': true,
  2365. 'bindKey': true,
  2366. 'concat': true,
  2367. 'difference': true,
  2368. 'divide': true,
  2369. 'eq': true,
  2370. 'gt': true,
  2371. 'gte': true,
  2372. 'isEqual': true,
  2373. 'lt': true,
  2374. 'lte': true,
  2375. 'matchesProperty': true,
  2376. 'merge': true,
  2377. 'multiply': true,
  2378. 'overArgs': true,
  2379. 'partial': true,
  2380. 'partialRight': true,
  2381. 'propertyOf': true,
  2382. 'random': true,
  2383. 'range': true,
  2384. 'rangeRight': true,
  2385. 'subtract': true,
  2386. 'zip': true,
  2387. 'zipObject': true,
  2388. 'zipObjectDeep': true
  2389. };
  2390. }, "/$$rollup_base$$/node_modules/lodash/fp");
  2391. /**
  2392. * The default argument placeholder value for methods.
  2393. *
  2394. * @type {Object}
  2395. */
  2396. var placeholder = {};
  2397. /** Built-in value reference. */
  2398. var push = Array.prototype.push;
  2399. /**
  2400. * Creates a function, with an arity of `n`, that invokes `func` with the
  2401. * arguments it receives.
  2402. *
  2403. * @private
  2404. * @param {Function} func The function to wrap.
  2405. * @param {number} n The arity of the new function.
  2406. * @returns {Function} Returns the new function.
  2407. */
  2408. function baseArity(func, n) {
  2409. return n == 2
  2410. ? function(a, b) { return func.apply(undefined, arguments); }
  2411. : function(a) { return func.apply(undefined, arguments); };
  2412. }
  2413. /**
  2414. * Creates a function that invokes `func`, with up to `n` arguments, ignoring
  2415. * any additional arguments.
  2416. *
  2417. * @private
  2418. * @param {Function} func The function to cap arguments for.
  2419. * @param {number} n The arity cap.
  2420. * @returns {Function} Returns the new function.
  2421. */
  2422. function baseAry(func, n) {
  2423. return n == 2
  2424. ? function(a, b) { return func(a, b); }
  2425. : function(a) { return func(a); };
  2426. }
  2427. /**
  2428. * Creates a clone of `array`.
  2429. *
  2430. * @private
  2431. * @param {Array} array The array to clone.
  2432. * @returns {Array} Returns the cloned array.
  2433. */
  2434. function cloneArray(array) {
  2435. var length = array ? array.length : 0,
  2436. result = Array(length);
  2437. while (length--) {
  2438. result[length] = array[length];
  2439. }
  2440. return result;
  2441. }
  2442. /**
  2443. * Creates a function that clones a given object using the assignment `func`.
  2444. *
  2445. * @private
  2446. * @param {Function} func The assignment function.
  2447. * @returns {Function} Returns the new cloner function.
  2448. */
  2449. function createCloner(func) {
  2450. return function(object) {
  2451. return func({}, object);
  2452. };
  2453. }
  2454. /**
  2455. * A specialized version of `_.spread` which flattens the spread array into
  2456. * the arguments of the invoked `func`.
  2457. *
  2458. * @private
  2459. * @param {Function} func The function to spread arguments over.
  2460. * @param {number} start The start position of the spread.
  2461. * @returns {Function} Returns the new function.
  2462. */
  2463. function flatSpread(func, start) {
  2464. return function() {
  2465. var length = arguments.length,
  2466. lastIndex = length - 1,
  2467. args = Array(length);
  2468. while (length--) {
  2469. args[length] = arguments[length];
  2470. }
  2471. var array = args[start],
  2472. otherArgs = args.slice(0, start);
  2473. if (array) {
  2474. push.apply(otherArgs, array);
  2475. }
  2476. if (start != lastIndex) {
  2477. push.apply(otherArgs, args.slice(start + 1));
  2478. }
  2479. return func.apply(this, otherArgs);
  2480. };
  2481. }
  2482. /**
  2483. * Creates a function that wraps `func` and uses `cloner` to clone the first
  2484. * argument it receives.
  2485. *
  2486. * @private
  2487. * @param {Function} func The function to wrap.
  2488. * @param {Function} cloner The function to clone arguments.
  2489. * @returns {Function} Returns the new immutable function.
  2490. */
  2491. function wrapImmutable(func, cloner) {
  2492. return function() {
  2493. var length = arguments.length;
  2494. if (!length) {
  2495. return;
  2496. }
  2497. var args = Array(length);
  2498. while (length--) {
  2499. args[length] = arguments[length];
  2500. }
  2501. var result = args[0] = cloner.apply(undefined, args);
  2502. func.apply(undefined, args);
  2503. return result;
  2504. };
  2505. }
  2506. /**
  2507. * The base implementation of `convert` which accepts a `util` object of methods
  2508. * required to perform conversions.
  2509. *
  2510. * @param {Object} util The util object.
  2511. * @param {string} name The name of the function to convert.
  2512. * @param {Function} func The function to convert.
  2513. * @param {Object} [options] The options object.
  2514. * @param {boolean} [options.cap=true] Specify capping iteratee arguments.
  2515. * @param {boolean} [options.curry=true] Specify currying.
  2516. * @param {boolean} [options.fixed=true] Specify fixed arity.
  2517. * @param {boolean} [options.immutable=true] Specify immutable operations.
  2518. * @param {boolean} [options.rearg=true] Specify rearranging arguments.
  2519. * @returns {Function|Object} Returns the converted function or object.
  2520. */
  2521. function baseConvert(util, name, func, options) {
  2522. var isLib = typeof name == 'function',
  2523. isObj = name === Object(name);
  2524. if (isObj) {
  2525. options = func;
  2526. func = name;
  2527. name = undefined;
  2528. }
  2529. if (func == null) {
  2530. throw new TypeError;
  2531. }
  2532. options || (options = {});
  2533. var config = {
  2534. 'cap': 'cap' in options ? options.cap : true,
  2535. 'curry': 'curry' in options ? options.curry : true,
  2536. 'fixed': 'fixed' in options ? options.fixed : true,
  2537. 'immutable': 'immutable' in options ? options.immutable : true,
  2538. 'rearg': 'rearg' in options ? options.rearg : true
  2539. };
  2540. var defaultHolder = isLib ? func : placeholder,
  2541. forceCurry = ('curry' in options) && options.curry,
  2542. forceFixed = ('fixed' in options) && options.fixed,
  2543. forceRearg = ('rearg' in options) && options.rearg,
  2544. pristine = isLib ? func.runInContext() : undefined;
  2545. var helpers = isLib ? func : {
  2546. 'ary': util.ary,
  2547. 'assign': util.assign,
  2548. 'clone': util.clone,
  2549. 'curry': util.curry,
  2550. 'forEach': util.forEach,
  2551. 'isArray': util.isArray,
  2552. 'isError': util.isError,
  2553. 'isFunction': util.isFunction,
  2554. 'isWeakMap': util.isWeakMap,
  2555. 'iteratee': util.iteratee,
  2556. 'keys': util.keys,
  2557. 'rearg': util.rearg,
  2558. 'toInteger': util.toInteger,
  2559. 'toPath': util.toPath
  2560. };
  2561. var ary = helpers.ary,
  2562. assign = helpers.assign,
  2563. clone = helpers.clone,
  2564. curry = helpers.curry,
  2565. each = helpers.forEach,
  2566. isArray = helpers.isArray,
  2567. isError = helpers.isError,
  2568. isFunction = helpers.isFunction,
  2569. isWeakMap = helpers.isWeakMap,
  2570. keys = helpers.keys,
  2571. rearg = helpers.rearg,
  2572. toInteger = helpers.toInteger,
  2573. toPath = helpers.toPath;
  2574. var aryMethodKeys = keys(_mapping.aryMethod);
  2575. var wrappers = {
  2576. 'castArray': function(castArray) {
  2577. return function() {
  2578. var value = arguments[0];
  2579. return isArray(value)
  2580. ? castArray(cloneArray(value))
  2581. : castArray.apply(undefined, arguments);
  2582. };
  2583. },
  2584. 'iteratee': function(iteratee) {
  2585. return function() {
  2586. var func = arguments[0],
  2587. arity = arguments[1],
  2588. result = iteratee(func, arity),
  2589. length = result.length;
  2590. if (config.cap && typeof arity == 'number') {
  2591. arity = arity > 2 ? (arity - 2) : 1;
  2592. return (length && length <= arity) ? result : baseAry(result, arity);
  2593. }
  2594. return result;
  2595. };
  2596. },
  2597. 'mixin': function(mixin) {
  2598. return function(source) {
  2599. var func = this;
  2600. if (!isFunction(func)) {
  2601. return mixin(func, Object(source));
  2602. }
  2603. var pairs = [];
  2604. each(keys(source), function(key) {
  2605. if (isFunction(source[key])) {
  2606. pairs.push([key, func.prototype[key]]);
  2607. }
  2608. });
  2609. mixin(func, Object(source));
  2610. each(pairs, function(pair) {
  2611. var value = pair[1];
  2612. if (isFunction(value)) {
  2613. func.prototype[pair[0]] = value;
  2614. } else {
  2615. delete func.prototype[pair[0]];
  2616. }
  2617. });
  2618. return func;
  2619. };
  2620. },
  2621. 'nthArg': function(nthArg) {
  2622. return function(n) {
  2623. var arity = n < 0 ? 1 : (toInteger(n) + 1);
  2624. return curry(nthArg(n), arity);
  2625. };
  2626. },
  2627. 'rearg': function(rearg) {
  2628. return function(func, indexes) {
  2629. var arity = indexes ? indexes.length : 0;
  2630. return curry(rearg(func, indexes), arity);
  2631. };
  2632. },
  2633. 'runInContext': function(runInContext) {
  2634. return function(context) {
  2635. return baseConvert(util, runInContext(context), options);
  2636. };
  2637. }
  2638. };
  2639. /*--------------------------------------------------------------------------*/
  2640. /**
  2641. * Casts `func` to a function with an arity capped iteratee if needed.
  2642. *
  2643. * @private
  2644. * @param {string} name The name of the function to inspect.
  2645. * @param {Function} func The function to inspect.
  2646. * @returns {Function} Returns the cast function.
  2647. */
  2648. function castCap(name, func) {
  2649. if (config.cap) {
  2650. var indexes = _mapping.iterateeRearg[name];
  2651. if (indexes) {
  2652. return iterateeRearg(func, indexes);
  2653. }
  2654. var n = !isLib && _mapping.iterateeAry[name];
  2655. if (n) {
  2656. return iterateeAry(func, n);
  2657. }
  2658. }
  2659. return func;
  2660. }
  2661. /**
  2662. * Casts `func` to a curried function if needed.
  2663. *
  2664. * @private
  2665. * @param {string} name The name of the function to inspect.
  2666. * @param {Function} func The function to inspect.
  2667. * @param {number} n The arity of `func`.
  2668. * @returns {Function} Returns the cast function.
  2669. */
  2670. function castCurry(name, func, n) {
  2671. return (forceCurry || (config.curry && n > 1))
  2672. ? curry(func, n)
  2673. : func;
  2674. }
  2675. /**
  2676. * Casts `func` to a fixed arity function if needed.
  2677. *
  2678. * @private
  2679. * @param {string} name The name of the function to inspect.
  2680. * @param {Function} func The function to inspect.
  2681. * @param {number} n The arity cap.
  2682. * @returns {Function} Returns the cast function.
  2683. */
  2684. function castFixed(name, func, n) {
  2685. if (config.fixed && (forceFixed || !_mapping.skipFixed[name])) {
  2686. var data = _mapping.methodSpread[name],
  2687. start = data && data.start;
  2688. return start === undefined ? ary(func, n) : flatSpread(func, start);
  2689. }
  2690. return func;
  2691. }
  2692. /**
  2693. * Casts `func` to an rearged function if needed.
  2694. *
  2695. * @private
  2696. * @param {string} name The name of the function to inspect.
  2697. * @param {Function} func The function to inspect.
  2698. * @param {number} n The arity of `func`.
  2699. * @returns {Function} Returns the cast function.
  2700. */
  2701. function castRearg(name, func, n) {
  2702. return (config.rearg && n > 1 && (forceRearg || !_mapping.skipRearg[name]))
  2703. ? rearg(func, _mapping.methodRearg[name] || _mapping.aryRearg[n])
  2704. : func;
  2705. }
  2706. /**
  2707. * Creates a clone of `object` by `path`.
  2708. *
  2709. * @private
  2710. * @param {Object} object The object to clone.
  2711. * @param {Array|string} path The path to clone by.
  2712. * @returns {Object} Returns the cloned object.
  2713. */
  2714. function cloneByPath(object, path) {
  2715. path = toPath(path);
  2716. var index = -1,
  2717. length = path.length,
  2718. lastIndex = length - 1,
  2719. result = clone(Object(object)),
  2720. nested = result;
  2721. while (nested != null && ++index < length) {
  2722. var key = path[index],
  2723. value = nested[key];
  2724. if (value != null &&
  2725. !(isFunction(value) || isError(value) || isWeakMap(value))) {
  2726. nested[key] = clone(index == lastIndex ? value : Object(value));
  2727. }
  2728. nested = nested[key];
  2729. }
  2730. return result;
  2731. }
  2732. /**
  2733. * Converts `lodash` to an immutable auto-curried iteratee-first data-last
  2734. * version with conversion `options` applied.
  2735. *
  2736. * @param {Object} [options] The options object. See `baseConvert` for more details.
  2737. * @returns {Function} Returns the converted `lodash`.
  2738. */
  2739. function convertLib(options) {
  2740. return _.runInContext.convert(options)(undefined);
  2741. }
  2742. /**
  2743. * Create a converter function for `func` of `name`.
  2744. *
  2745. * @param {string} name The name of the function to convert.
  2746. * @param {Function} func The function to convert.
  2747. * @returns {Function} Returns the new converter function.
  2748. */
  2749. function createConverter(name, func) {
  2750. var realName = _mapping.aliasToReal[name] || name,
  2751. methodName = _mapping.remap[realName] || realName,
  2752. oldOptions = options;
  2753. return function(options) {
  2754. var newUtil = isLib ? pristine : helpers,
  2755. newFunc = isLib ? pristine[methodName] : func,
  2756. newOptions = assign(assign({}, oldOptions), options);
  2757. return baseConvert(newUtil, realName, newFunc, newOptions);
  2758. };
  2759. }
  2760. /**
  2761. * Creates a function that wraps `func` to invoke its iteratee, with up to `n`
  2762. * arguments, ignoring any additional arguments.
  2763. *
  2764. * @private
  2765. * @param {Function} func The function to cap iteratee arguments for.
  2766. * @param {number} n The arity cap.
  2767. * @returns {Function} Returns the new function.
  2768. */
  2769. function iterateeAry(func, n) {
  2770. return overArg(func, function(func) {
  2771. return typeof func == 'function' ? baseAry(func, n) : func;
  2772. });
  2773. }
  2774. /**
  2775. * Creates a function that wraps `func` to invoke its iteratee with arguments
  2776. * arranged according to the specified `indexes` where the argument value at
  2777. * the first index is provided as the first argument, the argument value at
  2778. * the second index is provided as the second argument, and so on.
  2779. *
  2780. * @private
  2781. * @param {Function} func The function to rearrange iteratee arguments for.
  2782. * @param {number[]} indexes The arranged argument indexes.
  2783. * @returns {Function} Returns the new function.
  2784. */
  2785. function iterateeRearg(func, indexes) {
  2786. return overArg(func, function(func) {
  2787. var n = indexes.length;
  2788. return baseArity(rearg(baseAry(func, n), indexes), n);
  2789. });
  2790. }
  2791. /**
  2792. * Creates a function that invokes `func` with its first argument transformed.
  2793. *
  2794. * @private
  2795. * @param {Function} func The function to wrap.
  2796. * @param {Function} transform The argument transform.
  2797. * @returns {Function} Returns the new function.
  2798. */
  2799. function overArg(func, transform) {
  2800. return function() {
  2801. var length = arguments.length;
  2802. if (!length) {
  2803. return func();
  2804. }
  2805. var args = Array(length);
  2806. while (length--) {
  2807. args[length] = arguments[length];
  2808. }
  2809. var index = config.rearg ? 0 : (length - 1);
  2810. args[index] = transform(args[index]);
  2811. return func.apply(undefined, args);
  2812. };
  2813. }
  2814. /**
  2815. * Creates a function that wraps `func` and applys the conversions
  2816. * rules by `name`.
  2817. *
  2818. * @private
  2819. * @param {string} name The name of the function to wrap.
  2820. * @param {Function} func The function to wrap.
  2821. * @returns {Function} Returns the converted function.
  2822. */
  2823. function wrap(name, func, placeholder) {
  2824. var result,
  2825. realName = _mapping.aliasToReal[name] || name,
  2826. wrapped = func,
  2827. wrapper = wrappers[realName];
  2828. if (wrapper) {
  2829. wrapped = wrapper(func);
  2830. }
  2831. else if (config.immutable) {
  2832. if (_mapping.mutate.array[realName]) {
  2833. wrapped = wrapImmutable(func, cloneArray);
  2834. }
  2835. else if (_mapping.mutate.object[realName]) {
  2836. wrapped = wrapImmutable(func, createCloner(func));
  2837. }
  2838. else if (_mapping.mutate.set[realName]) {
  2839. wrapped = wrapImmutable(func, cloneByPath);
  2840. }
  2841. }
  2842. each(aryMethodKeys, function(aryKey) {
  2843. each(_mapping.aryMethod[aryKey], function(otherName) {
  2844. if (realName == otherName) {
  2845. var data = _mapping.methodSpread[realName],
  2846. afterRearg = data && data.afterRearg;
  2847. result = afterRearg
  2848. ? castFixed(realName, castRearg(realName, wrapped, aryKey), aryKey)
  2849. : castRearg(realName, castFixed(realName, wrapped, aryKey), aryKey);
  2850. result = castCap(realName, result);
  2851. result = castCurry(realName, result, aryKey);
  2852. return false;
  2853. }
  2854. });
  2855. return !result;
  2856. });
  2857. result || (result = wrapped);
  2858. if (result == func) {
  2859. result = forceCurry ? curry(result, 1) : function() {
  2860. return func.apply(this, arguments);
  2861. };
  2862. }
  2863. result.convert = createConverter(realName, func);
  2864. result.placeholder = func.placeholder = placeholder;
  2865. return result;
  2866. }
  2867. /*--------------------------------------------------------------------------*/
  2868. if (!isObj) {
  2869. return wrap(name, func, defaultHolder);
  2870. }
  2871. var _ = func;
  2872. // Convert methods by ary cap.
  2873. var pairs = [];
  2874. each(aryMethodKeys, function(aryKey) {
  2875. each(_mapping.aryMethod[aryKey], function(key) {
  2876. var func = _[_mapping.remap[key] || key];
  2877. if (func) {
  2878. pairs.push([key, wrap(key, func, _)]);
  2879. }
  2880. });
  2881. });
  2882. // Convert remaining methods.
  2883. each(keys(_), function(key) {
  2884. var func = _[key];
  2885. if (typeof func == 'function') {
  2886. var length = pairs.length;
  2887. while (length--) {
  2888. if (pairs[length][0] == key) {
  2889. return;
  2890. }
  2891. }
  2892. func.convert = createConverter(key, func);
  2893. pairs.push([key, func]);
  2894. }
  2895. });
  2896. // Assign to `_` leaving `_.prototype` unchanged to allow chaining.
  2897. each(pairs, function(pair) {
  2898. _[pair[0]] = pair[1];
  2899. });
  2900. _.convert = convertLib;
  2901. _.placeholder = _;
  2902. // Assign aliases.
  2903. each(keys(_), function(key) {
  2904. each(_mapping.realToAlias[key] || [], function(alias) {
  2905. _[alias] = _[key];
  2906. });
  2907. });
  2908. return _;
  2909. }
  2910. var _baseConvert = baseConvert;
  2911. /** Used to compose bitmasks for function metadata. */
  2912. var WRAP_ARY_FLAG = 128;
  2913. /**
  2914. * Creates a function that invokes `func`, with up to `n` arguments,
  2915. * ignoring any additional arguments.
  2916. *
  2917. * @static
  2918. * @memberOf _
  2919. * @since 3.0.0
  2920. * @category Function
  2921. * @param {Function} func The function to cap arguments for.
  2922. * @param {number} [n=func.length] The arity cap.
  2923. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  2924. * @returns {Function} Returns the new capped function.
  2925. * @example
  2926. *
  2927. * _.map(['6', '8', '10'], _.ary(parseInt, 1));
  2928. * // => [6, 8, 10]
  2929. */
  2930. function ary(func, n, guard) {
  2931. n = guard ? undefined : n;
  2932. n = (func && n == null) ? func.length : n;
  2933. return _createWrap(func, WRAP_ARY_FLAG, undefined, undefined, undefined, undefined, n);
  2934. }
  2935. var ary_1 = ary;
  2936. /**
  2937. * The base implementation of `assignValue` and `assignMergeValue` without
  2938. * value checks.
  2939. *
  2940. * @private
  2941. * @param {Object} object The object to modify.
  2942. * @param {string} key The key of the property to assign.
  2943. * @param {*} value The value to assign.
  2944. */
  2945. function baseAssignValue(object, key, value) {
  2946. if (key == '__proto__' && _defineProperty) {
  2947. _defineProperty(object, key, {
  2948. 'configurable': true,
  2949. 'enumerable': true,
  2950. 'value': value,
  2951. 'writable': true
  2952. });
  2953. } else {
  2954. object[key] = value;
  2955. }
  2956. }
  2957. var _baseAssignValue = baseAssignValue;
  2958. /**
  2959. * Performs a
  2960. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  2961. * comparison between two values to determine if they are equivalent.
  2962. *
  2963. * @static
  2964. * @memberOf _
  2965. * @since 4.0.0
  2966. * @category Lang
  2967. * @param {*} value The value to compare.
  2968. * @param {*} other The other value to compare.
  2969. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  2970. * @example
  2971. *
  2972. * var object = { 'a': 1 };
  2973. * var other = { 'a': 1 };
  2974. *
  2975. * _.eq(object, object);
  2976. * // => true
  2977. *
  2978. * _.eq(object, other);
  2979. * // => false
  2980. *
  2981. * _.eq('a', 'a');
  2982. * // => true
  2983. *
  2984. * _.eq('a', Object('a'));
  2985. * // => false
  2986. *
  2987. * _.eq(NaN, NaN);
  2988. * // => true
  2989. */
  2990. function eq(value, other) {
  2991. return value === other || (value !== value && other !== other);
  2992. }
  2993. var eq_1 = eq;
  2994. /** Used for built-in method references. */
  2995. var objectProto$c = Object.prototype;
  2996. /** Used to check objects for own properties. */
  2997. var hasOwnProperty$a = objectProto$c.hasOwnProperty;
  2998. /**
  2999. * Assigns `value` to `key` of `object` if the existing value is not equivalent
  3000. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  3001. * for equality comparisons.
  3002. *
  3003. * @private
  3004. * @param {Object} object The object to modify.
  3005. * @param {string} key The key of the property to assign.
  3006. * @param {*} value The value to assign.
  3007. */
  3008. function assignValue(object, key, value) {
  3009. var objValue = object[key];
  3010. if (!(hasOwnProperty$a.call(object, key) && eq_1(objValue, value)) ||
  3011. (value === undefined && !(key in object))) {
  3012. _baseAssignValue(object, key, value);
  3013. }
  3014. }
  3015. var _assignValue = assignValue;
  3016. /**
  3017. * Copies properties of `source` to `object`.
  3018. *
  3019. * @private
  3020. * @param {Object} source The object to copy properties from.
  3021. * @param {Array} props The property identifiers to copy.
  3022. * @param {Object} [object={}] The object to copy properties to.
  3023. * @param {Function} [customizer] The function to customize copied values.
  3024. * @returns {Object} Returns `object`.
  3025. */
  3026. function copyObject(source, props, object, customizer) {
  3027. var isNew = !object;
  3028. object || (object = {});
  3029. var index = -1,
  3030. length = props.length;
  3031. while (++index < length) {
  3032. var key = props[index];
  3033. var newValue = customizer
  3034. ? customizer(object[key], source[key], key, object, source)
  3035. : undefined;
  3036. if (newValue === undefined) {
  3037. newValue = source[key];
  3038. }
  3039. if (isNew) {
  3040. _baseAssignValue(object, key, newValue);
  3041. } else {
  3042. _assignValue(object, key, newValue);
  3043. }
  3044. }
  3045. return object;
  3046. }
  3047. var _copyObject = copyObject;
  3048. /**
  3049. * The base implementation of `_.times` without support for iteratee shorthands
  3050. * or max array length checks.
  3051. *
  3052. * @private
  3053. * @param {number} n The number of times to invoke `iteratee`.
  3054. * @param {Function} iteratee The function invoked per iteration.
  3055. * @returns {Array} Returns the array of results.
  3056. */
  3057. function baseTimes(n, iteratee) {
  3058. var index = -1,
  3059. result = Array(n);
  3060. while (++index < n) {
  3061. result[index] = iteratee(index);
  3062. }
  3063. return result;
  3064. }
  3065. var _baseTimes = baseTimes;
  3066. /** `Object#toString` result references. */
  3067. var argsTag$3 = '[object Arguments]';
  3068. /**
  3069. * The base implementation of `_.isArguments`.
  3070. *
  3071. * @private
  3072. * @param {*} value The value to check.
  3073. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  3074. */
  3075. function baseIsArguments(value) {
  3076. return isObjectLike_1(value) && _baseGetTag(value) == argsTag$3;
  3077. }
  3078. var _baseIsArguments = baseIsArguments;
  3079. /** Used for built-in method references. */
  3080. var objectProto$b = Object.prototype;
  3081. /** Used to check objects for own properties. */
  3082. var hasOwnProperty$9 = objectProto$b.hasOwnProperty;
  3083. /** Built-in value references. */
  3084. var propertyIsEnumerable$1 = objectProto$b.propertyIsEnumerable;
  3085. /**
  3086. * Checks if `value` is likely an `arguments` object.
  3087. *
  3088. * @static
  3089. * @memberOf _
  3090. * @since 0.1.0
  3091. * @category Lang
  3092. * @param {*} value The value to check.
  3093. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  3094. * else `false`.
  3095. * @example
  3096. *
  3097. * _.isArguments(function() { return arguments; }());
  3098. * // => true
  3099. *
  3100. * _.isArguments([1, 2, 3]);
  3101. * // => false
  3102. */
  3103. var isArguments = _baseIsArguments(function() { return arguments; }()) ? _baseIsArguments : function(value) {
  3104. return isObjectLike_1(value) && hasOwnProperty$9.call(value, 'callee') &&
  3105. !propertyIsEnumerable$1.call(value, 'callee');
  3106. };
  3107. var isArguments_1 = isArguments;
  3108. /**
  3109. * This method returns `false`.
  3110. *
  3111. * @static
  3112. * @memberOf _
  3113. * @since 4.13.0
  3114. * @category Util
  3115. * @returns {boolean} Returns `false`.
  3116. * @example
  3117. *
  3118. * _.times(2, _.stubFalse);
  3119. * // => [false, false]
  3120. */
  3121. function stubFalse() {
  3122. return false;
  3123. }
  3124. var stubFalse_1 = stubFalse;
  3125. var isBuffer_1 = createCommonjsModule(function (module, exports) {
  3126. /** Detect free variable `exports`. */
  3127. var freeExports = exports && !exports.nodeType && exports;
  3128. /** Detect free variable `module`. */
  3129. var freeModule = freeExports && 'object' == 'object' && module && !module.nodeType && module;
  3130. /** Detect the popular CommonJS extension `module.exports`. */
  3131. var moduleExports = freeModule && freeModule.exports === freeExports;
  3132. /** Built-in value references. */
  3133. var Buffer = moduleExports ? _root.Buffer : undefined;
  3134. /* Built-in method references for those with the same name as other `lodash` methods. */
  3135. var nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined;
  3136. /**
  3137. * Checks if `value` is a buffer.
  3138. *
  3139. * @static
  3140. * @memberOf _
  3141. * @since 4.3.0
  3142. * @category Lang
  3143. * @param {*} value The value to check.
  3144. * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
  3145. * @example
  3146. *
  3147. * _.isBuffer(new Buffer(2));
  3148. * // => true
  3149. *
  3150. * _.isBuffer(new Uint8Array(2));
  3151. * // => false
  3152. */
  3153. var isBuffer = nativeIsBuffer || stubFalse_1;
  3154. module.exports = isBuffer;
  3155. }, "/$$rollup_base$$/node_modules/lodash");
  3156. /** Used as references for various `Number` constants. */
  3157. var MAX_SAFE_INTEGER = 9007199254740991;
  3158. /**
  3159. * Checks if `value` is a valid array-like length.
  3160. *
  3161. * **Note:** This method is loosely based on
  3162. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  3163. *
  3164. * @static
  3165. * @memberOf _
  3166. * @since 4.0.0
  3167. * @category Lang
  3168. * @param {*} value The value to check.
  3169. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  3170. * @example
  3171. *
  3172. * _.isLength(3);
  3173. * // => true
  3174. *
  3175. * _.isLength(Number.MIN_VALUE);
  3176. * // => false
  3177. *
  3178. * _.isLength(Infinity);
  3179. * // => false
  3180. *
  3181. * _.isLength('3');
  3182. * // => false
  3183. */
  3184. function isLength(value) {
  3185. return typeof value == 'number' &&
  3186. value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  3187. }
  3188. var isLength_1 = isLength;
  3189. /** `Object#toString` result references. */
  3190. var argsTag$2 = '[object Arguments]',
  3191. arrayTag$2 = '[object Array]',
  3192. boolTag$3 = '[object Boolean]',
  3193. dateTag$3 = '[object Date]',
  3194. errorTag$3 = '[object Error]',
  3195. funcTag$1 = '[object Function]',
  3196. mapTag$5 = '[object Map]',
  3197. numberTag$3 = '[object Number]',
  3198. objectTag$4 = '[object Object]',
  3199. regexpTag$3 = '[object RegExp]',
  3200. setTag$5 = '[object Set]',
  3201. stringTag$3 = '[object String]',
  3202. weakMapTag$3 = '[object WeakMap]';
  3203. var arrayBufferTag$3 = '[object ArrayBuffer]',
  3204. dataViewTag$4 = '[object DataView]',
  3205. float32Tag$2 = '[object Float32Array]',
  3206. float64Tag$2 = '[object Float64Array]',
  3207. int8Tag$2 = '[object Int8Array]',
  3208. int16Tag$2 = '[object Int16Array]',
  3209. int32Tag$2 = '[object Int32Array]',
  3210. uint8Tag$2 = '[object Uint8Array]',
  3211. uint8ClampedTag$2 = '[object Uint8ClampedArray]',
  3212. uint16Tag$2 = '[object Uint16Array]',
  3213. uint32Tag$2 = '[object Uint32Array]';
  3214. /** Used to identify `toStringTag` values of typed arrays. */
  3215. var typedArrayTags = {};
  3216. typedArrayTags[float32Tag$2] = typedArrayTags[float64Tag$2] =
  3217. typedArrayTags[int8Tag$2] = typedArrayTags[int16Tag$2] =
  3218. typedArrayTags[int32Tag$2] = typedArrayTags[uint8Tag$2] =
  3219. typedArrayTags[uint8ClampedTag$2] = typedArrayTags[uint16Tag$2] =
  3220. typedArrayTags[uint32Tag$2] = true;
  3221. typedArrayTags[argsTag$2] = typedArrayTags[arrayTag$2] =
  3222. typedArrayTags[arrayBufferTag$3] = typedArrayTags[boolTag$3] =
  3223. typedArrayTags[dataViewTag$4] = typedArrayTags[dateTag$3] =
  3224. typedArrayTags[errorTag$3] = typedArrayTags[funcTag$1] =
  3225. typedArrayTags[mapTag$5] = typedArrayTags[numberTag$3] =
  3226. typedArrayTags[objectTag$4] = typedArrayTags[regexpTag$3] =
  3227. typedArrayTags[setTag$5] = typedArrayTags[stringTag$3] =
  3228. typedArrayTags[weakMapTag$3] = false;
  3229. /**
  3230. * The base implementation of `_.isTypedArray` without Node.js optimizations.
  3231. *
  3232. * @private
  3233. * @param {*} value The value to check.
  3234. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  3235. */
  3236. function baseIsTypedArray(value) {
  3237. return isObjectLike_1(value) &&
  3238. isLength_1(value.length) && !!typedArrayTags[_baseGetTag(value)];
  3239. }
  3240. var _baseIsTypedArray = baseIsTypedArray;
  3241. /**
  3242. * The base implementation of `_.unary` without support for storing metadata.
  3243. *
  3244. * @private
  3245. * @param {Function} func The function to cap arguments for.
  3246. * @returns {Function} Returns the new capped function.
  3247. */
  3248. function baseUnary(func) {
  3249. return function(value) {
  3250. return func(value);
  3251. };
  3252. }
  3253. var _baseUnary = baseUnary;
  3254. var _nodeUtil = createCommonjsModule(function (module, exports) {
  3255. /** Detect free variable `exports`. */
  3256. var freeExports = exports && !exports.nodeType && exports;
  3257. /** Detect free variable `module`. */
  3258. var freeModule = freeExports && 'object' == 'object' && module && !module.nodeType && module;
  3259. /** Detect the popular CommonJS extension `module.exports`. */
  3260. var moduleExports = freeModule && freeModule.exports === freeExports;
  3261. /** Detect free variable `process` from Node.js. */
  3262. var freeProcess = moduleExports && _freeGlobal.process;
  3263. /** Used to access faster Node.js helpers. */
  3264. var nodeUtil = (function() {
  3265. try {
  3266. // Use `util.types` for Node.js 10+.
  3267. var types = freeModule && freeModule.require && freeModule.require('util').types;
  3268. if (types) {
  3269. return types;
  3270. }
  3271. // Legacy `process.binding('util')` for Node.js < 10.
  3272. return freeProcess && freeProcess.binding && freeProcess.binding('util');
  3273. } catch (e) {}
  3274. }());
  3275. module.exports = nodeUtil;
  3276. }, "/$$rollup_base$$/node_modules/lodash");
  3277. /* Node.js helper references. */
  3278. var nodeIsTypedArray = _nodeUtil && _nodeUtil.isTypedArray;
  3279. /**
  3280. * Checks if `value` is classified as a typed array.
  3281. *
  3282. * @static
  3283. * @memberOf _
  3284. * @since 3.0.0
  3285. * @category Lang
  3286. * @param {*} value The value to check.
  3287. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  3288. * @example
  3289. *
  3290. * _.isTypedArray(new Uint8Array);
  3291. * // => true
  3292. *
  3293. * _.isTypedArray([]);
  3294. * // => false
  3295. */
  3296. var isTypedArray = nodeIsTypedArray ? _baseUnary(nodeIsTypedArray) : _baseIsTypedArray;
  3297. var isTypedArray_1 = isTypedArray;
  3298. /** Used for built-in method references. */
  3299. var objectProto$a = Object.prototype;
  3300. /** Used to check objects for own properties. */
  3301. var hasOwnProperty$8 = objectProto$a.hasOwnProperty;
  3302. /**
  3303. * Creates an array of the enumerable property names of the array-like `value`.
  3304. *
  3305. * @private
  3306. * @param {*} value The value to query.
  3307. * @param {boolean} inherited Specify returning inherited property names.
  3308. * @returns {Array} Returns the array of property names.
  3309. */
  3310. function arrayLikeKeys(value, inherited) {
  3311. var isArr = isArray_1(value),
  3312. isArg = !isArr && isArguments_1(value),
  3313. isBuff = !isArr && !isArg && isBuffer_1(value),
  3314. isType = !isArr && !isArg && !isBuff && isTypedArray_1(value),
  3315. skipIndexes = isArr || isArg || isBuff || isType,
  3316. result = skipIndexes ? _baseTimes(value.length, String) : [],
  3317. length = result.length;
  3318. for (var key in value) {
  3319. if ((inherited || hasOwnProperty$8.call(value, key)) &&
  3320. !(skipIndexes && (
  3321. // Safari 9 has enumerable `arguments.length` in strict mode.
  3322. key == 'length' ||
  3323. // Node.js 0.10 has enumerable non-index properties on buffers.
  3324. (isBuff && (key == 'offset' || key == 'parent')) ||
  3325. // PhantomJS 2 has enumerable non-index properties on typed arrays.
  3326. (isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) ||
  3327. // Skip index properties.
  3328. _isIndex(key, length)
  3329. ))) {
  3330. result.push(key);
  3331. }
  3332. }
  3333. return result;
  3334. }
  3335. var _arrayLikeKeys = arrayLikeKeys;
  3336. /** Used for built-in method references. */
  3337. var objectProto$9 = Object.prototype;
  3338. /**
  3339. * Checks if `value` is likely a prototype object.
  3340. *
  3341. * @private
  3342. * @param {*} value The value to check.
  3343. * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
  3344. */
  3345. function isPrototype(value) {
  3346. var Ctor = value && value.constructor,
  3347. proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto$9;
  3348. return value === proto;
  3349. }
  3350. var _isPrototype = isPrototype;
  3351. /**
  3352. * Creates a unary function that invokes `func` with its argument transformed.
  3353. *
  3354. * @private
  3355. * @param {Function} func The function to wrap.
  3356. * @param {Function} transform The argument transform.
  3357. * @returns {Function} Returns the new function.
  3358. */
  3359. function overArg(func, transform) {
  3360. return function(arg) {
  3361. return func(transform(arg));
  3362. };
  3363. }
  3364. var _overArg = overArg;
  3365. /* Built-in method references for those with the same name as other `lodash` methods. */
  3366. var nativeKeys = _overArg(Object.keys, Object);
  3367. var _nativeKeys = nativeKeys;
  3368. /** Used for built-in method references. */
  3369. var objectProto$8 = Object.prototype;
  3370. /** Used to check objects for own properties. */
  3371. var hasOwnProperty$7 = objectProto$8.hasOwnProperty;
  3372. /**
  3373. * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
  3374. *
  3375. * @private
  3376. * @param {Object} object The object to query.
  3377. * @returns {Array} Returns the array of property names.
  3378. */
  3379. function baseKeys(object) {
  3380. if (!_isPrototype(object)) {
  3381. return _nativeKeys(object);
  3382. }
  3383. var result = [];
  3384. for (var key in Object(object)) {
  3385. if (hasOwnProperty$7.call(object, key) && key != 'constructor') {
  3386. result.push(key);
  3387. }
  3388. }
  3389. return result;
  3390. }
  3391. var _baseKeys = baseKeys;
  3392. /**
  3393. * Checks if `value` is array-like. A value is considered array-like if it's
  3394. * not a function and has a `value.length` that's an integer greater than or
  3395. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  3396. *
  3397. * @static
  3398. * @memberOf _
  3399. * @since 4.0.0
  3400. * @category Lang
  3401. * @param {*} value The value to check.
  3402. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  3403. * @example
  3404. *
  3405. * _.isArrayLike([1, 2, 3]);
  3406. * // => true
  3407. *
  3408. * _.isArrayLike(document.body.children);
  3409. * // => true
  3410. *
  3411. * _.isArrayLike('abc');
  3412. * // => true
  3413. *
  3414. * _.isArrayLike(_.noop);
  3415. * // => false
  3416. */
  3417. function isArrayLike(value) {
  3418. return value != null && isLength_1(value.length) && !isFunction_1(value);
  3419. }
  3420. var isArrayLike_1 = isArrayLike;
  3421. /**
  3422. * Creates an array of the own enumerable property names of `object`.
  3423. *
  3424. * **Note:** Non-object values are coerced to objects. See the
  3425. * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  3426. * for more details.
  3427. *
  3428. * @static
  3429. * @since 0.1.0
  3430. * @memberOf _
  3431. * @category Object
  3432. * @param {Object} object The object to query.
  3433. * @returns {Array} Returns the array of property names.
  3434. * @example
  3435. *
  3436. * function Foo() {
  3437. * this.a = 1;
  3438. * this.b = 2;
  3439. * }
  3440. *
  3441. * Foo.prototype.c = 3;
  3442. *
  3443. * _.keys(new Foo);
  3444. * // => ['a', 'b'] (iteration order is not guaranteed)
  3445. *
  3446. * _.keys('hi');
  3447. * // => ['0', '1']
  3448. */
  3449. function keys(object) {
  3450. return isArrayLike_1(object) ? _arrayLikeKeys(object) : _baseKeys(object);
  3451. }
  3452. var keys_1 = keys;
  3453. /**
  3454. * The base implementation of `_.assign` without support for multiple sources
  3455. * or `customizer` functions.
  3456. *
  3457. * @private
  3458. * @param {Object} object The destination object.
  3459. * @param {Object} source The source object.
  3460. * @returns {Object} Returns `object`.
  3461. */
  3462. function baseAssign(object, source) {
  3463. return object && _copyObject(source, keys_1(source), object);
  3464. }
  3465. var _baseAssign = baseAssign;
  3466. /**
  3467. * Removes all key-value entries from the list cache.
  3468. *
  3469. * @private
  3470. * @name clear
  3471. * @memberOf ListCache
  3472. */
  3473. function listCacheClear() {
  3474. this.__data__ = [];
  3475. this.size = 0;
  3476. }
  3477. var _listCacheClear = listCacheClear;
  3478. /**
  3479. * Gets the index at which the `key` is found in `array` of key-value pairs.
  3480. *
  3481. * @private
  3482. * @param {Array} array The array to inspect.
  3483. * @param {*} key The key to search for.
  3484. * @returns {number} Returns the index of the matched value, else `-1`.
  3485. */
  3486. function assocIndexOf(array, key) {
  3487. var length = array.length;
  3488. while (length--) {
  3489. if (eq_1(array[length][0], key)) {
  3490. return length;
  3491. }
  3492. }
  3493. return -1;
  3494. }
  3495. var _assocIndexOf = assocIndexOf;
  3496. /** Used for built-in method references. */
  3497. var arrayProto = Array.prototype;
  3498. /** Built-in value references. */
  3499. var splice = arrayProto.splice;
  3500. /**
  3501. * Removes `key` and its value from the list cache.
  3502. *
  3503. * @private
  3504. * @name delete
  3505. * @memberOf ListCache
  3506. * @param {string} key The key of the value to remove.
  3507. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  3508. */
  3509. function listCacheDelete(key) {
  3510. var data = this.__data__,
  3511. index = _assocIndexOf(data, key);
  3512. if (index < 0) {
  3513. return false;
  3514. }
  3515. var lastIndex = data.length - 1;
  3516. if (index == lastIndex) {
  3517. data.pop();
  3518. } else {
  3519. splice.call(data, index, 1);
  3520. }
  3521. --this.size;
  3522. return true;
  3523. }
  3524. var _listCacheDelete = listCacheDelete;
  3525. /**
  3526. * Gets the list cache value for `key`.
  3527. *
  3528. * @private
  3529. * @name get
  3530. * @memberOf ListCache
  3531. * @param {string} key The key of the value to get.
  3532. * @returns {*} Returns the entry value.
  3533. */
  3534. function listCacheGet(key) {
  3535. var data = this.__data__,
  3536. index = _assocIndexOf(data, key);
  3537. return index < 0 ? undefined : data[index][1];
  3538. }
  3539. var _listCacheGet = listCacheGet;
  3540. /**
  3541. * Checks if a list cache value for `key` exists.
  3542. *
  3543. * @private
  3544. * @name has
  3545. * @memberOf ListCache
  3546. * @param {string} key The key of the entry to check.
  3547. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  3548. */
  3549. function listCacheHas(key) {
  3550. return _assocIndexOf(this.__data__, key) > -1;
  3551. }
  3552. var _listCacheHas = listCacheHas;
  3553. /**
  3554. * Sets the list cache `key` to `value`.
  3555. *
  3556. * @private
  3557. * @name set
  3558. * @memberOf ListCache
  3559. * @param {string} key The key of the value to set.
  3560. * @param {*} value The value to set.
  3561. * @returns {Object} Returns the list cache instance.
  3562. */
  3563. function listCacheSet(key, value) {
  3564. var data = this.__data__,
  3565. index = _assocIndexOf(data, key);
  3566. if (index < 0) {
  3567. ++this.size;
  3568. data.push([key, value]);
  3569. } else {
  3570. data[index][1] = value;
  3571. }
  3572. return this;
  3573. }
  3574. var _listCacheSet = listCacheSet;
  3575. /**
  3576. * Creates an list cache object.
  3577. *
  3578. * @private
  3579. * @constructor
  3580. * @param {Array} [entries] The key-value pairs to cache.
  3581. */
  3582. function ListCache(entries) {
  3583. var index = -1,
  3584. length = entries == null ? 0 : entries.length;
  3585. this.clear();
  3586. while (++index < length) {
  3587. var entry = entries[index];
  3588. this.set(entry[0], entry[1]);
  3589. }
  3590. }
  3591. // Add methods to `ListCache`.
  3592. ListCache.prototype.clear = _listCacheClear;
  3593. ListCache.prototype['delete'] = _listCacheDelete;
  3594. ListCache.prototype.get = _listCacheGet;
  3595. ListCache.prototype.has = _listCacheHas;
  3596. ListCache.prototype.set = _listCacheSet;
  3597. var _ListCache = ListCache;
  3598. /**
  3599. * Removes all key-value entries from the stack.
  3600. *
  3601. * @private
  3602. * @name clear
  3603. * @memberOf Stack
  3604. */
  3605. function stackClear() {
  3606. this.__data__ = new _ListCache;
  3607. this.size = 0;
  3608. }
  3609. var _stackClear = stackClear;
  3610. /**
  3611. * Removes `key` and its value from the stack.
  3612. *
  3613. * @private
  3614. * @name delete
  3615. * @memberOf Stack
  3616. * @param {string} key The key of the value to remove.
  3617. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  3618. */
  3619. function stackDelete(key) {
  3620. var data = this.__data__,
  3621. result = data['delete'](key);
  3622. this.size = data.size;
  3623. return result;
  3624. }
  3625. var _stackDelete = stackDelete;
  3626. /**
  3627. * Gets the stack value for `key`.
  3628. *
  3629. * @private
  3630. * @name get
  3631. * @memberOf Stack
  3632. * @param {string} key The key of the value to get.
  3633. * @returns {*} Returns the entry value.
  3634. */
  3635. function stackGet(key) {
  3636. return this.__data__.get(key);
  3637. }
  3638. var _stackGet = stackGet;
  3639. /**
  3640. * Checks if a stack value for `key` exists.
  3641. *
  3642. * @private
  3643. * @name has
  3644. * @memberOf Stack
  3645. * @param {string} key The key of the entry to check.
  3646. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  3647. */
  3648. function stackHas(key) {
  3649. return this.__data__.has(key);
  3650. }
  3651. var _stackHas = stackHas;
  3652. /* Built-in method references that are verified to be native. */
  3653. var Map$1 = _getNative(_root, 'Map');
  3654. var _Map = Map$1;
  3655. /* Built-in method references that are verified to be native. */
  3656. var nativeCreate = _getNative(Object, 'create');
  3657. var _nativeCreate = nativeCreate;
  3658. /**
  3659. * Removes all key-value entries from the hash.
  3660. *
  3661. * @private
  3662. * @name clear
  3663. * @memberOf Hash
  3664. */
  3665. function hashClear() {
  3666. this.__data__ = _nativeCreate ? _nativeCreate(null) : {};
  3667. this.size = 0;
  3668. }
  3669. var _hashClear = hashClear;
  3670. /**
  3671. * Removes `key` and its value from the hash.
  3672. *
  3673. * @private
  3674. * @name delete
  3675. * @memberOf Hash
  3676. * @param {Object} hash The hash to modify.
  3677. * @param {string} key The key of the value to remove.
  3678. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  3679. */
  3680. function hashDelete(key) {
  3681. var result = this.has(key) && delete this.__data__[key];
  3682. this.size -= result ? 1 : 0;
  3683. return result;
  3684. }
  3685. var _hashDelete = hashDelete;
  3686. /** Used to stand-in for `undefined` hash values. */
  3687. var HASH_UNDEFINED$2 = '__lodash_hash_undefined__';
  3688. /** Used for built-in method references. */
  3689. var objectProto$7 = Object.prototype;
  3690. /** Used to check objects for own properties. */
  3691. var hasOwnProperty$6 = objectProto$7.hasOwnProperty;
  3692. /**
  3693. * Gets the hash value for `key`.
  3694. *
  3695. * @private
  3696. * @name get
  3697. * @memberOf Hash
  3698. * @param {string} key The key of the value to get.
  3699. * @returns {*} Returns the entry value.
  3700. */
  3701. function hashGet(key) {
  3702. var data = this.__data__;
  3703. if (_nativeCreate) {
  3704. var result = data[key];
  3705. return result === HASH_UNDEFINED$2 ? undefined : result;
  3706. }
  3707. return hasOwnProperty$6.call(data, key) ? data[key] : undefined;
  3708. }
  3709. var _hashGet = hashGet;
  3710. /** Used for built-in method references. */
  3711. var objectProto$6 = Object.prototype;
  3712. /** Used to check objects for own properties. */
  3713. var hasOwnProperty$5 = objectProto$6.hasOwnProperty;
  3714. /**
  3715. * Checks if a hash value for `key` exists.
  3716. *
  3717. * @private
  3718. * @name has
  3719. * @memberOf Hash
  3720. * @param {string} key The key of the entry to check.
  3721. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  3722. */
  3723. function hashHas(key) {
  3724. var data = this.__data__;
  3725. return _nativeCreate ? (data[key] !== undefined) : hasOwnProperty$5.call(data, key);
  3726. }
  3727. var _hashHas = hashHas;
  3728. /** Used to stand-in for `undefined` hash values. */
  3729. var HASH_UNDEFINED$1 = '__lodash_hash_undefined__';
  3730. /**
  3731. * Sets the hash `key` to `value`.
  3732. *
  3733. * @private
  3734. * @name set
  3735. * @memberOf Hash
  3736. * @param {string} key The key of the value to set.
  3737. * @param {*} value The value to set.
  3738. * @returns {Object} Returns the hash instance.
  3739. */
  3740. function hashSet(key, value) {
  3741. var data = this.__data__;
  3742. this.size += this.has(key) ? 0 : 1;
  3743. data[key] = (_nativeCreate && value === undefined) ? HASH_UNDEFINED$1 : value;
  3744. return this;
  3745. }
  3746. var _hashSet = hashSet;
  3747. /**
  3748. * Creates a hash object.
  3749. *
  3750. * @private
  3751. * @constructor
  3752. * @param {Array} [entries] The key-value pairs to cache.
  3753. */
  3754. function Hash(entries) {
  3755. var index = -1,
  3756. length = entries == null ? 0 : entries.length;
  3757. this.clear();
  3758. while (++index < length) {
  3759. var entry = entries[index];
  3760. this.set(entry[0], entry[1]);
  3761. }
  3762. }
  3763. // Add methods to `Hash`.
  3764. Hash.prototype.clear = _hashClear;
  3765. Hash.prototype['delete'] = _hashDelete;
  3766. Hash.prototype.get = _hashGet;
  3767. Hash.prototype.has = _hashHas;
  3768. Hash.prototype.set = _hashSet;
  3769. var _Hash = Hash;
  3770. /**
  3771. * Removes all key-value entries from the map.
  3772. *
  3773. * @private
  3774. * @name clear
  3775. * @memberOf MapCache
  3776. */
  3777. function mapCacheClear() {
  3778. this.size = 0;
  3779. this.__data__ = {
  3780. 'hash': new _Hash,
  3781. 'map': new (_Map || _ListCache),
  3782. 'string': new _Hash
  3783. };
  3784. }
  3785. var _mapCacheClear = mapCacheClear;
  3786. /**
  3787. * Checks if `value` is suitable for use as unique object key.
  3788. *
  3789. * @private
  3790. * @param {*} value The value to check.
  3791. * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
  3792. */
  3793. function isKeyable(value) {
  3794. var type = typeof value;
  3795. return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
  3796. ? (value !== '__proto__')
  3797. : (value === null);
  3798. }
  3799. var _isKeyable = isKeyable;
  3800. /**
  3801. * Gets the data for `map`.
  3802. *
  3803. * @private
  3804. * @param {Object} map The map to query.
  3805. * @param {string} key The reference key.
  3806. * @returns {*} Returns the map data.
  3807. */
  3808. function getMapData(map, key) {
  3809. var data = map.__data__;
  3810. return _isKeyable(key)
  3811. ? data[typeof key == 'string' ? 'string' : 'hash']
  3812. : data.map;
  3813. }
  3814. var _getMapData = getMapData;
  3815. /**
  3816. * Removes `key` and its value from the map.
  3817. *
  3818. * @private
  3819. * @name delete
  3820. * @memberOf MapCache
  3821. * @param {string} key The key of the value to remove.
  3822. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  3823. */
  3824. function mapCacheDelete(key) {
  3825. var result = _getMapData(this, key)['delete'](key);
  3826. this.size -= result ? 1 : 0;
  3827. return result;
  3828. }
  3829. var _mapCacheDelete = mapCacheDelete;
  3830. /**
  3831. * Gets the map value for `key`.
  3832. *
  3833. * @private
  3834. * @name get
  3835. * @memberOf MapCache
  3836. * @param {string} key The key of the value to get.
  3837. * @returns {*} Returns the entry value.
  3838. */
  3839. function mapCacheGet(key) {
  3840. return _getMapData(this, key).get(key);
  3841. }
  3842. var _mapCacheGet = mapCacheGet;
  3843. /**
  3844. * Checks if a map value for `key` exists.
  3845. *
  3846. * @private
  3847. * @name has
  3848. * @memberOf MapCache
  3849. * @param {string} key The key of the entry to check.
  3850. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  3851. */
  3852. function mapCacheHas(key) {
  3853. return _getMapData(this, key).has(key);
  3854. }
  3855. var _mapCacheHas = mapCacheHas;
  3856. /**
  3857. * Sets the map `key` to `value`.
  3858. *
  3859. * @private
  3860. * @name set
  3861. * @memberOf MapCache
  3862. * @param {string} key The key of the value to set.
  3863. * @param {*} value The value to set.
  3864. * @returns {Object} Returns the map cache instance.
  3865. */
  3866. function mapCacheSet(key, value) {
  3867. var data = _getMapData(this, key),
  3868. size = data.size;
  3869. data.set(key, value);
  3870. this.size += data.size == size ? 0 : 1;
  3871. return this;
  3872. }
  3873. var _mapCacheSet = mapCacheSet;
  3874. /**
  3875. * Creates a map cache object to store key-value pairs.
  3876. *
  3877. * @private
  3878. * @constructor
  3879. * @param {Array} [entries] The key-value pairs to cache.
  3880. */
  3881. function MapCache(entries) {
  3882. var index = -1,
  3883. length = entries == null ? 0 : entries.length;
  3884. this.clear();
  3885. while (++index < length) {
  3886. var entry = entries[index];
  3887. this.set(entry[0], entry[1]);
  3888. }
  3889. }
  3890. // Add methods to `MapCache`.
  3891. MapCache.prototype.clear = _mapCacheClear;
  3892. MapCache.prototype['delete'] = _mapCacheDelete;
  3893. MapCache.prototype.get = _mapCacheGet;
  3894. MapCache.prototype.has = _mapCacheHas;
  3895. MapCache.prototype.set = _mapCacheSet;
  3896. var _MapCache = MapCache;
  3897. /** Used as the size to enable large array optimizations. */
  3898. var LARGE_ARRAY_SIZE = 200;
  3899. /**
  3900. * Sets the stack `key` to `value`.
  3901. *
  3902. * @private
  3903. * @name set
  3904. * @memberOf Stack
  3905. * @param {string} key The key of the value to set.
  3906. * @param {*} value The value to set.
  3907. * @returns {Object} Returns the stack cache instance.
  3908. */
  3909. function stackSet(key, value) {
  3910. var data = this.__data__;
  3911. if (data instanceof _ListCache) {
  3912. var pairs = data.__data__;
  3913. if (!_Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) {
  3914. pairs.push([key, value]);
  3915. this.size = ++data.size;
  3916. return this;
  3917. }
  3918. data = this.__data__ = new _MapCache(pairs);
  3919. }
  3920. data.set(key, value);
  3921. this.size = data.size;
  3922. return this;
  3923. }
  3924. var _stackSet = stackSet;
  3925. /**
  3926. * Creates a stack cache object to store key-value pairs.
  3927. *
  3928. * @private
  3929. * @constructor
  3930. * @param {Array} [entries] The key-value pairs to cache.
  3931. */
  3932. function Stack(entries) {
  3933. var data = this.__data__ = new _ListCache(entries);
  3934. this.size = data.size;
  3935. }
  3936. // Add methods to `Stack`.
  3937. Stack.prototype.clear = _stackClear;
  3938. Stack.prototype['delete'] = _stackDelete;
  3939. Stack.prototype.get = _stackGet;
  3940. Stack.prototype.has = _stackHas;
  3941. Stack.prototype.set = _stackSet;
  3942. var _Stack = Stack;
  3943. /**
  3944. * This function is like
  3945. * [`Object.keys`](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  3946. * except that it includes inherited enumerable properties.
  3947. *
  3948. * @private
  3949. * @param {Object} object The object to query.
  3950. * @returns {Array} Returns the array of property names.
  3951. */
  3952. function nativeKeysIn(object) {
  3953. var result = [];
  3954. if (object != null) {
  3955. for (var key in Object(object)) {
  3956. result.push(key);
  3957. }
  3958. }
  3959. return result;
  3960. }
  3961. var _nativeKeysIn = nativeKeysIn;
  3962. /** Used for built-in method references. */
  3963. var objectProto$5 = Object.prototype;
  3964. /** Used to check objects for own properties. */
  3965. var hasOwnProperty$4 = objectProto$5.hasOwnProperty;
  3966. /**
  3967. * The base implementation of `_.keysIn` which doesn't treat sparse arrays as dense.
  3968. *
  3969. * @private
  3970. * @param {Object} object The object to query.
  3971. * @returns {Array} Returns the array of property names.
  3972. */
  3973. function baseKeysIn(object) {
  3974. if (!isObject_1(object)) {
  3975. return _nativeKeysIn(object);
  3976. }
  3977. var isProto = _isPrototype(object),
  3978. result = [];
  3979. for (var key in object) {
  3980. if (!(key == 'constructor' && (isProto || !hasOwnProperty$4.call(object, key)))) {
  3981. result.push(key);
  3982. }
  3983. }
  3984. return result;
  3985. }
  3986. var _baseKeysIn = baseKeysIn;
  3987. /**
  3988. * Creates an array of the own and inherited enumerable property names of `object`.
  3989. *
  3990. * **Note:** Non-object values are coerced to objects.
  3991. *
  3992. * @static
  3993. * @memberOf _
  3994. * @since 3.0.0
  3995. * @category Object
  3996. * @param {Object} object The object to query.
  3997. * @returns {Array} Returns the array of property names.
  3998. * @example
  3999. *
  4000. * function Foo() {
  4001. * this.a = 1;
  4002. * this.b = 2;
  4003. * }
  4004. *
  4005. * Foo.prototype.c = 3;
  4006. *
  4007. * _.keysIn(new Foo);
  4008. * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
  4009. */
  4010. function keysIn(object) {
  4011. return isArrayLike_1(object) ? _arrayLikeKeys(object, true) : _baseKeysIn(object);
  4012. }
  4013. var keysIn_1 = keysIn;
  4014. /**
  4015. * The base implementation of `_.assignIn` without support for multiple sources
  4016. * or `customizer` functions.
  4017. *
  4018. * @private
  4019. * @param {Object} object The destination object.
  4020. * @param {Object} source The source object.
  4021. * @returns {Object} Returns `object`.
  4022. */
  4023. function baseAssignIn(object, source) {
  4024. return object && _copyObject(source, keysIn_1(source), object);
  4025. }
  4026. var _baseAssignIn = baseAssignIn;
  4027. var _cloneBuffer = createCommonjsModule(function (module, exports) {
  4028. /** Detect free variable `exports`. */
  4029. var freeExports = exports && !exports.nodeType && exports;
  4030. /** Detect free variable `module`. */
  4031. var freeModule = freeExports && 'object' == 'object' && module && !module.nodeType && module;
  4032. /** Detect the popular CommonJS extension `module.exports`. */
  4033. var moduleExports = freeModule && freeModule.exports === freeExports;
  4034. /** Built-in value references. */
  4035. var Buffer = moduleExports ? _root.Buffer : undefined,
  4036. allocUnsafe = Buffer ? Buffer.allocUnsafe : undefined;
  4037. /**
  4038. * Creates a clone of `buffer`.
  4039. *
  4040. * @private
  4041. * @param {Buffer} buffer The buffer to clone.
  4042. * @param {boolean} [isDeep] Specify a deep clone.
  4043. * @returns {Buffer} Returns the cloned buffer.
  4044. */
  4045. function cloneBuffer(buffer, isDeep) {
  4046. if (isDeep) {
  4047. return buffer.slice();
  4048. }
  4049. var length = buffer.length,
  4050. result = allocUnsafe ? allocUnsafe(length) : new buffer.constructor(length);
  4051. buffer.copy(result);
  4052. return result;
  4053. }
  4054. module.exports = cloneBuffer;
  4055. }, "/$$rollup_base$$/node_modules/lodash");
  4056. /**
  4057. * A specialized version of `_.filter` for arrays without support for
  4058. * iteratee shorthands.
  4059. *
  4060. * @private
  4061. * @param {Array} [array] The array to iterate over.
  4062. * @param {Function} predicate The function invoked per iteration.
  4063. * @returns {Array} Returns the new filtered array.
  4064. */
  4065. function arrayFilter(array, predicate) {
  4066. var index = -1,
  4067. length = array == null ? 0 : array.length,
  4068. resIndex = 0,
  4069. result = [];
  4070. while (++index < length) {
  4071. var value = array[index];
  4072. if (predicate(value, index, array)) {
  4073. result[resIndex++] = value;
  4074. }
  4075. }
  4076. return result;
  4077. }
  4078. var _arrayFilter = arrayFilter;
  4079. /**
  4080. * This method returns a new empty array.
  4081. *
  4082. * @static
  4083. * @memberOf _
  4084. * @since 4.13.0
  4085. * @category Util
  4086. * @returns {Array} Returns the new empty array.
  4087. * @example
  4088. *
  4089. * var arrays = _.times(2, _.stubArray);
  4090. *
  4091. * console.log(arrays);
  4092. * // => [[], []]
  4093. *
  4094. * console.log(arrays[0] === arrays[1]);
  4095. * // => false
  4096. */
  4097. function stubArray() {
  4098. return [];
  4099. }
  4100. var stubArray_1 = stubArray;
  4101. /** Used for built-in method references. */
  4102. var objectProto$4 = Object.prototype;
  4103. /** Built-in value references. */
  4104. var propertyIsEnumerable = objectProto$4.propertyIsEnumerable;
  4105. /* Built-in method references for those with the same name as other `lodash` methods. */
  4106. var nativeGetSymbols$1 = Object.getOwnPropertySymbols;
  4107. /**
  4108. * Creates an array of the own enumerable symbols of `object`.
  4109. *
  4110. * @private
  4111. * @param {Object} object The object to query.
  4112. * @returns {Array} Returns the array of symbols.
  4113. */
  4114. var getSymbols = !nativeGetSymbols$1 ? stubArray_1 : function(object) {
  4115. if (object == null) {
  4116. return [];
  4117. }
  4118. object = Object(object);
  4119. return _arrayFilter(nativeGetSymbols$1(object), function(symbol) {
  4120. return propertyIsEnumerable.call(object, symbol);
  4121. });
  4122. };
  4123. var _getSymbols = getSymbols;
  4124. /**
  4125. * Copies own symbols of `source` to `object`.
  4126. *
  4127. * @private
  4128. * @param {Object} source The object to copy symbols from.
  4129. * @param {Object} [object={}] The object to copy symbols to.
  4130. * @returns {Object} Returns `object`.
  4131. */
  4132. function copySymbols(source, object) {
  4133. return _copyObject(source, _getSymbols(source), object);
  4134. }
  4135. var _copySymbols = copySymbols;
  4136. /**
  4137. * Appends the elements of `values` to `array`.
  4138. *
  4139. * @private
  4140. * @param {Array} array The array to modify.
  4141. * @param {Array} values The values to append.
  4142. * @returns {Array} Returns `array`.
  4143. */
  4144. function arrayPush(array, values) {
  4145. var index = -1,
  4146. length = values.length,
  4147. offset = array.length;
  4148. while (++index < length) {
  4149. array[offset + index] = values[index];
  4150. }
  4151. return array;
  4152. }
  4153. var _arrayPush = arrayPush;
  4154. /** Built-in value references. */
  4155. var getPrototype = _overArg(Object.getPrototypeOf, Object);
  4156. var _getPrototype = getPrototype;
  4157. /* Built-in method references for those with the same name as other `lodash` methods. */
  4158. var nativeGetSymbols = Object.getOwnPropertySymbols;
  4159. /**
  4160. * Creates an array of the own and inherited enumerable symbols of `object`.
  4161. *
  4162. * @private
  4163. * @param {Object} object The object to query.
  4164. * @returns {Array} Returns the array of symbols.
  4165. */
  4166. var getSymbolsIn = !nativeGetSymbols ? stubArray_1 : function(object) {
  4167. var result = [];
  4168. while (object) {
  4169. _arrayPush(result, _getSymbols(object));
  4170. object = _getPrototype(object);
  4171. }
  4172. return result;
  4173. };
  4174. var _getSymbolsIn = getSymbolsIn;
  4175. /**
  4176. * Copies own and inherited symbols of `source` to `object`.
  4177. *
  4178. * @private
  4179. * @param {Object} source The object to copy symbols from.
  4180. * @param {Object} [object={}] The object to copy symbols to.
  4181. * @returns {Object} Returns `object`.
  4182. */
  4183. function copySymbolsIn(source, object) {
  4184. return _copyObject(source, _getSymbolsIn(source), object);
  4185. }
  4186. var _copySymbolsIn = copySymbolsIn;
  4187. /**
  4188. * The base implementation of `getAllKeys` and `getAllKeysIn` which uses
  4189. * `keysFunc` and `symbolsFunc` to get the enumerable property names and
  4190. * symbols of `object`.
  4191. *
  4192. * @private
  4193. * @param {Object} object The object to query.
  4194. * @param {Function} keysFunc The function to get the keys of `object`.
  4195. * @param {Function} symbolsFunc The function to get the symbols of `object`.
  4196. * @returns {Array} Returns the array of property names and symbols.
  4197. */
  4198. function baseGetAllKeys(object, keysFunc, symbolsFunc) {
  4199. var result = keysFunc(object);
  4200. return isArray_1(object) ? result : _arrayPush(result, symbolsFunc(object));
  4201. }
  4202. var _baseGetAllKeys = baseGetAllKeys;
  4203. /**
  4204. * Creates an array of own enumerable property names and symbols of `object`.
  4205. *
  4206. * @private
  4207. * @param {Object} object The object to query.
  4208. * @returns {Array} Returns the array of property names and symbols.
  4209. */
  4210. function getAllKeys(object) {
  4211. return _baseGetAllKeys(object, keys_1, _getSymbols);
  4212. }
  4213. var _getAllKeys = getAllKeys;
  4214. /**
  4215. * Creates an array of own and inherited enumerable property names and
  4216. * symbols of `object`.
  4217. *
  4218. * @private
  4219. * @param {Object} object The object to query.
  4220. * @returns {Array} Returns the array of property names and symbols.
  4221. */
  4222. function getAllKeysIn(object) {
  4223. return _baseGetAllKeys(object, keysIn_1, _getSymbolsIn);
  4224. }
  4225. var _getAllKeysIn = getAllKeysIn;
  4226. /* Built-in method references that are verified to be native. */
  4227. var DataView = _getNative(_root, 'DataView');
  4228. var _DataView = DataView;
  4229. /* Built-in method references that are verified to be native. */
  4230. var Promise$1 = _getNative(_root, 'Promise');
  4231. var _Promise = Promise$1;
  4232. /* Built-in method references that are verified to be native. */
  4233. var Set$1 = _getNative(_root, 'Set');
  4234. var _Set = Set$1;
  4235. /** `Object#toString` result references. */
  4236. var mapTag$4 = '[object Map]',
  4237. objectTag$3 = '[object Object]',
  4238. promiseTag = '[object Promise]',
  4239. setTag$4 = '[object Set]',
  4240. weakMapTag$2 = '[object WeakMap]';
  4241. var dataViewTag$3 = '[object DataView]';
  4242. /** Used to detect maps, sets, and weakmaps. */
  4243. var dataViewCtorString = _toSource(_DataView),
  4244. mapCtorString = _toSource(_Map),
  4245. promiseCtorString = _toSource(_Promise),
  4246. setCtorString = _toSource(_Set),
  4247. weakMapCtorString = _toSource(_WeakMap);
  4248. /**
  4249. * Gets the `toStringTag` of `value`.
  4250. *
  4251. * @private
  4252. * @param {*} value The value to query.
  4253. * @returns {string} Returns the `toStringTag`.
  4254. */
  4255. var getTag = _baseGetTag;
  4256. // Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6.
  4257. if ((_DataView && getTag(new _DataView(new ArrayBuffer(1))) != dataViewTag$3) ||
  4258. (_Map && getTag(new _Map) != mapTag$4) ||
  4259. (_Promise && getTag(_Promise.resolve()) != promiseTag) ||
  4260. (_Set && getTag(new _Set) != setTag$4) ||
  4261. (_WeakMap && getTag(new _WeakMap) != weakMapTag$2)) {
  4262. getTag = function(value) {
  4263. var result = _baseGetTag(value),
  4264. Ctor = result == objectTag$3 ? value.constructor : undefined,
  4265. ctorString = Ctor ? _toSource(Ctor) : '';
  4266. if (ctorString) {
  4267. switch (ctorString) {
  4268. case dataViewCtorString: return dataViewTag$3;
  4269. case mapCtorString: return mapTag$4;
  4270. case promiseCtorString: return promiseTag;
  4271. case setCtorString: return setTag$4;
  4272. case weakMapCtorString: return weakMapTag$2;
  4273. }
  4274. }
  4275. return result;
  4276. };
  4277. }
  4278. var _getTag = getTag;
  4279. /** Used for built-in method references. */
  4280. var objectProto$3 = Object.prototype;
  4281. /** Used to check objects for own properties. */
  4282. var hasOwnProperty$3 = objectProto$3.hasOwnProperty;
  4283. /**
  4284. * Initializes an array clone.
  4285. *
  4286. * @private
  4287. * @param {Array} array The array to clone.
  4288. * @returns {Array} Returns the initialized clone.
  4289. */
  4290. function initCloneArray(array) {
  4291. var length = array.length,
  4292. result = new array.constructor(length);
  4293. // Add properties assigned by `RegExp#exec`.
  4294. if (length && typeof array[0] == 'string' && hasOwnProperty$3.call(array, 'index')) {
  4295. result.index = array.index;
  4296. result.input = array.input;
  4297. }
  4298. return result;
  4299. }
  4300. var _initCloneArray = initCloneArray;
  4301. /** Built-in value references. */
  4302. var Uint8Array = _root.Uint8Array;
  4303. var _Uint8Array = Uint8Array;
  4304. /**
  4305. * Creates a clone of `arrayBuffer`.
  4306. *
  4307. * @private
  4308. * @param {ArrayBuffer} arrayBuffer The array buffer to clone.
  4309. * @returns {ArrayBuffer} Returns the cloned array buffer.
  4310. */
  4311. function cloneArrayBuffer(arrayBuffer) {
  4312. var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
  4313. new _Uint8Array(result).set(new _Uint8Array(arrayBuffer));
  4314. return result;
  4315. }
  4316. var _cloneArrayBuffer = cloneArrayBuffer;
  4317. /**
  4318. * Creates a clone of `dataView`.
  4319. *
  4320. * @private
  4321. * @param {Object} dataView The data view to clone.
  4322. * @param {boolean} [isDeep] Specify a deep clone.
  4323. * @returns {Object} Returns the cloned data view.
  4324. */
  4325. function cloneDataView(dataView, isDeep) {
  4326. var buffer = isDeep ? _cloneArrayBuffer(dataView.buffer) : dataView.buffer;
  4327. return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength);
  4328. }
  4329. var _cloneDataView = cloneDataView;
  4330. /** Used to match `RegExp` flags from their coerced string values. */
  4331. var reFlags = /\w*$/;
  4332. /**
  4333. * Creates a clone of `regexp`.
  4334. *
  4335. * @private
  4336. * @param {Object} regexp The regexp to clone.
  4337. * @returns {Object} Returns the cloned regexp.
  4338. */
  4339. function cloneRegExp(regexp) {
  4340. var result = new regexp.constructor(regexp.source, reFlags.exec(regexp));
  4341. result.lastIndex = regexp.lastIndex;
  4342. return result;
  4343. }
  4344. var _cloneRegExp = cloneRegExp;
  4345. /** Used to convert symbols to primitives and strings. */
  4346. var symbolProto$2 = _Symbol ? _Symbol.prototype : undefined,
  4347. symbolValueOf$1 = symbolProto$2 ? symbolProto$2.valueOf : undefined;
  4348. /**
  4349. * Creates a clone of the `symbol` object.
  4350. *
  4351. * @private
  4352. * @param {Object} symbol The symbol object to clone.
  4353. * @returns {Object} Returns the cloned symbol object.
  4354. */
  4355. function cloneSymbol(symbol) {
  4356. return symbolValueOf$1 ? Object(symbolValueOf$1.call(symbol)) : {};
  4357. }
  4358. var _cloneSymbol = cloneSymbol;
  4359. /**
  4360. * Creates a clone of `typedArray`.
  4361. *
  4362. * @private
  4363. * @param {Object} typedArray The typed array to clone.
  4364. * @param {boolean} [isDeep] Specify a deep clone.
  4365. * @returns {Object} Returns the cloned typed array.
  4366. */
  4367. function cloneTypedArray(typedArray, isDeep) {
  4368. var buffer = isDeep ? _cloneArrayBuffer(typedArray.buffer) : typedArray.buffer;
  4369. return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);
  4370. }
  4371. var _cloneTypedArray = cloneTypedArray;
  4372. /** `Object#toString` result references. */
  4373. var boolTag$2 = '[object Boolean]',
  4374. dateTag$2 = '[object Date]',
  4375. mapTag$3 = '[object Map]',
  4376. numberTag$2 = '[object Number]',
  4377. regexpTag$2 = '[object RegExp]',
  4378. setTag$3 = '[object Set]',
  4379. stringTag$2 = '[object String]',
  4380. symbolTag$2 = '[object Symbol]';
  4381. var arrayBufferTag$2 = '[object ArrayBuffer]',
  4382. dataViewTag$2 = '[object DataView]',
  4383. float32Tag$1 = '[object Float32Array]',
  4384. float64Tag$1 = '[object Float64Array]',
  4385. int8Tag$1 = '[object Int8Array]',
  4386. int16Tag$1 = '[object Int16Array]',
  4387. int32Tag$1 = '[object Int32Array]',
  4388. uint8Tag$1 = '[object Uint8Array]',
  4389. uint8ClampedTag$1 = '[object Uint8ClampedArray]',
  4390. uint16Tag$1 = '[object Uint16Array]',
  4391. uint32Tag$1 = '[object Uint32Array]';
  4392. /**
  4393. * Initializes an object clone based on its `toStringTag`.
  4394. *
  4395. * **Note:** This function only supports cloning values with tags of
  4396. * `Boolean`, `Date`, `Error`, `Map`, `Number`, `RegExp`, `Set`, or `String`.
  4397. *
  4398. * @private
  4399. * @param {Object} object The object to clone.
  4400. * @param {string} tag The `toStringTag` of the object to clone.
  4401. * @param {boolean} [isDeep] Specify a deep clone.
  4402. * @returns {Object} Returns the initialized clone.
  4403. */
  4404. function initCloneByTag(object, tag, isDeep) {
  4405. var Ctor = object.constructor;
  4406. switch (tag) {
  4407. case arrayBufferTag$2:
  4408. return _cloneArrayBuffer(object);
  4409. case boolTag$2:
  4410. case dateTag$2:
  4411. return new Ctor(+object);
  4412. case dataViewTag$2:
  4413. return _cloneDataView(object, isDeep);
  4414. case float32Tag$1: case float64Tag$1:
  4415. case int8Tag$1: case int16Tag$1: case int32Tag$1:
  4416. case uint8Tag$1: case uint8ClampedTag$1: case uint16Tag$1: case uint32Tag$1:
  4417. return _cloneTypedArray(object, isDeep);
  4418. case mapTag$3:
  4419. return new Ctor;
  4420. case numberTag$2:
  4421. case stringTag$2:
  4422. return new Ctor(object);
  4423. case regexpTag$2:
  4424. return _cloneRegExp(object);
  4425. case setTag$3:
  4426. return new Ctor;
  4427. case symbolTag$2:
  4428. return _cloneSymbol(object);
  4429. }
  4430. }
  4431. var _initCloneByTag = initCloneByTag;
  4432. /**
  4433. * Initializes an object clone.
  4434. *
  4435. * @private
  4436. * @param {Object} object The object to clone.
  4437. * @returns {Object} Returns the initialized clone.
  4438. */
  4439. function initCloneObject(object) {
  4440. return (typeof object.constructor == 'function' && !_isPrototype(object))
  4441. ? _baseCreate(_getPrototype(object))
  4442. : {};
  4443. }
  4444. var _initCloneObject = initCloneObject;
  4445. /** `Object#toString` result references. */
  4446. var mapTag$2 = '[object Map]';
  4447. /**
  4448. * The base implementation of `_.isMap` without Node.js optimizations.
  4449. *
  4450. * @private
  4451. * @param {*} value The value to check.
  4452. * @returns {boolean} Returns `true` if `value` is a map, else `false`.
  4453. */
  4454. function baseIsMap(value) {
  4455. return isObjectLike_1(value) && _getTag(value) == mapTag$2;
  4456. }
  4457. var _baseIsMap = baseIsMap;
  4458. /* Node.js helper references. */
  4459. var nodeIsMap = _nodeUtil && _nodeUtil.isMap;
  4460. /**
  4461. * Checks if `value` is classified as a `Map` object.
  4462. *
  4463. * @static
  4464. * @memberOf _
  4465. * @since 4.3.0
  4466. * @category Lang
  4467. * @param {*} value The value to check.
  4468. * @returns {boolean} Returns `true` if `value` is a map, else `false`.
  4469. * @example
  4470. *
  4471. * _.isMap(new Map);
  4472. * // => true
  4473. *
  4474. * _.isMap(new WeakMap);
  4475. * // => false
  4476. */
  4477. var isMap = nodeIsMap ? _baseUnary(nodeIsMap) : _baseIsMap;
  4478. var isMap_1 = isMap;
  4479. /** `Object#toString` result references. */
  4480. var setTag$2 = '[object Set]';
  4481. /**
  4482. * The base implementation of `_.isSet` without Node.js optimizations.
  4483. *
  4484. * @private
  4485. * @param {*} value The value to check.
  4486. * @returns {boolean} Returns `true` if `value` is a set, else `false`.
  4487. */
  4488. function baseIsSet(value) {
  4489. return isObjectLike_1(value) && _getTag(value) == setTag$2;
  4490. }
  4491. var _baseIsSet = baseIsSet;
  4492. /* Node.js helper references. */
  4493. var nodeIsSet = _nodeUtil && _nodeUtil.isSet;
  4494. /**
  4495. * Checks if `value` is classified as a `Set` object.
  4496. *
  4497. * @static
  4498. * @memberOf _
  4499. * @since 4.3.0
  4500. * @category Lang
  4501. * @param {*} value The value to check.
  4502. * @returns {boolean} Returns `true` if `value` is a set, else `false`.
  4503. * @example
  4504. *
  4505. * _.isSet(new Set);
  4506. * // => true
  4507. *
  4508. * _.isSet(new WeakSet);
  4509. * // => false
  4510. */
  4511. var isSet = nodeIsSet ? _baseUnary(nodeIsSet) : _baseIsSet;
  4512. var isSet_1 = isSet;
  4513. /** Used to compose bitmasks for cloning. */
  4514. var CLONE_DEEP_FLAG$1 = 1,
  4515. CLONE_FLAT_FLAG = 2,
  4516. CLONE_SYMBOLS_FLAG$1 = 4;
  4517. /** `Object#toString` result references. */
  4518. var argsTag$1 = '[object Arguments]',
  4519. arrayTag$1 = '[object Array]',
  4520. boolTag$1 = '[object Boolean]',
  4521. dateTag$1 = '[object Date]',
  4522. errorTag$2 = '[object Error]',
  4523. funcTag = '[object Function]',
  4524. genTag = '[object GeneratorFunction]',
  4525. mapTag$1 = '[object Map]',
  4526. numberTag$1 = '[object Number]',
  4527. objectTag$2 = '[object Object]',
  4528. regexpTag$1 = '[object RegExp]',
  4529. setTag$1 = '[object Set]',
  4530. stringTag$1 = '[object String]',
  4531. symbolTag$1 = '[object Symbol]',
  4532. weakMapTag$1 = '[object WeakMap]';
  4533. var arrayBufferTag$1 = '[object ArrayBuffer]',
  4534. dataViewTag$1 = '[object DataView]',
  4535. float32Tag = '[object Float32Array]',
  4536. float64Tag = '[object Float64Array]',
  4537. int8Tag = '[object Int8Array]',
  4538. int16Tag = '[object Int16Array]',
  4539. int32Tag = '[object Int32Array]',
  4540. uint8Tag = '[object Uint8Array]',
  4541. uint8ClampedTag = '[object Uint8ClampedArray]',
  4542. uint16Tag = '[object Uint16Array]',
  4543. uint32Tag = '[object Uint32Array]';
  4544. /** Used to identify `toStringTag` values supported by `_.clone`. */
  4545. var cloneableTags = {};
  4546. cloneableTags[argsTag$1] = cloneableTags[arrayTag$1] =
  4547. cloneableTags[arrayBufferTag$1] = cloneableTags[dataViewTag$1] =
  4548. cloneableTags[boolTag$1] = cloneableTags[dateTag$1] =
  4549. cloneableTags[float32Tag] = cloneableTags[float64Tag] =
  4550. cloneableTags[int8Tag] = cloneableTags[int16Tag] =
  4551. cloneableTags[int32Tag] = cloneableTags[mapTag$1] =
  4552. cloneableTags[numberTag$1] = cloneableTags[objectTag$2] =
  4553. cloneableTags[regexpTag$1] = cloneableTags[setTag$1] =
  4554. cloneableTags[stringTag$1] = cloneableTags[symbolTag$1] =
  4555. cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =
  4556. cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
  4557. cloneableTags[errorTag$2] = cloneableTags[funcTag] =
  4558. cloneableTags[weakMapTag$1] = false;
  4559. /**
  4560. * The base implementation of `_.clone` and `_.cloneDeep` which tracks
  4561. * traversed objects.
  4562. *
  4563. * @private
  4564. * @param {*} value The value to clone.
  4565. * @param {boolean} bitmask The bitmask flags.
  4566. * 1 - Deep clone
  4567. * 2 - Flatten inherited properties
  4568. * 4 - Clone symbols
  4569. * @param {Function} [customizer] The function to customize cloning.
  4570. * @param {string} [key] The key of `value`.
  4571. * @param {Object} [object] The parent object of `value`.
  4572. * @param {Object} [stack] Tracks traversed objects and their clone counterparts.
  4573. * @returns {*} Returns the cloned value.
  4574. */
  4575. function baseClone(value, bitmask, customizer, key, object, stack) {
  4576. var result,
  4577. isDeep = bitmask & CLONE_DEEP_FLAG$1,
  4578. isFlat = bitmask & CLONE_FLAT_FLAG,
  4579. isFull = bitmask & CLONE_SYMBOLS_FLAG$1;
  4580. if (customizer) {
  4581. result = object ? customizer(value, key, object, stack) : customizer(value);
  4582. }
  4583. if (result !== undefined) {
  4584. return result;
  4585. }
  4586. if (!isObject_1(value)) {
  4587. return value;
  4588. }
  4589. var isArr = isArray_1(value);
  4590. if (isArr) {
  4591. result = _initCloneArray(value);
  4592. if (!isDeep) {
  4593. return _copyArray(value, result);
  4594. }
  4595. } else {
  4596. var tag = _getTag(value),
  4597. isFunc = tag == funcTag || tag == genTag;
  4598. if (isBuffer_1(value)) {
  4599. return _cloneBuffer(value, isDeep);
  4600. }
  4601. if (tag == objectTag$2 || tag == argsTag$1 || (isFunc && !object)) {
  4602. result = (isFlat || isFunc) ? {} : _initCloneObject(value);
  4603. if (!isDeep) {
  4604. return isFlat
  4605. ? _copySymbolsIn(value, _baseAssignIn(result, value))
  4606. : _copySymbols(value, _baseAssign(result, value));
  4607. }
  4608. } else {
  4609. if (!cloneableTags[tag]) {
  4610. return object ? value : {};
  4611. }
  4612. result = _initCloneByTag(value, tag, isDeep);
  4613. }
  4614. }
  4615. // Check for circular references and return its corresponding clone.
  4616. stack || (stack = new _Stack);
  4617. var stacked = stack.get(value);
  4618. if (stacked) {
  4619. return stacked;
  4620. }
  4621. stack.set(value, result);
  4622. if (isSet_1(value)) {
  4623. value.forEach(function(subValue) {
  4624. result.add(baseClone(subValue, bitmask, customizer, subValue, value, stack));
  4625. });
  4626. } else if (isMap_1(value)) {
  4627. value.forEach(function(subValue, key) {
  4628. result.set(key, baseClone(subValue, bitmask, customizer, key, value, stack));
  4629. });
  4630. }
  4631. var keysFunc = isFull
  4632. ? (isFlat ? _getAllKeysIn : _getAllKeys)
  4633. : (isFlat ? keysIn_1 : keys_1);
  4634. var props = isArr ? undefined : keysFunc(value);
  4635. _arrayEach(props || value, function(subValue, key) {
  4636. if (props) {
  4637. key = subValue;
  4638. subValue = value[key];
  4639. }
  4640. // Recursively populate clone (susceptible to call stack limits).
  4641. _assignValue(result, key, baseClone(subValue, bitmask, customizer, key, value, stack));
  4642. });
  4643. return result;
  4644. }
  4645. var _baseClone = baseClone;
  4646. /** Used to compose bitmasks for cloning. */
  4647. var CLONE_SYMBOLS_FLAG = 4;
  4648. /**
  4649. * Creates a shallow clone of `value`.
  4650. *
  4651. * **Note:** This method is loosely based on the
  4652. * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
  4653. * and supports cloning arrays, array buffers, booleans, date objects, maps,
  4654. * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
  4655. * arrays. The own enumerable properties of `arguments` objects are cloned
  4656. * as plain objects. An empty object is returned for uncloneable values such
  4657. * as error objects, functions, DOM nodes, and WeakMaps.
  4658. *
  4659. * @static
  4660. * @memberOf _
  4661. * @since 0.1.0
  4662. * @category Lang
  4663. * @param {*} value The value to clone.
  4664. * @returns {*} Returns the cloned value.
  4665. * @see _.cloneDeep
  4666. * @example
  4667. *
  4668. * var objects = [{ 'a': 1 }, { 'b': 2 }];
  4669. *
  4670. * var shallow = _.clone(objects);
  4671. * console.log(shallow[0] === objects[0]);
  4672. * // => true
  4673. */
  4674. function clone(value) {
  4675. return _baseClone(value, CLONE_SYMBOLS_FLAG);
  4676. }
  4677. var clone_1 = clone;
  4678. /** `Object#toString` result references. */
  4679. var objectTag$1 = '[object Object]';
  4680. /** Used for built-in method references. */
  4681. var funcProto = Function.prototype,
  4682. objectProto$2 = Object.prototype;
  4683. /** Used to resolve the decompiled source of functions. */
  4684. var funcToString = funcProto.toString;
  4685. /** Used to check objects for own properties. */
  4686. var hasOwnProperty$2 = objectProto$2.hasOwnProperty;
  4687. /** Used to infer the `Object` constructor. */
  4688. var objectCtorString = funcToString.call(Object);
  4689. /**
  4690. * Checks if `value` is a plain object, that is, an object created by the
  4691. * `Object` constructor or one with a `[[Prototype]]` of `null`.
  4692. *
  4693. * @static
  4694. * @memberOf _
  4695. * @since 0.8.0
  4696. * @category Lang
  4697. * @param {*} value The value to check.
  4698. * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
  4699. * @example
  4700. *
  4701. * function Foo() {
  4702. * this.a = 1;
  4703. * }
  4704. *
  4705. * _.isPlainObject(new Foo);
  4706. * // => false
  4707. *
  4708. * _.isPlainObject([1, 2, 3]);
  4709. * // => false
  4710. *
  4711. * _.isPlainObject({ 'x': 0, 'y': 0 });
  4712. * // => true
  4713. *
  4714. * _.isPlainObject(Object.create(null));
  4715. * // => true
  4716. */
  4717. function isPlainObject(value) {
  4718. if (!isObjectLike_1(value) || _baseGetTag(value) != objectTag$1) {
  4719. return false;
  4720. }
  4721. var proto = _getPrototype(value);
  4722. if (proto === null) {
  4723. return true;
  4724. }
  4725. var Ctor = hasOwnProperty$2.call(proto, 'constructor') && proto.constructor;
  4726. return typeof Ctor == 'function' && Ctor instanceof Ctor &&
  4727. funcToString.call(Ctor) == objectCtorString;
  4728. }
  4729. var isPlainObject_1 = isPlainObject;
  4730. /** `Object#toString` result references. */
  4731. var domExcTag = '[object DOMException]',
  4732. errorTag$1 = '[object Error]';
  4733. /**
  4734. * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
  4735. * `SyntaxError`, `TypeError`, or `URIError` object.
  4736. *
  4737. * @static
  4738. * @memberOf _
  4739. * @since 3.0.0
  4740. * @category Lang
  4741. * @param {*} value The value to check.
  4742. * @returns {boolean} Returns `true` if `value` is an error object, else `false`.
  4743. * @example
  4744. *
  4745. * _.isError(new Error);
  4746. * // => true
  4747. *
  4748. * _.isError(Error);
  4749. * // => false
  4750. */
  4751. function isError(value) {
  4752. if (!isObjectLike_1(value)) {
  4753. return false;
  4754. }
  4755. var tag = _baseGetTag(value);
  4756. return tag == errorTag$1 || tag == domExcTag ||
  4757. (typeof value.message == 'string' && typeof value.name == 'string' && !isPlainObject_1(value));
  4758. }
  4759. var isError_1 = isError;
  4760. /** `Object#toString` result references. */
  4761. var weakMapTag = '[object WeakMap]';
  4762. /**
  4763. * Checks if `value` is classified as a `WeakMap` object.
  4764. *
  4765. * @static
  4766. * @memberOf _
  4767. * @since 4.3.0
  4768. * @category Lang
  4769. * @param {*} value The value to check.
  4770. * @returns {boolean} Returns `true` if `value` is a weak map, else `false`.
  4771. * @example
  4772. *
  4773. * _.isWeakMap(new WeakMap);
  4774. * // => true
  4775. *
  4776. * _.isWeakMap(new Map);
  4777. * // => false
  4778. */
  4779. function isWeakMap(value) {
  4780. return isObjectLike_1(value) && _getTag(value) == weakMapTag;
  4781. }
  4782. var isWeakMap_1 = isWeakMap;
  4783. /** Used to stand-in for `undefined` hash values. */
  4784. var HASH_UNDEFINED = '__lodash_hash_undefined__';
  4785. /**
  4786. * Adds `value` to the array cache.
  4787. *
  4788. * @private
  4789. * @name add
  4790. * @memberOf SetCache
  4791. * @alias push
  4792. * @param {*} value The value to cache.
  4793. * @returns {Object} Returns the cache instance.
  4794. */
  4795. function setCacheAdd(value) {
  4796. this.__data__.set(value, HASH_UNDEFINED);
  4797. return this;
  4798. }
  4799. var _setCacheAdd = setCacheAdd;
  4800. /**
  4801. * Checks if `value` is in the array cache.
  4802. *
  4803. * @private
  4804. * @name has
  4805. * @memberOf SetCache
  4806. * @param {*} value The value to search for.
  4807. * @returns {number} Returns `true` if `value` is found, else `false`.
  4808. */
  4809. function setCacheHas(value) {
  4810. return this.__data__.has(value);
  4811. }
  4812. var _setCacheHas = setCacheHas;
  4813. /**
  4814. *
  4815. * Creates an array cache object to store unique values.
  4816. *
  4817. * @private
  4818. * @constructor
  4819. * @param {Array} [values] The values to cache.
  4820. */
  4821. function SetCache(values) {
  4822. var index = -1,
  4823. length = values == null ? 0 : values.length;
  4824. this.__data__ = new _MapCache;
  4825. while (++index < length) {
  4826. this.add(values[index]);
  4827. }
  4828. }
  4829. // Add methods to `SetCache`.
  4830. SetCache.prototype.add = SetCache.prototype.push = _setCacheAdd;
  4831. SetCache.prototype.has = _setCacheHas;
  4832. var _SetCache = SetCache;
  4833. /**
  4834. * A specialized version of `_.some` for arrays without support for iteratee
  4835. * shorthands.
  4836. *
  4837. * @private
  4838. * @param {Array} [array] The array to iterate over.
  4839. * @param {Function} predicate The function invoked per iteration.
  4840. * @returns {boolean} Returns `true` if any element passes the predicate check,
  4841. * else `false`.
  4842. */
  4843. function arraySome(array, predicate) {
  4844. var index = -1,
  4845. length = array == null ? 0 : array.length;
  4846. while (++index < length) {
  4847. if (predicate(array[index], index, array)) {
  4848. return true;
  4849. }
  4850. }
  4851. return false;
  4852. }
  4853. var _arraySome = arraySome;
  4854. /**
  4855. * Checks if a `cache` value for `key` exists.
  4856. *
  4857. * @private
  4858. * @param {Object} cache The cache to query.
  4859. * @param {string} key The key of the entry to check.
  4860. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  4861. */
  4862. function cacheHas(cache, key) {
  4863. return cache.has(key);
  4864. }
  4865. var _cacheHas = cacheHas;
  4866. /** Used to compose bitmasks for value comparisons. */
  4867. var COMPARE_PARTIAL_FLAG$5 = 1,
  4868. COMPARE_UNORDERED_FLAG$3 = 2;
  4869. /**
  4870. * A specialized version of `baseIsEqualDeep` for arrays with support for
  4871. * partial deep comparisons.
  4872. *
  4873. * @private
  4874. * @param {Array} array The array to compare.
  4875. * @param {Array} other The other array to compare.
  4876. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  4877. * @param {Function} customizer The function to customize comparisons.
  4878. * @param {Function} equalFunc The function to determine equivalents of values.
  4879. * @param {Object} stack Tracks traversed `array` and `other` objects.
  4880. * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
  4881. */
  4882. function equalArrays(array, other, bitmask, customizer, equalFunc, stack) {
  4883. var isPartial = bitmask & COMPARE_PARTIAL_FLAG$5,
  4884. arrLength = array.length,
  4885. othLength = other.length;
  4886. if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
  4887. return false;
  4888. }
  4889. // Check that cyclic values are equal.
  4890. var arrStacked = stack.get(array);
  4891. var othStacked = stack.get(other);
  4892. if (arrStacked && othStacked) {
  4893. return arrStacked == other && othStacked == array;
  4894. }
  4895. var index = -1,
  4896. result = true,
  4897. seen = (bitmask & COMPARE_UNORDERED_FLAG$3) ? new _SetCache : undefined;
  4898. stack.set(array, other);
  4899. stack.set(other, array);
  4900. // Ignore non-index properties.
  4901. while (++index < arrLength) {
  4902. var arrValue = array[index],
  4903. othValue = other[index];
  4904. if (customizer) {
  4905. var compared = isPartial
  4906. ? customizer(othValue, arrValue, index, other, array, stack)
  4907. : customizer(arrValue, othValue, index, array, other, stack);
  4908. }
  4909. if (compared !== undefined) {
  4910. if (compared) {
  4911. continue;
  4912. }
  4913. result = false;
  4914. break;
  4915. }
  4916. // Recursively compare arrays (susceptible to call stack limits).
  4917. if (seen) {
  4918. if (!_arraySome(other, function(othValue, othIndex) {
  4919. if (!_cacheHas(seen, othIndex) &&
  4920. (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
  4921. return seen.push(othIndex);
  4922. }
  4923. })) {
  4924. result = false;
  4925. break;
  4926. }
  4927. } else if (!(
  4928. arrValue === othValue ||
  4929. equalFunc(arrValue, othValue, bitmask, customizer, stack)
  4930. )) {
  4931. result = false;
  4932. break;
  4933. }
  4934. }
  4935. stack['delete'](array);
  4936. stack['delete'](other);
  4937. return result;
  4938. }
  4939. var _equalArrays = equalArrays;
  4940. /**
  4941. * Converts `map` to its key-value pairs.
  4942. *
  4943. * @private
  4944. * @param {Object} map The map to convert.
  4945. * @returns {Array} Returns the key-value pairs.
  4946. */
  4947. function mapToArray(map) {
  4948. var index = -1,
  4949. result = Array(map.size);
  4950. map.forEach(function(value, key) {
  4951. result[++index] = [key, value];
  4952. });
  4953. return result;
  4954. }
  4955. var _mapToArray = mapToArray;
  4956. /**
  4957. * Converts `set` to an array of its values.
  4958. *
  4959. * @private
  4960. * @param {Object} set The set to convert.
  4961. * @returns {Array} Returns the values.
  4962. */
  4963. function setToArray(set) {
  4964. var index = -1,
  4965. result = Array(set.size);
  4966. set.forEach(function(value) {
  4967. result[++index] = value;
  4968. });
  4969. return result;
  4970. }
  4971. var _setToArray = setToArray;
  4972. /** Used to compose bitmasks for value comparisons. */
  4973. var COMPARE_PARTIAL_FLAG$4 = 1,
  4974. COMPARE_UNORDERED_FLAG$2 = 2;
  4975. /** `Object#toString` result references. */
  4976. var boolTag = '[object Boolean]',
  4977. dateTag = '[object Date]',
  4978. errorTag = '[object Error]',
  4979. mapTag = '[object Map]',
  4980. numberTag = '[object Number]',
  4981. regexpTag = '[object RegExp]',
  4982. setTag = '[object Set]',
  4983. stringTag = '[object String]',
  4984. symbolTag = '[object Symbol]';
  4985. var arrayBufferTag = '[object ArrayBuffer]',
  4986. dataViewTag = '[object DataView]';
  4987. /** Used to convert symbols to primitives and strings. */
  4988. var symbolProto$1 = _Symbol ? _Symbol.prototype : undefined,
  4989. symbolValueOf = symbolProto$1 ? symbolProto$1.valueOf : undefined;
  4990. /**
  4991. * A specialized version of `baseIsEqualDeep` for comparing objects of
  4992. * the same `toStringTag`.
  4993. *
  4994. * **Note:** This function only supports comparing values with tags of
  4995. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  4996. *
  4997. * @private
  4998. * @param {Object} object The object to compare.
  4999. * @param {Object} other The other object to compare.
  5000. * @param {string} tag The `toStringTag` of the objects to compare.
  5001. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  5002. * @param {Function} customizer The function to customize comparisons.
  5003. * @param {Function} equalFunc The function to determine equivalents of values.
  5004. * @param {Object} stack Tracks traversed `object` and `other` objects.
  5005. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  5006. */
  5007. function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) {
  5008. switch (tag) {
  5009. case dataViewTag:
  5010. if ((object.byteLength != other.byteLength) ||
  5011. (object.byteOffset != other.byteOffset)) {
  5012. return false;
  5013. }
  5014. object = object.buffer;
  5015. other = other.buffer;
  5016. case arrayBufferTag:
  5017. if ((object.byteLength != other.byteLength) ||
  5018. !equalFunc(new _Uint8Array(object), new _Uint8Array(other))) {
  5019. return false;
  5020. }
  5021. return true;
  5022. case boolTag:
  5023. case dateTag:
  5024. case numberTag:
  5025. // Coerce booleans to `1` or `0` and dates to milliseconds.
  5026. // Invalid dates are coerced to `NaN`.
  5027. return eq_1(+object, +other);
  5028. case errorTag:
  5029. return object.name == other.name && object.message == other.message;
  5030. case regexpTag:
  5031. case stringTag:
  5032. // Coerce regexes to strings and treat strings, primitives and objects,
  5033. // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
  5034. // for more details.
  5035. return object == (other + '');
  5036. case mapTag:
  5037. var convert = _mapToArray;
  5038. case setTag:
  5039. var isPartial = bitmask & COMPARE_PARTIAL_FLAG$4;
  5040. convert || (convert = _setToArray);
  5041. if (object.size != other.size && !isPartial) {
  5042. return false;
  5043. }
  5044. // Assume cyclic values are equal.
  5045. var stacked = stack.get(object);
  5046. if (stacked) {
  5047. return stacked == other;
  5048. }
  5049. bitmask |= COMPARE_UNORDERED_FLAG$2;
  5050. // Recursively compare objects (susceptible to call stack limits).
  5051. stack.set(object, other);
  5052. var result = _equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack);
  5053. stack['delete'](object);
  5054. return result;
  5055. case symbolTag:
  5056. if (symbolValueOf) {
  5057. return symbolValueOf.call(object) == symbolValueOf.call(other);
  5058. }
  5059. }
  5060. return false;
  5061. }
  5062. var _equalByTag = equalByTag;
  5063. /** Used to compose bitmasks for value comparisons. */
  5064. var COMPARE_PARTIAL_FLAG$3 = 1;
  5065. /** Used for built-in method references. */
  5066. var objectProto$1 = Object.prototype;
  5067. /** Used to check objects for own properties. */
  5068. var hasOwnProperty$1 = objectProto$1.hasOwnProperty;
  5069. /**
  5070. * A specialized version of `baseIsEqualDeep` for objects with support for
  5071. * partial deep comparisons.
  5072. *
  5073. * @private
  5074. * @param {Object} object The object to compare.
  5075. * @param {Object} other The other object to compare.
  5076. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  5077. * @param {Function} customizer The function to customize comparisons.
  5078. * @param {Function} equalFunc The function to determine equivalents of values.
  5079. * @param {Object} stack Tracks traversed `object` and `other` objects.
  5080. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  5081. */
  5082. function equalObjects(object, other, bitmask, customizer, equalFunc, stack) {
  5083. var isPartial = bitmask & COMPARE_PARTIAL_FLAG$3,
  5084. objProps = _getAllKeys(object),
  5085. objLength = objProps.length,
  5086. othProps = _getAllKeys(other),
  5087. othLength = othProps.length;
  5088. if (objLength != othLength && !isPartial) {
  5089. return false;
  5090. }
  5091. var index = objLength;
  5092. while (index--) {
  5093. var key = objProps[index];
  5094. if (!(isPartial ? key in other : hasOwnProperty$1.call(other, key))) {
  5095. return false;
  5096. }
  5097. }
  5098. // Check that cyclic values are equal.
  5099. var objStacked = stack.get(object);
  5100. var othStacked = stack.get(other);
  5101. if (objStacked && othStacked) {
  5102. return objStacked == other && othStacked == object;
  5103. }
  5104. var result = true;
  5105. stack.set(object, other);
  5106. stack.set(other, object);
  5107. var skipCtor = isPartial;
  5108. while (++index < objLength) {
  5109. key = objProps[index];
  5110. var objValue = object[key],
  5111. othValue = other[key];
  5112. if (customizer) {
  5113. var compared = isPartial
  5114. ? customizer(othValue, objValue, key, other, object, stack)
  5115. : customizer(objValue, othValue, key, object, other, stack);
  5116. }
  5117. // Recursively compare objects (susceptible to call stack limits).
  5118. if (!(compared === undefined
  5119. ? (objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack))
  5120. : compared
  5121. )) {
  5122. result = false;
  5123. break;
  5124. }
  5125. skipCtor || (skipCtor = key == 'constructor');
  5126. }
  5127. if (result && !skipCtor) {
  5128. var objCtor = object.constructor,
  5129. othCtor = other.constructor;
  5130. // Non `Object` object instances with different constructors are not equal.
  5131. if (objCtor != othCtor &&
  5132. ('constructor' in object && 'constructor' in other) &&
  5133. !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
  5134. typeof othCtor == 'function' && othCtor instanceof othCtor)) {
  5135. result = false;
  5136. }
  5137. }
  5138. stack['delete'](object);
  5139. stack['delete'](other);
  5140. return result;
  5141. }
  5142. var _equalObjects = equalObjects;
  5143. /** Used to compose bitmasks for value comparisons. */
  5144. var COMPARE_PARTIAL_FLAG$2 = 1;
  5145. /** `Object#toString` result references. */
  5146. var argsTag = '[object Arguments]',
  5147. arrayTag = '[object Array]',
  5148. objectTag = '[object Object]';
  5149. /** Used for built-in method references. */
  5150. var objectProto = Object.prototype;
  5151. /** Used to check objects for own properties. */
  5152. var hasOwnProperty = objectProto.hasOwnProperty;
  5153. /**
  5154. * A specialized version of `baseIsEqual` for arrays and objects which performs
  5155. * deep comparisons and tracks traversed objects enabling objects with circular
  5156. * references to be compared.
  5157. *
  5158. * @private
  5159. * @param {Object} object The object to compare.
  5160. * @param {Object} other The other object to compare.
  5161. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  5162. * @param {Function} customizer The function to customize comparisons.
  5163. * @param {Function} equalFunc The function to determine equivalents of values.
  5164. * @param {Object} [stack] Tracks traversed `object` and `other` objects.
  5165. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  5166. */
  5167. function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) {
  5168. var objIsArr = isArray_1(object),
  5169. othIsArr = isArray_1(other),
  5170. objTag = objIsArr ? arrayTag : _getTag(object),
  5171. othTag = othIsArr ? arrayTag : _getTag(other);
  5172. objTag = objTag == argsTag ? objectTag : objTag;
  5173. othTag = othTag == argsTag ? objectTag : othTag;
  5174. var objIsObj = objTag == objectTag,
  5175. othIsObj = othTag == objectTag,
  5176. isSameTag = objTag == othTag;
  5177. if (isSameTag && isBuffer_1(object)) {
  5178. if (!isBuffer_1(other)) {
  5179. return false;
  5180. }
  5181. objIsArr = true;
  5182. objIsObj = false;
  5183. }
  5184. if (isSameTag && !objIsObj) {
  5185. stack || (stack = new _Stack);
  5186. return (objIsArr || isTypedArray_1(object))
  5187. ? _equalArrays(object, other, bitmask, customizer, equalFunc, stack)
  5188. : _equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack);
  5189. }
  5190. if (!(bitmask & COMPARE_PARTIAL_FLAG$2)) {
  5191. var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
  5192. othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
  5193. if (objIsWrapped || othIsWrapped) {
  5194. var objUnwrapped = objIsWrapped ? object.value() : object,
  5195. othUnwrapped = othIsWrapped ? other.value() : other;
  5196. stack || (stack = new _Stack);
  5197. return equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack);
  5198. }
  5199. }
  5200. if (!isSameTag) {
  5201. return false;
  5202. }
  5203. stack || (stack = new _Stack);
  5204. return _equalObjects(object, other, bitmask, customizer, equalFunc, stack);
  5205. }
  5206. var _baseIsEqualDeep = baseIsEqualDeep;
  5207. /**
  5208. * The base implementation of `_.isEqual` which supports partial comparisons
  5209. * and tracks traversed objects.
  5210. *
  5211. * @private
  5212. * @param {*} value The value to compare.
  5213. * @param {*} other The other value to compare.
  5214. * @param {boolean} bitmask The bitmask flags.
  5215. * 1 - Unordered comparison
  5216. * 2 - Partial comparison
  5217. * @param {Function} [customizer] The function to customize comparisons.
  5218. * @param {Object} [stack] Tracks traversed `value` and `other` objects.
  5219. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  5220. */
  5221. function baseIsEqual(value, other, bitmask, customizer, stack) {
  5222. if (value === other) {
  5223. return true;
  5224. }
  5225. if (value == null || other == null || (!isObjectLike_1(value) && !isObjectLike_1(other))) {
  5226. return value !== value && other !== other;
  5227. }
  5228. return _baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack);
  5229. }
  5230. var _baseIsEqual = baseIsEqual;
  5231. /** Used to compose bitmasks for value comparisons. */
  5232. var COMPARE_PARTIAL_FLAG$1 = 1,
  5233. COMPARE_UNORDERED_FLAG$1 = 2;
  5234. /**
  5235. * The base implementation of `_.isMatch` without support for iteratee shorthands.
  5236. *
  5237. * @private
  5238. * @param {Object} object The object to inspect.
  5239. * @param {Object} source The object of property values to match.
  5240. * @param {Array} matchData The property names, values, and compare flags to match.
  5241. * @param {Function} [customizer] The function to customize comparisons.
  5242. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  5243. */
  5244. function baseIsMatch(object, source, matchData, customizer) {
  5245. var index = matchData.length,
  5246. length = index,
  5247. noCustomizer = !customizer;
  5248. if (object == null) {
  5249. return !length;
  5250. }
  5251. object = Object(object);
  5252. while (index--) {
  5253. var data = matchData[index];
  5254. if ((noCustomizer && data[2])
  5255. ? data[1] !== object[data[0]]
  5256. : !(data[0] in object)
  5257. ) {
  5258. return false;
  5259. }
  5260. }
  5261. while (++index < length) {
  5262. data = matchData[index];
  5263. var key = data[0],
  5264. objValue = object[key],
  5265. srcValue = data[1];
  5266. if (noCustomizer && data[2]) {
  5267. if (objValue === undefined && !(key in object)) {
  5268. return false;
  5269. }
  5270. } else {
  5271. var stack = new _Stack;
  5272. if (customizer) {
  5273. var result = customizer(objValue, srcValue, key, object, source, stack);
  5274. }
  5275. if (!(result === undefined
  5276. ? _baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG$1 | COMPARE_UNORDERED_FLAG$1, customizer, stack)
  5277. : result
  5278. )) {
  5279. return false;
  5280. }
  5281. }
  5282. }
  5283. return true;
  5284. }
  5285. var _baseIsMatch = baseIsMatch;
  5286. /**
  5287. * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
  5288. *
  5289. * @private
  5290. * @param {*} value The value to check.
  5291. * @returns {boolean} Returns `true` if `value` if suitable for strict
  5292. * equality comparisons, else `false`.
  5293. */
  5294. function isStrictComparable(value) {
  5295. return value === value && !isObject_1(value);
  5296. }
  5297. var _isStrictComparable = isStrictComparable;
  5298. /**
  5299. * Gets the property names, values, and compare flags of `object`.
  5300. *
  5301. * @private
  5302. * @param {Object} object The object to query.
  5303. * @returns {Array} Returns the match data of `object`.
  5304. */
  5305. function getMatchData(object) {
  5306. var result = keys_1(object),
  5307. length = result.length;
  5308. while (length--) {
  5309. var key = result[length],
  5310. value = object[key];
  5311. result[length] = [key, value, _isStrictComparable(value)];
  5312. }
  5313. return result;
  5314. }
  5315. var _getMatchData = getMatchData;
  5316. /**
  5317. * A specialized version of `matchesProperty` for source values suitable
  5318. * for strict equality comparisons, i.e. `===`.
  5319. *
  5320. * @private
  5321. * @param {string} key The key of the property to get.
  5322. * @param {*} srcValue The value to match.
  5323. * @returns {Function} Returns the new spec function.
  5324. */
  5325. function matchesStrictComparable(key, srcValue) {
  5326. return function(object) {
  5327. if (object == null) {
  5328. return false;
  5329. }
  5330. return object[key] === srcValue &&
  5331. (srcValue !== undefined || (key in Object(object)));
  5332. };
  5333. }
  5334. var _matchesStrictComparable = matchesStrictComparable;
  5335. /**
  5336. * The base implementation of `_.matches` which doesn't clone `source`.
  5337. *
  5338. * @private
  5339. * @param {Object} source The object of property values to match.
  5340. * @returns {Function} Returns the new spec function.
  5341. */
  5342. function baseMatches(source) {
  5343. var matchData = _getMatchData(source);
  5344. if (matchData.length == 1 && matchData[0][2]) {
  5345. return _matchesStrictComparable(matchData[0][0], matchData[0][1]);
  5346. }
  5347. return function(object) {
  5348. return object === source || _baseIsMatch(object, source, matchData);
  5349. };
  5350. }
  5351. var _baseMatches = baseMatches;
  5352. /** Used to match property names within property paths. */
  5353. var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
  5354. reIsPlainProp = /^\w*$/;
  5355. /**
  5356. * Checks if `value` is a property name and not a property path.
  5357. *
  5358. * @private
  5359. * @param {*} value The value to check.
  5360. * @param {Object} [object] The object to query keys on.
  5361. * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
  5362. */
  5363. function isKey(value, object) {
  5364. if (isArray_1(value)) {
  5365. return false;
  5366. }
  5367. var type = typeof value;
  5368. if (type == 'number' || type == 'symbol' || type == 'boolean' ||
  5369. value == null || isSymbol_1(value)) {
  5370. return true;
  5371. }
  5372. return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
  5373. (object != null && value in Object(object));
  5374. }
  5375. var _isKey = isKey;
  5376. /** Error message constants. */
  5377. var FUNC_ERROR_TEXT = 'Expected a function';
  5378. /**
  5379. * Creates a function that memoizes the result of `func`. If `resolver` is
  5380. * provided, it determines the cache key for storing the result based on the
  5381. * arguments provided to the memoized function. By default, the first argument
  5382. * provided to the memoized function is used as the map cache key. The `func`
  5383. * is invoked with the `this` binding of the memoized function.
  5384. *
  5385. * **Note:** The cache is exposed as the `cache` property on the memoized
  5386. * function. Its creation may be customized by replacing the `_.memoize.Cache`
  5387. * constructor with one whose instances implement the
  5388. * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
  5389. * method interface of `clear`, `delete`, `get`, `has`, and `set`.
  5390. *
  5391. * @static
  5392. * @memberOf _
  5393. * @since 0.1.0
  5394. * @category Function
  5395. * @param {Function} func The function to have its output memoized.
  5396. * @param {Function} [resolver] The function to resolve the cache key.
  5397. * @returns {Function} Returns the new memoized function.
  5398. * @example
  5399. *
  5400. * var object = { 'a': 1, 'b': 2 };
  5401. * var other = { 'c': 3, 'd': 4 };
  5402. *
  5403. * var values = _.memoize(_.values);
  5404. * values(object);
  5405. * // => [1, 2]
  5406. *
  5407. * values(other);
  5408. * // => [3, 4]
  5409. *
  5410. * object.a = 2;
  5411. * values(object);
  5412. * // => [1, 2]
  5413. *
  5414. * // Modify the result cache.
  5415. * values.cache.set(object, ['a', 'b']);
  5416. * values(object);
  5417. * // => ['a', 'b']
  5418. *
  5419. * // Replace `_.memoize.Cache`.
  5420. * _.memoize.Cache = WeakMap;
  5421. */
  5422. function memoize(func, resolver) {
  5423. if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) {
  5424. throw new TypeError(FUNC_ERROR_TEXT);
  5425. }
  5426. var memoized = function() {
  5427. var args = arguments,
  5428. key = resolver ? resolver.apply(this, args) : args[0],
  5429. cache = memoized.cache;
  5430. if (cache.has(key)) {
  5431. return cache.get(key);
  5432. }
  5433. var result = func.apply(this, args);
  5434. memoized.cache = cache.set(key, result) || cache;
  5435. return result;
  5436. };
  5437. memoized.cache = new (memoize.Cache || _MapCache);
  5438. return memoized;
  5439. }
  5440. // Expose `MapCache`.
  5441. memoize.Cache = _MapCache;
  5442. var memoize_1 = memoize;
  5443. /** Used as the maximum memoize cache size. */
  5444. var MAX_MEMOIZE_SIZE = 500;
  5445. /**
  5446. * A specialized version of `_.memoize` which clears the memoized function's
  5447. * cache when it exceeds `MAX_MEMOIZE_SIZE`.
  5448. *
  5449. * @private
  5450. * @param {Function} func The function to have its output memoized.
  5451. * @returns {Function} Returns the new memoized function.
  5452. */
  5453. function memoizeCapped(func) {
  5454. var result = memoize_1(func, function(key) {
  5455. if (cache.size === MAX_MEMOIZE_SIZE) {
  5456. cache.clear();
  5457. }
  5458. return key;
  5459. });
  5460. var cache = result.cache;
  5461. return result;
  5462. }
  5463. var _memoizeCapped = memoizeCapped;
  5464. /** Used to match property names within property paths. */
  5465. var rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
  5466. /** Used to match backslashes in property paths. */
  5467. var reEscapeChar = /\\(\\)?/g;
  5468. /**
  5469. * Converts `string` to a property path array.
  5470. *
  5471. * @private
  5472. * @param {string} string The string to convert.
  5473. * @returns {Array} Returns the property path array.
  5474. */
  5475. var stringToPath = _memoizeCapped(function(string) {
  5476. var result = [];
  5477. if (string.charCodeAt(0) === 46 /* . */) {
  5478. result.push('');
  5479. }
  5480. string.replace(rePropName, function(match, number, quote, subString) {
  5481. result.push(quote ? subString.replace(reEscapeChar, '$1') : (number || match));
  5482. });
  5483. return result;
  5484. });
  5485. var _stringToPath = stringToPath;
  5486. /**
  5487. * A specialized version of `_.map` for arrays without support for iteratee
  5488. * shorthands.
  5489. *
  5490. * @private
  5491. * @param {Array} [array] The array to iterate over.
  5492. * @param {Function} iteratee The function invoked per iteration.
  5493. * @returns {Array} Returns the new mapped array.
  5494. */
  5495. function arrayMap(array, iteratee) {
  5496. var index = -1,
  5497. length = array == null ? 0 : array.length,
  5498. result = Array(length);
  5499. while (++index < length) {
  5500. result[index] = iteratee(array[index], index, array);
  5501. }
  5502. return result;
  5503. }
  5504. var _arrayMap = arrayMap;
  5505. /** Used as references for various `Number` constants. */
  5506. var INFINITY$1 = 1 / 0;
  5507. /** Used to convert symbols to primitives and strings. */
  5508. var symbolProto = _Symbol ? _Symbol.prototype : undefined,
  5509. symbolToString = symbolProto ? symbolProto.toString : undefined;
  5510. /**
  5511. * The base implementation of `_.toString` which doesn't convert nullish
  5512. * values to empty strings.
  5513. *
  5514. * @private
  5515. * @param {*} value The value to process.
  5516. * @returns {string} Returns the string.
  5517. */
  5518. function baseToString(value) {
  5519. // Exit early for strings to avoid a performance hit in some environments.
  5520. if (typeof value == 'string') {
  5521. return value;
  5522. }
  5523. if (isArray_1(value)) {
  5524. // Recursively convert values (susceptible to call stack limits).
  5525. return _arrayMap(value, baseToString) + '';
  5526. }
  5527. if (isSymbol_1(value)) {
  5528. return symbolToString ? symbolToString.call(value) : '';
  5529. }
  5530. var result = (value + '');
  5531. return (result == '0' && (1 / value) == -INFINITY$1) ? '-0' : result;
  5532. }
  5533. var _baseToString = baseToString;
  5534. /**
  5535. * Converts `value` to a string. An empty string is returned for `null`
  5536. * and `undefined` values. The sign of `-0` is preserved.
  5537. *
  5538. * @static
  5539. * @memberOf _
  5540. * @since 4.0.0
  5541. * @category Lang
  5542. * @param {*} value The value to convert.
  5543. * @returns {string} Returns the converted string.
  5544. * @example
  5545. *
  5546. * _.toString(null);
  5547. * // => ''
  5548. *
  5549. * _.toString(-0);
  5550. * // => '-0'
  5551. *
  5552. * _.toString([1, 2, 3]);
  5553. * // => '1,2,3'
  5554. */
  5555. function toString(value) {
  5556. return value == null ? '' : _baseToString(value);
  5557. }
  5558. var toString_1 = toString;
  5559. /**
  5560. * Casts `value` to a path array if it's not one.
  5561. *
  5562. * @private
  5563. * @param {*} value The value to inspect.
  5564. * @param {Object} [object] The object to query keys on.
  5565. * @returns {Array} Returns the cast property path array.
  5566. */
  5567. function castPath(value, object) {
  5568. if (isArray_1(value)) {
  5569. return value;
  5570. }
  5571. return _isKey(value, object) ? [value] : _stringToPath(toString_1(value));
  5572. }
  5573. var _castPath = castPath;
  5574. /** Used as references for various `Number` constants. */
  5575. var INFINITY = 1 / 0;
  5576. /**
  5577. * Converts `value` to a string key if it's not a string or symbol.
  5578. *
  5579. * @private
  5580. * @param {*} value The value to inspect.
  5581. * @returns {string|symbol} Returns the key.
  5582. */
  5583. function toKey(value) {
  5584. if (typeof value == 'string' || isSymbol_1(value)) {
  5585. return value;
  5586. }
  5587. var result = (value + '');
  5588. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  5589. }
  5590. var _toKey = toKey;
  5591. /**
  5592. * The base implementation of `_.get` without support for default values.
  5593. *
  5594. * @private
  5595. * @param {Object} object The object to query.
  5596. * @param {Array|string} path The path of the property to get.
  5597. * @returns {*} Returns the resolved value.
  5598. */
  5599. function baseGet(object, path) {
  5600. path = _castPath(path, object);
  5601. var index = 0,
  5602. length = path.length;
  5603. while (object != null && index < length) {
  5604. object = object[_toKey(path[index++])];
  5605. }
  5606. return (index && index == length) ? object : undefined;
  5607. }
  5608. var _baseGet = baseGet;
  5609. /**
  5610. * Gets the value at `path` of `object`. If the resolved value is
  5611. * `undefined`, the `defaultValue` is returned in its place.
  5612. *
  5613. * @static
  5614. * @memberOf _
  5615. * @since 3.7.0
  5616. * @category Object
  5617. * @param {Object} object The object to query.
  5618. * @param {Array|string} path The path of the property to get.
  5619. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  5620. * @returns {*} Returns the resolved value.
  5621. * @example
  5622. *
  5623. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  5624. *
  5625. * _.get(object, 'a[0].b.c');
  5626. * // => 3
  5627. *
  5628. * _.get(object, ['a', '0', 'b', 'c']);
  5629. * // => 3
  5630. *
  5631. * _.get(object, 'a.b.c', 'default');
  5632. * // => 'default'
  5633. */
  5634. function get(object, path, defaultValue) {
  5635. var result = object == null ? undefined : _baseGet(object, path);
  5636. return result === undefined ? defaultValue : result;
  5637. }
  5638. var get_1 = get;
  5639. /**
  5640. * The base implementation of `_.hasIn` without support for deep paths.
  5641. *
  5642. * @private
  5643. * @param {Object} [object] The object to query.
  5644. * @param {Array|string} key The key to check.
  5645. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  5646. */
  5647. function baseHasIn(object, key) {
  5648. return object != null && key in Object(object);
  5649. }
  5650. var _baseHasIn = baseHasIn;
  5651. /**
  5652. * Checks if `path` exists on `object`.
  5653. *
  5654. * @private
  5655. * @param {Object} object The object to query.
  5656. * @param {Array|string} path The path to check.
  5657. * @param {Function} hasFunc The function to check properties.
  5658. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  5659. */
  5660. function hasPath(object, path, hasFunc) {
  5661. path = _castPath(path, object);
  5662. var index = -1,
  5663. length = path.length,
  5664. result = false;
  5665. while (++index < length) {
  5666. var key = _toKey(path[index]);
  5667. if (!(result = object != null && hasFunc(object, key))) {
  5668. break;
  5669. }
  5670. object = object[key];
  5671. }
  5672. if (result || ++index != length) {
  5673. return result;
  5674. }
  5675. length = object == null ? 0 : object.length;
  5676. return !!length && isLength_1(length) && _isIndex(key, length) &&
  5677. (isArray_1(object) || isArguments_1(object));
  5678. }
  5679. var _hasPath = hasPath;
  5680. /**
  5681. * Checks if `path` is a direct or inherited property of `object`.
  5682. *
  5683. * @static
  5684. * @memberOf _
  5685. * @since 4.0.0
  5686. * @category Object
  5687. * @param {Object} object The object to query.
  5688. * @param {Array|string} path The path to check.
  5689. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  5690. * @example
  5691. *
  5692. * var object = _.create({ 'a': _.create({ 'b': 2 }) });
  5693. *
  5694. * _.hasIn(object, 'a');
  5695. * // => true
  5696. *
  5697. * _.hasIn(object, 'a.b');
  5698. * // => true
  5699. *
  5700. * _.hasIn(object, ['a', 'b']);
  5701. * // => true
  5702. *
  5703. * _.hasIn(object, 'b');
  5704. * // => false
  5705. */
  5706. function hasIn(object, path) {
  5707. return object != null && _hasPath(object, path, _baseHasIn);
  5708. }
  5709. var hasIn_1 = hasIn;
  5710. /** Used to compose bitmasks for value comparisons. */
  5711. var COMPARE_PARTIAL_FLAG = 1,
  5712. COMPARE_UNORDERED_FLAG = 2;
  5713. /**
  5714. * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
  5715. *
  5716. * @private
  5717. * @param {string} path The path of the property to get.
  5718. * @param {*} srcValue The value to match.
  5719. * @returns {Function} Returns the new spec function.
  5720. */
  5721. function baseMatchesProperty(path, srcValue) {
  5722. if (_isKey(path) && _isStrictComparable(srcValue)) {
  5723. return _matchesStrictComparable(_toKey(path), srcValue);
  5724. }
  5725. return function(object) {
  5726. var objValue = get_1(object, path);
  5727. return (objValue === undefined && objValue === srcValue)
  5728. ? hasIn_1(object, path)
  5729. : _baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG);
  5730. };
  5731. }
  5732. var _baseMatchesProperty = baseMatchesProperty;
  5733. /**
  5734. * The base implementation of `_.property` without support for deep paths.
  5735. *
  5736. * @private
  5737. * @param {string} key The key of the property to get.
  5738. * @returns {Function} Returns the new accessor function.
  5739. */
  5740. function baseProperty(key) {
  5741. return function(object) {
  5742. return object == null ? undefined : object[key];
  5743. };
  5744. }
  5745. var _baseProperty = baseProperty;
  5746. /**
  5747. * A specialized version of `baseProperty` which supports deep paths.
  5748. *
  5749. * @private
  5750. * @param {Array|string} path The path of the property to get.
  5751. * @returns {Function} Returns the new accessor function.
  5752. */
  5753. function basePropertyDeep(path) {
  5754. return function(object) {
  5755. return _baseGet(object, path);
  5756. };
  5757. }
  5758. var _basePropertyDeep = basePropertyDeep;
  5759. /**
  5760. * Creates a function that returns the value at `path` of a given object.
  5761. *
  5762. * @static
  5763. * @memberOf _
  5764. * @since 2.4.0
  5765. * @category Util
  5766. * @param {Array|string} path The path of the property to get.
  5767. * @returns {Function} Returns the new accessor function.
  5768. * @example
  5769. *
  5770. * var objects = [
  5771. * { 'a': { 'b': 2 } },
  5772. * { 'a': { 'b': 1 } }
  5773. * ];
  5774. *
  5775. * _.map(objects, _.property('a.b'));
  5776. * // => [2, 1]
  5777. *
  5778. * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b');
  5779. * // => [1, 2]
  5780. */
  5781. function property(path) {
  5782. return _isKey(path) ? _baseProperty(_toKey(path)) : _basePropertyDeep(path);
  5783. }
  5784. var property_1 = property;
  5785. /**
  5786. * The base implementation of `_.iteratee`.
  5787. *
  5788. * @private
  5789. * @param {*} [value=_.identity] The value to convert to an iteratee.
  5790. * @returns {Function} Returns the iteratee.
  5791. */
  5792. function baseIteratee(value) {
  5793. // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9.
  5794. // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details.
  5795. if (typeof value == 'function') {
  5796. return value;
  5797. }
  5798. if (value == null) {
  5799. return identity_1;
  5800. }
  5801. if (typeof value == 'object') {
  5802. return isArray_1(value)
  5803. ? _baseMatchesProperty(value[0], value[1])
  5804. : _baseMatches(value);
  5805. }
  5806. return property_1(value);
  5807. }
  5808. var _baseIteratee = baseIteratee;
  5809. /** Used to compose bitmasks for cloning. */
  5810. var CLONE_DEEP_FLAG = 1;
  5811. /**
  5812. * Creates a function that invokes `func` with the arguments of the created
  5813. * function. If `func` is a property name, the created function returns the
  5814. * property value for a given element. If `func` is an array or object, the
  5815. * created function returns `true` for elements that contain the equivalent
  5816. * source properties, otherwise it returns `false`.
  5817. *
  5818. * @static
  5819. * @since 4.0.0
  5820. * @memberOf _
  5821. * @category Util
  5822. * @param {*} [func=_.identity] The value to convert to a callback.
  5823. * @returns {Function} Returns the callback.
  5824. * @example
  5825. *
  5826. * var users = [
  5827. * { 'user': 'barney', 'age': 36, 'active': true },
  5828. * { 'user': 'fred', 'age': 40, 'active': false }
  5829. * ];
  5830. *
  5831. * // The `_.matches` iteratee shorthand.
  5832. * _.filter(users, _.iteratee({ 'user': 'barney', 'active': true }));
  5833. * // => [{ 'user': 'barney', 'age': 36, 'active': true }]
  5834. *
  5835. * // The `_.matchesProperty` iteratee shorthand.
  5836. * _.filter(users, _.iteratee(['user', 'fred']));
  5837. * // => [{ 'user': 'fred', 'age': 40 }]
  5838. *
  5839. * // The `_.property` iteratee shorthand.
  5840. * _.map(users, _.iteratee('user'));
  5841. * // => ['barney', 'fred']
  5842. *
  5843. * // Create custom iteratee shorthands.
  5844. * _.iteratee = _.wrap(_.iteratee, function(iteratee, func) {
  5845. * return !_.isRegExp(func) ? iteratee(func) : function(string) {
  5846. * return func.test(string);
  5847. * };
  5848. * });
  5849. *
  5850. * _.filter(['abc', 'def'], /ef/);
  5851. * // => ['def']
  5852. */
  5853. function iteratee(func) {
  5854. return _baseIteratee(typeof func == 'function' ? func : _baseClone(func, CLONE_DEEP_FLAG));
  5855. }
  5856. var iteratee_1 = iteratee;
  5857. /** Built-in value references. */
  5858. var spreadableSymbol = _Symbol ? _Symbol.isConcatSpreadable : undefined;
  5859. /**
  5860. * Checks if `value` is a flattenable `arguments` object or array.
  5861. *
  5862. * @private
  5863. * @param {*} value The value to check.
  5864. * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
  5865. */
  5866. function isFlattenable(value) {
  5867. return isArray_1(value) || isArguments_1(value) ||
  5868. !!(spreadableSymbol && value && value[spreadableSymbol]);
  5869. }
  5870. var _isFlattenable = isFlattenable;
  5871. /**
  5872. * The base implementation of `_.flatten` with support for restricting flattening.
  5873. *
  5874. * @private
  5875. * @param {Array} array The array to flatten.
  5876. * @param {number} depth The maximum recursion depth.
  5877. * @param {boolean} [predicate=isFlattenable] The function invoked per iteration.
  5878. * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks.
  5879. * @param {Array} [result=[]] The initial result value.
  5880. * @returns {Array} Returns the new flattened array.
  5881. */
  5882. function baseFlatten(array, depth, predicate, isStrict, result) {
  5883. var index = -1,
  5884. length = array.length;
  5885. predicate || (predicate = _isFlattenable);
  5886. result || (result = []);
  5887. while (++index < length) {
  5888. var value = array[index];
  5889. if (depth > 0 && predicate(value)) {
  5890. if (depth > 1) {
  5891. // Recursively flatten arrays (susceptible to call stack limits).
  5892. baseFlatten(value, depth - 1, predicate, isStrict, result);
  5893. } else {
  5894. _arrayPush(result, value);
  5895. }
  5896. } else if (!isStrict) {
  5897. result[result.length] = value;
  5898. }
  5899. }
  5900. return result;
  5901. }
  5902. var _baseFlatten = baseFlatten;
  5903. /**
  5904. * Flattens `array` a single level deep.
  5905. *
  5906. * @static
  5907. * @memberOf _
  5908. * @since 0.1.0
  5909. * @category Array
  5910. * @param {Array} array The array to flatten.
  5911. * @returns {Array} Returns the new flattened array.
  5912. * @example
  5913. *
  5914. * _.flatten([1, [2, [3, [4]], 5]]);
  5915. * // => [1, 2, [3, [4]], 5]
  5916. */
  5917. function flatten(array) {
  5918. var length = array == null ? 0 : array.length;
  5919. return length ? _baseFlatten(array, 1) : [];
  5920. }
  5921. var flatten_1 = flatten;
  5922. /* Built-in method references for those with the same name as other `lodash` methods. */
  5923. var nativeMax = Math.max;
  5924. /**
  5925. * A specialized version of `baseRest` which transforms the rest array.
  5926. *
  5927. * @private
  5928. * @param {Function} func The function to apply a rest parameter to.
  5929. * @param {number} [start=func.length-1] The start position of the rest parameter.
  5930. * @param {Function} transform The rest array transform.
  5931. * @returns {Function} Returns the new function.
  5932. */
  5933. function overRest(func, start, transform) {
  5934. start = nativeMax(start === undefined ? (func.length - 1) : start, 0);
  5935. return function() {
  5936. var args = arguments,
  5937. index = -1,
  5938. length = nativeMax(args.length - start, 0),
  5939. array = Array(length);
  5940. while (++index < length) {
  5941. array[index] = args[start + index];
  5942. }
  5943. index = -1;
  5944. var otherArgs = Array(start + 1);
  5945. while (++index < start) {
  5946. otherArgs[index] = args[index];
  5947. }
  5948. otherArgs[start] = transform(array);
  5949. return _apply(func, this, otherArgs);
  5950. };
  5951. }
  5952. var _overRest = overRest;
  5953. /**
  5954. * A specialized version of `baseRest` which flattens the rest array.
  5955. *
  5956. * @private
  5957. * @param {Function} func The function to apply a rest parameter to.
  5958. * @returns {Function} Returns the new function.
  5959. */
  5960. function flatRest(func) {
  5961. return _setToString(_overRest(func, undefined, flatten_1), func + '');
  5962. }
  5963. var _flatRest = flatRest;
  5964. /** Used to compose bitmasks for function metadata. */
  5965. var WRAP_REARG_FLAG = 256;
  5966. /**
  5967. * Creates a function that invokes `func` with arguments arranged according
  5968. * to the specified `indexes` where the argument value at the first index is
  5969. * provided as the first argument, the argument value at the second index is
  5970. * provided as the second argument, and so on.
  5971. *
  5972. * @static
  5973. * @memberOf _
  5974. * @since 3.0.0
  5975. * @category Function
  5976. * @param {Function} func The function to rearrange arguments for.
  5977. * @param {...(number|number[])} indexes The arranged argument indexes.
  5978. * @returns {Function} Returns the new function.
  5979. * @example
  5980. *
  5981. * var rearged = _.rearg(function(a, b, c) {
  5982. * return [a, b, c];
  5983. * }, [2, 0, 1]);
  5984. *
  5985. * rearged('b', 'c', 'a')
  5986. * // => ['a', 'b', 'c']
  5987. */
  5988. var rearg = _flatRest(function(func, indexes) {
  5989. return _createWrap(func, WRAP_REARG_FLAG, undefined, undefined, undefined, indexes);
  5990. });
  5991. var rearg_1 = rearg;
  5992. /**
  5993. * Converts `value` to a property path array.
  5994. *
  5995. * @static
  5996. * @memberOf _
  5997. * @since 4.0.0
  5998. * @category Util
  5999. * @param {*} value The value to convert.
  6000. * @returns {Array} Returns the new property path array.
  6001. * @example
  6002. *
  6003. * _.toPath('a.b.c');
  6004. * // => ['a', 'b', 'c']
  6005. *
  6006. * _.toPath('a[0].b.c');
  6007. * // => ['a', '0', 'b', 'c']
  6008. */
  6009. function toPath(value) {
  6010. if (isArray_1(value)) {
  6011. return _arrayMap(value, _toKey);
  6012. }
  6013. return isSymbol_1(value) ? [value] : _copyArray(_stringToPath(toString_1(value)));
  6014. }
  6015. var toPath_1 = toPath;
  6016. var _util = {
  6017. 'ary': ary_1,
  6018. 'assign': _baseAssign,
  6019. 'clone': clone_1,
  6020. 'curry': commonjsRequire("../curry", "/$$rollup_base$$/node_modules/lodash/fp"),
  6021. 'forEach': _arrayEach,
  6022. 'isArray': isArray_1,
  6023. 'isError': isError_1,
  6024. 'isFunction': isFunction_1,
  6025. 'isWeakMap': isWeakMap_1,
  6026. 'iteratee': iteratee_1,
  6027. 'keys': _baseKeys,
  6028. 'rearg': rearg_1,
  6029. 'toInteger': toInteger_1,
  6030. 'toPath': toPath_1
  6031. };
  6032. /**
  6033. * Converts `func` of `name` to an immutable auto-curried iteratee-first data-last
  6034. * version with conversion `options` applied. If `name` is an object its methods
  6035. * will be converted.
  6036. *
  6037. * @param {string} name The name of the function to wrap.
  6038. * @param {Function} [func] The function to wrap.
  6039. * @param {Object} [options] The options object. See `baseConvert` for more details.
  6040. * @returns {Function|Object} Returns the converted function or object.
  6041. */
  6042. function convert$2(name, func, options) {
  6043. return _baseConvert(_util, name, func, options);
  6044. }
  6045. var convert_1 = convert$2;
  6046. commonjsRegister("/$$rollup_base$$/node_modules/lodash/fp/curry.js", function (module, exports) {
  6047. var convert = convert_1,
  6048. func = convert('curry', commonjsRequire("../curry", "/$$rollup_base$$/node_modules/lodash/fp"));
  6049. func.placeholder = placeholder;
  6050. module.exports = func;
  6051. });
  6052. commonjsRegister("/$$rollup_base$$/node_modules/lodash/fp/curryN.js", function (module, exports) {
  6053. var convert = convert_1,
  6054. func = convert('curryN', commonjsRequire("../curry", "/$$rollup_base$$/node_modules/lodash/fp"));
  6055. func.placeholder = placeholder;
  6056. module.exports = func;
  6057. });
  6058. commonjsRegister("/$$rollup_base$$/node_modules/lodash/fp/curryRight.js", function (module, exports) {
  6059. var convert = convert_1,
  6060. func = convert('curryRight', commonjsRequire("../curryRight", "/$$rollup_base$$/node_modules/lodash/fp"));
  6061. func.placeholder = placeholder;
  6062. module.exports = func;
  6063. });
  6064. commonjsRegister("/$$rollup_base$$/node_modules/lodash/fp/curryRightN.js", function (module, exports) {
  6065. var convert = convert_1,
  6066. func = convert('curryRightN', commonjsRequire("../curryRight", "/$$rollup_base$$/node_modules/lodash/fp"));
  6067. func.placeholder = placeholder;
  6068. module.exports = func;
  6069. });
  6070. const crossfilter = crossfilterreq__default['default'].default ? crossfilterreq__default['default'].default : crossfilterreq__default['default'];
  6071. // -------------------------------------------------------------------
  6072. // dx = multidimensional Crossfilter = Wrapper for crossfilter
  6073. var dx = {
  6074. indexFns : { id : function (d) { return d.id || "" } }
  6075. , createIndexFn : function(indexFn, dim){
  6076. var indexFns = {
  6077. dim : function(d) { return d[dim] || "" }
  6078. , dimId : function(d) { return d[dim + 'Id'] || "" }
  6079. };
  6080. if(Object.prototype.toString.call(indexFn) === '[object Function]' ) return indexFn;
  6081. if(indexFn) return function(d) { return d[indexFn] || "" } // Assume its the column name on the data.
  6082. indexFn = function(d){
  6083. // First time execution detects key to use. We try [dim] then[{{dim}}Id] then [id]
  6084. // This is though dangerous if first item has missing data i.e. d[dim] is undefined even though other rows have d[dim]
  6085. console.error('default generated indexFn on non existence of model property is dangerous.');
  6086. indexFn = d[dim] ? indexFns['dim'] : d[dim + 'Id'] ? indexFns['dimId'] : dx.indexFns['id'];
  6087. dx.indexFns['id'] === indexFn ? console.error('Warning : dimension name not found. Using id as default is not recommended.') : null;
  6088. // Since we were called after the dimension processing has started we will continue to get called until each item is processed.
  6089. // We therefore switch the function that will get called from next time onwards.
  6090. return indexFn(d); //
  6091. };
  6092. return function(d){ return indexFn(d) }
  6093. }
  6094. , filter : function(filter, dim){
  6095. // Note : Ensure that the filter function that you pass in is the same function object. This is the only way to prevent bloat.
  6096. if(!filter) { console.warn('Useless call to filter without a real filter.'); return;} // All filters should already be in place since we are stateful.
  6097. var filterable = dim ? this.dims[dim] : this;
  6098. // Filters are shared between master and dimension on data.
  6099. if(!filterable.wkFilters.get(filter)) {
  6100. filterable.wkFilters.set(filter, true);
  6101. filterable.filters.push(filter); // PB : Note -- Push unique distinct filters ! This will bloat if duplicates are pushed.
  6102. }
  6103. // PB : TODO -- Check CF may not re-evaluate filters if it detects no change in filter.
  6104. if(filterable.dxFd){
  6105. // This is a master dim with attached fact dimension. this.model should give us the column name on the fact data.
  6106. filterable.dxFd.filter( filterable.__filter );
  6107. }
  6108. filterable.dxF.filter(filterable.__filter);
  6109. // If it does re-evaluate following cascade code is not required.
  6110. // Cascade to all nested dimensions which are implicitly bound.
  6111. // Object.keys(specs.dims).forEach((dim)=>{
  6112. // this.dims[dim].dxF.filter( this.dims[dim].__filter )
  6113. // })
  6114. // Handle other custom bound Dimensions on this dimension.
  6115. // Master and Data crossfilters are implicitly bound.
  6116. // this.dims[dim].dxFm ? this.dims[dim].dxFm.filter( this.dims[dim].__filter ) : null;
  6117. // this.dims[dim].dxFd ? this.dims[dim].dxFd.filter( this.dims[dim].__filter ) : null;
  6118. }
  6119. , filterAll : function(dim){
  6120. var filterable = dim ? this.dims[dim] : this;
  6121. if(filterable.dxFd){
  6122. // This is a master dim with attached fact dimension. this.model should give us the column name on the fact data.
  6123. filterable.dxFd.filterAll();
  6124. }
  6125. filterable.dxF.filterAll( );
  6126. // Cascade to all nested dimensions.
  6127. // Object.keys(specs.dims).forEach((dim)=>{
  6128. // specs[dim][dx] = specs[dim].data ? dx.create( specs[dim] ) : null;
  6129. // dx.__createPairedDx(specs, dim);
  6130. // })
  6131. }
  6132. , addFilter : function(filter, dim) {
  6133. dim = dim || 'id';
  6134. this.dims[dim].filters.push(filter);
  6135. }
  6136. , __initDim : function(oDim){
  6137. var __filter = function(d){
  6138. for(var f=0; f < oDim.filters.length; f++) {
  6139. // Filter function will be called on the dimension.
  6140. // PB : TODO accept any scope instead of only the dimension.
  6141. if(!oDim.filters[f].call(oDim, d)) return false;
  6142. }
  6143. return true;
  6144. };
  6145. return oDim ? (()=>{
  6146. oDim.wkFilters = new(WeakMap);
  6147. oDim.filters = []; oDim.__filter = __filter;
  6148. return oDim
  6149. })()
  6150. : { wkFilters : new(WeakMap), filters : [], __filter : __filter }
  6151. }
  6152. , __createPairedDx : function(specs, dim, idxFn){
  6153. var oDim = dim === 'id' ? specs : specs.dims[dim];
  6154. idxFn = idxFn || dx.createIndexFn(oDim.indexFn, dim);
  6155. oDim.dxU = specs.ndxU.dimension( idxFn );
  6156. oDim.dxF = specs.ndxF.dimension( idxFn );
  6157. }
  6158. , create : function( specs ){
  6159. specs.ndxF = crossfilter(specs.data);
  6160. specs.ndxU = crossfilter(specs.data);
  6161. // specs.dims ? null : specs.dims = { 'id' : null }
  6162. // specs.dims['id'] = dx.__initDim(specs.dims['id'])
  6163. dx.__initDim(specs); // id Dimension is merged with dx itself. Other dimensions will be found in dims.
  6164. dx.__createPairedDx(specs, 'id', dx.indexFns.id);
  6165. specs.dims ? Object.keys(specs.dims).forEach((dim)=>{
  6166. specs.dims[dim].data ? (()=>{
  6167. // We have some master data for this dimension.
  6168. dx.create( specs.dims[dim] );
  6169. // PB : TODO -- We should probably bind the an array dx's ...
  6170. // Eg: An array of master dx's for a fact dx...
  6171. // i.e specs.bound = [ dx1 = practitioner, dx2 = xyz etc...]
  6172. })()
  6173. : dx.__initDim(specs.dims[dim]);
  6174. var idxFn = dx.createIndexFn(specs.dims[dim].indexFn, dim);
  6175. specs.dims[dim].dxFd = specs.ndxF.dimension( idxFn );
  6176. specs.dims[dim].dxUd = specs.ndxU.dimension( idxFn );
  6177. }) : null;
  6178. specs.filter = this.filter;
  6179. specs.filterAll = this.filterAll;
  6180. return specs;
  6181. }
  6182. // , exclude : ( dxU, dxF, filterFn )=>{
  6183. // // Excludes filtered from unfiltered.
  6184. // var filterFn = null;
  6185. // if(this.get('selected_doctor.id')) {
  6186. // }
  6187. // else {
  6188. // var __inclusions = [];
  6189. // var __exclusions = [];
  6190. // practitionersDimUnfiltered.top(Infinity).forEach((availablePractitioner)=>{
  6191. // // Per Doc
  6192. // ndxFiltered.filterAll()
  6193. // practitionersDimFiltered.filter(availablePractitioner.id);
  6194. // var freeTimes = getFreeTimes(tRange, practitionersDimFiltered);
  6195. // if(freeTimes.length > 0) { /*available*/
  6196. // __inclusions.push(availablePractitioner) }
  6197. // else {
  6198. // __exclusions.push(availablePractitioner)
  6199. // }
  6200. // })
  6201. // filterFn = ()=> { return ((inclusions, exclusions)=>{
  6202. // for(var f in filters) {
  6203. // if(!filters[f]) return false;
  6204. // }
  6205. // return true;
  6206. // })(__inclusions, __exclusions) } ;
  6207. // practitionersDimFiltered.filter(filterFn);
  6208. // }
  6209. // return filterFn;
  6210. // }
  6211. };
  6212. var dx_1 = dx;
  6213. try {
  6214. var x$1 = BigInt(0);
  6215. }
  6216. catch(e){
  6217. console.warn('BigInt check failed. Falling back to Number');
  6218. // PB : TODO -- All Number issues with bitmasks will fail since BigInt is not available.
  6219. // Eg : Older Safari versions will not work
  6220. // PB : TODO -- provide a proper polyfill for older Safari Browsers in the ember build.
  6221. BigInt = Number;
  6222. }
  6223. // -------------------------------
  6224. // Command line option parsing
  6225. // -------------------------------
  6226. function cliargs$1(args, opts) {
  6227. if (!opts) opts = {};
  6228. var flags = { bools : {}, strings : {}, unknownFn: null };
  6229. if (typeof opts['unknown'] === 'function') {
  6230. flags.unknownFn = opts['unknown'];
  6231. }
  6232. if (typeof opts['boolean'] === 'boolean' && opts['boolean']) {
  6233. flags.allBools = true;
  6234. } else {
  6235. [].concat(opts['boolean']).filter(Boolean).forEach(function (key) {
  6236. flags.bools[key] = true;
  6237. });
  6238. }
  6239. var aliases = {};
  6240. Object.keys(opts.alias || {}).forEach(function (key) {
  6241. aliases[key] = [].concat(opts.alias[key]);
  6242. aliases[key].forEach(function (x) {
  6243. aliases[x] = [key].concat(aliases[key].filter(function (y) {
  6244. return x !== y;
  6245. }));
  6246. });
  6247. });
  6248. [].concat(opts.string).filter(Boolean).forEach(function (key) {
  6249. flags.strings[key] = true;
  6250. if (aliases[key]) {
  6251. flags.strings[aliases[key]] = true;
  6252. }
  6253. });
  6254. var defaults = opts['default'] || {};
  6255. var argv = { _ : [] };
  6256. Object.keys(flags.bools).forEach(function (key) {
  6257. setArg(key, defaults[key] === undefined ? false : defaults[key]);
  6258. });
  6259. var notFlags = [];
  6260. if (args.indexOf('--') !== -1) {
  6261. notFlags = args.slice(args.indexOf('--')+1);
  6262. args = args.slice(0, args.indexOf('--'));
  6263. }
  6264. function argDefined(key, arg) {
  6265. return (flags.allBools && /^--[^=]+$/.test(arg)) ||
  6266. flags.strings[key] || flags.bools[key] || aliases[key];
  6267. }
  6268. function setArg (key, val, arg) {
  6269. if (arg && flags.unknownFn && !argDefined(key, arg)) {
  6270. if (flags.unknownFn(arg) === false) return;
  6271. }
  6272. var value = !flags.strings[key] && isNumber(val)
  6273. ? Number(val) : val
  6274. ;
  6275. setKey(argv, key.split('.'), value);
  6276. (aliases[key] || []).forEach(function (x) {
  6277. setKey(argv, x.split('.'), value);
  6278. });
  6279. }
  6280. function setKey (obj, keys, value) {
  6281. var o = obj;
  6282. keys.slice(0,-1).forEach(function (key) {
  6283. if (o[key] === undefined) o[key] = {};
  6284. o = o[key];
  6285. });
  6286. var key = keys[keys.length - 1];
  6287. if (o[key] === undefined || flags.bools[key] || typeof o[key] === 'boolean') {
  6288. o[key] = value;
  6289. }
  6290. else if (Array.isArray(o[key])) {
  6291. o[key].push(value);
  6292. }
  6293. else {
  6294. o[key] = [ o[key], value ];
  6295. }
  6296. }
  6297. function aliasIsBoolean(key) {
  6298. return aliases[key].some(function (x) {
  6299. return flags.bools[x];
  6300. });
  6301. }
  6302. for (var i = 0; i < args.length; i++) {
  6303. var arg = args[i];
  6304. if (/^--.+=/.test(arg)) {
  6305. // Using [\s\S] instead of . because js doesn't support the
  6306. // 'dotall' regex modifier. See:
  6307. // http://stackoverflow.com/a/1068308/13216
  6308. var m = arg.match(/^--([^=]+)=([\s\S]*)$/);
  6309. var key = m[1];
  6310. var value = m[2];
  6311. if (flags.bools[key]) {
  6312. value = value !== 'false';
  6313. }
  6314. setArg(key, value, arg);
  6315. }
  6316. else if (/^--no-.+/.test(arg)) {
  6317. var key = arg.match(/^--no-(.+)/)[1];
  6318. setArg(key, false, arg);
  6319. }
  6320. else if (/^--.+/.test(arg)) {
  6321. var key = arg.match(/^--(.+)/)[1];
  6322. var next = args[i + 1];
  6323. if (next !== undefined && !/^-/.test(next)
  6324. && !flags.bools[key]
  6325. && !flags.allBools
  6326. && (aliases[key] ? !aliasIsBoolean(key) : true)) {
  6327. setArg(key, next, arg);
  6328. i++;
  6329. }
  6330. else if (/^(true|false)$/.test(next)) {
  6331. setArg(key, next === 'true', arg);
  6332. i++;
  6333. }
  6334. else {
  6335. setArg(key, flags.strings[key] ? '' : true, arg);
  6336. }
  6337. }
  6338. else if (/^-[^-]+/.test(arg)) {
  6339. var letters = arg.slice(1,-1).split('');
  6340. var broken = false;
  6341. for (var j = 0; j < letters.length; j++) {
  6342. var next = arg.slice(j+2);
  6343. if (next === '-') {
  6344. setArg(letters[j], next, arg);
  6345. continue;
  6346. }
  6347. if (/[A-Za-z]/.test(letters[j]) && /=/.test(next)) {
  6348. setArg(letters[j], next.split('=')[1], arg);
  6349. broken = true;
  6350. break;
  6351. }
  6352. if (/[A-Za-z]/.test(letters[j])
  6353. && /-?\d+(\.\d*)?(e-?\d+)?$/.test(next)) {
  6354. setArg(letters[j], next, arg);
  6355. broken = true;
  6356. break;
  6357. }
  6358. if (letters[j+1] && letters[j+1].match(/\W/)) {
  6359. setArg(letters[j], arg.slice(j+2), arg);
  6360. broken = true;
  6361. break;
  6362. }
  6363. else {
  6364. setArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);
  6365. }
  6366. }
  6367. var key = arg.slice(-1)[0];
  6368. if (!broken && key !== '-') {
  6369. if (args[i+1] && !/^(-|--)[^-]/.test(args[i+1])
  6370. && !flags.bools[key]
  6371. && (aliases[key] ? !aliasIsBoolean(key) : true)) {
  6372. setArg(key, args[i+1], arg);
  6373. i++;
  6374. }
  6375. else if (args[i+1] && /true|false/.test(args[i+1])) {
  6376. setArg(key, args[i+1] === 'true', arg);
  6377. i++;
  6378. }
  6379. else {
  6380. setArg(key, flags.strings[key] ? '' : true, arg);
  6381. }
  6382. }
  6383. }
  6384. else {
  6385. if (!flags.unknownFn || flags.unknownFn(arg) !== false) {
  6386. argv._.push(
  6387. flags.strings['_'] || !isNumber(arg) ? arg : Number(arg)
  6388. );
  6389. }
  6390. if (opts.stopEarly) {
  6391. argv._.push.apply(argv._, args.slice(i + 1));
  6392. break;
  6393. }
  6394. }
  6395. }
  6396. Object.keys(defaults).forEach(function (key) {
  6397. if (!hasKey(argv, key.split('.'))) {
  6398. setKey(argv, key.split('.'), defaults[key]);
  6399. (aliases[key] || []).forEach(function (x) {
  6400. setKey(argv, x.split('.'), defaults[key]);
  6401. });
  6402. }
  6403. });
  6404. if (opts['--']) {
  6405. argv['--'] = new Array();
  6406. notFlags.forEach(function(key) {
  6407. argv['--'].push(key);
  6408. });
  6409. }
  6410. else {
  6411. notFlags.forEach(function(key) {
  6412. argv._.push(key);
  6413. });
  6414. }
  6415. return argv;
  6416. }
  6417. /*
  6418. Iterable task should return either truthy or false
  6419. Any fn will return only one value for an array of iterables. If any one iterable fails, the return value would be false.
  6420. If all succeed , the return value will be true.
  6421. If continueOnFailure is false, an execption is raised on any one failure
  6422. */
  6423. function any$1(iterable, continueOnFailure) {
  6424. var cancelsignal = Symbol();
  6425. return iterable.reduce(
  6426. (p, tasq, i ,a) => {
  6427. var handleError = (err, pVal)=>{
  6428. if(err !== cancelsignal) {
  6429. // Cancel only once on first failure.
  6430. console.log('Failed : ' + err.message + ' ' + JSON.stringify(pVal));
  6431. console.dir(p);
  6432. console.warn('Possible failure for task with result : ' + JSON.stringify(pVal));
  6433. if(i>0 && a[i-1].info) console.dir(a[i-1].info);
  6434. console.error('Error : ' + err.stack);
  6435. console.error(a[i-1]);
  6436. a[i-1] ? console.log("tasq : " + a[i-1].toString()) : null;
  6437. if(!continueOnFailure) {console.log("Cancelling remaining on any one failure ..."); throw cancelsignal}
  6438. else return pVal;
  6439. // tasq ? console.log("tasq : " + tasq.toString()) : null; // Previous task is what failed not the one we are going to run.
  6440. }
  6441. };
  6442. if(Promise.resolve(p) === p ) {
  6443. if(i>0 && a[i-1].info) p.info = a[i-1].info;
  6444. return p.then((pVal) => {
  6445. // Falsy values are no longer treated as task failure exceptions. Specially for Promises.
  6446. // Even tasq function wrappers are required to return promises that eventually either resolve or reject..
  6447. // Failures are known for promises on reject.
  6448. // In future if we support direct sync function execution with a result examination for failure
  6449. // we could examine the result of the function as falsy's... or a result evaluator handler needs to be passed in...
  6450. // if(!pVal) handleError({ error : true, message : 'Failed without result' }, pVal)
  6451. // Truthy values are failures if obj has error=true.
  6452. if(pVal && pVal.error) handleError(pVal, pVal);
  6453. var trycall = function(tasq){
  6454. try {
  6455. var result = tasq(); // PB : TODO -- Handle scope for call
  6456. if(tasq.resultHandler) return tasq.resultHandler(result)
  6457. // if(!result) throw result; // Default failure detection for functions is falsy values.
  6458. return result
  6459. } catch (error) {
  6460. console.error(error);
  6461. console.error('Error : ' + error ? error.stack : 'No stack');
  6462. if(!continueOnFailure) throw error; // PB : TODO -- Support array of results for any with or without continueonfailure.
  6463. }
  6464. };
  6465. var handleNext = ()=>{
  6466. console.log('Task finished with result : ' + JSON.stringify(pVal));
  6467. if(i>0 && a[i-1].info) console.dir(a[i-1].info);
  6468. if(!tasq && !continueOnFailure) { console.log('Error : No task specified.'); throw false;}
  6469. else if(!tasq) { console.log('Error : No task specified.'); return false;}
  6470. return (Promise.resolve(tasq) === tasq ) ? tasq : trycall(tasq) ;
  6471. };
  6472. if(Promise.resolve(pVal) === pVal) {
  6473. // Passed in function retured a promise. We still need to wait for it.
  6474. pVal.then((pVal)=>{ return handleNext(); });
  6475. }
  6476. else return handleNext()
  6477. }).catch((error) => {
  6478. if(error !== cancelsignal) {
  6479. console.log(`E3 : i = ${i} `);
  6480. console.error('Error : ' + error.message);
  6481. console.error('Error : ' + error.stack);
  6482. tasq ? console.log("tasq : " + tasq.toString()) : null;
  6483. console.log('debugData 3-------------------------');
  6484. // handleError()
  6485. throw error
  6486. }
  6487. else throw cancelsignal;
  6488. })
  6489. }
  6490. else if(!p) {
  6491. handleError({ error : true, message : 'Failed without result' }, pVal);
  6492. console.log("Bypass remaining on prior failure");
  6493. return false; // All remaining tasks will return false in the any results even if they are promisies still running or functions not initiated.
  6494. }
  6495. else return p; // A truthy value
  6496. }
  6497. , Promise.resolve(true)
  6498. );
  6499. }
  6500. function hasKey (obj, keys) {
  6501. var o = obj;
  6502. keys.slice(0,-1).forEach(function (key) {
  6503. o = (o[key] || {});
  6504. });
  6505. var key = keys[keys.length - 1];
  6506. return key in o;
  6507. }
  6508. function isNumber (x) {
  6509. if (typeof x === 'number') return true;
  6510. if (/^0x[0-9a-f]+$/i.test(x)) return true;
  6511. return /^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(x);
  6512. }
  6513. // -------------------------------------------------------------------
  6514. // timeUtils
  6515. const daysbits = 7;
  6516. const datesbits = 31;
  6517. const monthsbits = 12;
  6518. // 2**53-1 (+/-) is largest integer precision for 64 bit floating point IEE 754
  6519. // 7 + 31 + 12 = 50 bits which fits.
  6520. const datebitOffset = daysbits;
  6521. const monthbitOffset = datesbits + daysbits; // Months are 0 based. So we need to offeset by 1 more so 31st is not overrwritten.
  6522. const monthsMask = 0b111111111111 * 2** (monthbitOffset);
  6523. const datesMask = 0b1111111111111111111111111111111 * 2 ** (datebitOffset);
  6524. const daysMask = 0b1111111;
  6525. var timeUtils = {
  6526. // PB : TODO -- Currently assuming event e1 is a sub 1 day duration. Which may not be true.
  6527. toRecurringPattern( event ){
  6528. var dayBitToSet = event.from.getDay(); // 0 based Index
  6529. var dateBitToSet = event.from.getDate() + datebitOffset - 1; // Dates are 1 based.
  6530. var monthBitToSet = event.from.getMonth() + monthbitOffset; // 0 based
  6531. var recurring = 2**dayBitToSet + 2**dateBitToSet + 2**monthBitToSet;
  6532. // PB : TODO -- loop through all matching masks until the end.
  6533. return {
  6534. from : event.from, to : event.to, recurring: recurring
  6535. , start: new Date ( event.from - new Date( moment__default['default'](event.from).startOf('day') ) )
  6536. , end: new Date ( event.to - new Date( moment__default['default'](event.to).startOf('day') ) )
  6537. }
  6538. }
  6539. , getSkipFunction(r, boundedRange){
  6540. var areMonthsSelected = monthsMask & r.recurring;
  6541. var areDatesSelected = datesMask & r.recurring;
  6542. var areDaysSelected = daysMask & r.recurring;
  6543. if(!areMonthsSelected && !areDatesSelected && !areDaysSelected) {
  6544. console.error("Null patterns are useless for selection. This is probably not a recurring pattern");
  6545. return null;
  6546. }
  6547. var filter = { from : boundedRange && boundedRange.from || new Date(moment__default['default']().startOf('day')), to : boundedRange && boundedRange.to };
  6548. // Returns how much to skip for next available value for a dimension.
  6549. var reset = Symbol('reset');
  6550. var stop = Symbol('stop');
  6551. var skipFn = {
  6552. create : (options)=>{
  6553. var startFrom = options.startFrom;
  6554. options.nBits;
  6555. return {
  6556. originOffset : null // From the origin.
  6557. , getSkipGenerator : (selected)=>{
  6558. var startOffset = null; // From position to start from.
  6559. // var cycleEntryPoint = null;
  6560. var nextCycleIndex = 0;
  6561. var incrementCycle = [];
  6562. var previous = 0;
  6563. // Discover the cycle from the bitmask.
  6564. for(var b = 0; b < nBits; b++) {
  6565. if(selected & 1) {
  6566. if(utils.js.isNull(originOffset)) this.originOffset = b;
  6567. if(utils.js.isNull(startOffset) && (startFrom - b) <= 0){
  6568. // startOffset cannot be negative. cycleEntryPoint is from the origin and is the entrypoint when there is no fitler.from...
  6569. startOffset = b - startFrom; // As measured from filter.from i.e from startingPoint
  6570. // cycleEntryPoint = b
  6571. nextCycleIndex = incrementCycle.length-1; // The place to enter cycle after startoffset aligns to currentCycleIndex.
  6572. }
  6573. incrementCycle.push(1 + b - previous); // We keep pushing and then splice in the first item as the last item to make this cyclical.
  6574. previous = 1 + b; // Minimum incrment is always 1;
  6575. }
  6576. }
  6577. // Due to the cyclical nature incrementCycle[0] has the increment to the second item
  6578. // and incrementCycle[incrementCycle.length-1] points to first item in cycle.
  6579. incrementCycle.push(incrementCycle.splice(0,1));
  6580. if(nextCycleIndex < 0) nextCycleIndex = 0;
  6581. return function*(){
  6582. var signal = false;
  6583. signal = yield startOffset; // Could be 0. Aligns to the first match in the cycle after from.
  6584. var i = nextCycleIndex;
  6585. for(;;){
  6586. for(; i < incrementCycle.length; i++ ) {
  6587. signal = yield incrementCycle[i];
  6588. if(reset === signal) { signal = yield this.originOffset; break; }
  6589. if(signal === stop || signal.done) return null;
  6590. }
  6591. i = 0;
  6592. }
  6593. }
  6594. }
  6595. // Generator for Irregular boundaries.
  6596. , getNextDateGenerator(selection){
  6597. var iterator = this.getSkipGenerator(selection);
  6598. return function*(){
  6599. var nextPotentialDate = moment__default['default'](potentialDate).add(iterator.next(), 'd');
  6600. if(nextPotentialDate.month() != potentialDate.getMonth()) {
  6601. // Handle month boundary increments.
  6602. nextPotentialDate.startOf('month').add(dateIterator.next(reset), 'm');
  6603. }
  6604. var potentialDate = nextPotentialDate;
  6605. yield nextPotentialDate;
  6606. }
  6607. }
  6608. // Cyclical Generator.
  6609. , getNextGenerator(options, selection){
  6610. this.getSkipGenerator(selection);
  6611. var next = filter.from;
  6612. return function*(){
  6613. yield next = moment__default['default'](next).add(dayIterator.next(), 'd');
  6614. }
  6615. }
  6616. }
  6617. }
  6618. };
  6619. var monthSkipper = skipFn.create({ nBits : monthsbits, startFrom : filter.from.getMonth() });
  6620. var daySkipper = skipFn.create({ nBits : daysbits, startFrom : filter.from.getDay() });
  6621. var dateSkipper = skipFn.create({ nBits : datebits, startFrom : filter.from.getDate()-1 }); // Skipfn requires a 0 based startFrom.
  6622. if(!areMonthsSelected && !areDatesSelected) return daySkipper(areDaysSelected)
  6623. else if(!areDatesSelected && !areDaysSelected) return monthSkipper(areMonthsSelected/2**(datesbits + daysbits))
  6624. else if(!areMonthsSelected && !areDaysSelected) return dateSkipper(areDatesSelected/2**(daysbits))
  6625. else {
  6626. if(!areMonthsSelected) {
  6627. // Dates, Days are selected.
  6628. return function*(){
  6629. var dateIterator = dateSkipper.getNextDateGenerator({ nBits : datebits, startFrom : filter.from.getDate()-1 }, areDatesSelected/2**(daysbits));
  6630. var dayIterator = daySkipper.getNextGenerator({ nBits : daysbits, startFrom : filter.from.getDay() }, areDaysSelected);
  6631. var potentialDay = null;
  6632. var potentialDate = dateIterator.next(); // Irregular cycle end...
  6633. if(isAnd) {
  6634. // Both day and date shuld match.
  6635. for(;;){
  6636. for(; (potentialDay = dayIterator.next()) < potentialDate ;);
  6637. // PB : TODO -- If we never hit the equals condition this will be a perpetual loop.
  6638. // If both are integer skips we will have a LCM and therefore hit this condition.
  6639. // In the case of sets of irregular skips we still will have the sum of each set also have an LCM.
  6640. // However for irregular boundaries we cannot predict whether an LCM exists and if a equality condition will ever be met.
  6641. // In such cases we need to protect from an infinite loop that will never yield.
  6642. // For dates though despite the irregular boundaries the pattern is that every date, month combination falls on every day of week.
  6643. if(potentialDay == potentialDate) {
  6644. yield potentialDay;
  6645. potentialDate = dateIterator.next();
  6646. continue;
  6647. }
  6648. for(; (potentialDate = dateIterator.next()) < potentialDay;);
  6649. }
  6650. }
  6651. else {
  6652. for(;;){
  6653. for(; (potentialDay = dayIterator.next()) < potentialDate ;) {
  6654. if(stop === (yield potentialDay)) return null;
  6655. }
  6656. if(potentialDay == potentialDate) {
  6657. potentialDate = dateIterator.next();
  6658. continue; // We need to yield in sorted sequence.
  6659. }
  6660. for(; (potentialDate = dateIterator.next()) < potentialDay;) {
  6661. if(stop === (yield potentialDate)) return null;
  6662. }
  6663. }
  6664. }
  6665. }
  6666. }
  6667. }
  6668. }
  6669. , skipThisRecurrable : Symbol('skipThisRecurrable')
  6670. , stopThisIterator : Symbol('stopThisIterator')
  6671. , toEvents( r, boundedRange){
  6672. if(!boundedRange.to) throw 'toEvents requires a bounded Range with an end to terminate. Use generater for unbounded operations'
  6673. ({ from : boundedRange.from || new Date(moment__default['default'](new Date()).startOf('day')), to : boundedRange.to });
  6674. }
  6675. , jsstart : function(){
  6676. return new Date(moment__default['default'](new Date(0)).startOf('day')) //1st Jan 1970 12AM local time
  6677. }
  6678. // Returns the whole event that is qualified even by a partial intersection.
  6679. , getEventGenerator : function* (objOrArray, boundedRange, getEvent) {
  6680. getEvent = getEvent || function(r, startOfDayFrom, start, end) {
  6681. var event = Object.assign( {}, r);
  6682. delete event.recurring;
  6683. event.from = new Date (startOfDayFrom.getTime() + start.getTime() + utils.getTZOffsetMilliseconds() );
  6684. event.to = new Date ( startOfDayFrom.getTime() + end.getTime() + utils.getTZOffsetMilliseconds());
  6685. // { from : new Date ( startOfDayFrom.getTime() + start.getTime() ) , to : new Date ( startOfDayFrom.getTime() + end.getTime()) }
  6686. return event
  6687. };
  6688. var recurrables = utils.js.isObject(objOrArray) ? [objOrArray] : objOrArray;
  6689. // We need to start somewhere. We dont need an end as we keep generating perpetually.
  6690. var filter = { from : boundedRange && boundedRange.from || new Date(moment__default['default']().startOf('day')), to : boundedRange && boundedRange.to };
  6691. for(var gIdx=0; gIdx < recurrables.length; gIdx++){
  6692. // Explode eachRecurrable to list of qualified events
  6693. var eachRecurrable = recurrables[gIdx]; // eachRecurrable -> Recurrable event (eg)
  6694. if( eachRecurrable.to && eachRecurrable.to <= filter.from ) continue; // Disjoint. No need to generate. Usually a past recurring pattern.
  6695. var startFrom = filter.from;
  6696. if( eachRecurrable.from) {
  6697. if(filter.to && filter.to <= eachRecurrable.from ) continue; // Disjoint.
  6698. if(eachRecurrable.from >= filter.from) startFrom = eachRecurrable.from;
  6699. }
  6700. var startOfDayFrom = new Date( moment__default['default'](startFrom).startOf('day') ); // PB : TODO -- IMP pattern TZ...
  6701. var next = null;
  6702. var stopAt = eachRecurrable.to ? filter.to ? Math.min(filter.to, eachRecurrable.to) : eachRecurrable.to : filter.to ? filter.to : false;
  6703. var shouldStop = stopAt ? ()=>{ return option === this.skipThisRecurrable || next.from >= stopAt } : ()=>{ return option === this.skipThisRecurrable || false }; // Perpetual callee can stop asking for next()..
  6704. // time recurring patterns are sorted and sequential so there is no chance we will find any more after end.
  6705. // which implies there is no need to test the rest of the recurring patterns until end of the boundary
  6706. if(filter.to && eachRecurrable.to) {
  6707. var stopAt = new Date(Min(filter.to, eachRecurrable.to));
  6708. shouldStop = ()=>{ return option === this.skipThisRecurrable || (stopAt <= next.to ? stopAt : false) };
  6709. }
  6710. var start = eachRecurrable.start || this.jsstart();
  6711. var end = eachRecurrable.end || new Date(moment__default['default'](start).add(1, "d"));
  6712. var option = true;
  6713. next = getEvent(eachRecurrable, startOfDayFrom, start, end);
  6714. while( !shouldStop() ) {
  6715. // PB : TODO -- If we provide an impossible pattern match we will perpetually not match and end up in an infinite loop.
  6716. var patternMatched = this.__hasPatternIntersection(next, eachRecurrable);
  6717. if(patternMatched) option = yield next;
  6718. if(option === this.stopThisIterator) return null;
  6719. // PB : TODO -- Instead of checking every day skip straightaway to the next sequential pattern match.
  6720. startOfDayFrom = new Date( moment__default['default'](startOfDayFrom).add(1, 'd') );
  6721. next = getEvent(eachRecurrable, startOfDayFrom, start, end);
  6722. }
  6723. }
  6724. }
  6725. // PB : TODO -- Generator that returns a series of intersections events.
  6726. // , recurringIntersectionsG : ()=>{}
  6727. , isEvent : function(obj){
  6728. return !obj.recurring
  6729. }
  6730. , isRecurringPattern : function(obj){
  6731. return obj.recurring
  6732. }
  6733. , hasEventIntersection( e1Orr1, e2Orr2 ){
  6734. return utils.timeUtils.isEvent(e1Orr1) && utils.timeUtils.isRecurringPattern( e2Orr2 ) ? utils.timeUtils.__recurringHasIntersection( e1Orr1, e2Orr2 )
  6735. : utils.timeUtils.isEvent(e2Orr2 ) && utils.timeUtils.isRecurringPattern( e1Orr1 ) ? utils.timeUtils.__recurringHasIntersection( e2Orr2, e1Orr1 )
  6736. : utils.timeUtils.isEvent(e1Orr1) && utils.timeUtils.isEvent(e2Orr2) ? utils.timeUtils.__hasEventIntersection( e1Orr1, e2Orr2 )
  6737. : utils.timeUtils.__willPatternsIntersect( e1Orr1, e2Orr2 ) //(()=>{throw 'PB : TDOO -- To Be implemented'})()
  6738. }
  6739. , __hasPatternIntersection( e1, p2 ){
  6740. var areMonthsSelected = monthsMask & p2.recurring;
  6741. var areDatesSelected = datesMask & p2.recurring;
  6742. var areDaysSelected = daysMask & p2.recurring;
  6743. // PB : TODO -- Gaurd against impossible patters like 29th Feb, 31st April etc...
  6744. if(!areMonthsSelected && !areDatesSelected && !areDaysSelected) {
  6745. console.error("Null patterns are useless for selection. This is probably not a recurring pattern");
  6746. return null; // Null patterns result in null intersection.
  6747. }
  6748. var isAnd = false;
  6749. if(!areMonthsSelected && !areDatesSelected || !areMonthsSelected && !areDaysSelected || !areDatesSelected && !areDaysSelected ) ;
  6750. else {
  6751. isAnd = p2.isAnd;
  6752. }
  6753. var p1 = this.toRecurringPattern(e1);
  6754. var patternMatched = p1.recurring & p2.recurring;
  6755. // In the and case asserts if p1 is a subset of p2 not the other way around. A recurring pattern should always be a superset of an event.
  6756. // And that is what is being queried... for any degree of usefulness.
  6757. return ( isAnd ? p1.recurring === patternMatched : patternMatched );
  6758. // returns truthy pattern that intersects.
  6759. }
  6760. , __willPatternsIntersect( p1, p2 ){
  6761. if(p1.from && p2.to && p2.to <= p1.from) return false;
  6762. if(p2.from && p1.to && p1.to <= p2.from) return false;
  6763. var areMonthsSelected = monthsMask & p2.recurring;
  6764. var areDatesSelected = datesMask & p2.recurring;
  6765. var areDaysSelected = daysMask & p2.recurring;
  6766. // PB : TODO -- Gaurd against impossible patters like 29th Feb, 31st April etc...
  6767. if(!areMonthsSelected && !areDatesSelected && !areDaysSelected) {
  6768. console.error("Null patterns are useless for selection. This is probably not a recurring pattern");
  6769. return null; // Null patterns result in null intersection.
  6770. }
  6771. var isAnd = false;
  6772. if(!areMonthsSelected && !areDatesSelected || !areMonthsSelected && !areDaysSelected || !areDatesSelected && !areDaysSelected ) ;
  6773. else {
  6774. isAnd = p2.isAnd;
  6775. }
  6776. var areP1MonthsSelected = monthsMask & p1.recurring;
  6777. var areP1DatesSelected = datesMask & p1.recurring;
  6778. var areP1DaysSelected = daysMask & p1.recurring;
  6779. // PB : TODO -- Gaurd against impossible patters like 29th Feb, 31st April etc...
  6780. if(!areP1MonthsSelected && !areP1DatesSelected && !areP1DaysSelected) {
  6781. console.error("Null patterns are useless for selection. This is probably not a recurring pattern");
  6782. return null; // Null patterns result in null intersection.
  6783. }
  6784. var isP1And = false;
  6785. if(!areP1MonthsSelected && !areP1DatesSelected || !areP1MonthsSelected && !areP1DaysSelected || !areP1DatesSelected && !areP1DaysSelected ) ;
  6786. else {
  6787. isP1And = p1.isAnd;
  6788. }
  6789. if(isAnd && isP1And === isAnd ) {
  6790. return p1.recurring === p2.recurring;
  6791. }
  6792. else if(isAnd) {
  6793. matchtarget = p2.recurring ;
  6794. }
  6795. else if(isP1And ) {
  6796. matchtarget = p1.recurring ;
  6797. }
  6798. var patternMatched = p1.recurring & p2.recurring;
  6799. // In the and case asserts if p1 is a subset of p2 not the other way around. A recurring pattern should always be a superset of an event.
  6800. // And that is what is being queried... for any degree of usefulness.
  6801. var __patternMatched = ( isAnd || isP1And ? matchtarget === patternMatched : patternMatched );
  6802. if(__patternMatched) {
  6803. if(p1.start && p2.end && p2.end <= p1.start) return false;
  6804. if(p2.start && p1.end && p1.end <= p2.start) return false;
  6805. return true;
  6806. }
  6807. else {
  6808. return false
  6809. }
  6810. // returns truthy pattern that intersects.
  6811. }
  6812. , __recurringHasIntersection(e1, r1){
  6813. // PB : TODO -- Date patterns UTC or Local ? i.e does a Monday mask match UTC Mondays or Local Mondays ????
  6814. // PB : TODO -- Use recunrence generator insteadof startOf today hack based on simplified same day start end assumptions.
  6815. if(e1.from && r1.to && r1.to <= e1.from) return false;
  6816. if(r1.from && e1.to && e1.to <= r1.from) return false;
  6817. // Returns intersection or false.
  6818. return ( utils.timeUtils.__hasPatternIntersection(e1, r1) ) ? (()=>{
  6819. // new Date ( new Date( this.rdata.get('unavailablefrom') ) - new Date( moment().startOf('day') ) )
  6820. var startOfe1 = new Date( moment__default['default'](e1.from).startOf('day') );
  6821. var r1E = {
  6822. from: new Date(startOfe1.getTime() + r1.start.getTime() + utils.getTZOffsetMilliseconds() )
  6823. , to: new Date(startOfe1.getTime() + r1.end.getTime() + utils.getTZOffsetMilliseconds() )
  6824. };
  6825. return utils.timeUtils.__hasEventIntersection(e1, r1E)
  6826. })()
  6827. : false
  6828. }
  6829. // Checks if two non recurring i.e singular events intersect and if so returns the actual intersection.
  6830. , __hasEventIntersection(e1, e2){
  6831. // PB : TODO -- No assertions for invalid inputs e.from is expected to be <= e.to
  6832. if(!e1.from && !e1.to) return e2;
  6833. if(!e2.from && !e2.to) return e1;
  6834. var e1FromAnde2To = e1.from && e2.to;
  6835. var e2FromAnde1To = e2.from && e1.to;
  6836. var __aFrombTo = (a, b)=>{
  6837. // boundary value overlap is insufficient for intersection. At least 1 millisecond diff is required.
  6838. return (a.from >= b.to ? false
  6839. : a.to && a.to > b.to || !a.to ?
  6840. { from : b.from && b.from > a.from ? b.from : a.from, to : b.to }
  6841. : b.from && b.from >= a.to ? false : { from : b.from && b.from > a.from ? b.from : a.from, to : a.to }
  6842. )
  6843. };
  6844. var result = e1FromAnde2To ? __aFrombTo(e1, e2)
  6845. :( e2FromAnde1To ? __aFrombTo(e2, e1)
  6846. : /* e1FromAnde2To is false and e2FromAnde1To is false => either both froms or both tos exist */
  6847. e1.from ? { from: new Date(Math.max(e1.from, e2.from)) } : { to: new Date(Math.min(e1.to, e2.to)) });
  6848. return result
  6849. }
  6850. , exludeIntersection(freeTimes, e) {
  6851. // Removal of unavilable times will split and splice into the same freeTimes array.
  6852. for(var i =0; i < freeTimes.length; i++) {
  6853. var intersection = timeUtils.hasEventIntersection(freeTimes[i], e);
  6854. if(intersection) {
  6855. // Edit freetime to correct for current collision.
  6856. if(freeTimes[i].from >= intersection.from && freeTimes[i].to <= intersection.to) {
  6857. freeTimes.splice(i,1); i = i--;
  6858. }
  6859. else {
  6860. var right = Object.assign({}, freeTimes[i]);
  6861. right.from = intersection.to;
  6862. freeTimes[i].to = intersection.from;
  6863. if( right.from < right.to ) {
  6864. freeTimes.splice(++i,0, right); // Skip this we have already processed it.
  6865. }
  6866. }
  6867. }
  6868. }
  6869. }
  6870. , getFreeTimes( tRange, events, dimensions) {
  6871. var freeTimes = [tRange];
  6872. for(var eIdx = 0; eIdx < events.length; eIdx++) {
  6873. var e = events[eIdx];
  6874. timeUtils.exludeIntersection(freeTimes, e);
  6875. if(freeTimes.length === 0) break;
  6876. }
  6877. // { result : freeTimes.length > 0, freeTimes : freeTimes}
  6878. return freeTimes;
  6879. }
  6880. // PB : TODO -- Timeutils Test cases. Comment in production.
  6881. , testAll(){
  6882. // // Disjoint
  6883. // var expected = false
  6884. // var actual = null;
  6885. expected = 2**4 + 2**(6+21) + 2**(5+31+6);
  6886. actual = this.toRecurringPattern(
  6887. { from : new Date('5/21/2020, 11:45:00 PM'), to : new Date('5/22/2020, 00:15:00 AM') } ).recurring;
  6888. if(expected !== actual ) throw (' TEST FAILED toRecurringPattern : expected = ' + expected + ' actual = ' + actual)
  6889. // actual = this.__hasEventIntersection(
  6890. // { from : new Date('5/21/2020, 11:45:00 PM'), to : new Date('5/22/2020, 00:15:00 AM') }
  6891. // , { from : new Date('5/22/2020, 11:45:00 PM'), to : new Date('5/23/2020, 00:15:00 AM') })
  6892. // if(expected !== actual ) throw (' TEST FAILED Disjoint : expected = ' + expected + ' actual = ' + actual)
  6893. // // Interleaved
  6894. // expected = JSON.stringify({ from : new Date('5/22/2020, 00:00:00 AM'), to : new Date('5/22/2020, 00:15:00 AM') })
  6895. // actual = this.__hasEventIntersection(
  6896. // { from : new Date('5/21/2020, 11:45:00 PM'), to : new Date('5/22/2020, 00:15:00 AM') }
  6897. // , { from : new Date('5/22/2020, 00:00:00 AM'), to : new Date('5/22/2020, 00:30:00 AM') })
  6898. // if(expected !== JSON.stringify(actual) ) throw (' TEST FAILED Interleaved : expected = ' + expected + ' actual = ' + JSON.stringify(actual))
  6899. // // Subset
  6900. // expected = JSON.stringify({ from : new Date('5/22/2020, 00:00:00 AM'), to : new Date('5/22/2020, 00:10:00 AM') })
  6901. // actual = this.__hasEventIntersection(
  6902. // { from : new Date('5/21/2020, 11:45:00 PM'), to : new Date('5/22/2020, 00:15:00 AM') }
  6903. // , { from : new Date('5/22/2020, 00:00:00 AM'), to : new Date('5/22/2020, 00:10:00 AM') })
  6904. // if(expected !== JSON.stringify(actual) ) throw (' TEST FAILED Interleaved : expected = ' + expected + ' actual = ' + JSON.stringify(actual))
  6905. // Null
  6906. // Boundary Test Cases....
  6907. var r1 = {
  6908. end: new Date("1970-01-01T11:00:00.000Z")
  6909. , every: null
  6910. , from: new Date("2020-06-04T06:30:00.000Z")
  6911. , id: "DC664060-A0A8-11EA-8B3D-7771F3D49CC1"
  6912. , migrationstate: 1
  6913. , practitionerId: "5FDF1790-8288-11E9-9044-91D8D8658887"
  6914. , purpose: "Meeting"
  6915. , recurring: 106
  6916. , start: new Date("1970-01-01T06:30:00.000Z")
  6917. , status: "SCHEDULED"
  6918. , to: null
  6919. };
  6920. var e1 = {
  6921. availability: false
  6922. , end: null
  6923. , every: null
  6924. , for: null
  6925. , from: new Date("2020-06-08T11:00:00.000Z")
  6926. , id: "AEC5A7E1-A96D-11EA-8DE7-19E354C126F4"
  6927. , migrationstate: 8
  6928. , patientId: "271F4970-F173-4530-A894-68F520BF7945"
  6929. , patientmob: "9944715969"
  6930. , patientname: "SAMUEL RAJA DURAI J"
  6931. , practitionerId: "5FDF1790-8288-11E9-9044-91D8D8658887"
  6932. , purpose: "Appointment"
  6933. , start: null
  6934. , status: "SCHEDULED"
  6935. , to: new Date("2020-06-08T11:15:00.000Z")
  6936. };
  6937. this.hasEventIntersection(e1, r1);
  6938. debugger
  6939. // Iterators
  6940. var eventIterator = this.getEventGenerator({ recurring : 2**1 }); // All Mondays from today.
  6941. for(var i=0, e; i<10 && !(e=eventIterator.next()).done; i++) {
  6942. console.dir(e);
  6943. }
  6944. }
  6945. };
  6946. function promisify(ctx, asyncoperation, arraylikearguments) {
  6947. var originalcallback = arraylikearguments.splice(arraylikearguments.length-1, 1)[0];
  6948. return new Promise(function(resolve, reject) {
  6949. asyncoperation.call(ctx, ...arraylikearguments, function(err, result) {
  6950. if (err) return reject(arguments);
  6951. resolve(arguments);
  6952. });
  6953. }).then((aArr)=>{
  6954. originalcallback(...aArr);
  6955. return aArr[1]
  6956. }).catch(function(aArr){
  6957. originalcallback(...aArr);
  6958. throw aArr[0];
  6959. });
  6960. }
  6961. var Tasq$1 = (function(){
  6962. var __proto__ = {
  6963. };
  6964. var listeners = [];
  6965. function Tasq(first, ...rest){
  6966. first.info = utils.assign({ args : rest }, __proto__);
  6967. return first
  6968. }
  6969. Tasq.create = Tasq;
  6970. Tasq.addlistener = (l)=>{ listeners.push(l); };
  6971. Tasq.catch = (e)=>{ console.error(e); console.error(e.messages.join(' ')); listeners.forEach(l => { l(e); } );};
  6972. Tasq.then = (d)=>{ listeners.forEach(l => { l(null, d); } ); return d};
  6973. return Tasq
  6974. })();
  6975. var Traq$1 = (function(){
  6976. var __proto__ = {};
  6977. var log = {
  6978. SUCCESS : []
  6979. , FAILURE : []
  6980. , SKIPPED : []
  6981. };
  6982. Traq$1 = function(){ return utils.assign({}, __proto__) };
  6983. Traq$1.create = Traq$1;
  6984. Traq$1.statuslog = statuslog;
  6985. function statuslog(err, data){
  6986. if(err) log.FAILURE.push( {err, data} );
  6987. else log.SUCCESS.push(data);
  6988. }
  6989. Traq$1.notify = (event)=>{
  6990. if(event.error) log.FAILURE.push( event );
  6991. else log.SUCCESS.push(event);
  6992. };
  6993. Traq$1.finally = ()=>{
  6994. console.log('Total : ' + (log.SKIPPED.length + log.SUCCESS.length + log.FAILURE.length));
  6995. console.log('Pass : ' + log.SUCCESS.length );
  6996. console.log('Fail : ' + log.FAILURE.length);
  6997. console.log('Skipped : ' + log.SKIPPED.length);
  6998. console.log('FAILURES');
  6999. console.log([JSON.stringify(log.FAILURE)]);
  7000. };
  7001. return Traq$1
  7002. })();
  7003. var tzoffset = 0;
  7004. var utils = {
  7005. escapeRegExp(string) {
  7006. return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
  7007. }
  7008. , getTZOffsetMilliseconds : (()=>{
  7009. var d = new Date();
  7010. var t1 = d.toISOString().replace('Z','');
  7011. var t2 = d.toISOString();
  7012. tzoffset = ( new Date(t2) - (new Date(t1))); // /60/60/1000 -- milliseconds.
  7013. return ()=>{ return tzoffset}
  7014. })()
  7015. , getLocalDateYYYYMMDD(date){
  7016. var d = new Date();
  7017. d.setTime(tzoffset + new Date(date).getTime());
  7018. return d.toISOString().slice(0,10).replace(/-/g,"")
  7019. }
  7020. , assign(target /** , ...sources */) {
  7021. return utils.assign_core(false, ...arguments)
  7022. }
  7023. , assign_caseless(target /** , ...sources */) {
  7024. return utils.assign_core(true, ...arguments)
  7025. }
  7026. // assign
  7027. , assign_core(ignorecase, target /** , ...sources */) {
  7028. // Important use this instead of Object.assign.
  7029. // Object.assign has several limitations.
  7030. // 1) It doesn't skip intermediates if the final overriden value is already determined.
  7031. // This implementation address this.
  7032. // 2) It is shallow and doesn't clone object references and therefore risks side effects to original nested objects.
  7033. // This implementation deep clones objects arrays and other types with some limitations.
  7034. // 3) Does not merge but allways overrides.
  7035. // Merges objects and arrays. Overides primitives.
  7036. // Array merge is by default a concatenation.
  7037. // PB : TODO -- If corresponding array indices have objects they can be merged like lodash.
  7038. // 4) Does not retain non writable and configurable attributes.
  7039. // This implementation copies descirptors so clones retain non writability and configurability identical to the source.
  7040. // 5) Recursion can cause infinite recursion. Object.assign doesn't deal with this.
  7041. // Detects and avides ininite recursion.
  7042. var cpi = {}; // Caseless property index of already processed target keys. Since we do not alter the target key we need a lookup that gives the actual key.
  7043. var getNormalizedKey = ignorecase ? (key)=>key : (key)=> key.toLowerCase(); // returns a normalized equivalent key.
  7044. // We do a right to left iterations!
  7045. // overrideKeys = true;
  7046. // PB : Note -- IMPORTANT alreadyScanned has side effects..
  7047. var alreadyScanned = (key)=>{
  7048. Object.keys(target).forEach(k => {
  7049. cpi[k.toLowerCase()] = k;
  7050. if(cpi[k.toLowerCase()] !== k){
  7051. Object.defineProperty( target, cpi[k.toLowerCase()], Object.getOwnPropertyDescriptor(target, k) ); // Relocate to new overridden key
  7052. delete target[tkeys[tkidx]]; // PB : TODO -- review that accessors are not called during delete !
  7053. }
  7054. });
  7055. alreadyScanned = ()=>{ return true; }; // Dont do anything next time we are called.
  7056. // Its not necessary that we found it.
  7057. cpi[key.toLowerCase()] ? null : cpi[key.toLowerCase()] = key;
  7058. return false;
  7059. };
  7060. // PB : Note -- IMPORTANT findEqualKey has side effects..
  7061. var findEqualKey = (key) => {
  7062. // If equiv key on the target is what the target key should ultimately be we will cache all possible now.
  7063. // However in the overrideKeys case this is not true in which case we postpone until the first one found in the overrider.
  7064. {
  7065. if(alreadyScanned(key)) { cpi[key.toLowerCase()] ? null : cpi[key.toLowerCase()] = key; } }
  7066. var targetKey = cpi[key.toLowerCase()];
  7067. return { targetKey, propertyDescriptor : Object.getOwnPropertyDescriptor(target, targetKey) }
  7068. };
  7069. var hOP = Object.prototype.hasOwnProperty;
  7070. var __assign = function(ignorecase, target /** , ...sources */) {
  7071. if(utils.js.isUndefined(target)) return; // There is noting to assign to. We just play dumb. Why did the caller even call us ?
  7072. // PB : TODO -- we need a flag to support undefined overrides. Default behavior is to retain as much as possible.
  7073. // if(utils.js.isUndefined(arguments[arguments.length-1])) return undefined;
  7074. var undef = 0;
  7075. for(; undef < arguments.length-1 && utils.js.isUndefined(arguments[arguments.length-undef-1]); undef++); // Skip all undefined overrides.
  7076. if(undef === arguments.length-1) return target;
  7077. if(utils.js.isPrimitive(arguments[arguments.length-1-undef])) return arguments[arguments.length-1-undef];
  7078. else {
  7079. // PB : TODO -- Primitive targets cannot be preserved.
  7080. // Target should be decided on first non primitive discovery.
  7081. // Arrays don't work properly yet...
  7082. // We start with a temporary object and if there is a primitive override it will override this temporary object altogether.
  7083. // PB : TODO -- We could convert primitives to their respective object counterparts... Howeer strings with indexes and arrays will get messy.
  7084. if(utils.js.isPrimitive(target)) {
  7085. target = {};
  7086. } }
  7087. for(var
  7088. finalized = {} // One instance for each structurally corresponding key that has already been overridden. Order need not be guaranteed.
  7089. , overrideOrMerge = function (originalkey) {
  7090. // Decision merge or override default to the following.
  7091. // Primitives are overridden by non Primitives ( arrays or objects )
  7092. // Non Primitives are overridden by Primitives. There is no concept of assigning Primitives as new named attributes of Objects.
  7093. // Objects assigned to Objects will be merged.
  7094. // Arrays assigned to Arrays will be merged i.e concatenated. PB : TOOD -- Order will be ??? target then right to left for sources.
  7095. // PB : TODO -- We should avoid examining or tampering with the value during clone and should find another way to make this decision.
  7096. // We do not want side effects to occur while examining the value. Accessors and proxies can do this.
  7097. // Currently assuming simple use cases at this point...
  7098. // Ideally Accessor Descriptors should be postponed for evaluation when runtime access to value is required.
  7099. var { targetKey, dL } = findEqualKey(originalkey);
  7100. var dR = Object.getOwnPropertyDescriptor(this, originalkey);
  7101. if(!dL) {
  7102. // target did not have what it should be according to what was specifed. Lets check for other possibilities.
  7103. dL = Object.getOwnPropertyDescriptor(target, originalkey);
  7104. if(!dL) { Object.defineProperty( target, targetKey, dR ); finalized[targetKey] = true; return; }
  7105. }
  7106. if(!utils.js.isUndefined( dR.writable )) { // writable attribute is present only in Data Descriptor Case
  7107. var valR = this[originalkey]; // We can examine data descriptors without any side effects. ( PB : TODO -- Proxies ! are expected to be transparent !! )
  7108. if(utils.js.isPrimitive( valR )) {
  7109. finalized[targetKey] = true;
  7110. // Primitive values also are implicitly cloned by Data Descriptors when defineProperty is called.
  7111. // Advantage is writable / configurable permissions are retained instead of simple assignment.
  7112. Object.defineProperty( target, targetKey, dR );
  7113. return
  7114. }
  7115. // If its not primitive it may need to get merged if the Left value is also non primitive and of a compatible type...
  7116. }
  7117. // PB : TODO -- Data descriptor that is not writable needs to be handled !? proper check to handle value etc required.
  7118. if(utils.js.isUndefined( dR.writable ) || utils.js.isUndefined( dL.writable ) ){
  7119. // One or both of them is an accessor descriptor.
  7120. // If either one of them is an accessor we need to postpone the merge to runtime evaluation on access.
  7121. var dChosen = !utils.js.isUndefined( dL.writable ) ? dR : dL; // Figure out which one is the accessor.
  7122. // Accessor Descriptors cannot be examined due to possible side effects and possible differences
  7123. // in the value and its type at the point of execution.
  7124. // Since the accessed value here is meaningless we don't know what type it will eventually be at the point wehre
  7125. // real program code needs the value !!!
  7126. // There are 2 options
  7127. // 1) we could do a decoupling here (at clone time) and capture the value.
  7128. // 2) or we could postpone until run time evaluation.
  7129. // Since in either case We need to examine the value it may be superior to evaluate at runtime and decide then.
  7130. // Although decoupling is important and better done as early as possible the delayed value is more important.
  7131. // PB : TODO -- We should provide a pref to evaluate and decouple at clone time
  7132. // PB : TODO -- The postponing strategy has one more issue where delayed override can clobber target modifications on the left side.
  7133. // -- Causing unexpected values specifically when the delayed override value from the source is expected.
  7134. // Ideally the value that was set intermediately should supercede.
  7135. // -- The preferred behaviour implemented here is to decouple on first set such that the intermediate value set on the clone supercedes.
  7136. // Original getter needs to access value in original context.
  7137. // Setters need to be redirected to "cloned setter" in current context.
  7138. var ctx = this;
  7139. var dRGetter = !utils.js.isUndefined( dR.writable ) ? function(){ return dR.value} : dR.get;
  7140. var dLGetter = !utils.js.isUndefined( dL.writable ) ? function(){ return dL.value} : dL.get;
  7141. var valForSetter = null;
  7142. dR.configurable;
  7143. if(!utils.js.isUndefined( dL.writable )) {
  7144. // Oridinarily since we postpone we need to refrence and reevaluete valL also at access time coz the target val could have been switched.
  7145. // The target is now an accessor which gets decoupled on first set in that case there is no need to re-evaluate.
  7146. // These getters are still valid until such a first set happens until which time the valL remains
  7147. // It is therefore possible to cache the valL and use it instead of target[key] at access time....
  7148. var valL = target[targetKey];
  7149. if(utils.js.isPrimitive(valL)) { dChosen.get = function(){ return dRGetter.call(ctx) }; }
  7150. else { dChosen.get = function(){
  7151. // In this case decoupling could happen on first access instead of first set.
  7152. return utils.assign_core(ignorecase, valL, dRGetter.call(ctx))
  7153. };
  7154. }
  7155. }
  7156. else {
  7157. // rVal could be an accessor or a nonPrimitive. Either case it needs to be mreged in.
  7158. dChosen.get = function(){ return utils.assign_core(ignorecase, dLGetter.call(target), dRGetter.call(ctx)) };
  7159. }
  7160. // __setter ! Although this is running in the current context we cant use the dR.set setter like so dL.set = dR.set
  7161. // this is dangerous as we do not know what else the setter does !!!. We don't konw what the getter does either
  7162. // but we need to do a one time read in any case wheter at clone time or at access time.
  7163. dChosen.set = function(val) {
  7164. // First time set on clone decouples
  7165. dChosen.get = function() { return valForSetter};
  7166. dChosen.set = function(val) { return valForSetter = val };
  7167. dChosen.configurable = true;
  7168. Object.defineProperty( target, targetKey, dChosen );
  7169. return valForSetter = val
  7170. };
  7171. dChosen.configurable = true;
  7172. Object.defineProperty( target, targetKey, dChosen );
  7173. finalized[targetKey] = true;
  7174. return
  7175. }
  7176. // Neither is an accessor. valR is nonPrimitive, dL is not an Accessor
  7177. // Target is also a Data Descriptor. We can examine it as well to take a decision.
  7178. var valL = target[targetKey]; // We can examine data descriptors without any side effects. ( Proxies ! are expected to be transparent !! )
  7179. if(utils.js.isPrimitive( valL )) {
  7180. if(!utils.js.isNull( valR ) && !utils.js.isUndefined( valR )) {
  7181. finalized[targetKey] = true;
  7182. Object.defineProperty( target, targetKey, dR );
  7183. }
  7184. return
  7185. }
  7186. else {
  7187. // Neither is Primitive.
  7188. // console.log('Assign Iter...')
  7189. if(valL === valR) { finalized[targetKey] = true; return true;}
  7190. if(utils.js.isObject( valL ) && utils.js.isObject( valR )) { utils.assign_core(ignorecase, valL, valR ); finalized[targetKey] = true; return;}
  7191. if(utils.js.isArray( valL ) && utils.js.isArray( valR )) { target[targetKey] = valL.concat(valR); finalized[targetKey] = true; return;}
  7192. if(utils.js.isNull( valL ) || utils.js.isNull( valR )) { target[targetKey] = valR; finalized[targetKey] = true; return;}
  7193. if(utils.js.isUndefined( valL ) && utils.js.isUndefined( valR )) { target[targetKey] = valR; finalized[targetKey] = true; return;}
  7194. // Functions are tricky. Closures and bound functinos will continue to refer to source locations and could cause unpredictable behaviour.
  7195. // However if such bound functions are being used the intention must be retention of such linkage.
  7196. if(utils.js.isFunction( valL ) && utils.js.isFunction( valR )) { target[targetKey] = valR; return;}
  7197. // Unsupported assign / merge for property datemodified data types Thu Sep 10 2020 15:59:38 GMT+0530 (India Standard Time)
  7198. // , Thu Sep 10 2020 15:54:22 GMT+0530 (India Standard Time)
  7199. // SAM : TODO dates are not getting merged.
  7200. // if(utils.js.isDate( valL ) && utils.js.isDate( valR )) { target[targetKey] = valR; return;}
  7201. var msg = `Unsupported assign / merge for property ${targetKey} data types ` + valL + ' , ' + valR;
  7202. console.error(msg);
  7203. throw msg;
  7204. }
  7205. }
  7206. , appendmissing = function (originalkey) {
  7207. var standardizedKey = getNormalizedKey(originalkey);
  7208. if (!hOP.call(finalized, standardizedKey)) overrideOrMerge.call(this, originalkey);
  7209. }
  7210. // Start from the rightmost and override or merge.
  7211. , _junkvar = Object.keys(arguments[arguments.length-1-undef]).forEach(overrideOrMerge, arguments[arguments.length-1-undef])
  7212. , i = arguments.length-1-undef;
  7213. 2 < i--;
  7214. utils.js.isUndefined(arguments[i]) ? null :
  7215. // Intermediate primitives are useless. Skipped coz the target has already been assigned.
  7216. utils.js.isPrimitive(arguments[i]) ? null
  7217. : Object.keys(arguments[i]).forEach(appendmissing, arguments[i])
  7218. ){}
  7219. return target;
  7220. };
  7221. return __assign(...arguments)
  7222. }
  7223. // PB : TODO -- Proper type checking.
  7224. // , __TPL__typeHandlers : {
  7225. // '[object String]' : defaultFn
  7226. // , '[object Array]' : defaultFn
  7227. // , '[object Object]' : defaultFn
  7228. // , '[object Null]' : defaultFn
  7229. // , '[object Undefined]' : defaultFn
  7230. // , '[object Date]' : defaultFn
  7231. // , '[object RegExp]' : defaultFn
  7232. // , '[object Function]' : defaultFn
  7233. // }
  7234. // PB : TODO -- Proper type checking.
  7235. // Javascript language utilities that should have been really in the language itself.
  7236. , js : {
  7237. typeInstances : [
  7238. ""
  7239. , 0
  7240. , true
  7241. , null
  7242. , // undefined
  7243. , []
  7244. , {}
  7245. , Symbol()
  7246. , new Date()
  7247. , /.*/
  7248. , Promise.resolve(true)
  7249. , function() {}
  7250. , BigInt(0)
  7251. ]
  7252. , proxyable : []
  7253. , nonproxyable : []
  7254. , isString(x) {
  7255. return Object.prototype.toString.call(x) === "[object String]"
  7256. }
  7257. , isNumber(x) {
  7258. return Object.prototype.toString.call(x) === '[object Number]'
  7259. }
  7260. , isBoolean(x) {
  7261. return Object.prototype.toString.call(x) === '[object Boolean]'
  7262. }
  7263. , isNull(x) {
  7264. return Object.prototype.toString.call(x) === '[object Null]'
  7265. }
  7266. , isUndefined(x) {
  7267. return Object.prototype.toString.call(x) === '[object Undefined]'
  7268. }
  7269. , isArray(x) {
  7270. return Object.prototype.toString.call(x) === '[object Array]'
  7271. }
  7272. , isObject(x) {
  7273. return Object.prototype.toString.call(x) === '[object Object]'
  7274. }
  7275. , isSymbol(x) {
  7276. return Object.prototype.toString.call(x) === '[object Symbol]'
  7277. }
  7278. , isDate(x) {
  7279. return Object.prototype.toString.call(x) === '[object Date]'
  7280. }
  7281. , isRegExp(x) {
  7282. return Object.prototype.toString.call(x) === '[object RegExp]'
  7283. }
  7284. , isPromise(x) {
  7285. return Promise.resolve(x) === x
  7286. }
  7287. , isPromiseOrFunction(o) {
  7288. if(utils.js.isPromise( o ) || utils.js.isFunction(o)) return true;
  7289. return false;
  7290. }
  7291. , isFunction(x) {
  7292. return Object.prototype.toString.call(x) === '[object Function]'
  7293. }
  7294. , isBigInt(x) {
  7295. return Object.prototype.toString.call(x) === '[object BigInt]'
  7296. }
  7297. , isDataDescriptor(d) { return (utils.js.isUndefined(d.set) && utils.js.isUndefined(d.get)) ? d : false }
  7298. // Grouping JS Types into 4 Groups
  7299. // Primitives
  7300. // -- boolean, String, Number
  7301. // Arrays
  7302. // Objects
  7303. // Special
  7304. // -- date, regexp, function ... and other unkown types
  7305. , typeGroups() {
  7306. return [
  7307. '[Primitive]'
  7308. , '[Null]'
  7309. , '[Undefined]'
  7310. , '[Symbol]'
  7311. , '[Array]'
  7312. , '[Object]'
  7313. , '[Special]'
  7314. ]
  7315. }
  7316. , typeGroup(x) {
  7317. var tgMap = {
  7318. '[object String]' : '[Primitive]'
  7319. , '[object Number]' : '[Primitive]'
  7320. , '[object Boolean]' : '[Primitive]'
  7321. , '[object Null]' : '[Null]'
  7322. , '[object Undefined]' : '[Undefined]'
  7323. , '[object Symbol]' : '[Symbol]'
  7324. , '[object BigInt]' : '[BigInt]'
  7325. , '[object Array]' : '[Array]'
  7326. , '[object Object]' : '[Object]'
  7327. , '[object Date]' : '[Special]'
  7328. , '[object RegExp]' : '[Special]'
  7329. , '[object Function]' : '[Special]'
  7330. , '[object Promise]' : '[Special]'
  7331. };
  7332. return tgMap[Object.prototype.toString.call(x)]
  7333. }
  7334. , getTypeInfo(x) {
  7335. var typeMap = {
  7336. '[object String]' : //__assign(typeInfo,
  7337. { typeGroup : '[Primitive]', isString : true, isPrimitive : true
  7338. , create : ()=>{return ""} }
  7339. //)
  7340. , '[object Number]' : { typeGroup : '[Primitive]', isNumber : true, isNumeric : true, isPrimitive : true
  7341. , create : ()=>{return 1}}
  7342. , '[object Boolean]' : { typeGroup : '[Primitive]', isBoolean : true, isPrimitive : true
  7343. , create : ()=>{return true}}
  7344. , '[object Null]' : { typeGroup : '[Null]', isNull : true
  7345. , create : ()=>{return null}}
  7346. , '[object Undefined]' : { typeGroup : '[Undefined]', isUndefined : true
  7347. , create : ()=>{return }}
  7348. , '[object Symbol]' : { typeGroup : '[Symbol]', isSymbol : true
  7349. , create : ()=>{return new Symbol()}}
  7350. , '[object BigInt]' : { typeGroup : '[BigInt]', isNumeric : true, isPrimitive : true
  7351. , create : ()=>{return new BigInt()}}
  7352. , '[object Array]' : { typeGroup : '[Array]', isArray : true
  7353. , create : ()=>{return []}}
  7354. , '[object Object]' : { typeGroup : '[Object]', isObject : true
  7355. , create : ()=>{return {}}}
  7356. , '[object Date]' : { typeGroup : '[Special]', isDate : true
  7357. , create : ()=>{return new Date}}
  7358. , '[object RegExp]' : { typeGroup : '[Special]', isRegExp : true
  7359. , create : ()=>{return new RegExp}}
  7360. , '[object Function]' : { typeGroup : '[Special]', isFunction : true
  7361. , create : ()=>{return new Function}}
  7362. , '[object Promise]' : { typeGroup : '[Special]', isPromise : true
  7363. , create : ()=>{ throw "Blank promise cannot be created."}}
  7364. };
  7365. return typeMap[Object.prototype.toString.call(x)]
  7366. }
  7367. , isPrimitive(x) {
  7368. var xType = this.nativeType(x);
  7369. return xType === '[object Boolean]' || xType === '[object String]' || xType === '[object Number]' || xType === '[object Symbol]' ||
  7370. xType === '[object BigInt]'
  7371. }
  7372. , isSpecial(x) {
  7373. return !isArray(x) && !isObject(x) && !isPrimitive(x)
  7374. }
  7375. , nativeTypes() {
  7376. return [
  7377. // Primitives
  7378. '[object String]'
  7379. , '[object Number]'
  7380. , '[object Boolean]'
  7381. , '[object Null]'
  7382. , '[object Undefined]'
  7383. , '[object Symbol]'
  7384. , '[object BigInt]'
  7385. // Non Primitives.
  7386. , '[object Array]'
  7387. , '[object Object]'
  7388. , '[object Date]'
  7389. , '[object RegExp]'
  7390. , '[object Function]'
  7391. , '[object Promise]'
  7392. ]
  7393. }
  7394. , nativeType(x) { return Object.prototype.toString.call(x) }
  7395. }
  7396. // Upsert for a hash ??
  7397. , hashupsert : function(oA, oB){
  7398. Object.keys(oA).forEach(( oAKey )=>{
  7399. if(oB[oAKey]) {
  7400. var distinct = new Set(oA[oAKey]);
  7401. oB[oAKey].forEach((each)=>{
  7402. distinct.add(each);
  7403. });
  7404. oA[oAKey] = Array.from(distinct);
  7405. }
  7406. });
  7407. }
  7408. // Upsert for an array.
  7409. // Also the same as pushdistinct. Target is expected to have only one instance.
  7410. , upsert(arr, val) {
  7411. // 0 -- did nothing
  7412. // 2 -- inserted
  7413. // 3 -- updated
  7414. // PB: TODO -- We can use (new Set(arr)).add ???. But is this more expensive ?
  7415. var found = arr.find((element)=>{ return element === val});
  7416. return found ? utils.js.isObject(val) && utils.js.isObject(val) ? (Object.assign( found, val), 3) : 0
  7417. : (arr.push(val), 2) ;
  7418. }
  7419. // accumulate
  7420. // o[toVectorPropName] which is an array
  7421. // and o[propName] which is a string
  7422. // into vectorTarget which is an array
  7423. // already previously accumulated in a similar manner probably already attached as oTarget[toVectorPropName]
  7424. // 0 or undefined or null -- didnt do anything. ( val doesn't exist )
  7425. // 1 -- created target and inserted val
  7426. // 2 -- didn't create target but inserted val
  7427. // 3 -- didn't create target but updated val and also handled o[propName].
  7428. , accumulate : function(val, o, propName, toVectorPropName, vectorTargetCreator,
  7429. identityEvaluator
  7430. ){
  7431. var created = 0;
  7432. if(utils.js.isUndefined(val)) return; // Nothing to do i.e. nothing was provided to accumulate. We don't accumulate undefined.
  7433. if(val === o[propName]) return; // Nothing to do.
  7434. var vectorTargetContainer = o[toVectorPropName] || (o[toVectorPropName] = {});
  7435. if(!vectorTargetCreator) vectorTargetCreator = { create : (val)=>{
  7436. return val ? vectorTargetContainer[o["id"]] = [val] : [] } };
  7437. var vectorTarget = vectorTargetContainer[o["id"]];
  7438. if(!vectorTarget) {
  7439. created = 1;
  7440. vectorTarget = vectorTargetContainer[o["id"]] = vectorTargetCreator.create(o[propName]);
  7441. }
  7442. if(!identityEvaluator) identityEvaluator = (a, b)=>{ return a === b };
  7443. var upsertResult = 0;
  7444. if(!created && !utils.js.isUndefined(o[propName])) {
  7445. if(!vectorTargetContainer[o["id"]].find((element)=>{ return identityEvaluator(element, o[propName]) })) {
  7446. upsertResult = utils.upsert(vectorTarget, o[propName]);
  7447. }
  7448. }
  7449. upsertResult = utils.upsert(vectorTarget, val);
  7450. return created ? created : upsertResult;
  7451. }
  7452. // async Utils
  7453. , async : {
  7454. all(list, task){
  7455. var queueditems=[];
  7456. list.forEach(function(v, i, a) {
  7457. queueditems.push(task(v, i, a));
  7458. });
  7459. return Promise.all(queueditems)
  7460. }
  7461. }
  7462. // PB : TODO -- Remove these.
  7463. // , fsdb : require('./fsdb/fsdb')
  7464. // , xlsx : require('./fsdb/xlsx')
  7465. // , xlsxvalidator : require('./fsdb/xlsxvalidator')
  7466. , timeUtils
  7467. , dx: dx_1
  7468. , cliargs: cliargs$1
  7469. , any: any$1
  7470. , promisify
  7471. , moment: moment__default['default']
  7472. , Tasq: Tasq$1
  7473. , Traq: Traq$1
  7474. };
  7475. var utils_1 = utils;
  7476. var naiveFallback = function () {
  7477. if (typeof self === "object" && self) return self;
  7478. if (typeof window === "object" && window) return window;
  7479. throw new Error("Unable to resolve global `this`");
  7480. };
  7481. // https://mathiasbynens.be/notes/globalthis
  7482. var globalThis_1 = (function () {
  7483. if (this) return this;
  7484. // Unexpected strict mode (may happen if e.g. bundled into ESM module)
  7485. // Fallback to standard globalThis if available
  7486. if (typeof globalThis === "object" && globalThis) return globalThis;
  7487. // Thanks @mathiasbynens -> https://mathiasbynens.be/notes/globalthis
  7488. // In all ES5+ engines global object inherits from Object.prototype
  7489. // (if you approached one that doesn't please report)
  7490. try {
  7491. Object.prototype.__defineGetter__('__global__', function() {
  7492. return this;
  7493. });
  7494. __global__.globalThis = __global__; // lolwat
  7495. } catch (error) {
  7496. // Unfortunate case of updates to Object.prototype being restricted
  7497. // via preventExtensions, seal or freeze
  7498. return naiveFallback();
  7499. }
  7500. try {
  7501. // Safari case (window.__global__ works, but __global__ does not)
  7502. if (!__global__) return naiveFallback();
  7503. return __global__;
  7504. } finally {
  7505. delete Object.prototype.__global__;
  7506. }
  7507. })();
  7508. // A selector based channels implementation as compared to a simple array.
  7509. var channelMixin = (function() {
  7510. // get channels that qualify for a selector.
  7511. function getSubscriptions(selector) {
  7512. console.dir(this.__channels);
  7513. var filtered = this.__channels; // start with the world...
  7514. // Selector is a simple list of tags.
  7515. for(var select in selector) {
  7516. if(!filtered[selector[select]]) {
  7517. // If the assumption is that all indexes are properly built it implies this channel doesn't exist.
  7518. return []; // We are looking for all selectors therefore if even one fails we don't have anything.
  7519. }
  7520. filtered = filtered[selector[select]];
  7521. }
  7522. return filtered['__data']; // Flattened array
  7523. }
  7524. function addSubscription(selector, func, context) {
  7525. var unfulfilled = selector.splice(0);
  7526. var filtered = this.__channels; // start with the world...
  7527. console.log(filtered);
  7528. for(var select in unfulfilled) {
  7529. if(!filtered[unfulfilled[select]]) {
  7530. filtered[unfulfilled[select]] = { __data : [] };
  7531. }
  7532. filtered = filtered[unfulfilled[select]];
  7533. unfulfilled = unfulfilled.splice(0,1);
  7534. }
  7535. // PB : TODO -- All accessor paths need to be indexed !
  7536. // Will currently fail if not published and queried in the same order.
  7537. filtered.__data.push({context: context, callback: func});
  7538. }
  7539. return function(){
  7540. this.__channels = {};
  7541. this.getSubscriptions = getSubscriptions;
  7542. this.addSubscription = addSubscription;
  7543. return this;
  7544. }
  7545. })();
  7546. // Mediator pattern.
  7547. var mediator = (function() {
  7548. var __subscribe = function(selector, func, context) {
  7549. var subscriptions = this.channels.getSubscriptions(selector);
  7550. if(subscriptions.length < 1){
  7551. this.channels.addSubscription(selector, func, context);
  7552. }
  7553. return this;
  7554. };
  7555. var __publish = function(selector) {
  7556. console.log('publishing for selector ' + selector);
  7557. var subscriptions = this.channels.getSubscriptions(selector);
  7558. console.log(subscriptions);
  7559. if(subscriptions.length < 1){ return; }
  7560. var args = Array.prototype.slice.call(arguments, 1);
  7561. for(i=0; i < subscriptions.length; i++) {
  7562. subscription = subscriptions[i];
  7563. subscription.callback.apply(subscription.context, args);
  7564. }
  7565. return this;
  7566. };
  7567. return function mediator() {
  7568. var thisObj = this ? this : {};
  7569. Object.defineProperty(thisObj, 'channels', { value : channelMixin.apply({}), writable: false, enumerable : false});
  7570. thisObj.publish = __publish;
  7571. thisObj.subscribe = __subscribe;
  7572. return thisObj;
  7573. };
  7574. })();
  7575. // Unique ID creation requires a high quality random # generator. In node.js
  7576. // this is pretty straight-forward - we use the crypto API.
  7577. var rng = function nodeRNG() {
  7578. return crypto__default['default'].randomBytes(16);
  7579. };
  7580. /**
  7581. * Convert array of 16 byte values to UUID string format of the form:
  7582. * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
  7583. */
  7584. var byteToHex = [];
  7585. for (var i$1 = 0; i$1 < 256; ++i$1) {
  7586. byteToHex[i$1] = (i$1 + 0x100).toString(16).substr(1);
  7587. }
  7588. function bytesToUuid(buf, offset) {
  7589. var i = offset || 0;
  7590. var bth = byteToHex;
  7591. // join used to fix memory issue caused by concatenation: https://bugs.chromium.org/p/v8/issues/detail?id=3175#c4
  7592. return ([bth[buf[i++]], bth[buf[i++]],
  7593. bth[buf[i++]], bth[buf[i++]], '-',
  7594. bth[buf[i++]], bth[buf[i++]], '-',
  7595. bth[buf[i++]], bth[buf[i++]], '-',
  7596. bth[buf[i++]], bth[buf[i++]], '-',
  7597. bth[buf[i++]], bth[buf[i++]],
  7598. bth[buf[i++]], bth[buf[i++]],
  7599. bth[buf[i++]], bth[buf[i++]]]).join('');
  7600. }
  7601. var bytesToUuid_1 = bytesToUuid;
  7602. // **`v1()` - Generate time-based UUID**
  7603. //
  7604. // Inspired by https://github.com/LiosK/UUID.js
  7605. // and http://docs.python.org/library/uuid.html
  7606. var _nodeId;
  7607. var _clockseq;
  7608. // Previous uuid creation time
  7609. var _lastMSecs = 0;
  7610. var _lastNSecs = 0;
  7611. // See https://github.com/broofa/node-uuid for API details
  7612. function v1(options, buf, offset) {
  7613. var i = buf && offset || 0;
  7614. var b = buf || [];
  7615. options = options || {};
  7616. var node = options.node || _nodeId;
  7617. var clockseq = options.clockseq !== undefined ? options.clockseq : _clockseq;
  7618. // node and clockseq need to be initialized to random values if they're not
  7619. // specified. We do this lazily to minimize issues related to insufficient
  7620. // system entropy. See #189
  7621. if (node == null || clockseq == null) {
  7622. var seedBytes = rng();
  7623. if (node == null) {
  7624. // Per 4.5, create and 48-bit node id, (47 random bits + multicast bit = 1)
  7625. node = _nodeId = [
  7626. seedBytes[0] | 0x01,
  7627. seedBytes[1], seedBytes[2], seedBytes[3], seedBytes[4], seedBytes[5]
  7628. ];
  7629. }
  7630. if (clockseq == null) {
  7631. // Per 4.2.2, randomize (14 bit) clockseq
  7632. clockseq = _clockseq = (seedBytes[6] << 8 | seedBytes[7]) & 0x3fff;
  7633. }
  7634. }
  7635. // UUID timestamps are 100 nano-second units since the Gregorian epoch,
  7636. // (1582-10-15 00:00). JSNumbers aren't precise enough for this, so
  7637. // time is handled internally as 'msecs' (integer milliseconds) and 'nsecs'
  7638. // (100-nanoseconds offset from msecs) since unix epoch, 1970-01-01 00:00.
  7639. var msecs = options.msecs !== undefined ? options.msecs : new Date().getTime();
  7640. // Per 4.2.1.2, use count of uuid's generated during the current clock
  7641. // cycle to simulate higher resolution clock
  7642. var nsecs = options.nsecs !== undefined ? options.nsecs : _lastNSecs + 1;
  7643. // Time since last uuid creation (in msecs)
  7644. var dt = (msecs - _lastMSecs) + (nsecs - _lastNSecs)/10000;
  7645. // Per 4.2.1.2, Bump clockseq on clock regression
  7646. if (dt < 0 && options.clockseq === undefined) {
  7647. clockseq = clockseq + 1 & 0x3fff;
  7648. }
  7649. // Reset nsecs if clock regresses (new clockseq) or we've moved onto a new
  7650. // time interval
  7651. if ((dt < 0 || msecs > _lastMSecs) && options.nsecs === undefined) {
  7652. nsecs = 0;
  7653. }
  7654. // Per 4.2.1.2 Throw error if too many uuids are requested
  7655. if (nsecs >= 10000) {
  7656. throw new Error('uuid.v1(): Can\'t create more than 10M uuids/sec');
  7657. }
  7658. _lastMSecs = msecs;
  7659. _lastNSecs = nsecs;
  7660. _clockseq = clockseq;
  7661. // Per 4.1.4 - Convert from unix epoch to Gregorian epoch
  7662. msecs += 12219292800000;
  7663. // `time_low`
  7664. var tl = ((msecs & 0xfffffff) * 10000 + nsecs) % 0x100000000;
  7665. b[i++] = tl >>> 24 & 0xff;
  7666. b[i++] = tl >>> 16 & 0xff;
  7667. b[i++] = tl >>> 8 & 0xff;
  7668. b[i++] = tl & 0xff;
  7669. // `time_mid`
  7670. var tmh = (msecs / 0x100000000 * 10000) & 0xfffffff;
  7671. b[i++] = tmh >>> 8 & 0xff;
  7672. b[i++] = tmh & 0xff;
  7673. // `time_high_and_version`
  7674. b[i++] = tmh >>> 24 & 0xf | 0x10; // include version
  7675. b[i++] = tmh >>> 16 & 0xff;
  7676. // `clock_seq_hi_and_reserved` (Per 4.2.2 - include variant)
  7677. b[i++] = clockseq >>> 8 | 0x80;
  7678. // `clock_seq_low`
  7679. b[i++] = clockseq & 0xff;
  7680. // `node`
  7681. for (var n = 0; n < 6; ++n) {
  7682. b[i + n] = node[n];
  7683. }
  7684. return buf ? buf : bytesToUuid_1(b);
  7685. }
  7686. var v1_1 = v1;
  7687. // var __g = __G.__g;
  7688. globalThis_1.mediator = mediator.apply({});
  7689. // __g.mediator = __g.mediator.apply({})
  7690. console.dir(globalThis_1.mediator);
  7691. const indexHelper = (function(){
  7692. var getPermutations = function(array){
  7693. var permutations = {};
  7694. // l(array.splice(0, 1))
  7695. for(var i in array) {
  7696. // l(array[i]);
  7697. var aclone = array.slice(0);
  7698. aclone.splice(i, 1);
  7699. permutations[array[i]] = getPermutations(aclone );
  7700. }
  7701. return permutations
  7702. };
  7703. var getCombinations = function(array){
  7704. // P & C
  7705. // http://www.scielo.br/scielo.php?script=sci_arttext&pid=S0104-65002001000200009
  7706. var set = [];
  7707. var alen = array.length;
  7708. var combinations = 1 << alen; // Math.pow(2, array.length);
  7709. for (var i = 1; i < combinations ; i++){
  7710. var combination= [];
  7711. for (var j=0;j<alen;j++) {
  7712. if ((i & (1 << j))){
  7713. combination.push(array[j]);
  7714. }
  7715. }
  7716. set.push(combination);
  7717. }
  7718. return set;
  7719. };
  7720. return function(obj) {
  7721. obj.getPermutations = getPermutations;
  7722. // obj.getPermutations = getPermutations_HeapsMethod;
  7723. obj.getCombinations = getCombinations;
  7724. return obj;
  7725. };
  7726. })();
  7727. const AnyStore = (function(){
  7728. // A store that can store any type and lookup any type.
  7729. // Weakmaps cannot have primitives as keys and hashs cannot have objects as keys.
  7730. // This wraps hash and a weakmap into an abstract class that routes to the appropriate
  7731. // store based on the type of the object.
  7732. const getForPrimitive = function(primitive, target) { return target.storeForPrmitives[primitive] };
  7733. const getForObject = function(obj, target) { return target.storeForObjects.get(obj) };
  7734. const getForSymbol = function(symbol, target) { return target.storeForObjects.get(target.__symbolToObj[symbol]) };
  7735. const setForPrimitive = function(primitive, content, target) {
  7736. // PB : -- Note : Importatn -- No difference between 100 and "100" due to JS keys all being strings...
  7737. target.storeForPrmitives[primitive] = content;
  7738. return content;
  7739. };
  7740. const setForObject = function(obj, content, target) {
  7741. // PB : TODO -- need to listen to changes in content and its attributes to re-index it.
  7742. target.storeForObjects.set(obj, content);
  7743. return content;
  7744. };
  7745. const setForSymbol = function(symbol, content, target) {
  7746. // PB : TODO -- need to listen to changes in content and its attributes to re-index it.
  7747. target.storeForObjects.set(target.__symbolToObj[symbol], content);
  7748. return content;
  7749. };
  7750. const getFor = {
  7751. '[object String]' : getForPrimitive
  7752. , '[object Object]' : getForObject
  7753. , '[object Symbol]' : getForSymbol
  7754. };
  7755. getFor['[object Number]'] = getFor['[object String]'];
  7756. getFor['[object Array]'] = getFor['[object Object]'];
  7757. const setFor = {
  7758. '[object String]' : setForPrimitive
  7759. , '[object Object]' : setForObject
  7760. , '[object Symbol]' : setForSymbol
  7761. };
  7762. setFor['[object Number]'] = setFor['[object String]'];
  7763. setFor['[object Array]'] = setFor['[object Object]'];
  7764. function IndexFactory(__symbolFromObj, __symbolToObj, valuecompare) {
  7765. // In some cases we are looking for value equivalence and in others referenced object equivalence.
  7766. // Implicit behavior is to use referenced object equivalence as valuecompare is undefined.
  7767. // What we really need is dereferencing until real value is reached.
  7768. // And value compare in scope even if the value is an extremely long stream of bits..
  7769. // Both of these are expensive in terms of scanning and finding the info required.
  7770. // p[p.Index(what, true)] !! is not a value compare for find.
  7771. // We also need to deal with sorting and filtering....
  7772. if(valuecompare) throw "Not yet implemented."
  7773. return function Index(anyThing, bDontCreate){ return utils_1.js.isPrimitive(anyThing) ? anyThing : (__symbolFromObj.get(anyThing) ? __symbolFromObj.get(anyThing) :
  7774. (()=>{
  7775. if(bDontCreate) return
  7776. var newSymbol = Symbol();
  7777. __symbolFromObj.set(anyThing, newSymbol);
  7778. __symbolToObj[newSymbol] = anyThing;
  7779. return newSymbol })()
  7780. ) }
  7781. }
  7782. function AnyStore(){
  7783. // Dispatch based on type of prop.
  7784. var targ = { storeForPrmitives : {}, storeForObjects : new WeakMap(), __symbolToObj : {}, __symbolFromObj : new WeakMap() };
  7785. var p = new Proxy( targ
  7786. , {
  7787. // PB : TODO -- Proxy handler gets hit for Index function prop..
  7788. get: function (target, prop) { return getFor[utils_1.js.nativeType(prop)](prop, target); }
  7789. , set: function (target, prop, content) { return setFor[utils_1.js.nativeType(prop)](prop, content, target); }
  7790. });
  7791. p.Index = IndexFactory(targ.__symbolFromObj, targ.__symbolToObj);
  7792. p.get = (what)=>{ return p[p.Index(what, true)] };
  7793. p.set = (what, content)=>{ return p[p.Index(what)] = content};
  7794. return p
  7795. }
  7796. AnyStore.create = AnyStore;
  7797. return AnyStore
  7798. })();
  7799. function expandUint32Array(arr, data) {
  7800. const newArray = new Uint32Array(arr.length + data.length);
  7801. newArray.set(arr); // copy old data
  7802. newArray.set(data, arr.length); // copy new data after end of old data
  7803. return newArray;
  7804. }
  7805. const HEX_FFFFFFFF = 0xFFFFFFFF;
  7806. const HEX_FFFF0000 = 0xFFFF0000;
  7807. const HEX_FF00 = 0xFF00;
  7808. const HEX_F0 = 0xF0;
  7809. const HEX_0C = 0x0C;
  7810. const MAX_32BITS = HEX_FFFFFFFF;
  7811. const MAX_53BITS = Number.MAX_SAFE_INTEGER;
  7812. const BIGINT_HEX_FFFFFFFF = BigInt(HEX_FFFFFFFF);
  7813. BigInt(HEX_FFFF0000);
  7814. BigInt(HEX_FF00);
  7815. BigInt(HEX_F0);
  7816. BigInt(HEX_0C);
  7817. const BIGINT_MAX_32BITS = BIGINT_HEX_FFFFFFFF;
  7818. const BIGINT_0 = BigInt(0);
  7819. const BIGINT_1 = BigInt(1);
  7820. BigInt(2);
  7821. BigInt(4);
  7822. BigInt(8);
  7823. BigInt(16);
  7824. const BIGINT_32 = BigInt(32);
  7825. // Only Positive numbers;
  7826. function *bigIntBufferGenerator(bn){
  7827. // len = len || find32BitArrLen(bn); // Inefficeint to detect. Lets just iterate and see where it ends...
  7828. var signal = {};
  7829. var stop = Symbol();
  7830. var i = 0;
  7831. for(;;){
  7832. var bits32 = new Uint32Array(1);
  7833. if(bn > MAX_32BITS){
  7834. bits32[0]= Number((bn & BIGINT_MAX_32BITS));
  7835. signal = (yield {i, bits32}) || {};
  7836. if(signal === stop || signal.done) return {i, bits32};
  7837. bn >>= BIGINT_32;
  7838. i++;
  7839. }
  7840. else {
  7841. bits32[0] = Number(bn);
  7842. return {i, bits32};
  7843. }
  7844. }
  7845. }
  7846. function bigIntToBuffer(bn) {
  7847. // if(utils.js.isUndefined(bn) || utils.js.isNull(bn)) throw 'bigIntToBuffer suported only for BigInts...'
  7848. if(!utils_1.js.isBigInt(bn)) throw 'bigIntToBuffer suported only for BigInts...'
  7849. // PB : Note -- bn must be passed in. Callee should validate.
  7850. var buffer = null;
  7851. var iterator = bigIntBufferGenerator(bn);
  7852. var next = iterator.next();
  7853. if(next && !next.done) buffer = next.value.bits32;
  7854. else return next.value.bits32;
  7855. while(!(next = iterator.next()).done) {
  7856. // PB : TODO -- Ineffficient copy in a loop !!
  7857. // It would be really nice to know how much space is needed. In the absence lets do binary expansion.
  7858. buffer = expandUint32Array(buffer, next.value.bits32);
  7859. }
  7860. buffer = expandUint32Array(buffer, next.value.bits32);
  7861. return buffer;
  7862. }
  7863. function bufferToBigInt(buffer) {
  7864. // PB : Note -- buffer must be a Uint32Array. Callee should validate.
  7865. var bn = BIGINT_0;
  7866. for(var i=buffer.length; --i > -1;){ bn <<= BIGINT_32; bn |= BigInt(buffer[i]); }
  7867. return bn;
  7868. }
  7869. // A bitmask can also be specified by a index number of the bit in a BitArray
  7870. // Implemented as a class to distinguish from a mask value.
  7871. // For convenieance mask value is provided the ability to be passed in as a Number althout BitIndexes are more naturally in the Number Space..
  7872. // mask values larger than 32 bits will implicitly need to be converted to BitArrays.
  7873. const BitIndex = (function() { function BitIndex(){ return this } // BitIndex constructor.
  7874. // Should support Numbers, BigInt and Uint32Array.
  7875. function __is__(t){ if(t === BitIndex) return true; }
  7876. function __is(type){ return typeof this === type ? true : __is__(type) }
  7877. function __create(n){
  7878. return BitIndex.apply({
  7879. value : n
  7880. , is : __is
  7881. })
  7882. }
  7883. __create.create = __create;
  7884. return __create
  7885. })();
  7886. // function leftshift(m){ return utils.js.isNumber(m) ? leftshift_Number(m) : leftshift_BigInt(m) } // Universal.
  7887. function leftshift_Number(m){ return m << 1 }
  7888. function leftshift_BigInt(m){ return m << BIGINT_1 }
  7889. // function leftshift_Uint32Array(m) { throw "leftshift_Uint32Array not yet implemented." }
  7890. function indexOfLSB32(x, gptwo){
  7891. // x needs to be a 32 bit number.
  7892. // Private functions don't do validations to avoid overhead of validation.
  7893. // Only public api's need to validate inputs.
  7894. if(x === 0) return null;
  7895. var i = 0;
  7896. x & 0xFFFF0000 && (i += 16, x >>= 16),
  7897. x & 0xFF00 && (i += 8, x >>= 8),
  7898. x & 0xF0 && (i += 4, x >>= 4),
  7899. x & 0x0C && (i += 2, x>>= 2),
  7900. x & 2 && (i += 1);
  7901. // x & 1 && (i = 0);
  7902. return i;
  7903. }
  7904. // PB : TODO -- Not yet implemented... profile to see if this is any more performant.
  7905. // function indexOfLSB_BigInt_DeBruijn(x, gptwo){
  7906. // // x needs to be a BigInt.
  7907. // // gptwo needs to be BigInt
  7908. // // Private functions don't do validations to avoid overhead of validation.
  7909. // // Only public api's need to validate inputs.
  7910. // if(x === 0) return null;
  7911. // gptwo = gptwo || x & -x;
  7912. // // DeBruijn explodes on multiplication and needs to work on BigInts even if the results are containted in 32 bits...
  7913. // // PB : TODO -- Not sure if this is faster. In any case BigInts are slower.
  7914. // var MultiplyDeBruijnBitPosition = [
  7915. // 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8,
  7916. // 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9
  7917. // ];
  7918. // return MultiplyDeBruijnBitPosition[( ( gptwo * BigInt( 0x077CB531 )) >> BigInt(27) ) % BigInt(32) ];
  7919. // }
  7920. // https://stackoverflow.com/questions/757059/position-of-least-significant-bit-that-is-set
  7921. // http://graphics.stanford.edu/~seander/bithacks.html
  7922. const BitArrayUpto32Bits = (function(){
  7923. function validateBitLength(length){ if(length > 32) throw 'BitArrayUpto32Bits doesnt accept BitLength > 32' }
  7924. function __createA(arr){
  7925. validateBitLength(arr.length);
  7926. var created = __create();
  7927. // PB : TODO -- Changes this to preincrement. Mask need not overflow for 32 bits...
  7928. var iterateUpto = [
  7929. ()=>{for(var i =0 ; i < 1; i++) { console.log(i); created.assignMask(arr[i], { title : arr[i]}); }}
  7930. , ()=>{for(var i =1 ; i < Math.min(31, arr.length); i++) { console.log(i); created.assignMask(arr[i], { title : arr[i]}, leftshift_Number ); }}
  7931. , ()=>{for(var i =31; i < Math.min(32, arr.length); i++) { console.log(i); created.assignMask(arr[i], { title : arr[i]}, (m)=>{ return leftshift_Number(m)>>>0 } ); }}
  7932. ];
  7933. arr.length > 31 ? iterateUpto.forEach(f=>f()) :
  7934. arr.length > 1 ? iterateUpto.slice(0,2).forEach(f=>f()) :
  7935. iterateUpto[0]();
  7936. return created;
  7937. }
  7938. function __createO(o){
  7939. var arr = Object.keys(o);
  7940. validateBitLength(arr.length);
  7941. var created = __create();
  7942. var iterateUpto = [
  7943. ()=>{for(var i =0 ; i < 1; i++) { console.log(i); created.assignMask(arr[i], o[arr[i]]); }}
  7944. , ()=>{for(var i =1 ; i < Math.min(31, arr.length); i++) { console.log(i); created.assignMask(arr[i], o[arr[i]], leftshift_Number ); }}
  7945. , ()=>{for(var i =31; i < Math.min(32, arr.length); i++) { console.log(i); created.assignMask(arr[i], o[arr[i]], (m)=>{ return leftshift_Number(m)>>>0 } ); }}
  7946. ];
  7947. arr.length > 31 ? iterateUpto.forEach(f=>f()) :
  7948. arr.length > 1 ? iterateUpto.slice(0,2).forEach(f=>f()) :
  7949. iterateUpto[0]();
  7950. return created;
  7951. }
  7952. function __create(){
  7953. var labels = {};
  7954. var masks = {};
  7955. var currentMaxMask;
  7956. function __nextMask(){ __nextMask = leftshift_Number;
  7957. return currentMaxMask = 1; }
  7958. // var store = ??? new Uint32Array(1)var mxn = Mixin.create()
  7959. utils_1.assign(mxn,
  7960. {
  7961. validateMask(m){
  7962. if(__is(m, BitIndex)) {
  7963. if(m > 32) throw 'BitArrayUpto32Bits doesnt accept BitIndex > 32'
  7964. return { BitIndex, labels : [masks[indexToMask(m.value)]]
  7965. // , indices : m.value
  7966. }
  7967. }
  7968. if(m > MAX_32BITS) throw "BitArrayUpto32Bits only supports numbers upto MAX_32BITS "
  7969. if(!utils_1.js.isNumber(+m)) throw "BitArrayUpto32Bits requires Numbers upto MAX_32BITS "
  7970. return true;
  7971. }
  7972. , labelsToMask : (__labels)=>{
  7973. var result = 0; __labels.forEach(l=>{ result |= labels[l]; });
  7974. return result >>> 0;
  7975. }
  7976. , hasMask : function(label) { return labels[label] ? labels[label].mask : null ; }
  7977. , maskToLabels(m, transformEach){
  7978. var valid = this.validateMask(m);
  7979. if(!valid) throw "Invalid Mask"
  7980. if(valid.BitIndex) return valid.labels;
  7981. var __labels = [];
  7982. for(var gptwo;gptwo=m&-m;m^=gptwo) {
  7983. if(!masks[gptwo]) { console.log('Error : Invalid mask passed in.'); }
  7984. else __labels.push( transformEach(masks[Number(gptwo)], labels[masks[Number(gptwo)]]) );
  7985. }
  7986. return __labels;
  7987. }
  7988. , labelToMask : (l)=>{ return labels[l] }
  7989. , bit_or : (a, b)=>a | b
  7990. , bit_and : (a, b)=>a & b
  7991. , bit_xor : (a, b)=>a ^ b
  7992. , bit_not : (a)=> ~a
  7993. , assignMask : function(label, entity, incrementFn) {
  7994. var lmask = this.hasMask(label); if(lmask) return lmask; // Already assigned.
  7995. labels[label] = entity;
  7996. labels[label].mask = currentMaxMask = incrementFn ? incrementFn(currentMaxMask) : __nextMask(); // Use the next unused mask for this dictionary of labels. Currently random. We should eventually have a sort order.
  7997. masks[labels[label].mask] = label;
  7998. return labels[label];
  7999. }
  8000. , msbIndex : function(v) { throw "msb Not yet implemented" }
  8001. , indexToMask : function(index) {
  8002. if(index > 31) throw 'Not supported beyond 32 bits.'
  8003. return (1 << index) >>> 0;
  8004. }
  8005. , indicesToMask : function(indices){
  8006. var mask = 0;
  8007. indices.forEach(index=>{
  8008. if(index > 31) throw 'Not supported beyond 32 bits.'
  8009. mask |= (1 << index);
  8010. });
  8011. return mask >>> 0;
  8012. }
  8013. , maskToIndices : function(m) {
  8014. var valid = this.validateMask(m);
  8015. if(!valid) throw "Invalid Mask"
  8016. if(valid.BitIndex) return [m.value];
  8017. var indices = [];
  8018. var gptwo;
  8019. for (;gptwo=m&-m;m^=gptwo) indices.push(indexOfLSB32(gptwo));
  8020. return indices;
  8021. }
  8022. , bit_shiftl : (a, s)=>{ return a << s }
  8023. , bit_shiftr : (a, s)=>{ return a >> s }
  8024. , bit_shiftr_uz : (a)=>{ return a >>> 0} // Unsigned right shift by 0.
  8025. // , bit_shiftl_1 : ()=>{}
  8026. , toJSON(radix, eachFn){
  8027. var transFormed = {};
  8028. if(!eachFn) return labels;
  8029. Object.keys(labels).forEach(label =>{
  8030. transFormed[label] = eachFn(labels[label]);
  8031. });
  8032. return transFormed;
  8033. }
  8034. , test(){
  8035. Object.keys(masks).forEach((v, i)=> {
  8036. console.log( v );
  8037. console.log( i + ' : ' + v.toString(2) );
  8038. console.log( this.maskToIndices(v));
  8039. });
  8040. console.log( (173).toString(2) );
  8041. this.maskToIndices(173).map( (i)=>{ console.log( i ); });
  8042. console.log('indicesToMask :' + this.indicesToMask([1,4,31]).toString(2));
  8043. }
  8044. });
  8045. }
  8046. var creatorFor = {
  8047. '[object Array]' : __createA
  8048. , '[object Object]' : __createO
  8049. , 'undefined' : function(){ return __create() }
  8050. };
  8051. // PB : TODO -- Constructor is not preserved... But mixing in an external passed in object is what we want to achive.
  8052. function BitArrayUpto32Bits(){
  8053. return arguments.length ? creatorFor[utils_1.js.nativeType(arguments[0])](...arguments) :
  8054. creatorFor['undefined'](...arguments)}
  8055. BitArrayUpto32Bits.create = BitArrayUpto32Bits;
  8056. return BitArrayUpto32Bits
  8057. })();
  8058. const Mixin = (function(){
  8059. function create(){
  8060. var __mixins = new WeakMap();
  8061. __mixins.set(Mixin, true);
  8062. function __is__(t, type){
  8063. if(utils_1.js.isPrimitive(t)) return false;
  8064. if(!t || !t.mixins) return false;
  8065. return t.mixins().get(type) ? true : false ; }
  8066. function __is(v, type){ return typeof v === type ? true : __is__(v, type) }
  8067. return { addMixin : (clazz)=>{ __mixins.set(clazz, true);}
  8068. , is : __is
  8069. }
  8070. }
  8071. return {create}
  8072. })();
  8073. const BitArrayBigInt = (function(){
  8074. function __createA(arr){
  8075. var created = __create();
  8076. for(var i =0 ; i < 1; i++) { created.assignMask(arr[i], { title : arr[i]}); }
  8077. for(var i =1 ; i < arr.length; i++) { created.assignMask(arr[i], { title : arr[i]}, leftshift_BigInt ); }
  8078. return created;
  8079. }
  8080. function __createO(o){
  8081. var arr = Object.keys(o);
  8082. var created = __create();
  8083. for(var i =0 ; i < 1; i++) { created.assignMask(arr[i], o[arr[i]]); }
  8084. for(var i =1 ; i < arr.length; i++) { created.assignMask(arr[i], o[arr[i]], leftshift_BigInt ); }
  8085. return created;
  8086. }
  8087. function __create(){
  8088. var labels = {};
  8089. var masks = {};
  8090. var currentMaxMask;
  8091. function __nextMask(){ __nextMask = leftshift_BigInt;
  8092. return currentMaxMask = BIGINT_1; }
  8093. // var store = ??? new Uint32Array(1)
  8094. var mxn = Mixin.create();
  8095. var created = utils_1.assign(mxn,
  8096. {
  8097. validateMask(m){
  8098. if(mxn.is(m, BitIndex)) {
  8099. return { BitIndex, labels : [masks[indexToMask(m.value)]] }
  8100. }
  8101. if(!utils_1.js.isBigInt(BigInt(m))) throw "BitArrayBigInt requires BigInt Mask "
  8102. return true;
  8103. }
  8104. , labelsToMask : (__labels)=>{
  8105. var result = BIGINT_0; __labels.forEach(l=>{ result |= labels[l]; });
  8106. return result ;
  8107. }
  8108. , hasMask : function(label) { return labels[label] ? labels[label].mask : null ; }
  8109. , maskToLabels(m, transformEach){
  8110. m = BigInt(m);
  8111. var valid = this.validateMask(m);
  8112. if(!valid) throw "Invalid Mask"
  8113. if(valid.BitIndex) return valid.labels;
  8114. var __labels = [];
  8115. for(var gptwo;gptwo=m&-m;m^=gptwo) {
  8116. if(!masks[gptwo]) { console.log('Error : Invalid mask passed in.'); }
  8117. else __labels.push( transformEach(masks[Number(gptwo)], labels[masks[Number(gptwo)]]) );
  8118. }
  8119. return __labels;
  8120. }
  8121. , labelToMask : (l)=>{ return labels[l] }
  8122. , bit_or : (a, b)=>a | b
  8123. , bit_and : (a, b)=>a & b
  8124. , bit_xor : (a, b)=>a ^ b
  8125. , bit_not : (a)=> ~a
  8126. , assignMask : function(label, entity, incrementFn) {
  8127. var lmask = this.hasMask(label); if(lmask) throw `Duplicate assignment for same label ${label} not allowed : mask (${lmask}) ` // Already assigned.
  8128. labels[label] = entity;
  8129. labels[label].mask = currentMaxMask = incrementFn ? incrementFn(currentMaxMask) : __nextMask(); // Use the next unused mask for this dictionary of labels. Currently random. We should eventually have a sort order.
  8130. masks[labels[label].mask] = label;
  8131. return labels[label];
  8132. }
  8133. , msbIndex : function(v) { throw "msb Not yet implemented" }
  8134. , indexToMask : function(index) {
  8135. return BIGINT_1 << index;
  8136. }
  8137. , indicesToMask : function(indices){
  8138. var mask = 0;
  8139. indices.forEach(index=>{
  8140. mask |= (1 << index);
  8141. });
  8142. return mask;
  8143. }
  8144. , maskToIndices : function(m) {
  8145. var valid = this.validateMask(m);
  8146. if(!valid) throw "Invalid Mask"
  8147. if(valid.BitIndex) return [m.value];
  8148. var indices = [];
  8149. var gptwo;
  8150. var iterator = bigIntBufferGenerator(BigInt(m));
  8151. var next;
  8152. // if(next && !next.done) buffer = next.value.bits32;
  8153. // else return next.value.bits32;
  8154. var i = 0;
  8155. while(!(next = iterator.next()).done) {
  8156. next.value.bits32 > 0 ?
  8157. ( ()=> { for(;gptwo=(next.value.bits32& -next.value.bits32) ;next.value.bits32^=gptwo) indices.push(32 * i + indexOfLSB32(gptwo)); } )
  8158. : null;
  8159. i++;
  8160. }
  8161. for(;gptwo=(next.value.bits32&-next.value.bits32);next.value.bits32^=gptwo) indices.push(32 * i + indexOfLSB32(gptwo));
  8162. return indices;
  8163. }
  8164. , bit_shiftl : (a, s)=>{ return a << s }
  8165. , bit_shiftr : (a, s)=>{ return a >> s }
  8166. , bit_shiftr_uz : (a)=>{ throw "BigInt doesnt suppored unsigned right shift."} // Unsigned right shift by 0.
  8167. // , bit_shiftl_1 : ()=>{}
  8168. , toJSON(radix, eachFn){
  8169. var transFormed = {};
  8170. if(!eachFn) return labels;
  8171. Object.keys(labels).forEach(label =>{
  8172. transFormed[label] = eachFn(labels[label]);
  8173. });
  8174. return transFormed;
  8175. }
  8176. , tosqlcte() {
  8177. var select = '';
  8178. // debugger
  8179. Object.keys(labels).forEach((label, index, array) =>{
  8180. var labelObject = labels[label];
  8181. var rowselect = 'select ';
  8182. Object.keys(labelObject).forEach((key, index, array) =>{
  8183. rowselect = rowselect + ` '${labelObject[key]}' ${key}`;
  8184. if(array.length !== index+1) rowselect = rowselect + ',';
  8185. });
  8186. select = select + rowselect;
  8187. if(array.length !== index+1) select = select + '\n union all \n';
  8188. });
  8189. console.log(select);
  8190. return labels
  8191. }
  8192. , test(){
  8193. Object.keys(masks).forEach((v, i)=> {
  8194. console.log( v );
  8195. console.log( i + ' : ' + v.toString(2) );
  8196. console.log( this.maskToIndices(v));
  8197. });
  8198. console.log( (173).toString(2) );
  8199. this.maskToIndices(173).map( (i)=>{ console.log( i ); });
  8200. console.log('indicesToMask :' + this.indicesToMask([1,4,31]).toString(2));
  8201. console.log(BigInt(2535301200456458802993406410752));
  8202. console.log('bigIntToBuffer : ' + bigIntToBuffer(BigInt(2535301200456458802993406410752) ));
  8203. console.log('bufferToBigInt : ' + bufferToBigInt( bigIntToBuffer(BigInt(2535301200456458802993406410752)) ));
  8204. }
  8205. }
  8206. );
  8207. created.addMixin(BitArrayBigInt);
  8208. return created;
  8209. }
  8210. var creatorFor = {
  8211. '[object Array]' : __createA
  8212. , '[object Object]' : __createO
  8213. , 'undefined' : function(){ return __create() }
  8214. };
  8215. // PB : TODO -- Constructor is not preserved... But mixing in an external passed in object is what we want to achive.
  8216. function BitArrayBigInt(){
  8217. return arguments.length ? creatorFor[utils_1.js.nativeType(arguments[0])](...arguments) :
  8218. creatorFor['undefined'](...arguments)}
  8219. BitArrayBigInt.create = BitArrayBigInt;
  8220. return BitArrayBigInt
  8221. })();
  8222. // > 32 bits upto 53 bits.
  8223. const BitArrayUpto53Bits = (function(){
  8224. function validateBitLength(length){ if(length > 53) throw 'BitArrayUpto53Bits doesnt accept BitLength > 53' }
  8225. function __createO(o, options){
  8226. var arr = Object.keys(o);
  8227. validateBitLength(arr.length);
  8228. var created = __create();
  8229. var iterateUpto = [
  8230. ()=>{for(var i =0 ; i < 1; i++) { console.log(i); created.assignMask(arr[i], o[arr[i]]); }}
  8231. , ()=>{for(var i =1 ; i < Math.min(31, arr.length); i++) { console.log(i); created.assignMask(arr[i], o[arr[i]], leftshift_Number ); }}
  8232. , ()=>{for(var i =31; i < Math.min(32, arr.length); i++) { console.log(i); created.assignMask(arr[i], o[arr[i]], (m)=>{ return leftshift_Number(m)>>>0 } ); }}
  8233. , ()=>{for(var i =32; i < Math.min(53, arr.length); i++) { console.log(i); created.assignMask(arr[i], o[arr[i]], (m)=>{ return Number(BigInt(m) << BIGINT_1) } ); }}
  8234. ];
  8235. arr.length > 32 ? iterateUpto.forEach(f=>f()) :
  8236. arr.length > 31 ? iterateUpto.slice(0,3).forEach(f=>f()) :
  8237. arr.length > 1 ? iterateUpto.slice(0,2).forEach(f=>f()) :
  8238. iterateUpto[0]();
  8239. return created;
  8240. }
  8241. function __createA(arrInp, options){
  8242. validateBitLength(arrInp.length);
  8243. var created = __create();
  8244. var arr = [];
  8245. var pregencache = [];
  8246. // PB : Changed to preincrement. Mask need not overflow for 53 bits...
  8247. var iterateUpto = [
  8248. (prelen)=>{for(var i =Math.max(0, prelen) ; i < 1; i++) { console.log(i); created.assignMask(arr[i-prelen], pregencache[arr[i-prelen]] || { title : arr[i-prelen]} ); }}
  8249. , (prelen)=>{for(var i =Math.max(1, prelen) ; i < Math.min(31, arr.length + prelen); i++) { console.log(i); created.assignMask(arr[i-prelen], pregencache[arr[i-prelen]] || { title : arr[i-prelen]}, leftshift_Number ); }}
  8250. , (prelen)=>{for(var i =Math.max(31, prelen); i < Math.min(32, arr.length + prelen); i++) { console.log(i); created.assignMask(arr[i-prelen], pregencache[arr[i-prelen]] || { title : arr[i-prelen]}, (m)=>{ return leftshift_Number(m)>>>0 } ); }}
  8251. , (prelen)=>{for(var i =Math.max(32, prelen); i < Math.min(53, arr.length + prelen); i++) { console.log(i); created.assignMask(arr[i-prelen], pregencache[arr[i-prelen]] || { title : arr[i-prelen]}, (m)=>{ return Number(BigInt(m) << BIGINT_1) } ); }}
  8252. ];
  8253. if(options && options.pregenerated) {
  8254. arrInp.forEach((inp=>{
  8255. if(!options.pregenerated[inp] || !options.pregenerated[inp].mask) {
  8256. // Doesn't have a mask so needs generation.
  8257. arr.push(inp);
  8258. pregencache[inp] = options.pregenerated[inp];
  8259. }
  8260. else if(!options.pregenerated[inp]) arr.push(inp);
  8261. }));
  8262. Object.keys(options.pregenerated).forEach(p=>{
  8263. if(pregencache[p]) return;
  8264. created.assignMask(p, options.pregenerated[p], created.assignMaxAsNextIncrement );
  8265. });
  8266. var prelen = Object.keys(created.toJSON()).length;
  8267. prelen > 31 ? iterateUpto.slice(3).forEach(f=>f(prelen)) :
  8268. prelen > 30 ?
  8269. (prelen + arr.length) > 32 ? iterateUpto.slice(2).forEach(f=>f(prelen))
  8270. : iterateUpto.slice(2, 3).forEach(f=>f(prelen))
  8271. :
  8272. prelen > 0 ?
  8273. (prelen + arr.length) > 32 ? iterateUpto.slice(1).forEach(f=>f(prelen))
  8274. : (prelen + arr.length) > 31 ? iterateUpto.slice(1,3).forEach(f=>f(prelen)) :
  8275. iterateUpto.slice(1,2).forEach(f=>f(prelen))
  8276. :
  8277. arr.length > 32 ? iterateUpto.forEach(f=>f(prelen)) :
  8278. arr.length > 31 ? iterateUpto.slice(0,3).forEach(f=>f(prelen)) :
  8279. arr.length > 1 ? iterateUpto.slice(0,2).forEach(f=>f(prelen)) :
  8280. iterateUpto[0](prelen);
  8281. }
  8282. else {
  8283. arr = arrInp;
  8284. arr.length > 32 ? iterateUpto.forEach(f=>f(0)) :
  8285. arr.length > 31 ? iterateUpto.slice(0,3).forEach(f=>f(0)) :
  8286. arr.length > 1 ? iterateUpto.slice(0,2).forEach(f=>f(0)) :
  8287. iterateUpto[0](0);
  8288. }
  8289. return created;
  8290. }
  8291. function __create(){
  8292. var labels = {};
  8293. var masks = {};
  8294. var currentMaxMask;
  8295. function __nextMask(){ __nextMask = leftshift_Number;
  8296. return currentMaxMask = 1; }
  8297. // var store = ??? new Uint32Array(1)
  8298. var mxn = Mixin.create();
  8299. var created = utils_1.assign(mxn,
  8300. {
  8301. assignMaxAsNextIncrement(possibleMax) {
  8302. if(currentMaxMask && currentMaxMask < possibleMax) currentMaxMask = possibleMax;
  8303. else currentMaxMask = possibleMax;
  8304. }
  8305. , validateMask(m){
  8306. if(mxn.is(m, BitIndex)) {
  8307. return { BitIndex, labels : [masks[indexToMask(m.value)]] }
  8308. }
  8309. if(m > MAX_53BITS) throw "BitArrayUpto53Bits only supports numbers upto MAX_53BITS "
  8310. if(!utils_1.js.isNumber(+m)) throw "BitArrayUpto53Bits requires Numbers upto MAX_53BITS "
  8311. return true;
  8312. }
  8313. , labelsToMask : (__labels)=>{
  8314. var result = 0; __labels.forEach(l=>{ result |= labels[l]; });
  8315. return result >>> 0;
  8316. }
  8317. , hasMask : function(label) { return labels[label] ? labels[label].mask : null ; }
  8318. , maskToLabels(m, transformEach){
  8319. var valid = this.validateMask(m);
  8320. if(!valid) throw "Invalid Mask"
  8321. if(valid.BitIndex) return valid.labels;
  8322. var __labels = [];
  8323. var m = BigInt(m);
  8324. // for(var gptwo;gptwo=this.bit_and(m,-m); gptwo = this.bit_xor(m,gptwo)) {
  8325. for(var gptwo;gptwo=m&-m;m^=gptwo) {
  8326. if(!masks[Number(gptwo)]) { console.log('Error : Invalid mask passed in.'); }
  8327. else __labels.push( transformEach(masks[Number(gptwo)], labels[masks[Number(gptwo)]]) );
  8328. }
  8329. return __labels;
  8330. }
  8331. , labelToMask : (l)=>{ return labels[l] }
  8332. , bit_or : (a, b) => {
  8333. return bit_opFn_Upto53(a,b, (a, b)=>a | b)
  8334. }
  8335. , bit_and : (a, b) => bit_opFn_Upto53(a,b, (a, b)=>a & b)
  8336. , bit_xor : (a, b) => bit_opFn_Upto53(a,b, (a, b)=>a ^ b)
  8337. , bit_not : (a) => Number(~BigInt(a))
  8338. , assignMask : function(label, entity, onassignment) {
  8339. if(entity && entity.mask && masks[entity.mask]) {
  8340. throw 'Mask collision. Cannot assign requested mask. ' + entity
  8341. }
  8342. var pregenerated = labels[label] || entity;
  8343. // var lmask = this.hasMask(label); if(lmask) return lmask; // Already assigned.
  8344. // Everything is overridable except mask.
  8345. if(pregenerated && pregenerated.mask) {
  8346. onassignment = (onassignment || created.assignMaxAsNextIncrement);
  8347. labels[label] = utils_1.assign(pregenerated, entity, {mask : pregenerated.mask});
  8348. onassignment(pregenerated.mask);
  8349. }
  8350. else {
  8351. onassignment = (onassignment || __nextMask);
  8352. labels[label] = entity;
  8353. labels[label].mask = currentMaxMask = onassignment ? onassignment(currentMaxMask) : __nextMask(); // Use the next unused mask for this dictionary of labels. Currently random. We should eventually have a sort order.
  8354. }
  8355. masks[labels[label].mask] = label;
  8356. return labels[label];
  8357. }
  8358. , msbIndex : function(v) { throw "msb Not yet implemented" }
  8359. , indexToMask : function(index) {
  8360. if(index > 52) throw 'Not supported beyond 53 bits.'
  8361. return Number(BigInt(1) << BigInt(index));
  8362. }
  8363. , indicesToMask : function(indices){
  8364. var mask = BigInt(0);
  8365. indices.forEach(index=>{
  8366. if(index > 52) throw 'Not supported beyond 53 bits.'
  8367. mask |= (BIGINT_1 << BigInt(index));
  8368. });
  8369. return Number(mask);
  8370. }
  8371. , maskToIndices : function(m) {
  8372. var valid = this.validateMask(m);
  8373. if(!valid) throw "Invalid Mask"
  8374. if(valid.BitIndex) return [m.value];
  8375. var indices = [];
  8376. var gptwo;
  8377. if(m > MAX_32BITS) {
  8378. var iterator = bigIntBufferGenerator(BigInt(m));
  8379. var next;
  8380. // if(next && !next.done) buffer = next.value.bits32;
  8381. // else return next.value.bits32;
  8382. var i = 0;
  8383. while(!(next = iterator.next()).done) {
  8384. next.value.bits32 > 0 ?
  8385. ( ()=> { for(;gptwo=(next.value.bits32& -next.value.bits32) ;next.value.bits32^=gptwo) indices.push(32 * i + indexOfLSB32(gptwo)); } )
  8386. : null;
  8387. i++;
  8388. }
  8389. for(;gptwo=(next.value.bits32&-next.value.bits32);next.value.bits32^=gptwo) indices.push(32 * i + indexOfLSB32(gptwo));
  8390. }
  8391. else {
  8392. m = Number(m);
  8393. for (;gptwo=m&-m;m^=gptwo) indices.push(indexOfLSB32(gptwo)); }
  8394. // for (;gptwo=BigInt(m)&BigInt(-m);m^=gptwo) indices.push(indexOfLSB32(m, gptwo))
  8395. return indices;
  8396. }
  8397. , bit_shiftl : (a, s)=>{ return a << s }
  8398. , bit_shiftr : (a, s)=>{ return a >> s }
  8399. , bit_shiftr_uz : (a)=>{ return a >>> 0} // Unsigned right shift by 0.
  8400. // , bit_shiftl_1 : ()=>{}
  8401. , toJSON(radix, eachFn){
  8402. var transFormed = {};
  8403. if(!eachFn) return labels;
  8404. Object.keys(labels).forEach(label =>{
  8405. transFormed[label] = eachFn(labels[label]);
  8406. });
  8407. return transFormed;
  8408. }
  8409. , tosqlcte() {
  8410. var select = '';
  8411. // debugger
  8412. Object.keys(labels).forEach((label, index, array) =>{
  8413. var labelObject = labels[label];
  8414. var rowselect = 'select ';
  8415. Object.keys(labelObject).forEach((key, index, array) =>{
  8416. rowselect = rowselect + ` '${labelObject[key]}' ${key}`;
  8417. if(array.length !== index+1) rowselect = rowselect + ',';
  8418. });
  8419. select = select + rowselect;
  8420. if(array.length !== index+1) select = select + '\n union all \n';
  8421. });
  8422. console.log(select);
  8423. return labels
  8424. }
  8425. , test(){
  8426. Object.keys(masks).forEach((v, i)=> {
  8427. console.log( v );
  8428. console.log( i + ' : ' + v.toString(2) );
  8429. console.log( this.maskToIndices(v));
  8430. });
  8431. console.log( (173).toString(2) );
  8432. this.maskToIndices(173).map( (i)=>{ console.log( i ); });
  8433. console.log('indicesToMask :' + this.indicesToMask([1,4,31]).toString(2));
  8434. }
  8435. });
  8436. return created;
  8437. }
  8438. var creatorFor = {
  8439. '[object Array]' : __createA
  8440. , '[object Object]' : __createO
  8441. , 'undefined' : function(){ return __create() }
  8442. };
  8443. // PB : TODO -- Constructor is not preserved... But mixing in an external passed in object is what we want to achive.
  8444. function BitArrayUpto53Bits(){
  8445. return arguments.length ? creatorFor[utils_1.js.nativeType(arguments[0])](...arguments) :
  8446. creatorFor['undefined'](...arguments)}
  8447. BitArrayUpto53Bits.create = BitArrayUpto53Bits;
  8448. return BitArrayUpto53Bits
  8449. })();
  8450. function bit_opFn_Upto53(a, b, opFn){
  8451. return Number(opFn(BigInt(a), BigInt(b) ))
  8452. // var result = new Uint32Array(2);
  8453. // result[0] = opFn( (a / POWER32)>>0 , (b / POWER32)>>0 )
  8454. // result[1] = opFn(a % POWER32, b % POWER32)
  8455. // return POWER32 * result[0] + result[1];
  8456. }
  8457. // An arbitrarily-wide array of bits. Can be used for bitmasks longer than 32 bits in JS.
  8458. const BitArray = (function(){
  8459. // const NEEDS_BIT_SPLIT = (b)=> b > Number.MAX_SAFE_INTEGER;
  8460. // const MAX_SAFE_MASK_LENGTH = 32
  8461. // function getMinMax(a, b){
  8462. // return a.length > b.length ? { min : b.length, minX : b, max : a.length, maxX : a }
  8463. // : { min : a.length, minX : a, max : b.length, maxX : b }
  8464. // }
  8465. // function getTypes(a, b){
  8466. // var aIsPrimitive = utils.js.isPrimitive(a);
  8467. // var bIsPrimitive = utils.js.isPrimitive(b);
  8468. // return { a : aIsPrimitive, b : bIsPrimitive }
  8469. // }
  8470. // // Binary oprations
  8471. // function bit_opFn(a, b, opFn){
  8472. // var tt = getTypes(a, b);
  8473. // var mm = {}
  8474. // var getRemaining = function(){ return mm.maxX.subarray(mm.min, mm.max-1)}
  8475. // if(tt.a && tt.b) {
  8476. // // both are primitive
  8477. // mm = { min : 1, minX : [a], max : 1, maxX : [b]}
  8478. // getRemaining = function(){ return []}
  8479. // }
  8480. // else if(tt.a){
  8481. // // b is bitarray
  8482. // mm = { min : 1, minX : [a], max : b.length, maxX : b}
  8483. // }
  8484. // else if(tt.b){
  8485. // mm = { min : 1, minX : [b], max : a.length, maxX : a}
  8486. // }
  8487. // else {
  8488. // var mm = getMinMax(a, b)
  8489. // }
  8490. // var result = new Uint32Array(mm.max);
  8491. // for (var i = 0; i < mm.min; ++i) { result.set( [opFn(mm.minX[i], mm.maxX[i])], i) }
  8492. // // js.utils.isPrimitive(mm.maxX) ?
  8493. // var remaining = getRemaining()
  8494. // remaining.length > 0 ? result.set( remaining, mm.min) : null;
  8495. // return result;
  8496. // }
  8497. // // Unary operations
  8498. // function bit_opFnU(mm, opFn){
  8499. // var result = new Uint32Array(mm.length);
  8500. // for (var i = 0; i < mm.min; ++i) { result.set( opFn(a), i) }
  8501. // result.set( mm.maxX.subarray(mm.min, mm.max-1), mm.min)
  8502. // return result;
  8503. // }
  8504. // function __expand(){
  8505. // }
  8506. function __createA(arr){
  8507. // Create a new BitArray
  8508. // Assign Unique bits to each item in an array of labels.
  8509. arr.length % 32;
  8510. arr.length/32 >>> 0;
  8511. var created = arr.length > 53 ?
  8512. BitArrayBigInt.create(...arguments) : arr.length > 32 ?
  8513. BitArrayUpto53Bits.create(...arguments) :
  8514. BitArrayUpto32Bits.create(...arguments);
  8515. return created;
  8516. }
  8517. function __createO(o){
  8518. // Create a new BitArray
  8519. // Assign Unique bits to each item in an array of labels.
  8520. var arr = Object.keys(o);
  8521. arr.length % 32;
  8522. arr.length/32 >>> 0;
  8523. var created = arr.length > 53 ?
  8524. BitArrayBigInt.create(...arguments) : arr.length > 32 ?
  8525. BitArrayUpto53Bits.create(...arguments) :
  8526. BitArrayUpto32Bits.create(...arguments);
  8527. return created;
  8528. }
  8529. function __create(){
  8530. // var store = new Uint32Array(1)
  8531. Mixin.create();
  8532. var created = BitArrayBigInt.create();
  8533. created.addMixin(BitArray);
  8534. return created;
  8535. }
  8536. var creatorFor = {
  8537. '[object Array]' : __createA
  8538. , '[object Object]' : __createO
  8539. , 'undefined' : function(){ return __create() }
  8540. };
  8541. // PB : TODO -- Constructor for BitArrays read from files that have been generated and saved.
  8542. // PB : TODO -- Constructor is not preserved... But mixing in an external passed in object is what we want to achive.
  8543. function BitArray(){
  8544. return arguments.length ? creatorFor[utils_1.js.nativeType(arguments[0])](...arguments) :
  8545. creatorFor['undefined'](...arguments)}
  8546. BitArray.create = BitArray;
  8547. return BitArray
  8548. })();
  8549. // Mixins.
  8550. const mixs = {
  8551. // __JSTPL : (function() {
  8552. // function __f() {}
  8553. // return function() {
  8554. // this.f = __f;
  8555. // return this;
  8556. // };
  8557. // })()
  8558. // Return a set of mixins.
  8559. kernelMixin : (function() {
  8560. // Wrapper to generate the currently chosen UUID version
  8561. // In JS UUID v4 vs v1 -> In browsers v1 has the timestamp but uses a random number for the node part.
  8562. function __getuuid() {
  8563. return v1_1();
  8564. }
  8565. // uuid property Mainstream getter after lazy init
  8566. function __get() {
  8567. return this.kernel.uuidv1;
  8568. }
  8569. // uuid property First Time getter for lazy init.
  8570. function __firstGet() {
  8571. this.kernel.uuidv1 = __getuuid();
  8572. __finalize.apply(this);
  8573. return this.uuid;
  8574. }
  8575. function __finalize(){
  8576. Object.defineProperty(this.kernel, 'uuidv1', { writable : false, configurable : false});
  8577. Object.defineProperty(this, 'uuid', {
  8578. get : __get
  8579. , enumerable : true
  8580. , configurable : false
  8581. });
  8582. Object.defineProperty(this, 'kernel', {
  8583. enumerable : false
  8584. , configurable : false
  8585. , writable : false
  8586. });
  8587. }
  8588. function __defineKernel(){
  8589. // MAC and time. Guaranteed unique unless generated way too fast or parallelly.
  8590. //const uuidv1 = require('uuid/v1'); // (date-time and MAC address)
  8591. //const uuidv2 = // (date-time and MAC Address, DCE security version)
  8592. // (namespace name-based) ...
  8593. //const uuidv3md5 = require('uuid/v3');
  8594. //const uuidv5sha1 = require('uuid/v3'); // SHA1(v5) is broken
  8595. //const uuidv4 = require('uuid/v4'); //(random)
  8596. // Kernel Properties are promoted onto the object itself without value as getters and setters as
  8597. // configurable = false
  8598. // enumerable = false
  8599. // writable = false
  8600. Object.defineProperty(this, 'kernel', { value :{}, writable : true });
  8601. // Keep it lazy. Only generate on first use. Which could be first time persistence.
  8602. Object.defineProperty(this.kernel, 'uuidv1', { writable : true, configurable : true});
  8603. // PB : TODO -- Note : A hash of the content may need to be computed dynamically.
  8604. // The best place to do this is on persistance. In memory objects undergo a lot of changes so the hash keeps varying.
  8605. // It therefore becomes unnecessary to compute the hash very frequently. We may need to do this lazily when accessed or
  8606. // simply use all attributes for comparison. The value of a hash is useful only when the attributes are not changing
  8607. // and the hash is precomputed and ready to be used. We need to use gits methodology to track changes.
  8608. }
  8609. function __loadKernel() {
  8610. // Reinitialize the kernel for an object that already has a uuid probably loaded from a JSON.
  8611. this.kernel.uuidv1 = this.uuid;
  8612. __finalize.apply(this);
  8613. }
  8614. function __attachKernel() {
  8615. // Dont mess with something that already has a kernel.
  8616. if(this.hasOwnProperty('kernel')) {
  8617. l('Already has kernel');
  8618. return this;
  8619. }
  8620. __defineKernel.apply(this);
  8621. if(this.hasOwnProperty('uuid')) {
  8622. l('Already has uuid');
  8623. __loadKernel.apply(this);
  8624. return this;
  8625. }
  8626. Object.defineProperty(this, 'uuid', { get : __firstGet, configurable : true});
  8627. return this;
  8628. }
  8629. var __kernelInstanceMixin = function() {
  8630. return __attachKernel.apply(this);
  8631. };
  8632. __kernelInstanceMixin.getuuid = __getuuid;
  8633. return __kernelInstanceMixin;
  8634. })()
  8635. // Publishes messages to a message queue broker or mediator.
  8636. , publisherMixin : (function() {
  8637. function __publish() {
  8638. }
  8639. return function() {
  8640. this.publish = __publish;
  8641. return this;
  8642. };
  8643. })()
  8644. };
  8645. // Note : Prophelpers are not mixed into the object and hence need to be applied on some other object.
  8646. const helpers = {
  8647. indexHelper : indexHelper
  8648. , meta : (function() {
  8649. // Mainly to observe changes to object properties.
  8650. // A kernel uuid is a prerequisite.
  8651. function spy(obj, prop, action) {
  8652. action = action || 'set';
  8653. if(action != 'set') {
  8654. throw 'Currently only set actions can be observed on properties';
  8655. }
  8656. // Get the current descriptor
  8657. var descriptor = Object.getOwnPropertyDescriptor(obj, prop);
  8658. var value = obj[prop];
  8659. if(descriptor && descriptor.get && descriptor.get.$meta){
  8660. var originalset = descriptor.set;
  8661. descriptor.set = function(newValue) {
  8662. globalThis_1.mediator.publish(obj.uuid + '.' + prop, 'willchange', {from : value, to : newValue});
  8663. originalset(newValue);
  8664. globalThis_1.mediator.publish(obj.uuid + '.' + prop, 'haschanged', {from : value, to : newValue});
  8665. };
  8666. return this;
  8667. }
  8668. descriptor = {
  8669. get: function() {
  8670. return value;
  8671. },
  8672. set: function(newValue) {
  8673. globalThis_1.mediator.publish([obj.uuid, prop, 'willchange'], {from : value, to : newValue});
  8674. value = newValue;
  8675. globalThis_1.mediator.publish([obj.uuid, prop, 'haschanged' ], {from : value, to : newValue});
  8676. }
  8677. };
  8678. descriptor.get.$meta = {};
  8679. Object.defineProperty(obj, prop, descriptor);
  8680. return this;
  8681. }
  8682. function getCustomPropertyDescriptor(obj, prop) {
  8683. var actualDescriptor = Object.getOwnPropertyDescriptor(obj, prop);
  8684. if (actualDescriptor && actualDescriptor.get && actualDescriptor.get.$meta) {
  8685. return actualDescriptor;
  8686. }
  8687. var value = obj[prop];
  8688. var descriptor = {
  8689. get: function() {
  8690. return value;
  8691. },
  8692. set: function(newValue) {
  8693. value = newValue;
  8694. }
  8695. };
  8696. descriptor.get.$meta = {};
  8697. Object.defineProperty(obj, prop, descriptor);
  8698. return Object.getOwnPropertyDescriptor(obj, prop);
  8699. }
  8700. function setPropertyAttribute(obj, propertyName, attributeName, attributeValue) {
  8701. var descriptor = getCustomPropertyDescriptor(obj, propertyName);
  8702. descriptor.get.$meta[attributeName] = attributeValue;
  8703. }
  8704. function getPropertyAttributes(obj, propertyName) {
  8705. var descriptor = getCustomPropertyDescriptor(obj, propertyName);
  8706. return descriptor.get.$meta;
  8707. }
  8708. function getPropertyAttribute(obj, propertyName, attributeName) {
  8709. return getPropertyAttributes(obj, propertyName)[attributeName];
  8710. }
  8711. return function(obj) {
  8712. obj.getPropertyAttribute = getPropertyAttribute;
  8713. obj.getPropertyAttributes = getPropertyAttributes;
  8714. obj.setPropertyAttribute = setPropertyAttribute;
  8715. obj.spy = spy;
  8716. return obj;
  8717. };
  8718. })()
  8719. };
  8720. var core = function(object){
  8721. // l('in \tFunction core')
  8722. return {
  8723. mixs
  8724. , helpers
  8725. , AnyStore
  8726. , BitArray
  8727. , BitArrayUpto32Bits
  8728. , BitArrayUpto53Bits
  8729. , BitArrayBigInt
  8730. // core object instances
  8731. , uuidv1: v1_1
  8732. , Rule
  8733. }
  8734. };
  8735. // export default core;
  8736. var core_1 = core;
  8737. // console.dir(__g.mediator)
  8738. // try {
  8739. // console.log( '__g === global : ' + (__g === global) )
  8740. // }
  8741. // catch(e){
  8742. // console.log( '__g === global : ' + false )
  8743. // }
  8744. // try {
  8745. // console.log( '__g === globalThis : ' + (__g === globalThis) )
  8746. // }
  8747. // catch(e){
  8748. // console.log( '__g === globalThis : ' + false )
  8749. // }
  8750. function *bigIntBitGenerator(){
  8751. var signal = {};
  8752. var stop = Symbol();
  8753. var iId = 0;
  8754. var bit = BIGINT_1;
  8755. for(;;){
  8756. signal = (yield { iId, bit }) || {};
  8757. if(signal === stop || signal.done) return { iId, bit };
  8758. bit = bit << BIGINT_1;
  8759. iId++;
  8760. }
  8761. }
  8762. var Rule = (function(){
  8763. // Immutable private static.
  8764. var __Rule = {};
  8765. // Overridable public static shared on the instance as well as convenience functions.
  8766. // When the extend method is used the instance methods also correspond.
  8767. // IMP : NOTE -- However instance overrides do not switch the static ones attached to the class.
  8768. // These could also be called statically with call or apply Eg: fn.apply(this)
  8769. var _XRule = { assignbit, getParticipating };
  8770. // Extendable public static
  8771. // _Rule should not be referenced anywhere... as its members can be swithed.
  8772. var _Rule = {
  8773. extend : function(extension){
  8774. function __create(){ return init.call({}) }
  8775. function __createO(o){ return init.call(o) }
  8776. function __createA(a){ a.forEach(r=> __createO(r)); return a }
  8777. var creatorFor = {
  8778. '[object Array]' : __createA
  8779. , '[object Object]' : __createO
  8780. , 'undefined' : function(){ return __create() }
  8781. };
  8782. function Rule(){ return arguments.length ? creatorFor[utils_1.js.nativeType(arguments[0])](...arguments) : creatorFor['undefined'](...arguments) }
  8783. // All static extensions shall be available on the instance as well.
  8784. var _extension = utils_1.assign({}, _XRule, extension);
  8785. function init() { return utils_1.assign(this, rProto, _extension, __newInstance(this), this) } _extension.init = init;
  8786. utils_1.assign(Rule, _Rule, _extension, __Rule);
  8787. // Immutable public static methods.
  8788. Rule.create = Rule;
  8789. Rule.build = buildRules;
  8790. Rule.match = match;
  8791. Rule.connect = connectRules;
  8792. Rule.branch = function(as, ...rest){
  8793. // PB : TODO -- All lists will be invalidated when we splice rules in...
  8794. // Rule.create()
  8795. // Replace an exisiting rule node with an intermediate rule that connects this rule to another rule.
  8796. console.error('Not yet implemented.');
  8797. };
  8798. // from loopback-connector/lib/sql.js
  8799. // PB : TODO -- a generic multipurpose buildwhere which doesn't enforce model property existence
  8800. // Convert from a natural filter to key val expanded filter.
  8801. // Convert In clauses to one rule for each listed values.
  8802. // Do not output the where clause but inlude the operator in the result assosiated with the respective params.
  8803. // Handle mask overflows gracefully
  8804. /**
  8805. * @param where
  8806. * @returns {ChoppedRules}
  8807. */
  8808. function buildRules(where, data, fullResult, parentRule) {
  8809. let columnValue;
  8810. if (!where) return Promise.resolve(fullResult) ;
  8811. if (typeof where !== 'object' || Array.isArray(where)) {
  8812. debug('Invalid value for where: %j', where);
  8813. return Promise.resolve(fullResult);
  8814. }
  8815. var ruleset = [];
  8816. // var id = Object.keys(where).length > 1 ? null : data ? data.id : null;
  8817. var id = data ? data.id : null;
  8818. fullResult = fullResult || [];
  8819. var createIntermediate = createIntermediateParentLess;
  8820. var immediateParentP = null;
  8821. if(parentRule) {
  8822. immediateParentP = parentRule;
  8823. createIntermediate = createIntermediateWithParent;
  8824. }
  8825. if(Object.keys(where).length > 1) {
  8826. immediateParentP = createIntermediate({operator : AND}, ()=>{ return [] }, parentRule);
  8827. ruleset.push(immediateParentP);
  8828. fullResult.push(immediateParentP);
  8829. createIntermediate = createIntermediateWithParent;
  8830. }
  8831. for (const key in where) {
  8832. // Handle and/or operators
  8833. if (key === AND || key === OR) {
  8834. const clauses = where[key];
  8835. if (Array.isArray(clauses)) {
  8836. if(clauses.length > 1) {
  8837. var rp = createIntermediate({operator : key}, (rParent)=>{
  8838. var list = [];
  8839. for (let i = 0, n = clauses.length; i < n; i++) {
  8840. list.push(buildRules(clauses[i], null, fullResult).then( ruleForClause => {
  8841. connectRules(operators[rParent.operator].bit, ruleForClause, rParent);
  8842. return ruleForClause;
  8843. }));
  8844. }
  8845. return list;
  8846. }, immediateParentP);
  8847. ruleset.push(rp);
  8848. fullResult.push(rp);
  8849. }
  8850. else {
  8851. // An outer 'or' OR 'and' condition is meaningless if we have only 1 clause. At least two are required to make sense.
  8852. // We just drop the wrapped grouped (or or and) condition and promote then inner clause to the same level. =
  8853. var rP = buildRules(clauses[0], null, fullResult, immediateParentP);
  8854. // fullResult.push(rP) // Buildrules should should have already pushed this.
  8855. ruleset.push(rP); // buildRules should have already linked parent and child.
  8856. }
  8857. continue;
  8858. }
  8859. else {
  8860. throw 'Invalid filter '
  8861. }
  8862. }
  8863. // eslint-disable one-var
  8864. let expression = where[key];
  8865. let p = key;
  8866. var op ='eq;';
  8867. const columnName = columnEscaped(/* modelinstance || */ where, key);
  8868. // eslint-enable one-var
  8869. if (expression === null || expression === undefined) {
  8870. // If null has been passed in we should match null.
  8871. expression = null;
  8872. var rpromise = assignbit(Rule.create(rChild, { key : columnName, value : toColumnValue(p, expression)})).then((rChild)=>{
  8873. if(immediateParentP) {
  8874. return immediateParentP.then((immediateParent)=> {
  8875. connectRules(operators[immediateParent.operator].bit, rChild, immediateParent);
  8876. return rChild
  8877. })
  8878. }
  8879. // PB : TODO -- Unwrapped decendents update on parent!!!
  8880. return rChild
  8881. }).catch(e=>{ console.error('null expression : ' + e); });
  8882. fullResult.push(rpromise);
  8883. ruleset.push(rpromise);
  8884. } else if (expression && expression.constructor === Object) {
  8885. const operator = Object.keys(expression)[0];
  8886. expression = expression[operator];
  8887. if (operator === INQ || operator === NIN || operator === BETWEEN) {
  8888. columnValue = [];
  8889. op = operator === INQ ? (EQ) : operator === NIN ? (NEQ) : (LTE);
  8890. if (Array.isArray(expression)) {
  8891. // Column value is a list
  8892. for (let j = 0, m = expression.length; j < m; j++) {
  8893. columnValue.push(toColumnValue(p, expression[j]));
  8894. }
  8895. } else {
  8896. columnValue.push(toColumnValue(p, expression[j]));
  8897. }
  8898. if (operator === BETWEEN) {
  8899. var rp = createIntermediate({operator : AND}, (rParent)=>{
  8900. // BETWEEN v1 AND v2
  8901. columnValue[0] === undefined ? null : columnValue[0];
  8902. columnValue[1] === undefined ? null : columnValue[1];
  8903. if(expression.length !== 2) console.error('Invalid between operator parameter length');
  8904. var list = [];
  8905. list.push(assignbit(Rule.create({key : columnName, value : columnValue[0], operator : GTE})).then((rChild)=>{
  8906. connectRules(operators[rParent.operator].bit, rChild, rParent);
  8907. return rChild
  8908. }));
  8909. list.push(assignbit(Rule.create({key : columnName, value : columnValue[1], operator : LTE})).then((rChild)=>{
  8910. connectRules(operators[rParent.operator].bit, rChild, rParent);
  8911. return rChild
  8912. }));
  8913. fullResult.push.apply(fullResult, list);
  8914. return list;
  8915. }, immediateParentP);
  8916. ruleset.push(rp);
  8917. fullResult.push(rp);
  8918. } else {
  8919. var rp = createIntermediate({operator : OR}, (rParent)=>{
  8920. // IN (v1,v2,v3) or NOT IN (v1,v2,v3)
  8921. // PB : TODO -- loopbacks handling of nulls is questionable. Invalid rules match nulls and return data.
  8922. if (columnValue.length === 0) {
  8923. if (operator === INQ) {
  8924. columnValue = [null];
  8925. } else {
  8926. // nin () is true
  8927. // nin : [null] is a world query which is an invalid filter. We don't support yet.
  8928. return [];
  8929. }
  8930. }
  8931. var list = [];
  8932. for (let j = 0, m = columnValue.length; j < m; j++) {
  8933. list.push(
  8934. assignbit(Rule.create({key : columnName, value : toColumnValue(p, columnValue[j]), operator : op})).then((rChild)=>{
  8935. connectRules(operators[rParent.operator].bit, rChild, rParent);
  8936. return rChild
  8937. })
  8938. );
  8939. }
  8940. fullResult.push.apply(fullResult, list);
  8941. return list
  8942. }, immediateParentP);
  8943. ruleset.push(rp);
  8944. fullResult.push(rp);
  8945. }
  8946. } else if (operator === 'regexp' && expression instanceof RegExp) {
  8947. // do not coerce RegExp based on property definitions
  8948. var rpromise = assignbit(Rule.create({key : columnName, value : toColumnValue(p, expression), operator})).then((rChild)=>{
  8949. if(immediateParentP) {
  8950. return immediateParentP.then((immediateParent)=> {
  8951. connectRules(operators[immediateParent.operator].bit, rChild, immediateParent);
  8952. return rChild
  8953. })
  8954. }
  8955. // PB : TODO -- Unwrapped decendents update on parent!!!
  8956. return rChild
  8957. }).catch(e=>{ console.error('Regexp expression : ' + e); });
  8958. fullResult.push(rpromise);
  8959. ruleset.push(rpromise);
  8960. // columnValue = expression;
  8961. } else {
  8962. var rpromise = assignbit(Rule.create({key : columnName, value : toColumnValue(p, expression), operator})).then((rChild)=>{
  8963. if(immediateParentP) {
  8964. return immediateParentP.then((immediateParent)=> {
  8965. connectRules(operators[immediateParent.operator].bit, rChild, immediateParent);
  8966. return rChild
  8967. })
  8968. }
  8969. // PB : TODO -- Unwrapped decendents update on parent!!!
  8970. return rChild
  8971. }).catch(e=>{ console.error('other expression : ' + e); });
  8972. fullResult.push(rpromise);
  8973. ruleset.push(rpromise);
  8974. // columnValue = toColumnValue(p, expression);
  8975. }
  8976. } else {
  8977. if(utils_1.js.isArray(expression)) throw 'Invalid array value for filter. Implicit INQ not supported. '
  8978. // ruleProcessor[EQ]();
  8979. var rpromise = assignbit(Rule.create({key : columnName, value : toColumnValue(p, expression), operator : EQ})).then((rChild)=>{
  8980. if(immediateParentP) {
  8981. return immediateParentP.then((immediateParent)=> {
  8982. connectRules(operators[immediateParent.operator].bit, rChild, immediateParent);
  8983. return rChild
  8984. })
  8985. }
  8986. // PB : TODO -- Unwrapped decendents update on parent!!!
  8987. return rChild
  8988. }).catch(e=>{ console.error('other expression : ' + e); });
  8989. fullResult.push(rpromise);
  8990. ruleset.push(rpromise);
  8991. }
  8992. }
  8993. return Promise.all(ruleset).then(()=>{
  8994. if(immediateParentP){
  8995. return immediateParentP;
  8996. }
  8997. if(ruleset.length > 1) {
  8998. // If only 1 rule there is no point in having an outer implicit and.
  8999. // If length is > 1 it implies there are a mixture of ands ors and raw rules specified as an outer object
  9000. // and we need to return the grouped rule.
  9001. // var grpromise = Promise.all(ruleset).then( (list)=>{
  9002. // var grouped = Rule.create({ id, operator : AND }).assignbit();
  9003. // return grouped.then(r=>{
  9004. // r.list = list;
  9005. // return r
  9006. // })
  9007. // });
  9008. // fullResult.push(grpromise)
  9009. // return grpromise
  9010. return ruleset[ruleset.length-1].then((r)=>{ r.id = id || r.id; return r});
  9011. }
  9012. else if(ruleset.length > 0) {
  9013. return ruleset[0].then((r)=>{ r.id = id || r.id; return r});
  9014. }
  9015. else {
  9016. return fullResult[fullResult.length-1].then((r)=>{ r.id = id || r.id; return r});
  9017. }
  9018. })
  9019. }
  9020. return Rule
  9021. }
  9022. };
  9023. var createIntermediateParentLess = (interMediatGroupParent, createChildren)=>{
  9024. var interMediatGroupParentP = assignbit(Rule.create(interMediatGroupParent)).then((rIntermediate)=>{
  9025. return rIntermediate
  9026. });
  9027. var grpromise = interMediatGroupParentP.then((rParent)=>{
  9028. // var rParent = resolved[1]
  9029. // if(immediateParentP) {
  9030. // connectRules( operators[ resolved[0].operator].bit, rParent, resolved[0] )
  9031. // // PB : Note -- we connect right here and after children are properly created we update parent descendents when we unwrap to root parent.
  9032. // rParent.ancestors |= resolved[0].ancestors | resolved[0].bit // PB : TODO -- should ancestors be included in the mask ???
  9033. // }
  9034. // PB : TODO -- When we unwind descendents on ancestors need to be updated.
  9035. // PB : TODO -- Why is this group not getting pushed into the full list.
  9036. // Also what happens when caluse[i] is an array ? Does a group get created and also clause i ?
  9037. return Promise.all(createChildren(rParent)).then( (list)=>{
  9038. // PB : TODO -- We don't know yet whether id needs to be assigned to this rule
  9039. // or an outer grouped rule.
  9040. rParent.list = list;
  9041. return rParent
  9042. });
  9043. });
  9044. return grpromise;
  9045. };
  9046. var createIntermediateWithParent = (interMediatGroupParent, createChildren, immediateParentP)=>{
  9047. var interMediatGroupParentP = assignbit(Rule.create(interMediatGroupParent)).then((rIntermediate)=>{
  9048. return immediateParentP.then((immediateParent)=>{
  9049. connectRules(operators[immediateParent.operator].bit, rIntermediate, immediateParent);
  9050. return rIntermediate
  9051. })
  9052. });
  9053. var grpromise = interMediatGroupParentP.then((rParent)=>{
  9054. // var rParent = resolved[1]
  9055. // if(immediateParentP) {
  9056. // connectRules( operators[ resolved[0].operator].bit, rParent, resolved[0] )
  9057. // // PB : Note -- we connect right here and after children are properly created we update parent descendents when we unwrap to root parent.
  9058. // rParent.ancestors |= resolved[0].ancestors | resolved[0].bit // PB : TODO -- should ancestors be included in the mask ???
  9059. // }
  9060. // PB : TODO -- When we unwind descendents on ancestors need to be updated.
  9061. // PB : TODO -- Why is this group not getting pushed into the full list.
  9062. // Also what happens when caluse[i] is an array ? Does a group get created and also clause i ?
  9063. return Promise.all(createChildren(rParent)).then( (list)=>{
  9064. // PB : TODO -- We don't know yet whether id needs to be assigned to this rule
  9065. // or an outer grouped rule.
  9066. rParent.list = list;
  9067. return rParent
  9068. });
  9069. });
  9070. return grpromise;
  9071. };
  9072. // Literals
  9073. const EQ = 'eq';
  9074. const LTE = 'lte';
  9075. const GTE = 'gte';
  9076. const LT = 'lt';
  9077. const GT = 'gt';
  9078. const AND = 'and';
  9079. const OR = 'or';
  9080. const INQ = 'inq';
  9081. const BETWEEN = 'between';
  9082. const NIN = 'nin';
  9083. const NEQ = 'neq';
  9084. __Rule.EQ = 1;
  9085. __Rule.LTE = 2;
  9086. __Rule.GTE = 4;
  9087. __Rule.LT = 8;
  9088. __Rule.GT = 16;
  9089. __Rule.AND = 32;
  9090. __Rule.OR = 64;
  9091. var operators = {
  9092. eq : { operator : '=', bit : __Rule.EQ}
  9093. , lte : { operator : '<=', bit : __Rule.LTE}
  9094. , gte : { operator : '>=', bit : __Rule.GTE}
  9095. , lt : { operator : '<', bit : __Rule.LT}
  9096. , gt : { operator : '>', bit : __Rule.GT}
  9097. , and : { operator : AND, bit : __Rule.AND}
  9098. , or : { operator : OR, bit : __Rule.OR}
  9099. };
  9100. var operatorsIndex = {};
  9101. Object.keys(operators).forEach(op => operatorsIndex[operators[op].bit] = operators[op] );
  9102. function __newInstance(o){
  9103. var d = new Date();
  9104. var id = o.id || v1_1();
  9105. return { v1ruleId : id, id, datecreated : d, datemodified : d
  9106. , permissive : BIGINT_0, restrictive : BIGINT_0, descendents : BIGINT_0, ancestors : BIGINT_0, list :[] }
  9107. }
  9108. var globalBitIterator = bigIntBitGenerator();
  9109. function assignbit(rule){ var g = globalBitIterator.next().value; rule.bit = g.bit; rule.ruleiId = g.iId;
  9110. return Promise.resolve(rule); // PB : TODO -- remove backward compatible promisification...
  9111. }
  9112. // Find leaf rules from a set of rules ( in a database of rules ) that match the inputs
  9113. function getParticipating(iRule, rList, cb){
  9114. return Promise.all(iRule.results).then((iRules)=>{
  9115. var SUCCESS = BIGINT_0;
  9116. var FAILURE = BIGINT_0;
  9117. var mask = BIGINT_0;
  9118. var results = rList.filter(rule => {
  9119. var found = iRules.find( iR => {
  9120. if(iR === rule || iR.id === rule.id ||
  9121. iR.key === rule.key &&
  9122. ( rule.operator == GT && (
  9123. rule.value <= iR.value && iR.operator == GT
  9124. || rule.value < iR.value && ( iR.operator == GTE || iR.operator == EQ )
  9125. )
  9126. || rule.operator == GTE && (
  9127. rule.value <= iR.value && (iR.operator == GTE || iR.operator == EQ)
  9128. || (iR.value - rule.value) >= 0 && iR.operator == GT
  9129. )
  9130. || rule.operator == LT && (
  9131. rule.value >= iR.value && iR.operator == LT
  9132. || rule.value > iR.value && ( iR.operator == LTE || iR.operator == EQ )
  9133. )
  9134. || rule.operator == LTE && (
  9135. rule.value >= iR.value && (iR.operator == LTE || iR.operator == EQ)
  9136. || (rule.value - iR.value) >= 0 && iR.operator == LT
  9137. )
  9138. || rule.operator == EQ && (
  9139. rule.value == iR.value && iR.operator == EQ
  9140. )
  9141. )
  9142. ) {
  9143. SUCCESS |= rule.bit;
  9144. mask |= rule.mask;
  9145. return true;
  9146. }
  9147. });
  9148. if(!found) {
  9149. if(rule.isleaf) { FAILURE |= rule.bit; }
  9150. else {
  9151. // Composite rule evaluation here is incomplete since we are still iterating and finding leaf level participants.
  9152. // Optimistically computed in case we get lucky here on first pass for result caching efficiency.
  9153. // No point in attempting a full evaluation for composite rule through parts as parts are still being evaluated.
  9154. // A priority evaluation registration of leaf level descendents with a async postponed evaluation task for this rule...
  9155. // may help with evaulation of relevant rules earlier....
  9156. // This specific rules full evaluation may be moot if no asserting participants can be found.
  9157. // Or all its ancestral rules are already true without needing this rule to be evaluated....
  9158. if(rule.permissive & SUCCESS ) { SUCCESS |= rule.bit; mask |= rule.mask; return true; }
  9159. if(rule.restrictive & FAILURE) {FAILURE |= rule.bit; }
  9160. if(rule.restrictive && (rule.restrictive & SUCCESS) === rule.restrictive) { SUCCESS |= rule.bit; mask |= rule.mask; return true; }
  9161. if(rule.permissive && (rule.permissive & FAILURE) === rule.permissive) {FAILURE |= rule.bit; }
  9162. // if((rule.descendents & SUCCESS) === rule.descendents) {
  9163. // // Implies all intermediate groups are true. We only need to examine direct leaf connections.
  9164. // SUCCESS |= rule.bit;
  9165. // mask |= rule.mask;
  9166. // }
  9167. }
  9168. }
  9169. return found;
  9170. });
  9171. if(utils_1.js.isFunction(arguments[arguments.length-1])) { return cb(null, { SUCCESS, FAILURE, mask, results} ) }
  9172. else return { mask, list : found};
  9173. });
  9174. }
  9175. function getParticipatingRoots(participating, rList, cb){
  9176. var qualifiedRoots = [];
  9177. rList.forEach((r)=>{
  9178. if(r.isRoot && evaluate(r, participating)){ qualifiedRoots.push(r); }
  9179. });
  9180. cb(null, qualifiedRoots);
  9181. }
  9182. function toColumnValue(p, v) { return v; }
  9183. function columnEscaped(inst, p) { return p; }
  9184. function getsql_cond_group(){
  9185. if(!this.list) { console.warn(`${this.operator} condition without list is moot`); return ''}
  9186. if(this.list.length < 2) {
  9187. this.list.push( this.list[0] ); // PB : TOOD -- We are adding instead of eliminating Redundant groups ...
  9188. }
  9189. var slqexprs = [];
  9190. this.list.forEach(r => slqexprs.push(r.sql) );
  9191. return '( ' + slqexprs.join( ` ${this.operator} `) + ' )'
  9192. }
  9193. function getfilter_cond_group(){
  9194. if(!this.list) { console.warn(`${this.operator} condition without list is moot`); return ''}
  9195. if(this.list.length < 2) {
  9196. this.list.push( this.list[0] ); // PB : TOOD -- We are adding instead of eliminating Redundant groups ...
  9197. }
  9198. var filterexprs = [];
  9199. this.list.forEach(r => filterexprs.push(r.filter) );
  9200. return filterexprs;
  9201. }
  9202. // PB : TODO -- This might be easier done in a stored procedure.
  9203. // It will also help if participating is not the whole list but the filtered list relevant for this rule.
  9204. // Relocation so inline functions don't need to be redefined again and again.
  9205. // Implement __Rule.isRoot
  9206. var evaluate = function(rule, participating){
  9207. if(rule.bit & participating.SUCCESS ) return true;
  9208. if(rule.bit & participating.FAILURE) return false
  9209. if(rule.permissive & participating.SUCCESS ) { participating.SUCCESS |= rule.bit; return true }
  9210. if(rule.restrictive & participating.FAILURE) {participating.FAILURE |= rule.bit; return false;}
  9211. if(rule.restrictive && (rule.restrictive & participating.SUCCESS) === rule.restrictive) { participating.SUCCESS |= rule.bit; return true }
  9212. if(rule.permissive && (rule.permissive & participating.FAILURE) === rule.permissive) {participating.FAILURE |= rule.bit; return false;}
  9213. // PB : TODO -- Truth value of grouped could be driven from the roots so we can limit to those rules that are relevant and avoid evaluation of each one.
  9214. if(rule.isleaf) {
  9215. if(participating.results.find( pp => pp === rule )) { participating.SUCCESS |= rule.bit; return true }
  9216. else { participating.FAILURE |= rule.bit; return false; }
  9217. }
  9218. // else {
  9219. // // If descendents are true we can extract only the ones that are direct connections and
  9220. // // Evaluate...
  9221. // var alldescendentsAreTrue = false;
  9222. // if((rule.descendents & participating.SUCCESS) === rule.descendents) {
  9223. // // Implies all intermediate groups are true. We only need to examine direct leaf connections.
  9224. // alldescendentsAreTrue = true;
  9225. // }
  9226. // }
  9227. // getUnevaluated
  9228. var permissive = rule.permissive & (BigInt(-1)-participating.SUCCESS) & (BigInt(-1)-participating.FAILURE);
  9229. for(var rc in rule.list){
  9230. var r = rule.list[rc];
  9231. if(r.bit & permissive) {
  9232. if(evaluate(r, participating)) { participating.SUCCESS |= r.bit; participating.SUCCESS |= rule.bit; return true }
  9233. else participating.FAILURE |= r.bit;
  9234. }
  9235. }
  9236. if(rule.permissive){ participating.FAILURE |= rule.bit; return false; }
  9237. // getUnevaluated.
  9238. var restrictive = rule.restrictive & (BigInt(-1)-participating.SUCCESS) & (BigInt(-1)-participating.FAILURE);
  9239. for(var rc in rule.list){
  9240. var r = rule.list[rc];
  9241. if(r.bit & restrictive) {
  9242. if(!evaluate(r, participating)) { participating.FAILURE |= r.bit; participating.FAILURE |= rule.bit; return false}
  9243. participating.SUCCESS |= r.bit;
  9244. }
  9245. }
  9246. if(rule.restrictive){ participating.SUCCESS |= rule.bit; return true; }
  9247. throw 'Error : A group rule should either be permissive or restrictive...'
  9248. };
  9249. var match = function (inputs, rList, cb) {
  9250. var results = [];
  9251. Rule.build(inputs, clause, results).then((inputRule)=>{
  9252. inputRule.results = results;
  9253. // inputs are usually individual assertions. An and / or condition between individual assertions are usually not useful.
  9254. // Unless the assertion is of the form
  9255. // Eg : this indiviudal's age is between x and y which is kind of rare.
  9256. // A negation is also not how an assertion is typically made. However not from location C or D is a possible assertion.
  9257. // An or assertion is still more rare and is usually an abstraction to not be specific.
  9258. // Eg : The user is from location A or B and uses either a Mac or Ubuntu OS.
  9259. // Although the user has specific characteristics the specificity is not disclosed in the inputs.
  9260. // And is adequate to distinguish the inputs from amongst a superset.
  9261. // In the above example the user cannot be from both locations A and B at the same time but could be using both Mac and Ubuntu probably even at the same time.
  9262. // 1) The simplest and fastest use case is exact matches of input assertions with and exact match of saved rules.
  9263. // 2) exact input values with condition groups in the rules is also supportable.
  9264. // 3) complex input rules as abstract or range assertions matching
  9265. // complex rules that have range or absctract conditions -- How to Implement ??
  9266. // IMPLEMENTATION AS SQL
  9267. // FIND PARTICIPATING rules that evaluate true.
  9268. /* WHERE rule.key = input.key ( rule.operator = '>' AND rule.value <= input.value AND input.operator = '>'
  9269. OR rule.operator = '>' AND rule.value < input.value AND input.operator = '>='
  9270. OR rule.operator = '>=' AND rule.value <= input.value AND (input.operator = '>=' OR input.operator = '=')
  9271. ) AND
  9272. ( rule.operator = '<' AND rule.value <= input.value AND input.operator = '<'
  9273. OR rule.operator = '<' AND rule.value < input.value AND input.operator = '<='
  9274. OR rule.operator = '<=' AND rule.value <= input.value AND (input.operator = '<=' OR input.operator = '=')
  9275. )
  9276. */
  9277. // QUALIFY ALL ( GROUPED and LEAF ) RULES that evaluate true using the assertions from the participating rules.
  9278. /*
  9279. LEFT JOIN rule
  9280. WHERE participating.bit = (participating.bit & rule.mask)
  9281. -- and rule.operator = 'or'
  9282. -- or rule.mask = (allparticipating.mask & rule.mask ) and rule.operator = 'and'
  9283. */
  9284. /* USE THE QUALIFED RULES TO EVALUEATE RESULTS for GROUP LEVELS and ROOT RULES.
  9285. Any grouped rule is associated with 3 kinds evaluation sets composed of rules that are either leaf
  9286. level rules directly or through other promoted grouped rules or groups.
  9287. Evaluation Sets.
  9288. Permissive rules, Restrictive rules, Indeterminant rules
  9289. 1) Permissive bits turn the whole group to true if any one is true.
  9290. Irrespective of all the other participating leaf rules.
  9291. It is therefore not required to evaluate any other types of leaf rules.
  9292. 2) Restrictive rules turn the whole group to false if any one is false.
  9293. If there are no permissive rules it then becomes relevant to evaluate the restrictive rules.
  9294. Other Indeterminant rule evaluation is therefore not relevant.
  9295. 3) Indeterminant rules need to be evaluated at run time.
  9296. -- Are typically unevaluated nested groups
  9297. -- Or can be Individual Evaluated results
  9298. which don't yet determine the overall result and mean anything
  9299. until a complex hierarchy of conditions
  9300. are evaluated and collectively satisifed.
  9301. -- Since we do not (yet) support rule negations
  9302. -- it necessarily implies that if all of the Indeterminant set items are true then the whole group is true.
  9303. -- which then implies we can bypass the Indeterminant group and subgroup structure evaluation for efficiency.
  9304. -- Pre-Evaluated promotion to parent group evaluation sets to parent groups evaluation sets.
  9305. Composition of a subgroup can be promoted directly into the parent groups evaluation sets when certain conditions are met.
  9306. When There are no Permissive rules
  9307. AND ( There are no restrictive rules OR all the restrictive rules are true )
  9308. Then evaluation of the descendents rule set is required until we reach all leaf level nodes.
  9309. Subgroups are recursively evaluated using these same 3 steps.
  9310. Following caching efficiencies can be precomputed and stored with the parents rule sets as rule promotions.
  9311. If the sub group rule participates in parents permissive set.
  9312. All of its permissive rules should be added to the parent groups permissive set.
  9313. -- The sub group has no restrictive and descendents sets sub group bit need not be in the parents permissive set.
  9314. If subgroup has restricitve sets and no descendents sets
  9315. -- and is a subset of the parent groups restrictive set
  9316. -- then subgroup bit can be removed from parents permissive and restrictive groups.
  9317. -- This is good for preventing re-evaluation of the sub group for efficiency.
  9318. -- else subgroup bit should be present in the permissive
  9319. Sub group has descendents sets
  9320. -- the sub group bit must necessarily be added to the parents permissive set.
  9321. If the sub group rule participates in the parents restrictive set
  9322. - Sub Group is Pure Permissive = Has no restrictive set or descendents set
  9323. Runtime Evaluate.
  9324. - Sub Group is Pure Restrictive = Has no permissive or descendents set
  9325. -- Restrictive set of sub group should be promoted into the restrictive set of the parent
  9326. -- sub group bit should be removed from all parent sets for effciency by bypassing subgroup evaluation.
  9327. - All other cases Runtime Evaluate.
  9328. Sub Group participates in descendents set.
  9329. -- Run time evaluation.
  9330. */
  9331. getParticipating(inputRule, rList, (err, participating)=>{
  9332. getParticipatingRoots(participating, rList, (err, participatingRoots)=>{
  9333. cb(null, participatingRoots);
  9334. });
  9335. });
  9336. });
  9337. };
  9338. // PB : TODO -- Creations are easy. Edits and updates for addition of a single rule are expensive due to cascading updates to all relations.
  9339. // Connections can be made in multiple dimensions. For Rules we currlently only implement the child and parent dimensions.
  9340. // PB : TODO -ve dimensions ?? In this implementation there are no negative dimensions...
  9341. // So both -ve and +ve dimensions are independent. But can be marked as opposites.
  9342. // Note : Therefore Child and Parent are different independent dimensions.
  9343. // They may not be exactly oposing in this case ( Rules are networks ) and some circular loops may exist.
  9344. var connectRules = function(as, ...rest){ return branch[as](...rest) };
  9345. var branch = {};
  9346. branch[__Rule.AND] = function(rChild, rParent, refresh){
  9347. rChild.ancestors |= rParent.ancestors | rParent.bit; // This should set the whole ancestral network.
  9348. if(rParent.permissive || rParent.operator === OR) throw 'Error Invalid rule addition to parent'
  9349. if(rParent.restrictive & rChild.bit) return; // Was already connected within this and.
  9350. rParent.list.push(rChild);
  9351. // if(!rParent.permissive && !rParent.restrictive) {
  9352. // if(rParent.operator !== AND && rParent.operator !== OR) {
  9353. // if(!rParent.operator) rParent.operator = AND; // Implicit AND if unspeicified
  9354. // else throw 'Incomplete parent. Invalid operator or no operator specified.'
  9355. // }
  9356. // rParent.operator === AND ? rParent.restrictive |= rChild.bit : rParent.permissive |= rChild.bit ;
  9357. // }
  9358. // Promotions : All child rules are only a bunch of Ands or ors
  9359. // they can be flattened directly into the containing rule.
  9360. // if(!rParent.permissive) { rParent.restrictive |= rChild.restrictive; rParent.restrictive |= rChild.bit; }
  9361. // if(!rParent.restrictive) { rParent.permissive |= rChild.permissive; rParent.permissive |= rChild.bit; }
  9362. rParent.restrictive |= rChild.restrictive | rChild.bit;
  9363. // Descendents should be all non immediate descendents.
  9364. // Immmediate descendents can always be computed as (r.permissive | r.restrictive) & !r.descendents
  9365. // child may be either permissive or restrictive. Since child.restrictive is already added in.
  9366. rParent.descendents |= rChild.descendents | rChild.permissive | rChild.restrictive ;
  9367. // If we add another ancestral network to one of the ancestors we need to cascaded it down to the child network.
  9368. // and vice versa.
  9369. if(refresh){
  9370. // PB : TODO -- Cascading refreshes should avoid circular loops..
  9371. rChild.refreshDescendents(rChild.ancestors);
  9372. rParent.refreshAncestors(rParent.descendents);
  9373. }
  9374. };
  9375. branch[__Rule.OR] = function(rChild, rParent, refresh){
  9376. rChild.ancestors |= rParent.ancestors | rParent.bit;
  9377. if(rParent.restrictive || rParent.operator !== OR) throw 'Error Invalid rule addition to parent'
  9378. if(rParent.permissive & rChild.bit) return
  9379. rParent.list.push(rChild);
  9380. rParent.permissive |= rChild.permissive | rChild.bit;
  9381. rParent.descendents |= rChild.descendents | rChild.permissive | rChild.restrictive ;
  9382. if(refresh){
  9383. rChild.refreshDescendents(rChild.ancestors); // This should set the whole ancestral network.
  9384. rParent.refreshAncestors(rParent.descendents);
  9385. }
  9386. };
  9387. var rProto = { migrationstate : 8, operator : EQ
  9388. , evaluate // PB : TODO -- Enforce preconditions for evaluate on instance. Eg. Assignbit is a precondition for evaluate or match.
  9389. , connect : function(parent){
  9390. connectRules(operators[parent.operator].bit, this, parent);
  9391. }
  9392. // PB : TODO -- Cloning descriptors using assgin is expense. Review and just atttach to each new instance...
  9393. , get sql(){
  9394. var getSql = this.operator === AND ? getsql_cond_group : this.operator === OR ? getsql_cond_group
  9395. : ()=>this.key + ' ' + operators[this.operator].operator + ` '${this.value}' `;
  9396. return getSql.call(this)
  9397. }
  9398. , get filter(){
  9399. var getFilter = this.operator === AND ? getfilter_cond_group : this.operator === OR ? getgetfilter_cond_group
  9400. : ()=>{
  9401. var f = {};
  9402. f[this.key] = {};
  9403. f[this.key][this.operator] = this.value; return f;};
  9404. return getFilter.call(this)
  9405. }
  9406. // PB : TODO -- this.siblings will be a nice addtion.
  9407. , get mask(){ return this.permissive | this.restrictive | this.descendents | this.ancestors | this.bit }
  9408. , get isIndependent() { return this.bit === this.mask }
  9409. , get isRoot() { return !this.ancestors }
  9410. , get isChild() { return this.ancestors }
  9411. , get isParent() { return (this.permissive | this.restrictive | this.descendents) }
  9412. , get isleaf() { return !(this.permissive | this.restrictive | this.descendents) }
  9413. , get iscomposite() { return this.list.length > 1 } // PB : TODO -- Non composite parents may be possible to collapse
  9414. };
  9415. return _Rule.extend()
  9416. })();
  9417. utils_1.core = core_1;
  9418. var bbhverse = utils_1;
  9419. const { spawn: spawn$1, spawnSync } = childProcess__default['default'];
  9420. function nodeShellExec$1() {
  9421. var args = Array.from(arguments);
  9422. var opts = args[2] = args[2] || {};
  9423. opts.title ? null : opts.title = `${args[0]} ${args[1] }`;
  9424. const child = spawn$1(...arguments);
  9425. // // const spawn = require('child_process').spawn;
  9426. // const s = spawn(
  9427. // 'C:\\Program Files\\Git\\bin\\sh.exe'
  9428. // , ['notepad', 'index'], { cwd: __dirname });
  9429. var p = new Promise(function(resolve, reject){
  9430. if(!opts.detached) {
  9431. var messages = []; // PB : TODO -- Explore stream for Task level aggregation to prevent interleaved messages from multiple tasks...
  9432. var success = true;
  9433. if(opts.stdio !== 'ignore') {
  9434. child.stdout.setEncoding('utf8');
  9435. child.stderr.setEncoding('utf8');
  9436. child.stdout.on('data', (chunk) => { chunk.trim() === '' ? null : messages.push(chunk); /* console.log('d: ' + chunk) */ });
  9437. child.on('error', (chunk) => { success = false; messages.push(chunk); /* console.error('e: ' + chunk) */ } );
  9438. child.stderr.on('data', (chunk) => {
  9439. if(messages.join('').indexOf('fatal: not a git repository') > -1) opts.haserrors = true;
  9440. messages.push(chunk);
  9441. // console.error('stderr e: ' + chunk)
  9442. });
  9443. }
  9444. child.on('close', (code) => {
  9445. if(+code !== 0 || opts.haserrors) success = false;
  9446. if(opts.stdio !== 'ignore') {
  9447. var logEntry = { result: `${opts.title} exited with code ${code}`, messages };
  9448. logEntry.success = success;
  9449. if(opts.runas){
  9450. // success ? logEntry.success = true : null;
  9451. fs__default['default'].writeFileSync('run.log', ', ' + JSON.stringify(logEntry), {'flag':'a+'} );
  9452. }
  9453. else {
  9454. // console.log( messages.join('') )
  9455. process.stdout.write( messages.join('') );
  9456. }
  9457. }
  9458. if(code !== 0 || opts.haserrors) return reject(logEntry)
  9459. resolve(logEntry);
  9460. });
  9461. }
  9462. else {
  9463. child.unref();
  9464. resolve(true);
  9465. }
  9466. });
  9467. p.process = child;
  9468. return p;
  9469. }
  9470. var cli = {
  9471. nodeShellExec: nodeShellExec$1
  9472. , get prompt() {
  9473. const clii = readline__default['default'].createInterface({ input: process.stdin, output: process.stdout });
  9474. clii.ask = function(q){
  9475. return new Promise((resolve, reject)=>{
  9476. clii.question(q, (answer)=>{ resolve(answer); });
  9477. })
  9478. };
  9479. return clii
  9480. }
  9481. };
  9482. var cliverse = cli;
  9483. var colorName = {
  9484. "aliceblue": [240, 248, 255],
  9485. "antiquewhite": [250, 235, 215],
  9486. "aqua": [0, 255, 255],
  9487. "aquamarine": [127, 255, 212],
  9488. "azure": [240, 255, 255],
  9489. "beige": [245, 245, 220],
  9490. "bisque": [255, 228, 196],
  9491. "black": [0, 0, 0],
  9492. "blanchedalmond": [255, 235, 205],
  9493. "blue": [0, 0, 255],
  9494. "blueviolet": [138, 43, 226],
  9495. "brown": [165, 42, 42],
  9496. "burlywood": [222, 184, 135],
  9497. "cadetblue": [95, 158, 160],
  9498. "chartreuse": [127, 255, 0],
  9499. "chocolate": [210, 105, 30],
  9500. "coral": [255, 127, 80],
  9501. "cornflowerblue": [100, 149, 237],
  9502. "cornsilk": [255, 248, 220],
  9503. "crimson": [220, 20, 60],
  9504. "cyan": [0, 255, 255],
  9505. "darkblue": [0, 0, 139],
  9506. "darkcyan": [0, 139, 139],
  9507. "darkgoldenrod": [184, 134, 11],
  9508. "darkgray": [169, 169, 169],
  9509. "darkgreen": [0, 100, 0],
  9510. "darkgrey": [169, 169, 169],
  9511. "darkkhaki": [189, 183, 107],
  9512. "darkmagenta": [139, 0, 139],
  9513. "darkolivegreen": [85, 107, 47],
  9514. "darkorange": [255, 140, 0],
  9515. "darkorchid": [153, 50, 204],
  9516. "darkred": [139, 0, 0],
  9517. "darksalmon": [233, 150, 122],
  9518. "darkseagreen": [143, 188, 143],
  9519. "darkslateblue": [72, 61, 139],
  9520. "darkslategray": [47, 79, 79],
  9521. "darkslategrey": [47, 79, 79],
  9522. "darkturquoise": [0, 206, 209],
  9523. "darkviolet": [148, 0, 211],
  9524. "deeppink": [255, 20, 147],
  9525. "deepskyblue": [0, 191, 255],
  9526. "dimgray": [105, 105, 105],
  9527. "dimgrey": [105, 105, 105],
  9528. "dodgerblue": [30, 144, 255],
  9529. "firebrick": [178, 34, 34],
  9530. "floralwhite": [255, 250, 240],
  9531. "forestgreen": [34, 139, 34],
  9532. "fuchsia": [255, 0, 255],
  9533. "gainsboro": [220, 220, 220],
  9534. "ghostwhite": [248, 248, 255],
  9535. "gold": [255, 215, 0],
  9536. "goldenrod": [218, 165, 32],
  9537. "gray": [128, 128, 128],
  9538. "green": [0, 128, 0],
  9539. "greenyellow": [173, 255, 47],
  9540. "grey": [128, 128, 128],
  9541. "honeydew": [240, 255, 240],
  9542. "hotpink": [255, 105, 180],
  9543. "indianred": [205, 92, 92],
  9544. "indigo": [75, 0, 130],
  9545. "ivory": [255, 255, 240],
  9546. "khaki": [240, 230, 140],
  9547. "lavender": [230, 230, 250],
  9548. "lavenderblush": [255, 240, 245],
  9549. "lawngreen": [124, 252, 0],
  9550. "lemonchiffon": [255, 250, 205],
  9551. "lightblue": [173, 216, 230],
  9552. "lightcoral": [240, 128, 128],
  9553. "lightcyan": [224, 255, 255],
  9554. "lightgoldenrodyellow": [250, 250, 210],
  9555. "lightgray": [211, 211, 211],
  9556. "lightgreen": [144, 238, 144],
  9557. "lightgrey": [211, 211, 211],
  9558. "lightpink": [255, 182, 193],
  9559. "lightsalmon": [255, 160, 122],
  9560. "lightseagreen": [32, 178, 170],
  9561. "lightskyblue": [135, 206, 250],
  9562. "lightslategray": [119, 136, 153],
  9563. "lightslategrey": [119, 136, 153],
  9564. "lightsteelblue": [176, 196, 222],
  9565. "lightyellow": [255, 255, 224],
  9566. "lime": [0, 255, 0],
  9567. "limegreen": [50, 205, 50],
  9568. "linen": [250, 240, 230],
  9569. "magenta": [255, 0, 255],
  9570. "maroon": [128, 0, 0],
  9571. "mediumaquamarine": [102, 205, 170],
  9572. "mediumblue": [0, 0, 205],
  9573. "mediumorchid": [186, 85, 211],
  9574. "mediumpurple": [147, 112, 219],
  9575. "mediumseagreen": [60, 179, 113],
  9576. "mediumslateblue": [123, 104, 238],
  9577. "mediumspringgreen": [0, 250, 154],
  9578. "mediumturquoise": [72, 209, 204],
  9579. "mediumvioletred": [199, 21, 133],
  9580. "midnightblue": [25, 25, 112],
  9581. "mintcream": [245, 255, 250],
  9582. "mistyrose": [255, 228, 225],
  9583. "moccasin": [255, 228, 181],
  9584. "navajowhite": [255, 222, 173],
  9585. "navy": [0, 0, 128],
  9586. "oldlace": [253, 245, 230],
  9587. "olive": [128, 128, 0],
  9588. "olivedrab": [107, 142, 35],
  9589. "orange": [255, 165, 0],
  9590. "orangered": [255, 69, 0],
  9591. "orchid": [218, 112, 214],
  9592. "palegoldenrod": [238, 232, 170],
  9593. "palegreen": [152, 251, 152],
  9594. "paleturquoise": [175, 238, 238],
  9595. "palevioletred": [219, 112, 147],
  9596. "papayawhip": [255, 239, 213],
  9597. "peachpuff": [255, 218, 185],
  9598. "peru": [205, 133, 63],
  9599. "pink": [255, 192, 203],
  9600. "plum": [221, 160, 221],
  9601. "powderblue": [176, 224, 230],
  9602. "purple": [128, 0, 128],
  9603. "rebeccapurple": [102, 51, 153],
  9604. "red": [255, 0, 0],
  9605. "rosybrown": [188, 143, 143],
  9606. "royalblue": [65, 105, 225],
  9607. "saddlebrown": [139, 69, 19],
  9608. "salmon": [250, 128, 114],
  9609. "sandybrown": [244, 164, 96],
  9610. "seagreen": [46, 139, 87],
  9611. "seashell": [255, 245, 238],
  9612. "sienna": [160, 82, 45],
  9613. "silver": [192, 192, 192],
  9614. "skyblue": [135, 206, 235],
  9615. "slateblue": [106, 90, 205],
  9616. "slategray": [112, 128, 144],
  9617. "slategrey": [112, 128, 144],
  9618. "snow": [255, 250, 250],
  9619. "springgreen": [0, 255, 127],
  9620. "steelblue": [70, 130, 180],
  9621. "tan": [210, 180, 140],
  9622. "teal": [0, 128, 128],
  9623. "thistle": [216, 191, 216],
  9624. "tomato": [255, 99, 71],
  9625. "turquoise": [64, 224, 208],
  9626. "violet": [238, 130, 238],
  9627. "wheat": [245, 222, 179],
  9628. "white": [255, 255, 255],
  9629. "whitesmoke": [245, 245, 245],
  9630. "yellow": [255, 255, 0],
  9631. "yellowgreen": [154, 205, 50]
  9632. };
  9633. /* MIT license */
  9634. /* eslint-disable no-mixed-operators */
  9635. // NOTE: conversions should only return primitive values (i.e. arrays, or
  9636. // values that give correct `typeof` results).
  9637. // do not use box values types (i.e. Number(), String(), etc.)
  9638. const reverseKeywords = {};
  9639. for (const key of Object.keys(colorName)) {
  9640. reverseKeywords[colorName[key]] = key;
  9641. }
  9642. const convert$1 = {
  9643. rgb: {channels: 3, labels: 'rgb'},
  9644. hsl: {channels: 3, labels: 'hsl'},
  9645. hsv: {channels: 3, labels: 'hsv'},
  9646. hwb: {channels: 3, labels: 'hwb'},
  9647. cmyk: {channels: 4, labels: 'cmyk'},
  9648. xyz: {channels: 3, labels: 'xyz'},
  9649. lab: {channels: 3, labels: 'lab'},
  9650. lch: {channels: 3, labels: 'lch'},
  9651. hex: {channels: 1, labels: ['hex']},
  9652. keyword: {channels: 1, labels: ['keyword']},
  9653. ansi16: {channels: 1, labels: ['ansi16']},
  9654. ansi256: {channels: 1, labels: ['ansi256']},
  9655. hcg: {channels: 3, labels: ['h', 'c', 'g']},
  9656. apple: {channels: 3, labels: ['r16', 'g16', 'b16']},
  9657. gray: {channels: 1, labels: ['gray']}
  9658. };
  9659. var conversions = convert$1;
  9660. // Hide .channels and .labels properties
  9661. for (const model of Object.keys(convert$1)) {
  9662. if (!('channels' in convert$1[model])) {
  9663. throw new Error('missing channels property: ' + model);
  9664. }
  9665. if (!('labels' in convert$1[model])) {
  9666. throw new Error('missing channel labels property: ' + model);
  9667. }
  9668. if (convert$1[model].labels.length !== convert$1[model].channels) {
  9669. throw new Error('channel and label counts mismatch: ' + model);
  9670. }
  9671. const {channels, labels} = convert$1[model];
  9672. delete convert$1[model].channels;
  9673. delete convert$1[model].labels;
  9674. Object.defineProperty(convert$1[model], 'channels', {value: channels});
  9675. Object.defineProperty(convert$1[model], 'labels', {value: labels});
  9676. }
  9677. convert$1.rgb.hsl = function (rgb) {
  9678. const r = rgb[0] / 255;
  9679. const g = rgb[1] / 255;
  9680. const b = rgb[2] / 255;
  9681. const min = Math.min(r, g, b);
  9682. const max = Math.max(r, g, b);
  9683. const delta = max - min;
  9684. let h;
  9685. let s;
  9686. if (max === min) {
  9687. h = 0;
  9688. } else if (r === max) {
  9689. h = (g - b) / delta;
  9690. } else if (g === max) {
  9691. h = 2 + (b - r) / delta;
  9692. } else if (b === max) {
  9693. h = 4 + (r - g) / delta;
  9694. }
  9695. h = Math.min(h * 60, 360);
  9696. if (h < 0) {
  9697. h += 360;
  9698. }
  9699. const l = (min + max) / 2;
  9700. if (max === min) {
  9701. s = 0;
  9702. } else if (l <= 0.5) {
  9703. s = delta / (max + min);
  9704. } else {
  9705. s = delta / (2 - max - min);
  9706. }
  9707. return [h, s * 100, l * 100];
  9708. };
  9709. convert$1.rgb.hsv = function (rgb) {
  9710. let rdif;
  9711. let gdif;
  9712. let bdif;
  9713. let h;
  9714. let s;
  9715. const r = rgb[0] / 255;
  9716. const g = rgb[1] / 255;
  9717. const b = rgb[2] / 255;
  9718. const v = Math.max(r, g, b);
  9719. const diff = v - Math.min(r, g, b);
  9720. const diffc = function (c) {
  9721. return (v - c) / 6 / diff + 1 / 2;
  9722. };
  9723. if (diff === 0) {
  9724. h = 0;
  9725. s = 0;
  9726. } else {
  9727. s = diff / v;
  9728. rdif = diffc(r);
  9729. gdif = diffc(g);
  9730. bdif = diffc(b);
  9731. if (r === v) {
  9732. h = bdif - gdif;
  9733. } else if (g === v) {
  9734. h = (1 / 3) + rdif - bdif;
  9735. } else if (b === v) {
  9736. h = (2 / 3) + gdif - rdif;
  9737. }
  9738. if (h < 0) {
  9739. h += 1;
  9740. } else if (h > 1) {
  9741. h -= 1;
  9742. }
  9743. }
  9744. return [
  9745. h * 360,
  9746. s * 100,
  9747. v * 100
  9748. ];
  9749. };
  9750. convert$1.rgb.hwb = function (rgb) {
  9751. const r = rgb[0];
  9752. const g = rgb[1];
  9753. let b = rgb[2];
  9754. const h = convert$1.rgb.hsl(rgb)[0];
  9755. const w = 1 / 255 * Math.min(r, Math.min(g, b));
  9756. b = 1 - 1 / 255 * Math.max(r, Math.max(g, b));
  9757. return [h, w * 100, b * 100];
  9758. };
  9759. convert$1.rgb.cmyk = function (rgb) {
  9760. const r = rgb[0] / 255;
  9761. const g = rgb[1] / 255;
  9762. const b = rgb[2] / 255;
  9763. const k = Math.min(1 - r, 1 - g, 1 - b);
  9764. const c = (1 - r - k) / (1 - k) || 0;
  9765. const m = (1 - g - k) / (1 - k) || 0;
  9766. const y = (1 - b - k) / (1 - k) || 0;
  9767. return [c * 100, m * 100, y * 100, k * 100];
  9768. };
  9769. function comparativeDistance(x, y) {
  9770. /*
  9771. See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
  9772. */
  9773. return (
  9774. ((x[0] - y[0]) ** 2) +
  9775. ((x[1] - y[1]) ** 2) +
  9776. ((x[2] - y[2]) ** 2)
  9777. );
  9778. }
  9779. convert$1.rgb.keyword = function (rgb) {
  9780. const reversed = reverseKeywords[rgb];
  9781. if (reversed) {
  9782. return reversed;
  9783. }
  9784. let currentClosestDistance = Infinity;
  9785. let currentClosestKeyword;
  9786. for (const keyword of Object.keys(colorName)) {
  9787. const value = colorName[keyword];
  9788. // Compute comparative distance
  9789. const distance = comparativeDistance(rgb, value);
  9790. // Check if its less, if so set as closest
  9791. if (distance < currentClosestDistance) {
  9792. currentClosestDistance = distance;
  9793. currentClosestKeyword = keyword;
  9794. }
  9795. }
  9796. return currentClosestKeyword;
  9797. };
  9798. convert$1.keyword.rgb = function (keyword) {
  9799. return colorName[keyword];
  9800. };
  9801. convert$1.rgb.xyz = function (rgb) {
  9802. let r = rgb[0] / 255;
  9803. let g = rgb[1] / 255;
  9804. let b = rgb[2] / 255;
  9805. // Assume sRGB
  9806. r = r > 0.04045 ? (((r + 0.055) / 1.055) ** 2.4) : (r / 12.92);
  9807. g = g > 0.04045 ? (((g + 0.055) / 1.055) ** 2.4) : (g / 12.92);
  9808. b = b > 0.04045 ? (((b + 0.055) / 1.055) ** 2.4) : (b / 12.92);
  9809. const x = (r * 0.4124) + (g * 0.3576) + (b * 0.1805);
  9810. const y = (r * 0.2126) + (g * 0.7152) + (b * 0.0722);
  9811. const z = (r * 0.0193) + (g * 0.1192) + (b * 0.9505);
  9812. return [x * 100, y * 100, z * 100];
  9813. };
  9814. convert$1.rgb.lab = function (rgb) {
  9815. const xyz = convert$1.rgb.xyz(rgb);
  9816. let x = xyz[0];
  9817. let y = xyz[1];
  9818. let z = xyz[2];
  9819. x /= 95.047;
  9820. y /= 100;
  9821. z /= 108.883;
  9822. x = x > 0.008856 ? (x ** (1 / 3)) : (7.787 * x) + (16 / 116);
  9823. y = y > 0.008856 ? (y ** (1 / 3)) : (7.787 * y) + (16 / 116);
  9824. z = z > 0.008856 ? (z ** (1 / 3)) : (7.787 * z) + (16 / 116);
  9825. const l = (116 * y) - 16;
  9826. const a = 500 * (x - y);
  9827. const b = 200 * (y - z);
  9828. return [l, a, b];
  9829. };
  9830. convert$1.hsl.rgb = function (hsl) {
  9831. const h = hsl[0] / 360;
  9832. const s = hsl[1] / 100;
  9833. const l = hsl[2] / 100;
  9834. let t2;
  9835. let t3;
  9836. let val;
  9837. if (s === 0) {
  9838. val = l * 255;
  9839. return [val, val, val];
  9840. }
  9841. if (l < 0.5) {
  9842. t2 = l * (1 + s);
  9843. } else {
  9844. t2 = l + s - l * s;
  9845. }
  9846. const t1 = 2 * l - t2;
  9847. const rgb = [0, 0, 0];
  9848. for (let i = 0; i < 3; i++) {
  9849. t3 = h + 1 / 3 * -(i - 1);
  9850. if (t3 < 0) {
  9851. t3++;
  9852. }
  9853. if (t3 > 1) {
  9854. t3--;
  9855. }
  9856. if (6 * t3 < 1) {
  9857. val = t1 + (t2 - t1) * 6 * t3;
  9858. } else if (2 * t3 < 1) {
  9859. val = t2;
  9860. } else if (3 * t3 < 2) {
  9861. val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
  9862. } else {
  9863. val = t1;
  9864. }
  9865. rgb[i] = val * 255;
  9866. }
  9867. return rgb;
  9868. };
  9869. convert$1.hsl.hsv = function (hsl) {
  9870. const h = hsl[0];
  9871. let s = hsl[1] / 100;
  9872. let l = hsl[2] / 100;
  9873. let smin = s;
  9874. const lmin = Math.max(l, 0.01);
  9875. l *= 2;
  9876. s *= (l <= 1) ? l : 2 - l;
  9877. smin *= lmin <= 1 ? lmin : 2 - lmin;
  9878. const v = (l + s) / 2;
  9879. const sv = l === 0 ? (2 * smin) / (lmin + smin) : (2 * s) / (l + s);
  9880. return [h, sv * 100, v * 100];
  9881. };
  9882. convert$1.hsv.rgb = function (hsv) {
  9883. const h = hsv[0] / 60;
  9884. const s = hsv[1] / 100;
  9885. let v = hsv[2] / 100;
  9886. const hi = Math.floor(h) % 6;
  9887. const f = h - Math.floor(h);
  9888. const p = 255 * v * (1 - s);
  9889. const q = 255 * v * (1 - (s * f));
  9890. const t = 255 * v * (1 - (s * (1 - f)));
  9891. v *= 255;
  9892. switch (hi) {
  9893. case 0:
  9894. return [v, t, p];
  9895. case 1:
  9896. return [q, v, p];
  9897. case 2:
  9898. return [p, v, t];
  9899. case 3:
  9900. return [p, q, v];
  9901. case 4:
  9902. return [t, p, v];
  9903. case 5:
  9904. return [v, p, q];
  9905. }
  9906. };
  9907. convert$1.hsv.hsl = function (hsv) {
  9908. const h = hsv[0];
  9909. const s = hsv[1] / 100;
  9910. const v = hsv[2] / 100;
  9911. const vmin = Math.max(v, 0.01);
  9912. let sl;
  9913. let l;
  9914. l = (2 - s) * v;
  9915. const lmin = (2 - s) * vmin;
  9916. sl = s * vmin;
  9917. sl /= (lmin <= 1) ? lmin : 2 - lmin;
  9918. sl = sl || 0;
  9919. l /= 2;
  9920. return [h, sl * 100, l * 100];
  9921. };
  9922. // http://dev.w3.org/csswg/css-color/#hwb-to-rgb
  9923. convert$1.hwb.rgb = function (hwb) {
  9924. const h = hwb[0] / 360;
  9925. let wh = hwb[1] / 100;
  9926. let bl = hwb[2] / 100;
  9927. const ratio = wh + bl;
  9928. let f;
  9929. // Wh + bl cant be > 1
  9930. if (ratio > 1) {
  9931. wh /= ratio;
  9932. bl /= ratio;
  9933. }
  9934. const i = Math.floor(6 * h);
  9935. const v = 1 - bl;
  9936. f = 6 * h - i;
  9937. if ((i & 0x01) !== 0) {
  9938. f = 1 - f;
  9939. }
  9940. const n = wh + f * (v - wh); // Linear interpolation
  9941. let r;
  9942. let g;
  9943. let b;
  9944. /* eslint-disable max-statements-per-line,no-multi-spaces */
  9945. switch (i) {
  9946. default:
  9947. case 6:
  9948. case 0: r = v; g = n; b = wh; break;
  9949. case 1: r = n; g = v; b = wh; break;
  9950. case 2: r = wh; g = v; b = n; break;
  9951. case 3: r = wh; g = n; b = v; break;
  9952. case 4: r = n; g = wh; b = v; break;
  9953. case 5: r = v; g = wh; b = n; break;
  9954. }
  9955. /* eslint-enable max-statements-per-line,no-multi-spaces */
  9956. return [r * 255, g * 255, b * 255];
  9957. };
  9958. convert$1.cmyk.rgb = function (cmyk) {
  9959. const c = cmyk[0] / 100;
  9960. const m = cmyk[1] / 100;
  9961. const y = cmyk[2] / 100;
  9962. const k = cmyk[3] / 100;
  9963. const r = 1 - Math.min(1, c * (1 - k) + k);
  9964. const g = 1 - Math.min(1, m * (1 - k) + k);
  9965. const b = 1 - Math.min(1, y * (1 - k) + k);
  9966. return [r * 255, g * 255, b * 255];
  9967. };
  9968. convert$1.xyz.rgb = function (xyz) {
  9969. const x = xyz[0] / 100;
  9970. const y = xyz[1] / 100;
  9971. const z = xyz[2] / 100;
  9972. let r;
  9973. let g;
  9974. let b;
  9975. r = (x * 3.2406) + (y * -1.5372) + (z * -0.4986);
  9976. g = (x * -0.9689) + (y * 1.8758) + (z * 0.0415);
  9977. b = (x * 0.0557) + (y * -0.2040) + (z * 1.0570);
  9978. // Assume sRGB
  9979. r = r > 0.0031308
  9980. ? ((1.055 * (r ** (1.0 / 2.4))) - 0.055)
  9981. : r * 12.92;
  9982. g = g > 0.0031308
  9983. ? ((1.055 * (g ** (1.0 / 2.4))) - 0.055)
  9984. : g * 12.92;
  9985. b = b > 0.0031308
  9986. ? ((1.055 * (b ** (1.0 / 2.4))) - 0.055)
  9987. : b * 12.92;
  9988. r = Math.min(Math.max(0, r), 1);
  9989. g = Math.min(Math.max(0, g), 1);
  9990. b = Math.min(Math.max(0, b), 1);
  9991. return [r * 255, g * 255, b * 255];
  9992. };
  9993. convert$1.xyz.lab = function (xyz) {
  9994. let x = xyz[0];
  9995. let y = xyz[1];
  9996. let z = xyz[2];
  9997. x /= 95.047;
  9998. y /= 100;
  9999. z /= 108.883;
  10000. x = x > 0.008856 ? (x ** (1 / 3)) : (7.787 * x) + (16 / 116);
  10001. y = y > 0.008856 ? (y ** (1 / 3)) : (7.787 * y) + (16 / 116);
  10002. z = z > 0.008856 ? (z ** (1 / 3)) : (7.787 * z) + (16 / 116);
  10003. const l = (116 * y) - 16;
  10004. const a = 500 * (x - y);
  10005. const b = 200 * (y - z);
  10006. return [l, a, b];
  10007. };
  10008. convert$1.lab.xyz = function (lab) {
  10009. const l = lab[0];
  10010. const a = lab[1];
  10011. const b = lab[2];
  10012. let x;
  10013. let y;
  10014. let z;
  10015. y = (l + 16) / 116;
  10016. x = a / 500 + y;
  10017. z = y - b / 200;
  10018. const y2 = y ** 3;
  10019. const x2 = x ** 3;
  10020. const z2 = z ** 3;
  10021. y = y2 > 0.008856 ? y2 : (y - 16 / 116) / 7.787;
  10022. x = x2 > 0.008856 ? x2 : (x - 16 / 116) / 7.787;
  10023. z = z2 > 0.008856 ? z2 : (z - 16 / 116) / 7.787;
  10024. x *= 95.047;
  10025. y *= 100;
  10026. z *= 108.883;
  10027. return [x, y, z];
  10028. };
  10029. convert$1.lab.lch = function (lab) {
  10030. const l = lab[0];
  10031. const a = lab[1];
  10032. const b = lab[2];
  10033. let h;
  10034. const hr = Math.atan2(b, a);
  10035. h = hr * 360 / 2 / Math.PI;
  10036. if (h < 0) {
  10037. h += 360;
  10038. }
  10039. const c = Math.sqrt(a * a + b * b);
  10040. return [l, c, h];
  10041. };
  10042. convert$1.lch.lab = function (lch) {
  10043. const l = lch[0];
  10044. const c = lch[1];
  10045. const h = lch[2];
  10046. const hr = h / 360 * 2 * Math.PI;
  10047. const a = c * Math.cos(hr);
  10048. const b = c * Math.sin(hr);
  10049. return [l, a, b];
  10050. };
  10051. convert$1.rgb.ansi16 = function (args, saturation = null) {
  10052. const [r, g, b] = args;
  10053. let value = saturation === null ? convert$1.rgb.hsv(args)[2] : saturation; // Hsv -> ansi16 optimization
  10054. value = Math.round(value / 50);
  10055. if (value === 0) {
  10056. return 30;
  10057. }
  10058. let ansi = 30
  10059. + ((Math.round(b / 255) << 2)
  10060. | (Math.round(g / 255) << 1)
  10061. | Math.round(r / 255));
  10062. if (value === 2) {
  10063. ansi += 60;
  10064. }
  10065. return ansi;
  10066. };
  10067. convert$1.hsv.ansi16 = function (args) {
  10068. // Optimization here; we already know the value and don't need to get
  10069. // it converted for us.
  10070. return convert$1.rgb.ansi16(convert$1.hsv.rgb(args), args[2]);
  10071. };
  10072. convert$1.rgb.ansi256 = function (args) {
  10073. const r = args[0];
  10074. const g = args[1];
  10075. const b = args[2];
  10076. // We use the extended greyscale palette here, with the exception of
  10077. // black and white. normal palette only has 4 greyscale shades.
  10078. if (r === g && g === b) {
  10079. if (r < 8) {
  10080. return 16;
  10081. }
  10082. if (r > 248) {
  10083. return 231;
  10084. }
  10085. return Math.round(((r - 8) / 247) * 24) + 232;
  10086. }
  10087. const ansi = 16
  10088. + (36 * Math.round(r / 255 * 5))
  10089. + (6 * Math.round(g / 255 * 5))
  10090. + Math.round(b / 255 * 5);
  10091. return ansi;
  10092. };
  10093. convert$1.ansi16.rgb = function (args) {
  10094. let color = args % 10;
  10095. // Handle greyscale
  10096. if (color === 0 || color === 7) {
  10097. if (args > 50) {
  10098. color += 3.5;
  10099. }
  10100. color = color / 10.5 * 255;
  10101. return [color, color, color];
  10102. }
  10103. const mult = (~~(args > 50) + 1) * 0.5;
  10104. const r = ((color & 1) * mult) * 255;
  10105. const g = (((color >> 1) & 1) * mult) * 255;
  10106. const b = (((color >> 2) & 1) * mult) * 255;
  10107. return [r, g, b];
  10108. };
  10109. convert$1.ansi256.rgb = function (args) {
  10110. // Handle greyscale
  10111. if (args >= 232) {
  10112. const c = (args - 232) * 10 + 8;
  10113. return [c, c, c];
  10114. }
  10115. args -= 16;
  10116. let rem;
  10117. const r = Math.floor(args / 36) / 5 * 255;
  10118. const g = Math.floor((rem = args % 36) / 6) / 5 * 255;
  10119. const b = (rem % 6) / 5 * 255;
  10120. return [r, g, b];
  10121. };
  10122. convert$1.rgb.hex = function (args) {
  10123. const integer = ((Math.round(args[0]) & 0xFF) << 16)
  10124. + ((Math.round(args[1]) & 0xFF) << 8)
  10125. + (Math.round(args[2]) & 0xFF);
  10126. const string = integer.toString(16).toUpperCase();
  10127. return '000000'.substring(string.length) + string;
  10128. };
  10129. convert$1.hex.rgb = function (args) {
  10130. const match = args.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);
  10131. if (!match) {
  10132. return [0, 0, 0];
  10133. }
  10134. let colorString = match[0];
  10135. if (match[0].length === 3) {
  10136. colorString = colorString.split('').map(char => {
  10137. return char + char;
  10138. }).join('');
  10139. }
  10140. const integer = parseInt(colorString, 16);
  10141. const r = (integer >> 16) & 0xFF;
  10142. const g = (integer >> 8) & 0xFF;
  10143. const b = integer & 0xFF;
  10144. return [r, g, b];
  10145. };
  10146. convert$1.rgb.hcg = function (rgb) {
  10147. const r = rgb[0] / 255;
  10148. const g = rgb[1] / 255;
  10149. const b = rgb[2] / 255;
  10150. const max = Math.max(Math.max(r, g), b);
  10151. const min = Math.min(Math.min(r, g), b);
  10152. const chroma = (max - min);
  10153. let grayscale;
  10154. let hue;
  10155. if (chroma < 1) {
  10156. grayscale = min / (1 - chroma);
  10157. } else {
  10158. grayscale = 0;
  10159. }
  10160. if (chroma <= 0) {
  10161. hue = 0;
  10162. } else
  10163. if (max === r) {
  10164. hue = ((g - b) / chroma) % 6;
  10165. } else
  10166. if (max === g) {
  10167. hue = 2 + (b - r) / chroma;
  10168. } else {
  10169. hue = 4 + (r - g) / chroma;
  10170. }
  10171. hue /= 6;
  10172. hue %= 1;
  10173. return [hue * 360, chroma * 100, grayscale * 100];
  10174. };
  10175. convert$1.hsl.hcg = function (hsl) {
  10176. const s = hsl[1] / 100;
  10177. const l = hsl[2] / 100;
  10178. const c = l < 0.5 ? (2.0 * s * l) : (2.0 * s * (1.0 - l));
  10179. let f = 0;
  10180. if (c < 1.0) {
  10181. f = (l - 0.5 * c) / (1.0 - c);
  10182. }
  10183. return [hsl[0], c * 100, f * 100];
  10184. };
  10185. convert$1.hsv.hcg = function (hsv) {
  10186. const s = hsv[1] / 100;
  10187. const v = hsv[2] / 100;
  10188. const c = s * v;
  10189. let f = 0;
  10190. if (c < 1.0) {
  10191. f = (v - c) / (1 - c);
  10192. }
  10193. return [hsv[0], c * 100, f * 100];
  10194. };
  10195. convert$1.hcg.rgb = function (hcg) {
  10196. const h = hcg[0] / 360;
  10197. const c = hcg[1] / 100;
  10198. const g = hcg[2] / 100;
  10199. if (c === 0.0) {
  10200. return [g * 255, g * 255, g * 255];
  10201. }
  10202. const pure = [0, 0, 0];
  10203. const hi = (h % 1) * 6;
  10204. const v = hi % 1;
  10205. const w = 1 - v;
  10206. let mg = 0;
  10207. /* eslint-disable max-statements-per-line */
  10208. switch (Math.floor(hi)) {
  10209. case 0:
  10210. pure[0] = 1; pure[1] = v; pure[2] = 0; break;
  10211. case 1:
  10212. pure[0] = w; pure[1] = 1; pure[2] = 0; break;
  10213. case 2:
  10214. pure[0] = 0; pure[1] = 1; pure[2] = v; break;
  10215. case 3:
  10216. pure[0] = 0; pure[1] = w; pure[2] = 1; break;
  10217. case 4:
  10218. pure[0] = v; pure[1] = 0; pure[2] = 1; break;
  10219. default:
  10220. pure[0] = 1; pure[1] = 0; pure[2] = w;
  10221. }
  10222. /* eslint-enable max-statements-per-line */
  10223. mg = (1.0 - c) * g;
  10224. return [
  10225. (c * pure[0] + mg) * 255,
  10226. (c * pure[1] + mg) * 255,
  10227. (c * pure[2] + mg) * 255
  10228. ];
  10229. };
  10230. convert$1.hcg.hsv = function (hcg) {
  10231. const c = hcg[1] / 100;
  10232. const g = hcg[2] / 100;
  10233. const v = c + g * (1.0 - c);
  10234. let f = 0;
  10235. if (v > 0.0) {
  10236. f = c / v;
  10237. }
  10238. return [hcg[0], f * 100, v * 100];
  10239. };
  10240. convert$1.hcg.hsl = function (hcg) {
  10241. const c = hcg[1] / 100;
  10242. const g = hcg[2] / 100;
  10243. const l = g * (1.0 - c) + 0.5 * c;
  10244. let s = 0;
  10245. if (l > 0.0 && l < 0.5) {
  10246. s = c / (2 * l);
  10247. } else
  10248. if (l >= 0.5 && l < 1.0) {
  10249. s = c / (2 * (1 - l));
  10250. }
  10251. return [hcg[0], s * 100, l * 100];
  10252. };
  10253. convert$1.hcg.hwb = function (hcg) {
  10254. const c = hcg[1] / 100;
  10255. const g = hcg[2] / 100;
  10256. const v = c + g * (1.0 - c);
  10257. return [hcg[0], (v - c) * 100, (1 - v) * 100];
  10258. };
  10259. convert$1.hwb.hcg = function (hwb) {
  10260. const w = hwb[1] / 100;
  10261. const b = hwb[2] / 100;
  10262. const v = 1 - b;
  10263. const c = v - w;
  10264. let g = 0;
  10265. if (c < 1) {
  10266. g = (v - c) / (1 - c);
  10267. }
  10268. return [hwb[0], c * 100, g * 100];
  10269. };
  10270. convert$1.apple.rgb = function (apple) {
  10271. return [(apple[0] / 65535) * 255, (apple[1] / 65535) * 255, (apple[2] / 65535) * 255];
  10272. };
  10273. convert$1.rgb.apple = function (rgb) {
  10274. return [(rgb[0] / 255) * 65535, (rgb[1] / 255) * 65535, (rgb[2] / 255) * 65535];
  10275. };
  10276. convert$1.gray.rgb = function (args) {
  10277. return [args[0] / 100 * 255, args[0] / 100 * 255, args[0] / 100 * 255];
  10278. };
  10279. convert$1.gray.hsl = function (args) {
  10280. return [0, 0, args[0]];
  10281. };
  10282. convert$1.gray.hsv = convert$1.gray.hsl;
  10283. convert$1.gray.hwb = function (gray) {
  10284. return [0, 100, gray[0]];
  10285. };
  10286. convert$1.gray.cmyk = function (gray) {
  10287. return [0, 0, 0, gray[0]];
  10288. };
  10289. convert$1.gray.lab = function (gray) {
  10290. return [gray[0], 0, 0];
  10291. };
  10292. convert$1.gray.hex = function (gray) {
  10293. const val = Math.round(gray[0] / 100 * 255) & 0xFF;
  10294. const integer = (val << 16) + (val << 8) + val;
  10295. const string = integer.toString(16).toUpperCase();
  10296. return '000000'.substring(string.length) + string;
  10297. };
  10298. convert$1.rgb.gray = function (rgb) {
  10299. const val = (rgb[0] + rgb[1] + rgb[2]) / 3;
  10300. return [val / 255 * 100];
  10301. };
  10302. /*
  10303. This function routes a model to all other models.
  10304. all functions that are routed have a property `.conversion` attached
  10305. to the returned synthetic function. This property is an array
  10306. of strings, each with the steps in between the 'from' and 'to'
  10307. color models (inclusive).
  10308. conversions that are not possible simply are not included.
  10309. */
  10310. function buildGraph() {
  10311. const graph = {};
  10312. // https://jsperf.com/object-keys-vs-for-in-with-closure/3
  10313. const models = Object.keys(conversions);
  10314. for (let len = models.length, i = 0; i < len; i++) {
  10315. graph[models[i]] = {
  10316. // http://jsperf.com/1-vs-infinity
  10317. // micro-opt, but this is simple.
  10318. distance: -1,
  10319. parent: null
  10320. };
  10321. }
  10322. return graph;
  10323. }
  10324. // https://en.wikipedia.org/wiki/Breadth-first_search
  10325. function deriveBFS(fromModel) {
  10326. const graph = buildGraph();
  10327. const queue = [fromModel]; // Unshift -> queue -> pop
  10328. graph[fromModel].distance = 0;
  10329. while (queue.length) {
  10330. const current = queue.pop();
  10331. const adjacents = Object.keys(conversions[current]);
  10332. for (let len = adjacents.length, i = 0; i < len; i++) {
  10333. const adjacent = adjacents[i];
  10334. const node = graph[adjacent];
  10335. if (node.distance === -1) {
  10336. node.distance = graph[current].distance + 1;
  10337. node.parent = current;
  10338. queue.unshift(adjacent);
  10339. }
  10340. }
  10341. }
  10342. return graph;
  10343. }
  10344. function link(from, to) {
  10345. return function (args) {
  10346. return to(from(args));
  10347. };
  10348. }
  10349. function wrapConversion(toModel, graph) {
  10350. const path = [graph[toModel].parent, toModel];
  10351. let fn = conversions[graph[toModel].parent][toModel];
  10352. let cur = graph[toModel].parent;
  10353. while (graph[cur].parent) {
  10354. path.unshift(graph[cur].parent);
  10355. fn = link(conversions[graph[cur].parent][cur], fn);
  10356. cur = graph[cur].parent;
  10357. }
  10358. fn.conversion = path;
  10359. return fn;
  10360. }
  10361. var route = function (fromModel) {
  10362. const graph = deriveBFS(fromModel);
  10363. const conversion = {};
  10364. const models = Object.keys(graph);
  10365. for (let len = models.length, i = 0; i < len; i++) {
  10366. const toModel = models[i];
  10367. const node = graph[toModel];
  10368. if (node.parent === null) {
  10369. // No possible conversion, or this node is the source model.
  10370. continue;
  10371. }
  10372. conversion[toModel] = wrapConversion(toModel, graph);
  10373. }
  10374. return conversion;
  10375. };
  10376. const convert = {};
  10377. const models = Object.keys(conversions);
  10378. function wrapRaw(fn) {
  10379. const wrappedFn = function (...args) {
  10380. const arg0 = args[0];
  10381. if (arg0 === undefined || arg0 === null) {
  10382. return arg0;
  10383. }
  10384. if (arg0.length > 1) {
  10385. args = arg0;
  10386. }
  10387. return fn(args);
  10388. };
  10389. // Preserve .conversion property if there is one
  10390. if ('conversion' in fn) {
  10391. wrappedFn.conversion = fn.conversion;
  10392. }
  10393. return wrappedFn;
  10394. }
  10395. function wrapRounded(fn) {
  10396. const wrappedFn = function (...args) {
  10397. const arg0 = args[0];
  10398. if (arg0 === undefined || arg0 === null) {
  10399. return arg0;
  10400. }
  10401. if (arg0.length > 1) {
  10402. args = arg0;
  10403. }
  10404. const result = fn(args);
  10405. // We're assuming the result is an array here.
  10406. // see notice in conversions.js; don't use box types
  10407. // in conversion functions.
  10408. if (typeof result === 'object') {
  10409. for (let len = result.length, i = 0; i < len; i++) {
  10410. result[i] = Math.round(result[i]);
  10411. }
  10412. }
  10413. return result;
  10414. };
  10415. // Preserve .conversion property if there is one
  10416. if ('conversion' in fn) {
  10417. wrappedFn.conversion = fn.conversion;
  10418. }
  10419. return wrappedFn;
  10420. }
  10421. models.forEach(fromModel => {
  10422. convert[fromModel] = {};
  10423. Object.defineProperty(convert[fromModel], 'channels', {value: conversions[fromModel].channels});
  10424. Object.defineProperty(convert[fromModel], 'labels', {value: conversions[fromModel].labels});
  10425. const routes = route(fromModel);
  10426. const routeModels = Object.keys(routes);
  10427. routeModels.forEach(toModel => {
  10428. const fn = routes[toModel];
  10429. convert[fromModel][toModel] = wrapRounded(fn);
  10430. convert[fromModel][toModel].raw = wrapRaw(fn);
  10431. });
  10432. });
  10433. var colorConvert = convert;
  10434. var ansiStyles = createCommonjsModule(function (module) {
  10435. const wrapAnsi16 = (fn, offset) => (...args) => {
  10436. const code = fn(...args);
  10437. return `\u001B[${code + offset}m`;
  10438. };
  10439. const wrapAnsi256 = (fn, offset) => (...args) => {
  10440. const code = fn(...args);
  10441. return `\u001B[${38 + offset};5;${code}m`;
  10442. };
  10443. const wrapAnsi16m = (fn, offset) => (...args) => {
  10444. const rgb = fn(...args);
  10445. return `\u001B[${38 + offset};2;${rgb[0]};${rgb[1]};${rgb[2]}m`;
  10446. };
  10447. const ansi2ansi = n => n;
  10448. const rgb2rgb = (r, g, b) => [r, g, b];
  10449. const setLazyProperty = (object, property, get) => {
  10450. Object.defineProperty(object, property, {
  10451. get: () => {
  10452. const value = get();
  10453. Object.defineProperty(object, property, {
  10454. value,
  10455. enumerable: true,
  10456. configurable: true
  10457. });
  10458. return value;
  10459. },
  10460. enumerable: true,
  10461. configurable: true
  10462. });
  10463. };
  10464. /** @type {typeof import('color-convert')} */
  10465. let colorConvert$1;
  10466. const makeDynamicStyles = (wrap, targetSpace, identity, isBackground) => {
  10467. if (colorConvert$1 === undefined) {
  10468. colorConvert$1 = colorConvert;
  10469. }
  10470. const offset = isBackground ? 10 : 0;
  10471. const styles = {};
  10472. for (const [sourceSpace, suite] of Object.entries(colorConvert$1)) {
  10473. const name = sourceSpace === 'ansi16' ? 'ansi' : sourceSpace;
  10474. if (sourceSpace === targetSpace) {
  10475. styles[name] = wrap(identity, offset);
  10476. } else if (typeof suite === 'object') {
  10477. styles[name] = wrap(suite[targetSpace], offset);
  10478. }
  10479. }
  10480. return styles;
  10481. };
  10482. function assembleStyles() {
  10483. const codes = new Map();
  10484. const styles = {
  10485. modifier: {
  10486. reset: [0, 0],
  10487. // 21 isn't widely supported and 22 does the same thing
  10488. bold: [1, 22],
  10489. dim: [2, 22],
  10490. italic: [3, 23],
  10491. underline: [4, 24],
  10492. inverse: [7, 27],
  10493. hidden: [8, 28],
  10494. strikethrough: [9, 29]
  10495. },
  10496. color: {
  10497. black: [30, 39],
  10498. red: [31, 39],
  10499. green: [32, 39],
  10500. yellow: [33, 39],
  10501. blue: [34, 39],
  10502. magenta: [35, 39],
  10503. cyan: [36, 39],
  10504. white: [37, 39],
  10505. // Bright color
  10506. blackBright: [90, 39],
  10507. redBright: [91, 39],
  10508. greenBright: [92, 39],
  10509. yellowBright: [93, 39],
  10510. blueBright: [94, 39],
  10511. magentaBright: [95, 39],
  10512. cyanBright: [96, 39],
  10513. whiteBright: [97, 39]
  10514. },
  10515. bgColor: {
  10516. bgBlack: [40, 49],
  10517. bgRed: [41, 49],
  10518. bgGreen: [42, 49],
  10519. bgYellow: [43, 49],
  10520. bgBlue: [44, 49],
  10521. bgMagenta: [45, 49],
  10522. bgCyan: [46, 49],
  10523. bgWhite: [47, 49],
  10524. // Bright color
  10525. bgBlackBright: [100, 49],
  10526. bgRedBright: [101, 49],
  10527. bgGreenBright: [102, 49],
  10528. bgYellowBright: [103, 49],
  10529. bgBlueBright: [104, 49],
  10530. bgMagentaBright: [105, 49],
  10531. bgCyanBright: [106, 49],
  10532. bgWhiteBright: [107, 49]
  10533. }
  10534. };
  10535. // Alias bright black as gray (and grey)
  10536. styles.color.gray = styles.color.blackBright;
  10537. styles.bgColor.bgGray = styles.bgColor.bgBlackBright;
  10538. styles.color.grey = styles.color.blackBright;
  10539. styles.bgColor.bgGrey = styles.bgColor.bgBlackBright;
  10540. for (const [groupName, group] of Object.entries(styles)) {
  10541. for (const [styleName, style] of Object.entries(group)) {
  10542. styles[styleName] = {
  10543. open: `\u001B[${style[0]}m`,
  10544. close: `\u001B[${style[1]}m`
  10545. };
  10546. group[styleName] = styles[styleName];
  10547. codes.set(style[0], style[1]);
  10548. }
  10549. Object.defineProperty(styles, groupName, {
  10550. value: group,
  10551. enumerable: false
  10552. });
  10553. }
  10554. Object.defineProperty(styles, 'codes', {
  10555. value: codes,
  10556. enumerable: false
  10557. });
  10558. styles.color.close = '\u001B[39m';
  10559. styles.bgColor.close = '\u001B[49m';
  10560. setLazyProperty(styles.color, 'ansi', () => makeDynamicStyles(wrapAnsi16, 'ansi16', ansi2ansi, false));
  10561. setLazyProperty(styles.color, 'ansi256', () => makeDynamicStyles(wrapAnsi256, 'ansi256', ansi2ansi, false));
  10562. setLazyProperty(styles.color, 'ansi16m', () => makeDynamicStyles(wrapAnsi16m, 'rgb', rgb2rgb, false));
  10563. setLazyProperty(styles.bgColor, 'ansi', () => makeDynamicStyles(wrapAnsi16, 'ansi16', ansi2ansi, true));
  10564. setLazyProperty(styles.bgColor, 'ansi256', () => makeDynamicStyles(wrapAnsi256, 'ansi256', ansi2ansi, true));
  10565. setLazyProperty(styles.bgColor, 'ansi16m', () => makeDynamicStyles(wrapAnsi16m, 'rgb', rgb2rgb, true));
  10566. return styles;
  10567. }
  10568. // Make the export immutable
  10569. Object.defineProperty(module, 'exports', {
  10570. enumerable: true,
  10571. get: assembleStyles
  10572. });
  10573. }, "/$$rollup_base$$/node_modules/ansi-styles");
  10574. var hasFlag = (flag, argv = process.argv) => {
  10575. const prefix = flag.startsWith('-') ? '' : (flag.length === 1 ? '-' : '--');
  10576. const position = argv.indexOf(prefix + flag);
  10577. const terminatorPosition = argv.indexOf('--');
  10578. return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
  10579. };
  10580. const {env: env$1} = process;
  10581. let forceColor;
  10582. if (hasFlag('no-color') ||
  10583. hasFlag('no-colors') ||
  10584. hasFlag('color=false') ||
  10585. hasFlag('color=never')) {
  10586. forceColor = 0;
  10587. } else if (hasFlag('color') ||
  10588. hasFlag('colors') ||
  10589. hasFlag('color=true') ||
  10590. hasFlag('color=always')) {
  10591. forceColor = 1;
  10592. }
  10593. if ('FORCE_COLOR' in env$1) {
  10594. if (env$1.FORCE_COLOR === 'true') {
  10595. forceColor = 1;
  10596. } else if (env$1.FORCE_COLOR === 'false') {
  10597. forceColor = 0;
  10598. } else {
  10599. forceColor = env$1.FORCE_COLOR.length === 0 ? 1 : Math.min(parseInt(env$1.FORCE_COLOR, 10), 3);
  10600. }
  10601. }
  10602. function translateLevel(level) {
  10603. if (level === 0) {
  10604. return false;
  10605. }
  10606. return {
  10607. level,
  10608. hasBasic: true,
  10609. has256: level >= 2,
  10610. has16m: level >= 3
  10611. };
  10612. }
  10613. function supportsColor(haveStream, streamIsTTY) {
  10614. if (forceColor === 0) {
  10615. return 0;
  10616. }
  10617. if (hasFlag('color=16m') ||
  10618. hasFlag('color=full') ||
  10619. hasFlag('color=truecolor')) {
  10620. return 3;
  10621. }
  10622. if (hasFlag('color=256')) {
  10623. return 2;
  10624. }
  10625. if (haveStream && !streamIsTTY && forceColor === undefined) {
  10626. return 0;
  10627. }
  10628. const min = forceColor || 0;
  10629. if (env$1.TERM === 'dumb') {
  10630. return min;
  10631. }
  10632. if (process.platform === 'win32') {
  10633. // Windows 10 build 10586 is the first Windows release that supports 256 colors.
  10634. // Windows 10 build 14931 is the first release that supports 16m/TrueColor.
  10635. const osRelease = os__default['default'].release().split('.');
  10636. if (
  10637. Number(osRelease[0]) >= 10 &&
  10638. Number(osRelease[2]) >= 10586
  10639. ) {
  10640. return Number(osRelease[2]) >= 14931 ? 3 : 2;
  10641. }
  10642. return 1;
  10643. }
  10644. if ('CI' in env$1) {
  10645. if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI', 'GITHUB_ACTIONS', 'BUILDKITE'].some(sign => sign in env$1) || env$1.CI_NAME === 'codeship') {
  10646. return 1;
  10647. }
  10648. return min;
  10649. }
  10650. if ('TEAMCITY_VERSION' in env$1) {
  10651. return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env$1.TEAMCITY_VERSION) ? 1 : 0;
  10652. }
  10653. if (env$1.COLORTERM === 'truecolor') {
  10654. return 3;
  10655. }
  10656. if ('TERM_PROGRAM' in env$1) {
  10657. const version = parseInt((env$1.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
  10658. switch (env$1.TERM_PROGRAM) {
  10659. case 'iTerm.app':
  10660. return version >= 3 ? 3 : 2;
  10661. case 'Apple_Terminal':
  10662. return 2;
  10663. // No default
  10664. }
  10665. }
  10666. if (/-256(color)?$/i.test(env$1.TERM)) {
  10667. return 2;
  10668. }
  10669. if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env$1.TERM)) {
  10670. return 1;
  10671. }
  10672. if ('COLORTERM' in env$1) {
  10673. return 1;
  10674. }
  10675. return min;
  10676. }
  10677. function getSupportLevel(stream) {
  10678. const level = supportsColor(stream, stream && stream.isTTY);
  10679. return translateLevel(level);
  10680. }
  10681. var supportsColor_1 = {
  10682. supportsColor: getSupportLevel,
  10683. stdout: translateLevel(supportsColor(true, tty__default['default'].isatty(1))),
  10684. stderr: translateLevel(supportsColor(true, tty__default['default'].isatty(2)))
  10685. };
  10686. const stringReplaceAll$1 = (string, substring, replacer) => {
  10687. let index = string.indexOf(substring);
  10688. if (index === -1) {
  10689. return string;
  10690. }
  10691. const substringLength = substring.length;
  10692. let endIndex = 0;
  10693. let returnValue = '';
  10694. do {
  10695. returnValue += string.substr(endIndex, index - endIndex) + substring + replacer;
  10696. endIndex = index + substringLength;
  10697. index = string.indexOf(substring, endIndex);
  10698. } while (index !== -1);
  10699. returnValue += string.substr(endIndex);
  10700. return returnValue;
  10701. };
  10702. const stringEncaseCRLFWithFirstIndex$1 = (string, prefix, postfix, index) => {
  10703. let endIndex = 0;
  10704. let returnValue = '';
  10705. do {
  10706. const gotCR = string[index - 1] === '\r';
  10707. returnValue += string.substr(endIndex, (gotCR ? index - 1 : index) - endIndex) + prefix + (gotCR ? '\r\n' : '\n') + postfix;
  10708. endIndex = index + 1;
  10709. index = string.indexOf('\n', endIndex);
  10710. } while (index !== -1);
  10711. returnValue += string.substr(endIndex);
  10712. return returnValue;
  10713. };
  10714. var util = {
  10715. stringReplaceAll: stringReplaceAll$1,
  10716. stringEncaseCRLFWithFirstIndex: stringEncaseCRLFWithFirstIndex$1
  10717. };
  10718. const TEMPLATE_REGEX = /(?:\\(u(?:[a-f\d]{4}|\{[a-f\d]{1,6}\})|x[a-f\d]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi;
  10719. const STYLE_REGEX = /(?:^|\.)(\w+)(?:\(([^)]*)\))?/g;
  10720. const STRING_REGEX = /^(['"])((?:\\.|(?!\1)[^\\])*)\1$/;
  10721. const ESCAPE_REGEX = /\\(u(?:[a-f\d]{4}|{[a-f\d]{1,6}})|x[a-f\d]{2}|.)|([^\\])/gi;
  10722. const ESCAPES = new Map([
  10723. ['n', '\n'],
  10724. ['r', '\r'],
  10725. ['t', '\t'],
  10726. ['b', '\b'],
  10727. ['f', '\f'],
  10728. ['v', '\v'],
  10729. ['0', '\0'],
  10730. ['\\', '\\'],
  10731. ['e', '\u001B'],
  10732. ['a', '\u0007']
  10733. ]);
  10734. function unescape(c) {
  10735. const u = c[0] === 'u';
  10736. const bracket = c[1] === '{';
  10737. if ((u && !bracket && c.length === 5) || (c[0] === 'x' && c.length === 3)) {
  10738. return String.fromCharCode(parseInt(c.slice(1), 16));
  10739. }
  10740. if (u && bracket) {
  10741. return String.fromCodePoint(parseInt(c.slice(2, -1), 16));
  10742. }
  10743. return ESCAPES.get(c) || c;
  10744. }
  10745. function parseArguments(name, arguments_) {
  10746. const results = [];
  10747. const chunks = arguments_.trim().split(/\s*,\s*/g);
  10748. let matches;
  10749. for (const chunk of chunks) {
  10750. const number = Number(chunk);
  10751. if (!Number.isNaN(number)) {
  10752. results.push(number);
  10753. } else if ((matches = chunk.match(STRING_REGEX))) {
  10754. results.push(matches[2].replace(ESCAPE_REGEX, (m, escape, character) => escape ? unescape(escape) : character));
  10755. } else {
  10756. throw new Error(`Invalid Chalk template style argument: ${chunk} (in style '${name}')`);
  10757. }
  10758. }
  10759. return results;
  10760. }
  10761. function parseStyle(style) {
  10762. STYLE_REGEX.lastIndex = 0;
  10763. const results = [];
  10764. let matches;
  10765. while ((matches = STYLE_REGEX.exec(style)) !== null) {
  10766. const name = matches[1];
  10767. if (matches[2]) {
  10768. const args = parseArguments(name, matches[2]);
  10769. results.push([name].concat(args));
  10770. } else {
  10771. results.push([name]);
  10772. }
  10773. }
  10774. return results;
  10775. }
  10776. function buildStyle(chalk, styles) {
  10777. const enabled = {};
  10778. for (const layer of styles) {
  10779. for (const style of layer.styles) {
  10780. enabled[style[0]] = layer.inverse ? null : style.slice(1);
  10781. }
  10782. }
  10783. let current = chalk;
  10784. for (const [styleName, styles] of Object.entries(enabled)) {
  10785. if (!Array.isArray(styles)) {
  10786. continue;
  10787. }
  10788. if (!(styleName in current)) {
  10789. throw new Error(`Unknown Chalk style: ${styleName}`);
  10790. }
  10791. current = styles.length > 0 ? current[styleName](...styles) : current[styleName];
  10792. }
  10793. return current;
  10794. }
  10795. var templates = (chalk, temporary) => {
  10796. const styles = [];
  10797. const chunks = [];
  10798. let chunk = [];
  10799. // eslint-disable-next-line max-params
  10800. temporary.replace(TEMPLATE_REGEX, (m, escapeCharacter, inverse, style, close, character) => {
  10801. if (escapeCharacter) {
  10802. chunk.push(unescape(escapeCharacter));
  10803. } else if (style) {
  10804. const string = chunk.join('');
  10805. chunk = [];
  10806. chunks.push(styles.length === 0 ? string : buildStyle(chalk, styles)(string));
  10807. styles.push({inverse, styles: parseStyle(style)});
  10808. } else if (close) {
  10809. if (styles.length === 0) {
  10810. throw new Error('Found extraneous } in Chalk template literal');
  10811. }
  10812. chunks.push(buildStyle(chalk, styles)(chunk.join('')));
  10813. chunk = [];
  10814. styles.pop();
  10815. } else {
  10816. chunk.push(character);
  10817. }
  10818. });
  10819. chunks.push(chunk.join(''));
  10820. if (styles.length > 0) {
  10821. const errMessage = `Chalk template literal is missing ${styles.length} closing bracket${styles.length === 1 ? '' : 's'} (\`}\`)`;
  10822. throw new Error(errMessage);
  10823. }
  10824. return chunks.join('');
  10825. };
  10826. const {stdout: stdoutColor, stderr: stderrColor} = supportsColor_1;
  10827. const {
  10828. stringReplaceAll,
  10829. stringEncaseCRLFWithFirstIndex
  10830. } = util;
  10831. const {isArray: isArray$2} = Array;
  10832. // `supportsColor.level` → `ansiStyles.color[name]` mapping
  10833. const levelMapping = [
  10834. 'ansi',
  10835. 'ansi',
  10836. 'ansi256',
  10837. 'ansi16m'
  10838. ];
  10839. const styles = Object.create(null);
  10840. const applyOptions = (object, options = {}) => {
  10841. if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
  10842. throw new Error('The `level` option should be an integer from 0 to 3');
  10843. }
  10844. // Detect level if not set manually
  10845. const colorLevel = stdoutColor ? stdoutColor.level : 0;
  10846. object.level = options.level === undefined ? colorLevel : options.level;
  10847. };
  10848. class ChalkClass {
  10849. constructor(options) {
  10850. // eslint-disable-next-line no-constructor-return
  10851. return chalkFactory(options);
  10852. }
  10853. }
  10854. const chalkFactory = options => {
  10855. const chalk = {};
  10856. applyOptions(chalk, options);
  10857. chalk.template = (...arguments_) => chalkTag(chalk.template, ...arguments_);
  10858. Object.setPrototypeOf(chalk, Chalk.prototype);
  10859. Object.setPrototypeOf(chalk.template, chalk);
  10860. chalk.template.constructor = () => {
  10861. throw new Error('`chalk.constructor()` is deprecated. Use `new chalk.Instance()` instead.');
  10862. };
  10863. chalk.template.Instance = ChalkClass;
  10864. return chalk.template;
  10865. };
  10866. function Chalk(options) {
  10867. return chalkFactory(options);
  10868. }
  10869. for (const [styleName, style] of Object.entries(ansiStyles)) {
  10870. styles[styleName] = {
  10871. get() {
  10872. const builder = createBuilder(this, createStyler(style.open, style.close, this._styler), this._isEmpty);
  10873. Object.defineProperty(this, styleName, {value: builder});
  10874. return builder;
  10875. }
  10876. };
  10877. }
  10878. styles.visible = {
  10879. get() {
  10880. const builder = createBuilder(this, this._styler, true);
  10881. Object.defineProperty(this, 'visible', {value: builder});
  10882. return builder;
  10883. }
  10884. };
  10885. const usedModels = ['rgb', 'hex', 'keyword', 'hsl', 'hsv', 'hwb', 'ansi', 'ansi256'];
  10886. for (const model of usedModels) {
  10887. styles[model] = {
  10888. get() {
  10889. const {level} = this;
  10890. return function (...arguments_) {
  10891. const styler = createStyler(ansiStyles.color[levelMapping[level]][model](...arguments_), ansiStyles.color.close, this._styler);
  10892. return createBuilder(this, styler, this._isEmpty);
  10893. };
  10894. }
  10895. };
  10896. }
  10897. for (const model of usedModels) {
  10898. const bgModel = 'bg' + model[0].toUpperCase() + model.slice(1);
  10899. styles[bgModel] = {
  10900. get() {
  10901. const {level} = this;
  10902. return function (...arguments_) {
  10903. const styler = createStyler(ansiStyles.bgColor[levelMapping[level]][model](...arguments_), ansiStyles.bgColor.close, this._styler);
  10904. return createBuilder(this, styler, this._isEmpty);
  10905. };
  10906. }
  10907. };
  10908. }
  10909. const proto = Object.defineProperties(() => {}, {
  10910. ...styles,
  10911. level: {
  10912. enumerable: true,
  10913. get() {
  10914. return this._generator.level;
  10915. },
  10916. set(level) {
  10917. this._generator.level = level;
  10918. }
  10919. }
  10920. });
  10921. const createStyler = (open, close, parent) => {
  10922. let openAll;
  10923. let closeAll;
  10924. if (parent === undefined) {
  10925. openAll = open;
  10926. closeAll = close;
  10927. } else {
  10928. openAll = parent.openAll + open;
  10929. closeAll = close + parent.closeAll;
  10930. }
  10931. return {
  10932. open,
  10933. close,
  10934. openAll,
  10935. closeAll,
  10936. parent
  10937. };
  10938. };
  10939. const createBuilder = (self, _styler, _isEmpty) => {
  10940. const builder = (...arguments_) => {
  10941. if (isArray$2(arguments_[0]) && isArray$2(arguments_[0].raw)) {
  10942. // Called as a template literal, for example: chalk.red`2 + 3 = {bold ${2+3}}`
  10943. return applyStyle(builder, chalkTag(builder, ...arguments_));
  10944. }
  10945. // Single argument is hot path, implicit coercion is faster than anything
  10946. // eslint-disable-next-line no-implicit-coercion
  10947. return applyStyle(builder, (arguments_.length === 1) ? ('' + arguments_[0]) : arguments_.join(' '));
  10948. };
  10949. // We alter the prototype because we must return a function, but there is
  10950. // no way to create a function with a different prototype
  10951. Object.setPrototypeOf(builder, proto);
  10952. builder._generator = self;
  10953. builder._styler = _styler;
  10954. builder._isEmpty = _isEmpty;
  10955. return builder;
  10956. };
  10957. const applyStyle = (self, string) => {
  10958. if (self.level <= 0 || !string) {
  10959. return self._isEmpty ? '' : string;
  10960. }
  10961. let styler = self._styler;
  10962. if (styler === undefined) {
  10963. return string;
  10964. }
  10965. const {openAll, closeAll} = styler;
  10966. if (string.indexOf('\u001B') !== -1) {
  10967. while (styler !== undefined) {
  10968. // Replace any instances already present with a re-opening code
  10969. // otherwise only the part of the string until said closing code
  10970. // will be colored, and the rest will simply be 'plain'.
  10971. string = stringReplaceAll(string, styler.close, styler.open);
  10972. styler = styler.parent;
  10973. }
  10974. }
  10975. // We can move both next actions out of loop, because remaining actions in loop won't have
  10976. // any/visible effect on parts we add here. Close the styling before a linebreak and reopen
  10977. // after next line to fix a bleed issue on macOS: https://github.com/chalk/chalk/pull/92
  10978. const lfIndex = string.indexOf('\n');
  10979. if (lfIndex !== -1) {
  10980. string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
  10981. }
  10982. return openAll + string + closeAll;
  10983. };
  10984. let template;
  10985. const chalkTag = (chalk, ...strings) => {
  10986. const [firstString] = strings;
  10987. if (!isArray$2(firstString) || !isArray$2(firstString.raw)) {
  10988. // If chalk() was called by itself or with a string,
  10989. // return the string itself as a string.
  10990. return strings.join(' ');
  10991. }
  10992. const arguments_ = strings.slice(1);
  10993. const parts = [firstString.raw[0]];
  10994. for (let i = 1; i < firstString.length; i++) {
  10995. parts.push(
  10996. String(arguments_[i - 1]).replace(/[{}\\]/g, '\\$&'),
  10997. String(firstString.raw[i])
  10998. );
  10999. }
  11000. if (template === undefined) {
  11001. template = templates;
  11002. }
  11003. return template(chalk, parts.join(''));
  11004. };
  11005. Object.defineProperties(Chalk.prototype, styles);
  11006. const chalk = Chalk(); // eslint-disable-line new-cap
  11007. chalk.supportsColor = stdoutColor;
  11008. chalk.stderr = Chalk({level: stderrColor ? stderrColor.level : 0}); // eslint-disable-line new-cap
  11009. chalk.stderr.supportsColor = stderrColor;
  11010. var source = chalk;
  11011. // Copyright Joyent, Inc. and other Node contributors.
  11012. //
  11013. // Permission is hereby granted, free of charge, to any person obtaining a
  11014. // copy of this software and associated documentation files (the
  11015. // "Software"), to deal in the Software without restriction, including
  11016. // without limitation the rights to use, copy, modify, merge, publish,
  11017. // distribute, sublicense, and/or sell copies of the Software, and to permit
  11018. // persons to whom the Software is furnished to do so, subject to the
  11019. // following conditions:
  11020. //
  11021. // The above copyright notice and this permission notice shall be included
  11022. // in all copies or substantial portions of the Software.
  11023. //
  11024. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  11025. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  11026. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  11027. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  11028. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  11029. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  11030. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  11031. var isWindows = process.platform === 'win32';
  11032. // JavaScript implementation of realpath, ported from node pre-v6
  11033. var DEBUG = process.env.NODE_DEBUG && /fs/.test(process.env.NODE_DEBUG);
  11034. function rethrow() {
  11035. // Only enable in debug mode. A backtrace uses ~1000 bytes of heap space and
  11036. // is fairly slow to generate.
  11037. var callback;
  11038. if (DEBUG) {
  11039. var backtrace = new Error;
  11040. callback = debugCallback;
  11041. } else
  11042. callback = missingCallback;
  11043. return callback;
  11044. function debugCallback(err) {
  11045. if (err) {
  11046. backtrace.message = err.message;
  11047. err = backtrace;
  11048. missingCallback(err);
  11049. }
  11050. }
  11051. function missingCallback(err) {
  11052. if (err) {
  11053. if (process.throwDeprecation)
  11054. throw err; // Forgot a callback but don't know where? Use NODE_DEBUG=fs
  11055. else if (!process.noDeprecation) {
  11056. var msg = 'fs: missing callback ' + (err.stack || err.message);
  11057. if (process.traceDeprecation)
  11058. console.trace(msg);
  11059. else
  11060. console.error(msg);
  11061. }
  11062. }
  11063. }
  11064. }
  11065. function maybeCallback(cb) {
  11066. return typeof cb === 'function' ? cb : rethrow();
  11067. }
  11068. path__default['default'].normalize;
  11069. // Regexp that finds the next partion of a (partial) path
  11070. // result is [base_with_slash, base], e.g. ['somedir/', 'somedir']
  11071. if (isWindows) {
  11072. var nextPartRe = /(.*?)(?:[\/\\]+|$)/g;
  11073. } else {
  11074. var nextPartRe = /(.*?)(?:[\/]+|$)/g;
  11075. }
  11076. // Regex to find the device root, including trailing slash. E.g. 'c:\\'.
  11077. if (isWindows) {
  11078. var splitRootRe = /^(?:[a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/][^\\\/]+)?[\\\/]*/;
  11079. } else {
  11080. var splitRootRe = /^[\/]*/;
  11081. }
  11082. var realpathSync$1 = function realpathSync(p, cache) {
  11083. // make p is absolute
  11084. p = path__default['default'].resolve(p);
  11085. if (cache && Object.prototype.hasOwnProperty.call(cache, p)) {
  11086. return cache[p];
  11087. }
  11088. var original = p,
  11089. seenLinks = {},
  11090. knownHard = {};
  11091. // current character position in p
  11092. var pos;
  11093. // the partial path so far, including a trailing slash if any
  11094. var current;
  11095. // the partial path without a trailing slash (except when pointing at a root)
  11096. var base;
  11097. // the partial path scanned in the previous round, with slash
  11098. var previous;
  11099. start();
  11100. function start() {
  11101. // Skip over roots
  11102. var m = splitRootRe.exec(p);
  11103. pos = m[0].length;
  11104. current = m[0];
  11105. base = m[0];
  11106. previous = '';
  11107. // On windows, check that the root exists. On unix there is no need.
  11108. if (isWindows && !knownHard[base]) {
  11109. fs__default['default'].lstatSync(base);
  11110. knownHard[base] = true;
  11111. }
  11112. }
  11113. // walk down the path, swapping out linked pathparts for their real
  11114. // values
  11115. // NB: p.length changes.
  11116. while (pos < p.length) {
  11117. // find the next part
  11118. nextPartRe.lastIndex = pos;
  11119. var result = nextPartRe.exec(p);
  11120. previous = current;
  11121. current += result[0];
  11122. base = previous + result[1];
  11123. pos = nextPartRe.lastIndex;
  11124. // continue if not a symlink
  11125. if (knownHard[base] || (cache && cache[base] === base)) {
  11126. continue;
  11127. }
  11128. var resolvedLink;
  11129. if (cache && Object.prototype.hasOwnProperty.call(cache, base)) {
  11130. // some known symbolic link. no need to stat again.
  11131. resolvedLink = cache[base];
  11132. } else {
  11133. var stat = fs__default['default'].lstatSync(base);
  11134. if (!stat.isSymbolicLink()) {
  11135. knownHard[base] = true;
  11136. if (cache) cache[base] = base;
  11137. continue;
  11138. }
  11139. // read the link if it wasn't read before
  11140. // dev/ino always return 0 on windows, so skip the check.
  11141. var linkTarget = null;
  11142. if (!isWindows) {
  11143. var id = stat.dev.toString(32) + ':' + stat.ino.toString(32);
  11144. if (seenLinks.hasOwnProperty(id)) {
  11145. linkTarget = seenLinks[id];
  11146. }
  11147. }
  11148. if (linkTarget === null) {
  11149. fs__default['default'].statSync(base);
  11150. linkTarget = fs__default['default'].readlinkSync(base);
  11151. }
  11152. resolvedLink = path__default['default'].resolve(previous, linkTarget);
  11153. // track this, if given a cache.
  11154. if (cache) cache[base] = resolvedLink;
  11155. if (!isWindows) seenLinks[id] = linkTarget;
  11156. }
  11157. // resolve the link, then start over
  11158. p = path__default['default'].resolve(resolvedLink, p.slice(pos));
  11159. start();
  11160. }
  11161. if (cache) cache[original] = p;
  11162. return p;
  11163. };
  11164. var realpath$1 = function realpath(p, cache, cb) {
  11165. if (typeof cb !== 'function') {
  11166. cb = maybeCallback(cache);
  11167. cache = null;
  11168. }
  11169. // make p is absolute
  11170. p = path__default['default'].resolve(p);
  11171. if (cache && Object.prototype.hasOwnProperty.call(cache, p)) {
  11172. return process.nextTick(cb.bind(null, null, cache[p]));
  11173. }
  11174. var original = p,
  11175. seenLinks = {},
  11176. knownHard = {};
  11177. // current character position in p
  11178. var pos;
  11179. // the partial path so far, including a trailing slash if any
  11180. var current;
  11181. // the partial path without a trailing slash (except when pointing at a root)
  11182. var base;
  11183. // the partial path scanned in the previous round, with slash
  11184. var previous;
  11185. start();
  11186. function start() {
  11187. // Skip over roots
  11188. var m = splitRootRe.exec(p);
  11189. pos = m[0].length;
  11190. current = m[0];
  11191. base = m[0];
  11192. previous = '';
  11193. // On windows, check that the root exists. On unix there is no need.
  11194. if (isWindows && !knownHard[base]) {
  11195. fs__default['default'].lstat(base, function(err) {
  11196. if (err) return cb(err);
  11197. knownHard[base] = true;
  11198. LOOP();
  11199. });
  11200. } else {
  11201. process.nextTick(LOOP);
  11202. }
  11203. }
  11204. // walk down the path, swapping out linked pathparts for their real
  11205. // values
  11206. function LOOP() {
  11207. // stop if scanned past end of path
  11208. if (pos >= p.length) {
  11209. if (cache) cache[original] = p;
  11210. return cb(null, p);
  11211. }
  11212. // find the next part
  11213. nextPartRe.lastIndex = pos;
  11214. var result = nextPartRe.exec(p);
  11215. previous = current;
  11216. current += result[0];
  11217. base = previous + result[1];
  11218. pos = nextPartRe.lastIndex;
  11219. // continue if not a symlink
  11220. if (knownHard[base] || (cache && cache[base] === base)) {
  11221. return process.nextTick(LOOP);
  11222. }
  11223. if (cache && Object.prototype.hasOwnProperty.call(cache, base)) {
  11224. // known symbolic link. no need to stat again.
  11225. return gotResolvedLink(cache[base]);
  11226. }
  11227. return fs__default['default'].lstat(base, gotStat);
  11228. }
  11229. function gotStat(err, stat) {
  11230. if (err) return cb(err);
  11231. // if not a symlink, skip to the next path part
  11232. if (!stat.isSymbolicLink()) {
  11233. knownHard[base] = true;
  11234. if (cache) cache[base] = base;
  11235. return process.nextTick(LOOP);
  11236. }
  11237. // stat & read the link if not read before
  11238. // call gotTarget as soon as the link target is known
  11239. // dev/ino always return 0 on windows, so skip the check.
  11240. if (!isWindows) {
  11241. var id = stat.dev.toString(32) + ':' + stat.ino.toString(32);
  11242. if (seenLinks.hasOwnProperty(id)) {
  11243. return gotTarget(null, seenLinks[id], base);
  11244. }
  11245. }
  11246. fs__default['default'].stat(base, function(err) {
  11247. if (err) return cb(err);
  11248. fs__default['default'].readlink(base, function(err, target) {
  11249. if (!isWindows) seenLinks[id] = target;
  11250. gotTarget(err, target);
  11251. });
  11252. });
  11253. }
  11254. function gotTarget(err, target, base) {
  11255. if (err) return cb(err);
  11256. var resolvedLink = path__default['default'].resolve(previous, target);
  11257. if (cache) cache[base] = resolvedLink;
  11258. gotResolvedLink(resolvedLink);
  11259. }
  11260. function gotResolvedLink(resolvedLink) {
  11261. // resolve the link, then start over
  11262. p = path__default['default'].resolve(resolvedLink, p.slice(pos));
  11263. start();
  11264. }
  11265. };
  11266. var old = {
  11267. realpathSync: realpathSync$1,
  11268. realpath: realpath$1
  11269. };
  11270. var fs_realpath = realpath;
  11271. realpath.realpath = realpath;
  11272. realpath.sync = realpathSync;
  11273. realpath.realpathSync = realpathSync;
  11274. realpath.monkeypatch = monkeypatch;
  11275. realpath.unmonkeypatch = unmonkeypatch;
  11276. var origRealpath = fs__default['default'].realpath;
  11277. var origRealpathSync = fs__default['default'].realpathSync;
  11278. var version = process.version;
  11279. var ok = /^v[0-5]\./.test(version);
  11280. function newError (er) {
  11281. return er && er.syscall === 'realpath' && (
  11282. er.code === 'ELOOP' ||
  11283. er.code === 'ENOMEM' ||
  11284. er.code === 'ENAMETOOLONG'
  11285. )
  11286. }
  11287. function realpath (p, cache, cb) {
  11288. if (ok) {
  11289. return origRealpath(p, cache, cb)
  11290. }
  11291. if (typeof cache === 'function') {
  11292. cb = cache;
  11293. cache = null;
  11294. }
  11295. origRealpath(p, cache, function (er, result) {
  11296. if (newError(er)) {
  11297. old.realpath(p, cache, cb);
  11298. } else {
  11299. cb(er, result);
  11300. }
  11301. });
  11302. }
  11303. function realpathSync (p, cache) {
  11304. if (ok) {
  11305. return origRealpathSync(p, cache)
  11306. }
  11307. try {
  11308. return origRealpathSync(p, cache)
  11309. } catch (er) {
  11310. if (newError(er)) {
  11311. return old.realpathSync(p, cache)
  11312. } else {
  11313. throw er
  11314. }
  11315. }
  11316. }
  11317. function monkeypatch () {
  11318. fs__default['default'].realpath = realpath;
  11319. fs__default['default'].realpathSync = realpathSync;
  11320. }
  11321. function unmonkeypatch () {
  11322. fs__default['default'].realpath = origRealpath;
  11323. fs__default['default'].realpathSync = origRealpathSync;
  11324. }
  11325. var concatMap = function (xs, fn) {
  11326. var res = [];
  11327. for (var i = 0; i < xs.length; i++) {
  11328. var x = fn(xs[i], i);
  11329. if (isArray$1(x)) res.push.apply(res, x);
  11330. else res.push(x);
  11331. }
  11332. return res;
  11333. };
  11334. var isArray$1 = Array.isArray || function (xs) {
  11335. return Object.prototype.toString.call(xs) === '[object Array]';
  11336. };
  11337. var balancedMatch = balanced;
  11338. function balanced(a, b, str) {
  11339. if (a instanceof RegExp) a = maybeMatch(a, str);
  11340. if (b instanceof RegExp) b = maybeMatch(b, str);
  11341. var r = range(a, b, str);
  11342. return r && {
  11343. start: r[0],
  11344. end: r[1],
  11345. pre: str.slice(0, r[0]),
  11346. body: str.slice(r[0] + a.length, r[1]),
  11347. post: str.slice(r[1] + b.length)
  11348. };
  11349. }
  11350. function maybeMatch(reg, str) {
  11351. var m = str.match(reg);
  11352. return m ? m[0] : null;
  11353. }
  11354. balanced.range = range;
  11355. function range(a, b, str) {
  11356. var begs, beg, left, right, result;
  11357. var ai = str.indexOf(a);
  11358. var bi = str.indexOf(b, ai + 1);
  11359. var i = ai;
  11360. if (ai >= 0 && bi > 0) {
  11361. begs = [];
  11362. left = str.length;
  11363. while (i >= 0 && !result) {
  11364. if (i == ai) {
  11365. begs.push(i);
  11366. ai = str.indexOf(a, i + 1);
  11367. } else if (begs.length == 1) {
  11368. result = [ begs.pop(), bi ];
  11369. } else {
  11370. beg = begs.pop();
  11371. if (beg < left) {
  11372. left = beg;
  11373. right = bi;
  11374. }
  11375. bi = str.indexOf(b, i + 1);
  11376. }
  11377. i = ai < bi && ai >= 0 ? ai : bi;
  11378. }
  11379. if (begs.length) {
  11380. result = [ left, right ];
  11381. }
  11382. }
  11383. return result;
  11384. }
  11385. var braceExpansion = expandTop;
  11386. var escSlash = '\0SLASH'+Math.random()+'\0';
  11387. var escOpen = '\0OPEN'+Math.random()+'\0';
  11388. var escClose = '\0CLOSE'+Math.random()+'\0';
  11389. var escComma = '\0COMMA'+Math.random()+'\0';
  11390. var escPeriod = '\0PERIOD'+Math.random()+'\0';
  11391. function numeric(str) {
  11392. return parseInt(str, 10) == str
  11393. ? parseInt(str, 10)
  11394. : str.charCodeAt(0);
  11395. }
  11396. function escapeBraces(str) {
  11397. return str.split('\\\\').join(escSlash)
  11398. .split('\\{').join(escOpen)
  11399. .split('\\}').join(escClose)
  11400. .split('\\,').join(escComma)
  11401. .split('\\.').join(escPeriod);
  11402. }
  11403. function unescapeBraces(str) {
  11404. return str.split(escSlash).join('\\')
  11405. .split(escOpen).join('{')
  11406. .split(escClose).join('}')
  11407. .split(escComma).join(',')
  11408. .split(escPeriod).join('.');
  11409. }
  11410. // Basically just str.split(","), but handling cases
  11411. // where we have nested braced sections, which should be
  11412. // treated as individual members, like {a,{b,c},d}
  11413. function parseCommaParts(str) {
  11414. if (!str)
  11415. return [''];
  11416. var parts = [];
  11417. var m = balancedMatch('{', '}', str);
  11418. if (!m)
  11419. return str.split(',');
  11420. var pre = m.pre;
  11421. var body = m.body;
  11422. var post = m.post;
  11423. var p = pre.split(',');
  11424. p[p.length-1] += '{' + body + '}';
  11425. var postParts = parseCommaParts(post);
  11426. if (post.length) {
  11427. p[p.length-1] += postParts.shift();
  11428. p.push.apply(p, postParts);
  11429. }
  11430. parts.push.apply(parts, p);
  11431. return parts;
  11432. }
  11433. function expandTop(str) {
  11434. if (!str)
  11435. return [];
  11436. // I don't know why Bash 4.3 does this, but it does.
  11437. // Anything starting with {} will have the first two bytes preserved
  11438. // but *only* at the top level, so {},a}b will not expand to anything,
  11439. // but a{},b}c will be expanded to [a}c,abc].
  11440. // One could argue that this is a bug in Bash, but since the goal of
  11441. // this module is to match Bash's rules, we escape a leading {}
  11442. if (str.substr(0, 2) === '{}') {
  11443. str = '\\{\\}' + str.substr(2);
  11444. }
  11445. return expand(escapeBraces(str), true).map(unescapeBraces);
  11446. }
  11447. function embrace(str) {
  11448. return '{' + str + '}';
  11449. }
  11450. function isPadded(el) {
  11451. return /^-?0\d/.test(el);
  11452. }
  11453. function lte(i, y) {
  11454. return i <= y;
  11455. }
  11456. function gte(i, y) {
  11457. return i >= y;
  11458. }
  11459. function expand(str, isTop) {
  11460. var expansions = [];
  11461. var m = balancedMatch('{', '}', str);
  11462. if (!m || /\$$/.test(m.pre)) return [str];
  11463. var isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
  11464. var isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
  11465. var isSequence = isNumericSequence || isAlphaSequence;
  11466. var isOptions = m.body.indexOf(',') >= 0;
  11467. if (!isSequence && !isOptions) {
  11468. // {a},b}
  11469. if (m.post.match(/,.*\}/)) {
  11470. str = m.pre + '{' + m.body + escClose + m.post;
  11471. return expand(str);
  11472. }
  11473. return [str];
  11474. }
  11475. var n;
  11476. if (isSequence) {
  11477. n = m.body.split(/\.\./);
  11478. } else {
  11479. n = parseCommaParts(m.body);
  11480. if (n.length === 1) {
  11481. // x{{a,b}}y ==> x{a}y x{b}y
  11482. n = expand(n[0], false).map(embrace);
  11483. if (n.length === 1) {
  11484. var post = m.post.length
  11485. ? expand(m.post, false)
  11486. : [''];
  11487. return post.map(function(p) {
  11488. return m.pre + n[0] + p;
  11489. });
  11490. }
  11491. }
  11492. }
  11493. // at this point, n is the parts, and we know it's not a comma set
  11494. // with a single entry.
  11495. // no need to expand pre, since it is guaranteed to be free of brace-sets
  11496. var pre = m.pre;
  11497. var post = m.post.length
  11498. ? expand(m.post, false)
  11499. : [''];
  11500. var N;
  11501. if (isSequence) {
  11502. var x = numeric(n[0]);
  11503. var y = numeric(n[1]);
  11504. var width = Math.max(n[0].length, n[1].length);
  11505. var incr = n.length == 3
  11506. ? Math.abs(numeric(n[2]))
  11507. : 1;
  11508. var test = lte;
  11509. var reverse = y < x;
  11510. if (reverse) {
  11511. incr *= -1;
  11512. test = gte;
  11513. }
  11514. var pad = n.some(isPadded);
  11515. N = [];
  11516. for (var i = x; test(i, y); i += incr) {
  11517. var c;
  11518. if (isAlphaSequence) {
  11519. c = String.fromCharCode(i);
  11520. if (c === '\\')
  11521. c = '';
  11522. } else {
  11523. c = String(i);
  11524. if (pad) {
  11525. var need = width - c.length;
  11526. if (need > 0) {
  11527. var z = new Array(need + 1).join('0');
  11528. if (i < 0)
  11529. c = '-' + z + c.slice(1);
  11530. else
  11531. c = z + c;
  11532. }
  11533. }
  11534. }
  11535. N.push(c);
  11536. }
  11537. } else {
  11538. N = concatMap(n, function(el) { return expand(el, false) });
  11539. }
  11540. for (var j = 0; j < N.length; j++) {
  11541. for (var k = 0; k < post.length; k++) {
  11542. var expansion = pre + N[j] + post[k];
  11543. if (!isTop || isSequence || expansion)
  11544. expansions.push(expansion);
  11545. }
  11546. }
  11547. return expansions;
  11548. }
  11549. var minimatch_1 = minimatch;
  11550. minimatch.Minimatch = Minimatch$1;
  11551. var path = { sep: '/' };
  11552. try {
  11553. path = path__default['default'];
  11554. } catch (er) {}
  11555. var GLOBSTAR = minimatch.GLOBSTAR = Minimatch$1.GLOBSTAR = {};
  11556. var plTypes = {
  11557. '!': { open: '(?:(?!(?:', close: '))[^/]*?)'},
  11558. '?': { open: '(?:', close: ')?' },
  11559. '+': { open: '(?:', close: ')+' },
  11560. '*': { open: '(?:', close: ')*' },
  11561. '@': { open: '(?:', close: ')' }
  11562. };
  11563. // any single thing other than /
  11564. // don't need to escape / when using new RegExp()
  11565. var qmark = '[^/]';
  11566. // * => any number of characters
  11567. var star = qmark + '*?';
  11568. // ** when dots are allowed. Anything goes, except .. and .
  11569. // not (^ or / followed by one or two dots followed by $ or /),
  11570. // followed by anything, any number of times.
  11571. var twoStarDot = '(?:(?!(?:\\\/|^)(?:\\.{1,2})($|\\\/)).)*?';
  11572. // not a ^ or / followed by a dot,
  11573. // followed by anything, any number of times.
  11574. var twoStarNoDot = '(?:(?!(?:\\\/|^)\\.).)*?';
  11575. // characters that need to be escaped in RegExp.
  11576. var reSpecials = charSet('().*{}+?[]^$\\!');
  11577. // "abc" -> { a:true, b:true, c:true }
  11578. function charSet (s) {
  11579. return s.split('').reduce(function (set, c) {
  11580. set[c] = true;
  11581. return set
  11582. }, {})
  11583. }
  11584. // normalizes slashes.
  11585. var slashSplit = /\/+/;
  11586. minimatch.filter = filter;
  11587. function filter (pattern, options) {
  11588. options = options || {};
  11589. return function (p, i, list) {
  11590. return minimatch(p, pattern, options)
  11591. }
  11592. }
  11593. function ext (a, b) {
  11594. a = a || {};
  11595. b = b || {};
  11596. var t = {};
  11597. Object.keys(b).forEach(function (k) {
  11598. t[k] = b[k];
  11599. });
  11600. Object.keys(a).forEach(function (k) {
  11601. t[k] = a[k];
  11602. });
  11603. return t
  11604. }
  11605. minimatch.defaults = function (def) {
  11606. if (!def || !Object.keys(def).length) return minimatch
  11607. var orig = minimatch;
  11608. var m = function minimatch (p, pattern, options) {
  11609. return orig.minimatch(p, pattern, ext(def, options))
  11610. };
  11611. m.Minimatch = function Minimatch (pattern, options) {
  11612. return new orig.Minimatch(pattern, ext(def, options))
  11613. };
  11614. return m
  11615. };
  11616. Minimatch$1.defaults = function (def) {
  11617. if (!def || !Object.keys(def).length) return Minimatch$1
  11618. return minimatch.defaults(def).Minimatch
  11619. };
  11620. function minimatch (p, pattern, options) {
  11621. if (typeof pattern !== 'string') {
  11622. throw new TypeError('glob pattern string required')
  11623. }
  11624. if (!options) options = {};
  11625. // shortcut: comments match nothing.
  11626. if (!options.nocomment && pattern.charAt(0) === '#') {
  11627. return false
  11628. }
  11629. // "" only matches ""
  11630. if (pattern.trim() === '') return p === ''
  11631. return new Minimatch$1(pattern, options).match(p)
  11632. }
  11633. function Minimatch$1 (pattern, options) {
  11634. if (!(this instanceof Minimatch$1)) {
  11635. return new Minimatch$1(pattern, options)
  11636. }
  11637. if (typeof pattern !== 'string') {
  11638. throw new TypeError('glob pattern string required')
  11639. }
  11640. if (!options) options = {};
  11641. pattern = pattern.trim();
  11642. // windows support: need to use /, not \
  11643. if (path.sep !== '/') {
  11644. pattern = pattern.split(path.sep).join('/');
  11645. }
  11646. this.options = options;
  11647. this.set = [];
  11648. this.pattern = pattern;
  11649. this.regexp = null;
  11650. this.negate = false;
  11651. this.comment = false;
  11652. this.empty = false;
  11653. // make the set of regexps etc.
  11654. this.make();
  11655. }
  11656. Minimatch$1.prototype.debug = function () {};
  11657. Minimatch$1.prototype.make = make;
  11658. function make () {
  11659. // don't do it more than once.
  11660. if (this._made) return
  11661. var pattern = this.pattern;
  11662. var options = this.options;
  11663. // empty patterns and comments match nothing.
  11664. if (!options.nocomment && pattern.charAt(0) === '#') {
  11665. this.comment = true;
  11666. return
  11667. }
  11668. if (!pattern) {
  11669. this.empty = true;
  11670. return
  11671. }
  11672. // step 1: figure out negation, etc.
  11673. this.parseNegate();
  11674. // step 2: expand braces
  11675. var set = this.globSet = this.braceExpand();
  11676. if (options.debug) this.debug = console.error;
  11677. this.debug(this.pattern, set);
  11678. // step 3: now we have a set, so turn each one into a series of path-portion
  11679. // matching patterns.
  11680. // These will be regexps, except in the case of "**", which is
  11681. // set to the GLOBSTAR object for globstar behavior,
  11682. // and will not contain any / characters
  11683. set = this.globParts = set.map(function (s) {
  11684. return s.split(slashSplit)
  11685. });
  11686. this.debug(this.pattern, set);
  11687. // glob --> regexps
  11688. set = set.map(function (s, si, set) {
  11689. return s.map(this.parse, this)
  11690. }, this);
  11691. this.debug(this.pattern, set);
  11692. // filter out everything that didn't compile properly.
  11693. set = set.filter(function (s) {
  11694. return s.indexOf(false) === -1
  11695. });
  11696. this.debug(this.pattern, set);
  11697. this.set = set;
  11698. }
  11699. Minimatch$1.prototype.parseNegate = parseNegate;
  11700. function parseNegate () {
  11701. var pattern = this.pattern;
  11702. var negate = false;
  11703. var options = this.options;
  11704. var negateOffset = 0;
  11705. if (options.nonegate) return
  11706. for (var i = 0, l = pattern.length
  11707. ; i < l && pattern.charAt(i) === '!'
  11708. ; i++) {
  11709. negate = !negate;
  11710. negateOffset++;
  11711. }
  11712. if (negateOffset) this.pattern = pattern.substr(negateOffset);
  11713. this.negate = negate;
  11714. }
  11715. // Brace expansion:
  11716. // a{b,c}d -> abd acd
  11717. // a{b,}c -> abc ac
  11718. // a{0..3}d -> a0d a1d a2d a3d
  11719. // a{b,c{d,e}f}g -> abg acdfg acefg
  11720. // a{b,c}d{e,f}g -> abdeg acdeg abdeg abdfg
  11721. //
  11722. // Invalid sets are not expanded.
  11723. // a{2..}b -> a{2..}b
  11724. // a{b}c -> a{b}c
  11725. minimatch.braceExpand = function (pattern, options) {
  11726. return braceExpand(pattern, options)
  11727. };
  11728. Minimatch$1.prototype.braceExpand = braceExpand;
  11729. function braceExpand (pattern, options) {
  11730. if (!options) {
  11731. if (this instanceof Minimatch$1) {
  11732. options = this.options;
  11733. } else {
  11734. options = {};
  11735. }
  11736. }
  11737. pattern = typeof pattern === 'undefined'
  11738. ? this.pattern : pattern;
  11739. if (typeof pattern === 'undefined') {
  11740. throw new TypeError('undefined pattern')
  11741. }
  11742. if (options.nobrace ||
  11743. !pattern.match(/\{.*\}/)) {
  11744. // shortcut. no need to expand.
  11745. return [pattern]
  11746. }
  11747. return braceExpansion(pattern)
  11748. }
  11749. // parse a component of the expanded set.
  11750. // At this point, no pattern may contain "/" in it
  11751. // so we're going to return a 2d array, where each entry is the full
  11752. // pattern, split on '/', and then turned into a regular expression.
  11753. // A regexp is made at the end which joins each array with an
  11754. // escaped /, and another full one which joins each regexp with |.
  11755. //
  11756. // Following the lead of Bash 4.1, note that "**" only has special meaning
  11757. // when it is the *only* thing in a path portion. Otherwise, any series
  11758. // of * is equivalent to a single *. Globstar behavior is enabled by
  11759. // default, and can be disabled by setting options.noglobstar.
  11760. Minimatch$1.prototype.parse = parse;
  11761. var SUBPARSE = {};
  11762. function parse (pattern, isSub) {
  11763. if (pattern.length > 1024 * 64) {
  11764. throw new TypeError('pattern is too long')
  11765. }
  11766. var options = this.options;
  11767. // shortcuts
  11768. if (!options.noglobstar && pattern === '**') return GLOBSTAR
  11769. if (pattern === '') return ''
  11770. var re = '';
  11771. var hasMagic = !!options.nocase;
  11772. var escaping = false;
  11773. // ? => one single character
  11774. var patternListStack = [];
  11775. var negativeLists = [];
  11776. var stateChar;
  11777. var inClass = false;
  11778. var reClassStart = -1;
  11779. var classStart = -1;
  11780. // . and .. never match anything that doesn't start with .,
  11781. // even when options.dot is set.
  11782. var patternStart = pattern.charAt(0) === '.' ? '' // anything
  11783. // not (start or / followed by . or .. followed by / or end)
  11784. : options.dot ? '(?!(?:^|\\\/)\\.{1,2}(?:$|\\\/))'
  11785. : '(?!\\.)';
  11786. var self = this;
  11787. function clearStateChar () {
  11788. if (stateChar) {
  11789. // we had some state-tracking character
  11790. // that wasn't consumed by this pass.
  11791. switch (stateChar) {
  11792. case '*':
  11793. re += star;
  11794. hasMagic = true;
  11795. break
  11796. case '?':
  11797. re += qmark;
  11798. hasMagic = true;
  11799. break
  11800. default:
  11801. re += '\\' + stateChar;
  11802. break
  11803. }
  11804. self.debug('clearStateChar %j %j', stateChar, re);
  11805. stateChar = false;
  11806. }
  11807. }
  11808. for (var i = 0, len = pattern.length, c
  11809. ; (i < len) && (c = pattern.charAt(i))
  11810. ; i++) {
  11811. this.debug('%s\t%s %s %j', pattern, i, re, c);
  11812. // skip over any that are escaped.
  11813. if (escaping && reSpecials[c]) {
  11814. re += '\\' + c;
  11815. escaping = false;
  11816. continue
  11817. }
  11818. switch (c) {
  11819. case '/':
  11820. // completely not allowed, even escaped.
  11821. // Should already be path-split by now.
  11822. return false
  11823. case '\\':
  11824. clearStateChar();
  11825. escaping = true;
  11826. continue
  11827. // the various stateChar values
  11828. // for the "extglob" stuff.
  11829. case '?':
  11830. case '*':
  11831. case '+':
  11832. case '@':
  11833. case '!':
  11834. this.debug('%s\t%s %s %j <-- stateChar', pattern, i, re, c);
  11835. // all of those are literals inside a class, except that
  11836. // the glob [!a] means [^a] in regexp
  11837. if (inClass) {
  11838. this.debug(' in class');
  11839. if (c === '!' && i === classStart + 1) c = '^';
  11840. re += c;
  11841. continue
  11842. }
  11843. // if we already have a stateChar, then it means
  11844. // that there was something like ** or +? in there.
  11845. // Handle the stateChar, then proceed with this one.
  11846. self.debug('call clearStateChar %j', stateChar);
  11847. clearStateChar();
  11848. stateChar = c;
  11849. // if extglob is disabled, then +(asdf|foo) isn't a thing.
  11850. // just clear the statechar *now*, rather than even diving into
  11851. // the patternList stuff.
  11852. if (options.noext) clearStateChar();
  11853. continue
  11854. case '(':
  11855. if (inClass) {
  11856. re += '(';
  11857. continue
  11858. }
  11859. if (!stateChar) {
  11860. re += '\\(';
  11861. continue
  11862. }
  11863. patternListStack.push({
  11864. type: stateChar,
  11865. start: i - 1,
  11866. reStart: re.length,
  11867. open: plTypes[stateChar].open,
  11868. close: plTypes[stateChar].close
  11869. });
  11870. // negation is (?:(?!js)[^/]*)
  11871. re += stateChar === '!' ? '(?:(?!(?:' : '(?:';
  11872. this.debug('plType %j %j', stateChar, re);
  11873. stateChar = false;
  11874. continue
  11875. case ')':
  11876. if (inClass || !patternListStack.length) {
  11877. re += '\\)';
  11878. continue
  11879. }
  11880. clearStateChar();
  11881. hasMagic = true;
  11882. var pl = patternListStack.pop();
  11883. // negation is (?:(?!js)[^/]*)
  11884. // The others are (?:<pattern>)<type>
  11885. re += pl.close;
  11886. if (pl.type === '!') {
  11887. negativeLists.push(pl);
  11888. }
  11889. pl.reEnd = re.length;
  11890. continue
  11891. case '|':
  11892. if (inClass || !patternListStack.length || escaping) {
  11893. re += '\\|';
  11894. escaping = false;
  11895. continue
  11896. }
  11897. clearStateChar();
  11898. re += '|';
  11899. continue
  11900. // these are mostly the same in regexp and glob
  11901. case '[':
  11902. // swallow any state-tracking char before the [
  11903. clearStateChar();
  11904. if (inClass) {
  11905. re += '\\' + c;
  11906. continue
  11907. }
  11908. inClass = true;
  11909. classStart = i;
  11910. reClassStart = re.length;
  11911. re += c;
  11912. continue
  11913. case ']':
  11914. // a right bracket shall lose its special
  11915. // meaning and represent itself in
  11916. // a bracket expression if it occurs
  11917. // first in the list. -- POSIX.2 2.8.3.2
  11918. if (i === classStart + 1 || !inClass) {
  11919. re += '\\' + c;
  11920. escaping = false;
  11921. continue
  11922. }
  11923. // handle the case where we left a class open.
  11924. // "[z-a]" is valid, equivalent to "\[z-a\]"
  11925. if (inClass) {
  11926. // split where the last [ was, make sure we don't have
  11927. // an invalid re. if so, re-walk the contents of the
  11928. // would-be class to re-translate any characters that
  11929. // were passed through as-is
  11930. // TODO: It would probably be faster to determine this
  11931. // without a try/catch and a new RegExp, but it's tricky
  11932. // to do safely. For now, this is safe and works.
  11933. var cs = pattern.substring(classStart + 1, i);
  11934. try {
  11935. RegExp('[' + cs + ']');
  11936. } catch (er) {
  11937. // not a valid class!
  11938. var sp = this.parse(cs, SUBPARSE);
  11939. re = re.substr(0, reClassStart) + '\\[' + sp[0] + '\\]';
  11940. hasMagic = hasMagic || sp[1];
  11941. inClass = false;
  11942. continue
  11943. }
  11944. }
  11945. // finish up the class.
  11946. hasMagic = true;
  11947. inClass = false;
  11948. re += c;
  11949. continue
  11950. default:
  11951. // swallow any state char that wasn't consumed
  11952. clearStateChar();
  11953. if (escaping) {
  11954. // no need
  11955. escaping = false;
  11956. } else if (reSpecials[c]
  11957. && !(c === '^' && inClass)) {
  11958. re += '\\';
  11959. }
  11960. re += c;
  11961. } // switch
  11962. } // for
  11963. // handle the case where we left a class open.
  11964. // "[abc" is valid, equivalent to "\[abc"
  11965. if (inClass) {
  11966. // split where the last [ was, and escape it
  11967. // this is a huge pita. We now have to re-walk
  11968. // the contents of the would-be class to re-translate
  11969. // any characters that were passed through as-is
  11970. cs = pattern.substr(classStart + 1);
  11971. sp = this.parse(cs, SUBPARSE);
  11972. re = re.substr(0, reClassStart) + '\\[' + sp[0];
  11973. hasMagic = hasMagic || sp[1];
  11974. }
  11975. // handle the case where we had a +( thing at the *end*
  11976. // of the pattern.
  11977. // each pattern list stack adds 3 chars, and we need to go through
  11978. // and escape any | chars that were passed through as-is for the regexp.
  11979. // Go through and escape them, taking care not to double-escape any
  11980. // | chars that were already escaped.
  11981. for (pl = patternListStack.pop(); pl; pl = patternListStack.pop()) {
  11982. var tail = re.slice(pl.reStart + pl.open.length);
  11983. this.debug('setting tail', re, pl);
  11984. // maybe some even number of \, then maybe 1 \, followed by a |
  11985. tail = tail.replace(/((?:\\{2}){0,64})(\\?)\|/g, function (_, $1, $2) {
  11986. if (!$2) {
  11987. // the | isn't already escaped, so escape it.
  11988. $2 = '\\';
  11989. }
  11990. // need to escape all those slashes *again*, without escaping the
  11991. // one that we need for escaping the | character. As it works out,
  11992. // escaping an even number of slashes can be done by simply repeating
  11993. // it exactly after itself. That's why this trick works.
  11994. //
  11995. // I am sorry that you have to see this.
  11996. return $1 + $1 + $2 + '|'
  11997. });
  11998. this.debug('tail=%j\n %s', tail, tail, pl, re);
  11999. var t = pl.type === '*' ? star
  12000. : pl.type === '?' ? qmark
  12001. : '\\' + pl.type;
  12002. hasMagic = true;
  12003. re = re.slice(0, pl.reStart) + t + '\\(' + tail;
  12004. }
  12005. // handle trailing things that only matter at the very end.
  12006. clearStateChar();
  12007. if (escaping) {
  12008. // trailing \\
  12009. re += '\\\\';
  12010. }
  12011. // only need to apply the nodot start if the re starts with
  12012. // something that could conceivably capture a dot
  12013. var addPatternStart = false;
  12014. switch (re.charAt(0)) {
  12015. case '.':
  12016. case '[':
  12017. case '(': addPatternStart = true;
  12018. }
  12019. // Hack to work around lack of negative lookbehind in JS
  12020. // A pattern like: *.!(x).!(y|z) needs to ensure that a name
  12021. // like 'a.xyz.yz' doesn't match. So, the first negative
  12022. // lookahead, has to look ALL the way ahead, to the end of
  12023. // the pattern.
  12024. for (var n = negativeLists.length - 1; n > -1; n--) {
  12025. var nl = negativeLists[n];
  12026. var nlBefore = re.slice(0, nl.reStart);
  12027. var nlFirst = re.slice(nl.reStart, nl.reEnd - 8);
  12028. var nlLast = re.slice(nl.reEnd - 8, nl.reEnd);
  12029. var nlAfter = re.slice(nl.reEnd);
  12030. nlLast += nlAfter;
  12031. // Handle nested stuff like *(*.js|!(*.json)), where open parens
  12032. // mean that we should *not* include the ) in the bit that is considered
  12033. // "after" the negated section.
  12034. var openParensBefore = nlBefore.split('(').length - 1;
  12035. var cleanAfter = nlAfter;
  12036. for (i = 0; i < openParensBefore; i++) {
  12037. cleanAfter = cleanAfter.replace(/\)[+*?]?/, '');
  12038. }
  12039. nlAfter = cleanAfter;
  12040. var dollar = '';
  12041. if (nlAfter === '' && isSub !== SUBPARSE) {
  12042. dollar = '$';
  12043. }
  12044. var newRe = nlBefore + nlFirst + nlAfter + dollar + nlLast;
  12045. re = newRe;
  12046. }
  12047. // if the re is not "" at this point, then we need to make sure
  12048. // it doesn't match against an empty path part.
  12049. // Otherwise a/* will match a/, which it should not.
  12050. if (re !== '' && hasMagic) {
  12051. re = '(?=.)' + re;
  12052. }
  12053. if (addPatternStart) {
  12054. re = patternStart + re;
  12055. }
  12056. // parsing just a piece of a larger pattern.
  12057. if (isSub === SUBPARSE) {
  12058. return [re, hasMagic]
  12059. }
  12060. // skip the regexp for non-magical patterns
  12061. // unescape anything in it, though, so that it'll be
  12062. // an exact match against a file etc.
  12063. if (!hasMagic) {
  12064. return globUnescape(pattern)
  12065. }
  12066. var flags = options.nocase ? 'i' : '';
  12067. try {
  12068. var regExp = new RegExp('^' + re + '$', flags);
  12069. } catch (er) {
  12070. // If it was an invalid regular expression, then it can't match
  12071. // anything. This trick looks for a character after the end of
  12072. // the string, which is of course impossible, except in multi-line
  12073. // mode, but it's not a /m regex.
  12074. return new RegExp('$.')
  12075. }
  12076. regExp._glob = pattern;
  12077. regExp._src = re;
  12078. return regExp
  12079. }
  12080. minimatch.makeRe = function (pattern, options) {
  12081. return new Minimatch$1(pattern, options || {}).makeRe()
  12082. };
  12083. Minimatch$1.prototype.makeRe = makeRe;
  12084. function makeRe () {
  12085. if (this.regexp || this.regexp === false) return this.regexp
  12086. // at this point, this.set is a 2d array of partial
  12087. // pattern strings, or "**".
  12088. //
  12089. // It's better to use .match(). This function shouldn't
  12090. // be used, really, but it's pretty convenient sometimes,
  12091. // when you just want to work with a regex.
  12092. var set = this.set;
  12093. if (!set.length) {
  12094. this.regexp = false;
  12095. return this.regexp
  12096. }
  12097. var options = this.options;
  12098. var twoStar = options.noglobstar ? star
  12099. : options.dot ? twoStarDot
  12100. : twoStarNoDot;
  12101. var flags = options.nocase ? 'i' : '';
  12102. var re = set.map(function (pattern) {
  12103. return pattern.map(function (p) {
  12104. return (p === GLOBSTAR) ? twoStar
  12105. : (typeof p === 'string') ? regExpEscape(p)
  12106. : p._src
  12107. }).join('\\\/')
  12108. }).join('|');
  12109. // must match entire pattern
  12110. // ending in a * or ** will make it less strict.
  12111. re = '^(?:' + re + ')$';
  12112. // can match anything, as long as it's not this.
  12113. if (this.negate) re = '^(?!' + re + ').*$';
  12114. try {
  12115. this.regexp = new RegExp(re, flags);
  12116. } catch (ex) {
  12117. this.regexp = false;
  12118. }
  12119. return this.regexp
  12120. }
  12121. minimatch.match = function (list, pattern, options) {
  12122. options = options || {};
  12123. var mm = new Minimatch$1(pattern, options);
  12124. list = list.filter(function (f) {
  12125. return mm.match(f)
  12126. });
  12127. if (mm.options.nonull && !list.length) {
  12128. list.push(pattern);
  12129. }
  12130. return list
  12131. };
  12132. Minimatch$1.prototype.match = match;
  12133. function match (f, partial) {
  12134. this.debug('match', f, this.pattern);
  12135. // short-circuit in the case of busted things.
  12136. // comments, etc.
  12137. if (this.comment) return false
  12138. if (this.empty) return f === ''
  12139. if (f === '/' && partial) return true
  12140. var options = this.options;
  12141. // windows: need to use /, not \
  12142. if (path.sep !== '/') {
  12143. f = f.split(path.sep).join('/');
  12144. }
  12145. // treat the test path as a set of pathparts.
  12146. f = f.split(slashSplit);
  12147. this.debug(this.pattern, 'split', f);
  12148. // just ONE of the pattern sets in this.set needs to match
  12149. // in order for it to be valid. If negating, then just one
  12150. // match means that we have failed.
  12151. // Either way, return on the first hit.
  12152. var set = this.set;
  12153. this.debug(this.pattern, 'set', set);
  12154. // Find the basename of the path by looking for the last non-empty segment
  12155. var filename;
  12156. var i;
  12157. for (i = f.length - 1; i >= 0; i--) {
  12158. filename = f[i];
  12159. if (filename) break
  12160. }
  12161. for (i = 0; i < set.length; i++) {
  12162. var pattern = set[i];
  12163. var file = f;
  12164. if (options.matchBase && pattern.length === 1) {
  12165. file = [filename];
  12166. }
  12167. var hit = this.matchOne(file, pattern, partial);
  12168. if (hit) {
  12169. if (options.flipNegate) return true
  12170. return !this.negate
  12171. }
  12172. }
  12173. // didn't get any hits. this is success if it's a negative
  12174. // pattern, failure otherwise.
  12175. if (options.flipNegate) return false
  12176. return this.negate
  12177. }
  12178. // set partial to true to test if, for example,
  12179. // "/a/b" matches the start of "/*/b/*/d"
  12180. // Partial means, if you run out of file before you run
  12181. // out of pattern, then that's fine, as long as all
  12182. // the parts match.
  12183. Minimatch$1.prototype.matchOne = function (file, pattern, partial) {
  12184. var options = this.options;
  12185. this.debug('matchOne',
  12186. { 'this': this, file: file, pattern: pattern });
  12187. this.debug('matchOne', file.length, pattern.length);
  12188. for (var fi = 0,
  12189. pi = 0,
  12190. fl = file.length,
  12191. pl = pattern.length
  12192. ; (fi < fl) && (pi < pl)
  12193. ; fi++, pi++) {
  12194. this.debug('matchOne loop');
  12195. var p = pattern[pi];
  12196. var f = file[fi];
  12197. this.debug(pattern, p, f);
  12198. // should be impossible.
  12199. // some invalid regexp stuff in the set.
  12200. if (p === false) return false
  12201. if (p === GLOBSTAR) {
  12202. this.debug('GLOBSTAR', [pattern, p, f]);
  12203. // "**"
  12204. // a/**/b/**/c would match the following:
  12205. // a/b/x/y/z/c
  12206. // a/x/y/z/b/c
  12207. // a/b/x/b/x/c
  12208. // a/b/c
  12209. // To do this, take the rest of the pattern after
  12210. // the **, and see if it would match the file remainder.
  12211. // If so, return success.
  12212. // If not, the ** "swallows" a segment, and try again.
  12213. // This is recursively awful.
  12214. //
  12215. // a/**/b/**/c matching a/b/x/y/z/c
  12216. // - a matches a
  12217. // - doublestar
  12218. // - matchOne(b/x/y/z/c, b/**/c)
  12219. // - b matches b
  12220. // - doublestar
  12221. // - matchOne(x/y/z/c, c) -> no
  12222. // - matchOne(y/z/c, c) -> no
  12223. // - matchOne(z/c, c) -> no
  12224. // - matchOne(c, c) yes, hit
  12225. var fr = fi;
  12226. var pr = pi + 1;
  12227. if (pr === pl) {
  12228. this.debug('** at the end');
  12229. // a ** at the end will just swallow the rest.
  12230. // We have found a match.
  12231. // however, it will not swallow /.x, unless
  12232. // options.dot is set.
  12233. // . and .. are *never* matched by **, for explosively
  12234. // exponential reasons.
  12235. for (; fi < fl; fi++) {
  12236. if (file[fi] === '.' || file[fi] === '..' ||
  12237. (!options.dot && file[fi].charAt(0) === '.')) return false
  12238. }
  12239. return true
  12240. }
  12241. // ok, let's see if we can swallow whatever we can.
  12242. while (fr < fl) {
  12243. var swallowee = file[fr];
  12244. this.debug('\nglobstar while', file, fr, pattern, pr, swallowee);
  12245. // XXX remove this slice. Just pass the start index.
  12246. if (this.matchOne(file.slice(fr), pattern.slice(pr), partial)) {
  12247. this.debug('globstar found match!', fr, fl, swallowee);
  12248. // found a match.
  12249. return true
  12250. } else {
  12251. // can't swallow "." or ".." ever.
  12252. // can only swallow ".foo" when explicitly asked.
  12253. if (swallowee === '.' || swallowee === '..' ||
  12254. (!options.dot && swallowee.charAt(0) === '.')) {
  12255. this.debug('dot detected!', file, fr, pattern, pr);
  12256. break
  12257. }
  12258. // ** swallows a segment, and continue.
  12259. this.debug('globstar swallow a segment, and continue');
  12260. fr++;
  12261. }
  12262. }
  12263. // no match was found.
  12264. // However, in partial mode, we can't say this is necessarily over.
  12265. // If there's more *pattern* left, then
  12266. if (partial) {
  12267. // ran out of file
  12268. this.debug('\n>>> no match, partial?', file, fr, pattern, pr);
  12269. if (fr === fl) return true
  12270. }
  12271. return false
  12272. }
  12273. // something other than **
  12274. // non-magic patterns just have to match exactly
  12275. // patterns with magic have been turned into regexps.
  12276. var hit;
  12277. if (typeof p === 'string') {
  12278. if (options.nocase) {
  12279. hit = f.toLowerCase() === p.toLowerCase();
  12280. } else {
  12281. hit = f === p;
  12282. }
  12283. this.debug('string match', p, f, hit);
  12284. } else {
  12285. hit = f.match(p);
  12286. this.debug('pattern match', p, f, hit);
  12287. }
  12288. if (!hit) return false
  12289. }
  12290. // Note: ending in / means that we'll get a final ""
  12291. // at the end of the pattern. This can only match a
  12292. // corresponding "" at the end of the file.
  12293. // If the file ends in /, then it can only match a
  12294. // a pattern that ends in /, unless the pattern just
  12295. // doesn't have any more for it. But, a/b/ should *not*
  12296. // match "a/b/*", even though "" matches against the
  12297. // [^/]*? pattern, except in partial mode, where it might
  12298. // simply not be reached yet.
  12299. // However, a/b/ should still satisfy a/*
  12300. // now either we fell off the end of the pattern, or we're done.
  12301. if (fi === fl && pi === pl) {
  12302. // ran out of pattern and filename at the same time.
  12303. // an exact hit!
  12304. return true
  12305. } else if (fi === fl) {
  12306. // ran out of file, but still had pattern left.
  12307. // this is ok if we're doing the match as part of
  12308. // a glob fs traversal.
  12309. return partial
  12310. } else if (pi === pl) {
  12311. // ran out of pattern, still have file left.
  12312. // this is only acceptable if we're on the very last
  12313. // empty segment of a file with a trailing slash.
  12314. // a/* should match a/b/
  12315. var emptyFileEnd = (fi === fl - 1) && (file[fi] === '');
  12316. return emptyFileEnd
  12317. }
  12318. // should be unreachable.
  12319. throw new Error('wtf?')
  12320. };
  12321. // replace stuff like \* with *
  12322. function globUnescape (s) {
  12323. return s.replace(/\\(.)/g, '$1')
  12324. }
  12325. function regExpEscape (s) {
  12326. return s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&')
  12327. }
  12328. var inherits_browser = createCommonjsModule(function (module) {
  12329. if (typeof Object.create === 'function') {
  12330. // implementation from standard node.js 'util' module
  12331. module.exports = function inherits(ctor, superCtor) {
  12332. if (superCtor) {
  12333. ctor.super_ = superCtor;
  12334. ctor.prototype = Object.create(superCtor.prototype, {
  12335. constructor: {
  12336. value: ctor,
  12337. enumerable: false,
  12338. writable: true,
  12339. configurable: true
  12340. }
  12341. });
  12342. }
  12343. };
  12344. } else {
  12345. // old school shim for old browsers
  12346. module.exports = function inherits(ctor, superCtor) {
  12347. if (superCtor) {
  12348. ctor.super_ = superCtor;
  12349. var TempCtor = function () {};
  12350. TempCtor.prototype = superCtor.prototype;
  12351. ctor.prototype = new TempCtor();
  12352. ctor.prototype.constructor = ctor;
  12353. }
  12354. };
  12355. }
  12356. }, "/$$rollup_base$$/node_modules/inherits");
  12357. var inherits = createCommonjsModule(function (module) {
  12358. try {
  12359. var util = require$$0__default['default'];
  12360. /* istanbul ignore next */
  12361. if (typeof util.inherits !== 'function') throw '';
  12362. module.exports = util.inherits;
  12363. } catch (e) {
  12364. /* istanbul ignore next */
  12365. module.exports = inherits_browser;
  12366. }
  12367. }, "/$$rollup_base$$/node_modules/inherits");
  12368. function posix(path) {
  12369. return path.charAt(0) === '/';
  12370. }
  12371. function win32(path) {
  12372. // https://github.com/nodejs/node/blob/b3fcc245fb25539909ef1d5eaa01dbf92e168633/lib/path.js#L56
  12373. var splitDeviceRe = /^([a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/]+[^\\\/]+)?([\\\/])?([\s\S]*?)$/;
  12374. var result = splitDeviceRe.exec(path);
  12375. var device = result[1] || '';
  12376. var isUnc = Boolean(device && device.charAt(1) !== ':');
  12377. // UNC paths are always absolute
  12378. return Boolean(result[2] || isUnc);
  12379. }
  12380. var pathIsAbsolute = process.platform === 'win32' ? win32 : posix;
  12381. var posix_1 = posix;
  12382. var win32_1 = win32;
  12383. pathIsAbsolute.posix = posix_1;
  12384. pathIsAbsolute.win32 = win32_1;
  12385. var alphasort_1 = alphasort;
  12386. var alphasorti_1 = alphasorti;
  12387. var setopts_1 = setopts$2;
  12388. var ownProp_1 = ownProp$2;
  12389. var makeAbs_1 = makeAbs;
  12390. var finish_1 = finish;
  12391. var mark_1 = mark;
  12392. var isIgnored_1 = isIgnored$2;
  12393. var childrenIgnored_1 = childrenIgnored$2;
  12394. function ownProp$2 (obj, field) {
  12395. return Object.prototype.hasOwnProperty.call(obj, field)
  12396. }
  12397. var Minimatch = minimatch_1.Minimatch;
  12398. function alphasorti (a, b) {
  12399. return a.toLowerCase().localeCompare(b.toLowerCase())
  12400. }
  12401. function alphasort (a, b) {
  12402. return a.localeCompare(b)
  12403. }
  12404. function setupIgnores (self, options) {
  12405. self.ignore = options.ignore || [];
  12406. if (!Array.isArray(self.ignore))
  12407. self.ignore = [self.ignore];
  12408. if (self.ignore.length) {
  12409. self.ignore = self.ignore.map(ignoreMap);
  12410. }
  12411. }
  12412. // ignore patterns are always in dot:true mode.
  12413. function ignoreMap (pattern) {
  12414. var gmatcher = null;
  12415. if (pattern.slice(-3) === '/**') {
  12416. var gpattern = pattern.replace(/(\/\*\*)+$/, '');
  12417. gmatcher = new Minimatch(gpattern, { dot: true });
  12418. }
  12419. return {
  12420. matcher: new Minimatch(pattern, { dot: true }),
  12421. gmatcher: gmatcher
  12422. }
  12423. }
  12424. function setopts$2 (self, pattern, options) {
  12425. if (!options)
  12426. options = {};
  12427. // base-matching: just use globstar for that.
  12428. if (options.matchBase && -1 === pattern.indexOf("/")) {
  12429. if (options.noglobstar) {
  12430. throw new Error("base matching requires globstar")
  12431. }
  12432. pattern = "**/" + pattern;
  12433. }
  12434. self.silent = !!options.silent;
  12435. self.pattern = pattern;
  12436. self.strict = options.strict !== false;
  12437. self.realpath = !!options.realpath;
  12438. self.realpathCache = options.realpathCache || Object.create(null);
  12439. self.follow = !!options.follow;
  12440. self.dot = !!options.dot;
  12441. self.mark = !!options.mark;
  12442. self.nodir = !!options.nodir;
  12443. if (self.nodir)
  12444. self.mark = true;
  12445. self.sync = !!options.sync;
  12446. self.nounique = !!options.nounique;
  12447. self.nonull = !!options.nonull;
  12448. self.nosort = !!options.nosort;
  12449. self.nocase = !!options.nocase;
  12450. self.stat = !!options.stat;
  12451. self.noprocess = !!options.noprocess;
  12452. self.absolute = !!options.absolute;
  12453. self.maxLength = options.maxLength || Infinity;
  12454. self.cache = options.cache || Object.create(null);
  12455. self.statCache = options.statCache || Object.create(null);
  12456. self.symlinks = options.symlinks || Object.create(null);
  12457. setupIgnores(self, options);
  12458. self.changedCwd = false;
  12459. var cwd = process.cwd();
  12460. if (!ownProp$2(options, "cwd"))
  12461. self.cwd = cwd;
  12462. else {
  12463. self.cwd = path__default['default'].resolve(options.cwd);
  12464. self.changedCwd = self.cwd !== cwd;
  12465. }
  12466. self.root = options.root || path__default['default'].resolve(self.cwd, "/");
  12467. self.root = path__default['default'].resolve(self.root);
  12468. if (process.platform === "win32")
  12469. self.root = self.root.replace(/\\/g, "/");
  12470. // TODO: is an absolute `cwd` supposed to be resolved against `root`?
  12471. // e.g. { cwd: '/test', root: __dirname } === path.join(__dirname, '/test')
  12472. self.cwdAbs = pathIsAbsolute(self.cwd) ? self.cwd : makeAbs(self, self.cwd);
  12473. if (process.platform === "win32")
  12474. self.cwdAbs = self.cwdAbs.replace(/\\/g, "/");
  12475. self.nomount = !!options.nomount;
  12476. // disable comments and negation in Minimatch.
  12477. // Note that they are not supported in Glob itself anyway.
  12478. options.nonegate = true;
  12479. options.nocomment = true;
  12480. self.minimatch = new Minimatch(pattern, options);
  12481. self.options = self.minimatch.options;
  12482. }
  12483. function finish (self) {
  12484. var nou = self.nounique;
  12485. var all = nou ? [] : Object.create(null);
  12486. for (var i = 0, l = self.matches.length; i < l; i ++) {
  12487. var matches = self.matches[i];
  12488. if (!matches || Object.keys(matches).length === 0) {
  12489. if (self.nonull) {
  12490. // do like the shell, and spit out the literal glob
  12491. var literal = self.minimatch.globSet[i];
  12492. if (nou)
  12493. all.push(literal);
  12494. else
  12495. all[literal] = true;
  12496. }
  12497. } else {
  12498. // had matches
  12499. var m = Object.keys(matches);
  12500. if (nou)
  12501. all.push.apply(all, m);
  12502. else
  12503. m.forEach(function (m) {
  12504. all[m] = true;
  12505. });
  12506. }
  12507. }
  12508. if (!nou)
  12509. all = Object.keys(all);
  12510. if (!self.nosort)
  12511. all = all.sort(self.nocase ? alphasorti : alphasort);
  12512. // at *some* point we statted all of these
  12513. if (self.mark) {
  12514. for (var i = 0; i < all.length; i++) {
  12515. all[i] = self._mark(all[i]);
  12516. }
  12517. if (self.nodir) {
  12518. all = all.filter(function (e) {
  12519. var notDir = !(/\/$/.test(e));
  12520. var c = self.cache[e] || self.cache[makeAbs(self, e)];
  12521. if (notDir && c)
  12522. notDir = c !== 'DIR' && !Array.isArray(c);
  12523. return notDir
  12524. });
  12525. }
  12526. }
  12527. if (self.ignore.length)
  12528. all = all.filter(function(m) {
  12529. return !isIgnored$2(self, m)
  12530. });
  12531. self.found = all;
  12532. }
  12533. function mark (self, p) {
  12534. var abs = makeAbs(self, p);
  12535. var c = self.cache[abs];
  12536. var m = p;
  12537. if (c) {
  12538. var isDir = c === 'DIR' || Array.isArray(c);
  12539. var slash = p.slice(-1) === '/';
  12540. if (isDir && !slash)
  12541. m += '/';
  12542. else if (!isDir && slash)
  12543. m = m.slice(0, -1);
  12544. if (m !== p) {
  12545. var mabs = makeAbs(self, m);
  12546. self.statCache[mabs] = self.statCache[abs];
  12547. self.cache[mabs] = self.cache[abs];
  12548. }
  12549. }
  12550. return m
  12551. }
  12552. // lotta situps...
  12553. function makeAbs (self, f) {
  12554. var abs = f;
  12555. if (f.charAt(0) === '/') {
  12556. abs = path__default['default'].join(self.root, f);
  12557. } else if (pathIsAbsolute(f) || f === '') {
  12558. abs = f;
  12559. } else if (self.changedCwd) {
  12560. abs = path__default['default'].resolve(self.cwd, f);
  12561. } else {
  12562. abs = path__default['default'].resolve(f);
  12563. }
  12564. if (process.platform === 'win32')
  12565. abs = abs.replace(/\\/g, '/');
  12566. return abs
  12567. }
  12568. // Return true, if pattern ends with globstar '**', for the accompanying parent directory.
  12569. // Ex:- If node_modules/** is the pattern, add 'node_modules' to ignore list along with it's contents
  12570. function isIgnored$2 (self, path) {
  12571. if (!self.ignore.length)
  12572. return false
  12573. return self.ignore.some(function(item) {
  12574. return item.matcher.match(path) || !!(item.gmatcher && item.gmatcher.match(path))
  12575. })
  12576. }
  12577. function childrenIgnored$2 (self, path) {
  12578. if (!self.ignore.length)
  12579. return false
  12580. return self.ignore.some(function(item) {
  12581. return !!(item.gmatcher && item.gmatcher.match(path))
  12582. })
  12583. }
  12584. var common = {
  12585. alphasort: alphasort_1,
  12586. alphasorti: alphasorti_1,
  12587. setopts: setopts_1,
  12588. ownProp: ownProp_1,
  12589. makeAbs: makeAbs_1,
  12590. finish: finish_1,
  12591. mark: mark_1,
  12592. isIgnored: isIgnored_1,
  12593. childrenIgnored: childrenIgnored_1
  12594. };
  12595. var sync = globSync;
  12596. globSync.GlobSync = GlobSync$1;
  12597. var setopts$1 = common.setopts;
  12598. var ownProp$1 = common.ownProp;
  12599. var childrenIgnored$1 = common.childrenIgnored;
  12600. var isIgnored$1 = common.isIgnored;
  12601. function globSync (pattern, options) {
  12602. if (typeof options === 'function' || arguments.length === 3)
  12603. throw new TypeError('callback provided to sync glob\n'+
  12604. 'See: https://github.com/isaacs/node-glob/issues/167')
  12605. return new GlobSync$1(pattern, options).found
  12606. }
  12607. function GlobSync$1 (pattern, options) {
  12608. if (!pattern)
  12609. throw new Error('must provide pattern')
  12610. if (typeof options === 'function' || arguments.length === 3)
  12611. throw new TypeError('callback provided to sync glob\n'+
  12612. 'See: https://github.com/isaacs/node-glob/issues/167')
  12613. if (!(this instanceof GlobSync$1))
  12614. return new GlobSync$1(pattern, options)
  12615. setopts$1(this, pattern, options);
  12616. if (this.noprocess)
  12617. return this
  12618. var n = this.minimatch.set.length;
  12619. this.matches = new Array(n);
  12620. for (var i = 0; i < n; i ++) {
  12621. this._process(this.minimatch.set[i], i, false);
  12622. }
  12623. this._finish();
  12624. }
  12625. GlobSync$1.prototype._finish = function () {
  12626. assert__default['default'](this instanceof GlobSync$1);
  12627. if (this.realpath) {
  12628. var self = this;
  12629. this.matches.forEach(function (matchset, index) {
  12630. var set = self.matches[index] = Object.create(null);
  12631. for (var p in matchset) {
  12632. try {
  12633. p = self._makeAbs(p);
  12634. var real = fs_realpath.realpathSync(p, self.realpathCache);
  12635. set[real] = true;
  12636. } catch (er) {
  12637. if (er.syscall === 'stat')
  12638. set[self._makeAbs(p)] = true;
  12639. else
  12640. throw er
  12641. }
  12642. }
  12643. });
  12644. }
  12645. common.finish(this);
  12646. };
  12647. GlobSync$1.prototype._process = function (pattern, index, inGlobStar) {
  12648. assert__default['default'](this instanceof GlobSync$1);
  12649. // Get the first [n] parts of pattern that are all strings.
  12650. var n = 0;
  12651. while (typeof pattern[n] === 'string') {
  12652. n ++;
  12653. }
  12654. // now n is the index of the first one that is *not* a string.
  12655. // See if there's anything else
  12656. var prefix;
  12657. switch (n) {
  12658. // if not, then this is rather simple
  12659. case pattern.length:
  12660. this._processSimple(pattern.join('/'), index);
  12661. return
  12662. case 0:
  12663. // pattern *starts* with some non-trivial item.
  12664. // going to readdir(cwd), but not include the prefix in matches.
  12665. prefix = null;
  12666. break
  12667. default:
  12668. // pattern has some string bits in the front.
  12669. // whatever it starts with, whether that's 'absolute' like /foo/bar,
  12670. // or 'relative' like '../baz'
  12671. prefix = pattern.slice(0, n).join('/');
  12672. break
  12673. }
  12674. var remain = pattern.slice(n);
  12675. // get the list of entries.
  12676. var read;
  12677. if (prefix === null)
  12678. read = '.';
  12679. else if (pathIsAbsolute(prefix) || pathIsAbsolute(pattern.join('/'))) {
  12680. if (!prefix || !pathIsAbsolute(prefix))
  12681. prefix = '/' + prefix;
  12682. read = prefix;
  12683. } else
  12684. read = prefix;
  12685. var abs = this._makeAbs(read);
  12686. //if ignored, skip processing
  12687. if (childrenIgnored$1(this, read))
  12688. return
  12689. var isGlobStar = remain[0] === minimatch_1.GLOBSTAR;
  12690. if (isGlobStar)
  12691. this._processGlobStar(prefix, read, abs, remain, index, inGlobStar);
  12692. else
  12693. this._processReaddir(prefix, read, abs, remain, index, inGlobStar);
  12694. };
  12695. GlobSync$1.prototype._processReaddir = function (prefix, read, abs, remain, index, inGlobStar) {
  12696. var entries = this._readdir(abs, inGlobStar);
  12697. // if the abs isn't a dir, then nothing can match!
  12698. if (!entries)
  12699. return
  12700. // It will only match dot entries if it starts with a dot, or if
  12701. // dot is set. Stuff like @(.foo|.bar) isn't allowed.
  12702. var pn = remain[0];
  12703. var negate = !!this.minimatch.negate;
  12704. var rawGlob = pn._glob;
  12705. var dotOk = this.dot || rawGlob.charAt(0) === '.';
  12706. var matchedEntries = [];
  12707. for (var i = 0; i < entries.length; i++) {
  12708. var e = entries[i];
  12709. if (e.charAt(0) !== '.' || dotOk) {
  12710. var m;
  12711. if (negate && !prefix) {
  12712. m = !e.match(pn);
  12713. } else {
  12714. m = e.match(pn);
  12715. }
  12716. if (m)
  12717. matchedEntries.push(e);
  12718. }
  12719. }
  12720. var len = matchedEntries.length;
  12721. // If there are no matched entries, then nothing matches.
  12722. if (len === 0)
  12723. return
  12724. // if this is the last remaining pattern bit, then no need for
  12725. // an additional stat *unless* the user has specified mark or
  12726. // stat explicitly. We know they exist, since readdir returned
  12727. // them.
  12728. if (remain.length === 1 && !this.mark && !this.stat) {
  12729. if (!this.matches[index])
  12730. this.matches[index] = Object.create(null);
  12731. for (var i = 0; i < len; i ++) {
  12732. var e = matchedEntries[i];
  12733. if (prefix) {
  12734. if (prefix.slice(-1) !== '/')
  12735. e = prefix + '/' + e;
  12736. else
  12737. e = prefix + e;
  12738. }
  12739. if (e.charAt(0) === '/' && !this.nomount) {
  12740. e = path__default['default'].join(this.root, e);
  12741. }
  12742. this._emitMatch(index, e);
  12743. }
  12744. // This was the last one, and no stats were needed
  12745. return
  12746. }
  12747. // now test all matched entries as stand-ins for that part
  12748. // of the pattern.
  12749. remain.shift();
  12750. for (var i = 0; i < len; i ++) {
  12751. var e = matchedEntries[i];
  12752. var newPattern;
  12753. if (prefix)
  12754. newPattern = [prefix, e];
  12755. else
  12756. newPattern = [e];
  12757. this._process(newPattern.concat(remain), index, inGlobStar);
  12758. }
  12759. };
  12760. GlobSync$1.prototype._emitMatch = function (index, e) {
  12761. if (isIgnored$1(this, e))
  12762. return
  12763. var abs = this._makeAbs(e);
  12764. if (this.mark)
  12765. e = this._mark(e);
  12766. if (this.absolute) {
  12767. e = abs;
  12768. }
  12769. if (this.matches[index][e])
  12770. return
  12771. if (this.nodir) {
  12772. var c = this.cache[abs];
  12773. if (c === 'DIR' || Array.isArray(c))
  12774. return
  12775. }
  12776. this.matches[index][e] = true;
  12777. if (this.stat)
  12778. this._stat(e);
  12779. };
  12780. GlobSync$1.prototype._readdirInGlobStar = function (abs) {
  12781. // follow all symlinked directories forever
  12782. // just proceed as if this is a non-globstar situation
  12783. if (this.follow)
  12784. return this._readdir(abs, false)
  12785. var entries;
  12786. var lstat;
  12787. try {
  12788. lstat = fs__default['default'].lstatSync(abs);
  12789. } catch (er) {
  12790. if (er.code === 'ENOENT') {
  12791. // lstat failed, doesn't exist
  12792. return null
  12793. }
  12794. }
  12795. var isSym = lstat && lstat.isSymbolicLink();
  12796. this.symlinks[abs] = isSym;
  12797. // If it's not a symlink or a dir, then it's definitely a regular file.
  12798. // don't bother doing a readdir in that case.
  12799. if (!isSym && lstat && !lstat.isDirectory())
  12800. this.cache[abs] = 'FILE';
  12801. else
  12802. entries = this._readdir(abs, false);
  12803. return entries
  12804. };
  12805. GlobSync$1.prototype._readdir = function (abs, inGlobStar) {
  12806. if (inGlobStar && !ownProp$1(this.symlinks, abs))
  12807. return this._readdirInGlobStar(abs)
  12808. if (ownProp$1(this.cache, abs)) {
  12809. var c = this.cache[abs];
  12810. if (!c || c === 'FILE')
  12811. return null
  12812. if (Array.isArray(c))
  12813. return c
  12814. }
  12815. try {
  12816. return this._readdirEntries(abs, fs__default['default'].readdirSync(abs))
  12817. } catch (er) {
  12818. this._readdirError(abs, er);
  12819. return null
  12820. }
  12821. };
  12822. GlobSync$1.prototype._readdirEntries = function (abs, entries) {
  12823. // if we haven't asked to stat everything, then just
  12824. // assume that everything in there exists, so we can avoid
  12825. // having to stat it a second time.
  12826. if (!this.mark && !this.stat) {
  12827. for (var i = 0; i < entries.length; i ++) {
  12828. var e = entries[i];
  12829. if (abs === '/')
  12830. e = abs + e;
  12831. else
  12832. e = abs + '/' + e;
  12833. this.cache[e] = true;
  12834. }
  12835. }
  12836. this.cache[abs] = entries;
  12837. // mark and cache dir-ness
  12838. return entries
  12839. };
  12840. GlobSync$1.prototype._readdirError = function (f, er) {
  12841. // handle errors, and cache the information
  12842. switch (er.code) {
  12843. case 'ENOTSUP': // https://github.com/isaacs/node-glob/issues/205
  12844. case 'ENOTDIR': // totally normal. means it *does* exist.
  12845. var abs = this._makeAbs(f);
  12846. this.cache[abs] = 'FILE';
  12847. if (abs === this.cwdAbs) {
  12848. var error = new Error(er.code + ' invalid cwd ' + this.cwd);
  12849. error.path = this.cwd;
  12850. error.code = er.code;
  12851. throw error
  12852. }
  12853. break
  12854. case 'ENOENT': // not terribly unusual
  12855. case 'ELOOP':
  12856. case 'ENAMETOOLONG':
  12857. case 'UNKNOWN':
  12858. this.cache[this._makeAbs(f)] = false;
  12859. break
  12860. default: // some unusual error. Treat as failure.
  12861. this.cache[this._makeAbs(f)] = false;
  12862. if (this.strict)
  12863. throw er
  12864. if (!this.silent)
  12865. console.error('glob error', er);
  12866. break
  12867. }
  12868. };
  12869. GlobSync$1.prototype._processGlobStar = function (prefix, read, abs, remain, index, inGlobStar) {
  12870. var entries = this._readdir(abs, inGlobStar);
  12871. // no entries means not a dir, so it can never have matches
  12872. // foo.txt/** doesn't match foo.txt
  12873. if (!entries)
  12874. return
  12875. // test without the globstar, and with every child both below
  12876. // and replacing the globstar.
  12877. var remainWithoutGlobStar = remain.slice(1);
  12878. var gspref = prefix ? [ prefix ] : [];
  12879. var noGlobStar = gspref.concat(remainWithoutGlobStar);
  12880. // the noGlobStar pattern exits the inGlobStar state
  12881. this._process(noGlobStar, index, false);
  12882. var len = entries.length;
  12883. var isSym = this.symlinks[abs];
  12884. // If it's a symlink, and we're in a globstar, then stop
  12885. if (isSym && inGlobStar)
  12886. return
  12887. for (var i = 0; i < len; i++) {
  12888. var e = entries[i];
  12889. if (e.charAt(0) === '.' && !this.dot)
  12890. continue
  12891. // these two cases enter the inGlobStar state
  12892. var instead = gspref.concat(entries[i], remainWithoutGlobStar);
  12893. this._process(instead, index, true);
  12894. var below = gspref.concat(entries[i], remain);
  12895. this._process(below, index, true);
  12896. }
  12897. };
  12898. GlobSync$1.prototype._processSimple = function (prefix, index) {
  12899. // XXX review this. Shouldn't it be doing the mounting etc
  12900. // before doing stat? kinda weird?
  12901. var exists = this._stat(prefix);
  12902. if (!this.matches[index])
  12903. this.matches[index] = Object.create(null);
  12904. // If it doesn't exist, then just mark the lack of results
  12905. if (!exists)
  12906. return
  12907. if (prefix && pathIsAbsolute(prefix) && !this.nomount) {
  12908. var trail = /[\/\\]$/.test(prefix);
  12909. if (prefix.charAt(0) === '/') {
  12910. prefix = path__default['default'].join(this.root, prefix);
  12911. } else {
  12912. prefix = path__default['default'].resolve(this.root, prefix);
  12913. if (trail)
  12914. prefix += '/';
  12915. }
  12916. }
  12917. if (process.platform === 'win32')
  12918. prefix = prefix.replace(/\\/g, '/');
  12919. // Mark this as a match
  12920. this._emitMatch(index, prefix);
  12921. };
  12922. // Returns either 'DIR', 'FILE', or false
  12923. GlobSync$1.prototype._stat = function (f) {
  12924. var abs = this._makeAbs(f);
  12925. var needDir = f.slice(-1) === '/';
  12926. if (f.length > this.maxLength)
  12927. return false
  12928. if (!this.stat && ownProp$1(this.cache, abs)) {
  12929. var c = this.cache[abs];
  12930. if (Array.isArray(c))
  12931. c = 'DIR';
  12932. // It exists, but maybe not how we need it
  12933. if (!needDir || c === 'DIR')
  12934. return c
  12935. if (needDir && c === 'FILE')
  12936. return false
  12937. // otherwise we have to stat, because maybe c=true
  12938. // if we know it exists, but not what it is.
  12939. }
  12940. var stat = this.statCache[abs];
  12941. if (!stat) {
  12942. var lstat;
  12943. try {
  12944. lstat = fs__default['default'].lstatSync(abs);
  12945. } catch (er) {
  12946. if (er && (er.code === 'ENOENT' || er.code === 'ENOTDIR')) {
  12947. this.statCache[abs] = false;
  12948. return false
  12949. }
  12950. }
  12951. if (lstat && lstat.isSymbolicLink()) {
  12952. try {
  12953. stat = fs__default['default'].statSync(abs);
  12954. } catch (er) {
  12955. stat = lstat;
  12956. }
  12957. } else {
  12958. stat = lstat;
  12959. }
  12960. }
  12961. this.statCache[abs] = stat;
  12962. var c = true;
  12963. if (stat)
  12964. c = stat.isDirectory() ? 'DIR' : 'FILE';
  12965. this.cache[abs] = this.cache[abs] || c;
  12966. if (needDir && c === 'FILE')
  12967. return false
  12968. return c
  12969. };
  12970. GlobSync$1.prototype._mark = function (p) {
  12971. return common.mark(this, p)
  12972. };
  12973. GlobSync$1.prototype._makeAbs = function (f) {
  12974. return common.makeAbs(this, f)
  12975. };
  12976. // Returns a wrapper function that returns a wrapped callback
  12977. // The wrapper function should do some stuff, and return a
  12978. // presumably different callback function.
  12979. // This makes sure that own properties are retained, so that
  12980. // decorations and such are not lost along the way.
  12981. var wrappy_1 = wrappy;
  12982. function wrappy (fn, cb) {
  12983. if (fn && cb) return wrappy(fn)(cb)
  12984. if (typeof fn !== 'function')
  12985. throw new TypeError('need wrapper function')
  12986. Object.keys(fn).forEach(function (k) {
  12987. wrapper[k] = fn[k];
  12988. });
  12989. return wrapper
  12990. function wrapper() {
  12991. var args = new Array(arguments.length);
  12992. for (var i = 0; i < args.length; i++) {
  12993. args[i] = arguments[i];
  12994. }
  12995. var ret = fn.apply(this, args);
  12996. var cb = args[args.length-1];
  12997. if (typeof ret === 'function' && ret !== cb) {
  12998. Object.keys(cb).forEach(function (k) {
  12999. ret[k] = cb[k];
  13000. });
  13001. }
  13002. return ret
  13003. }
  13004. }
  13005. var once_1 = wrappy_1(once);
  13006. var strict = wrappy_1(onceStrict);
  13007. once.proto = once(function () {
  13008. Object.defineProperty(Function.prototype, 'once', {
  13009. value: function () {
  13010. return once(this)
  13011. },
  13012. configurable: true
  13013. });
  13014. Object.defineProperty(Function.prototype, 'onceStrict', {
  13015. value: function () {
  13016. return onceStrict(this)
  13017. },
  13018. configurable: true
  13019. });
  13020. });
  13021. function once (fn) {
  13022. var f = function () {
  13023. if (f.called) return f.value
  13024. f.called = true;
  13025. return f.value = fn.apply(this, arguments)
  13026. };
  13027. f.called = false;
  13028. return f
  13029. }
  13030. function onceStrict (fn) {
  13031. var f = function () {
  13032. if (f.called)
  13033. throw new Error(f.onceError)
  13034. f.called = true;
  13035. return f.value = fn.apply(this, arguments)
  13036. };
  13037. var name = fn.name || 'Function wrapped with `once`';
  13038. f.onceError = name + " shouldn't be called more than once";
  13039. f.called = false;
  13040. return f
  13041. }
  13042. once_1.strict = strict;
  13043. var reqs = Object.create(null);
  13044. var inflight_1 = wrappy_1(inflight);
  13045. function inflight (key, cb) {
  13046. if (reqs[key]) {
  13047. reqs[key].push(cb);
  13048. return null
  13049. } else {
  13050. reqs[key] = [cb];
  13051. return makeres(key)
  13052. }
  13053. }
  13054. function makeres (key) {
  13055. return once_1(function RES () {
  13056. var cbs = reqs[key];
  13057. var len = cbs.length;
  13058. var args = slice(arguments);
  13059. // XXX It's somewhat ambiguous whether a new callback added in this
  13060. // pass should be queued for later execution if something in the
  13061. // list of callbacks throws, or if it should just be discarded.
  13062. // However, it's such an edge case that it hardly matters, and either
  13063. // choice is likely as surprising as the other.
  13064. // As it happens, we do go ahead and schedule it for later execution.
  13065. try {
  13066. for (var i = 0; i < len; i++) {
  13067. cbs[i].apply(null, args);
  13068. }
  13069. } finally {
  13070. if (cbs.length > len) {
  13071. // added more in the interim.
  13072. // de-zalgo, just in case, but don't call again.
  13073. cbs.splice(0, len);
  13074. process.nextTick(function () {
  13075. RES.apply(null, args);
  13076. });
  13077. } else {
  13078. delete reqs[key];
  13079. }
  13080. }
  13081. })
  13082. }
  13083. function slice (args) {
  13084. var length = args.length;
  13085. var array = [];
  13086. for (var i = 0; i < length; i++) array[i] = args[i];
  13087. return array
  13088. }
  13089. var EE = require$$0__default$1['default'].EventEmitter;
  13090. var setopts = common.setopts;
  13091. var ownProp = common.ownProp;
  13092. var childrenIgnored = common.childrenIgnored;
  13093. var isIgnored = common.isIgnored;
  13094. var GlobSync = sync.GlobSync;
  13095. inherits(Glob, EE);
  13096. function Glob (pattern, options, cb) {
  13097. if (typeof options === 'function') {
  13098. cb = options;
  13099. options = null;
  13100. }
  13101. if (options && options.sync) {
  13102. if (cb)
  13103. throw new TypeError('callback provided to sync glob')
  13104. return new GlobSync(pattern, options)
  13105. }
  13106. if (!(this instanceof Glob))
  13107. return new Glob(pattern, options, cb)
  13108. setopts(this, pattern, options);
  13109. this._didRealPath = false;
  13110. // process each pattern in the minimatch set
  13111. var n = this.minimatch.set.length;
  13112. // The matches are stored as {<filename>: true,...} so that
  13113. // duplicates are automagically pruned.
  13114. // Later, we do an Object.keys() on these.
  13115. // Keep them as a list so we can fill in when nonull is set.
  13116. this.matches = new Array(n);
  13117. if (typeof cb === 'function') {
  13118. cb = once_1(cb);
  13119. this.on('error', cb);
  13120. this.on('end', function (matches) {
  13121. cb(null, matches);
  13122. });
  13123. }
  13124. var self = this;
  13125. this._processing = 0;
  13126. this._emitQueue = [];
  13127. this._processQueue = [];
  13128. this.paused = false;
  13129. if (this.noprocess)
  13130. return this
  13131. if (n === 0)
  13132. return done()
  13133. var sync = true;
  13134. for (var i = 0; i < n; i ++) {
  13135. this._process(this.minimatch.set[i], i, false, done);
  13136. }
  13137. sync = false;
  13138. function done () {
  13139. --self._processing;
  13140. if (self._processing <= 0) {
  13141. if (sync) {
  13142. process.nextTick(function () {
  13143. self._finish();
  13144. });
  13145. } else {
  13146. self._finish();
  13147. }
  13148. }
  13149. }
  13150. }
  13151. Glob.prototype._finish = function () {
  13152. assert__default['default'](this instanceof Glob);
  13153. if (this.aborted)
  13154. return
  13155. if (this.realpath && !this._didRealpath)
  13156. return this._realpath()
  13157. common.finish(this);
  13158. this.emit('end', this.found);
  13159. };
  13160. Glob.prototype._realpath = function () {
  13161. if (this._didRealpath)
  13162. return
  13163. this._didRealpath = true;
  13164. var n = this.matches.length;
  13165. if (n === 0)
  13166. return this._finish()
  13167. var self = this;
  13168. for (var i = 0; i < this.matches.length; i++)
  13169. this._realpathSet(i, next);
  13170. function next () {
  13171. if (--n === 0)
  13172. self._finish();
  13173. }
  13174. };
  13175. Glob.prototype._realpathSet = function (index, cb) {
  13176. var matchset = this.matches[index];
  13177. if (!matchset)
  13178. return cb()
  13179. var found = Object.keys(matchset);
  13180. var self = this;
  13181. var n = found.length;
  13182. if (n === 0)
  13183. return cb()
  13184. var set = this.matches[index] = Object.create(null);
  13185. found.forEach(function (p, i) {
  13186. // If there's a problem with the stat, then it means that
  13187. // one or more of the links in the realpath couldn't be
  13188. // resolved. just return the abs value in that case.
  13189. p = self._makeAbs(p);
  13190. fs_realpath.realpath(p, self.realpathCache, function (er, real) {
  13191. if (!er)
  13192. set[real] = true;
  13193. else if (er.syscall === 'stat')
  13194. set[p] = true;
  13195. else
  13196. self.emit('error', er); // srsly wtf right here
  13197. if (--n === 0) {
  13198. self.matches[index] = set;
  13199. cb();
  13200. }
  13201. });
  13202. });
  13203. };
  13204. Glob.prototype._mark = function (p) {
  13205. return common.mark(this, p)
  13206. };
  13207. Glob.prototype._makeAbs = function (f) {
  13208. return common.makeAbs(this, f)
  13209. };
  13210. Glob.prototype.abort = function () {
  13211. this.aborted = true;
  13212. this.emit('abort');
  13213. };
  13214. Glob.prototype.pause = function () {
  13215. if (!this.paused) {
  13216. this.paused = true;
  13217. this.emit('pause');
  13218. }
  13219. };
  13220. Glob.prototype.resume = function () {
  13221. if (this.paused) {
  13222. this.emit('resume');
  13223. this.paused = false;
  13224. if (this._emitQueue.length) {
  13225. var eq = this._emitQueue.slice(0);
  13226. this._emitQueue.length = 0;
  13227. for (var i = 0; i < eq.length; i ++) {
  13228. var e = eq[i];
  13229. this._emitMatch(e[0], e[1]);
  13230. }
  13231. }
  13232. if (this._processQueue.length) {
  13233. var pq = this._processQueue.slice(0);
  13234. this._processQueue.length = 0;
  13235. for (var i = 0; i < pq.length; i ++) {
  13236. var p = pq[i];
  13237. this._processing--;
  13238. this._process(p[0], p[1], p[2], p[3]);
  13239. }
  13240. }
  13241. }
  13242. };
  13243. Glob.prototype._process = function (pattern, index, inGlobStar, cb) {
  13244. assert__default['default'](this instanceof Glob);
  13245. assert__default['default'](typeof cb === 'function');
  13246. if (this.aborted)
  13247. return
  13248. this._processing++;
  13249. if (this.paused) {
  13250. this._processQueue.push([pattern, index, inGlobStar, cb]);
  13251. return
  13252. }
  13253. //console.error('PROCESS %d', this._processing, pattern)
  13254. // Get the first [n] parts of pattern that are all strings.
  13255. var n = 0;
  13256. while (typeof pattern[n] === 'string') {
  13257. n ++;
  13258. }
  13259. // now n is the index of the first one that is *not* a string.
  13260. // see if there's anything else
  13261. var prefix;
  13262. switch (n) {
  13263. // if not, then this is rather simple
  13264. case pattern.length:
  13265. this._processSimple(pattern.join('/'), index, cb);
  13266. return
  13267. case 0:
  13268. // pattern *starts* with some non-trivial item.
  13269. // going to readdir(cwd), but not include the prefix in matches.
  13270. prefix = null;
  13271. break
  13272. default:
  13273. // pattern has some string bits in the front.
  13274. // whatever it starts with, whether that's 'absolute' like /foo/bar,
  13275. // or 'relative' like '../baz'
  13276. prefix = pattern.slice(0, n).join('/');
  13277. break
  13278. }
  13279. var remain = pattern.slice(n);
  13280. // get the list of entries.
  13281. var read;
  13282. if (prefix === null)
  13283. read = '.';
  13284. else if (pathIsAbsolute(prefix) || pathIsAbsolute(pattern.join('/'))) {
  13285. if (!prefix || !pathIsAbsolute(prefix))
  13286. prefix = '/' + prefix;
  13287. read = prefix;
  13288. } else
  13289. read = prefix;
  13290. var abs = this._makeAbs(read);
  13291. //if ignored, skip _processing
  13292. if (childrenIgnored(this, read))
  13293. return cb()
  13294. var isGlobStar = remain[0] === minimatch_1.GLOBSTAR;
  13295. if (isGlobStar)
  13296. this._processGlobStar(prefix, read, abs, remain, index, inGlobStar, cb);
  13297. else
  13298. this._processReaddir(prefix, read, abs, remain, index, inGlobStar, cb);
  13299. };
  13300. Glob.prototype._processReaddir = function (prefix, read, abs, remain, index, inGlobStar, cb) {
  13301. var self = this;
  13302. this._readdir(abs, inGlobStar, function (er, entries) {
  13303. return self._processReaddir2(prefix, read, abs, remain, index, inGlobStar, entries, cb)
  13304. });
  13305. };
  13306. Glob.prototype._processReaddir2 = function (prefix, read, abs, remain, index, inGlobStar, entries, cb) {
  13307. // if the abs isn't a dir, then nothing can match!
  13308. if (!entries)
  13309. return cb()
  13310. // It will only match dot entries if it starts with a dot, or if
  13311. // dot is set. Stuff like @(.foo|.bar) isn't allowed.
  13312. var pn = remain[0];
  13313. var negate = !!this.minimatch.negate;
  13314. var rawGlob = pn._glob;
  13315. var dotOk = this.dot || rawGlob.charAt(0) === '.';
  13316. var matchedEntries = [];
  13317. for (var i = 0; i < entries.length; i++) {
  13318. var e = entries[i];
  13319. if (e.charAt(0) !== '.' || dotOk) {
  13320. var m;
  13321. if (negate && !prefix) {
  13322. m = !e.match(pn);
  13323. } else {
  13324. m = e.match(pn);
  13325. }
  13326. if (m)
  13327. matchedEntries.push(e);
  13328. }
  13329. }
  13330. //console.error('prd2', prefix, entries, remain[0]._glob, matchedEntries)
  13331. var len = matchedEntries.length;
  13332. // If there are no matched entries, then nothing matches.
  13333. if (len === 0)
  13334. return cb()
  13335. // if this is the last remaining pattern bit, then no need for
  13336. // an additional stat *unless* the user has specified mark or
  13337. // stat explicitly. We know they exist, since readdir returned
  13338. // them.
  13339. if (remain.length === 1 && !this.mark && !this.stat) {
  13340. if (!this.matches[index])
  13341. this.matches[index] = Object.create(null);
  13342. for (var i = 0; i < len; i ++) {
  13343. var e = matchedEntries[i];
  13344. if (prefix) {
  13345. if (prefix !== '/')
  13346. e = prefix + '/' + e;
  13347. else
  13348. e = prefix + e;
  13349. }
  13350. if (e.charAt(0) === '/' && !this.nomount) {
  13351. e = path__default['default'].join(this.root, e);
  13352. }
  13353. this._emitMatch(index, e);
  13354. }
  13355. // This was the last one, and no stats were needed
  13356. return cb()
  13357. }
  13358. // now test all matched entries as stand-ins for that part
  13359. // of the pattern.
  13360. remain.shift();
  13361. for (var i = 0; i < len; i ++) {
  13362. var e = matchedEntries[i];
  13363. if (prefix) {
  13364. if (prefix !== '/')
  13365. e = prefix + '/' + e;
  13366. else
  13367. e = prefix + e;
  13368. }
  13369. this._process([e].concat(remain), index, inGlobStar, cb);
  13370. }
  13371. cb();
  13372. };
  13373. Glob.prototype._emitMatch = function (index, e) {
  13374. if (this.aborted)
  13375. return
  13376. if (isIgnored(this, e))
  13377. return
  13378. if (this.paused) {
  13379. this._emitQueue.push([index, e]);
  13380. return
  13381. }
  13382. var abs = pathIsAbsolute(e) ? e : this._makeAbs(e);
  13383. if (this.mark)
  13384. e = this._mark(e);
  13385. if (this.absolute)
  13386. e = abs;
  13387. if (this.matches[index][e])
  13388. return
  13389. if (this.nodir) {
  13390. var c = this.cache[abs];
  13391. if (c === 'DIR' || Array.isArray(c))
  13392. return
  13393. }
  13394. this.matches[index][e] = true;
  13395. var st = this.statCache[abs];
  13396. if (st)
  13397. this.emit('stat', e, st);
  13398. this.emit('match', e);
  13399. };
  13400. Glob.prototype._readdirInGlobStar = function (abs, cb) {
  13401. if (this.aborted)
  13402. return
  13403. // follow all symlinked directories forever
  13404. // just proceed as if this is a non-globstar situation
  13405. if (this.follow)
  13406. return this._readdir(abs, false, cb)
  13407. var lstatkey = 'lstat\0' + abs;
  13408. var self = this;
  13409. var lstatcb = inflight_1(lstatkey, lstatcb_);
  13410. if (lstatcb)
  13411. fs__default['default'].lstat(abs, lstatcb);
  13412. function lstatcb_ (er, lstat) {
  13413. if (er && er.code === 'ENOENT')
  13414. return cb()
  13415. var isSym = lstat && lstat.isSymbolicLink();
  13416. self.symlinks[abs] = isSym;
  13417. // If it's not a symlink or a dir, then it's definitely a regular file.
  13418. // don't bother doing a readdir in that case.
  13419. if (!isSym && lstat && !lstat.isDirectory()) {
  13420. self.cache[abs] = 'FILE';
  13421. cb();
  13422. } else
  13423. self._readdir(abs, false, cb);
  13424. }
  13425. };
  13426. Glob.prototype._readdir = function (abs, inGlobStar, cb) {
  13427. if (this.aborted)
  13428. return
  13429. cb = inflight_1('readdir\0'+abs+'\0'+inGlobStar, cb);
  13430. if (!cb)
  13431. return
  13432. //console.error('RD %j %j', +inGlobStar, abs)
  13433. if (inGlobStar && !ownProp(this.symlinks, abs))
  13434. return this._readdirInGlobStar(abs, cb)
  13435. if (ownProp(this.cache, abs)) {
  13436. var c = this.cache[abs];
  13437. if (!c || c === 'FILE')
  13438. return cb()
  13439. if (Array.isArray(c))
  13440. return cb(null, c)
  13441. }
  13442. fs__default['default'].readdir(abs, readdirCb(this, abs, cb));
  13443. };
  13444. function readdirCb (self, abs, cb) {
  13445. return function (er, entries) {
  13446. if (er)
  13447. self._readdirError(abs, er, cb);
  13448. else
  13449. self._readdirEntries(abs, entries, cb);
  13450. }
  13451. }
  13452. Glob.prototype._readdirEntries = function (abs, entries, cb) {
  13453. if (this.aborted)
  13454. return
  13455. // if we haven't asked to stat everything, then just
  13456. // assume that everything in there exists, so we can avoid
  13457. // having to stat it a second time.
  13458. if (!this.mark && !this.stat) {
  13459. for (var i = 0; i < entries.length; i ++) {
  13460. var e = entries[i];
  13461. if (abs === '/')
  13462. e = abs + e;
  13463. else
  13464. e = abs + '/' + e;
  13465. this.cache[e] = true;
  13466. }
  13467. }
  13468. this.cache[abs] = entries;
  13469. return cb(null, entries)
  13470. };
  13471. Glob.prototype._readdirError = function (f, er, cb) {
  13472. if (this.aborted)
  13473. return
  13474. // handle errors, and cache the information
  13475. switch (er.code) {
  13476. case 'ENOTSUP': // https://github.com/isaacs/node-glob/issues/205
  13477. case 'ENOTDIR': // totally normal. means it *does* exist.
  13478. var abs = this._makeAbs(f);
  13479. this.cache[abs] = 'FILE';
  13480. if (abs === this.cwdAbs) {
  13481. var error = new Error(er.code + ' invalid cwd ' + this.cwd);
  13482. error.path = this.cwd;
  13483. error.code = er.code;
  13484. this.emit('error', error);
  13485. this.abort();
  13486. }
  13487. break
  13488. case 'ENOENT': // not terribly unusual
  13489. case 'ELOOP':
  13490. case 'ENAMETOOLONG':
  13491. case 'UNKNOWN':
  13492. this.cache[this._makeAbs(f)] = false;
  13493. break
  13494. default: // some unusual error. Treat as failure.
  13495. this.cache[this._makeAbs(f)] = false;
  13496. if (this.strict) {
  13497. this.emit('error', er);
  13498. // If the error is handled, then we abort
  13499. // if not, we threw out of here
  13500. this.abort();
  13501. }
  13502. if (!this.silent)
  13503. console.error('glob error', er);
  13504. break
  13505. }
  13506. return cb()
  13507. };
  13508. Glob.prototype._processGlobStar = function (prefix, read, abs, remain, index, inGlobStar, cb) {
  13509. var self = this;
  13510. this._readdir(abs, inGlobStar, function (er, entries) {
  13511. self._processGlobStar2(prefix, read, abs, remain, index, inGlobStar, entries, cb);
  13512. });
  13513. };
  13514. Glob.prototype._processGlobStar2 = function (prefix, read, abs, remain, index, inGlobStar, entries, cb) {
  13515. //console.error('pgs2', prefix, remain[0], entries)
  13516. // no entries means not a dir, so it can never have matches
  13517. // foo.txt/** doesn't match foo.txt
  13518. if (!entries)
  13519. return cb()
  13520. // test without the globstar, and with every child both below
  13521. // and replacing the globstar.
  13522. var remainWithoutGlobStar = remain.slice(1);
  13523. var gspref = prefix ? [ prefix ] : [];
  13524. var noGlobStar = gspref.concat(remainWithoutGlobStar);
  13525. // the noGlobStar pattern exits the inGlobStar state
  13526. this._process(noGlobStar, index, false, cb);
  13527. var isSym = this.symlinks[abs];
  13528. var len = entries.length;
  13529. // If it's a symlink, and we're in a globstar, then stop
  13530. if (isSym && inGlobStar)
  13531. return cb()
  13532. for (var i = 0; i < len; i++) {
  13533. var e = entries[i];
  13534. if (e.charAt(0) === '.' && !this.dot)
  13535. continue
  13536. // these two cases enter the inGlobStar state
  13537. var instead = gspref.concat(entries[i], remainWithoutGlobStar);
  13538. this._process(instead, index, true, cb);
  13539. var below = gspref.concat(entries[i], remain);
  13540. this._process(below, index, true, cb);
  13541. }
  13542. cb();
  13543. };
  13544. Glob.prototype._processSimple = function (prefix, index, cb) {
  13545. // XXX review this. Shouldn't it be doing the mounting etc
  13546. // before doing stat? kinda weird?
  13547. var self = this;
  13548. this._stat(prefix, function (er, exists) {
  13549. self._processSimple2(prefix, index, er, exists, cb);
  13550. });
  13551. };
  13552. Glob.prototype._processSimple2 = function (prefix, index, er, exists, cb) {
  13553. //console.error('ps2', prefix, exists)
  13554. if (!this.matches[index])
  13555. this.matches[index] = Object.create(null);
  13556. // If it doesn't exist, then just mark the lack of results
  13557. if (!exists)
  13558. return cb()
  13559. if (prefix && pathIsAbsolute(prefix) && !this.nomount) {
  13560. var trail = /[\/\\]$/.test(prefix);
  13561. if (prefix.charAt(0) === '/') {
  13562. prefix = path__default['default'].join(this.root, prefix);
  13563. } else {
  13564. prefix = path__default['default'].resolve(this.root, prefix);
  13565. if (trail)
  13566. prefix += '/';
  13567. }
  13568. }
  13569. if (process.platform === 'win32')
  13570. prefix = prefix.replace(/\\/g, '/');
  13571. // Mark this as a match
  13572. this._emitMatch(index, prefix);
  13573. cb();
  13574. };
  13575. // Returns either 'DIR', 'FILE', or false
  13576. Glob.prototype._stat = function (f, cb) {
  13577. var abs = this._makeAbs(f);
  13578. var needDir = f.slice(-1) === '/';
  13579. if (f.length > this.maxLength)
  13580. return cb()
  13581. if (!this.stat && ownProp(this.cache, abs)) {
  13582. var c = this.cache[abs];
  13583. if (Array.isArray(c))
  13584. c = 'DIR';
  13585. // It exists, but maybe not how we need it
  13586. if (!needDir || c === 'DIR')
  13587. return cb(null, c)
  13588. if (needDir && c === 'FILE')
  13589. return cb()
  13590. // otherwise we have to stat, because maybe c=true
  13591. // if we know it exists, but not what it is.
  13592. }
  13593. var stat = this.statCache[abs];
  13594. if (stat !== undefined) {
  13595. if (stat === false)
  13596. return cb(null, stat)
  13597. else {
  13598. var type = stat.isDirectory() ? 'DIR' : 'FILE';
  13599. if (needDir && type === 'FILE')
  13600. return cb()
  13601. else
  13602. return cb(null, type, stat)
  13603. }
  13604. }
  13605. var self = this;
  13606. var statcb = inflight_1('stat\0' + abs, lstatcb_);
  13607. if (statcb)
  13608. fs__default['default'].lstat(abs, statcb);
  13609. function lstatcb_ (er, lstat) {
  13610. if (lstat && lstat.isSymbolicLink()) {
  13611. // If it's a symlink, then treat it as the target, unless
  13612. // the target does not exist, then treat it as a file.
  13613. return fs__default['default'].stat(abs, function (er, stat) {
  13614. if (er)
  13615. self._stat2(f, abs, null, lstat, cb);
  13616. else
  13617. self._stat2(f, abs, er, stat, cb);
  13618. })
  13619. } else {
  13620. self._stat2(f, abs, er, lstat, cb);
  13621. }
  13622. }
  13623. };
  13624. Glob.prototype._stat2 = function (f, abs, er, stat, cb) {
  13625. if (er && (er.code === 'ENOENT' || er.code === 'ENOTDIR')) {
  13626. this.statCache[abs] = false;
  13627. return cb()
  13628. }
  13629. var needDir = f.slice(-1) === '/';
  13630. this.statCache[abs] = stat;
  13631. if (abs.slice(-1) === '/' && stat && !stat.isDirectory())
  13632. return cb(null, false, stat)
  13633. var c = true;
  13634. if (stat)
  13635. c = stat.isDirectory() ? 'DIR' : 'FILE';
  13636. this.cache[abs] = this.cache[abs] || c;
  13637. if (needDir && c === 'FILE')
  13638. return cb()
  13639. return cb(null, c, stat)
  13640. };
  13641. var spawn = childProcess__default['default'].spawn;
  13642. var exec = childProcess__default['default'].exec;
  13643. var treeKill = function (pid, signal, callback) {
  13644. if (typeof signal === 'function' && callback === undefined) {
  13645. callback = signal;
  13646. signal = undefined;
  13647. }
  13648. pid = parseInt(pid);
  13649. if (Number.isNaN(pid)) {
  13650. if (callback) {
  13651. return callback(new Error("pid must be a number"));
  13652. } else {
  13653. throw new Error("pid must be a number");
  13654. }
  13655. }
  13656. var tree = {};
  13657. var pidsToProcess = {};
  13658. tree[pid] = [];
  13659. pidsToProcess[pid] = 1;
  13660. switch (process.platform) {
  13661. case 'win32':
  13662. exec('taskkill /pid ' + pid + ' /T /F', callback);
  13663. break;
  13664. case 'darwin':
  13665. buildProcessTree(pid, tree, pidsToProcess, function (parentPid) {
  13666. return spawn('pgrep', ['-P', parentPid]);
  13667. }, function () {
  13668. killAll(tree, signal, callback);
  13669. });
  13670. break;
  13671. // case 'sunos':
  13672. // buildProcessTreeSunOS(pid, tree, pidsToProcess, function () {
  13673. // killAll(tree, signal, callback);
  13674. // });
  13675. // break;
  13676. default: // Linux
  13677. buildProcessTree(pid, tree, pidsToProcess, function (parentPid) {
  13678. return spawn('ps', ['-o', 'pid', '--no-headers', '--ppid', parentPid]);
  13679. }, function () {
  13680. killAll(tree, signal, callback);
  13681. });
  13682. break;
  13683. }
  13684. };
  13685. function killAll (tree, signal, callback) {
  13686. var killed = {};
  13687. try {
  13688. Object.keys(tree).forEach(function (pid) {
  13689. tree[pid].forEach(function (pidpid) {
  13690. if (!killed[pidpid]) {
  13691. killPid(pidpid, signal);
  13692. killed[pidpid] = 1;
  13693. }
  13694. });
  13695. if (!killed[pid]) {
  13696. killPid(pid, signal);
  13697. killed[pid] = 1;
  13698. }
  13699. });
  13700. } catch (err) {
  13701. if (callback) {
  13702. return callback(err);
  13703. } else {
  13704. throw err;
  13705. }
  13706. }
  13707. if (callback) {
  13708. return callback();
  13709. }
  13710. }
  13711. function killPid(pid, signal) {
  13712. try {
  13713. process.kill(parseInt(pid, 10), signal);
  13714. }
  13715. catch (err) {
  13716. if (err.code !== 'ESRCH') throw err;
  13717. }
  13718. }
  13719. function buildProcessTree (parentPid, tree, pidsToProcess, spawnChildProcessesList, cb) {
  13720. var ps = spawnChildProcessesList(parentPid);
  13721. var allData = '';
  13722. ps.stdout.on('data', function (data) {
  13723. var data = data.toString('ascii');
  13724. allData += data;
  13725. });
  13726. var onClose = function (code) {
  13727. delete pidsToProcess[parentPid];
  13728. if (code != 0) {
  13729. // no more parent processes
  13730. if (Object.keys(pidsToProcess).length == 0) {
  13731. cb();
  13732. }
  13733. return;
  13734. }
  13735. allData.match(/\d+/g).forEach(function (pid) {
  13736. pid = parseInt(pid, 10);
  13737. tree[parentPid].push(pid);
  13738. tree[pid] = [];
  13739. pidsToProcess[pid] = 1;
  13740. buildProcessTree(pid, tree, pidsToProcess, spawnChildProcessesList, cb);
  13741. });
  13742. };
  13743. ps.on('close', onClose);
  13744. }
  13745. var any = bbhverse.any;
  13746. var Tasq = bbhverse.Tasq;
  13747. var statuslog = bbhverse.Traq;
  13748. var Traq = bbhverse.Traq;
  13749. Tasq.addlistener(statuslog.statuslog);
  13750. var nodeShellExec = cliverse.nodeShellExec;
  13751. const BUILD_VERSION = 'Version: 1.0.0 - built on March 24, 2021 22:27:48';
  13752. function getVersion() { return BUILD_VERSION; }
  13753. console.log(getVersion());
  13754. // 'use strict';
  13755. // PB : TODO -- make sure folder context is proper coz we can now run elxr from anywhere.
  13756. // PB : TODO --
  13757. // runas bypass non elevated tasks when we request privelege
  13758. // runas message is always error needs to be fixed.
  13759. // runas wait needs to be parallelized.
  13760. // suppress elevation check error messages
  13761. // support runas lauched directly from shell.
  13762. // pass in environment in hta to shellexecute.
  13763. const { existsSync } = fs__default['default'];
  13764. const fs = fs__default['default'];
  13765. const cliargs = bbhverse.cliargs;
  13766. const processedArgs = cliargs(process.argv.slice(2));
  13767. console.dir(processedArgs);
  13768. var ENV = Object.assign({}, process.env); // Shallow clone it.
  13769. var getShellTask = (command, args, options) => {
  13770. return () => {
  13771. var p = nodeShellExec.apply(null, [command, args, Object.assign({
  13772. inherit: true, shell: true, env: ENV, title: `${command} ${args}`
  13773. }, options)
  13774. ]);
  13775. if (options.ignorefailures) {
  13776. return p.catch(e => {
  13777. // Ignore. Not a major error.
  13778. })
  13779. }
  13780. else return p;
  13781. }
  13782. };
  13783. var callsheltask = (args) => { return () => { return nodeShellExec.apply(null, args) } };
  13784. var getTaskCheckExists = (command, options) => {
  13785. options = options || {};
  13786. return () => {
  13787. var p = nodeShellExec.apply(null, ['where', [command]]);
  13788. if (options.ignorefailures) {
  13789. return p.then(() => { return true }).catch(e => { // Ignore. Not a major error.
  13790. return false;
  13791. })
  13792. }
  13793. else return p.then(() => { return true });
  13794. }
  13795. };
  13796. var getPullCmd = (repo) => {
  13797. // console.log(useGitPull)
  13798. var pullCmd = [gitInstallDir
  13799. , ['-c', 'branch=`git rev-parse --abbrev-ref HEAD`;for i in `git remote`; do git pull $i $branch; done;']
  13800. , { cwd: instanceroot + '/' + repo, title: 'pull all origins for ' + repo }];
  13801. // var pullCmd = ['pullall', [], { cwd : repo }]
  13802. if (useGitPull) pullCmd = ['git', ['pull'], {
  13803. inherit: true, shell: true,
  13804. cwd: instanceroot + '/' + repo
  13805. // , env: process.env
  13806. , runas: processedArgs.runas
  13807. , title: `git pull ${repo}`
  13808. }];
  13809. return pullCmd
  13810. };
  13811. var performPull = (repo) => {
  13812. if (existsSync(instanceroot + '/' + repo)) {
  13813. console.log('pulling ' + instanceroot + '/' + repo);
  13814. return nodeShellExec.apply(null, getPullCmd(repo)).then(() => {
  13815. if (__isElevated) {
  13816. fs.writeFileSync('run.log', ', ' + JSON.stringify({ repo, success: true }), { 'flag': 'a+' });
  13817. }
  13818. else statuslog.statuslog(null, repo);
  13819. return true;
  13820. })
  13821. .catch((e) => {
  13822. e.repo = repo;
  13823. if (__isElevated) {
  13824. fs.writeFileSync('run.log', ', ' + JSON.stringify(e), { 'flag': 'a+' });
  13825. }
  13826. else statuslog.statuslog(e); console.error(e);
  13827. })
  13828. }
  13829. else {
  13830. console.log('cloning ' + repo);
  13831. // PB : TODO -- detect if a clonable repo exists in currentGitAuthUser
  13832. return nodeShellExec('git', ['clone', '-c', 'core.symlinks=true', defaultRepoServer + `/${defaultRepoOwner}/` + repo + '.git'],
  13833. {
  13834. inherit: true, shell: true,
  13835. env: process.env
  13836. , cwd : instanceroot
  13837. , runas: processedArgs.runas
  13838. }).catch((e) => {
  13839. throw e;
  13840. }).then(() => {
  13841. return nodeShellExec('git', ['config', '--replace-all', 'core.symlinks', true],
  13842. {
  13843. inherit: true, shell: true,
  13844. env: process.env
  13845. , cwd: instanceroot + '/' + repo
  13846. , runas: processedArgs.runas
  13847. , title: `git core.symlinks --replace-all true for ${defaultRepoServer + `/${defaultRepoOwner}/` + repo + '.git'}`
  13848. })
  13849. .then(() => {
  13850. if (__isElevated) {
  13851. fs.writeFileSync('run.log', ', ' + JSON.stringify({ repo, success: true }), { 'flag': 'a+' });
  13852. }
  13853. else statuslog.statuslog(null, repo);
  13854. })
  13855. .catch((e) => {
  13856. e.repo = repo;
  13857. if (__isElevated) {
  13858. fs.writeFileSync('run.log', ', ' + JSON.stringify(e), { 'flag': 'a+' });
  13859. }
  13860. else statuslog.statuslog(e);
  13861. })
  13862. })
  13863. .catch(e => {
  13864. e.repo = repo;
  13865. if (__isElevated) {
  13866. fs.writeFileSync('run.log', ', ' + JSON.stringify(e), { 'flag': 'a+' });
  13867. }
  13868. else statuslog.statuslog(e);
  13869. })
  13870. }
  13871. };
  13872. // PB : TODO -- If we are run from an elevated shell it never moves forward and simply exits.
  13873. // -- Currently workaround is to always run from a non-elevated shell.
  13874. var __isElevated = null; // We assume non-Elevated until someone evaluates and sets this variable.
  13875. var acquireElevationState = () => {
  13876. if (__isElevated === null) {
  13877. return nodeShellExec("fsutil", ["dirty", "query", "C:"], {
  13878. inherit: true
  13879. // , shell: true
  13880. , stdio: 'ignore'
  13881. , env: process.env
  13882. , title: `check privileged execution mode using "fsutil dirty query C:"`
  13883. }).then((exitcode) => {
  13884. console.log('Elevated');
  13885. __isElevated = true;
  13886. return true;
  13887. }).catch(() => {
  13888. __isElevated = false;
  13889. console.log('Not Elevated');
  13890. return false;
  13891. });
  13892. }
  13893. else return Promise.resolve(__isElevated);
  13894. };
  13895. var repomanifest = null;
  13896. var defaultRepoOwner = 'chess';
  13897. var elevatedRunasRepos = null;
  13898. var gitRepos = null;
  13899. var defaultRepoServer = null;
  13900. // grep -qxF 'alias elxr="node elxr/index.js"' ~/.bash_profile || echo 'alias elxr="node elxr/index.js"' >> ~/.bash_profile
  13901. // nodeShellExec('echo', ['elxr'], { inherit : true}) //, {stdio: "inherit"}
  13902. var dbForLabel = function (label) {
  13903. var dbsForLabel = {
  13904. devmysql: 'mysql'
  13905. , development: 'mssql'
  13906. , production: 'mssql'
  13907. };
  13908. return dbsForLabel[label] || 'mysql'
  13909. };
  13910. // SAM : TODO Use nodeshellexec where to detect git installation dir
  13911. var gitInstallDir = "C:\\Program Files\\Git\\bin\\sh.exe";
  13912. // var gitInstallDir = "G:\\Installed\\Git\\bin\\sh.exe"
  13913. // Relevant git repos
  13914. // var repomanifest = require('../'+repomanifest.instanceName+'-config-'+ nodeenv +'/repo-manifest')()
  13915. var exludeMergeRepos = [];
  13916. var useGitPull = processedArgs.useGitPull || false;
  13917. // elxr cli operations
  13918. var op = {
  13919. 'h': () => { console.log(elxr.info()); return '-h' }
  13920. , 'undefined': () => { return op.h(); }
  13921. , 'reset': () => {
  13922. // Reset NPM packages semver so major versions can be updated.
  13923. const fs = fs__default['default'];
  13924. const wipeDependencies = (__package) => {
  13925. const file = fs.readFileSync(__package + '/package.json');
  13926. const content = JSON.parse(file);
  13927. for (var devDep in content.devDependencies) {
  13928. if (content.devDependencies[devDep].match(/\W+\d+.\d+.\d+-?((alpha|beta|rc)?.\d+)?/g)) {
  13929. content.devDependencies[devDep] = '*';
  13930. }
  13931. }
  13932. for (var dep in content.dependencies) {
  13933. if (content.dependencies[dep].match(/\W+\d+.\d+.\d+-?((alpha|beta|rc)?.\d+)?/g)) {
  13934. content.dependencies[dep] = '*';
  13935. }
  13936. }
  13937. fs.writeFileSync(__package + '/package.json', JSON.stringify(content));
  13938. };
  13939. var repos = ['client'];
  13940. // repos = gitRepos;
  13941. repos.forEach(wipeDependencies);
  13942. // if (require.main === module) {
  13943. // } else {
  13944. // module.exports = wipeDependencies
  13945. // }
  13946. }
  13947. , 'upgrade': () => {
  13948. console.log('upgrade.......');
  13949. var tasks = [
  13950. () => {
  13951. var p = nodeShellExec('npm', ['i', '-g', 'npm-upgrade'], {
  13952. inherit: true, shell: true
  13953. , env: process.env
  13954. }).catch((e) => { console.error(e); });
  13955. p.position = 1;
  13956. console.log('One');
  13957. return p;
  13958. }
  13959. , () => {
  13960. var p = nodeShellExec('npm', ['cache', 'clean', '-f'], {
  13961. inherit: true, shell: true
  13962. , env: process.env
  13963. }).catch((e) => { console.error(e); });
  13964. p.position = 2;
  13965. console.log('Two');
  13966. return p;
  13967. }
  13968. , () => {
  13969. var p = nodeShellExec('npm', ['install', '-g', 'n'], {
  13970. inherit: true, shell: true
  13971. , env: process.env
  13972. }).catch((e) => { console.error(e); });
  13973. p.position = 3;
  13974. console.log('Three');
  13975. return p;
  13976. }
  13977. , () => {
  13978. var p = nodeShellExec('n', ['latest'], {
  13979. inherit: true, shell: true
  13980. , env: process.env
  13981. }).catch((e) => { console.error(e); });
  13982. p.position = 4;
  13983. console.log('Four');
  13984. return p;
  13985. }
  13986. ];
  13987. any(tasks);
  13988. console.log('.......done');
  13989. console.log('Running exlr upgrade in : ' + path__default['default'].dirname(__dirname));
  13990. console.log('Currently only upgrades ember : ' + path__default['default'].dirname(__dirname));
  13991. console.info('Uninstalling existing ember globally');
  13992. var step1 = nodeShellExec('cmd', ['/c', 'npm', 'uninstall', '-g', 'ember-cli'], {
  13993. stdio: ['pipe', process.stdout, process.stderr],
  13994. inherit: true,
  13995. shell: true,
  13996. cwd: path__default['default'].dirname(__dirname),
  13997. env: env
  13998. });
  13999. step1.on('close', () => {
  14000. console.info('Installing ember globally');
  14001. var step2 = nodeShellExec('cmd', ['/c', 'npm', 'install', '-g', 'ember-cli'], {
  14002. stdio: ['pipe', process.stdout, process.stderr],
  14003. inherit: true,
  14004. shell: true,
  14005. cwd: path__default['default'].dirname(__dirname),
  14006. env: env
  14007. });
  14008. step2.on('close', () => {
  14009. nodeShellExec('cmd', ['/c', 'ember', '--version'], {
  14010. stdio: ['pipe', process.stdout, process.stderr],
  14011. inherit: true,
  14012. shell: true,
  14013. cwd: path__default['default'].dirname(__dirname),
  14014. env: env
  14015. });
  14016. });
  14017. });
  14018. }
  14019. , 'runas': () => {
  14020. console.log('Testing Elevation');
  14021. if (__isElevated) {
  14022. try {
  14023. op[processedArgs.label || processedArgs._[0] || 'h']();
  14024. }
  14025. catch (e) {
  14026. console.error('Error Invalid command : ' + e);
  14027. fs.writeFileSync('run.done', 'error');
  14028. }
  14029. finally {
  14030. }
  14031. }
  14032. else {
  14033. console.log('Requesting Elevated Privileges');
  14034. // Wait for the runas to complete before we read it.
  14035. try {
  14036. fs.unlinkSync('run.done');
  14037. fs.unlinkSync('run.log');
  14038. }
  14039. catch (e) { } //Ignore
  14040. // Find node path to send to hta.
  14041. return nodeShellExec('where', ['node']).then(r => {
  14042. var namedArgs = [];
  14043. console.log('result : ' + JSON.stringify(r));
  14044. Object.keys(processedArgs).forEach((v) => { v != '_' ? namedArgs.push('--' + v + '=' + processedArgs[v]) : null; });
  14045. // PB : TODO -- Convert all the cli args back to string.
  14046. var args = [__dirname + '/windowselevate.hta'].concat(processedArgs._).concat(namedArgs.join(' ')); args.push('--runas=self');
  14047. args.push('--nodepath=' + r[r.length - 1]);
  14048. if (!processedArgs.node_env) args.push('--node_env=' + ENV.NODE_ENV);
  14049. if (processedArgs.debug) args.push('--debug=true'); // Enable to debug elevated..
  14050. return nodeShellExec('MSHTA', [`"${args.join('" "')}"`]
  14051. , {
  14052. inherit: true
  14053. , shell: true
  14054. , env: ENV
  14055. , runas: 'self'
  14056. , title: `runas`
  14057. }
  14058. ).then(() => {
  14059. // runas returned.
  14060. try {
  14061. // PB : TODO -- Log is comma prefixed. Needs to be proper JSON.
  14062. var runaslog = JSON.parse('[ { "success" : true, "result" : "started"}' + fs.readFileSync('run.log', { flags: 'a+' }) + ']');
  14063. runaslog.forEach((logEntry) => {
  14064. statuslog.statuslog(logEntry.success ? null : logEntry, logEntry);
  14065. logEntry.success ? (console.log(['success :' + logEntry.result]), console.log((logEntry.messages || []).join(' '))) : (console.error(['error :' + logEntry.result]), console.error((logEntry.messages || []).join(' ')));
  14066. });
  14067. }
  14068. catch (e) {
  14069. // We must have a runas log
  14070. statuslog.statuslog(e);
  14071. console.error('Run log error probably was not created by runas : ' + e);
  14072. }
  14073. })
  14074. .catch(err => console.error('Elevation failed : ' + err));
  14075. })
  14076. }
  14077. }
  14078. , 'push': () => {
  14079. if (!processedArgs._[1]) { console.error('push all not supported. Specify repo name'); return }
  14080. // init remote bare from local
  14081. // pushandinitremotebare
  14082. // https://www.jeffgeerling.com/blogs/jeff-geerling/push-your-git-repositories
  14083. // connect to repo server -- net use 172.16.0.27
  14084. // cd 172.16.0.27/repos/
  14085. // mkdir repo.git
  14086. // cd repo.git
  14087. // git init --bare
  14088. // cd localrepo
  14089. // git remote rename origin githubclone
  14090. // git remote add origin //172.16.0.27/repos/repo.git
  14091. // git push origin master
  14092. var repo = processedArgs._[1];
  14093. var sequentialTaskShellCommands = [];
  14094. if (!existsSync(`Z:/${repo}.git`)) {
  14095. sequentialTaskShellCommands = [
  14096. // ['net', ['use', 'Z:', defaultRepoServer.replace('/','\\')], {
  14097. // inherit : true, shell: true
  14098. // , env: process.env
  14099. // }]
  14100. ['pwd', { cwd: 'Z:', inherit: true }]
  14101. , ['mkdir', [`${repo}.git`], {
  14102. cwd: `Z:`
  14103. , inherit: true, shell: true
  14104. , env: process.env
  14105. }]
  14106. , ['pwd', { cwd: `Z:/${repo}.git`, inherit: true }]
  14107. , ['git', ['init', '--bare'], {
  14108. cwd: `Z:/${repo}.git`
  14109. , inherit: true, shell: true
  14110. , env: process.env
  14111. }]
  14112. // PB : TODO -- Do this conditionally only...
  14113. , ['git', ['remote', 'rename', 'origin', 'githubclone'], { cwd: `${instanceroot + '/' + repo}` }, (err) => {
  14114. console.log('Ignoring origin rename error : ' + err); return true; //return true to continue.
  14115. }] // PB ; Todo -- new repositories created locally will not have origin. Handle this failure.
  14116. , ['git', ['remote', 'add', 'origin', `${defaultRepoServer}/${repo}.git`], { cwd: `${instanceroot + '/' + repo}` }]
  14117. // PB : TODO -- If threre is a gitbubclone origin
  14118. // Set the master to pull from the local repo.
  14119. ];
  14120. if (!existsSync(`Z:`)) {
  14121. sequentialTaskShellCommands.splice(0, 0, ['net', ['use', 'Z:', defaultRepoServer.replace(/\//gm, '\\')], {
  14122. inherit: true, shell: true
  14123. , env: process.env
  14124. }]);
  14125. console.warn('Adding network drive z: for repo server. ' + sequentialTaskShellCommands[0]);
  14126. // throw 'done'
  14127. }
  14128. }
  14129. sequentialTaskShellCommands.push(['git', ['push', 'origin', 'master'], { cwd: `${instanceroot + '/' + repo}` }]);
  14130. // console.dir(sequentialTaskShellCommands);
  14131. var tasks = [];
  14132. sequentialTaskShellCommands.forEach(shellcmd => {
  14133. // console.log(shellcmd)
  14134. tasks.push(() => {
  14135. var p = nodeShellExec.apply(null, shellcmd.slice(0, 3)).catch((e) => { if (shellcmd[3]) { return shellcmd[3]() } else { console.error(e); } });
  14136. return p;
  14137. });
  14138. });
  14139. any(tasks);
  14140. }
  14141. , 'is-git-repo': (dir) => {
  14142. return nodeShellExec('git', ['-C', dir.name, 'rev-parse'], { stdio: 'ignore' })
  14143. }
  14144. , 'set-url': (remotename, url) => {
  14145. var pushable = processedArgs.pushable || false;
  14146. remotename = remotename || processedArgs._[1];
  14147. url = url || processedArgs._[2];
  14148. var serial_perform_git_seturl = (repo) => {
  14149. // console.log(repo)
  14150. if (pushable) {
  14151. return [
  14152. ['git', ['remote', 'set-url', remotename, url + '/' + repo], { cwd: instanceroot + '/' + repo }]
  14153. ]
  14154. }
  14155. else {
  14156. console.error('not supported for non-pushable');
  14157. }
  14158. };
  14159. var perform_git_seturl = (dir) => {
  14160. op['is-git-repo'](dir).then((code) => {
  14161. any(serial_perform_git_seturl(dir.name).map(x));
  14162. }).catch((e) => {
  14163. // console.log('Failed : ' + dir.name)
  14164. });
  14165. };
  14166. const { readdir } = fs__default['default'].promises;
  14167. const dirs = async (perform, path) => {
  14168. for (const dir of await readdir(path || process.cwd(), { withFileTypes: true })) {
  14169. if (dir.isDirectory()) perform(dir);
  14170. }
  14171. };
  14172. dirs(perform_git_seturl);
  14173. }
  14174. , 'add': (remotename, url, branch) => {
  14175. var pushable = processedArgs.pushable || false;
  14176. remotename = remotename || processedArgs._[1];
  14177. url = url || processedArgs._[2];
  14178. branch = branch || processedArgs._[3];
  14179. var serial_perform_git_add = (repo) => {
  14180. // console.log(repo)
  14181. if (pushable) {
  14182. return [
  14183. ['git', ['remote', 'add', remotename, url + '/' + repo], { cwd: instanceroot + '/' + repo }]
  14184. , ['git', ['pull', remotename, branch], { cwd: instanceroot + '/' + repo }]
  14185. , ['git', ['branch', `--set-upstream-to=${remotename}/${branch}`, branch], { cwd: instanceroot + '/' + repo }]
  14186. ]
  14187. }
  14188. else {
  14189. return [
  14190. ['git', ['remote', 'add', remotename, url + '/' + repo], { cwd: instanceroot + '/' + repo }]
  14191. , ['git', ['remote', `set-url`, '--push', remotename, 'no-pushing'], { cwd: instanceroot + '/' + repo }]
  14192. , ['git', ['pull', remotename, branch], { cwd: instanceroot + '/' + repo }]
  14193. , ['git', ['branch', `--set-upstream-to=${remotename}/${branch}`, branch], { cwd: instanceroot + '/' + repo }]
  14194. ]
  14195. }
  14196. };
  14197. var x = (args) => {
  14198. return () => {
  14199. // console.log(args)
  14200. return nodeShellExec.apply(null, args)
  14201. }
  14202. // return Promise.resolve(true)
  14203. };
  14204. var perform_git_add = (dir) => {
  14205. op['is-git-repo'](dir).then((code) => {
  14206. // console.log(code)
  14207. if (code) {
  14208. nodeShellExec('git', ['remote', 'get-url', remotename], { cwd: dir.name, stdio: 'ignore' }).then(() => {
  14209. console.log('skipped : ' + dir.name + ', reason : A remote with same name already exists.');
  14210. })
  14211. .catch((e) => {
  14212. any(serial_perform_git_add(dir.name).map(x));
  14213. });
  14214. }
  14215. // else console.log('Skipped : Not a Git Repo : ' + dir.name)
  14216. }).catch((e) => {
  14217. // console.log('Failed : ' + dir.name)
  14218. });
  14219. };
  14220. const { readdir } = fs__default['default'].promises;
  14221. const dirs = async (perform, path) => {
  14222. for (const dir of await readdir(path || process.cwd(), { withFileTypes: true })) {
  14223. if (dir.isDirectory()) perform(dir);
  14224. }
  14225. };
  14226. dirs(perform_git_add);
  14227. }
  14228. , 'remove': (remotename) => {
  14229. remotename = remotename || processedArgs._[1];
  14230. var serial_perform_git_remove = (repo) => {
  14231. // console.log(repo)
  14232. return [
  14233. ['git', ['remote', 'remove', remotename], { cwd: instanceroot + '/' + repo }]
  14234. ]
  14235. };
  14236. var x = (args) => {
  14237. return () => {
  14238. // console.log(args)
  14239. return nodeShellExec.apply(null, args)
  14240. }
  14241. // return Promise.resolve(true)
  14242. };
  14243. var perform_git_remove = (dir) => {
  14244. op['is-git-repo'](dir).then((code) => {
  14245. // console.log(code)
  14246. if (code) {
  14247. nodeShellExec('git', ['remote', 'get-url', remotename], { cwd: dir.name, stdio: 'ignore' }).then(() => {
  14248. any(serial_perform_git_remove(dir.name).map(x));
  14249. })
  14250. .catch((e) => {
  14251. console.log('skipped : ' + dir.name + ', reason : No remote named origin');
  14252. });
  14253. }
  14254. // else console.log('Skipped : Not a Git Repo : ' + dir.name)
  14255. }).catch((e) => {
  14256. // console.log('Failed : ' + dir.name)
  14257. });
  14258. };
  14259. const { readdir } = fs__default['default'].promises;
  14260. const dirs = async (perform, path) => {
  14261. for (const dir of await readdir(path || process.cwd(), { withFileTypes: true })) {
  14262. if (dir.isDirectory()) perform(dir);
  14263. }
  14264. };
  14265. dirs(perform_git_remove);
  14266. }
  14267. , 'init-gitea': (user) => {
  14268. user = user || processedArgs._[1];
  14269. if (!user) throw 'User name required'
  14270. var serial_perform_init_gitea = (repo) => {
  14271. // console.log(repo)
  14272. return [
  14273. ['git', ['remote', 'add', 'chess', `${defaultRepoServer}/${user}/${repo}.git`], { cwd: instanceroot + '/' + repo }]
  14274. , ['git', ['remote', 'set-url', '--push', 'chess', 'no-pushing'], { cwd: instanceroot + '/' + repo }]
  14275. , ['git', ['remote', 'set-url', 'origin', `${defaultRepoServer}/${user}/${repo}.git`], { cwd: instanceroot + '/' + repo }]
  14276. ]
  14277. };
  14278. var x = (args) => {
  14279. return () => {
  14280. // console.log(args)
  14281. return nodeShellExec.apply(null, args)
  14282. }
  14283. // return Promise.resolve(true)
  14284. };
  14285. var perform_init_gitea = (dir) => {
  14286. op['is-git-repo'](dir).then((code) => {
  14287. // console.log(code)
  14288. if (code) {
  14289. nodeShellExec('git', ['remote', 'get-url', 'chess'], { cwd: dir.name, stdio: 'ignore' }).then(() => {
  14290. console.log('skipped : ' + dir.name + ', reason : Already has remote chess ');
  14291. })
  14292. .catch((e) => {
  14293. any(serial_perform_init_gitea(dir.name).map(x));
  14294. });
  14295. }
  14296. // else console.log('Skipped : Not a Git Repo : ' + dir.name)
  14297. }).catch((e) => {
  14298. // console.log('Failed : ' + dir.name)
  14299. });
  14300. };
  14301. const { readdir } = fs__default['default'].promises;
  14302. const dirs = async (perform, path) => {
  14303. for (const dir of await readdir(path || process.cwd(), { withFileTypes: true })) {
  14304. if (dir.isDirectory()) perform(dir);
  14305. }
  14306. };
  14307. dirs(perform_init_gitea);
  14308. }
  14309. , 'syncmaster': (label) => {
  14310. // Usage :
  14311. // elxr pull -- Defaults to run config
  14312. Object.assign({}, process.env); // Shallow clone it.
  14313. // console.dir(env)
  14314. console.log('Running exlr pull : ' + path__default['default'].dirname(__dirname));
  14315. if (!processedArgs.runas) gitRepos.forEach(performPull);
  14316. if (__isElevated) {
  14317. return any(elevatedRunasRepos.map((repo) => performPull(repo))).then(() => {
  14318. fs.writeFileSync('run.done', 'success');
  14319. }).catch(() => {
  14320. fs.writeFileSync('run.done', 'error');
  14321. })
  14322. }
  14323. else return op['runas']()
  14324. }
  14325. , 'pull': (label) => {
  14326. // Usage :
  14327. // elxr pull -- Defaults to run config
  14328. Object.assign({}, process.env); // Shallow clone it.
  14329. console.log('Running exlr pull : ' + path__default['default'].dirname(__dirname));
  14330. processedArgs.useGitPull || false;
  14331. if (__isElevated) {
  14332. return any(elevatedRunasRepos.map((repo) => performPull(repo))).then(() => {
  14333. fs.writeFileSync('run.done', 'success');
  14334. return true;
  14335. }).catch(() => {
  14336. fs.writeFileSync('run.done', 'error');
  14337. })
  14338. }
  14339. else {
  14340. // PB : TODO -- Rename op['runas'] to 'elevate'
  14341. return op['runas']().then(() => { return true; })
  14342. .catch((e) => {
  14343. console.error(e);
  14344. })
  14345. .finally(() => {
  14346. if (!processedArgs.runas) {
  14347. var pendingpulls = [];
  14348. gitRepos.forEach((r) => { pendingpulls.push(performPull(r)); });
  14349. return Promise.all(pendingpulls).then(results => {
  14350. return true;
  14351. }).finally(Traq.finally)
  14352. }
  14353. })
  14354. }
  14355. }
  14356. , 'isInstalled': () => {
  14357. return nodeShellExec('where', [processedArgs._[1]], { inherit: true }).then(() => {
  14358. console.log(processedArgs._[1] + ' exists.');
  14359. return true;
  14360. });
  14361. }
  14362. , 'i': () => {
  14363. var tasks = [];
  14364. tasks.push(op['pull']);
  14365. tasks.push(getShellTask.apply(null, ['rm', [instanceroot + '/run.js'], { ignorefailures: true }]));
  14366. tasks.push(op['use']);
  14367. if (!__isElevated) {
  14368. tasks.push(op['npmi']);
  14369. }
  14370. // var tasksdefs = [
  14371. // ['elxr', ['pull']]
  14372. // , ['elxr', ['use', 'elixir']]
  14373. // , ['elxr', ['npmi']]
  14374. // ]
  14375. // tasksdefs.forEach(tasksdef=>{
  14376. // tasks.push( ()=> nodeShellExec.apply(null, tasksdef) )
  14377. // })
  14378. return any(tasks);
  14379. }
  14380. , 'npmi': () => {
  14381. var tasks = [];
  14382. var npmbuildrepos = ['loopback-jsonapi-model-serializer'];
  14383. npmbuildrepos.forEach(repo => {
  14384. tasks.push(() => {
  14385. return nodeShellExec('npm', ['i --force'], {
  14386. inherit: true, shell: true
  14387. , cwd: instanceroot + '/' + repo
  14388. , env: process.env
  14389. , title: `npm i for ${repo}`
  14390. }).catch((e) => {
  14391. console.error('Ignoring Benign Error'); console.error(e);
  14392. }).then(() => {
  14393. console.log(`--------------------npm run build for ${repo}--------------------`);
  14394. return nodeShellExec('npm', ['run build'], {
  14395. inherit: true, shell: true
  14396. , cwd: instanceroot + '/' + repo
  14397. , env: process.env
  14398. , title: `npm run build for ${repo}`
  14399. }).then(Tasq.then).catch(Tasq.catch)
  14400. })
  14401. });
  14402. });
  14403. any(tasks).then(() => {
  14404. gitRepos.push('client/server');
  14405. gitRepos = gitRepos.concat(elevatedRunasRepos);
  14406. var rmtasks = [];
  14407. var repotasks = [];
  14408. gitRepos.forEach(repo => {
  14409. rmtasks.push(() => {
  14410. console.log(`--------------------rm package-lock.json for ${repo}--------------------`);
  14411. return nodeShellExec('rm', ['package-lock.json'], {
  14412. inherit: true, shell: true
  14413. , cwd: instanceroot + '/' + repo
  14414. , env: process.env
  14415. , title: `rm 'package-lock.json' for ${repo}`
  14416. }).catch((e) => { console.error(e); })
  14417. });
  14418. if (npmbuildrepos.indexOf(repo) < 0) {
  14419. repotasks.push(
  14420. () => {
  14421. console.log(`--------------------npm i for ${repo}--------------------`);
  14422. var p = nodeShellExec('npm', ['i --force'], {
  14423. inherit: true, shell: true
  14424. , cwd: instanceroot + '/' + repo
  14425. , env: process.env
  14426. , title: `npm i for ${repo}`
  14427. }).then(Tasq.then).catch(Tasq.catch);
  14428. return p;
  14429. });
  14430. }
  14431. });
  14432. var bowerRepos = ['client'];
  14433. bowerRepos.forEach(repo => {
  14434. repotasks.push(() => {
  14435. var p = nodeShellExec('bower', ['install'], {
  14436. inherit: true, shell: true
  14437. , cwd: instanceroot + '/' + repo
  14438. , env: process.env
  14439. , title: `bower i for ${repo}`
  14440. }).then(Tasq.then).catch(Tasq.catch);
  14441. return p;
  14442. });
  14443. });
  14444. return Promise.all(rmtasks).then(() => any(repotasks));
  14445. }).catch(e => {
  14446. }).finally(statuslog.finally);
  14447. }
  14448. , 'start': (label) => {
  14449. console.log('Starting Elixir Server.');
  14450. var env = Object.assign({}, process.env); // Shallow clone it.
  14451. // console.dir(env)
  14452. env.NODE_ENV = process.env.NODE_ENV || 'development';
  14453. env.DEBUG = 'loopback:connector:' + dbForLabel(label);
  14454. var cmd = env.NODE_ENV === 'development' ? 'nodemon' : 'node';
  14455. // cmd = 'node'
  14456. cmd = [cmd, ['--inspect=9228', 'elixir/server.js']];
  14457. var childPromise = nodeShellExec(...cmd, {
  14458. // inherit : true,
  14459. shell: true,
  14460. detached: true,
  14461. stdio: 'ignore',
  14462. cwd: instanceroot + '/' + 'elixir-server'
  14463. , env: env
  14464. });
  14465. var child = childPromise.process;
  14466. if (typeof child.pid !== 'undefined') {
  14467. console.log(`started Elixir Server PID(${child.pid}) : NODE_ENV=${process.NODE_ENV} ${cmd}`);
  14468. fs.writeFileSync('.elixir-server.elixir.server.pid', child.pid, {
  14469. encoding: 'utf8'
  14470. });
  14471. }
  14472. // nodeShellExec('node', ['--inspect=9226', ' bin/www'], {
  14473. // inherit : true,
  14474. // shell: true, detached: true,
  14475. // cwd : 'qms/server',
  14476. // env: env,
  14477. // shell : true
  14478. // })
  14479. // nodeShellExec('ember', ['s'], {
  14480. // // inherit : true,
  14481. // shell: true, detached: true,
  14482. // cwd : 'client/',
  14483. // env: env
  14484. // })
  14485. console.log('Starting Elixir Client Host.');
  14486. var cmd = ['ember', ['s']];
  14487. var childPromise = nodeShellExec(...cmd, {
  14488. // var childPromise = nodeShellExec('node', ['--inspect=9227', './node_modules/.bin/ember', 's'], {
  14489. // PB : TODO -- ember debugging.
  14490. // inherit : true,
  14491. shell: true,
  14492. detached: true,
  14493. stdio: 'ignore',
  14494. cwd: instanceroot + '/' + 'client'
  14495. , env: env
  14496. });
  14497. // .catch(e=>console.error(e))
  14498. child = childPromise.process;
  14499. if (typeof child.pid !== 'undefined') {
  14500. console.log(`started Elixir Client Host PID(${child.pid}) : NODE_ENV=${process.NODE_ENV} ${cmd}`);
  14501. fs.writeFileSync('.client.server.pid', child.pid, {
  14502. encoding: 'utf8'
  14503. });
  14504. }
  14505. }
  14506. , 'stop': (label) => {
  14507. const kill = treeKill;
  14508. var serverPid = fs.readFileSync('.elixir-server.elixir.server.pid', {
  14509. encoding: 'utf8'
  14510. });
  14511. fs.unlinkSync('.elixir-server.elixir.server.pid');
  14512. console.log(serverPid);
  14513. kill(serverPid);
  14514. serverPid = fs.readFileSync('.client.server.pid', {
  14515. encoding: 'utf8'
  14516. });
  14517. fs.unlinkSync('.client.server.pid');
  14518. console.log(serverPid);
  14519. kill(serverPid);
  14520. }
  14521. , 'use': () => {
  14522. // use a certain named instance.
  14523. // Eg :
  14524. // 1) elxr use elixir
  14525. // 2) elxr use cihsr
  14526. // If environment is not specified defaults to development.
  14527. // 1) NODE=test elxr use elixir
  14528. /*// Steps
  14529. 1) Delete Config and Data symlinks
  14530. 2) Make Links for config ({{name}}-config-{{node_env}}) and data with the NODE_ENV specified or default to dev
  14531. 3) Iterates all repos and pull all. 'git', ['pull', '--all'].
  14532. 4) Iterates all repos and checkout to the ENV specified. 'git', ['checkout', checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV]
  14533. 5) Iterates all repos and merge from source configured in mergeSource. 'git', ['merge', mergeSource],
  14534. */
  14535. var runconfig = { NODE_ENV: repomanifest.node_env };
  14536. try { runconfig = Object.assign(runconfig, commonjsRequire(instanceroot + '/run.js',"/$$rollup_base$$")); } catch (e) { }
  14537. if ((!processedArgs.runas || processedArgs.runas !== 'self') &&
  14538. runconfig.NODE_ENV && runconfig.NODE_ENV === (repomanifest.node_env || runconfig.NODE_ENV) &&
  14539. repomanifest.instanceName && runconfig.use === repomanifest.instanceName) {
  14540. console.log(`No change detected. Already using requested specs : ${runconfig.NODE_ENV} ${runconfig.use}`);
  14541. if (processedArgs.runas) { fs.writeFileSync('run.done', 'success'); }
  14542. return
  14543. }
  14544. var tasks = [
  14545. () => {
  14546. if (existsSync('config')) {
  14547. var p = nodeShellExec('rmdir', ['config'], { inherit: true, shell: true, env: process.env }
  14548. ).catch((err) => { console.log('Ignoring benign error : ' + err); return true; });
  14549. return p;
  14550. }
  14551. else return Promise.resolve(true);
  14552. },
  14553. () => {
  14554. if (existsSync('data')) {
  14555. var p = nodeShellExec('rmdir', ['data'], { inherit: true, shell: true, env: process.env }
  14556. ).catch((err) => { console.log('Ignoring benign error : ' + err); return true; });
  14557. return p;
  14558. }
  14559. else return Promise.resolve(true);
  14560. },
  14561. ];
  14562. runconfig.NODE_ENV = process.env.NODE_ENV = process.env.NODE_ENV || runconfig.NODE_ENV || 'development';
  14563. if (processedArgs._[1] && runconfig.use !== processedArgs._[1]) runconfig.use = processedArgs._[1];
  14564. if (!runconfig.use) { throw 'unspecifed use not allowed. Please specify chess instance name.' }
  14565. // console.log(process.env.cwd)
  14566. fs.writeFileSync(instanceroot + '/run.js', 'module.exports = ' + JSON.stringify(runconfig));
  14567. // Maps an environment to a branch. Not required if the branch is appropriately named.
  14568. var checkoutMap = { 'development': 'master' };
  14569. // cant use git checkout -b it fails with branch already exists.
  14570. var performCheckout = (repo, branch) => {
  14571. if (!branch) return Promise.resolve({ 'skipped': true })
  14572. if (excludeCheckouts[repo]) return Promise.resolve({ 'skipped': true })
  14573. return nodeShellExec('git', ['checkout', branch || checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV], {
  14574. // return nodeShellExec('git', ['switch', '-m', '-C', checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV], {
  14575. // inherit : true, shell: true,
  14576. cwd: repoinstanceroot + '/' + repo
  14577. // , stdio : ignore // Use when we want to silcence output completely.
  14578. , runas: processedArgs.runas
  14579. , title: `git checkout ${branch || checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV} for ${repo}`
  14580. }).catch((e) => { console.error(e); return { error: true, message: repo } })
  14581. };
  14582. if (runconfig.NODE_ENV === 'development') performCheckout = () => { return Promise.resolve(true) };
  14583. var performPullAll = (repo) => {
  14584. if (excludeCheckouts[repo]) return Promise.resolve({ 'skipped': true })
  14585. return nodeShellExec('git', ['pull', '--all'], {
  14586. // inherit : true, shell: true,
  14587. cwd: instanceroot + '/' + repo
  14588. , runas: processedArgs.runas
  14589. , title: `git pull -all for ${checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV} ${repo}`
  14590. }).catch((e) => { console.error(e); return { error: true, message: repo } })
  14591. };
  14592. var mergeSources = {
  14593. 'development': null,
  14594. 'test': 'master',
  14595. 'production': 'master'
  14596. };
  14597. var excludeCheckouts = Object.assign(exludeMergeRepos);
  14598. delete excludeCheckouts[`elixir-config-${runconfig.NODE_ENV}`];
  14599. delete excludeCheckouts[`cihsr-config-${runconfig.NODE_ENV}`];
  14600. var mergeSource = mergeSources[checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV];
  14601. var performMerge = (repo) => {
  14602. if (exludeMergeRepos[repo]) return Promise.resolve({ 'skipped': true })
  14603. return nodeShellExec('git', ['merge', mergeSource], {
  14604. inherit: true, shell: true,
  14605. cwd: instanceroot + '/' + repo
  14606. , runas: processedArgs.runas
  14607. }).catch((e) => { console.error(e); })
  14608. };
  14609. if (runconfig.NODE_ENV === 'development') performMerge = () => { return Promise.resolve(true) };
  14610. any(tasks).then(() => {
  14611. if (!processedArgs.runas) return op['runas']()
  14612. tasks = [
  14613. () => {
  14614. // Use junctions to avoid npm package issues
  14615. var p = nodeShellExec('mklink', ['/J', 'config', runconfig.use + '-config' + '-' + process.env.NODE_ENV], {
  14616. inherit: true, shell: true
  14617. , env: process.env
  14618. }).catch((e) => { console.error(e); });
  14619. return p;
  14620. }
  14621. ];
  14622. if (processedArgs._[1]) {
  14623. tasks = tasks.concat(
  14624. [
  14625. () => {
  14626. var p = nodeShellExec('mklink', ['/J', 'data', runconfig.use + '-data'], {
  14627. inherit: true, shell: true
  14628. , env: process.env
  14629. }).catch((e) => { console.error(e); });
  14630. return p;
  14631. }
  14632. ]
  14633. );
  14634. }
  14635. return any(tasks)
  14636. //target is the env is we specify in elxr use command. Default is dev
  14637. .then( //Switch to target branch
  14638. () => any([any(gitRepos.map((repo) => performCheckout(repo, process.env.NODE_ENV || 'development')))
  14639. , any(elevatedRunasRepos.map((repo) => performCheckout(repo, process.env.NODE_ENV || 'development')))]))
  14640. .then( //PULL from target branch
  14641. () => any([any(gitRepos.map((repo) => performPullAll(repo))), any(elevatedRunasRepos.map((repo) => performPullAll(repo)))]))
  14642. .then( //Switch to merge source branch
  14643. () => any([any(gitRepos.map((repo) => performCheckout(repo, mergeSources[process.env.NODE_ENV || 'development'])))
  14644. , any(elevatedRunasRepos.map((repo) => performCheckout(repo, mergeSources[process.env.NODE_ENV || 'development'])))]))
  14645. .then( //Pull on merge source branch
  14646. () => any([any(gitRepos.map((repo) => performPullAll(repo))), any(elevatedRunasRepos.map((repo) => performPullAll(repo)))]))
  14647. .then( //Switch to target branch
  14648. () => any([any(gitRepos.map((repo) => performCheckout(repo, process.env.NODE_ENV || 'development')))
  14649. , any(elevatedRunasRepos.map((repo) => performCheckout(repo, process.env.NODE_ENV || 'development')))]))
  14650. .then( //Merge source branch to target branch
  14651. () => any([any(gitRepos.map((repo) => performMerge(repo))).catch(err => { console.error('error in performMerge ' + err); }),
  14652. any(elevatedRunasRepos.map((repo) => performMerge(repo))).catch(err => { console.error('error in performMerge ' + err); })]))
  14653. .then(() => {
  14654. // Move test config from dev.
  14655. // if(process.env.NODE_ENV === 'test'){
  14656. // var devcfgreponame = runconfig.use + '-config' + '-development';
  14657. // var testcfgreponame = runconfig.use + '-config' + '-test';
  14658. // var testcfgdir = path.dirname(__dirname) + '/' + testcfgreponame + '/'
  14659. // var devcfgdir = path.dirname(__dirname) + '/' + devcfgreponame + '/' //eg (elxr/../elixir-config.development)
  14660. // return any([
  14661. // ()=>{
  14662. // return nodeShellExec('git', ['checkout', 'test'], {
  14663. // inherit : true, shell: true,
  14664. // cwd : testcfgdir
  14665. // // , env: process.env
  14666. // , runas : processedArgs.runas
  14667. // , title : `git checkout test for ${testcfgreponame}`
  14668. // }).catch((e)=>{ console.error(e) })
  14669. // }
  14670. // , ()=> {
  14671. // return nodeShellExec('git', ['checkout', 'master'], {
  14672. // inherit : true, shell: true,
  14673. // cwd : devcfgdir
  14674. // // , env: process.env
  14675. // , runas : processedArgs.runas
  14676. // , title : `git checkout master for ${devcfgreponame}`
  14677. // }).catch((e)=>{ console.error(e) })
  14678. // }
  14679. // , ()=> {
  14680. // globSync( '**/*.test.js', {cwd : devcfgdir}).map((filename) => {
  14681. // console.log('File found : ' + devcfgdir + filename)
  14682. // fs.copyFileSync(devcfgdir + filename, testcfgdir+ filename);
  14683. // })
  14684. // return nodeShellExec('git', ['checkout', 'test'], {
  14685. // inherit : true, shell: true,
  14686. // cwd : devcfgdir
  14687. // // , env: process.env
  14688. // , runas : processedArgs.runas
  14689. // , title : `git checkout test for ${devcfgreponame}`
  14690. // }).catch((e)=>{ console.error(e) })
  14691. // }
  14692. // ])
  14693. // }
  14694. // else {
  14695. return Promise.resolve(true)
  14696. // }
  14697. })
  14698. .then(() => {
  14699. fs.writeFileSync('run.done', 'success');
  14700. }).catch(() => {
  14701. fs.writeFileSync('run.done', 'error');
  14702. })
  14703. }).catch(() => {
  14704. fs.writeFileSync('run.done', 'error');
  14705. });
  14706. // Antibiotic stewardship program.
  14707. // 1st use is fine.
  14708. // Max vials dispense
  14709. // 2nd use Pharmacy needs justification Form.
  14710. // Approval after a certain period of time.
  14711. }
  14712. , 'g': () => {
  14713. if (processedArgs.h) {
  14714. console.log('elxr g [modelname] => generate a model named [modelname]');
  14715. console.log('elxr g => regenerate all known models');
  14716. return
  14717. }
  14718. // nodeShellExec('npm', ['init', '-y'], options);
  14719. // nodeShellExec('npm', ['init', '-y'], options);
  14720. // })
  14721. var g = {
  14722. 'client': () => {
  14723. console.info('Creating new ember client named : ' + processedArgs._[2]);
  14724. nodeShellExec('cmd', ['/c', 'ember', 'new', processedArgs._[2]], {
  14725. stdio: ['pipe', process.stdout, process.stderr],
  14726. inherit: true,
  14727. shell: true,
  14728. cwd: path__default['default'].dirname(__dirname),
  14729. env: env
  14730. });
  14731. },
  14732. 'modelr': () => {
  14733. var tasks = [
  14734. () => {
  14735. var p = nodeShellExec('"ember"', [
  14736. 'g'
  14737. , 'modelr'
  14738. , processedArgs._[2]], {
  14739. inherit: true, shell: true, env: process.env
  14740. }).then(() => {
  14741. console.log('Blueprint generation complete for : ' + processedArgs._[2]);
  14742. return true;
  14743. }).catch((e) => { console.error(e); });
  14744. return p;
  14745. },
  14746. () => {
  14747. var chromePrefsFile = "C:\\chess\\instances\\elixir_01\\data\\Google\\Chrome\\User Data\\chess\\Preferences";
  14748. var chromeprefs = fs.readFileSync(chromePrefsFile, { encoding: 'utf8' });
  14749. chromeprefs = JSON.parse(chromeprefs);
  14750. var previous = chromeprefs.download.default_directory;
  14751. var parentDir = path__default['default'].dirname(__dirname);
  14752. chromeprefs.download.default_directory = parentDir + "\\client\\app\\templates\\components\\resource";
  14753. fs.writeFileSync(chromePrefsFile, JSON.stringify(chromeprefs));
  14754. // PB : TODO -- detect where chrome is installed.
  14755. // PB : TODO -- set the download dir to the place where files are needed.
  14756. var p = nodeShellExec('"C:/Program Files (x86)/Google/Chrome/Application/chrome.exe"', [
  14757. '--user-data-dir="C:\\chess\\instances\\elixir_01\\data\\Google\\Chrome\\User Data"'
  14758. , '--profile-directory="chess"'
  14759. , 'http://localhost:4200/admin/crud/create/' + processedArgs._[2]], {
  14760. inherit: true, shell: true
  14761. , env: process.env
  14762. }).then(() => {
  14763. chromeprefs.download.default_directory = previous;
  14764. fs.writeFileSync(chromePrefsFile, JSON.stringify(chromeprefs));
  14765. return true;
  14766. }).catch((e) => { console.error(e); });
  14767. return p;
  14768. }
  14769. ,
  14770. () => {
  14771. console.log('Browser process should have closed here....');
  14772. return true;
  14773. }
  14774. ];
  14775. any(tasks);
  14776. }
  14777. };
  14778. g[processedArgs._[1]]();
  14779. }
  14780. };
  14781. var cliname = 'elxr';
  14782. var ver = '1.1';
  14783. var help = `# list of commands... please refer dveloper documentation for ${cliname}
  14784. ${
  14785. // util.inspect(
  14786. [Object.keys(op)]
  14787. // )
  14788. }
  14789. `;
  14790. var elxr = {
  14791. help() {
  14792. return source.cyanBright(`
  14793. -------------------------------------------------------------------------------
  14794. *** BBH Elixir ***
  14795. -------------------------------------------------------------------------------
  14796. elxr ${ver}
  14797. A cli tool for chess
  14798. ${help}
  14799. -------------------------------------------------------------------------------
  14800. `)
  14801. }
  14802. , info() {
  14803. return source.cyanBright(`
  14804. -------------------------------------------------------------------------------
  14805. *** BBH Elixir ***
  14806. -------------------------------------------------------------------------------
  14807. elxr ${ver}
  14808. A cli tool for chess
  14809. -------------------------------------------------------------------------------
  14810. `)
  14811. }
  14812. };
  14813. // The main elxr cli process
  14814. function elxrworker(hasconfig) {
  14815. // Everything runs after this check is completed. Elevation occurs out of process when needed.
  14816. gitRepos = repomanifest.repos;
  14817. // Repositiories that have symlinks that require elevated priviletes in windows to create symlinks
  14818. elevatedRunasRepos = repomanifest.elevated;
  14819. // Repos that should excluded from merge for releases...
  14820. exludeMergeRepos = repomanifest.exludeMergeRepos;
  14821. Object.assign({}, process.env); // Shallow clone it.
  14822. var __runcmd = function (label) {
  14823. return op[label] ? op[label]() : null;
  14824. };
  14825. // --runas
  14826. if (processedArgs.runas) {
  14827. // Weve been asked to run in priviledged mode. Check if we already are privileged.
  14828. return __runcmd('runas')
  14829. }
  14830. else return __runcmd(processedArgs.label || processedArgs._[0] || 'h');
  14831. }
  14832. var getManifest = function () {
  14833. // Once choices are made we need to load config according to those choices.
  14834. // No trace of a previous run...
  14835. // Default Config...
  14836. return repomanifest = selectedinstance;
  14837. };
  14838. function acquireChoices(selectedinstance) {
  14839. console.warn(source.yellow(`
  14840. -------------------------------------------------------------------------------
  14841. Warning : Cannot locate your preferred configuration since it was not specified
  14842. You should fork the default chess configuration to customize and make it
  14843. your own instance with a named config as
  14844. {{yourowninstancename}}-config-{{yourcurrentenvironment}}
  14845. And then run this tool as follows
  14846. NODE_ENV={{yourenvironment}} elxr i {{yourowninstancename}}
  14847. OR
  14848. Run this tool with the following command to use a quick start default.
  14849. node elxr --default
  14850. OR
  14851. Choose the the option to create a new instance for you interactively.
  14852. We will run your choice of default or create your own at the next prompt.
  14853. -------------------------------------------------------------------------------
  14854. `));
  14855. var prompt = cliverse.prompt;
  14856. return prompt.ask(`Choose an option :
  14857. d) Install the default chess instance.
  14858. => elxr i chess node_env=development --default
  14859. n) Create your custom new instance interactively
  14860. => elxr i {{instanceName}} node_env={{environment}}
  14861. i) Choose an instance and environment to install
  14862. => elxr i {{instanceName}} node_env={{environment}}
  14863. c) Choose a command to run ( pull, use, i, npmi ... ) <= pull
  14864. => elxr {{cmd}} {{instanceName}} node_env={{environment}}
  14865. h) Help
  14866. q) Quit
  14867. Default <= d
  14868. : `).then((choice) => {
  14869. prompt.close();
  14870. if (choice && choice === 'd' || !choice) {
  14871. processedArgs._[0] = 'i';
  14872. selectedinstance.instanceName = processedArgs._[1] = processedArgs._[1] || 'chess';
  14873. selectedinstance.node_env = processedArgs.node_env = (process.env.NODE_ENV && process.env.NODE_ENV.trim()) || processedArgs.node_env || 'development';
  14874. defaultRepoServer = 'https://git.bbh.org.in';
  14875. getManifest(); // PB : TODO -- acquire the manifest directly from http url instead of clone before cloning the config. Since
  14876. // This is because the manifest at any server location can redirect to the preferred server..
  14877. }
  14878. else if (choice === 'h') {
  14879. processedArgs._[0] = 'h';
  14880. fs.writeFileSync('run.done', 'noop help');
  14881. console.log(elxr.help()); process.exit();
  14882. }
  14883. else if (choice === 'n' || choice === 'i') {
  14884. var p1 = cliverse.prompt;
  14885. return p1.ask(`Enter Instance Name ( <= ${selectedinstance.instanceName} ) : `).then(function (instanceName) {
  14886. processedArgs._[0] = 'i';
  14887. selectedinstance.instanceName = processedArgs._[1] = instanceName || selectedinstance.instanceName;
  14888. return p1.ask(`Enter Environment ( <= ${selectedinstance.node_env} ) : `).then(function (node_env) {
  14889. selectedinstance.node_env = processedArgs.node_env = node_env || selectedinstance.node_env;
  14890. if (choice === 'n') {
  14891. defaultRepoServer = 'https://git.bbh.org.in';
  14892. console.warn(
  14893. source.magenta('No Option Available. Your account may not have privileges. You can request here http://git.bbh.org.in/chess'));
  14894. process.exit();
  14895. }
  14896. return p1.ask(`Enter preferred repo server ( <= ${selectedinstance.reposervers[0]} ) : `).then(function (reposerver) {
  14897. p1.close();
  14898. defaultRepoServer = reposerver || selectedinstance.reposervers[0] || 'https://git.bbh.org.in';
  14899. })
  14900. })
  14901. })
  14902. } else if (choice === 'c') {
  14903. var p1 = cliverse.prompt;
  14904. return p1.ask(`Enter Instance Name ( <= ${selectedinstance.instanceName} ) : `).then(function (instanceName) {
  14905. selectedinstance.instanceName = processedArgs._[1] = instanceName || selectedinstance.instanceName;
  14906. return p1.ask(`Enter Environment ( <= ${selectedinstance.node_env} ) : `).then(function (node_env) {
  14907. selectedinstance.node_env = processedArgs.node_env = node_env || selectedinstance.node_env;
  14908. return p1.ask(`Enter cmd :
  14909. p) pull
  14910. Default <= p
  14911. : `).then(function (cmd) {
  14912. if (!cmd || cmd === 'p') {
  14913. processedArgs._[0] = 'pull';
  14914. }
  14915. else processedArgs._[0] = cmd;
  14916. return p1.ask(`Enter preferred repo server ( <= ${selectedinstance.reposervers[0]} ) : `).then(function (reposerver) {
  14917. defaultRepoServer = reposerver || selectedinstance.reposervers[0] || 'https://git.bbh.org.in';
  14918. p1.close();
  14919. })
  14920. })
  14921. })
  14922. })
  14923. } else {
  14924. console.log(source.gray(`Default option not exercised. Please follow manual instructions to customize your instance here http://git.bbh.org.in/chess and try again.`));
  14925. fs.writeFileSync('run.log', ', ' + JSON.stringify({ success: 'quit without execution' }), { 'flag': 'a+' });
  14926. fs.writeFileSync('run.done', 'noop quit');
  14927. process.exit();
  14928. }
  14929. })
  14930. }
  14931. var acquireConfig = function (selected, chessinstances) {
  14932. var configrepo = selected.instanceName + '-config-' + selected.node_env;
  14933. return performPull(configrepo).then(() => {
  14934. var manifestpath = path__default['default'].normalize(selected.root + '/' + selected.instanceName + '-config-' + selected.node_env + '/repo-manifest');
  14935. repomanifest = commonjsRequire(manifestpath,"/$$rollup_base$$")();
  14936. chessinstances = chessinstances || {};
  14937. chessinstances[selected.instanceName] = chessinstances[selected.instanceName] || {};
  14938. chessinstances[selected.instanceName][selected.node_env] = chessinstances[selected.instanceName][selected.node_env] || {};
  14939. chessinstances['current_run'] = { instanceName: selected.instanceName, node_env: selected.node_env };
  14940. // Config from server always override merges into selection ecept for the current selection.
  14941. selectedinstance = bbhverse.assign(chessinstances[selected.instanceName][selected.node_env], selected, repomanifest);
  14942. fs.writeFileSync(instanceroot + '/chessinstances.js', 'module.exports = ' + JSON.stringify(chessinstances) + '', { 'flag': 'w' });
  14943. // PB : TODO -- We should probably write the new server config also...
  14944. defaultRepoServer = selectedinstance.reposervers[0]; // PB : TODO -- Attempt first one that is available and online...
  14945. ENV.NODE_ENV = selectedinstance.node_env;
  14946. })
  14947. .catch((e) => {
  14948. console.error(e);
  14949. console.error('Config acquisition failed.');
  14950. })
  14951. };
  14952. var launchpath = process.cwd();
  14953. var thisscriptdir = __dirname;
  14954. var instanceroot = launchpath;
  14955. var detectInstance = function () {
  14956. console.log(`launchpath = ${launchpath}`);
  14957. console.log(`thisscriptdir = ${thisscriptdir}`);
  14958. var root = launchpath;
  14959. // We need a reference to the root director for elxr cli to be properly oriented.
  14960. if ((launchpath + path__default['default'].normalize('/elxr')) === thisscriptdir) {
  14961. // We ran unbuilt from the proper root with elxr subfolder.
  14962. console.log(`Instance Path : ${root}`);
  14963. }
  14964. else {
  14965. if (launchpath === thisscriptdir) {
  14966. // Same directory doesn't mean we are being run from elxr directory or the root directory.
  14967. // It could be a standalone elxr build which may or maynot be in the proper location.
  14968. if (BUILD_VERSION.indexOf('Version: {version} - built on {date}') > -1) {
  14969. // Unbuilt therefore we are in the elxr directory.
  14970. root = path__default['default'].normalize(launchpath + '/..');
  14971. }
  14972. else {
  14973. // Built version.
  14974. // check if we have a elxr subfolder.
  14975. if (fs.existsSync(launchpath + '/..' + path__default['default'].normalize('/elxr'))) {
  14976. // Probably in the right place.
  14977. root = path__default['default'].normalize(launchpath + '/..');
  14978. }
  14979. else {
  14980. // Assume launchpath is meaningless.
  14981. // Figure it out from the input instance name and environment parameters if we are in the right location.
  14982. root = path__default['default'].normalize(launchpath + '/' + processedArgs._[1] + '/' + processedArgs.node_env);
  14983. }
  14984. }
  14985. }
  14986. }
  14987. instanceroot = root;
  14988. var __default = {
  14989. // Default is public server only.
  14990. reposervers: ['https://git.bbh.org.in']
  14991. // All public repos are by default available.
  14992. , repos: [
  14993. 'setup'
  14994. , 'elxr'
  14995. , 'loopback-connector-mysql'
  14996. , 'loopback-jsonapi-model-serializer'
  14997. , 'loopback-component-jsonapi'
  14998. , 'ember-service-worker'
  14999. , 'ember-service-worker-asset-cache'
  15000. , 'ember-service-worker-cache-fallback'
  15001. , 'ember-service-worker-index'
  15002. , 'ember-sw-client-route'
  15003. ]
  15004. , elevated: []
  15005. , exludeMergeRepos: {}
  15006. , instanceName: 'chess'
  15007. // Runas windowshta clobbers and removes the NODE_ENV !!! We therefore pass it in.
  15008. , node_env: 'development'
  15009. };
  15010. return Object.assign({ root }, __default);
  15011. };
  15012. var gitUser = 'chessdemo';
  15013. var gitEmail = 'chessdemo@bbh.org.in';
  15014. var downloadsdir = '../Downloads';
  15015. var prerequisites = [
  15016. {
  15017. shellcmd: 'git',
  15018. url: 'https://github.com/git-for-windows/git/releases/download/v2.31.0.windows.1/Git-2.31.0-64-bit.exe'
  15019. , installer: 'Git-2.31.0-64-bit.exe'
  15020. , installcmd: ['cmd', ['/c', 'start',
  15021. '/WAIT', path__default['default'].resolve(downloadsdir + '/' + 'Git-2.31.0-64-bit.exe')
  15022. , '/VERYSILENT'
  15023. // , '/MERGETASKS=!runcode' // This is required only for vscode...
  15024. ]]
  15025. , preinstallsteps: () => {
  15026. var prompt = cliverse.prompt;
  15027. var steps = [
  15028. () => {
  15029. if (!existsSync(downloadsdir + '/' + preq.installer)) {
  15030. return nodeShellExec('download.bat', [preq.url, downloadsdir + '/' + preq.installer])
  15031. }
  15032. else return Promise.resolve(true)
  15033. }
  15034. ];
  15035. var prompts = [
  15036. () => prompt.ask(`git user name : ( <= ${gitUser} )`).then((user) => { gitUser = user; })
  15037. , () => prompt.ask(`git user name : ( <= ${gitEmail} )`).then((email) => { gitEmail = email; })
  15038. ];
  15039. return Promise.all([any(steps), any(prompts)]).finally(() => { prompt.close(); })
  15040. }
  15041. , installsteps: function () {
  15042. return any([this.installcmd].map(callsheltask))
  15043. }
  15044. , postinstallsteps: () => {
  15045. var steps = [
  15046. ['git', ['config', '--global', '--add', 'user.name', `${gitUser}`]]
  15047. , ['git', ['config', '--global', '--add', 'user.email', `${gitEmail}`]]
  15048. ];
  15049. return any(steps.map(callsheltask)).then(() => { })
  15050. }
  15051. , install: function () {
  15052. return any([ /*this.preinstallsteps,*/ this.installsteps, this.postinstallsteps])
  15053. }
  15054. }
  15055. ,
  15056. {
  15057. shellcmd: 'node',
  15058. url: 'https://nodejs.org/dist/v14.16.0/node-v14.16.0-x64.msi'
  15059. , installer: 'node-v14.16.0-x64.msi'
  15060. , installcmd: ['MSIEXEC.exe', ['/i'
  15061. , path__default['default'].resolve(downloadsdir + '/' + 'node-v14.16.0-x64.msi')
  15062. , 'ACCEPT=YES', '/passive']]
  15063. }
  15064. ];
  15065. function ensureDirectoryExistence(filePath) {
  15066. var dirname = path__default['default'].dirname(filePath);
  15067. if (fs.existsSync(dirname)) {
  15068. return filePath;
  15069. }
  15070. ensureDirectoryExistence(dirname);
  15071. fs.mkdirSync(dirname);
  15072. return filePath;
  15073. }
  15074. var mainTasks = [];
  15075. function verifyAndInstallPrerequisites() {
  15076. fs.writeFileSync(ensureDirectoryExistence(path__default['default'].normalize(downloadsdir + '/readme.txt')), `${getVersion()} Your local downloads for this instance`);
  15077. var downloadbatch =
  15078. `::**************************************************************************
  15079. :Download_ <url> <File>
  15080. Powershell.exe ^
  15081. $AllProtocols = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12'; ^
  15082. [System.Net.ServicePointManager]::SecurityProtocol = $AllProtocols; ^
  15083. (New-Object System.Net.WebClient).DownloadFile('%1','%2')
  15084. exit /b
  15085. ::**************************************************************************`;
  15086. fs.writeFileSync('download.bat', downloadbatch);
  15087. var downloadtasks = [];
  15088. var installtasks = [];
  15089. prerequisites.forEach(preq => {
  15090. downloadtasks.push(getTaskCheckExists(preq.shellcmd, { ignorefailures: true })().then((exists) => {
  15091. if (exists) console.log(`${preq.shellcmd} exists`);
  15092. else {
  15093. console.log(`${preq.shellcmd} is not installed`);
  15094. return preq.preinstallsteps().then(() => {
  15095. installtasks.push(task.install);
  15096. })
  15097. }
  15098. }));
  15099. });
  15100. return Promise.all(downloadtasks).then(() => { return any(installtasks) })
  15101. }
  15102. function initinstances(chessinstances, selected) {
  15103. chessinstances.current_run.instanceName = processedArgs._[1] = processedArgs._[1] || chessinstances.current_run.instanceName || selected.instanceName;
  15104. chessinstances.current_run.node_env = processedArgs.node_env = processedArgs.node_env || chessinstances.current_run.node_env || selected.node_env;
  15105. chessinstances[chessinstances.current_run.instanceName] = chessinstances[chessinstances.current_run.instanceName] || {};
  15106. selectedinstance = Object.assign(selected, chessinstances[chessinstances.current_run.instanceName][chessinstances.current_run.node_env], clioverrides);
  15107. repomanifest = selectedinstance;
  15108. return chessinstances
  15109. }
  15110. function acquirelocalinstances(selected){
  15111. var chessinstances = bbhverse.assign(commonjsRequire(path__default['default'].normalize(selected.root + '/chessinstances.js'),"/$$rollup_base$$"));
  15112. return initinstances(chessinstances, selected)
  15113. }
  15114. var detectedInstance = detectInstance(); // From launch location etc.
  15115. var selectedinstance = detectedInstance;
  15116. var clioverrides = { };
  15117. processedArgs._[1] ? clioverrides.instanceName = processedArgs._[1]: null;
  15118. processedArgs.node_env ? clioverrides.node_env = (process.env.NODE_ENV && process.env.NODE_ENV.trim()) || processedArgs.node_env
  15119. : (process.env.NODE_ENV && process.env.NODE_ENV.trim()) ? clioverrides.node_env = (process.env.NODE_ENV && process.env.NODE_ENV.trim()): null;
  15120. var maintask = () => {
  15121. try {
  15122. // Default cmd to run !
  15123. var chessinstances = acquirelocalinstances(selectedinstance);
  15124. processedArgs._[0] === processedArgs._[0] || 'pull';
  15125. // defaultRepoServer = repomanifest.reposervers[0] // PB : TODO -- Attempt first one that is available and online from all that are available...
  15126. return acquireConfig(selectedinstance, chessinstances).catch((e) => {
  15127. console.error('Exisitng config Failed. Fix config and rerun or chose another.');
  15128. console.error(e);
  15129. }).then(() => { return elxrworker(true) })
  15130. }
  15131. catch (e) {
  15132. console.error(e);
  15133. // No local instances config found. We acquire user choices and proceed to reattempt.
  15134. chessinstances = {};
  15135. chessinstances.current_run = {};
  15136. initinstances(chessinstances, selectedinstance);
  15137. return acquireChoices(selectedinstance).then(() => {
  15138. try {
  15139. var chessinstances = acquirelocalinstances(selectedinstance);
  15140. }
  15141. catch (e) {
  15142. console.error(e);
  15143. console.error('No local instances config found in current root = ' + selectedinstance.root);
  15144. console.log('A config will be createed with the instance and environment chosen...');
  15145. }
  15146. finally {
  15147. return acquireConfig(selectedinstance, chessinstances).catch((e) => {
  15148. console.error('Chosen cofiguraton failed or not found');
  15149. console.error(e);
  15150. }).then(() => { return elxrworker() })
  15151. .finally(()=>{
  15152. fs.writeFileSync('run.log', ', ' + JSON.stringify({ error: e.message }), { 'flag': 'a+' });
  15153. fs.writeFileSync('run.done', 'error');
  15154. // return process.exit()
  15155. })
  15156. }
  15157. })
  15158. }
  15159. };
  15160. acquireElevationState().then(() => {
  15161. if (!__isElevated) mainTasks.push(verifyAndInstallPrerequisites);
  15162. mainTasks.push(maintask);
  15163. return any(mainTasks);
  15164. });
  15165. // Sample instances config.
  15166. // var instances = {
  15167. // "elixir": {
  15168. // "production": {
  15169. // "reposervers": ["http://git.bbh", "https://git.bbh.org.in"]
  15170. // , "repos": ["ember-masonry-grid", "client", "elixir-client"]
  15171. // , "exludeMergeRepos": {
  15172. // "elixir-config-development": true, "elixir-config-test": true
  15173. // , "elixir-config-production": true, "elixir-data": true
  15174. // }
  15175. // , "instanceName": "elixir", "node_env": "production"
  15176. // }
  15177. // },
  15178. // "current_run": { "instanceName": "elixir", "node_env": "production" }
  15179. // }
  15180. var elxr_1 = {
  15181. };
  15182. module.exports = elxr_1;