third-party.js 136 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357
  1. 'use strict';
  2. function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
  3. var os = _interopDefault(require('os'));
  4. var path = _interopDefault(require('path'));
  5. var util = _interopDefault(require('util'));
  6. var module$1 = _interopDefault(require('module'));
  7. var fs = _interopDefault(require('fs'));
  8. var stream = _interopDefault(require('stream'));
  9. function _classCallCheck(instance, Constructor) {
  10. if (!(instance instanceof Constructor)) {
  11. throw new TypeError("Cannot call a class as a function");
  12. }
  13. }
  14. function _defineProperties(target, props) {
  15. for (var i = 0; i < props.length; i++) {
  16. var descriptor = props[i];
  17. descriptor.enumerable = descriptor.enumerable || false;
  18. descriptor.configurable = true;
  19. if ("value" in descriptor) descriptor.writable = true;
  20. Object.defineProperty(target, descriptor.key, descriptor);
  21. }
  22. }
  23. function _createClass(Constructor, protoProps, staticProps) {
  24. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  25. if (staticProps) _defineProperties(Constructor, staticProps);
  26. return Constructor;
  27. }
  28. function _toArray(arr) {
  29. return _arrayWithHoles(arr) || _iterableToArray(arr) || _nonIterableRest();
  30. }
  31. function _arrayWithHoles(arr) {
  32. if (Array.isArray(arr)) return arr;
  33. }
  34. function _iterableToArray(iter) {
  35. if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
  36. }
  37. function _nonIterableRest() {
  38. throw new TypeError("Invalid attempt to destructure non-iterable instance");
  39. }
  40. function _toPrimitive(input, hint) {
  41. if (typeof input !== "object" || input === null) return input;
  42. var prim = input[Symbol.toPrimitive];
  43. if (prim !== undefined) {
  44. var res = prim.call(input, hint || "default");
  45. if (typeof res !== "object") return res;
  46. throw new TypeError("@@toPrimitive must return a primitive value.");
  47. }
  48. return (hint === "string" ? String : Number)(input);
  49. }
  50. function _toPropertyKey(arg) {
  51. var key = _toPrimitive(arg, "string");
  52. return typeof key === "symbol" ? key : String(key);
  53. }
  54. function _addElementPlacement(element, placements, silent) {
  55. var keys = placements[element.placement];
  56. if (!silent && keys.indexOf(element.key) !== -1) {
  57. throw new TypeError("Duplicated element (" + element.key + ")");
  58. }
  59. keys.push(element.key);
  60. }
  61. function _fromElementDescriptor(element) {
  62. var obj = {
  63. kind: element.kind,
  64. key: element.key,
  65. placement: element.placement,
  66. descriptor: element.descriptor
  67. };
  68. var desc = {
  69. value: "Descriptor",
  70. configurable: true
  71. };
  72. Object.defineProperty(obj, Symbol.toStringTag, desc);
  73. if (element.kind === "field") obj.initializer = element.initializer;
  74. return obj;
  75. }
  76. function _toElementDescriptors(elementObjects) {
  77. if (elementObjects === undefined) return;
  78. return _toArray(elementObjects).map(function (elementObject) {
  79. var element = _toElementDescriptor(elementObject);
  80. _disallowProperty(elementObject, "finisher", "An element descriptor");
  81. _disallowProperty(elementObject, "extras", "An element descriptor");
  82. return element;
  83. });
  84. }
  85. function _toElementDescriptor(elementObject) {
  86. var kind = String(elementObject.kind);
  87. if (kind !== "method" && kind !== "field") {
  88. throw new TypeError('An element descriptor\'s .kind property must be either "method" or' + ' "field", but a decorator created an element descriptor with' + ' .kind "' + kind + '"');
  89. }
  90. var key = _toPropertyKey(elementObject.key);
  91. var placement = String(elementObject.placement);
  92. if (placement !== "static" && placement !== "prototype" && placement !== "own") {
  93. throw new TypeError('An element descriptor\'s .placement property must be one of "static",' + ' "prototype" or "own", but a decorator created an element descriptor' + ' with .placement "' + placement + '"');
  94. }
  95. var descriptor = elementObject.descriptor;
  96. _disallowProperty(elementObject, "elements", "An element descriptor");
  97. var element = {
  98. kind: kind,
  99. key: key,
  100. placement: placement,
  101. descriptor: Object.assign({}, descriptor)
  102. };
  103. if (kind !== "field") {
  104. _disallowProperty(elementObject, "initializer", "A method descriptor");
  105. } else {
  106. _disallowProperty(descriptor, "get", "The property descriptor of a field descriptor");
  107. _disallowProperty(descriptor, "set", "The property descriptor of a field descriptor");
  108. _disallowProperty(descriptor, "value", "The property descriptor of a field descriptor");
  109. element.initializer = elementObject.initializer;
  110. }
  111. return element;
  112. }
  113. function _toElementFinisherExtras(elementObject) {
  114. var element = _toElementDescriptor(elementObject);
  115. var finisher = _optionalCallableProperty(elementObject, "finisher");
  116. var extras = _toElementDescriptors(elementObject.extras);
  117. return {
  118. element: element,
  119. finisher: finisher,
  120. extras: extras
  121. };
  122. }
  123. function _fromClassDescriptor(elements) {
  124. var obj = {
  125. kind: "class",
  126. elements: elements.map(_fromElementDescriptor)
  127. };
  128. var desc = {
  129. value: "Descriptor",
  130. configurable: true
  131. };
  132. Object.defineProperty(obj, Symbol.toStringTag, desc);
  133. return obj;
  134. }
  135. function _toClassDescriptor(obj) {
  136. var kind = String(obj.kind);
  137. if (kind !== "class") {
  138. throw new TypeError('A class descriptor\'s .kind property must be "class", but a decorator' + ' created a class descriptor with .kind "' + kind + '"');
  139. }
  140. _disallowProperty(obj, "key", "A class descriptor");
  141. _disallowProperty(obj, "placement", "A class descriptor");
  142. _disallowProperty(obj, "descriptor", "A class descriptor");
  143. _disallowProperty(obj, "initializer", "A class descriptor");
  144. _disallowProperty(obj, "extras", "A class descriptor");
  145. var finisher = _optionalCallableProperty(obj, "finisher");
  146. var elements = _toElementDescriptors(obj.elements);
  147. return {
  148. elements: elements,
  149. finisher: finisher
  150. };
  151. }
  152. function _disallowProperty(obj, name, objectType) {
  153. if (obj[name] !== undefined) {
  154. throw new TypeError(objectType + " can't have a ." + name + " property.");
  155. }
  156. }
  157. function _optionalCallableProperty(obj, name) {
  158. var value = obj[name];
  159. if (value !== undefined && typeof value !== "function") {
  160. throw new TypeError("Expected '" + name + "' to be a function");
  161. }
  162. return value;
  163. }
  164. function commonjsRequire () {
  165. throw new Error('Dynamic requires are not currently supported by rollup-plugin-commonjs');
  166. }
  167. function createCommonjsModule(fn, module) {
  168. return module = { exports: {} }, fn(module, module.exports), module.exports;
  169. }
  170. var isArrayish = function isArrayish(obj) {
  171. if (!obj) {
  172. return false;
  173. }
  174. return obj instanceof Array || Array.isArray(obj) || obj.length >= 0 && obj.splice instanceof Function;
  175. };
  176. var errorEx = function errorEx(name, properties) {
  177. if (!name || name.constructor !== String) {
  178. properties = name || {};
  179. name = Error.name;
  180. }
  181. var errorExError = function ErrorEXError(message) {
  182. if (!this) {
  183. return new ErrorEXError(message);
  184. }
  185. message = message instanceof Error ? message.message : message || this.message;
  186. Error.call(this, message);
  187. Error.captureStackTrace(this, errorExError);
  188. this.name = name;
  189. Object.defineProperty(this, 'message', {
  190. configurable: true,
  191. enumerable: false,
  192. get: function get() {
  193. var newMessage = message.split(/\r?\n/g);
  194. for (var key in properties) {
  195. if (!properties.hasOwnProperty(key)) {
  196. continue;
  197. }
  198. var modifier = properties[key];
  199. if ('message' in modifier) {
  200. newMessage = modifier.message(this[key], newMessage) || newMessage;
  201. if (!isArrayish(newMessage)) {
  202. newMessage = [newMessage];
  203. }
  204. }
  205. }
  206. return newMessage.join('\n');
  207. },
  208. set: function set(v) {
  209. message = v;
  210. }
  211. });
  212. var overwrittenStack = null;
  213. var stackDescriptor = Object.getOwnPropertyDescriptor(this, 'stack');
  214. var stackGetter = stackDescriptor.get;
  215. var stackValue = stackDescriptor.value;
  216. delete stackDescriptor.value;
  217. delete stackDescriptor.writable;
  218. stackDescriptor.set = function (newstack) {
  219. overwrittenStack = newstack;
  220. };
  221. stackDescriptor.get = function () {
  222. var stack = (overwrittenStack || (stackGetter ? stackGetter.call(this) : stackValue)).split(/\r?\n+/g); // starting in Node 7, the stack builder caches the message.
  223. // just replace it.
  224. if (!overwrittenStack) {
  225. stack[0] = this.name + ': ' + this.message;
  226. }
  227. var lineCount = 1;
  228. for (var key in properties) {
  229. if (!properties.hasOwnProperty(key)) {
  230. continue;
  231. }
  232. var modifier = properties[key];
  233. if ('line' in modifier) {
  234. var line = modifier.line(this[key]);
  235. if (line) {
  236. stack.splice(lineCount++, 0, ' ' + line);
  237. }
  238. }
  239. if ('stack' in modifier) {
  240. modifier.stack(this[key], stack);
  241. }
  242. }
  243. return stack.join('\n');
  244. };
  245. Object.defineProperty(this, 'stack', stackDescriptor);
  246. };
  247. if (Object.setPrototypeOf) {
  248. Object.setPrototypeOf(errorExError.prototype, Error.prototype);
  249. Object.setPrototypeOf(errorExError, Error);
  250. } else {
  251. util.inherits(errorExError, Error);
  252. }
  253. return errorExError;
  254. };
  255. errorEx.append = function (str, def) {
  256. return {
  257. message: function message(v, _message) {
  258. v = v || def;
  259. if (v) {
  260. _message[0] += ' ' + str.replace('%s', v.toString());
  261. }
  262. return _message;
  263. }
  264. };
  265. };
  266. errorEx.line = function (str, def) {
  267. return {
  268. line: function line(v) {
  269. v = v || def;
  270. if (v) {
  271. return str.replace('%s', v.toString());
  272. }
  273. return null;
  274. }
  275. };
  276. };
  277. var errorEx_1 = errorEx;
  278. var jsonParseBetterErrors = parseJson$2;
  279. function parseJson$2(txt, reviver, context) {
  280. context = context || 20;
  281. try {
  282. return JSON.parse(txt, reviver);
  283. } catch (e) {
  284. if (typeof txt !== 'string') {
  285. var isEmptyArray = Array.isArray(txt) && txt.length === 0;
  286. var errorMessage = 'Cannot parse ' + (isEmptyArray ? 'an empty array' : String(txt));
  287. throw new TypeError(errorMessage);
  288. }
  289. var syntaxErr = e.message.match(/^Unexpected token.*position\s+(\d+)/i);
  290. var errIdx = syntaxErr ? +syntaxErr[1] : e.message.match(/^Unexpected end of JSON.*/i) ? txt.length - 1 : null;
  291. if (errIdx != null) {
  292. var start = errIdx <= context ? 0 : errIdx - context;
  293. var end = errIdx + context >= txt.length ? txt.length : errIdx + context;
  294. e.message += ` while parsing near '${start === 0 ? '' : '...'}${txt.slice(start, end)}${end === txt.length ? '' : '...'}'`;
  295. } else {
  296. e.message += ` while parsing '${txt.slice(0, context * 2)}'`;
  297. }
  298. throw e;
  299. }
  300. }
  301. var parseJson = createCommonjsModule(function (module) {
  302. 'use strict';
  303. var JSONError = errorEx_1('JSONError', {
  304. fileName: errorEx_1.append('in %s')
  305. });
  306. module.exports = function (input, reviver, filename) {
  307. if (typeof reviver === 'string') {
  308. filename = reviver;
  309. reviver = null;
  310. }
  311. try {
  312. try {
  313. return JSON.parse(input, reviver);
  314. } catch (err) {
  315. jsonParseBetterErrors(input, reviver);
  316. throw err;
  317. }
  318. } catch (err) {
  319. err.message = err.message.replace(/\n/g, '');
  320. var jsonErr = new JSONError(err);
  321. if (filename) {
  322. jsonErr.fileName = filename;
  323. }
  324. throw jsonErr;
  325. }
  326. };
  327. });
  328. function isNothing(subject) {
  329. return typeof subject === 'undefined' || subject === null;
  330. }
  331. function isObject(subject) {
  332. return typeof subject === 'object' && subject !== null;
  333. }
  334. function toArray(sequence) {
  335. if (Array.isArray(sequence)) return sequence;else if (isNothing(sequence)) return [];
  336. return [sequence];
  337. }
  338. function extend(target, source) {
  339. var index, length, key, sourceKeys;
  340. if (source) {
  341. sourceKeys = Object.keys(source);
  342. for (index = 0, length = sourceKeys.length; index < length; index += 1) {
  343. key = sourceKeys[index];
  344. target[key] = source[key];
  345. }
  346. }
  347. return target;
  348. }
  349. function repeat(string, count) {
  350. var result = '',
  351. cycle;
  352. for (cycle = 0; cycle < count; cycle += 1) {
  353. result += string;
  354. }
  355. return result;
  356. }
  357. function isNegativeZero(number) {
  358. return number === 0 && Number.NEGATIVE_INFINITY === 1 / number;
  359. }
  360. var isNothing_1 = isNothing;
  361. var isObject_1 = isObject;
  362. var toArray_1 = toArray;
  363. var repeat_1 = repeat;
  364. var isNegativeZero_1 = isNegativeZero;
  365. var extend_1 = extend;
  366. var common = {
  367. isNothing: isNothing_1,
  368. isObject: isObject_1,
  369. toArray: toArray_1,
  370. repeat: repeat_1,
  371. isNegativeZero: isNegativeZero_1,
  372. extend: extend_1
  373. };
  374. // YAML error class. http://stackoverflow.com/questions/8458984
  375. //
  376. function YAMLException$1(reason, mark) {
  377. // Super constructor
  378. Error.call(this);
  379. this.name = 'YAMLException';
  380. this.reason = reason;
  381. this.mark = mark;
  382. this.message = (this.reason || '(unknown reason)') + (this.mark ? ' ' + this.mark.toString() : ''); // Include stack trace in error object
  383. if (Error.captureStackTrace) {
  384. // Chrome and NodeJS
  385. Error.captureStackTrace(this, this.constructor);
  386. } else {
  387. // FF, IE 10+ and Safari 6+. Fallback for others
  388. this.stack = new Error().stack || '';
  389. }
  390. } // Inherit from Error
  391. YAMLException$1.prototype = Object.create(Error.prototype);
  392. YAMLException$1.prototype.constructor = YAMLException$1;
  393. YAMLException$1.prototype.toString = function toString(compact) {
  394. var result = this.name + ': ';
  395. result += this.reason || '(unknown reason)';
  396. if (!compact && this.mark) {
  397. result += ' ' + this.mark.toString();
  398. }
  399. return result;
  400. };
  401. var exception = YAMLException$1;
  402. function Mark(name, buffer, position, line, column) {
  403. this.name = name;
  404. this.buffer = buffer;
  405. this.position = position;
  406. this.line = line;
  407. this.column = column;
  408. }
  409. Mark.prototype.getSnippet = function getSnippet(indent, maxLength) {
  410. var head, start, tail, end, snippet;
  411. if (!this.buffer) return null;
  412. indent = indent || 4;
  413. maxLength = maxLength || 75;
  414. head = '';
  415. start = this.position;
  416. while (start > 0 && '\x00\r\n\x85\u2028\u2029'.indexOf(this.buffer.charAt(start - 1)) === -1) {
  417. start -= 1;
  418. if (this.position - start > maxLength / 2 - 1) {
  419. head = ' ... ';
  420. start += 5;
  421. break;
  422. }
  423. }
  424. tail = '';
  425. end = this.position;
  426. while (end < this.buffer.length && '\x00\r\n\x85\u2028\u2029'.indexOf(this.buffer.charAt(end)) === -1) {
  427. end += 1;
  428. if (end - this.position > maxLength / 2 - 1) {
  429. tail = ' ... ';
  430. end -= 5;
  431. break;
  432. }
  433. }
  434. snippet = this.buffer.slice(start, end);
  435. return common.repeat(' ', indent) + head + snippet + tail + '\n' + common.repeat(' ', indent + this.position - start + head.length) + '^';
  436. };
  437. Mark.prototype.toString = function toString(compact) {
  438. var snippet,
  439. where = '';
  440. if (this.name) {
  441. where += 'in "' + this.name + '" ';
  442. }
  443. where += 'at line ' + (this.line + 1) + ', column ' + (this.column + 1);
  444. if (!compact) {
  445. snippet = this.getSnippet();
  446. if (snippet) {
  447. where += ':\n' + snippet;
  448. }
  449. }
  450. return where;
  451. };
  452. var mark = Mark;
  453. var TYPE_CONSTRUCTOR_OPTIONS = ['kind', 'resolve', 'construct', 'instanceOf', 'predicate', 'represent', 'defaultStyle', 'styleAliases'];
  454. var YAML_NODE_KINDS = ['scalar', 'sequence', 'mapping'];
  455. function compileStyleAliases(map) {
  456. var result = {};
  457. if (map !== null) {
  458. Object.keys(map).forEach(function (style) {
  459. map[style].forEach(function (alias) {
  460. result[String(alias)] = style;
  461. });
  462. });
  463. }
  464. return result;
  465. }
  466. function Type$1(tag, options) {
  467. options = options || {};
  468. Object.keys(options).forEach(function (name) {
  469. if (TYPE_CONSTRUCTOR_OPTIONS.indexOf(name) === -1) {
  470. throw new exception('Unknown option "' + name + '" is met in definition of "' + tag + '" YAML type.');
  471. }
  472. }); // TODO: Add tag format check.
  473. this.tag = tag;
  474. this.kind = options['kind'] || null;
  475. this.resolve = options['resolve'] || function () {
  476. return true;
  477. };
  478. this.construct = options['construct'] || function (data) {
  479. return data;
  480. };
  481. this.instanceOf = options['instanceOf'] || null;
  482. this.predicate = options['predicate'] || null;
  483. this.represent = options['represent'] || null;
  484. this.defaultStyle = options['defaultStyle'] || null;
  485. this.styleAliases = compileStyleAliases(options['styleAliases'] || null);
  486. if (YAML_NODE_KINDS.indexOf(this.kind) === -1) {
  487. throw new exception('Unknown kind "' + this.kind + '" is specified for "' + tag + '" YAML type.');
  488. }
  489. }
  490. var type = Type$1;
  491. /*eslint-disable max-len*/
  492. function compileList(schema, name, result) {
  493. var exclude = [];
  494. schema.include.forEach(function (includedSchema) {
  495. result = compileList(includedSchema, name, result);
  496. });
  497. schema[name].forEach(function (currentType) {
  498. result.forEach(function (previousType, previousIndex) {
  499. if (previousType.tag === currentType.tag && previousType.kind === currentType.kind) {
  500. exclude.push(previousIndex);
  501. }
  502. });
  503. result.push(currentType);
  504. });
  505. return result.filter(function (type$$1, index) {
  506. return exclude.indexOf(index) === -1;
  507. });
  508. }
  509. function compileMap()
  510. /* lists... */
  511. {
  512. var result = {
  513. scalar: {},
  514. sequence: {},
  515. mapping: {},
  516. fallback: {}
  517. },
  518. index,
  519. length;
  520. function collectType(type$$1) {
  521. result[type$$1.kind][type$$1.tag] = result['fallback'][type$$1.tag] = type$$1;
  522. }
  523. for (index = 0, length = arguments.length; index < length; index += 1) {
  524. arguments[index].forEach(collectType);
  525. }
  526. return result;
  527. }
  528. function Schema$1(definition) {
  529. this.include = definition.include || [];
  530. this.implicit = definition.implicit || [];
  531. this.explicit = definition.explicit || [];
  532. this.implicit.forEach(function (type$$1) {
  533. if (type$$1.loadKind && type$$1.loadKind !== 'scalar') {
  534. throw new exception('There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.');
  535. }
  536. });
  537. this.compiledImplicit = compileList(this, 'implicit', []);
  538. this.compiledExplicit = compileList(this, 'explicit', []);
  539. this.compiledTypeMap = compileMap(this.compiledImplicit, this.compiledExplicit);
  540. }
  541. Schema$1.DEFAULT = null;
  542. Schema$1.create = function createSchema() {
  543. var schemas, types;
  544. switch (arguments.length) {
  545. case 1:
  546. schemas = Schema$1.DEFAULT;
  547. types = arguments[0];
  548. break;
  549. case 2:
  550. schemas = arguments[0];
  551. types = arguments[1];
  552. break;
  553. default:
  554. throw new exception('Wrong number of arguments for Schema.create function');
  555. }
  556. schemas = common.toArray(schemas);
  557. types = common.toArray(types);
  558. if (!schemas.every(function (schema) {
  559. return schema instanceof Schema$1;
  560. })) {
  561. throw new exception('Specified list of super schemas (or a single Schema object) contains a non-Schema object.');
  562. }
  563. if (!types.every(function (type$$1) {
  564. return type$$1 instanceof type;
  565. })) {
  566. throw new exception('Specified list of YAML types (or a single Type object) contains a non-Type object.');
  567. }
  568. return new Schema$1({
  569. include: schemas,
  570. explicit: types
  571. });
  572. };
  573. var schema = Schema$1;
  574. var str = new type('tag:yaml.org,2002:str', {
  575. kind: 'scalar',
  576. construct: function construct(data) {
  577. return data !== null ? data : '';
  578. }
  579. });
  580. var seq = new type('tag:yaml.org,2002:seq', {
  581. kind: 'sequence',
  582. construct: function construct(data) {
  583. return data !== null ? data : [];
  584. }
  585. });
  586. var map = new type('tag:yaml.org,2002:map', {
  587. kind: 'mapping',
  588. construct: function construct(data) {
  589. return data !== null ? data : {};
  590. }
  591. });
  592. var failsafe = new schema({
  593. explicit: [str, seq, map]
  594. });
  595. function resolveYamlNull(data) {
  596. if (data === null) return true;
  597. var max = data.length;
  598. return max === 1 && data === '~' || max === 4 && (data === 'null' || data === 'Null' || data === 'NULL');
  599. }
  600. function constructYamlNull() {
  601. return null;
  602. }
  603. function isNull(object) {
  604. return object === null;
  605. }
  606. var _null = new type('tag:yaml.org,2002:null', {
  607. kind: 'scalar',
  608. resolve: resolveYamlNull,
  609. construct: constructYamlNull,
  610. predicate: isNull,
  611. represent: {
  612. canonical: function canonical() {
  613. return '~';
  614. },
  615. lowercase: function lowercase() {
  616. return 'null';
  617. },
  618. uppercase: function uppercase() {
  619. return 'NULL';
  620. },
  621. camelcase: function camelcase() {
  622. return 'Null';
  623. }
  624. },
  625. defaultStyle: 'lowercase'
  626. });
  627. function resolveYamlBoolean(data) {
  628. if (data === null) return false;
  629. var max = data.length;
  630. return max === 4 && (data === 'true' || data === 'True' || data === 'TRUE') || max === 5 && (data === 'false' || data === 'False' || data === 'FALSE');
  631. }
  632. function constructYamlBoolean(data) {
  633. return data === 'true' || data === 'True' || data === 'TRUE';
  634. }
  635. function isBoolean(object) {
  636. return Object.prototype.toString.call(object) === '[object Boolean]';
  637. }
  638. var bool = new type('tag:yaml.org,2002:bool', {
  639. kind: 'scalar',
  640. resolve: resolveYamlBoolean,
  641. construct: constructYamlBoolean,
  642. predicate: isBoolean,
  643. represent: {
  644. lowercase: function lowercase(object) {
  645. return object ? 'true' : 'false';
  646. },
  647. uppercase: function uppercase(object) {
  648. return object ? 'TRUE' : 'FALSE';
  649. },
  650. camelcase: function camelcase(object) {
  651. return object ? 'True' : 'False';
  652. }
  653. },
  654. defaultStyle: 'lowercase'
  655. });
  656. function isHexCode(c) {
  657. return 0x30
  658. /* 0 */
  659. <= c && c <= 0x39
  660. /* 9 */
  661. || 0x41
  662. /* A */
  663. <= c && c <= 0x46
  664. /* F */
  665. || 0x61
  666. /* a */
  667. <= c && c <= 0x66
  668. /* f */
  669. ;
  670. }
  671. function isOctCode(c) {
  672. return 0x30
  673. /* 0 */
  674. <= c && c <= 0x37
  675. /* 7 */
  676. ;
  677. }
  678. function isDecCode(c) {
  679. return 0x30
  680. /* 0 */
  681. <= c && c <= 0x39
  682. /* 9 */
  683. ;
  684. }
  685. function resolveYamlInteger(data) {
  686. if (data === null) return false;
  687. var max = data.length,
  688. index = 0,
  689. hasDigits = false,
  690. ch;
  691. if (!max) return false;
  692. ch = data[index]; // sign
  693. if (ch === '-' || ch === '+') {
  694. ch = data[++index];
  695. }
  696. if (ch === '0') {
  697. // 0
  698. if (index + 1 === max) return true;
  699. ch = data[++index]; // base 2, base 8, base 16
  700. if (ch === 'b') {
  701. // base 2
  702. index++;
  703. for (; index < max; index++) {
  704. ch = data[index];
  705. if (ch === '_') continue;
  706. if (ch !== '0' && ch !== '1') return false;
  707. hasDigits = true;
  708. }
  709. return hasDigits && ch !== '_';
  710. }
  711. if (ch === 'x') {
  712. // base 16
  713. index++;
  714. for (; index < max; index++) {
  715. ch = data[index];
  716. if (ch === '_') continue;
  717. if (!isHexCode(data.charCodeAt(index))) return false;
  718. hasDigits = true;
  719. }
  720. return hasDigits && ch !== '_';
  721. } // base 8
  722. for (; index < max; index++) {
  723. ch = data[index];
  724. if (ch === '_') continue;
  725. if (!isOctCode(data.charCodeAt(index))) return false;
  726. hasDigits = true;
  727. }
  728. return hasDigits && ch !== '_';
  729. } // base 10 (except 0) or base 60
  730. // value should not start with `_`;
  731. if (ch === '_') return false;
  732. for (; index < max; index++) {
  733. ch = data[index];
  734. if (ch === '_') continue;
  735. if (ch === ':') break;
  736. if (!isDecCode(data.charCodeAt(index))) {
  737. return false;
  738. }
  739. hasDigits = true;
  740. } // Should have digits and should not end with `_`
  741. if (!hasDigits || ch === '_') return false; // if !base60 - done;
  742. if (ch !== ':') return true; // base60 almost not used, no needs to optimize
  743. return /^(:[0-5]?[0-9])+$/.test(data.slice(index));
  744. }
  745. function constructYamlInteger(data) {
  746. var value = data,
  747. sign = 1,
  748. ch,
  749. base,
  750. digits = [];
  751. if (value.indexOf('_') !== -1) {
  752. value = value.replace(/_/g, '');
  753. }
  754. ch = value[0];
  755. if (ch === '-' || ch === '+') {
  756. if (ch === '-') sign = -1;
  757. value = value.slice(1);
  758. ch = value[0];
  759. }
  760. if (value === '0') return 0;
  761. if (ch === '0') {
  762. if (value[1] === 'b') return sign * parseInt(value.slice(2), 2);
  763. if (value[1] === 'x') return sign * parseInt(value, 16);
  764. return sign * parseInt(value, 8);
  765. }
  766. if (value.indexOf(':') !== -1) {
  767. value.split(':').forEach(function (v) {
  768. digits.unshift(parseInt(v, 10));
  769. });
  770. value = 0;
  771. base = 1;
  772. digits.forEach(function (d) {
  773. value += d * base;
  774. base *= 60;
  775. });
  776. return sign * value;
  777. }
  778. return sign * parseInt(value, 10);
  779. }
  780. function isInteger(object) {
  781. return Object.prototype.toString.call(object) === '[object Number]' && object % 1 === 0 && !common.isNegativeZero(object);
  782. }
  783. var int_1 = new type('tag:yaml.org,2002:int', {
  784. kind: 'scalar',
  785. resolve: resolveYamlInteger,
  786. construct: constructYamlInteger,
  787. predicate: isInteger,
  788. represent: {
  789. binary: function binary(obj) {
  790. return obj >= 0 ? '0b' + obj.toString(2) : '-0b' + obj.toString(2).slice(1);
  791. },
  792. octal: function octal(obj) {
  793. return obj >= 0 ? '0' + obj.toString(8) : '-0' + obj.toString(8).slice(1);
  794. },
  795. decimal: function decimal(obj) {
  796. return obj.toString(10);
  797. },
  798. /* eslint-disable max-len */
  799. hexadecimal: function hexadecimal(obj) {
  800. return obj >= 0 ? '0x' + obj.toString(16).toUpperCase() : '-0x' + obj.toString(16).toUpperCase().slice(1);
  801. }
  802. },
  803. defaultStyle: 'decimal',
  804. styleAliases: {
  805. binary: [2, 'bin'],
  806. octal: [8, 'oct'],
  807. decimal: [10, 'dec'],
  808. hexadecimal: [16, 'hex']
  809. }
  810. });
  811. var YAML_FLOAT_PATTERN = new RegExp( // 2.5e4, 2.5 and integers
  812. '^(?:[-+]?(?:0|[1-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?' + // .2e4, .2
  813. // special case, seems not from spec
  814. '|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?' + // 20:59
  815. '|[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]*' + // .inf
  816. '|[-+]?\\.(?:inf|Inf|INF)' + // .nan
  817. '|\\.(?:nan|NaN|NAN))$');
  818. function resolveYamlFloat(data) {
  819. if (data === null) return false;
  820. if (!YAML_FLOAT_PATTERN.test(data) || // Quick hack to not allow integers end with `_`
  821. // Probably should update regexp & check speed
  822. data[data.length - 1] === '_') {
  823. return false;
  824. }
  825. return true;
  826. }
  827. function constructYamlFloat(data) {
  828. var value, sign, base, digits;
  829. value = data.replace(/_/g, '').toLowerCase();
  830. sign = value[0] === '-' ? -1 : 1;
  831. digits = [];
  832. if ('+-'.indexOf(value[0]) >= 0) {
  833. value = value.slice(1);
  834. }
  835. if (value === '.inf') {
  836. return sign === 1 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
  837. } else if (value === '.nan') {
  838. return NaN;
  839. } else if (value.indexOf(':') >= 0) {
  840. value.split(':').forEach(function (v) {
  841. digits.unshift(parseFloat(v, 10));
  842. });
  843. value = 0.0;
  844. base = 1;
  845. digits.forEach(function (d) {
  846. value += d * base;
  847. base *= 60;
  848. });
  849. return sign * value;
  850. }
  851. return sign * parseFloat(value, 10);
  852. }
  853. var SCIENTIFIC_WITHOUT_DOT = /^[-+]?[0-9]+e/;
  854. function representYamlFloat(object, style) {
  855. var res;
  856. if (isNaN(object)) {
  857. switch (style) {
  858. case 'lowercase':
  859. return '.nan';
  860. case 'uppercase':
  861. return '.NAN';
  862. case 'camelcase':
  863. return '.NaN';
  864. }
  865. } else if (Number.POSITIVE_INFINITY === object) {
  866. switch (style) {
  867. case 'lowercase':
  868. return '.inf';
  869. case 'uppercase':
  870. return '.INF';
  871. case 'camelcase':
  872. return '.Inf';
  873. }
  874. } else if (Number.NEGATIVE_INFINITY === object) {
  875. switch (style) {
  876. case 'lowercase':
  877. return '-.inf';
  878. case 'uppercase':
  879. return '-.INF';
  880. case 'camelcase':
  881. return '-.Inf';
  882. }
  883. } else if (common.isNegativeZero(object)) {
  884. return '-0.0';
  885. }
  886. res = object.toString(10); // JS stringifier can build scientific format without dots: 5e-100,
  887. // while YAML requres dot: 5.e-100. Fix it with simple hack
  888. return SCIENTIFIC_WITHOUT_DOT.test(res) ? res.replace('e', '.e') : res;
  889. }
  890. function isFloat(object) {
  891. return Object.prototype.toString.call(object) === '[object Number]' && (object % 1 !== 0 || common.isNegativeZero(object));
  892. }
  893. var float_1 = new type('tag:yaml.org,2002:float', {
  894. kind: 'scalar',
  895. resolve: resolveYamlFloat,
  896. construct: constructYamlFloat,
  897. predicate: isFloat,
  898. represent: representYamlFloat,
  899. defaultStyle: 'lowercase'
  900. });
  901. var json = new schema({
  902. include: [failsafe],
  903. implicit: [_null, bool, int_1, float_1]
  904. });
  905. var core = new schema({
  906. include: [json]
  907. });
  908. var YAML_DATE_REGEXP = new RegExp('^([0-9][0-9][0-9][0-9])' + // [1] year
  909. '-([0-9][0-9])' + // [2] month
  910. '-([0-9][0-9])$'); // [3] day
  911. var YAML_TIMESTAMP_REGEXP = new RegExp('^([0-9][0-9][0-9][0-9])' + // [1] year
  912. '-([0-9][0-9]?)' + // [2] month
  913. '-([0-9][0-9]?)' + // [3] day
  914. '(?:[Tt]|[ \\t]+)' + // ...
  915. '([0-9][0-9]?)' + // [4] hour
  916. ':([0-9][0-9])' + // [5] minute
  917. ':([0-9][0-9])' + // [6] second
  918. '(?:\\.([0-9]*))?' + // [7] fraction
  919. '(?:[ \\t]*(Z|([-+])([0-9][0-9]?)' + // [8] tz [9] tz_sign [10] tz_hour
  920. '(?::([0-9][0-9]))?))?$'); // [11] tz_minute
  921. function resolveYamlTimestamp(data) {
  922. if (data === null) return false;
  923. if (YAML_DATE_REGEXP.exec(data) !== null) return true;
  924. if (YAML_TIMESTAMP_REGEXP.exec(data) !== null) return true;
  925. return false;
  926. }
  927. function constructYamlTimestamp(data) {
  928. var match,
  929. year,
  930. month,
  931. day,
  932. hour,
  933. minute,
  934. second,
  935. fraction = 0,
  936. delta = null,
  937. tz_hour,
  938. tz_minute,
  939. date;
  940. match = YAML_DATE_REGEXP.exec(data);
  941. if (match === null) match = YAML_TIMESTAMP_REGEXP.exec(data);
  942. if (match === null) throw new Error('Date resolve error'); // match: [1] year [2] month [3] day
  943. year = +match[1];
  944. month = +match[2] - 1; // JS month starts with 0
  945. day = +match[3];
  946. if (!match[4]) {
  947. // no hour
  948. return new Date(Date.UTC(year, month, day));
  949. } // match: [4] hour [5] minute [6] second [7] fraction
  950. hour = +match[4];
  951. minute = +match[5];
  952. second = +match[6];
  953. if (match[7]) {
  954. fraction = match[7].slice(0, 3);
  955. while (fraction.length < 3) {
  956. // milli-seconds
  957. fraction += '0';
  958. }
  959. fraction = +fraction;
  960. } // match: [8] tz [9] tz_sign [10] tz_hour [11] tz_minute
  961. if (match[9]) {
  962. tz_hour = +match[10];
  963. tz_minute = +(match[11] || 0);
  964. delta = (tz_hour * 60 + tz_minute) * 60000; // delta in mili-seconds
  965. if (match[9] === '-') delta = -delta;
  966. }
  967. date = new Date(Date.UTC(year, month, day, hour, minute, second, fraction));
  968. if (delta) date.setTime(date.getTime() - delta);
  969. return date;
  970. }
  971. function representYamlTimestamp(object
  972. /*, style*/
  973. ) {
  974. return object.toISOString();
  975. }
  976. var timestamp = new type('tag:yaml.org,2002:timestamp', {
  977. kind: 'scalar',
  978. resolve: resolveYamlTimestamp,
  979. construct: constructYamlTimestamp,
  980. instanceOf: Date,
  981. represent: representYamlTimestamp
  982. });
  983. function resolveYamlMerge(data) {
  984. return data === '<<' || data === null;
  985. }
  986. var merge = new type('tag:yaml.org,2002:merge', {
  987. kind: 'scalar',
  988. resolve: resolveYamlMerge
  989. });
  990. /*eslint-disable no-bitwise*/
  991. var NodeBuffer;
  992. try {
  993. // A trick for browserified version, to not include `Buffer` shim
  994. var _require = commonjsRequire;
  995. NodeBuffer = _require('buffer').Buffer;
  996. } catch (__) {} // [ 64, 65, 66 ] -> [ padding, CR, LF ]
  997. var BASE64_MAP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\n\r';
  998. function resolveYamlBinary(data) {
  999. if (data === null) return false;
  1000. var code,
  1001. idx,
  1002. bitlen = 0,
  1003. max = data.length,
  1004. map = BASE64_MAP; // Convert one by one.
  1005. for (idx = 0; idx < max; idx++) {
  1006. code = map.indexOf(data.charAt(idx)); // Skip CR/LF
  1007. if (code > 64) continue; // Fail on illegal characters
  1008. if (code < 0) return false;
  1009. bitlen += 6;
  1010. } // If there are any bits left, source was corrupted
  1011. return bitlen % 8 === 0;
  1012. }
  1013. function constructYamlBinary(data) {
  1014. var idx,
  1015. tailbits,
  1016. input = data.replace(/[\r\n=]/g, ''),
  1017. // remove CR/LF & padding to simplify scan
  1018. max = input.length,
  1019. map = BASE64_MAP,
  1020. bits = 0,
  1021. result = []; // Collect by 6*4 bits (3 bytes)
  1022. for (idx = 0; idx < max; idx++) {
  1023. if (idx % 4 === 0 && idx) {
  1024. result.push(bits >> 16 & 0xFF);
  1025. result.push(bits >> 8 & 0xFF);
  1026. result.push(bits & 0xFF);
  1027. }
  1028. bits = bits << 6 | map.indexOf(input.charAt(idx));
  1029. } // Dump tail
  1030. tailbits = max % 4 * 6;
  1031. if (tailbits === 0) {
  1032. result.push(bits >> 16 & 0xFF);
  1033. result.push(bits >> 8 & 0xFF);
  1034. result.push(bits & 0xFF);
  1035. } else if (tailbits === 18) {
  1036. result.push(bits >> 10 & 0xFF);
  1037. result.push(bits >> 2 & 0xFF);
  1038. } else if (tailbits === 12) {
  1039. result.push(bits >> 4 & 0xFF);
  1040. } // Wrap into Buffer for NodeJS and leave Array for browser
  1041. if (NodeBuffer) {
  1042. // Support node 6.+ Buffer API when available
  1043. return NodeBuffer.from ? NodeBuffer.from(result) : new NodeBuffer(result);
  1044. }
  1045. return result;
  1046. }
  1047. function representYamlBinary(object
  1048. /*, style*/
  1049. ) {
  1050. var result = '',
  1051. bits = 0,
  1052. idx,
  1053. tail,
  1054. max = object.length,
  1055. map = BASE64_MAP; // Convert every three bytes to 4 ASCII characters.
  1056. for (idx = 0; idx < max; idx++) {
  1057. if (idx % 3 === 0 && idx) {
  1058. result += map[bits >> 18 & 0x3F];
  1059. result += map[bits >> 12 & 0x3F];
  1060. result += map[bits >> 6 & 0x3F];
  1061. result += map[bits & 0x3F];
  1062. }
  1063. bits = (bits << 8) + object[idx];
  1064. } // Dump tail
  1065. tail = max % 3;
  1066. if (tail === 0) {
  1067. result += map[bits >> 18 & 0x3F];
  1068. result += map[bits >> 12 & 0x3F];
  1069. result += map[bits >> 6 & 0x3F];
  1070. result += map[bits & 0x3F];
  1071. } else if (tail === 2) {
  1072. result += map[bits >> 10 & 0x3F];
  1073. result += map[bits >> 4 & 0x3F];
  1074. result += map[bits << 2 & 0x3F];
  1075. result += map[64];
  1076. } else if (tail === 1) {
  1077. result += map[bits >> 2 & 0x3F];
  1078. result += map[bits << 4 & 0x3F];
  1079. result += map[64];
  1080. result += map[64];
  1081. }
  1082. return result;
  1083. }
  1084. function isBinary(object) {
  1085. return NodeBuffer && NodeBuffer.isBuffer(object);
  1086. }
  1087. var binary = new type('tag:yaml.org,2002:binary', {
  1088. kind: 'scalar',
  1089. resolve: resolveYamlBinary,
  1090. construct: constructYamlBinary,
  1091. predicate: isBinary,
  1092. represent: representYamlBinary
  1093. });
  1094. var _hasOwnProperty$1 = Object.prototype.hasOwnProperty;
  1095. var _toString = Object.prototype.toString;
  1096. function resolveYamlOmap(data) {
  1097. if (data === null) return true;
  1098. var objectKeys = [],
  1099. index,
  1100. length,
  1101. pair,
  1102. pairKey,
  1103. pairHasKey,
  1104. object = data;
  1105. for (index = 0, length = object.length; index < length; index += 1) {
  1106. pair = object[index];
  1107. pairHasKey = false;
  1108. if (_toString.call(pair) !== '[object Object]') return false;
  1109. for (pairKey in pair) {
  1110. if (_hasOwnProperty$1.call(pair, pairKey)) {
  1111. if (!pairHasKey) pairHasKey = true;else return false;
  1112. }
  1113. }
  1114. if (!pairHasKey) return false;
  1115. if (objectKeys.indexOf(pairKey) === -1) objectKeys.push(pairKey);else return false;
  1116. }
  1117. return true;
  1118. }
  1119. function constructYamlOmap(data) {
  1120. return data !== null ? data : [];
  1121. }
  1122. var omap = new type('tag:yaml.org,2002:omap', {
  1123. kind: 'sequence',
  1124. resolve: resolveYamlOmap,
  1125. construct: constructYamlOmap
  1126. });
  1127. var _toString$1 = Object.prototype.toString;
  1128. function resolveYamlPairs(data) {
  1129. if (data === null) return true;
  1130. var index,
  1131. length,
  1132. pair,
  1133. keys,
  1134. result,
  1135. object = data;
  1136. result = new Array(object.length);
  1137. for (index = 0, length = object.length; index < length; index += 1) {
  1138. pair = object[index];
  1139. if (_toString$1.call(pair) !== '[object Object]') return false;
  1140. keys = Object.keys(pair);
  1141. if (keys.length !== 1) return false;
  1142. result[index] = [keys[0], pair[keys[0]]];
  1143. }
  1144. return true;
  1145. }
  1146. function constructYamlPairs(data) {
  1147. if (data === null) return [];
  1148. var index,
  1149. length,
  1150. pair,
  1151. keys,
  1152. result,
  1153. object = data;
  1154. result = new Array(object.length);
  1155. for (index = 0, length = object.length; index < length; index += 1) {
  1156. pair = object[index];
  1157. keys = Object.keys(pair);
  1158. result[index] = [keys[0], pair[keys[0]]];
  1159. }
  1160. return result;
  1161. }
  1162. var pairs = new type('tag:yaml.org,2002:pairs', {
  1163. kind: 'sequence',
  1164. resolve: resolveYamlPairs,
  1165. construct: constructYamlPairs
  1166. });
  1167. var _hasOwnProperty$2 = Object.prototype.hasOwnProperty;
  1168. function resolveYamlSet(data) {
  1169. if (data === null) return true;
  1170. var key,
  1171. object = data;
  1172. for (key in object) {
  1173. if (_hasOwnProperty$2.call(object, key)) {
  1174. if (object[key] !== null) return false;
  1175. }
  1176. }
  1177. return true;
  1178. }
  1179. function constructYamlSet(data) {
  1180. return data !== null ? data : {};
  1181. }
  1182. var set$1 = new type('tag:yaml.org,2002:set', {
  1183. kind: 'mapping',
  1184. resolve: resolveYamlSet,
  1185. construct: constructYamlSet
  1186. });
  1187. var default_safe = new schema({
  1188. include: [core],
  1189. implicit: [timestamp, merge],
  1190. explicit: [binary, omap, pairs, set$1]
  1191. });
  1192. function resolveJavascriptUndefined() {
  1193. return true;
  1194. }
  1195. function constructJavascriptUndefined() {
  1196. /*eslint-disable no-undefined*/
  1197. return undefined;
  1198. }
  1199. function representJavascriptUndefined() {
  1200. return '';
  1201. }
  1202. function isUndefined(object) {
  1203. return typeof object === 'undefined';
  1204. }
  1205. var _undefined = new type('tag:yaml.org,2002:js/undefined', {
  1206. kind: 'scalar',
  1207. resolve: resolveJavascriptUndefined,
  1208. construct: constructJavascriptUndefined,
  1209. predicate: isUndefined,
  1210. represent: representJavascriptUndefined
  1211. });
  1212. function resolveJavascriptRegExp(data) {
  1213. if (data === null) return false;
  1214. if (data.length === 0) return false;
  1215. var regexp = data,
  1216. tail = /\/([gim]*)$/.exec(data),
  1217. modifiers = ''; // if regexp starts with '/' it can have modifiers and must be properly closed
  1218. // `/foo/gim` - modifiers tail can be maximum 3 chars
  1219. if (regexp[0] === '/') {
  1220. if (tail) modifiers = tail[1];
  1221. if (modifiers.length > 3) return false; // if expression starts with /, is should be properly terminated
  1222. if (regexp[regexp.length - modifiers.length - 1] !== '/') return false;
  1223. }
  1224. return true;
  1225. }
  1226. function constructJavascriptRegExp(data) {
  1227. var regexp = data,
  1228. tail = /\/([gim]*)$/.exec(data),
  1229. modifiers = ''; // `/foo/gim` - tail can be maximum 4 chars
  1230. if (regexp[0] === '/') {
  1231. if (tail) modifiers = tail[1];
  1232. regexp = regexp.slice(1, regexp.length - modifiers.length - 1);
  1233. }
  1234. return new RegExp(regexp, modifiers);
  1235. }
  1236. function representJavascriptRegExp(object
  1237. /*, style*/
  1238. ) {
  1239. var result = '/' + object.source + '/';
  1240. if (object.global) result += 'g';
  1241. if (object.multiline) result += 'm';
  1242. if (object.ignoreCase) result += 'i';
  1243. return result;
  1244. }
  1245. function isRegExp(object) {
  1246. return Object.prototype.toString.call(object) === '[object RegExp]';
  1247. }
  1248. var regexp = new type('tag:yaml.org,2002:js/regexp', {
  1249. kind: 'scalar',
  1250. resolve: resolveJavascriptRegExp,
  1251. construct: constructJavascriptRegExp,
  1252. predicate: isRegExp,
  1253. represent: representJavascriptRegExp
  1254. });
  1255. var esprima; // Browserified version does not have esprima
  1256. //
  1257. // 1. For node.js just require module as deps
  1258. // 2. For browser try to require mudule via external AMD system.
  1259. // If not found - try to fallback to window.esprima. If not
  1260. // found too - then fail to parse.
  1261. //
  1262. try {
  1263. // workaround to exclude package from browserify list.
  1264. var _require$1 = commonjsRequire;
  1265. esprima = _require$1('esprima');
  1266. } catch (_) {
  1267. /*global window */
  1268. if (typeof window !== 'undefined') esprima = window.esprima;
  1269. }
  1270. function resolveJavascriptFunction(data) {
  1271. if (data === null) return false;
  1272. try {
  1273. var source = '(' + data + ')',
  1274. ast = esprima.parse(source, {
  1275. range: true
  1276. });
  1277. if (ast.type !== 'Program' || ast.body.length !== 1 || ast.body[0].type !== 'ExpressionStatement' || ast.body[0].expression.type !== 'ArrowFunctionExpression' && ast.body[0].expression.type !== 'FunctionExpression') {
  1278. return false;
  1279. }
  1280. return true;
  1281. } catch (err) {
  1282. return false;
  1283. }
  1284. }
  1285. function constructJavascriptFunction(data) {
  1286. /*jslint evil:true*/
  1287. var source = '(' + data + ')',
  1288. ast = esprima.parse(source, {
  1289. range: true
  1290. }),
  1291. params = [],
  1292. body;
  1293. if (ast.type !== 'Program' || ast.body.length !== 1 || ast.body[0].type !== 'ExpressionStatement' || ast.body[0].expression.type !== 'ArrowFunctionExpression' && ast.body[0].expression.type !== 'FunctionExpression') {
  1294. throw new Error('Failed to resolve function');
  1295. }
  1296. ast.body[0].expression.params.forEach(function (param) {
  1297. params.push(param.name);
  1298. });
  1299. body = ast.body[0].expression.body.range; // Esprima's ranges include the first '{' and the last '}' characters on
  1300. // function expressions. So cut them out.
  1301. if (ast.body[0].expression.body.type === 'BlockStatement') {
  1302. /*eslint-disable no-new-func*/
  1303. return new Function(params, source.slice(body[0] + 1, body[1] - 1));
  1304. } // ES6 arrow functions can omit the BlockStatement. In that case, just return
  1305. // the body.
  1306. /*eslint-disable no-new-func*/
  1307. return new Function(params, 'return ' + source.slice(body[0], body[1]));
  1308. }
  1309. function representJavascriptFunction(object
  1310. /*, style*/
  1311. ) {
  1312. return object.toString();
  1313. }
  1314. function isFunction(object) {
  1315. return Object.prototype.toString.call(object) === '[object Function]';
  1316. }
  1317. var _function = new type('tag:yaml.org,2002:js/function', {
  1318. kind: 'scalar',
  1319. resolve: resolveJavascriptFunction,
  1320. construct: constructJavascriptFunction,
  1321. predicate: isFunction,
  1322. represent: representJavascriptFunction
  1323. });
  1324. var default_full = schema.DEFAULT = new schema({
  1325. include: [default_safe],
  1326. explicit: [_undefined, regexp, _function]
  1327. });
  1328. /*eslint-disable max-len,no-use-before-define*/
  1329. var _hasOwnProperty = Object.prototype.hasOwnProperty;
  1330. var CONTEXT_FLOW_IN = 1;
  1331. var CONTEXT_FLOW_OUT = 2;
  1332. var CONTEXT_BLOCK_IN = 3;
  1333. var CONTEXT_BLOCK_OUT = 4;
  1334. var CHOMPING_CLIP = 1;
  1335. var CHOMPING_STRIP = 2;
  1336. var CHOMPING_KEEP = 3;
  1337. var PATTERN_NON_PRINTABLE = /[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/;
  1338. var PATTERN_NON_ASCII_LINE_BREAKS = /[\x85\u2028\u2029]/;
  1339. var PATTERN_FLOW_INDICATORS = /[,\[\]\{\}]/;
  1340. var PATTERN_TAG_HANDLE = /^(?:!|!!|![a-z\-]+!)$/i;
  1341. var PATTERN_TAG_URI = /^(?:!|[^,\[\]\{\}])(?:%[0-9a-f]{2}|[0-9a-z\-#;\/\?:@&=\+\$,_\.!~\*'\(\)\[\]])*$/i;
  1342. function _class(obj) {
  1343. return Object.prototype.toString.call(obj);
  1344. }
  1345. function is_EOL(c) {
  1346. return c === 0x0A
  1347. /* LF */
  1348. || c === 0x0D
  1349. /* CR */
  1350. ;
  1351. }
  1352. function is_WHITE_SPACE(c) {
  1353. return c === 0x09
  1354. /* Tab */
  1355. || c === 0x20
  1356. /* Space */
  1357. ;
  1358. }
  1359. function is_WS_OR_EOL(c) {
  1360. return c === 0x09
  1361. /* Tab */
  1362. || c === 0x20
  1363. /* Space */
  1364. || c === 0x0A
  1365. /* LF */
  1366. || c === 0x0D
  1367. /* CR */
  1368. ;
  1369. }
  1370. function is_FLOW_INDICATOR(c) {
  1371. return c === 0x2C
  1372. /* , */
  1373. || c === 0x5B
  1374. /* [ */
  1375. || c === 0x5D
  1376. /* ] */
  1377. || c === 0x7B
  1378. /* { */
  1379. || c === 0x7D
  1380. /* } */
  1381. ;
  1382. }
  1383. function fromHexCode(c) {
  1384. var lc;
  1385. if (0x30
  1386. /* 0 */
  1387. <= c && c <= 0x39
  1388. /* 9 */
  1389. ) {
  1390. return c - 0x30;
  1391. }
  1392. /*eslint-disable no-bitwise*/
  1393. lc = c | 0x20;
  1394. if (0x61
  1395. /* a */
  1396. <= lc && lc <= 0x66
  1397. /* f */
  1398. ) {
  1399. return lc - 0x61 + 10;
  1400. }
  1401. return -1;
  1402. }
  1403. function escapedHexLen(c) {
  1404. if (c === 0x78
  1405. /* x */
  1406. ) {
  1407. return 2;
  1408. }
  1409. if (c === 0x75
  1410. /* u */
  1411. ) {
  1412. return 4;
  1413. }
  1414. if (c === 0x55
  1415. /* U */
  1416. ) {
  1417. return 8;
  1418. }
  1419. return 0;
  1420. }
  1421. function fromDecimalCode(c) {
  1422. if (0x30
  1423. /* 0 */
  1424. <= c && c <= 0x39
  1425. /* 9 */
  1426. ) {
  1427. return c - 0x30;
  1428. }
  1429. return -1;
  1430. }
  1431. function simpleEscapeSequence(c) {
  1432. /* eslint-disable indent */
  1433. return c === 0x30
  1434. /* 0 */
  1435. ? '\x00' : c === 0x61
  1436. /* a */
  1437. ? '\x07' : c === 0x62
  1438. /* b */
  1439. ? '\x08' : c === 0x74
  1440. /* t */
  1441. ? '\x09' : c === 0x09
  1442. /* Tab */
  1443. ? '\x09' : c === 0x6E
  1444. /* n */
  1445. ? '\x0A' : c === 0x76
  1446. /* v */
  1447. ? '\x0B' : c === 0x66
  1448. /* f */
  1449. ? '\x0C' : c === 0x72
  1450. /* r */
  1451. ? '\x0D' : c === 0x65
  1452. /* e */
  1453. ? '\x1B' : c === 0x20
  1454. /* Space */
  1455. ? ' ' : c === 0x22
  1456. /* " */
  1457. ? '\x22' : c === 0x2F
  1458. /* / */
  1459. ? '/' : c === 0x5C
  1460. /* \ */
  1461. ? '\x5C' : c === 0x4E
  1462. /* N */
  1463. ? '\x85' : c === 0x5F
  1464. /* _ */
  1465. ? '\xA0' : c === 0x4C
  1466. /* L */
  1467. ? '\u2028' : c === 0x50
  1468. /* P */
  1469. ? '\u2029' : '';
  1470. }
  1471. function charFromCodepoint(c) {
  1472. if (c <= 0xFFFF) {
  1473. return String.fromCharCode(c);
  1474. } // Encode UTF-16 surrogate pair
  1475. // https://en.wikipedia.org/wiki/UTF-16#Code_points_U.2B010000_to_U.2B10FFFF
  1476. return String.fromCharCode((c - 0x010000 >> 10) + 0xD800, (c - 0x010000 & 0x03FF) + 0xDC00);
  1477. }
  1478. var simpleEscapeCheck = new Array(256); // integer, for fast access
  1479. var simpleEscapeMap = new Array(256);
  1480. for (var i = 0; i < 256; i++) {
  1481. simpleEscapeCheck[i] = simpleEscapeSequence(i) ? 1 : 0;
  1482. simpleEscapeMap[i] = simpleEscapeSequence(i);
  1483. }
  1484. function State(input, options) {
  1485. this.input = input;
  1486. this.filename = options['filename'] || null;
  1487. this.schema = options['schema'] || default_full;
  1488. this.onWarning = options['onWarning'] || null;
  1489. this.legacy = options['legacy'] || false;
  1490. this.json = options['json'] || false;
  1491. this.listener = options['listener'] || null;
  1492. this.implicitTypes = this.schema.compiledImplicit;
  1493. this.typeMap = this.schema.compiledTypeMap;
  1494. this.length = input.length;
  1495. this.position = 0;
  1496. this.line = 0;
  1497. this.lineStart = 0;
  1498. this.lineIndent = 0;
  1499. this.documents = [];
  1500. /*
  1501. this.version;
  1502. this.checkLineBreaks;
  1503. this.tagMap;
  1504. this.anchorMap;
  1505. this.tag;
  1506. this.anchor;
  1507. this.kind;
  1508. this.result;*/
  1509. }
  1510. function generateError(state, message) {
  1511. return new exception(message, new mark(state.filename, state.input, state.position, state.line, state.position - state.lineStart));
  1512. }
  1513. function throwError(state, message) {
  1514. throw generateError(state, message);
  1515. }
  1516. function throwWarning(state, message) {
  1517. if (state.onWarning) {
  1518. state.onWarning.call(null, generateError(state, message));
  1519. }
  1520. }
  1521. var directiveHandlers = {
  1522. YAML: function handleYamlDirective(state, name, args) {
  1523. var match, major, minor;
  1524. if (state.version !== null) {
  1525. throwError(state, 'duplication of %YAML directive');
  1526. }
  1527. if (args.length !== 1) {
  1528. throwError(state, 'YAML directive accepts exactly one argument');
  1529. }
  1530. match = /^([0-9]+)\.([0-9]+)$/.exec(args[0]);
  1531. if (match === null) {
  1532. throwError(state, 'ill-formed argument of the YAML directive');
  1533. }
  1534. major = parseInt(match[1], 10);
  1535. minor = parseInt(match[2], 10);
  1536. if (major !== 1) {
  1537. throwError(state, 'unacceptable YAML version of the document');
  1538. }
  1539. state.version = args[0];
  1540. state.checkLineBreaks = minor < 2;
  1541. if (minor !== 1 && minor !== 2) {
  1542. throwWarning(state, 'unsupported YAML version of the document');
  1543. }
  1544. },
  1545. TAG: function handleTagDirective(state, name, args) {
  1546. var handle, prefix;
  1547. if (args.length !== 2) {
  1548. throwError(state, 'TAG directive accepts exactly two arguments');
  1549. }
  1550. handle = args[0];
  1551. prefix = args[1];
  1552. if (!PATTERN_TAG_HANDLE.test(handle)) {
  1553. throwError(state, 'ill-formed tag handle (first argument) of the TAG directive');
  1554. }
  1555. if (_hasOwnProperty.call(state.tagMap, handle)) {
  1556. throwError(state, 'there is a previously declared suffix for "' + handle + '" tag handle');
  1557. }
  1558. if (!PATTERN_TAG_URI.test(prefix)) {
  1559. throwError(state, 'ill-formed tag prefix (second argument) of the TAG directive');
  1560. }
  1561. state.tagMap[handle] = prefix;
  1562. }
  1563. };
  1564. function captureSegment(state, start, end, checkJson) {
  1565. var _position, _length, _character, _result;
  1566. if (start < end) {
  1567. _result = state.input.slice(start, end);
  1568. if (checkJson) {
  1569. for (_position = 0, _length = _result.length; _position < _length; _position += 1) {
  1570. _character = _result.charCodeAt(_position);
  1571. if (!(_character === 0x09 || 0x20 <= _character && _character <= 0x10FFFF)) {
  1572. throwError(state, 'expected valid JSON character');
  1573. }
  1574. }
  1575. } else if (PATTERN_NON_PRINTABLE.test(_result)) {
  1576. throwError(state, 'the stream contains non-printable characters');
  1577. }
  1578. state.result += _result;
  1579. }
  1580. }
  1581. function mergeMappings(state, destination, source, overridableKeys) {
  1582. var sourceKeys, key, index, quantity;
  1583. if (!common.isObject(source)) {
  1584. throwError(state, 'cannot merge mappings; the provided source object is unacceptable');
  1585. }
  1586. sourceKeys = Object.keys(source);
  1587. for (index = 0, quantity = sourceKeys.length; index < quantity; index += 1) {
  1588. key = sourceKeys[index];
  1589. if (!_hasOwnProperty.call(destination, key)) {
  1590. destination[key] = source[key];
  1591. overridableKeys[key] = true;
  1592. }
  1593. }
  1594. }
  1595. function storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, startLine, startPos) {
  1596. var index, quantity; // The output is a plain object here, so keys can only be strings.
  1597. // We need to convert keyNode to a string, but doing so can hang the process
  1598. // (deeply nested arrays that explode exponentially using aliases).
  1599. if (Array.isArray(keyNode)) {
  1600. keyNode = Array.prototype.slice.call(keyNode);
  1601. for (index = 0, quantity = keyNode.length; index < quantity; index += 1) {
  1602. if (Array.isArray(keyNode[index])) {
  1603. throwError(state, 'nested arrays are not supported inside keys');
  1604. }
  1605. if (typeof keyNode === 'object' && _class(keyNode[index]) === '[object Object]') {
  1606. keyNode[index] = '[object Object]';
  1607. }
  1608. }
  1609. } // Avoid code execution in load() via toString property
  1610. // (still use its own toString for arrays, timestamps,
  1611. // and whatever user schema extensions happen to have @@toStringTag)
  1612. if (typeof keyNode === 'object' && _class(keyNode) === '[object Object]') {
  1613. keyNode = '[object Object]';
  1614. }
  1615. keyNode = String(keyNode);
  1616. if (_result === null) {
  1617. _result = {};
  1618. }
  1619. if (keyTag === 'tag:yaml.org,2002:merge') {
  1620. if (Array.isArray(valueNode)) {
  1621. for (index = 0, quantity = valueNode.length; index < quantity; index += 1) {
  1622. mergeMappings(state, _result, valueNode[index], overridableKeys);
  1623. }
  1624. } else {
  1625. mergeMappings(state, _result, valueNode, overridableKeys);
  1626. }
  1627. } else {
  1628. if (!state.json && !_hasOwnProperty.call(overridableKeys, keyNode) && _hasOwnProperty.call(_result, keyNode)) {
  1629. state.line = startLine || state.line;
  1630. state.position = startPos || state.position;
  1631. throwError(state, 'duplicated mapping key');
  1632. }
  1633. _result[keyNode] = valueNode;
  1634. delete overridableKeys[keyNode];
  1635. }
  1636. return _result;
  1637. }
  1638. function readLineBreak(state) {
  1639. var ch;
  1640. ch = state.input.charCodeAt(state.position);
  1641. if (ch === 0x0A
  1642. /* LF */
  1643. ) {
  1644. state.position++;
  1645. } else if (ch === 0x0D
  1646. /* CR */
  1647. ) {
  1648. state.position++;
  1649. if (state.input.charCodeAt(state.position) === 0x0A
  1650. /* LF */
  1651. ) {
  1652. state.position++;
  1653. }
  1654. } else {
  1655. throwError(state, 'a line break is expected');
  1656. }
  1657. state.line += 1;
  1658. state.lineStart = state.position;
  1659. }
  1660. function skipSeparationSpace(state, allowComments, checkIndent) {
  1661. var lineBreaks = 0,
  1662. ch = state.input.charCodeAt(state.position);
  1663. while (ch !== 0) {
  1664. while (is_WHITE_SPACE(ch)) {
  1665. ch = state.input.charCodeAt(++state.position);
  1666. }
  1667. if (allowComments && ch === 0x23
  1668. /* # */
  1669. ) {
  1670. do {
  1671. ch = state.input.charCodeAt(++state.position);
  1672. } while (ch !== 0x0A
  1673. /* LF */
  1674. && ch !== 0x0D
  1675. /* CR */
  1676. && ch !== 0);
  1677. }
  1678. if (is_EOL(ch)) {
  1679. readLineBreak(state);
  1680. ch = state.input.charCodeAt(state.position);
  1681. lineBreaks++;
  1682. state.lineIndent = 0;
  1683. while (ch === 0x20
  1684. /* Space */
  1685. ) {
  1686. state.lineIndent++;
  1687. ch = state.input.charCodeAt(++state.position);
  1688. }
  1689. } else {
  1690. break;
  1691. }
  1692. }
  1693. if (checkIndent !== -1 && lineBreaks !== 0 && state.lineIndent < checkIndent) {
  1694. throwWarning(state, 'deficient indentation');
  1695. }
  1696. return lineBreaks;
  1697. }
  1698. function testDocumentSeparator(state) {
  1699. var _position = state.position,
  1700. ch;
  1701. ch = state.input.charCodeAt(_position); // Condition state.position === state.lineStart is tested
  1702. // in parent on each call, for efficiency. No needs to test here again.
  1703. if ((ch === 0x2D
  1704. /* - */
  1705. || ch === 0x2E
  1706. /* . */
  1707. ) && ch === state.input.charCodeAt(_position + 1) && ch === state.input.charCodeAt(_position + 2)) {
  1708. _position += 3;
  1709. ch = state.input.charCodeAt(_position);
  1710. if (ch === 0 || is_WS_OR_EOL(ch)) {
  1711. return true;
  1712. }
  1713. }
  1714. return false;
  1715. }
  1716. function writeFoldedLines(state, count) {
  1717. if (count === 1) {
  1718. state.result += ' ';
  1719. } else if (count > 1) {
  1720. state.result += common.repeat('\n', count - 1);
  1721. }
  1722. }
  1723. function readPlainScalar(state, nodeIndent, withinFlowCollection) {
  1724. var preceding,
  1725. following,
  1726. captureStart,
  1727. captureEnd,
  1728. hasPendingContent,
  1729. _line,
  1730. _lineStart,
  1731. _lineIndent,
  1732. _kind = state.kind,
  1733. _result = state.result,
  1734. ch;
  1735. ch = state.input.charCodeAt(state.position);
  1736. if (is_WS_OR_EOL(ch) || is_FLOW_INDICATOR(ch) || ch === 0x23
  1737. /* # */
  1738. || ch === 0x26
  1739. /* & */
  1740. || ch === 0x2A
  1741. /* * */
  1742. || ch === 0x21
  1743. /* ! */
  1744. || ch === 0x7C
  1745. /* | */
  1746. || ch === 0x3E
  1747. /* > */
  1748. || ch === 0x27
  1749. /* ' */
  1750. || ch === 0x22
  1751. /* " */
  1752. || ch === 0x25
  1753. /* % */
  1754. || ch === 0x40
  1755. /* @ */
  1756. || ch === 0x60
  1757. /* ` */
  1758. ) {
  1759. return false;
  1760. }
  1761. if (ch === 0x3F
  1762. /* ? */
  1763. || ch === 0x2D
  1764. /* - */
  1765. ) {
  1766. following = state.input.charCodeAt(state.position + 1);
  1767. if (is_WS_OR_EOL(following) || withinFlowCollection && is_FLOW_INDICATOR(following)) {
  1768. return false;
  1769. }
  1770. }
  1771. state.kind = 'scalar';
  1772. state.result = '';
  1773. captureStart = captureEnd = state.position;
  1774. hasPendingContent = false;
  1775. while (ch !== 0) {
  1776. if (ch === 0x3A
  1777. /* : */
  1778. ) {
  1779. following = state.input.charCodeAt(state.position + 1);
  1780. if (is_WS_OR_EOL(following) || withinFlowCollection && is_FLOW_INDICATOR(following)) {
  1781. break;
  1782. }
  1783. } else if (ch === 0x23
  1784. /* # */
  1785. ) {
  1786. preceding = state.input.charCodeAt(state.position - 1);
  1787. if (is_WS_OR_EOL(preceding)) {
  1788. break;
  1789. }
  1790. } else if (state.position === state.lineStart && testDocumentSeparator(state) || withinFlowCollection && is_FLOW_INDICATOR(ch)) {
  1791. break;
  1792. } else if (is_EOL(ch)) {
  1793. _line = state.line;
  1794. _lineStart = state.lineStart;
  1795. _lineIndent = state.lineIndent;
  1796. skipSeparationSpace(state, false, -1);
  1797. if (state.lineIndent >= nodeIndent) {
  1798. hasPendingContent = true;
  1799. ch = state.input.charCodeAt(state.position);
  1800. continue;
  1801. } else {
  1802. state.position = captureEnd;
  1803. state.line = _line;
  1804. state.lineStart = _lineStart;
  1805. state.lineIndent = _lineIndent;
  1806. break;
  1807. }
  1808. }
  1809. if (hasPendingContent) {
  1810. captureSegment(state, captureStart, captureEnd, false);
  1811. writeFoldedLines(state, state.line - _line);
  1812. captureStart = captureEnd = state.position;
  1813. hasPendingContent = false;
  1814. }
  1815. if (!is_WHITE_SPACE(ch)) {
  1816. captureEnd = state.position + 1;
  1817. }
  1818. ch = state.input.charCodeAt(++state.position);
  1819. }
  1820. captureSegment(state, captureStart, captureEnd, false);
  1821. if (state.result) {
  1822. return true;
  1823. }
  1824. state.kind = _kind;
  1825. state.result = _result;
  1826. return false;
  1827. }
  1828. function readSingleQuotedScalar(state, nodeIndent) {
  1829. var ch, captureStart, captureEnd;
  1830. ch = state.input.charCodeAt(state.position);
  1831. if (ch !== 0x27
  1832. /* ' */
  1833. ) {
  1834. return false;
  1835. }
  1836. state.kind = 'scalar';
  1837. state.result = '';
  1838. state.position++;
  1839. captureStart = captureEnd = state.position;
  1840. while ((ch = state.input.charCodeAt(state.position)) !== 0) {
  1841. if (ch === 0x27
  1842. /* ' */
  1843. ) {
  1844. captureSegment(state, captureStart, state.position, true);
  1845. ch = state.input.charCodeAt(++state.position);
  1846. if (ch === 0x27
  1847. /* ' */
  1848. ) {
  1849. captureStart = state.position;
  1850. state.position++;
  1851. captureEnd = state.position;
  1852. } else {
  1853. return true;
  1854. }
  1855. } else if (is_EOL(ch)) {
  1856. captureSegment(state, captureStart, captureEnd, true);
  1857. writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
  1858. captureStart = captureEnd = state.position;
  1859. } else if (state.position === state.lineStart && testDocumentSeparator(state)) {
  1860. throwError(state, 'unexpected end of the document within a single quoted scalar');
  1861. } else {
  1862. state.position++;
  1863. captureEnd = state.position;
  1864. }
  1865. }
  1866. throwError(state, 'unexpected end of the stream within a single quoted scalar');
  1867. }
  1868. function readDoubleQuotedScalar(state, nodeIndent) {
  1869. var captureStart, captureEnd, hexLength, hexResult, tmp, ch;
  1870. ch = state.input.charCodeAt(state.position);
  1871. if (ch !== 0x22
  1872. /* " */
  1873. ) {
  1874. return false;
  1875. }
  1876. state.kind = 'scalar';
  1877. state.result = '';
  1878. state.position++;
  1879. captureStart = captureEnd = state.position;
  1880. while ((ch = state.input.charCodeAt(state.position)) !== 0) {
  1881. if (ch === 0x22
  1882. /* " */
  1883. ) {
  1884. captureSegment(state, captureStart, state.position, true);
  1885. state.position++;
  1886. return true;
  1887. } else if (ch === 0x5C
  1888. /* \ */
  1889. ) {
  1890. captureSegment(state, captureStart, state.position, true);
  1891. ch = state.input.charCodeAt(++state.position);
  1892. if (is_EOL(ch)) {
  1893. skipSeparationSpace(state, false, nodeIndent); // TODO: rework to inline fn with no type cast?
  1894. } else if (ch < 256 && simpleEscapeCheck[ch]) {
  1895. state.result += simpleEscapeMap[ch];
  1896. state.position++;
  1897. } else if ((tmp = escapedHexLen(ch)) > 0) {
  1898. hexLength = tmp;
  1899. hexResult = 0;
  1900. for (; hexLength > 0; hexLength--) {
  1901. ch = state.input.charCodeAt(++state.position);
  1902. if ((tmp = fromHexCode(ch)) >= 0) {
  1903. hexResult = (hexResult << 4) + tmp;
  1904. } else {
  1905. throwError(state, 'expected hexadecimal character');
  1906. }
  1907. }
  1908. state.result += charFromCodepoint(hexResult);
  1909. state.position++;
  1910. } else {
  1911. throwError(state, 'unknown escape sequence');
  1912. }
  1913. captureStart = captureEnd = state.position;
  1914. } else if (is_EOL(ch)) {
  1915. captureSegment(state, captureStart, captureEnd, true);
  1916. writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
  1917. captureStart = captureEnd = state.position;
  1918. } else if (state.position === state.lineStart && testDocumentSeparator(state)) {
  1919. throwError(state, 'unexpected end of the document within a double quoted scalar');
  1920. } else {
  1921. state.position++;
  1922. captureEnd = state.position;
  1923. }
  1924. }
  1925. throwError(state, 'unexpected end of the stream within a double quoted scalar');
  1926. }
  1927. function readFlowCollection(state, nodeIndent) {
  1928. var readNext = true,
  1929. _line,
  1930. _tag = state.tag,
  1931. _result,
  1932. _anchor = state.anchor,
  1933. following,
  1934. terminator,
  1935. isPair,
  1936. isExplicitPair,
  1937. isMapping,
  1938. overridableKeys = {},
  1939. keyNode,
  1940. keyTag,
  1941. valueNode,
  1942. ch;
  1943. ch = state.input.charCodeAt(state.position);
  1944. if (ch === 0x5B
  1945. /* [ */
  1946. ) {
  1947. terminator = 0x5D;
  1948. /* ] */
  1949. isMapping = false;
  1950. _result = [];
  1951. } else if (ch === 0x7B
  1952. /* { */
  1953. ) {
  1954. terminator = 0x7D;
  1955. /* } */
  1956. isMapping = true;
  1957. _result = {};
  1958. } else {
  1959. return false;
  1960. }
  1961. if (state.anchor !== null) {
  1962. state.anchorMap[state.anchor] = _result;
  1963. }
  1964. ch = state.input.charCodeAt(++state.position);
  1965. while (ch !== 0) {
  1966. skipSeparationSpace(state, true, nodeIndent);
  1967. ch = state.input.charCodeAt(state.position);
  1968. if (ch === terminator) {
  1969. state.position++;
  1970. state.tag = _tag;
  1971. state.anchor = _anchor;
  1972. state.kind = isMapping ? 'mapping' : 'sequence';
  1973. state.result = _result;
  1974. return true;
  1975. } else if (!readNext) {
  1976. throwError(state, 'missed comma between flow collection entries');
  1977. }
  1978. keyTag = keyNode = valueNode = null;
  1979. isPair = isExplicitPair = false;
  1980. if (ch === 0x3F
  1981. /* ? */
  1982. ) {
  1983. following = state.input.charCodeAt(state.position + 1);
  1984. if (is_WS_OR_EOL(following)) {
  1985. isPair = isExplicitPair = true;
  1986. state.position++;
  1987. skipSeparationSpace(state, true, nodeIndent);
  1988. }
  1989. }
  1990. _line = state.line;
  1991. composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
  1992. keyTag = state.tag;
  1993. keyNode = state.result;
  1994. skipSeparationSpace(state, true, nodeIndent);
  1995. ch = state.input.charCodeAt(state.position);
  1996. if ((isExplicitPair || state.line === _line) && ch === 0x3A
  1997. /* : */
  1998. ) {
  1999. isPair = true;
  2000. ch = state.input.charCodeAt(++state.position);
  2001. skipSeparationSpace(state, true, nodeIndent);
  2002. composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
  2003. valueNode = state.result;
  2004. }
  2005. if (isMapping) {
  2006. storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode);
  2007. } else if (isPair) {
  2008. _result.push(storeMappingPair(state, null, overridableKeys, keyTag, keyNode, valueNode));
  2009. } else {
  2010. _result.push(keyNode);
  2011. }
  2012. skipSeparationSpace(state, true, nodeIndent);
  2013. ch = state.input.charCodeAt(state.position);
  2014. if (ch === 0x2C
  2015. /* , */
  2016. ) {
  2017. readNext = true;
  2018. ch = state.input.charCodeAt(++state.position);
  2019. } else {
  2020. readNext = false;
  2021. }
  2022. }
  2023. throwError(state, 'unexpected end of the stream within a flow collection');
  2024. }
  2025. function readBlockScalar(state, nodeIndent) {
  2026. var captureStart,
  2027. folding,
  2028. chomping = CHOMPING_CLIP,
  2029. didReadContent = false,
  2030. detectedIndent = false,
  2031. textIndent = nodeIndent,
  2032. emptyLines = 0,
  2033. atMoreIndented = false,
  2034. tmp,
  2035. ch;
  2036. ch = state.input.charCodeAt(state.position);
  2037. if (ch === 0x7C
  2038. /* | */
  2039. ) {
  2040. folding = false;
  2041. } else if (ch === 0x3E
  2042. /* > */
  2043. ) {
  2044. folding = true;
  2045. } else {
  2046. return false;
  2047. }
  2048. state.kind = 'scalar';
  2049. state.result = '';
  2050. while (ch !== 0) {
  2051. ch = state.input.charCodeAt(++state.position);
  2052. if (ch === 0x2B
  2053. /* + */
  2054. || ch === 0x2D
  2055. /* - */
  2056. ) {
  2057. if (CHOMPING_CLIP === chomping) {
  2058. chomping = ch === 0x2B
  2059. /* + */
  2060. ? CHOMPING_KEEP : CHOMPING_STRIP;
  2061. } else {
  2062. throwError(state, 'repeat of a chomping mode identifier');
  2063. }
  2064. } else if ((tmp = fromDecimalCode(ch)) >= 0) {
  2065. if (tmp === 0) {
  2066. throwError(state, 'bad explicit indentation width of a block scalar; it cannot be less than one');
  2067. } else if (!detectedIndent) {
  2068. textIndent = nodeIndent + tmp - 1;
  2069. detectedIndent = true;
  2070. } else {
  2071. throwError(state, 'repeat of an indentation width identifier');
  2072. }
  2073. } else {
  2074. break;
  2075. }
  2076. }
  2077. if (is_WHITE_SPACE(ch)) {
  2078. do {
  2079. ch = state.input.charCodeAt(++state.position);
  2080. } while (is_WHITE_SPACE(ch));
  2081. if (ch === 0x23
  2082. /* # */
  2083. ) {
  2084. do {
  2085. ch = state.input.charCodeAt(++state.position);
  2086. } while (!is_EOL(ch) && ch !== 0);
  2087. }
  2088. }
  2089. while (ch !== 0) {
  2090. readLineBreak(state);
  2091. state.lineIndent = 0;
  2092. ch = state.input.charCodeAt(state.position);
  2093. while ((!detectedIndent || state.lineIndent < textIndent) && ch === 0x20
  2094. /* Space */
  2095. ) {
  2096. state.lineIndent++;
  2097. ch = state.input.charCodeAt(++state.position);
  2098. }
  2099. if (!detectedIndent && state.lineIndent > textIndent) {
  2100. textIndent = state.lineIndent;
  2101. }
  2102. if (is_EOL(ch)) {
  2103. emptyLines++;
  2104. continue;
  2105. } // End of the scalar.
  2106. if (state.lineIndent < textIndent) {
  2107. // Perform the chomping.
  2108. if (chomping === CHOMPING_KEEP) {
  2109. state.result += common.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines);
  2110. } else if (chomping === CHOMPING_CLIP) {
  2111. if (didReadContent) {
  2112. // i.e. only if the scalar is not empty.
  2113. state.result += '\n';
  2114. }
  2115. } // Break this `while` cycle and go to the funciton's epilogue.
  2116. break;
  2117. } // Folded style: use fancy rules to handle line breaks.
  2118. if (folding) {
  2119. // Lines starting with white space characters (more-indented lines) are not folded.
  2120. if (is_WHITE_SPACE(ch)) {
  2121. atMoreIndented = true; // except for the first content line (cf. Example 8.1)
  2122. state.result += common.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines); // End of more-indented block.
  2123. } else if (atMoreIndented) {
  2124. atMoreIndented = false;
  2125. state.result += common.repeat('\n', emptyLines + 1); // Just one line break - perceive as the same line.
  2126. } else if (emptyLines === 0) {
  2127. if (didReadContent) {
  2128. // i.e. only if we have already read some scalar content.
  2129. state.result += ' ';
  2130. } // Several line breaks - perceive as different lines.
  2131. } else {
  2132. state.result += common.repeat('\n', emptyLines);
  2133. } // Literal style: just add exact number of line breaks between content lines.
  2134. } else {
  2135. // Keep all line breaks except the header line break.
  2136. state.result += common.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines);
  2137. }
  2138. didReadContent = true;
  2139. detectedIndent = true;
  2140. emptyLines = 0;
  2141. captureStart = state.position;
  2142. while (!is_EOL(ch) && ch !== 0) {
  2143. ch = state.input.charCodeAt(++state.position);
  2144. }
  2145. captureSegment(state, captureStart, state.position, false);
  2146. }
  2147. return true;
  2148. }
  2149. function readBlockSequence(state, nodeIndent) {
  2150. var _line,
  2151. _tag = state.tag,
  2152. _anchor = state.anchor,
  2153. _result = [],
  2154. following,
  2155. detected = false,
  2156. ch;
  2157. if (state.anchor !== null) {
  2158. state.anchorMap[state.anchor] = _result;
  2159. }
  2160. ch = state.input.charCodeAt(state.position);
  2161. while (ch !== 0) {
  2162. if (ch !== 0x2D
  2163. /* - */
  2164. ) {
  2165. break;
  2166. }
  2167. following = state.input.charCodeAt(state.position + 1);
  2168. if (!is_WS_OR_EOL(following)) {
  2169. break;
  2170. }
  2171. detected = true;
  2172. state.position++;
  2173. if (skipSeparationSpace(state, true, -1)) {
  2174. if (state.lineIndent <= nodeIndent) {
  2175. _result.push(null);
  2176. ch = state.input.charCodeAt(state.position);
  2177. continue;
  2178. }
  2179. }
  2180. _line = state.line;
  2181. composeNode(state, nodeIndent, CONTEXT_BLOCK_IN, false, true);
  2182. _result.push(state.result);
  2183. skipSeparationSpace(state, true, -1);
  2184. ch = state.input.charCodeAt(state.position);
  2185. if ((state.line === _line || state.lineIndent > nodeIndent) && ch !== 0) {
  2186. throwError(state, 'bad indentation of a sequence entry');
  2187. } else if (state.lineIndent < nodeIndent) {
  2188. break;
  2189. }
  2190. }
  2191. if (detected) {
  2192. state.tag = _tag;
  2193. state.anchor = _anchor;
  2194. state.kind = 'sequence';
  2195. state.result = _result;
  2196. return true;
  2197. }
  2198. return false;
  2199. }
  2200. function readBlockMapping(state, nodeIndent, flowIndent) {
  2201. var following,
  2202. allowCompact,
  2203. _line,
  2204. _pos,
  2205. _tag = state.tag,
  2206. _anchor = state.anchor,
  2207. _result = {},
  2208. overridableKeys = {},
  2209. keyTag = null,
  2210. keyNode = null,
  2211. valueNode = null,
  2212. atExplicitKey = false,
  2213. detected = false,
  2214. ch;
  2215. if (state.anchor !== null) {
  2216. state.anchorMap[state.anchor] = _result;
  2217. }
  2218. ch = state.input.charCodeAt(state.position);
  2219. while (ch !== 0) {
  2220. following = state.input.charCodeAt(state.position + 1);
  2221. _line = state.line; // Save the current line.
  2222. _pos = state.position; //
  2223. // Explicit notation case. There are two separate blocks:
  2224. // first for the key (denoted by "?") and second for the value (denoted by ":")
  2225. //
  2226. if ((ch === 0x3F
  2227. /* ? */
  2228. || ch === 0x3A
  2229. /* : */
  2230. ) && is_WS_OR_EOL(following)) {
  2231. if (ch === 0x3F
  2232. /* ? */
  2233. ) {
  2234. if (atExplicitKey) {
  2235. storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null);
  2236. keyTag = keyNode = valueNode = null;
  2237. }
  2238. detected = true;
  2239. atExplicitKey = true;
  2240. allowCompact = true;
  2241. } else if (atExplicitKey) {
  2242. // i.e. 0x3A/* : */ === character after the explicit key.
  2243. atExplicitKey = false;
  2244. allowCompact = true;
  2245. } else {
  2246. throwError(state, 'incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line');
  2247. }
  2248. state.position += 1;
  2249. ch = following; //
  2250. // Implicit notation case. Flow-style node as the key first, then ":", and the value.
  2251. //
  2252. } else if (composeNode(state, flowIndent, CONTEXT_FLOW_OUT, false, true)) {
  2253. if (state.line === _line) {
  2254. ch = state.input.charCodeAt(state.position);
  2255. while (is_WHITE_SPACE(ch)) {
  2256. ch = state.input.charCodeAt(++state.position);
  2257. }
  2258. if (ch === 0x3A
  2259. /* : */
  2260. ) {
  2261. ch = state.input.charCodeAt(++state.position);
  2262. if (!is_WS_OR_EOL(ch)) {
  2263. throwError(state, 'a whitespace character is expected after the key-value separator within a block mapping');
  2264. }
  2265. if (atExplicitKey) {
  2266. storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null);
  2267. keyTag = keyNode = valueNode = null;
  2268. }
  2269. detected = true;
  2270. atExplicitKey = false;
  2271. allowCompact = false;
  2272. keyTag = state.tag;
  2273. keyNode = state.result;
  2274. } else if (detected) {
  2275. throwError(state, 'can not read an implicit mapping pair; a colon is missed');
  2276. } else {
  2277. state.tag = _tag;
  2278. state.anchor = _anchor;
  2279. return true; // Keep the result of `composeNode`.
  2280. }
  2281. } else if (detected) {
  2282. throwError(state, 'can not read a block mapping entry; a multiline key may not be an implicit key');
  2283. } else {
  2284. state.tag = _tag;
  2285. state.anchor = _anchor;
  2286. return true; // Keep the result of `composeNode`.
  2287. }
  2288. } else {
  2289. break; // Reading is done. Go to the epilogue.
  2290. } //
  2291. // Common reading code for both explicit and implicit notations.
  2292. //
  2293. if (state.line === _line || state.lineIndent > nodeIndent) {
  2294. if (composeNode(state, nodeIndent, CONTEXT_BLOCK_OUT, true, allowCompact)) {
  2295. if (atExplicitKey) {
  2296. keyNode = state.result;
  2297. } else {
  2298. valueNode = state.result;
  2299. }
  2300. }
  2301. if (!atExplicitKey) {
  2302. storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, _line, _pos);
  2303. keyTag = keyNode = valueNode = null;
  2304. }
  2305. skipSeparationSpace(state, true, -1);
  2306. ch = state.input.charCodeAt(state.position);
  2307. }
  2308. if (state.lineIndent > nodeIndent && ch !== 0) {
  2309. throwError(state, 'bad indentation of a mapping entry');
  2310. } else if (state.lineIndent < nodeIndent) {
  2311. break;
  2312. }
  2313. } //
  2314. // Epilogue.
  2315. //
  2316. // Special case: last mapping's node contains only the key in explicit notation.
  2317. if (atExplicitKey) {
  2318. storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null);
  2319. } // Expose the resulting mapping.
  2320. if (detected) {
  2321. state.tag = _tag;
  2322. state.anchor = _anchor;
  2323. state.kind = 'mapping';
  2324. state.result = _result;
  2325. }
  2326. return detected;
  2327. }
  2328. function readTagProperty(state) {
  2329. var _position,
  2330. isVerbatim = false,
  2331. isNamed = false,
  2332. tagHandle,
  2333. tagName,
  2334. ch;
  2335. ch = state.input.charCodeAt(state.position);
  2336. if (ch !== 0x21
  2337. /* ! */
  2338. ) return false;
  2339. if (state.tag !== null) {
  2340. throwError(state, 'duplication of a tag property');
  2341. }
  2342. ch = state.input.charCodeAt(++state.position);
  2343. if (ch === 0x3C
  2344. /* < */
  2345. ) {
  2346. isVerbatim = true;
  2347. ch = state.input.charCodeAt(++state.position);
  2348. } else if (ch === 0x21
  2349. /* ! */
  2350. ) {
  2351. isNamed = true;
  2352. tagHandle = '!!';
  2353. ch = state.input.charCodeAt(++state.position);
  2354. } else {
  2355. tagHandle = '!';
  2356. }
  2357. _position = state.position;
  2358. if (isVerbatim) {
  2359. do {
  2360. ch = state.input.charCodeAt(++state.position);
  2361. } while (ch !== 0 && ch !== 0x3E
  2362. /* > */
  2363. );
  2364. if (state.position < state.length) {
  2365. tagName = state.input.slice(_position, state.position);
  2366. ch = state.input.charCodeAt(++state.position);
  2367. } else {
  2368. throwError(state, 'unexpected end of the stream within a verbatim tag');
  2369. }
  2370. } else {
  2371. while (ch !== 0 && !is_WS_OR_EOL(ch)) {
  2372. if (ch === 0x21
  2373. /* ! */
  2374. ) {
  2375. if (!isNamed) {
  2376. tagHandle = state.input.slice(_position - 1, state.position + 1);
  2377. if (!PATTERN_TAG_HANDLE.test(tagHandle)) {
  2378. throwError(state, 'named tag handle cannot contain such characters');
  2379. }
  2380. isNamed = true;
  2381. _position = state.position + 1;
  2382. } else {
  2383. throwError(state, 'tag suffix cannot contain exclamation marks');
  2384. }
  2385. }
  2386. ch = state.input.charCodeAt(++state.position);
  2387. }
  2388. tagName = state.input.slice(_position, state.position);
  2389. if (PATTERN_FLOW_INDICATORS.test(tagName)) {
  2390. throwError(state, 'tag suffix cannot contain flow indicator characters');
  2391. }
  2392. }
  2393. if (tagName && !PATTERN_TAG_URI.test(tagName)) {
  2394. throwError(state, 'tag name cannot contain such characters: ' + tagName);
  2395. }
  2396. if (isVerbatim) {
  2397. state.tag = tagName;
  2398. } else if (_hasOwnProperty.call(state.tagMap, tagHandle)) {
  2399. state.tag = state.tagMap[tagHandle] + tagName;
  2400. } else if (tagHandle === '!') {
  2401. state.tag = '!' + tagName;
  2402. } else if (tagHandle === '!!') {
  2403. state.tag = 'tag:yaml.org,2002:' + tagName;
  2404. } else {
  2405. throwError(state, 'undeclared tag handle "' + tagHandle + '"');
  2406. }
  2407. return true;
  2408. }
  2409. function readAnchorProperty(state) {
  2410. var _position, ch;
  2411. ch = state.input.charCodeAt(state.position);
  2412. if (ch !== 0x26
  2413. /* & */
  2414. ) return false;
  2415. if (state.anchor !== null) {
  2416. throwError(state, 'duplication of an anchor property');
  2417. }
  2418. ch = state.input.charCodeAt(++state.position);
  2419. _position = state.position;
  2420. while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
  2421. ch = state.input.charCodeAt(++state.position);
  2422. }
  2423. if (state.position === _position) {
  2424. throwError(state, 'name of an anchor node must contain at least one character');
  2425. }
  2426. state.anchor = state.input.slice(_position, state.position);
  2427. return true;
  2428. }
  2429. function readAlias(state) {
  2430. var _position, alias, ch;
  2431. ch = state.input.charCodeAt(state.position);
  2432. if (ch !== 0x2A
  2433. /* * */
  2434. ) return false;
  2435. ch = state.input.charCodeAt(++state.position);
  2436. _position = state.position;
  2437. while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
  2438. ch = state.input.charCodeAt(++state.position);
  2439. }
  2440. if (state.position === _position) {
  2441. throwError(state, 'name of an alias node must contain at least one character');
  2442. }
  2443. alias = state.input.slice(_position, state.position);
  2444. if (!state.anchorMap.hasOwnProperty(alias)) {
  2445. throwError(state, 'unidentified alias "' + alias + '"');
  2446. }
  2447. state.result = state.anchorMap[alias];
  2448. skipSeparationSpace(state, true, -1);
  2449. return true;
  2450. }
  2451. function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact) {
  2452. var allowBlockStyles,
  2453. allowBlockScalars,
  2454. allowBlockCollections,
  2455. indentStatus = 1,
  2456. // 1: this>parent, 0: this=parent, -1: this<parent
  2457. atNewLine = false,
  2458. hasContent = false,
  2459. typeIndex,
  2460. typeQuantity,
  2461. type,
  2462. flowIndent,
  2463. blockIndent;
  2464. if (state.listener !== null) {
  2465. state.listener('open', state);
  2466. }
  2467. state.tag = null;
  2468. state.anchor = null;
  2469. state.kind = null;
  2470. state.result = null;
  2471. allowBlockStyles = allowBlockScalars = allowBlockCollections = CONTEXT_BLOCK_OUT === nodeContext || CONTEXT_BLOCK_IN === nodeContext;
  2472. if (allowToSeek) {
  2473. if (skipSeparationSpace(state, true, -1)) {
  2474. atNewLine = true;
  2475. if (state.lineIndent > parentIndent) {
  2476. indentStatus = 1;
  2477. } else if (state.lineIndent === parentIndent) {
  2478. indentStatus = 0;
  2479. } else if (state.lineIndent < parentIndent) {
  2480. indentStatus = -1;
  2481. }
  2482. }
  2483. }
  2484. if (indentStatus === 1) {
  2485. while (readTagProperty(state) || readAnchorProperty(state)) {
  2486. if (skipSeparationSpace(state, true, -1)) {
  2487. atNewLine = true;
  2488. allowBlockCollections = allowBlockStyles;
  2489. if (state.lineIndent > parentIndent) {
  2490. indentStatus = 1;
  2491. } else if (state.lineIndent === parentIndent) {
  2492. indentStatus = 0;
  2493. } else if (state.lineIndent < parentIndent) {
  2494. indentStatus = -1;
  2495. }
  2496. } else {
  2497. allowBlockCollections = false;
  2498. }
  2499. }
  2500. }
  2501. if (allowBlockCollections) {
  2502. allowBlockCollections = atNewLine || allowCompact;
  2503. }
  2504. if (indentStatus === 1 || CONTEXT_BLOCK_OUT === nodeContext) {
  2505. if (CONTEXT_FLOW_IN === nodeContext || CONTEXT_FLOW_OUT === nodeContext) {
  2506. flowIndent = parentIndent;
  2507. } else {
  2508. flowIndent = parentIndent + 1;
  2509. }
  2510. blockIndent = state.position - state.lineStart;
  2511. if (indentStatus === 1) {
  2512. if (allowBlockCollections && (readBlockSequence(state, blockIndent) || readBlockMapping(state, blockIndent, flowIndent)) || readFlowCollection(state, flowIndent)) {
  2513. hasContent = true;
  2514. } else {
  2515. if (allowBlockScalars && readBlockScalar(state, flowIndent) || readSingleQuotedScalar(state, flowIndent) || readDoubleQuotedScalar(state, flowIndent)) {
  2516. hasContent = true;
  2517. } else if (readAlias(state)) {
  2518. hasContent = true;
  2519. if (state.tag !== null || state.anchor !== null) {
  2520. throwError(state, 'alias node should not have any properties');
  2521. }
  2522. } else if (readPlainScalar(state, flowIndent, CONTEXT_FLOW_IN === nodeContext)) {
  2523. hasContent = true;
  2524. if (state.tag === null) {
  2525. state.tag = '?';
  2526. }
  2527. }
  2528. if (state.anchor !== null) {
  2529. state.anchorMap[state.anchor] = state.result;
  2530. }
  2531. }
  2532. } else if (indentStatus === 0) {
  2533. // Special case: block sequences are allowed to have same indentation level as the parent.
  2534. // http://www.yaml.org/spec/1.2/spec.html#id2799784
  2535. hasContent = allowBlockCollections && readBlockSequence(state, blockIndent);
  2536. }
  2537. }
  2538. if (state.tag !== null && state.tag !== '!') {
  2539. if (state.tag === '?') {
  2540. for (typeIndex = 0, typeQuantity = state.implicitTypes.length; typeIndex < typeQuantity; typeIndex += 1) {
  2541. type = state.implicitTypes[typeIndex]; // Implicit resolving is not allowed for non-scalar types, and '?'
  2542. // non-specific tag is only assigned to plain scalars. So, it isn't
  2543. // needed to check for 'kind' conformity.
  2544. if (type.resolve(state.result)) {
  2545. // `state.result` updated in resolver if matched
  2546. state.result = type.construct(state.result);
  2547. state.tag = type.tag;
  2548. if (state.anchor !== null) {
  2549. state.anchorMap[state.anchor] = state.result;
  2550. }
  2551. break;
  2552. }
  2553. }
  2554. } else if (_hasOwnProperty.call(state.typeMap[state.kind || 'fallback'], state.tag)) {
  2555. type = state.typeMap[state.kind || 'fallback'][state.tag];
  2556. if (state.result !== null && type.kind !== state.kind) {
  2557. throwError(state, 'unacceptable node kind for !<' + state.tag + '> tag; it should be "' + type.kind + '", not "' + state.kind + '"');
  2558. }
  2559. if (!type.resolve(state.result)) {
  2560. // `state.result` updated in resolver if matched
  2561. throwError(state, 'cannot resolve a node with !<' + state.tag + '> explicit tag');
  2562. } else {
  2563. state.result = type.construct(state.result);
  2564. if (state.anchor !== null) {
  2565. state.anchorMap[state.anchor] = state.result;
  2566. }
  2567. }
  2568. } else {
  2569. throwError(state, 'unknown tag !<' + state.tag + '>');
  2570. }
  2571. }
  2572. if (state.listener !== null) {
  2573. state.listener('close', state);
  2574. }
  2575. return state.tag !== null || state.anchor !== null || hasContent;
  2576. }
  2577. function readDocument(state) {
  2578. var documentStart = state.position,
  2579. _position,
  2580. directiveName,
  2581. directiveArgs,
  2582. hasDirectives = false,
  2583. ch;
  2584. state.version = null;
  2585. state.checkLineBreaks = state.legacy;
  2586. state.tagMap = {};
  2587. state.anchorMap = {};
  2588. while ((ch = state.input.charCodeAt(state.position)) !== 0) {
  2589. skipSeparationSpace(state, true, -1);
  2590. ch = state.input.charCodeAt(state.position);
  2591. if (state.lineIndent > 0 || ch !== 0x25
  2592. /* % */
  2593. ) {
  2594. break;
  2595. }
  2596. hasDirectives = true;
  2597. ch = state.input.charCodeAt(++state.position);
  2598. _position = state.position;
  2599. while (ch !== 0 && !is_WS_OR_EOL(ch)) {
  2600. ch = state.input.charCodeAt(++state.position);
  2601. }
  2602. directiveName = state.input.slice(_position, state.position);
  2603. directiveArgs = [];
  2604. if (directiveName.length < 1) {
  2605. throwError(state, 'directive name must not be less than one character in length');
  2606. }
  2607. while (ch !== 0) {
  2608. while (is_WHITE_SPACE(ch)) {
  2609. ch = state.input.charCodeAt(++state.position);
  2610. }
  2611. if (ch === 0x23
  2612. /* # */
  2613. ) {
  2614. do {
  2615. ch = state.input.charCodeAt(++state.position);
  2616. } while (ch !== 0 && !is_EOL(ch));
  2617. break;
  2618. }
  2619. if (is_EOL(ch)) break;
  2620. _position = state.position;
  2621. while (ch !== 0 && !is_WS_OR_EOL(ch)) {
  2622. ch = state.input.charCodeAt(++state.position);
  2623. }
  2624. directiveArgs.push(state.input.slice(_position, state.position));
  2625. }
  2626. if (ch !== 0) readLineBreak(state);
  2627. if (_hasOwnProperty.call(directiveHandlers, directiveName)) {
  2628. directiveHandlers[directiveName](state, directiveName, directiveArgs);
  2629. } else {
  2630. throwWarning(state, 'unknown document directive "' + directiveName + '"');
  2631. }
  2632. }
  2633. skipSeparationSpace(state, true, -1);
  2634. if (state.lineIndent === 0 && state.input.charCodeAt(state.position) === 0x2D
  2635. /* - */
  2636. && state.input.charCodeAt(state.position + 1) === 0x2D
  2637. /* - */
  2638. && state.input.charCodeAt(state.position + 2) === 0x2D
  2639. /* - */
  2640. ) {
  2641. state.position += 3;
  2642. skipSeparationSpace(state, true, -1);
  2643. } else if (hasDirectives) {
  2644. throwError(state, 'directives end mark is expected');
  2645. }
  2646. composeNode(state, state.lineIndent - 1, CONTEXT_BLOCK_OUT, false, true);
  2647. skipSeparationSpace(state, true, -1);
  2648. if (state.checkLineBreaks && PATTERN_NON_ASCII_LINE_BREAKS.test(state.input.slice(documentStart, state.position))) {
  2649. throwWarning(state, 'non-ASCII line breaks are interpreted as content');
  2650. }
  2651. state.documents.push(state.result);
  2652. if (state.position === state.lineStart && testDocumentSeparator(state)) {
  2653. if (state.input.charCodeAt(state.position) === 0x2E
  2654. /* . */
  2655. ) {
  2656. state.position += 3;
  2657. skipSeparationSpace(state, true, -1);
  2658. }
  2659. return;
  2660. }
  2661. if (state.position < state.length - 1) {
  2662. throwError(state, 'end of the stream or a document separator is expected');
  2663. } else {
  2664. return;
  2665. }
  2666. }
  2667. function loadDocuments(input, options) {
  2668. input = String(input);
  2669. options = options || {};
  2670. if (input.length !== 0) {
  2671. // Add tailing `\n` if not exists
  2672. if (input.charCodeAt(input.length - 1) !== 0x0A
  2673. /* LF */
  2674. && input.charCodeAt(input.length - 1) !== 0x0D
  2675. /* CR */
  2676. ) {
  2677. input += '\n';
  2678. } // Strip BOM
  2679. if (input.charCodeAt(0) === 0xFEFF) {
  2680. input = input.slice(1);
  2681. }
  2682. }
  2683. var state = new State(input, options); // Use 0 as string terminator. That significantly simplifies bounds check.
  2684. state.input += '\0';
  2685. while (state.input.charCodeAt(state.position) === 0x20
  2686. /* Space */
  2687. ) {
  2688. state.lineIndent += 1;
  2689. state.position += 1;
  2690. }
  2691. while (state.position < state.length - 1) {
  2692. readDocument(state);
  2693. }
  2694. return state.documents;
  2695. }
  2696. function loadAll$1(input, iterator, options) {
  2697. var documents = loadDocuments(input, options),
  2698. index,
  2699. length;
  2700. if (typeof iterator !== 'function') {
  2701. return documents;
  2702. }
  2703. for (index = 0, length = documents.length; index < length; index += 1) {
  2704. iterator(documents[index]);
  2705. }
  2706. }
  2707. function load$1(input, options) {
  2708. var documents = loadDocuments(input, options);
  2709. if (documents.length === 0) {
  2710. /*eslint-disable no-undefined*/
  2711. return undefined;
  2712. } else if (documents.length === 1) {
  2713. return documents[0];
  2714. }
  2715. throw new exception('expected a single document in the stream, but found more');
  2716. }
  2717. function safeLoadAll$1(input, output, options) {
  2718. if (typeof output === 'function') {
  2719. loadAll$1(input, output, common.extend({
  2720. schema: default_safe
  2721. }, options));
  2722. } else {
  2723. return loadAll$1(input, common.extend({
  2724. schema: default_safe
  2725. }, options));
  2726. }
  2727. }
  2728. function safeLoad$1(input, options) {
  2729. return load$1(input, common.extend({
  2730. schema: default_safe
  2731. }, options));
  2732. }
  2733. var loadAll_1 = loadAll$1;
  2734. var load_1 = load$1;
  2735. var safeLoadAll_1 = safeLoadAll$1;
  2736. var safeLoad_1 = safeLoad$1;
  2737. var loader = {
  2738. loadAll: loadAll_1,
  2739. load: load_1,
  2740. safeLoadAll: safeLoadAll_1,
  2741. safeLoad: safeLoad_1
  2742. };
  2743. /*eslint-disable no-use-before-define*/
  2744. var _toString$2 = Object.prototype.toString;
  2745. var _hasOwnProperty$3 = Object.prototype.hasOwnProperty;
  2746. var CHAR_TAB = 0x09;
  2747. /* Tab */
  2748. var CHAR_LINE_FEED = 0x0A;
  2749. /* LF */
  2750. var CHAR_SPACE = 0x20;
  2751. /* Space */
  2752. var CHAR_EXCLAMATION = 0x21;
  2753. /* ! */
  2754. var CHAR_DOUBLE_QUOTE = 0x22;
  2755. /* " */
  2756. var CHAR_SHARP = 0x23;
  2757. /* # */
  2758. var CHAR_PERCENT = 0x25;
  2759. /* % */
  2760. var CHAR_AMPERSAND = 0x26;
  2761. /* & */
  2762. var CHAR_SINGLE_QUOTE = 0x27;
  2763. /* ' */
  2764. var CHAR_ASTERISK = 0x2A;
  2765. /* * */
  2766. var CHAR_COMMA = 0x2C;
  2767. /* , */
  2768. var CHAR_MINUS = 0x2D;
  2769. /* - */
  2770. var CHAR_COLON = 0x3A;
  2771. /* : */
  2772. var CHAR_GREATER_THAN = 0x3E;
  2773. /* > */
  2774. var CHAR_QUESTION = 0x3F;
  2775. /* ? */
  2776. var CHAR_COMMERCIAL_AT = 0x40;
  2777. /* @ */
  2778. var CHAR_LEFT_SQUARE_BRACKET = 0x5B;
  2779. /* [ */
  2780. var CHAR_RIGHT_SQUARE_BRACKET = 0x5D;
  2781. /* ] */
  2782. var CHAR_GRAVE_ACCENT = 0x60;
  2783. /* ` */
  2784. var CHAR_LEFT_CURLY_BRACKET = 0x7B;
  2785. /* { */
  2786. var CHAR_VERTICAL_LINE = 0x7C;
  2787. /* | */
  2788. var CHAR_RIGHT_CURLY_BRACKET = 0x7D;
  2789. /* } */
  2790. var ESCAPE_SEQUENCES = {};
  2791. ESCAPE_SEQUENCES[0x00] = '\\0';
  2792. ESCAPE_SEQUENCES[0x07] = '\\a';
  2793. ESCAPE_SEQUENCES[0x08] = '\\b';
  2794. ESCAPE_SEQUENCES[0x09] = '\\t';
  2795. ESCAPE_SEQUENCES[0x0A] = '\\n';
  2796. ESCAPE_SEQUENCES[0x0B] = '\\v';
  2797. ESCAPE_SEQUENCES[0x0C] = '\\f';
  2798. ESCAPE_SEQUENCES[0x0D] = '\\r';
  2799. ESCAPE_SEQUENCES[0x1B] = '\\e';
  2800. ESCAPE_SEQUENCES[0x22] = '\\"';
  2801. ESCAPE_SEQUENCES[0x5C] = '\\\\';
  2802. ESCAPE_SEQUENCES[0x85] = '\\N';
  2803. ESCAPE_SEQUENCES[0xA0] = '\\_';
  2804. ESCAPE_SEQUENCES[0x2028] = '\\L';
  2805. ESCAPE_SEQUENCES[0x2029] = '\\P';
  2806. var DEPRECATED_BOOLEANS_SYNTAX = ['y', 'Y', 'yes', 'Yes', 'YES', 'on', 'On', 'ON', 'n', 'N', 'no', 'No', 'NO', 'off', 'Off', 'OFF'];
  2807. function compileStyleMap(schema, map) {
  2808. var result, keys, index, length, tag, style, type;
  2809. if (map === null) return {};
  2810. result = {};
  2811. keys = Object.keys(map);
  2812. for (index = 0, length = keys.length; index < length; index += 1) {
  2813. tag = keys[index];
  2814. style = String(map[tag]);
  2815. if (tag.slice(0, 2) === '!!') {
  2816. tag = 'tag:yaml.org,2002:' + tag.slice(2);
  2817. }
  2818. type = schema.compiledTypeMap['fallback'][tag];
  2819. if (type && _hasOwnProperty$3.call(type.styleAliases, style)) {
  2820. style = type.styleAliases[style];
  2821. }
  2822. result[tag] = style;
  2823. }
  2824. return result;
  2825. }
  2826. function encodeHex(character) {
  2827. var string, handle, length;
  2828. string = character.toString(16).toUpperCase();
  2829. if (character <= 0xFF) {
  2830. handle = 'x';
  2831. length = 2;
  2832. } else if (character <= 0xFFFF) {
  2833. handle = 'u';
  2834. length = 4;
  2835. } else if (character <= 0xFFFFFFFF) {
  2836. handle = 'U';
  2837. length = 8;
  2838. } else {
  2839. throw new exception('code point within a string may not be greater than 0xFFFFFFFF');
  2840. }
  2841. return '\\' + handle + common.repeat('0', length - string.length) + string;
  2842. }
  2843. function State$1(options) {
  2844. this.schema = options['schema'] || default_full;
  2845. this.indent = Math.max(1, options['indent'] || 2);
  2846. this.noArrayIndent = options['noArrayIndent'] || false;
  2847. this.skipInvalid = options['skipInvalid'] || false;
  2848. this.flowLevel = common.isNothing(options['flowLevel']) ? -1 : options['flowLevel'];
  2849. this.styleMap = compileStyleMap(this.schema, options['styles'] || null);
  2850. this.sortKeys = options['sortKeys'] || false;
  2851. this.lineWidth = options['lineWidth'] || 80;
  2852. this.noRefs = options['noRefs'] || false;
  2853. this.noCompatMode = options['noCompatMode'] || false;
  2854. this.condenseFlow = options['condenseFlow'] || false;
  2855. this.implicitTypes = this.schema.compiledImplicit;
  2856. this.explicitTypes = this.schema.compiledExplicit;
  2857. this.tag = null;
  2858. this.result = '';
  2859. this.duplicates = [];
  2860. this.usedDuplicates = null;
  2861. } // Indents every line in a string. Empty lines (\n only) are not indented.
  2862. function indentString(string, spaces) {
  2863. var ind = common.repeat(' ', spaces),
  2864. position = 0,
  2865. next = -1,
  2866. result = '',
  2867. line,
  2868. length = string.length;
  2869. while (position < length) {
  2870. next = string.indexOf('\n', position);
  2871. if (next === -1) {
  2872. line = string.slice(position);
  2873. position = length;
  2874. } else {
  2875. line = string.slice(position, next + 1);
  2876. position = next + 1;
  2877. }
  2878. if (line.length && line !== '\n') result += ind;
  2879. result += line;
  2880. }
  2881. return result;
  2882. }
  2883. function generateNextLine(state, level) {
  2884. return '\n' + common.repeat(' ', state.indent * level);
  2885. }
  2886. function testImplicitResolving(state, str) {
  2887. var index, length, type;
  2888. for (index = 0, length = state.implicitTypes.length; index < length; index += 1) {
  2889. type = state.implicitTypes[index];
  2890. if (type.resolve(str)) {
  2891. return true;
  2892. }
  2893. }
  2894. return false;
  2895. } // [33] s-white ::= s-space | s-tab
  2896. function isWhitespace(c) {
  2897. return c === CHAR_SPACE || c === CHAR_TAB;
  2898. } // Returns true if the character can be printed without escaping.
  2899. // From YAML 1.2: "any allowed characters known to be non-printable
  2900. // should also be escaped. [However,] This isn’t mandatory"
  2901. // Derived from nb-char - \t - #x85 - #xA0 - #x2028 - #x2029.
  2902. function isPrintable(c) {
  2903. return 0x00020 <= c && c <= 0x00007E || 0x000A1 <= c && c <= 0x00D7FF && c !== 0x2028 && c !== 0x2029 || 0x0E000 <= c && c <= 0x00FFFD && c !== 0xFEFF
  2904. /* BOM */
  2905. || 0x10000 <= c && c <= 0x10FFFF;
  2906. } // Simplified test for values allowed after the first character in plain style.
  2907. function isPlainSafe(c) {
  2908. // Uses a subset of nb-char - c-flow-indicator - ":" - "#"
  2909. // where nb-char ::= c-printable - b-char - c-byte-order-mark.
  2910. return isPrintable(c) && c !== 0xFEFF // - c-flow-indicator
  2911. && c !== CHAR_COMMA && c !== CHAR_LEFT_SQUARE_BRACKET && c !== CHAR_RIGHT_SQUARE_BRACKET && c !== CHAR_LEFT_CURLY_BRACKET && c !== CHAR_RIGHT_CURLY_BRACKET // - ":" - "#"
  2912. && c !== CHAR_COLON && c !== CHAR_SHARP;
  2913. } // Simplified test for values allowed as the first character in plain style.
  2914. function isPlainSafeFirst(c) {
  2915. // Uses a subset of ns-char - c-indicator
  2916. // where ns-char = nb-char - s-white.
  2917. return isPrintable(c) && c !== 0xFEFF && !isWhitespace(c) // - s-white
  2918. // - (c-indicator ::=
  2919. // “-” | “?” | “:” | “,” | “[” | “]” | “{” | “}”
  2920. && c !== CHAR_MINUS && c !== CHAR_QUESTION && c !== CHAR_COLON && c !== CHAR_COMMA && c !== CHAR_LEFT_SQUARE_BRACKET && c !== CHAR_RIGHT_SQUARE_BRACKET && c !== CHAR_LEFT_CURLY_BRACKET && c !== CHAR_RIGHT_CURLY_BRACKET // | “#” | “&” | “*” | “!” | “|” | “>” | “'” | “"”
  2921. && c !== CHAR_SHARP && c !== CHAR_AMPERSAND && c !== CHAR_ASTERISK && c !== CHAR_EXCLAMATION && c !== CHAR_VERTICAL_LINE && c !== CHAR_GREATER_THAN && c !== CHAR_SINGLE_QUOTE && c !== CHAR_DOUBLE_QUOTE // | “%” | “@” | “`”)
  2922. && c !== CHAR_PERCENT && c !== CHAR_COMMERCIAL_AT && c !== CHAR_GRAVE_ACCENT;
  2923. } // Determines whether block indentation indicator is required.
  2924. function needIndentIndicator(string) {
  2925. var leadingSpaceRe = /^\n* /;
  2926. return leadingSpaceRe.test(string);
  2927. }
  2928. var STYLE_PLAIN = 1;
  2929. var STYLE_SINGLE = 2;
  2930. var STYLE_LITERAL = 3;
  2931. var STYLE_FOLDED = 4;
  2932. var STYLE_DOUBLE = 5; // Determines which scalar styles are possible and returns the preferred style.
  2933. // lineWidth = -1 => no limit.
  2934. // Pre-conditions: str.length > 0.
  2935. // Post-conditions:
  2936. // STYLE_PLAIN or STYLE_SINGLE => no \n are in the string.
  2937. // STYLE_LITERAL => no lines are suitable for folding (or lineWidth is -1).
  2938. // STYLE_FOLDED => a line > lineWidth and can be folded (and lineWidth != -1).
  2939. function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth, testAmbiguousType) {
  2940. var i;
  2941. var char;
  2942. var hasLineBreak = false;
  2943. var hasFoldableLine = false; // only checked if shouldTrackWidth
  2944. var shouldTrackWidth = lineWidth !== -1;
  2945. var previousLineBreak = -1; // count the first line correctly
  2946. var plain = isPlainSafeFirst(string.charCodeAt(0)) && !isWhitespace(string.charCodeAt(string.length - 1));
  2947. if (singleLineOnly) {
  2948. // Case: no block styles.
  2949. // Check for disallowed characters to rule out plain and single.
  2950. for (i = 0; i < string.length; i++) {
  2951. char = string.charCodeAt(i);
  2952. if (!isPrintable(char)) {
  2953. return STYLE_DOUBLE;
  2954. }
  2955. plain = plain && isPlainSafe(char);
  2956. }
  2957. } else {
  2958. // Case: block styles permitted.
  2959. for (i = 0; i < string.length; i++) {
  2960. char = string.charCodeAt(i);
  2961. if (char === CHAR_LINE_FEED) {
  2962. hasLineBreak = true; // Check if any line can be folded.
  2963. if (shouldTrackWidth) {
  2964. hasFoldableLine = hasFoldableLine || // Foldable line = too long, and not more-indented.
  2965. i - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !== ' ';
  2966. previousLineBreak = i;
  2967. }
  2968. } else if (!isPrintable(char)) {
  2969. return STYLE_DOUBLE;
  2970. }
  2971. plain = plain && isPlainSafe(char);
  2972. } // in case the end is missing a \n
  2973. hasFoldableLine = hasFoldableLine || shouldTrackWidth && i - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !== ' ';
  2974. } // Although every style can represent \n without escaping, prefer block styles
  2975. // for multiline, since they're more readable and they don't add empty lines.
  2976. // Also prefer folding a super-long line.
  2977. if (!hasLineBreak && !hasFoldableLine) {
  2978. // Strings interpretable as another type have to be quoted;
  2979. // e.g. the string 'true' vs. the boolean true.
  2980. return plain && !testAmbiguousType(string) ? STYLE_PLAIN : STYLE_SINGLE;
  2981. } // Edge case: block indentation indicator can only have one digit.
  2982. if (indentPerLevel > 9 && needIndentIndicator(string)) {
  2983. return STYLE_DOUBLE;
  2984. } // At this point we know block styles are valid.
  2985. // Prefer literal style unless we want to fold.
  2986. return hasFoldableLine ? STYLE_FOLDED : STYLE_LITERAL;
  2987. } // Note: line breaking/folding is implemented for only the folded style.
  2988. // NB. We drop the last trailing newline (if any) of a returned block scalar
  2989. // since the dumper adds its own newline. This always works:
  2990. // • No ending newline => unaffected; already using strip "-" chomping.
  2991. // • Ending newline => removed then restored.
  2992. // Importantly, this keeps the "+" chomp indicator from gaining an extra line.
  2993. function writeScalar(state, string, level, iskey) {
  2994. state.dump = function () {
  2995. if (string.length === 0) {
  2996. return "''";
  2997. }
  2998. if (!state.noCompatMode && DEPRECATED_BOOLEANS_SYNTAX.indexOf(string) !== -1) {
  2999. return "'" + string + "'";
  3000. }
  3001. var indent = state.indent * Math.max(1, level); // no 0-indent scalars
  3002. // As indentation gets deeper, let the width decrease monotonically
  3003. // to the lower bound min(state.lineWidth, 40).
  3004. // Note that this implies
  3005. // state.lineWidth ≤ 40 + state.indent: width is fixed at the lower bound.
  3006. // state.lineWidth > 40 + state.indent: width decreases until the lower bound.
  3007. // This behaves better than a constant minimum width which disallows narrower options,
  3008. // or an indent threshold which causes the width to suddenly increase.
  3009. var lineWidth = state.lineWidth === -1 ? -1 : Math.max(Math.min(state.lineWidth, 40), state.lineWidth - indent); // Without knowing if keys are implicit/explicit, assume implicit for safety.
  3010. var singleLineOnly = iskey // No block styles in flow mode.
  3011. || state.flowLevel > -1 && level >= state.flowLevel;
  3012. function testAmbiguity(string) {
  3013. return testImplicitResolving(state, string);
  3014. }
  3015. switch (chooseScalarStyle(string, singleLineOnly, state.indent, lineWidth, testAmbiguity)) {
  3016. case STYLE_PLAIN:
  3017. return string;
  3018. case STYLE_SINGLE:
  3019. return "'" + string.replace(/'/g, "''") + "'";
  3020. case STYLE_LITERAL:
  3021. return '|' + blockHeader(string, state.indent) + dropEndingNewline(indentString(string, indent));
  3022. case STYLE_FOLDED:
  3023. return '>' + blockHeader(string, state.indent) + dropEndingNewline(indentString(foldString(string, lineWidth), indent));
  3024. case STYLE_DOUBLE:
  3025. return '"' + escapeString(string, lineWidth) + '"';
  3026. default:
  3027. throw new exception('impossible error: invalid scalar style');
  3028. }
  3029. }();
  3030. } // Pre-conditions: string is valid for a block scalar, 1 <= indentPerLevel <= 9.
  3031. function blockHeader(string, indentPerLevel) {
  3032. var indentIndicator = needIndentIndicator(string) ? String(indentPerLevel) : ''; // note the special case: the string '\n' counts as a "trailing" empty line.
  3033. var clip = string[string.length - 1] === '\n';
  3034. var keep = clip && (string[string.length - 2] === '\n' || string === '\n');
  3035. var chomp = keep ? '+' : clip ? '' : '-';
  3036. return indentIndicator + chomp + '\n';
  3037. } // (See the note for writeScalar.)
  3038. function dropEndingNewline(string) {
  3039. return string[string.length - 1] === '\n' ? string.slice(0, -1) : string;
  3040. } // Note: a long line without a suitable break point will exceed the width limit.
  3041. // Pre-conditions: every char in str isPrintable, str.length > 0, width > 0.
  3042. function foldString(string, width) {
  3043. // In folded style, $k$ consecutive newlines output as $k+1$ newlines—
  3044. // unless they're before or after a more-indented line, or at the very
  3045. // beginning or end, in which case $k$ maps to $k$.
  3046. // Therefore, parse each chunk as newline(s) followed by a content line.
  3047. var lineRe = /(\n+)([^\n]*)/g; // first line (possibly an empty line)
  3048. var result = function () {
  3049. var nextLF = string.indexOf('\n');
  3050. nextLF = nextLF !== -1 ? nextLF : string.length;
  3051. lineRe.lastIndex = nextLF;
  3052. return foldLine(string.slice(0, nextLF), width);
  3053. }(); // If we haven't reached the first content line yet, don't add an extra \n.
  3054. var prevMoreIndented = string[0] === '\n' || string[0] === ' ';
  3055. var moreIndented; // rest of the lines
  3056. var match;
  3057. while (match = lineRe.exec(string)) {
  3058. var prefix = match[1],
  3059. line = match[2];
  3060. moreIndented = line[0] === ' ';
  3061. result += prefix + (!prevMoreIndented && !moreIndented && line !== '' ? '\n' : '') + foldLine(line, width);
  3062. prevMoreIndented = moreIndented;
  3063. }
  3064. return result;
  3065. } // Greedy line breaking.
  3066. // Picks the longest line under the limit each time,
  3067. // otherwise settles for the shortest line over the limit.
  3068. // NB. More-indented lines *cannot* be folded, as that would add an extra \n.
  3069. function foldLine(line, width) {
  3070. if (line === '' || line[0] === ' ') return line; // Since a more-indented line adds a \n, breaks can't be followed by a space.
  3071. var breakRe = / [^ ]/g; // note: the match index will always be <= length-2.
  3072. var match; // start is an inclusive index. end, curr, and next are exclusive.
  3073. var start = 0,
  3074. end,
  3075. curr = 0,
  3076. next = 0;
  3077. var result = ''; // Invariants: 0 <= start <= length-1.
  3078. // 0 <= curr <= next <= max(0, length-2). curr - start <= width.
  3079. // Inside the loop:
  3080. // A match implies length >= 2, so curr and next are <= length-2.
  3081. while (match = breakRe.exec(line)) {
  3082. next = match.index; // maintain invariant: curr - start <= width
  3083. if (next - start > width) {
  3084. end = curr > start ? curr : next; // derive end <= length-2
  3085. result += '\n' + line.slice(start, end); // skip the space that was output as \n
  3086. start = end + 1; // derive start <= length-1
  3087. }
  3088. curr = next;
  3089. } // By the invariants, start <= length-1, so there is something left over.
  3090. // It is either the whole string or a part starting from non-whitespace.
  3091. result += '\n'; // Insert a break if the remainder is too long and there is a break available.
  3092. if (line.length - start > width && curr > start) {
  3093. result += line.slice(start, curr) + '\n' + line.slice(curr + 1);
  3094. } else {
  3095. result += line.slice(start);
  3096. }
  3097. return result.slice(1); // drop extra \n joiner
  3098. } // Escapes a double-quoted string.
  3099. function escapeString(string) {
  3100. var result = '';
  3101. var char, nextChar;
  3102. var escapeSeq;
  3103. for (var i = 0; i < string.length; i++) {
  3104. char = string.charCodeAt(i); // Check for surrogate pairs (reference Unicode 3.0 section "3.7 Surrogates").
  3105. if (char >= 0xD800 && char <= 0xDBFF
  3106. /* high surrogate */
  3107. ) {
  3108. nextChar = string.charCodeAt(i + 1);
  3109. if (nextChar >= 0xDC00 && nextChar <= 0xDFFF
  3110. /* low surrogate */
  3111. ) {
  3112. // Combine the surrogate pair and store it escaped.
  3113. result += encodeHex((char - 0xD800) * 0x400 + nextChar - 0xDC00 + 0x10000); // Advance index one extra since we already used that char here.
  3114. i++;
  3115. continue;
  3116. }
  3117. }
  3118. escapeSeq = ESCAPE_SEQUENCES[char];
  3119. result += !escapeSeq && isPrintable(char) ? string[i] : escapeSeq || encodeHex(char);
  3120. }
  3121. return result;
  3122. }
  3123. function writeFlowSequence(state, level, object) {
  3124. var _result = '',
  3125. _tag = state.tag,
  3126. index,
  3127. length;
  3128. for (index = 0, length = object.length; index < length; index += 1) {
  3129. // Write only valid elements.
  3130. if (writeNode(state, level, object[index], false, false)) {
  3131. if (index !== 0) _result += ',' + (!state.condenseFlow ? ' ' : '');
  3132. _result += state.dump;
  3133. }
  3134. }
  3135. state.tag = _tag;
  3136. state.dump = '[' + _result + ']';
  3137. }
  3138. function writeBlockSequence(state, level, object, compact) {
  3139. var _result = '',
  3140. _tag = state.tag,
  3141. index,
  3142. length;
  3143. for (index = 0, length = object.length; index < length; index += 1) {
  3144. // Write only valid elements.
  3145. if (writeNode(state, level + 1, object[index], true, true)) {
  3146. if (!compact || index !== 0) {
  3147. _result += generateNextLine(state, level);
  3148. }
  3149. if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
  3150. _result += '-';
  3151. } else {
  3152. _result += '- ';
  3153. }
  3154. _result += state.dump;
  3155. }
  3156. }
  3157. state.tag = _tag;
  3158. state.dump = _result || '[]'; // Empty sequence if no valid values.
  3159. }
  3160. function writeFlowMapping(state, level, object) {
  3161. var _result = '',
  3162. _tag = state.tag,
  3163. objectKeyList = Object.keys(object),
  3164. index,
  3165. length,
  3166. objectKey,
  3167. objectValue,
  3168. pairBuffer;
  3169. for (index = 0, length = objectKeyList.length; index < length; index += 1) {
  3170. pairBuffer = state.condenseFlow ? '"' : '';
  3171. if (index !== 0) pairBuffer += ', ';
  3172. objectKey = objectKeyList[index];
  3173. objectValue = object[objectKey];
  3174. if (!writeNode(state, level, objectKey, false, false)) {
  3175. continue; // Skip this pair because of invalid key;
  3176. }
  3177. if (state.dump.length > 1024) pairBuffer += '? ';
  3178. pairBuffer += state.dump + (state.condenseFlow ? '"' : '') + ':' + (state.condenseFlow ? '' : ' ');
  3179. if (!writeNode(state, level, objectValue, false, false)) {
  3180. continue; // Skip this pair because of invalid value.
  3181. }
  3182. pairBuffer += state.dump; // Both key and value are valid.
  3183. _result += pairBuffer;
  3184. }
  3185. state.tag = _tag;
  3186. state.dump = '{' + _result + '}';
  3187. }
  3188. function writeBlockMapping(state, level, object, compact) {
  3189. var _result = '',
  3190. _tag = state.tag,
  3191. objectKeyList = Object.keys(object),
  3192. index,
  3193. length,
  3194. objectKey,
  3195. objectValue,
  3196. explicitPair,
  3197. pairBuffer; // Allow sorting keys so that the output file is deterministic
  3198. if (state.sortKeys === true) {
  3199. // Default sorting
  3200. objectKeyList.sort();
  3201. } else if (typeof state.sortKeys === 'function') {
  3202. // Custom sort function
  3203. objectKeyList.sort(state.sortKeys);
  3204. } else if (state.sortKeys) {
  3205. // Something is wrong
  3206. throw new exception('sortKeys must be a boolean or a function');
  3207. }
  3208. for (index = 0, length = objectKeyList.length; index < length; index += 1) {
  3209. pairBuffer = '';
  3210. if (!compact || index !== 0) {
  3211. pairBuffer += generateNextLine(state, level);
  3212. }
  3213. objectKey = objectKeyList[index];
  3214. objectValue = object[objectKey];
  3215. if (!writeNode(state, level + 1, objectKey, true, true, true)) {
  3216. continue; // Skip this pair because of invalid key.
  3217. }
  3218. explicitPair = state.tag !== null && state.tag !== '?' || state.dump && state.dump.length > 1024;
  3219. if (explicitPair) {
  3220. if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
  3221. pairBuffer += '?';
  3222. } else {
  3223. pairBuffer += '? ';
  3224. }
  3225. }
  3226. pairBuffer += state.dump;
  3227. if (explicitPair) {
  3228. pairBuffer += generateNextLine(state, level);
  3229. }
  3230. if (!writeNode(state, level + 1, objectValue, true, explicitPair)) {
  3231. continue; // Skip this pair because of invalid value.
  3232. }
  3233. if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
  3234. pairBuffer += ':';
  3235. } else {
  3236. pairBuffer += ': ';
  3237. }
  3238. pairBuffer += state.dump; // Both key and value are valid.
  3239. _result += pairBuffer;
  3240. }
  3241. state.tag = _tag;
  3242. state.dump = _result || '{}'; // Empty mapping if no valid pairs.
  3243. }
  3244. function detectType(state, object, explicit) {
  3245. var _result, typeList, index, length, type, style;
  3246. typeList = explicit ? state.explicitTypes : state.implicitTypes;
  3247. for (index = 0, length = typeList.length; index < length; index += 1) {
  3248. type = typeList[index];
  3249. if ((type.instanceOf || type.predicate) && (!type.instanceOf || typeof object === 'object' && object instanceof type.instanceOf) && (!type.predicate || type.predicate(object))) {
  3250. state.tag = explicit ? type.tag : '?';
  3251. if (type.represent) {
  3252. style = state.styleMap[type.tag] || type.defaultStyle;
  3253. if (_toString$2.call(type.represent) === '[object Function]') {
  3254. _result = type.represent(object, style);
  3255. } else if (_hasOwnProperty$3.call(type.represent, style)) {
  3256. _result = type.represent[style](object, style);
  3257. } else {
  3258. throw new exception('!<' + type.tag + '> tag resolver accepts not "' + style + '" style');
  3259. }
  3260. state.dump = _result;
  3261. }
  3262. return true;
  3263. }
  3264. }
  3265. return false;
  3266. } // Serializes `object` and writes it to global `result`.
  3267. // Returns true on success, or false on invalid object.
  3268. //
  3269. function writeNode(state, level, object, block, compact, iskey) {
  3270. state.tag = null;
  3271. state.dump = object;
  3272. if (!detectType(state, object, false)) {
  3273. detectType(state, object, true);
  3274. }
  3275. var type = _toString$2.call(state.dump);
  3276. if (block) {
  3277. block = state.flowLevel < 0 || state.flowLevel > level;
  3278. }
  3279. var objectOrArray = type === '[object Object]' || type === '[object Array]',
  3280. duplicateIndex,
  3281. duplicate;
  3282. if (objectOrArray) {
  3283. duplicateIndex = state.duplicates.indexOf(object);
  3284. duplicate = duplicateIndex !== -1;
  3285. }
  3286. if (state.tag !== null && state.tag !== '?' || duplicate || state.indent !== 2 && level > 0) {
  3287. compact = false;
  3288. }
  3289. if (duplicate && state.usedDuplicates[duplicateIndex]) {
  3290. state.dump = '*ref_' + duplicateIndex;
  3291. } else {
  3292. if (objectOrArray && duplicate && !state.usedDuplicates[duplicateIndex]) {
  3293. state.usedDuplicates[duplicateIndex] = true;
  3294. }
  3295. if (type === '[object Object]') {
  3296. if (block && Object.keys(state.dump).length !== 0) {
  3297. writeBlockMapping(state, level, state.dump, compact);
  3298. if (duplicate) {
  3299. state.dump = '&ref_' + duplicateIndex + state.dump;
  3300. }
  3301. } else {
  3302. writeFlowMapping(state, level, state.dump);
  3303. if (duplicate) {
  3304. state.dump = '&ref_' + duplicateIndex + ' ' + state.dump;
  3305. }
  3306. }
  3307. } else if (type === '[object Array]') {
  3308. var arrayLevel = state.noArrayIndent && level > 0 ? level - 1 : level;
  3309. if (block && state.dump.length !== 0) {
  3310. writeBlockSequence(state, arrayLevel, state.dump, compact);
  3311. if (duplicate) {
  3312. state.dump = '&ref_' + duplicateIndex + state.dump;
  3313. }
  3314. } else {
  3315. writeFlowSequence(state, arrayLevel, state.dump);
  3316. if (duplicate) {
  3317. state.dump = '&ref_' + duplicateIndex + ' ' + state.dump;
  3318. }
  3319. }
  3320. } else if (type === '[object String]') {
  3321. if (state.tag !== '?') {
  3322. writeScalar(state, state.dump, level, iskey);
  3323. }
  3324. } else {
  3325. if (state.skipInvalid) return false;
  3326. throw new exception('unacceptable kind of an object to dump ' + type);
  3327. }
  3328. if (state.tag !== null && state.tag !== '?') {
  3329. state.dump = '!<' + state.tag + '> ' + state.dump;
  3330. }
  3331. }
  3332. return true;
  3333. }
  3334. function getDuplicateReferences(object, state) {
  3335. var objects = [],
  3336. duplicatesIndexes = [],
  3337. index,
  3338. length;
  3339. inspectNode(object, objects, duplicatesIndexes);
  3340. for (index = 0, length = duplicatesIndexes.length; index < length; index += 1) {
  3341. state.duplicates.push(objects[duplicatesIndexes[index]]);
  3342. }
  3343. state.usedDuplicates = new Array(length);
  3344. }
  3345. function inspectNode(object, objects, duplicatesIndexes) {
  3346. var objectKeyList, index, length;
  3347. if (object !== null && typeof object === 'object') {
  3348. index = objects.indexOf(object);
  3349. if (index !== -1) {
  3350. if (duplicatesIndexes.indexOf(index) === -1) {
  3351. duplicatesIndexes.push(index);
  3352. }
  3353. } else {
  3354. objects.push(object);
  3355. if (Array.isArray(object)) {
  3356. for (index = 0, length = object.length; index < length; index += 1) {
  3357. inspectNode(object[index], objects, duplicatesIndexes);
  3358. }
  3359. } else {
  3360. objectKeyList = Object.keys(object);
  3361. for (index = 0, length = objectKeyList.length; index < length; index += 1) {
  3362. inspectNode(object[objectKeyList[index]], objects, duplicatesIndexes);
  3363. }
  3364. }
  3365. }
  3366. }
  3367. }
  3368. function dump$1(input, options) {
  3369. options = options || {};
  3370. var state = new State$1(options);
  3371. if (!state.noRefs) getDuplicateReferences(input, state);
  3372. if (writeNode(state, 0, input, true, true)) return state.dump + '\n';
  3373. return '';
  3374. }
  3375. function safeDump$1(input, options) {
  3376. return dump$1(input, common.extend({
  3377. schema: default_safe
  3378. }, options));
  3379. }
  3380. var dump_1 = dump$1;
  3381. var safeDump_1 = safeDump$1;
  3382. var dumper = {
  3383. dump: dump_1,
  3384. safeDump: safeDump_1
  3385. };
  3386. function deprecated(name) {
  3387. return function () {
  3388. throw new Error('Function ' + name + ' is deprecated and cannot be used.');
  3389. };
  3390. }
  3391. var Type = type;
  3392. var Schema = schema;
  3393. var FAILSAFE_SCHEMA = failsafe;
  3394. var JSON_SCHEMA = json;
  3395. var CORE_SCHEMA = core;
  3396. var DEFAULT_SAFE_SCHEMA = default_safe;
  3397. var DEFAULT_FULL_SCHEMA = default_full;
  3398. var load = loader.load;
  3399. var loadAll = loader.loadAll;
  3400. var safeLoad = loader.safeLoad;
  3401. var safeLoadAll = loader.safeLoadAll;
  3402. var dump = dumper.dump;
  3403. var safeDump = dumper.safeDump;
  3404. var YAMLException = exception; // Deprecated schema names from JS-YAML 2.0.x
  3405. var MINIMAL_SCHEMA = failsafe;
  3406. var SAFE_SCHEMA = default_safe;
  3407. var DEFAULT_SCHEMA = default_full; // Deprecated functions from JS-YAML 1.x.x
  3408. var scan = deprecated('scan');
  3409. var parse = deprecated('parse');
  3410. var compose = deprecated('compose');
  3411. var addConstructor = deprecated('addConstructor');
  3412. var jsYaml$2 = {
  3413. Type: Type,
  3414. Schema: Schema,
  3415. FAILSAFE_SCHEMA: FAILSAFE_SCHEMA,
  3416. JSON_SCHEMA: JSON_SCHEMA,
  3417. CORE_SCHEMA: CORE_SCHEMA,
  3418. DEFAULT_SAFE_SCHEMA: DEFAULT_SAFE_SCHEMA,
  3419. DEFAULT_FULL_SCHEMA: DEFAULT_FULL_SCHEMA,
  3420. load: load,
  3421. loadAll: loadAll,
  3422. safeLoad: safeLoad,
  3423. safeLoadAll: safeLoadAll,
  3424. dump: dump,
  3425. safeDump: safeDump,
  3426. YAMLException: YAMLException,
  3427. MINIMAL_SCHEMA: MINIMAL_SCHEMA,
  3428. SAFE_SCHEMA: SAFE_SCHEMA,
  3429. DEFAULT_SCHEMA: DEFAULT_SCHEMA,
  3430. scan: scan,
  3431. parse: parse,
  3432. compose: compose,
  3433. addConstructor: addConstructor
  3434. };
  3435. var jsYaml = jsYaml$2;
  3436. var resolveFrom_1 = createCommonjsModule(function (module) {
  3437. 'use strict';
  3438. var resolveFrom = function resolveFrom(fromDir, moduleId, silent) {
  3439. if (typeof fromDir !== 'string') {
  3440. throw new TypeError(`Expected \`fromDir\` to be of type \`string\`, got \`${typeof fromDir}\``);
  3441. }
  3442. if (typeof moduleId !== 'string') {
  3443. throw new TypeError(`Expected \`moduleId\` to be of type \`string\`, got \`${typeof moduleId}\``);
  3444. }
  3445. fromDir = path.resolve(fromDir);
  3446. var fromFile = path.join(fromDir, 'noop.js');
  3447. var resolveFileName = function resolveFileName() {
  3448. return module$1._resolveFilename(moduleId, {
  3449. id: fromFile,
  3450. filename: fromFile,
  3451. paths: module$1._nodeModulePaths(fromDir)
  3452. });
  3453. };
  3454. if (silent) {
  3455. try {
  3456. return resolveFileName();
  3457. } catch (err) {
  3458. return null;
  3459. }
  3460. }
  3461. return resolveFileName();
  3462. };
  3463. module.exports = function (fromDir, moduleId) {
  3464. return resolveFrom(fromDir, moduleId);
  3465. };
  3466. module.exports.silent = function (fromDir, moduleId) {
  3467. return resolveFrom(fromDir, moduleId, true);
  3468. };
  3469. });
  3470. var callsites = createCommonjsModule(function (module) {
  3471. 'use strict';
  3472. module.exports = function () {
  3473. var _ = Error.prepareStackTrace;
  3474. Error.prepareStackTrace = function (_, stack) {
  3475. return stack;
  3476. };
  3477. var stack = new Error().stack.slice(1);
  3478. Error.prepareStackTrace = _;
  3479. return stack;
  3480. };
  3481. });
  3482. var callerCallsite = createCommonjsModule(function (module) {
  3483. 'use strict';
  3484. module.exports = function () {
  3485. var c = callsites();
  3486. var caller;
  3487. for (var i = 0; i < c.length; i++) {
  3488. var hasReceiver = c[i].getTypeName() !== null;
  3489. if (hasReceiver) {
  3490. caller = i;
  3491. break;
  3492. }
  3493. }
  3494. return c[caller];
  3495. };
  3496. });
  3497. var callerPath = function callerPath() {
  3498. return callerCallsite().getFileName();
  3499. };
  3500. var importFresh = createCommonjsModule(function (module) {
  3501. 'use strict';
  3502. module.exports = function (moduleId) {
  3503. if (typeof moduleId !== 'string') {
  3504. throw new TypeError('Expected a string');
  3505. }
  3506. var filePath = resolveFrom_1(path.dirname(callerPath()), moduleId); // Delete itself from module parent
  3507. if (require.cache[filePath] && require.cache[filePath].parent) {
  3508. var i = require.cache[filePath].parent.children.length;
  3509. while (i--) {
  3510. if (require.cache[filePath].parent.children[i].id === filePath) {
  3511. require.cache[filePath].parent.children.splice(i, 1);
  3512. }
  3513. }
  3514. } // Delete module from cache
  3515. delete require.cache[filePath]; // Return fresh module
  3516. return require(filePath);
  3517. };
  3518. });
  3519. function loadJs(filepath) {
  3520. var result = importFresh(filepath);
  3521. return result;
  3522. }
  3523. function loadJson(filepath, content) {
  3524. try {
  3525. return parseJson(content);
  3526. } catch (err) {
  3527. err.message = `JSON Error in ${filepath}:\n${err.message}`;
  3528. throw err;
  3529. }
  3530. }
  3531. function loadYaml(filepath, content) {
  3532. return jsYaml.safeLoad(content, {
  3533. filename: filepath
  3534. });
  3535. }
  3536. var loaders = {
  3537. loadJs,
  3538. loadJson,
  3539. loadYaml
  3540. };
  3541. function readFile(filepath, options) {
  3542. options = options || {};
  3543. var throwNotFound = options.throwNotFound || false;
  3544. return new Promise(function (resolve, reject) {
  3545. fs.readFile(filepath, 'utf8', function (err, content) {
  3546. if (err && err.code === 'ENOENT' && !throwNotFound) {
  3547. return resolve(null);
  3548. }
  3549. if (err) return reject(err);
  3550. resolve(content);
  3551. });
  3552. });
  3553. }
  3554. readFile.sync = function readFileSync(filepath, options) {
  3555. options = options || {};
  3556. var throwNotFound = options.throwNotFound || false;
  3557. try {
  3558. return fs.readFileSync(filepath, 'utf8');
  3559. } catch (err) {
  3560. if (err.code === 'ENOENT' && !throwNotFound) {
  3561. return null;
  3562. }
  3563. throw err;
  3564. }
  3565. };
  3566. var readFile_1 = readFile;
  3567. //
  3568. function cacheWrapper(cache, key, fn) {
  3569. if (!cache) {
  3570. return fn();
  3571. }
  3572. var cached = cache.get(key);
  3573. if (cached !== undefined) {
  3574. return cached;
  3575. }
  3576. var result = fn();
  3577. cache.set(key, result);
  3578. return result;
  3579. }
  3580. var cacheWrapper_1 = cacheWrapper;
  3581. /**
  3582. * async
  3583. */
  3584. function isDirectory(filepath, cb) {
  3585. if (typeof cb !== 'function') {
  3586. throw new Error('expected a callback function');
  3587. }
  3588. if (typeof filepath !== 'string') {
  3589. cb(new Error('expected filepath to be a string'));
  3590. return;
  3591. }
  3592. fs.stat(filepath, function (err, stats) {
  3593. if (err) {
  3594. if (err.code === 'ENOENT') {
  3595. cb(null, false);
  3596. return;
  3597. }
  3598. cb(err);
  3599. return;
  3600. }
  3601. cb(null, stats.isDirectory());
  3602. });
  3603. }
  3604. /**
  3605. * sync
  3606. */
  3607. isDirectory.sync = function isDirectorySync(filepath) {
  3608. if (typeof filepath !== 'string') {
  3609. throw new Error('expected filepath to be a string');
  3610. }
  3611. try {
  3612. var stat = fs.statSync(filepath);
  3613. return stat.isDirectory();
  3614. } catch (err) {
  3615. if (err.code === 'ENOENT') {
  3616. return false;
  3617. } else {
  3618. throw err;
  3619. }
  3620. }
  3621. return false;
  3622. };
  3623. /**
  3624. * Expose `isDirectory`
  3625. */
  3626. var isDirectory_1 = isDirectory;
  3627. function getDirectory(filepath) {
  3628. return new Promise(function (resolve, reject) {
  3629. return isDirectory_1(filepath, function (err, filepathIsDirectory) {
  3630. if (err) {
  3631. return reject(err);
  3632. }
  3633. return resolve(filepathIsDirectory ? filepath : path.dirname(filepath));
  3634. });
  3635. });
  3636. }
  3637. getDirectory.sync = function getDirectorySync(filepath) {
  3638. return isDirectory_1.sync(filepath) ? filepath : path.dirname(filepath);
  3639. };
  3640. var getDirectory_1 = getDirectory;
  3641. var MODE_SYNC = 'sync'; // An object value represents a config object.
  3642. // null represents that the loader did not find anything relevant.
  3643. // undefined represents that the loader found something relevant
  3644. // but it was empty.
  3645. var Explorer =
  3646. /*#__PURE__*/
  3647. function () {
  3648. function Explorer(options) {
  3649. _classCallCheck(this, Explorer);
  3650. this.loadCache = options.cache ? new Map() : null;
  3651. this.loadSyncCache = options.cache ? new Map() : null;
  3652. this.searchCache = options.cache ? new Map() : null;
  3653. this.searchSyncCache = options.cache ? new Map() : null;
  3654. this.config = options;
  3655. this.validateConfig();
  3656. }
  3657. _createClass(Explorer, [{
  3658. key: "clearLoadCache",
  3659. value: function clearLoadCache() {
  3660. if (this.loadCache) {
  3661. this.loadCache.clear();
  3662. }
  3663. if (this.loadSyncCache) {
  3664. this.loadSyncCache.clear();
  3665. }
  3666. }
  3667. }, {
  3668. key: "clearSearchCache",
  3669. value: function clearSearchCache() {
  3670. if (this.searchCache) {
  3671. this.searchCache.clear();
  3672. }
  3673. if (this.searchSyncCache) {
  3674. this.searchSyncCache.clear();
  3675. }
  3676. }
  3677. }, {
  3678. key: "clearCaches",
  3679. value: function clearCaches() {
  3680. this.clearLoadCache();
  3681. this.clearSearchCache();
  3682. }
  3683. }, {
  3684. key: "validateConfig",
  3685. value: function validateConfig() {
  3686. var config = this.config;
  3687. config.searchPlaces.forEach(function (place) {
  3688. var loaderKey = path.extname(place) || 'noExt';
  3689. var loader = config.loaders[loaderKey];
  3690. if (!loader) {
  3691. throw new Error(`No loader specified for ${getExtensionDescription(place)}, so searchPlaces item "${place}" is invalid`);
  3692. }
  3693. });
  3694. }
  3695. }, {
  3696. key: "search",
  3697. value: function search(searchFrom) {
  3698. var _this = this;
  3699. searchFrom = searchFrom || process.cwd();
  3700. return getDirectory_1(searchFrom).then(function (dir) {
  3701. return _this.searchFromDirectory(dir);
  3702. });
  3703. }
  3704. }, {
  3705. key: "searchFromDirectory",
  3706. value: function searchFromDirectory(dir) {
  3707. var _this2 = this;
  3708. var absoluteDir = path.resolve(process.cwd(), dir);
  3709. var run = function run() {
  3710. return _this2.searchDirectory(absoluteDir).then(function (result) {
  3711. var nextDir = _this2.nextDirectoryToSearch(absoluteDir, result);
  3712. if (nextDir) {
  3713. return _this2.searchFromDirectory(nextDir);
  3714. }
  3715. return _this2.config.transform(result);
  3716. });
  3717. };
  3718. if (this.searchCache) {
  3719. return cacheWrapper_1(this.searchCache, absoluteDir, run);
  3720. }
  3721. return run();
  3722. }
  3723. }, {
  3724. key: "searchSync",
  3725. value: function searchSync(searchFrom) {
  3726. searchFrom = searchFrom || process.cwd();
  3727. var dir = getDirectory_1.sync(searchFrom);
  3728. return this.searchFromDirectorySync(dir);
  3729. }
  3730. }, {
  3731. key: "searchFromDirectorySync",
  3732. value: function searchFromDirectorySync(dir) {
  3733. var _this3 = this;
  3734. var absoluteDir = path.resolve(process.cwd(), dir);
  3735. var run = function run() {
  3736. var result = _this3.searchDirectorySync(absoluteDir);
  3737. var nextDir = _this3.nextDirectoryToSearch(absoluteDir, result);
  3738. if (nextDir) {
  3739. return _this3.searchFromDirectorySync(nextDir);
  3740. }
  3741. return _this3.config.transform(result);
  3742. };
  3743. if (this.searchSyncCache) {
  3744. return cacheWrapper_1(this.searchSyncCache, absoluteDir, run);
  3745. }
  3746. return run();
  3747. }
  3748. }, {
  3749. key: "searchDirectory",
  3750. value: function searchDirectory(dir) {
  3751. var _this4 = this;
  3752. return this.config.searchPlaces.reduce(function (prevResultPromise, place) {
  3753. return prevResultPromise.then(function (prevResult) {
  3754. if (_this4.shouldSearchStopWithResult(prevResult)) {
  3755. return prevResult;
  3756. }
  3757. return _this4.loadSearchPlace(dir, place);
  3758. });
  3759. }, Promise.resolve(null));
  3760. }
  3761. }, {
  3762. key: "searchDirectorySync",
  3763. value: function searchDirectorySync(dir) {
  3764. var result = null;
  3765. var _iteratorNormalCompletion = true;
  3766. var _didIteratorError = false;
  3767. var _iteratorError = undefined;
  3768. try {
  3769. for (var _iterator = this.config.searchPlaces[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  3770. var place = _step.value;
  3771. result = this.loadSearchPlaceSync(dir, place);
  3772. if (this.shouldSearchStopWithResult(result)) break;
  3773. }
  3774. } catch (err) {
  3775. _didIteratorError = true;
  3776. _iteratorError = err;
  3777. } finally {
  3778. try {
  3779. if (!_iteratorNormalCompletion && _iterator.return != null) {
  3780. _iterator.return();
  3781. }
  3782. } finally {
  3783. if (_didIteratorError) {
  3784. throw _iteratorError;
  3785. }
  3786. }
  3787. }
  3788. return result;
  3789. }
  3790. }, {
  3791. key: "shouldSearchStopWithResult",
  3792. value: function shouldSearchStopWithResult(result) {
  3793. if (result === null) return false;
  3794. if (result.isEmpty && this.config.ignoreEmptySearchPlaces) return false;
  3795. return true;
  3796. }
  3797. }, {
  3798. key: "loadSearchPlace",
  3799. value: function loadSearchPlace(dir, place) {
  3800. var _this5 = this;
  3801. var filepath = path.join(dir, place);
  3802. return readFile_1(filepath).then(function (content) {
  3803. return _this5.createCosmiconfigResult(filepath, content);
  3804. });
  3805. }
  3806. }, {
  3807. key: "loadSearchPlaceSync",
  3808. value: function loadSearchPlaceSync(dir, place) {
  3809. var filepath = path.join(dir, place);
  3810. var content = readFile_1.sync(filepath);
  3811. return this.createCosmiconfigResultSync(filepath, content);
  3812. }
  3813. }, {
  3814. key: "nextDirectoryToSearch",
  3815. value: function nextDirectoryToSearch(currentDir, currentResult) {
  3816. if (this.shouldSearchStopWithResult(currentResult)) {
  3817. return null;
  3818. }
  3819. var nextDir = nextDirUp(currentDir);
  3820. if (nextDir === currentDir || currentDir === this.config.stopDir) {
  3821. return null;
  3822. }
  3823. return nextDir;
  3824. }
  3825. }, {
  3826. key: "loadPackageProp",
  3827. value: function loadPackageProp(filepath, content) {
  3828. var parsedContent = loaders.loadJson(filepath, content);
  3829. var packagePropValue = parsedContent[this.config.packageProp];
  3830. return packagePropValue || null;
  3831. }
  3832. }, {
  3833. key: "getLoaderEntryForFile",
  3834. value: function getLoaderEntryForFile(filepath) {
  3835. if (path.basename(filepath) === 'package.json') {
  3836. var loader = this.loadPackageProp.bind(this);
  3837. return {
  3838. sync: loader,
  3839. async: loader
  3840. };
  3841. }
  3842. var loaderKey = path.extname(filepath) || 'noExt';
  3843. return this.config.loaders[loaderKey] || {};
  3844. }
  3845. }, {
  3846. key: "getSyncLoaderForFile",
  3847. value: function getSyncLoaderForFile(filepath) {
  3848. var entry = this.getLoaderEntryForFile(filepath);
  3849. if (!entry.sync) {
  3850. throw new Error(`No sync loader specified for ${getExtensionDescription(filepath)}`);
  3851. }
  3852. return entry.sync;
  3853. }
  3854. }, {
  3855. key: "getAsyncLoaderForFile",
  3856. value: function getAsyncLoaderForFile(filepath) {
  3857. var entry = this.getLoaderEntryForFile(filepath);
  3858. var loader = entry.async || entry.sync;
  3859. if (!loader) {
  3860. throw new Error(`No async loader specified for ${getExtensionDescription(filepath)}`);
  3861. }
  3862. return loader;
  3863. }
  3864. }, {
  3865. key: "loadFileContent",
  3866. value: function loadFileContent(mode, filepath, content) {
  3867. if (content === null) {
  3868. return null;
  3869. }
  3870. if (content.trim() === '') {
  3871. return undefined;
  3872. }
  3873. var loader = mode === MODE_SYNC ? this.getSyncLoaderForFile(filepath) : this.getAsyncLoaderForFile(filepath);
  3874. return loader(filepath, content);
  3875. }
  3876. }, {
  3877. key: "loadedContentToCosmiconfigResult",
  3878. value: function loadedContentToCosmiconfigResult(filepath, loadedContent) {
  3879. if (loadedContent === null) {
  3880. return null;
  3881. }
  3882. if (loadedContent === undefined) {
  3883. return {
  3884. filepath,
  3885. config: undefined,
  3886. isEmpty: true
  3887. };
  3888. }
  3889. return {
  3890. config: loadedContent,
  3891. filepath
  3892. };
  3893. }
  3894. }, {
  3895. key: "createCosmiconfigResult",
  3896. value: function createCosmiconfigResult(filepath, content) {
  3897. var _this6 = this;
  3898. return Promise.resolve().then(function () {
  3899. return _this6.loadFileContent('async', filepath, content);
  3900. }).then(function (loaderResult) {
  3901. return _this6.loadedContentToCosmiconfigResult(filepath, loaderResult);
  3902. });
  3903. }
  3904. }, {
  3905. key: "createCosmiconfigResultSync",
  3906. value: function createCosmiconfigResultSync(filepath, content) {
  3907. var loaderResult = this.loadFileContent('sync', filepath, content);
  3908. return this.loadedContentToCosmiconfigResult(filepath, loaderResult);
  3909. }
  3910. }, {
  3911. key: "validateFilePath",
  3912. value: function validateFilePath(filepath) {
  3913. if (!filepath) {
  3914. throw new Error('load and loadSync must pass a non-empty string');
  3915. }
  3916. }
  3917. }, {
  3918. key: "load",
  3919. value: function load(filepath) {
  3920. var _this7 = this;
  3921. return Promise.resolve().then(function () {
  3922. _this7.validateFilePath(filepath);
  3923. var absoluteFilePath = path.resolve(process.cwd(), filepath);
  3924. return cacheWrapper_1(_this7.loadCache, absoluteFilePath, function () {
  3925. return readFile_1(absoluteFilePath, {
  3926. throwNotFound: true
  3927. }).then(function (content) {
  3928. return _this7.createCosmiconfigResult(absoluteFilePath, content);
  3929. }).then(_this7.config.transform);
  3930. });
  3931. });
  3932. }
  3933. }, {
  3934. key: "loadSync",
  3935. value: function loadSync(filepath) {
  3936. var _this8 = this;
  3937. this.validateFilePath(filepath);
  3938. var absoluteFilePath = path.resolve(process.cwd(), filepath);
  3939. return cacheWrapper_1(this.loadSyncCache, absoluteFilePath, function () {
  3940. var content = readFile_1.sync(absoluteFilePath, {
  3941. throwNotFound: true
  3942. });
  3943. var result = _this8.createCosmiconfigResultSync(absoluteFilePath, content);
  3944. return _this8.config.transform(result);
  3945. });
  3946. }
  3947. }]);
  3948. return Explorer;
  3949. }();
  3950. var createExplorer = function createExplorer(options) {
  3951. var explorer = new Explorer(options);
  3952. return {
  3953. search: explorer.search.bind(explorer),
  3954. searchSync: explorer.searchSync.bind(explorer),
  3955. load: explorer.load.bind(explorer),
  3956. loadSync: explorer.loadSync.bind(explorer),
  3957. clearLoadCache: explorer.clearLoadCache.bind(explorer),
  3958. clearSearchCache: explorer.clearSearchCache.bind(explorer),
  3959. clearCaches: explorer.clearCaches.bind(explorer)
  3960. };
  3961. };
  3962. function nextDirUp(dir) {
  3963. return path.dirname(dir);
  3964. }
  3965. function getExtensionDescription(filepath) {
  3966. var ext = path.extname(filepath);
  3967. return ext ? `extension "${ext}"` : 'files without extensions';
  3968. }
  3969. var dist = cosmiconfig;
  3970. function cosmiconfig(moduleName, options) {
  3971. options = options || {};
  3972. var defaults = {
  3973. packageProp: moduleName,
  3974. searchPlaces: ['package.json', `.${moduleName}rc`, `.${moduleName}rc.json`, `.${moduleName}rc.yaml`, `.${moduleName}rc.yml`, `.${moduleName}rc.js`, `${moduleName}.config.js`],
  3975. ignoreEmptySearchPlaces: true,
  3976. stopDir: os.homedir(),
  3977. cache: true,
  3978. transform: identity
  3979. };
  3980. var normalizedOptions = Object.assign({}, defaults, options, {
  3981. loaders: normalizeLoaders(options.loaders)
  3982. });
  3983. return createExplorer(normalizedOptions);
  3984. }
  3985. cosmiconfig.loadJs = loaders.loadJs;
  3986. cosmiconfig.loadJson = loaders.loadJson;
  3987. cosmiconfig.loadYaml = loaders.loadYaml;
  3988. function normalizeLoaders(rawLoaders) {
  3989. var defaults = {
  3990. '.js': {
  3991. sync: loaders.loadJs,
  3992. async: loaders.loadJs
  3993. },
  3994. '.json': {
  3995. sync: loaders.loadJson,
  3996. async: loaders.loadJson
  3997. },
  3998. '.yaml': {
  3999. sync: loaders.loadYaml,
  4000. async: loaders.loadYaml
  4001. },
  4002. '.yml': {
  4003. sync: loaders.loadYaml,
  4004. async: loaders.loadYaml
  4005. },
  4006. noExt: {
  4007. sync: loaders.loadYaml,
  4008. async: loaders.loadYaml
  4009. }
  4010. };
  4011. if (!rawLoaders) {
  4012. return defaults;
  4013. }
  4014. return Object.keys(rawLoaders).reduce(function (result, ext) {
  4015. var entry = rawLoaders && rawLoaders[ext];
  4016. if (typeof entry === 'function') {
  4017. result[ext] = {
  4018. sync: entry,
  4019. async: entry
  4020. };
  4021. } else {
  4022. result[ext] = entry;
  4023. }
  4024. return result;
  4025. }, defaults);
  4026. }
  4027. function identity(x) {
  4028. return x;
  4029. }
  4030. var findParentDir$1 = createCommonjsModule(function (module, exports) {
  4031. 'use strict';
  4032. var exists = fs.exists || path.exists,
  4033. existsSync = fs.existsSync || path.existsSync;
  4034. function splitPath(path$$2) {
  4035. var parts = path$$2.split(/(\/|\\)/);
  4036. if (!parts.length) return parts; // when path starts with a slash, the first part is empty string
  4037. return !parts[0].length ? parts.slice(1) : parts;
  4038. }
  4039. exports = module.exports = function (currentFullPath, clue, cb) {
  4040. function testDir(parts) {
  4041. if (parts.length === 0) return cb(null, null);
  4042. var p = parts.join('');
  4043. exists(path.join(p, clue), function (itdoes) {
  4044. if (itdoes) return cb(null, p);
  4045. testDir(parts.slice(0, -1));
  4046. });
  4047. }
  4048. testDir(splitPath(currentFullPath));
  4049. };
  4050. exports.sync = function (currentFullPath, clue) {
  4051. function testDir(parts) {
  4052. if (parts.length === 0) return null;
  4053. var p = parts.join('');
  4054. var itdoes = existsSync(path.join(p, clue));
  4055. return itdoes ? p : testDir(parts.slice(0, -1));
  4056. }
  4057. return testDir(splitPath(currentFullPath));
  4058. };
  4059. });
  4060. var bufferStream = createCommonjsModule(function (module) {
  4061. 'use strict';
  4062. var PassThrough = stream.PassThrough;
  4063. module.exports = function (opts) {
  4064. opts = Object.assign({}, opts);
  4065. var array = opts.array;
  4066. var encoding = opts.encoding;
  4067. var buffer = encoding === 'buffer';
  4068. var objectMode = false;
  4069. if (array) {
  4070. objectMode = !(encoding || buffer);
  4071. } else {
  4072. encoding = encoding || 'utf8';
  4073. }
  4074. if (buffer) {
  4075. encoding = null;
  4076. }
  4077. var len = 0;
  4078. var ret = [];
  4079. var stream$$1 = new PassThrough({
  4080. objectMode
  4081. });
  4082. if (encoding) {
  4083. stream$$1.setEncoding(encoding);
  4084. }
  4085. stream$$1.on('data', function (chunk) {
  4086. ret.push(chunk);
  4087. if (objectMode) {
  4088. len = ret.length;
  4089. } else {
  4090. len += chunk.length;
  4091. }
  4092. });
  4093. stream$$1.getBufferedValue = function () {
  4094. if (array) {
  4095. return ret;
  4096. }
  4097. return buffer ? Buffer.concat(ret, len) : ret.join('');
  4098. };
  4099. stream$$1.getBufferedLength = function () {
  4100. return len;
  4101. };
  4102. return stream$$1;
  4103. };
  4104. });
  4105. function getStream(inputStream, opts) {
  4106. if (!inputStream) {
  4107. return Promise.reject(new Error('Expected a stream'));
  4108. }
  4109. opts = Object.assign({
  4110. maxBuffer: Infinity
  4111. }, opts);
  4112. var maxBuffer = opts.maxBuffer;
  4113. var stream$$1;
  4114. var clean;
  4115. var p = new Promise(function (resolve, reject) {
  4116. var error = function error(err) {
  4117. if (err) {
  4118. // null check
  4119. err.bufferedData = stream$$1.getBufferedValue();
  4120. }
  4121. reject(err);
  4122. };
  4123. stream$$1 = bufferStream(opts);
  4124. inputStream.once('error', error);
  4125. inputStream.pipe(stream$$1);
  4126. stream$$1.on('data', function () {
  4127. if (stream$$1.getBufferedLength() > maxBuffer) {
  4128. reject(new Error('maxBuffer exceeded'));
  4129. }
  4130. });
  4131. stream$$1.once('error', error);
  4132. stream$$1.on('end', resolve);
  4133. clean = function clean() {
  4134. // some streams doesn't implement the `stream.Readable` interface correctly
  4135. if (inputStream.unpipe) {
  4136. inputStream.unpipe(stream$$1);
  4137. }
  4138. };
  4139. });
  4140. p.then(clean, clean);
  4141. return p.then(function () {
  4142. return stream$$1.getBufferedValue();
  4143. });
  4144. }
  4145. var getStream_1 = getStream;
  4146. var buffer = function buffer(stream$$1, opts) {
  4147. return getStream(stream$$1, Object.assign({}, opts, {
  4148. encoding: 'buffer'
  4149. }));
  4150. };
  4151. var array = function array(stream$$1, opts) {
  4152. return getStream(stream$$1, Object.assign({}, opts, {
  4153. array: true
  4154. }));
  4155. };
  4156. getStream_1.buffer = buffer;
  4157. getStream_1.array = array;
  4158. var vendors = [{
  4159. "name": "AppVeyor",
  4160. "constant": "APPVEYOR",
  4161. "env": "APPVEYOR",
  4162. "pr": "APPVEYOR_PULL_REQUEST_NUMBER"
  4163. }, {
  4164. "name": "Azure Pipelines",
  4165. "constant": "AZURE_PIPELINES",
  4166. "env": "SYSTEM_TEAMFOUNDATIONCOLLECTIONURI",
  4167. "pr": "SYSTEM_PULLREQUEST_PULLREQUESTID"
  4168. }, {
  4169. "name": "Bamboo",
  4170. "constant": "BAMBOO",
  4171. "env": "bamboo_planKey"
  4172. }, {
  4173. "name": "Bitbucket Pipelines",
  4174. "constant": "BITBUCKET",
  4175. "env": "BITBUCKET_COMMIT",
  4176. "pr": "BITBUCKET_PR_ID"
  4177. }, {
  4178. "name": "Bitrise",
  4179. "constant": "BITRISE",
  4180. "env": "BITRISE_IO",
  4181. "pr": "BITRISE_PULL_REQUEST"
  4182. }, {
  4183. "name": "Buddy",
  4184. "constant": "BUDDY",
  4185. "env": "BUDDY_WORKSPACE_ID",
  4186. "pr": "BUDDY_EXECUTION_PULL_REQUEST_ID"
  4187. }, {
  4188. "name": "Buildkite",
  4189. "constant": "BUILDKITE",
  4190. "env": "BUILDKITE",
  4191. "pr": {
  4192. "env": "BUILDKITE_PULL_REQUEST",
  4193. "ne": "false"
  4194. }
  4195. }, {
  4196. "name": "CircleCI",
  4197. "constant": "CIRCLE",
  4198. "env": "CIRCLECI",
  4199. "pr": "CIRCLE_PULL_REQUEST"
  4200. }, {
  4201. "name": "Cirrus CI",
  4202. "constant": "CIRRUS",
  4203. "env": "CIRRUS_CI",
  4204. "pr": "CIRRUS_PR"
  4205. }, {
  4206. "name": "AWS CodeBuild",
  4207. "constant": "CODEBUILD",
  4208. "env": "CODEBUILD_BUILD_ARN"
  4209. }, {
  4210. "name": "Codeship",
  4211. "constant": "CODESHIP",
  4212. "env": {
  4213. "CI_NAME": "codeship"
  4214. }
  4215. }, {
  4216. "name": "Drone",
  4217. "constant": "DRONE",
  4218. "env": "DRONE",
  4219. "pr": {
  4220. "DRONE_BUILD_EVENT": "pull_request"
  4221. }
  4222. }, {
  4223. "name": "dsari",
  4224. "constant": "DSARI",
  4225. "env": "DSARI"
  4226. }, {
  4227. "name": "GitLab CI",
  4228. "constant": "GITLAB",
  4229. "env": "GITLAB_CI"
  4230. }, {
  4231. "name": "GoCD",
  4232. "constant": "GOCD",
  4233. "env": "GO_PIPELINE_LABEL"
  4234. }, {
  4235. "name": "Hudson",
  4236. "constant": "HUDSON",
  4237. "env": "HUDSON_URL"
  4238. }, {
  4239. "name": "Jenkins",
  4240. "constant": "JENKINS",
  4241. "env": ["JENKINS_URL", "BUILD_ID"],
  4242. "pr": {
  4243. "any": ["ghprbPullId", "CHANGE_ID"]
  4244. }
  4245. }, {
  4246. "name": "Magnum CI",
  4247. "constant": "MAGNUM",
  4248. "env": "MAGNUM"
  4249. }, {
  4250. "name": "Netlify CI",
  4251. "constant": "NETLIFY",
  4252. "env": "NETLIFY_BUILD_BASE",
  4253. "pr": {
  4254. "env": "PULL_REQUEST",
  4255. "ne": "false"
  4256. }
  4257. }, {
  4258. "name": "Sail CI",
  4259. "constant": "SAIL",
  4260. "env": "SAILCI",
  4261. "pr": "SAIL_PULL_REQUEST_NUMBER"
  4262. }, {
  4263. "name": "Semaphore",
  4264. "constant": "SEMAPHORE",
  4265. "env": "SEMAPHORE",
  4266. "pr": "PULL_REQUEST_NUMBER"
  4267. }, {
  4268. "name": "Shippable",
  4269. "constant": "SHIPPABLE",
  4270. "env": "SHIPPABLE",
  4271. "pr": {
  4272. "IS_PULL_REQUEST": "true"
  4273. }
  4274. }, {
  4275. "name": "Solano CI",
  4276. "constant": "SOLANO",
  4277. "env": "TDDIUM",
  4278. "pr": "TDDIUM_PR_ID"
  4279. }, {
  4280. "name": "Strider CD",
  4281. "constant": "STRIDER",
  4282. "env": "STRIDER"
  4283. }, {
  4284. "name": "TaskCluster",
  4285. "constant": "TASKCLUSTER",
  4286. "env": ["TASK_ID", "RUN_ID"]
  4287. }, {
  4288. "name": "TeamCity",
  4289. "constant": "TEAMCITY",
  4290. "env": "TEAMCITY_VERSION"
  4291. }, {
  4292. "name": "Travis CI",
  4293. "constant": "TRAVIS",
  4294. "env": "TRAVIS",
  4295. "pr": {
  4296. "env": "TRAVIS_PULL_REQUEST",
  4297. "ne": "false"
  4298. }
  4299. }];
  4300. var vendors$1 = Object.freeze({
  4301. default: vendors
  4302. });
  4303. var vendors$2 = ( vendors$1 && vendors ) || vendors$1;
  4304. var ciInfo = createCommonjsModule(function (module, exports) {
  4305. 'use strict';
  4306. var env = process.env; // Used for testing only
  4307. Object.defineProperty(exports, '_vendors', {
  4308. value: vendors$2.map(function (v) {
  4309. return v.constant;
  4310. })
  4311. });
  4312. exports.name = null;
  4313. exports.isPR = null;
  4314. vendors$2.forEach(function (vendor) {
  4315. var envs = Array.isArray(vendor.env) ? vendor.env : [vendor.env];
  4316. var isCI = envs.every(function (obj) {
  4317. return checkEnv(obj);
  4318. });
  4319. exports[vendor.constant] = isCI;
  4320. if (isCI) {
  4321. exports.name = vendor.name;
  4322. switch (typeof vendor.pr) {
  4323. case 'string':
  4324. // "pr": "CIRRUS_PR"
  4325. exports.isPR = !!env[vendor.pr];
  4326. break;
  4327. case 'object':
  4328. if ('env' in vendor.pr) {
  4329. // "pr": { "env": "BUILDKITE_PULL_REQUEST", "ne": "false" }
  4330. exports.isPR = vendor.pr.env in env && env[vendor.pr.env] !== vendor.pr.ne;
  4331. } else if ('any' in vendor.pr) {
  4332. // "pr": { "any": ["ghprbPullId", "CHANGE_ID"] }
  4333. exports.isPR = vendor.pr.any.some(function (key) {
  4334. return !!env[key];
  4335. });
  4336. } else {
  4337. // "pr": { "DRONE_BUILD_EVENT": "pull_request" }
  4338. exports.isPR = checkEnv(vendor.pr);
  4339. }
  4340. break;
  4341. default:
  4342. // PR detection not supported for this vendor
  4343. exports.isPR = null;
  4344. }
  4345. }
  4346. });
  4347. exports.isCI = !!(env.CI || // Travis CI, CircleCI, Cirrus CI, Gitlab CI, Appveyor, CodeShip, dsari
  4348. env.CONTINUOUS_INTEGRATION || // Travis CI, Cirrus CI
  4349. env.BUILD_NUMBER || // Jenkins, TeamCity
  4350. env.RUN_ID || // TaskCluster, dsari
  4351. exports.name || false);
  4352. function checkEnv(obj) {
  4353. if (typeof obj === 'string') return !!env[obj];
  4354. return Object.keys(obj).every(function (k) {
  4355. return env[k] === obj[k];
  4356. });
  4357. }
  4358. });
  4359. var isCi = ciInfo.isCI;
  4360. var findParentDir = findParentDir$1.sync;
  4361. var thirdParty = {
  4362. cosmiconfig: dist,
  4363. findParentDir,
  4364. getStream: getStream_1,
  4365. isCI:
  4366. /* istanbul ignore next */
  4367. function isCI() {
  4368. return isCi;
  4369. }
  4370. };
  4371. module.exports = thirdParty;