third-party.js 135 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327
  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 is_EOL(c) {
  1343. return c === 0x0A
  1344. /* LF */
  1345. || c === 0x0D
  1346. /* CR */
  1347. ;
  1348. }
  1349. function is_WHITE_SPACE(c) {
  1350. return c === 0x09
  1351. /* Tab */
  1352. || c === 0x20
  1353. /* Space */
  1354. ;
  1355. }
  1356. function is_WS_OR_EOL(c) {
  1357. return c === 0x09
  1358. /* Tab */
  1359. || c === 0x20
  1360. /* Space */
  1361. || c === 0x0A
  1362. /* LF */
  1363. || c === 0x0D
  1364. /* CR */
  1365. ;
  1366. }
  1367. function is_FLOW_INDICATOR(c) {
  1368. return c === 0x2C
  1369. /* , */
  1370. || c === 0x5B
  1371. /* [ */
  1372. || c === 0x5D
  1373. /* ] */
  1374. || c === 0x7B
  1375. /* { */
  1376. || c === 0x7D
  1377. /* } */
  1378. ;
  1379. }
  1380. function fromHexCode(c) {
  1381. var lc;
  1382. if (0x30
  1383. /* 0 */
  1384. <= c && c <= 0x39
  1385. /* 9 */
  1386. ) {
  1387. return c - 0x30;
  1388. }
  1389. /*eslint-disable no-bitwise*/
  1390. lc = c | 0x20;
  1391. if (0x61
  1392. /* a */
  1393. <= lc && lc <= 0x66
  1394. /* f */
  1395. ) {
  1396. return lc - 0x61 + 10;
  1397. }
  1398. return -1;
  1399. }
  1400. function escapedHexLen(c) {
  1401. if (c === 0x78
  1402. /* x */
  1403. ) {
  1404. return 2;
  1405. }
  1406. if (c === 0x75
  1407. /* u */
  1408. ) {
  1409. return 4;
  1410. }
  1411. if (c === 0x55
  1412. /* U */
  1413. ) {
  1414. return 8;
  1415. }
  1416. return 0;
  1417. }
  1418. function fromDecimalCode(c) {
  1419. if (0x30
  1420. /* 0 */
  1421. <= c && c <= 0x39
  1422. /* 9 */
  1423. ) {
  1424. return c - 0x30;
  1425. }
  1426. return -1;
  1427. }
  1428. function simpleEscapeSequence(c) {
  1429. /* eslint-disable indent */
  1430. return c === 0x30
  1431. /* 0 */
  1432. ? '\x00' : c === 0x61
  1433. /* a */
  1434. ? '\x07' : c === 0x62
  1435. /* b */
  1436. ? '\x08' : c === 0x74
  1437. /* t */
  1438. ? '\x09' : c === 0x09
  1439. /* Tab */
  1440. ? '\x09' : c === 0x6E
  1441. /* n */
  1442. ? '\x0A' : c === 0x76
  1443. /* v */
  1444. ? '\x0B' : c === 0x66
  1445. /* f */
  1446. ? '\x0C' : c === 0x72
  1447. /* r */
  1448. ? '\x0D' : c === 0x65
  1449. /* e */
  1450. ? '\x1B' : c === 0x20
  1451. /* Space */
  1452. ? ' ' : c === 0x22
  1453. /* " */
  1454. ? '\x22' : c === 0x2F
  1455. /* / */
  1456. ? '/' : c === 0x5C
  1457. /* \ */
  1458. ? '\x5C' : c === 0x4E
  1459. /* N */
  1460. ? '\x85' : c === 0x5F
  1461. /* _ */
  1462. ? '\xA0' : c === 0x4C
  1463. /* L */
  1464. ? '\u2028' : c === 0x50
  1465. /* P */
  1466. ? '\u2029' : '';
  1467. }
  1468. function charFromCodepoint(c) {
  1469. if (c <= 0xFFFF) {
  1470. return String.fromCharCode(c);
  1471. } // Encode UTF-16 surrogate pair
  1472. // https://en.wikipedia.org/wiki/UTF-16#Code_points_U.2B010000_to_U.2B10FFFF
  1473. return String.fromCharCode((c - 0x010000 >> 10) + 0xD800, (c - 0x010000 & 0x03FF) + 0xDC00);
  1474. }
  1475. var simpleEscapeCheck = new Array(256); // integer, for fast access
  1476. var simpleEscapeMap = new Array(256);
  1477. for (var i = 0; i < 256; i++) {
  1478. simpleEscapeCheck[i] = simpleEscapeSequence(i) ? 1 : 0;
  1479. simpleEscapeMap[i] = simpleEscapeSequence(i);
  1480. }
  1481. function State(input, options) {
  1482. this.input = input;
  1483. this.filename = options['filename'] || null;
  1484. this.schema = options['schema'] || default_full;
  1485. this.onWarning = options['onWarning'] || null;
  1486. this.legacy = options['legacy'] || false;
  1487. this.json = options['json'] || false;
  1488. this.listener = options['listener'] || null;
  1489. this.implicitTypes = this.schema.compiledImplicit;
  1490. this.typeMap = this.schema.compiledTypeMap;
  1491. this.length = input.length;
  1492. this.position = 0;
  1493. this.line = 0;
  1494. this.lineStart = 0;
  1495. this.lineIndent = 0;
  1496. this.documents = [];
  1497. /*
  1498. this.version;
  1499. this.checkLineBreaks;
  1500. this.tagMap;
  1501. this.anchorMap;
  1502. this.tag;
  1503. this.anchor;
  1504. this.kind;
  1505. this.result;*/
  1506. }
  1507. function generateError(state, message) {
  1508. return new exception(message, new mark(state.filename, state.input, state.position, state.line, state.position - state.lineStart));
  1509. }
  1510. function throwError(state, message) {
  1511. throw generateError(state, message);
  1512. }
  1513. function throwWarning(state, message) {
  1514. if (state.onWarning) {
  1515. state.onWarning.call(null, generateError(state, message));
  1516. }
  1517. }
  1518. var directiveHandlers = {
  1519. YAML: function handleYamlDirective(state, name, args) {
  1520. var match, major, minor;
  1521. if (state.version !== null) {
  1522. throwError(state, 'duplication of %YAML directive');
  1523. }
  1524. if (args.length !== 1) {
  1525. throwError(state, 'YAML directive accepts exactly one argument');
  1526. }
  1527. match = /^([0-9]+)\.([0-9]+)$/.exec(args[0]);
  1528. if (match === null) {
  1529. throwError(state, 'ill-formed argument of the YAML directive');
  1530. }
  1531. major = parseInt(match[1], 10);
  1532. minor = parseInt(match[2], 10);
  1533. if (major !== 1) {
  1534. throwError(state, 'unacceptable YAML version of the document');
  1535. }
  1536. state.version = args[0];
  1537. state.checkLineBreaks = minor < 2;
  1538. if (minor !== 1 && minor !== 2) {
  1539. throwWarning(state, 'unsupported YAML version of the document');
  1540. }
  1541. },
  1542. TAG: function handleTagDirective(state, name, args) {
  1543. var handle, prefix;
  1544. if (args.length !== 2) {
  1545. throwError(state, 'TAG directive accepts exactly two arguments');
  1546. }
  1547. handle = args[0];
  1548. prefix = args[1];
  1549. if (!PATTERN_TAG_HANDLE.test(handle)) {
  1550. throwError(state, 'ill-formed tag handle (first argument) of the TAG directive');
  1551. }
  1552. if (_hasOwnProperty.call(state.tagMap, handle)) {
  1553. throwError(state, 'there is a previously declared suffix for "' + handle + '" tag handle');
  1554. }
  1555. if (!PATTERN_TAG_URI.test(prefix)) {
  1556. throwError(state, 'ill-formed tag prefix (second argument) of the TAG directive');
  1557. }
  1558. state.tagMap[handle] = prefix;
  1559. }
  1560. };
  1561. function captureSegment(state, start, end, checkJson) {
  1562. var _position, _length, _character, _result;
  1563. if (start < end) {
  1564. _result = state.input.slice(start, end);
  1565. if (checkJson) {
  1566. for (_position = 0, _length = _result.length; _position < _length; _position += 1) {
  1567. _character = _result.charCodeAt(_position);
  1568. if (!(_character === 0x09 || 0x20 <= _character && _character <= 0x10FFFF)) {
  1569. throwError(state, 'expected valid JSON character');
  1570. }
  1571. }
  1572. } else if (PATTERN_NON_PRINTABLE.test(_result)) {
  1573. throwError(state, 'the stream contains non-printable characters');
  1574. }
  1575. state.result += _result;
  1576. }
  1577. }
  1578. function mergeMappings(state, destination, source, overridableKeys) {
  1579. var sourceKeys, key, index, quantity;
  1580. if (!common.isObject(source)) {
  1581. throwError(state, 'cannot merge mappings; the provided source object is unacceptable');
  1582. }
  1583. sourceKeys = Object.keys(source);
  1584. for (index = 0, quantity = sourceKeys.length; index < quantity; index += 1) {
  1585. key = sourceKeys[index];
  1586. if (!_hasOwnProperty.call(destination, key)) {
  1587. destination[key] = source[key];
  1588. overridableKeys[key] = true;
  1589. }
  1590. }
  1591. }
  1592. function storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, startLine, startPos) {
  1593. var index, quantity;
  1594. keyNode = String(keyNode);
  1595. if (_result === null) {
  1596. _result = {};
  1597. }
  1598. if (keyTag === 'tag:yaml.org,2002:merge') {
  1599. if (Array.isArray(valueNode)) {
  1600. for (index = 0, quantity = valueNode.length; index < quantity; index += 1) {
  1601. mergeMappings(state, _result, valueNode[index], overridableKeys);
  1602. }
  1603. } else {
  1604. mergeMappings(state, _result, valueNode, overridableKeys);
  1605. }
  1606. } else {
  1607. if (!state.json && !_hasOwnProperty.call(overridableKeys, keyNode) && _hasOwnProperty.call(_result, keyNode)) {
  1608. state.line = startLine || state.line;
  1609. state.position = startPos || state.position;
  1610. throwError(state, 'duplicated mapping key');
  1611. }
  1612. _result[keyNode] = valueNode;
  1613. delete overridableKeys[keyNode];
  1614. }
  1615. return _result;
  1616. }
  1617. function readLineBreak(state) {
  1618. var ch;
  1619. ch = state.input.charCodeAt(state.position);
  1620. if (ch === 0x0A
  1621. /* LF */
  1622. ) {
  1623. state.position++;
  1624. } else if (ch === 0x0D
  1625. /* CR */
  1626. ) {
  1627. state.position++;
  1628. if (state.input.charCodeAt(state.position) === 0x0A
  1629. /* LF */
  1630. ) {
  1631. state.position++;
  1632. }
  1633. } else {
  1634. throwError(state, 'a line break is expected');
  1635. }
  1636. state.line += 1;
  1637. state.lineStart = state.position;
  1638. }
  1639. function skipSeparationSpace(state, allowComments, checkIndent) {
  1640. var lineBreaks = 0,
  1641. ch = state.input.charCodeAt(state.position);
  1642. while (ch !== 0) {
  1643. while (is_WHITE_SPACE(ch)) {
  1644. ch = state.input.charCodeAt(++state.position);
  1645. }
  1646. if (allowComments && ch === 0x23
  1647. /* # */
  1648. ) {
  1649. do {
  1650. ch = state.input.charCodeAt(++state.position);
  1651. } while (ch !== 0x0A
  1652. /* LF */
  1653. && ch !== 0x0D
  1654. /* CR */
  1655. && ch !== 0);
  1656. }
  1657. if (is_EOL(ch)) {
  1658. readLineBreak(state);
  1659. ch = state.input.charCodeAt(state.position);
  1660. lineBreaks++;
  1661. state.lineIndent = 0;
  1662. while (ch === 0x20
  1663. /* Space */
  1664. ) {
  1665. state.lineIndent++;
  1666. ch = state.input.charCodeAt(++state.position);
  1667. }
  1668. } else {
  1669. break;
  1670. }
  1671. }
  1672. if (checkIndent !== -1 && lineBreaks !== 0 && state.lineIndent < checkIndent) {
  1673. throwWarning(state, 'deficient indentation');
  1674. }
  1675. return lineBreaks;
  1676. }
  1677. function testDocumentSeparator(state) {
  1678. var _position = state.position,
  1679. ch;
  1680. ch = state.input.charCodeAt(_position); // Condition state.position === state.lineStart is tested
  1681. // in parent on each call, for efficiency. No needs to test here again.
  1682. if ((ch === 0x2D
  1683. /* - */
  1684. || ch === 0x2E
  1685. /* . */
  1686. ) && ch === state.input.charCodeAt(_position + 1) && ch === state.input.charCodeAt(_position + 2)) {
  1687. _position += 3;
  1688. ch = state.input.charCodeAt(_position);
  1689. if (ch === 0 || is_WS_OR_EOL(ch)) {
  1690. return true;
  1691. }
  1692. }
  1693. return false;
  1694. }
  1695. function writeFoldedLines(state, count) {
  1696. if (count === 1) {
  1697. state.result += ' ';
  1698. } else if (count > 1) {
  1699. state.result += common.repeat('\n', count - 1);
  1700. }
  1701. }
  1702. function readPlainScalar(state, nodeIndent, withinFlowCollection) {
  1703. var preceding,
  1704. following,
  1705. captureStart,
  1706. captureEnd,
  1707. hasPendingContent,
  1708. _line,
  1709. _lineStart,
  1710. _lineIndent,
  1711. _kind = state.kind,
  1712. _result = state.result,
  1713. ch;
  1714. ch = state.input.charCodeAt(state.position);
  1715. if (is_WS_OR_EOL(ch) || is_FLOW_INDICATOR(ch) || ch === 0x23
  1716. /* # */
  1717. || ch === 0x26
  1718. /* & */
  1719. || ch === 0x2A
  1720. /* * */
  1721. || ch === 0x21
  1722. /* ! */
  1723. || ch === 0x7C
  1724. /* | */
  1725. || ch === 0x3E
  1726. /* > */
  1727. || ch === 0x27
  1728. /* ' */
  1729. || ch === 0x22
  1730. /* " */
  1731. || ch === 0x25
  1732. /* % */
  1733. || ch === 0x40
  1734. /* @ */
  1735. || ch === 0x60
  1736. /* ` */
  1737. ) {
  1738. return false;
  1739. }
  1740. if (ch === 0x3F
  1741. /* ? */
  1742. || ch === 0x2D
  1743. /* - */
  1744. ) {
  1745. following = state.input.charCodeAt(state.position + 1);
  1746. if (is_WS_OR_EOL(following) || withinFlowCollection && is_FLOW_INDICATOR(following)) {
  1747. return false;
  1748. }
  1749. }
  1750. state.kind = 'scalar';
  1751. state.result = '';
  1752. captureStart = captureEnd = state.position;
  1753. hasPendingContent = false;
  1754. while (ch !== 0) {
  1755. if (ch === 0x3A
  1756. /* : */
  1757. ) {
  1758. following = state.input.charCodeAt(state.position + 1);
  1759. if (is_WS_OR_EOL(following) || withinFlowCollection && is_FLOW_INDICATOR(following)) {
  1760. break;
  1761. }
  1762. } else if (ch === 0x23
  1763. /* # */
  1764. ) {
  1765. preceding = state.input.charCodeAt(state.position - 1);
  1766. if (is_WS_OR_EOL(preceding)) {
  1767. break;
  1768. }
  1769. } else if (state.position === state.lineStart && testDocumentSeparator(state) || withinFlowCollection && is_FLOW_INDICATOR(ch)) {
  1770. break;
  1771. } else if (is_EOL(ch)) {
  1772. _line = state.line;
  1773. _lineStart = state.lineStart;
  1774. _lineIndent = state.lineIndent;
  1775. skipSeparationSpace(state, false, -1);
  1776. if (state.lineIndent >= nodeIndent) {
  1777. hasPendingContent = true;
  1778. ch = state.input.charCodeAt(state.position);
  1779. continue;
  1780. } else {
  1781. state.position = captureEnd;
  1782. state.line = _line;
  1783. state.lineStart = _lineStart;
  1784. state.lineIndent = _lineIndent;
  1785. break;
  1786. }
  1787. }
  1788. if (hasPendingContent) {
  1789. captureSegment(state, captureStart, captureEnd, false);
  1790. writeFoldedLines(state, state.line - _line);
  1791. captureStart = captureEnd = state.position;
  1792. hasPendingContent = false;
  1793. }
  1794. if (!is_WHITE_SPACE(ch)) {
  1795. captureEnd = state.position + 1;
  1796. }
  1797. ch = state.input.charCodeAt(++state.position);
  1798. }
  1799. captureSegment(state, captureStart, captureEnd, false);
  1800. if (state.result) {
  1801. return true;
  1802. }
  1803. state.kind = _kind;
  1804. state.result = _result;
  1805. return false;
  1806. }
  1807. function readSingleQuotedScalar(state, nodeIndent) {
  1808. var ch, captureStart, captureEnd;
  1809. ch = state.input.charCodeAt(state.position);
  1810. if (ch !== 0x27
  1811. /* ' */
  1812. ) {
  1813. return false;
  1814. }
  1815. state.kind = 'scalar';
  1816. state.result = '';
  1817. state.position++;
  1818. captureStart = captureEnd = state.position;
  1819. while ((ch = state.input.charCodeAt(state.position)) !== 0) {
  1820. if (ch === 0x27
  1821. /* ' */
  1822. ) {
  1823. captureSegment(state, captureStart, state.position, true);
  1824. ch = state.input.charCodeAt(++state.position);
  1825. if (ch === 0x27
  1826. /* ' */
  1827. ) {
  1828. captureStart = state.position;
  1829. state.position++;
  1830. captureEnd = state.position;
  1831. } else {
  1832. return true;
  1833. }
  1834. } else if (is_EOL(ch)) {
  1835. captureSegment(state, captureStart, captureEnd, true);
  1836. writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
  1837. captureStart = captureEnd = state.position;
  1838. } else if (state.position === state.lineStart && testDocumentSeparator(state)) {
  1839. throwError(state, 'unexpected end of the document within a single quoted scalar');
  1840. } else {
  1841. state.position++;
  1842. captureEnd = state.position;
  1843. }
  1844. }
  1845. throwError(state, 'unexpected end of the stream within a single quoted scalar');
  1846. }
  1847. function readDoubleQuotedScalar(state, nodeIndent) {
  1848. var captureStart, captureEnd, hexLength, hexResult, tmp, ch;
  1849. ch = state.input.charCodeAt(state.position);
  1850. if (ch !== 0x22
  1851. /* " */
  1852. ) {
  1853. return false;
  1854. }
  1855. state.kind = 'scalar';
  1856. state.result = '';
  1857. state.position++;
  1858. captureStart = captureEnd = state.position;
  1859. while ((ch = state.input.charCodeAt(state.position)) !== 0) {
  1860. if (ch === 0x22
  1861. /* " */
  1862. ) {
  1863. captureSegment(state, captureStart, state.position, true);
  1864. state.position++;
  1865. return true;
  1866. } else if (ch === 0x5C
  1867. /* \ */
  1868. ) {
  1869. captureSegment(state, captureStart, state.position, true);
  1870. ch = state.input.charCodeAt(++state.position);
  1871. if (is_EOL(ch)) {
  1872. skipSeparationSpace(state, false, nodeIndent); // TODO: rework to inline fn with no type cast?
  1873. } else if (ch < 256 && simpleEscapeCheck[ch]) {
  1874. state.result += simpleEscapeMap[ch];
  1875. state.position++;
  1876. } else if ((tmp = escapedHexLen(ch)) > 0) {
  1877. hexLength = tmp;
  1878. hexResult = 0;
  1879. for (; hexLength > 0; hexLength--) {
  1880. ch = state.input.charCodeAt(++state.position);
  1881. if ((tmp = fromHexCode(ch)) >= 0) {
  1882. hexResult = (hexResult << 4) + tmp;
  1883. } else {
  1884. throwError(state, 'expected hexadecimal character');
  1885. }
  1886. }
  1887. state.result += charFromCodepoint(hexResult);
  1888. state.position++;
  1889. } else {
  1890. throwError(state, 'unknown escape sequence');
  1891. }
  1892. captureStart = captureEnd = state.position;
  1893. } else if (is_EOL(ch)) {
  1894. captureSegment(state, captureStart, captureEnd, true);
  1895. writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
  1896. captureStart = captureEnd = state.position;
  1897. } else if (state.position === state.lineStart && testDocumentSeparator(state)) {
  1898. throwError(state, 'unexpected end of the document within a double quoted scalar');
  1899. } else {
  1900. state.position++;
  1901. captureEnd = state.position;
  1902. }
  1903. }
  1904. throwError(state, 'unexpected end of the stream within a double quoted scalar');
  1905. }
  1906. function readFlowCollection(state, nodeIndent) {
  1907. var readNext = true,
  1908. _line,
  1909. _tag = state.tag,
  1910. _result,
  1911. _anchor = state.anchor,
  1912. following,
  1913. terminator,
  1914. isPair,
  1915. isExplicitPair,
  1916. isMapping,
  1917. overridableKeys = {},
  1918. keyNode,
  1919. keyTag,
  1920. valueNode,
  1921. ch;
  1922. ch = state.input.charCodeAt(state.position);
  1923. if (ch === 0x5B
  1924. /* [ */
  1925. ) {
  1926. terminator = 0x5D;
  1927. /* ] */
  1928. isMapping = false;
  1929. _result = [];
  1930. } else if (ch === 0x7B
  1931. /* { */
  1932. ) {
  1933. terminator = 0x7D;
  1934. /* } */
  1935. isMapping = true;
  1936. _result = {};
  1937. } else {
  1938. return false;
  1939. }
  1940. if (state.anchor !== null) {
  1941. state.anchorMap[state.anchor] = _result;
  1942. }
  1943. ch = state.input.charCodeAt(++state.position);
  1944. while (ch !== 0) {
  1945. skipSeparationSpace(state, true, nodeIndent);
  1946. ch = state.input.charCodeAt(state.position);
  1947. if (ch === terminator) {
  1948. state.position++;
  1949. state.tag = _tag;
  1950. state.anchor = _anchor;
  1951. state.kind = isMapping ? 'mapping' : 'sequence';
  1952. state.result = _result;
  1953. return true;
  1954. } else if (!readNext) {
  1955. throwError(state, 'missed comma between flow collection entries');
  1956. }
  1957. keyTag = keyNode = valueNode = null;
  1958. isPair = isExplicitPair = false;
  1959. if (ch === 0x3F
  1960. /* ? */
  1961. ) {
  1962. following = state.input.charCodeAt(state.position + 1);
  1963. if (is_WS_OR_EOL(following)) {
  1964. isPair = isExplicitPair = true;
  1965. state.position++;
  1966. skipSeparationSpace(state, true, nodeIndent);
  1967. }
  1968. }
  1969. _line = state.line;
  1970. composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
  1971. keyTag = state.tag;
  1972. keyNode = state.result;
  1973. skipSeparationSpace(state, true, nodeIndent);
  1974. ch = state.input.charCodeAt(state.position);
  1975. if ((isExplicitPair || state.line === _line) && ch === 0x3A
  1976. /* : */
  1977. ) {
  1978. isPair = true;
  1979. ch = state.input.charCodeAt(++state.position);
  1980. skipSeparationSpace(state, true, nodeIndent);
  1981. composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
  1982. valueNode = state.result;
  1983. }
  1984. if (isMapping) {
  1985. storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode);
  1986. } else if (isPair) {
  1987. _result.push(storeMappingPair(state, null, overridableKeys, keyTag, keyNode, valueNode));
  1988. } else {
  1989. _result.push(keyNode);
  1990. }
  1991. skipSeparationSpace(state, true, nodeIndent);
  1992. ch = state.input.charCodeAt(state.position);
  1993. if (ch === 0x2C
  1994. /* , */
  1995. ) {
  1996. readNext = true;
  1997. ch = state.input.charCodeAt(++state.position);
  1998. } else {
  1999. readNext = false;
  2000. }
  2001. }
  2002. throwError(state, 'unexpected end of the stream within a flow collection');
  2003. }
  2004. function readBlockScalar(state, nodeIndent) {
  2005. var captureStart,
  2006. folding,
  2007. chomping = CHOMPING_CLIP,
  2008. didReadContent = false,
  2009. detectedIndent = false,
  2010. textIndent = nodeIndent,
  2011. emptyLines = 0,
  2012. atMoreIndented = false,
  2013. tmp,
  2014. ch;
  2015. ch = state.input.charCodeAt(state.position);
  2016. if (ch === 0x7C
  2017. /* | */
  2018. ) {
  2019. folding = false;
  2020. } else if (ch === 0x3E
  2021. /* > */
  2022. ) {
  2023. folding = true;
  2024. } else {
  2025. return false;
  2026. }
  2027. state.kind = 'scalar';
  2028. state.result = '';
  2029. while (ch !== 0) {
  2030. ch = state.input.charCodeAt(++state.position);
  2031. if (ch === 0x2B
  2032. /* + */
  2033. || ch === 0x2D
  2034. /* - */
  2035. ) {
  2036. if (CHOMPING_CLIP === chomping) {
  2037. chomping = ch === 0x2B
  2038. /* + */
  2039. ? CHOMPING_KEEP : CHOMPING_STRIP;
  2040. } else {
  2041. throwError(state, 'repeat of a chomping mode identifier');
  2042. }
  2043. } else if ((tmp = fromDecimalCode(ch)) >= 0) {
  2044. if (tmp === 0) {
  2045. throwError(state, 'bad explicit indentation width of a block scalar; it cannot be less than one');
  2046. } else if (!detectedIndent) {
  2047. textIndent = nodeIndent + tmp - 1;
  2048. detectedIndent = true;
  2049. } else {
  2050. throwError(state, 'repeat of an indentation width identifier');
  2051. }
  2052. } else {
  2053. break;
  2054. }
  2055. }
  2056. if (is_WHITE_SPACE(ch)) {
  2057. do {
  2058. ch = state.input.charCodeAt(++state.position);
  2059. } while (is_WHITE_SPACE(ch));
  2060. if (ch === 0x23
  2061. /* # */
  2062. ) {
  2063. do {
  2064. ch = state.input.charCodeAt(++state.position);
  2065. } while (!is_EOL(ch) && ch !== 0);
  2066. }
  2067. }
  2068. while (ch !== 0) {
  2069. readLineBreak(state);
  2070. state.lineIndent = 0;
  2071. ch = state.input.charCodeAt(state.position);
  2072. while ((!detectedIndent || state.lineIndent < textIndent) && ch === 0x20
  2073. /* Space */
  2074. ) {
  2075. state.lineIndent++;
  2076. ch = state.input.charCodeAt(++state.position);
  2077. }
  2078. if (!detectedIndent && state.lineIndent > textIndent) {
  2079. textIndent = state.lineIndent;
  2080. }
  2081. if (is_EOL(ch)) {
  2082. emptyLines++;
  2083. continue;
  2084. } // End of the scalar.
  2085. if (state.lineIndent < textIndent) {
  2086. // Perform the chomping.
  2087. if (chomping === CHOMPING_KEEP) {
  2088. state.result += common.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines);
  2089. } else if (chomping === CHOMPING_CLIP) {
  2090. if (didReadContent) {
  2091. // i.e. only if the scalar is not empty.
  2092. state.result += '\n';
  2093. }
  2094. } // Break this `while` cycle and go to the funciton's epilogue.
  2095. break;
  2096. } // Folded style: use fancy rules to handle line breaks.
  2097. if (folding) {
  2098. // Lines starting with white space characters (more-indented lines) are not folded.
  2099. if (is_WHITE_SPACE(ch)) {
  2100. atMoreIndented = true; // except for the first content line (cf. Example 8.1)
  2101. state.result += common.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines); // End of more-indented block.
  2102. } else if (atMoreIndented) {
  2103. atMoreIndented = false;
  2104. state.result += common.repeat('\n', emptyLines + 1); // Just one line break - perceive as the same line.
  2105. } else if (emptyLines === 0) {
  2106. if (didReadContent) {
  2107. // i.e. only if we have already read some scalar content.
  2108. state.result += ' ';
  2109. } // Several line breaks - perceive as different lines.
  2110. } else {
  2111. state.result += common.repeat('\n', emptyLines);
  2112. } // Literal style: just add exact number of line breaks between content lines.
  2113. } else {
  2114. // Keep all line breaks except the header line break.
  2115. state.result += common.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines);
  2116. }
  2117. didReadContent = true;
  2118. detectedIndent = true;
  2119. emptyLines = 0;
  2120. captureStart = state.position;
  2121. while (!is_EOL(ch) && ch !== 0) {
  2122. ch = state.input.charCodeAt(++state.position);
  2123. }
  2124. captureSegment(state, captureStart, state.position, false);
  2125. }
  2126. return true;
  2127. }
  2128. function readBlockSequence(state, nodeIndent) {
  2129. var _line,
  2130. _tag = state.tag,
  2131. _anchor = state.anchor,
  2132. _result = [],
  2133. following,
  2134. detected = false,
  2135. ch;
  2136. if (state.anchor !== null) {
  2137. state.anchorMap[state.anchor] = _result;
  2138. }
  2139. ch = state.input.charCodeAt(state.position);
  2140. while (ch !== 0) {
  2141. if (ch !== 0x2D
  2142. /* - */
  2143. ) {
  2144. break;
  2145. }
  2146. following = state.input.charCodeAt(state.position + 1);
  2147. if (!is_WS_OR_EOL(following)) {
  2148. break;
  2149. }
  2150. detected = true;
  2151. state.position++;
  2152. if (skipSeparationSpace(state, true, -1)) {
  2153. if (state.lineIndent <= nodeIndent) {
  2154. _result.push(null);
  2155. ch = state.input.charCodeAt(state.position);
  2156. continue;
  2157. }
  2158. }
  2159. _line = state.line;
  2160. composeNode(state, nodeIndent, CONTEXT_BLOCK_IN, false, true);
  2161. _result.push(state.result);
  2162. skipSeparationSpace(state, true, -1);
  2163. ch = state.input.charCodeAt(state.position);
  2164. if ((state.line === _line || state.lineIndent > nodeIndent) && ch !== 0) {
  2165. throwError(state, 'bad indentation of a sequence entry');
  2166. } else if (state.lineIndent < nodeIndent) {
  2167. break;
  2168. }
  2169. }
  2170. if (detected) {
  2171. state.tag = _tag;
  2172. state.anchor = _anchor;
  2173. state.kind = 'sequence';
  2174. state.result = _result;
  2175. return true;
  2176. }
  2177. return false;
  2178. }
  2179. function readBlockMapping(state, nodeIndent, flowIndent) {
  2180. var following,
  2181. allowCompact,
  2182. _line,
  2183. _pos,
  2184. _tag = state.tag,
  2185. _anchor = state.anchor,
  2186. _result = {},
  2187. overridableKeys = {},
  2188. keyTag = null,
  2189. keyNode = null,
  2190. valueNode = null,
  2191. atExplicitKey = false,
  2192. detected = false,
  2193. ch;
  2194. if (state.anchor !== null) {
  2195. state.anchorMap[state.anchor] = _result;
  2196. }
  2197. ch = state.input.charCodeAt(state.position);
  2198. while (ch !== 0) {
  2199. following = state.input.charCodeAt(state.position + 1);
  2200. _line = state.line; // Save the current line.
  2201. _pos = state.position; //
  2202. // Explicit notation case. There are two separate blocks:
  2203. // first for the key (denoted by "?") and second for the value (denoted by ":")
  2204. //
  2205. if ((ch === 0x3F
  2206. /* ? */
  2207. || ch === 0x3A
  2208. /* : */
  2209. ) && is_WS_OR_EOL(following)) {
  2210. if (ch === 0x3F
  2211. /* ? */
  2212. ) {
  2213. if (atExplicitKey) {
  2214. storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null);
  2215. keyTag = keyNode = valueNode = null;
  2216. }
  2217. detected = true;
  2218. atExplicitKey = true;
  2219. allowCompact = true;
  2220. } else if (atExplicitKey) {
  2221. // i.e. 0x3A/* : */ === character after the explicit key.
  2222. atExplicitKey = false;
  2223. allowCompact = true;
  2224. } else {
  2225. throwError(state, 'incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line');
  2226. }
  2227. state.position += 1;
  2228. ch = following; //
  2229. // Implicit notation case. Flow-style node as the key first, then ":", and the value.
  2230. //
  2231. } else if (composeNode(state, flowIndent, CONTEXT_FLOW_OUT, false, true)) {
  2232. if (state.line === _line) {
  2233. ch = state.input.charCodeAt(state.position);
  2234. while (is_WHITE_SPACE(ch)) {
  2235. ch = state.input.charCodeAt(++state.position);
  2236. }
  2237. if (ch === 0x3A
  2238. /* : */
  2239. ) {
  2240. ch = state.input.charCodeAt(++state.position);
  2241. if (!is_WS_OR_EOL(ch)) {
  2242. throwError(state, 'a whitespace character is expected after the key-value separator within a block mapping');
  2243. }
  2244. if (atExplicitKey) {
  2245. storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null);
  2246. keyTag = keyNode = valueNode = null;
  2247. }
  2248. detected = true;
  2249. atExplicitKey = false;
  2250. allowCompact = false;
  2251. keyTag = state.tag;
  2252. keyNode = state.result;
  2253. } else if (detected) {
  2254. throwError(state, 'can not read an implicit mapping pair; a colon is missed');
  2255. } else {
  2256. state.tag = _tag;
  2257. state.anchor = _anchor;
  2258. return true; // Keep the result of `composeNode`.
  2259. }
  2260. } else if (detected) {
  2261. throwError(state, 'can not read a block mapping entry; a multiline key may not be an implicit key');
  2262. } else {
  2263. state.tag = _tag;
  2264. state.anchor = _anchor;
  2265. return true; // Keep the result of `composeNode`.
  2266. }
  2267. } else {
  2268. break; // Reading is done. Go to the epilogue.
  2269. } //
  2270. // Common reading code for both explicit and implicit notations.
  2271. //
  2272. if (state.line === _line || state.lineIndent > nodeIndent) {
  2273. if (composeNode(state, nodeIndent, CONTEXT_BLOCK_OUT, true, allowCompact)) {
  2274. if (atExplicitKey) {
  2275. keyNode = state.result;
  2276. } else {
  2277. valueNode = state.result;
  2278. }
  2279. }
  2280. if (!atExplicitKey) {
  2281. storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, _line, _pos);
  2282. keyTag = keyNode = valueNode = null;
  2283. }
  2284. skipSeparationSpace(state, true, -1);
  2285. ch = state.input.charCodeAt(state.position);
  2286. }
  2287. if (state.lineIndent > nodeIndent && ch !== 0) {
  2288. throwError(state, 'bad indentation of a mapping entry');
  2289. } else if (state.lineIndent < nodeIndent) {
  2290. break;
  2291. }
  2292. } //
  2293. // Epilogue.
  2294. //
  2295. // Special case: last mapping's node contains only the key in explicit notation.
  2296. if (atExplicitKey) {
  2297. storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null);
  2298. } // Expose the resulting mapping.
  2299. if (detected) {
  2300. state.tag = _tag;
  2301. state.anchor = _anchor;
  2302. state.kind = 'mapping';
  2303. state.result = _result;
  2304. }
  2305. return detected;
  2306. }
  2307. function readTagProperty(state) {
  2308. var _position,
  2309. isVerbatim = false,
  2310. isNamed = false,
  2311. tagHandle,
  2312. tagName,
  2313. ch;
  2314. ch = state.input.charCodeAt(state.position);
  2315. if (ch !== 0x21
  2316. /* ! */
  2317. ) return false;
  2318. if (state.tag !== null) {
  2319. throwError(state, 'duplication of a tag property');
  2320. }
  2321. ch = state.input.charCodeAt(++state.position);
  2322. if (ch === 0x3C
  2323. /* < */
  2324. ) {
  2325. isVerbatim = true;
  2326. ch = state.input.charCodeAt(++state.position);
  2327. } else if (ch === 0x21
  2328. /* ! */
  2329. ) {
  2330. isNamed = true;
  2331. tagHandle = '!!';
  2332. ch = state.input.charCodeAt(++state.position);
  2333. } else {
  2334. tagHandle = '!';
  2335. }
  2336. _position = state.position;
  2337. if (isVerbatim) {
  2338. do {
  2339. ch = state.input.charCodeAt(++state.position);
  2340. } while (ch !== 0 && ch !== 0x3E
  2341. /* > */
  2342. );
  2343. if (state.position < state.length) {
  2344. tagName = state.input.slice(_position, state.position);
  2345. ch = state.input.charCodeAt(++state.position);
  2346. } else {
  2347. throwError(state, 'unexpected end of the stream within a verbatim tag');
  2348. }
  2349. } else {
  2350. while (ch !== 0 && !is_WS_OR_EOL(ch)) {
  2351. if (ch === 0x21
  2352. /* ! */
  2353. ) {
  2354. if (!isNamed) {
  2355. tagHandle = state.input.slice(_position - 1, state.position + 1);
  2356. if (!PATTERN_TAG_HANDLE.test(tagHandle)) {
  2357. throwError(state, 'named tag handle cannot contain such characters');
  2358. }
  2359. isNamed = true;
  2360. _position = state.position + 1;
  2361. } else {
  2362. throwError(state, 'tag suffix cannot contain exclamation marks');
  2363. }
  2364. }
  2365. ch = state.input.charCodeAt(++state.position);
  2366. }
  2367. tagName = state.input.slice(_position, state.position);
  2368. if (PATTERN_FLOW_INDICATORS.test(tagName)) {
  2369. throwError(state, 'tag suffix cannot contain flow indicator characters');
  2370. }
  2371. }
  2372. if (tagName && !PATTERN_TAG_URI.test(tagName)) {
  2373. throwError(state, 'tag name cannot contain such characters: ' + tagName);
  2374. }
  2375. if (isVerbatim) {
  2376. state.tag = tagName;
  2377. } else if (_hasOwnProperty.call(state.tagMap, tagHandle)) {
  2378. state.tag = state.tagMap[tagHandle] + tagName;
  2379. } else if (tagHandle === '!') {
  2380. state.tag = '!' + tagName;
  2381. } else if (tagHandle === '!!') {
  2382. state.tag = 'tag:yaml.org,2002:' + tagName;
  2383. } else {
  2384. throwError(state, 'undeclared tag handle "' + tagHandle + '"');
  2385. }
  2386. return true;
  2387. }
  2388. function readAnchorProperty(state) {
  2389. var _position, ch;
  2390. ch = state.input.charCodeAt(state.position);
  2391. if (ch !== 0x26
  2392. /* & */
  2393. ) return false;
  2394. if (state.anchor !== null) {
  2395. throwError(state, 'duplication of an anchor property');
  2396. }
  2397. ch = state.input.charCodeAt(++state.position);
  2398. _position = state.position;
  2399. while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
  2400. ch = state.input.charCodeAt(++state.position);
  2401. }
  2402. if (state.position === _position) {
  2403. throwError(state, 'name of an anchor node must contain at least one character');
  2404. }
  2405. state.anchor = state.input.slice(_position, state.position);
  2406. return true;
  2407. }
  2408. function readAlias(state) {
  2409. var _position, alias, ch;
  2410. ch = state.input.charCodeAt(state.position);
  2411. if (ch !== 0x2A
  2412. /* * */
  2413. ) return false;
  2414. ch = state.input.charCodeAt(++state.position);
  2415. _position = state.position;
  2416. while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
  2417. ch = state.input.charCodeAt(++state.position);
  2418. }
  2419. if (state.position === _position) {
  2420. throwError(state, 'name of an alias node must contain at least one character');
  2421. }
  2422. alias = state.input.slice(_position, state.position);
  2423. if (!state.anchorMap.hasOwnProperty(alias)) {
  2424. throwError(state, 'unidentified alias "' + alias + '"');
  2425. }
  2426. state.result = state.anchorMap[alias];
  2427. skipSeparationSpace(state, true, -1);
  2428. return true;
  2429. }
  2430. function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact) {
  2431. var allowBlockStyles,
  2432. allowBlockScalars,
  2433. allowBlockCollections,
  2434. indentStatus = 1,
  2435. // 1: this>parent, 0: this=parent, -1: this<parent
  2436. atNewLine = false,
  2437. hasContent = false,
  2438. typeIndex,
  2439. typeQuantity,
  2440. type,
  2441. flowIndent,
  2442. blockIndent;
  2443. if (state.listener !== null) {
  2444. state.listener('open', state);
  2445. }
  2446. state.tag = null;
  2447. state.anchor = null;
  2448. state.kind = null;
  2449. state.result = null;
  2450. allowBlockStyles = allowBlockScalars = allowBlockCollections = CONTEXT_BLOCK_OUT === nodeContext || CONTEXT_BLOCK_IN === nodeContext;
  2451. if (allowToSeek) {
  2452. if (skipSeparationSpace(state, true, -1)) {
  2453. atNewLine = true;
  2454. if (state.lineIndent > parentIndent) {
  2455. indentStatus = 1;
  2456. } else if (state.lineIndent === parentIndent) {
  2457. indentStatus = 0;
  2458. } else if (state.lineIndent < parentIndent) {
  2459. indentStatus = -1;
  2460. }
  2461. }
  2462. }
  2463. if (indentStatus === 1) {
  2464. while (readTagProperty(state) || readAnchorProperty(state)) {
  2465. if (skipSeparationSpace(state, true, -1)) {
  2466. atNewLine = true;
  2467. allowBlockCollections = allowBlockStyles;
  2468. if (state.lineIndent > parentIndent) {
  2469. indentStatus = 1;
  2470. } else if (state.lineIndent === parentIndent) {
  2471. indentStatus = 0;
  2472. } else if (state.lineIndent < parentIndent) {
  2473. indentStatus = -1;
  2474. }
  2475. } else {
  2476. allowBlockCollections = false;
  2477. }
  2478. }
  2479. }
  2480. if (allowBlockCollections) {
  2481. allowBlockCollections = atNewLine || allowCompact;
  2482. }
  2483. if (indentStatus === 1 || CONTEXT_BLOCK_OUT === nodeContext) {
  2484. if (CONTEXT_FLOW_IN === nodeContext || CONTEXT_FLOW_OUT === nodeContext) {
  2485. flowIndent = parentIndent;
  2486. } else {
  2487. flowIndent = parentIndent + 1;
  2488. }
  2489. blockIndent = state.position - state.lineStart;
  2490. if (indentStatus === 1) {
  2491. if (allowBlockCollections && (readBlockSequence(state, blockIndent) || readBlockMapping(state, blockIndent, flowIndent)) || readFlowCollection(state, flowIndent)) {
  2492. hasContent = true;
  2493. } else {
  2494. if (allowBlockScalars && readBlockScalar(state, flowIndent) || readSingleQuotedScalar(state, flowIndent) || readDoubleQuotedScalar(state, flowIndent)) {
  2495. hasContent = true;
  2496. } else if (readAlias(state)) {
  2497. hasContent = true;
  2498. if (state.tag !== null || state.anchor !== null) {
  2499. throwError(state, 'alias node should not have any properties');
  2500. }
  2501. } else if (readPlainScalar(state, flowIndent, CONTEXT_FLOW_IN === nodeContext)) {
  2502. hasContent = true;
  2503. if (state.tag === null) {
  2504. state.tag = '?';
  2505. }
  2506. }
  2507. if (state.anchor !== null) {
  2508. state.anchorMap[state.anchor] = state.result;
  2509. }
  2510. }
  2511. } else if (indentStatus === 0) {
  2512. // Special case: block sequences are allowed to have same indentation level as the parent.
  2513. // http://www.yaml.org/spec/1.2/spec.html#id2799784
  2514. hasContent = allowBlockCollections && readBlockSequence(state, blockIndent);
  2515. }
  2516. }
  2517. if (state.tag !== null && state.tag !== '!') {
  2518. if (state.tag === '?') {
  2519. for (typeIndex = 0, typeQuantity = state.implicitTypes.length; typeIndex < typeQuantity; typeIndex += 1) {
  2520. type = state.implicitTypes[typeIndex]; // Implicit resolving is not allowed for non-scalar types, and '?'
  2521. // non-specific tag is only assigned to plain scalars. So, it isn't
  2522. // needed to check for 'kind' conformity.
  2523. if (type.resolve(state.result)) {
  2524. // `state.result` updated in resolver if matched
  2525. state.result = type.construct(state.result);
  2526. state.tag = type.tag;
  2527. if (state.anchor !== null) {
  2528. state.anchorMap[state.anchor] = state.result;
  2529. }
  2530. break;
  2531. }
  2532. }
  2533. } else if (_hasOwnProperty.call(state.typeMap[state.kind || 'fallback'], state.tag)) {
  2534. type = state.typeMap[state.kind || 'fallback'][state.tag];
  2535. if (state.result !== null && type.kind !== state.kind) {
  2536. throwError(state, 'unacceptable node kind for !<' + state.tag + '> tag; it should be "' + type.kind + '", not "' + state.kind + '"');
  2537. }
  2538. if (!type.resolve(state.result)) {
  2539. // `state.result` updated in resolver if matched
  2540. throwError(state, 'cannot resolve a node with !<' + state.tag + '> explicit tag');
  2541. } else {
  2542. state.result = type.construct(state.result);
  2543. if (state.anchor !== null) {
  2544. state.anchorMap[state.anchor] = state.result;
  2545. }
  2546. }
  2547. } else {
  2548. throwError(state, 'unknown tag !<' + state.tag + '>');
  2549. }
  2550. }
  2551. if (state.listener !== null) {
  2552. state.listener('close', state);
  2553. }
  2554. return state.tag !== null || state.anchor !== null || hasContent;
  2555. }
  2556. function readDocument(state) {
  2557. var documentStart = state.position,
  2558. _position,
  2559. directiveName,
  2560. directiveArgs,
  2561. hasDirectives = false,
  2562. ch;
  2563. state.version = null;
  2564. state.checkLineBreaks = state.legacy;
  2565. state.tagMap = {};
  2566. state.anchorMap = {};
  2567. while ((ch = state.input.charCodeAt(state.position)) !== 0) {
  2568. skipSeparationSpace(state, true, -1);
  2569. ch = state.input.charCodeAt(state.position);
  2570. if (state.lineIndent > 0 || ch !== 0x25
  2571. /* % */
  2572. ) {
  2573. break;
  2574. }
  2575. hasDirectives = true;
  2576. ch = state.input.charCodeAt(++state.position);
  2577. _position = state.position;
  2578. while (ch !== 0 && !is_WS_OR_EOL(ch)) {
  2579. ch = state.input.charCodeAt(++state.position);
  2580. }
  2581. directiveName = state.input.slice(_position, state.position);
  2582. directiveArgs = [];
  2583. if (directiveName.length < 1) {
  2584. throwError(state, 'directive name must not be less than one character in length');
  2585. }
  2586. while (ch !== 0) {
  2587. while (is_WHITE_SPACE(ch)) {
  2588. ch = state.input.charCodeAt(++state.position);
  2589. }
  2590. if (ch === 0x23
  2591. /* # */
  2592. ) {
  2593. do {
  2594. ch = state.input.charCodeAt(++state.position);
  2595. } while (ch !== 0 && !is_EOL(ch));
  2596. break;
  2597. }
  2598. if (is_EOL(ch)) break;
  2599. _position = state.position;
  2600. while (ch !== 0 && !is_WS_OR_EOL(ch)) {
  2601. ch = state.input.charCodeAt(++state.position);
  2602. }
  2603. directiveArgs.push(state.input.slice(_position, state.position));
  2604. }
  2605. if (ch !== 0) readLineBreak(state);
  2606. if (_hasOwnProperty.call(directiveHandlers, directiveName)) {
  2607. directiveHandlers[directiveName](state, directiveName, directiveArgs);
  2608. } else {
  2609. throwWarning(state, 'unknown document directive "' + directiveName + '"');
  2610. }
  2611. }
  2612. skipSeparationSpace(state, true, -1);
  2613. if (state.lineIndent === 0 && state.input.charCodeAt(state.position) === 0x2D
  2614. /* - */
  2615. && state.input.charCodeAt(state.position + 1) === 0x2D
  2616. /* - */
  2617. && state.input.charCodeAt(state.position + 2) === 0x2D
  2618. /* - */
  2619. ) {
  2620. state.position += 3;
  2621. skipSeparationSpace(state, true, -1);
  2622. } else if (hasDirectives) {
  2623. throwError(state, 'directives end mark is expected');
  2624. }
  2625. composeNode(state, state.lineIndent - 1, CONTEXT_BLOCK_OUT, false, true);
  2626. skipSeparationSpace(state, true, -1);
  2627. if (state.checkLineBreaks && PATTERN_NON_ASCII_LINE_BREAKS.test(state.input.slice(documentStart, state.position))) {
  2628. throwWarning(state, 'non-ASCII line breaks are interpreted as content');
  2629. }
  2630. state.documents.push(state.result);
  2631. if (state.position === state.lineStart && testDocumentSeparator(state)) {
  2632. if (state.input.charCodeAt(state.position) === 0x2E
  2633. /* . */
  2634. ) {
  2635. state.position += 3;
  2636. skipSeparationSpace(state, true, -1);
  2637. }
  2638. return;
  2639. }
  2640. if (state.position < state.length - 1) {
  2641. throwError(state, 'end of the stream or a document separator is expected');
  2642. } else {
  2643. return;
  2644. }
  2645. }
  2646. function loadDocuments(input, options) {
  2647. input = String(input);
  2648. options = options || {};
  2649. if (input.length !== 0) {
  2650. // Add tailing `\n` if not exists
  2651. if (input.charCodeAt(input.length - 1) !== 0x0A
  2652. /* LF */
  2653. && input.charCodeAt(input.length - 1) !== 0x0D
  2654. /* CR */
  2655. ) {
  2656. input += '\n';
  2657. } // Strip BOM
  2658. if (input.charCodeAt(0) === 0xFEFF) {
  2659. input = input.slice(1);
  2660. }
  2661. }
  2662. var state = new State(input, options); // Use 0 as string terminator. That significantly simplifies bounds check.
  2663. state.input += '\0';
  2664. while (state.input.charCodeAt(state.position) === 0x20
  2665. /* Space */
  2666. ) {
  2667. state.lineIndent += 1;
  2668. state.position += 1;
  2669. }
  2670. while (state.position < state.length - 1) {
  2671. readDocument(state);
  2672. }
  2673. return state.documents;
  2674. }
  2675. function loadAll$1(input, iterator, options) {
  2676. var documents = loadDocuments(input, options),
  2677. index,
  2678. length;
  2679. if (typeof iterator !== 'function') {
  2680. return documents;
  2681. }
  2682. for (index = 0, length = documents.length; index < length; index += 1) {
  2683. iterator(documents[index]);
  2684. }
  2685. }
  2686. function load$1(input, options) {
  2687. var documents = loadDocuments(input, options);
  2688. if (documents.length === 0) {
  2689. /*eslint-disable no-undefined*/
  2690. return undefined;
  2691. } else if (documents.length === 1) {
  2692. return documents[0];
  2693. }
  2694. throw new exception('expected a single document in the stream, but found more');
  2695. }
  2696. function safeLoadAll$1(input, output, options) {
  2697. if (typeof output === 'function') {
  2698. loadAll$1(input, output, common.extend({
  2699. schema: default_safe
  2700. }, options));
  2701. } else {
  2702. return loadAll$1(input, common.extend({
  2703. schema: default_safe
  2704. }, options));
  2705. }
  2706. }
  2707. function safeLoad$1(input, options) {
  2708. return load$1(input, common.extend({
  2709. schema: default_safe
  2710. }, options));
  2711. }
  2712. var loadAll_1 = loadAll$1;
  2713. var load_1 = load$1;
  2714. var safeLoadAll_1 = safeLoadAll$1;
  2715. var safeLoad_1 = safeLoad$1;
  2716. var loader = {
  2717. loadAll: loadAll_1,
  2718. load: load_1,
  2719. safeLoadAll: safeLoadAll_1,
  2720. safeLoad: safeLoad_1
  2721. };
  2722. /*eslint-disable no-use-before-define*/
  2723. var _toString$2 = Object.prototype.toString;
  2724. var _hasOwnProperty$3 = Object.prototype.hasOwnProperty;
  2725. var CHAR_TAB = 0x09;
  2726. /* Tab */
  2727. var CHAR_LINE_FEED = 0x0A;
  2728. /* LF */
  2729. var CHAR_SPACE = 0x20;
  2730. /* Space */
  2731. var CHAR_EXCLAMATION = 0x21;
  2732. /* ! */
  2733. var CHAR_DOUBLE_QUOTE = 0x22;
  2734. /* " */
  2735. var CHAR_SHARP = 0x23;
  2736. /* # */
  2737. var CHAR_PERCENT = 0x25;
  2738. /* % */
  2739. var CHAR_AMPERSAND = 0x26;
  2740. /* & */
  2741. var CHAR_SINGLE_QUOTE = 0x27;
  2742. /* ' */
  2743. var CHAR_ASTERISK = 0x2A;
  2744. /* * */
  2745. var CHAR_COMMA = 0x2C;
  2746. /* , */
  2747. var CHAR_MINUS = 0x2D;
  2748. /* - */
  2749. var CHAR_COLON = 0x3A;
  2750. /* : */
  2751. var CHAR_GREATER_THAN = 0x3E;
  2752. /* > */
  2753. var CHAR_QUESTION = 0x3F;
  2754. /* ? */
  2755. var CHAR_COMMERCIAL_AT = 0x40;
  2756. /* @ */
  2757. var CHAR_LEFT_SQUARE_BRACKET = 0x5B;
  2758. /* [ */
  2759. var CHAR_RIGHT_SQUARE_BRACKET = 0x5D;
  2760. /* ] */
  2761. var CHAR_GRAVE_ACCENT = 0x60;
  2762. /* ` */
  2763. var CHAR_LEFT_CURLY_BRACKET = 0x7B;
  2764. /* { */
  2765. var CHAR_VERTICAL_LINE = 0x7C;
  2766. /* | */
  2767. var CHAR_RIGHT_CURLY_BRACKET = 0x7D;
  2768. /* } */
  2769. var ESCAPE_SEQUENCES = {};
  2770. ESCAPE_SEQUENCES[0x00] = '\\0';
  2771. ESCAPE_SEQUENCES[0x07] = '\\a';
  2772. ESCAPE_SEQUENCES[0x08] = '\\b';
  2773. ESCAPE_SEQUENCES[0x09] = '\\t';
  2774. ESCAPE_SEQUENCES[0x0A] = '\\n';
  2775. ESCAPE_SEQUENCES[0x0B] = '\\v';
  2776. ESCAPE_SEQUENCES[0x0C] = '\\f';
  2777. ESCAPE_SEQUENCES[0x0D] = '\\r';
  2778. ESCAPE_SEQUENCES[0x1B] = '\\e';
  2779. ESCAPE_SEQUENCES[0x22] = '\\"';
  2780. ESCAPE_SEQUENCES[0x5C] = '\\\\';
  2781. ESCAPE_SEQUENCES[0x85] = '\\N';
  2782. ESCAPE_SEQUENCES[0xA0] = '\\_';
  2783. ESCAPE_SEQUENCES[0x2028] = '\\L';
  2784. ESCAPE_SEQUENCES[0x2029] = '\\P';
  2785. var DEPRECATED_BOOLEANS_SYNTAX = ['y', 'Y', 'yes', 'Yes', 'YES', 'on', 'On', 'ON', 'n', 'N', 'no', 'No', 'NO', 'off', 'Off', 'OFF'];
  2786. function compileStyleMap(schema, map) {
  2787. var result, keys, index, length, tag, style, type;
  2788. if (map === null) return {};
  2789. result = {};
  2790. keys = Object.keys(map);
  2791. for (index = 0, length = keys.length; index < length; index += 1) {
  2792. tag = keys[index];
  2793. style = String(map[tag]);
  2794. if (tag.slice(0, 2) === '!!') {
  2795. tag = 'tag:yaml.org,2002:' + tag.slice(2);
  2796. }
  2797. type = schema.compiledTypeMap['fallback'][tag];
  2798. if (type && _hasOwnProperty$3.call(type.styleAliases, style)) {
  2799. style = type.styleAliases[style];
  2800. }
  2801. result[tag] = style;
  2802. }
  2803. return result;
  2804. }
  2805. function encodeHex(character) {
  2806. var string, handle, length;
  2807. string = character.toString(16).toUpperCase();
  2808. if (character <= 0xFF) {
  2809. handle = 'x';
  2810. length = 2;
  2811. } else if (character <= 0xFFFF) {
  2812. handle = 'u';
  2813. length = 4;
  2814. } else if (character <= 0xFFFFFFFF) {
  2815. handle = 'U';
  2816. length = 8;
  2817. } else {
  2818. throw new exception('code point within a string may not be greater than 0xFFFFFFFF');
  2819. }
  2820. return '\\' + handle + common.repeat('0', length - string.length) + string;
  2821. }
  2822. function State$1(options) {
  2823. this.schema = options['schema'] || default_full;
  2824. this.indent = Math.max(1, options['indent'] || 2);
  2825. this.skipInvalid = options['skipInvalid'] || false;
  2826. this.flowLevel = common.isNothing(options['flowLevel']) ? -1 : options['flowLevel'];
  2827. this.styleMap = compileStyleMap(this.schema, options['styles'] || null);
  2828. this.sortKeys = options['sortKeys'] || false;
  2829. this.lineWidth = options['lineWidth'] || 80;
  2830. this.noRefs = options['noRefs'] || false;
  2831. this.noCompatMode = options['noCompatMode'] || false;
  2832. this.condenseFlow = options['condenseFlow'] || false;
  2833. this.implicitTypes = this.schema.compiledImplicit;
  2834. this.explicitTypes = this.schema.compiledExplicit;
  2835. this.tag = null;
  2836. this.result = '';
  2837. this.duplicates = [];
  2838. this.usedDuplicates = null;
  2839. } // Indents every line in a string. Empty lines (\n only) are not indented.
  2840. function indentString(string, spaces) {
  2841. var ind = common.repeat(' ', spaces),
  2842. position = 0,
  2843. next = -1,
  2844. result = '',
  2845. line,
  2846. length = string.length;
  2847. while (position < length) {
  2848. next = string.indexOf('\n', position);
  2849. if (next === -1) {
  2850. line = string.slice(position);
  2851. position = length;
  2852. } else {
  2853. line = string.slice(position, next + 1);
  2854. position = next + 1;
  2855. }
  2856. if (line.length && line !== '\n') result += ind;
  2857. result += line;
  2858. }
  2859. return result;
  2860. }
  2861. function generateNextLine(state, level) {
  2862. return '\n' + common.repeat(' ', state.indent * level);
  2863. }
  2864. function testImplicitResolving(state, str) {
  2865. var index, length, type;
  2866. for (index = 0, length = state.implicitTypes.length; index < length; index += 1) {
  2867. type = state.implicitTypes[index];
  2868. if (type.resolve(str)) {
  2869. return true;
  2870. }
  2871. }
  2872. return false;
  2873. } // [33] s-white ::= s-space | s-tab
  2874. function isWhitespace(c) {
  2875. return c === CHAR_SPACE || c === CHAR_TAB;
  2876. } // Returns true if the character can be printed without escaping.
  2877. // From YAML 1.2: "any allowed characters known to be non-printable
  2878. // should also be escaped. [However,] This isn’t mandatory"
  2879. // Derived from nb-char - \t - #x85 - #xA0 - #x2028 - #x2029.
  2880. function isPrintable(c) {
  2881. return 0x00020 <= c && c <= 0x00007E || 0x000A1 <= c && c <= 0x00D7FF && c !== 0x2028 && c !== 0x2029 || 0x0E000 <= c && c <= 0x00FFFD && c !== 0xFEFF
  2882. /* BOM */
  2883. || 0x10000 <= c && c <= 0x10FFFF;
  2884. } // Simplified test for values allowed after the first character in plain style.
  2885. function isPlainSafe(c) {
  2886. // Uses a subset of nb-char - c-flow-indicator - ":" - "#"
  2887. // where nb-char ::= c-printable - b-char - c-byte-order-mark.
  2888. return isPrintable(c) && c !== 0xFEFF // - c-flow-indicator
  2889. && c !== CHAR_COMMA && c !== CHAR_LEFT_SQUARE_BRACKET && c !== CHAR_RIGHT_SQUARE_BRACKET && c !== CHAR_LEFT_CURLY_BRACKET && c !== CHAR_RIGHT_CURLY_BRACKET // - ":" - "#"
  2890. && c !== CHAR_COLON && c !== CHAR_SHARP;
  2891. } // Simplified test for values allowed as the first character in plain style.
  2892. function isPlainSafeFirst(c) {
  2893. // Uses a subset of ns-char - c-indicator
  2894. // where ns-char = nb-char - s-white.
  2895. return isPrintable(c) && c !== 0xFEFF && !isWhitespace(c) // - s-white
  2896. // - (c-indicator ::=
  2897. // “-” | “?” | “:” | “,” | “[” | “]” | “{” | “}”
  2898. && 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 // | “#” | “&” | “*” | “!” | “|” | “>” | “'” | “"”
  2899. && 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 // | “%” | “@” | “`”)
  2900. && c !== CHAR_PERCENT && c !== CHAR_COMMERCIAL_AT && c !== CHAR_GRAVE_ACCENT;
  2901. } // Determines whether block indentation indicator is required.
  2902. function needIndentIndicator(string) {
  2903. var leadingSpaceRe = /^\n* /;
  2904. return leadingSpaceRe.test(string);
  2905. }
  2906. var STYLE_PLAIN = 1;
  2907. var STYLE_SINGLE = 2;
  2908. var STYLE_LITERAL = 3;
  2909. var STYLE_FOLDED = 4;
  2910. var STYLE_DOUBLE = 5; // Determines which scalar styles are possible and returns the preferred style.
  2911. // lineWidth = -1 => no limit.
  2912. // Pre-conditions: str.length > 0.
  2913. // Post-conditions:
  2914. // STYLE_PLAIN or STYLE_SINGLE => no \n are in the string.
  2915. // STYLE_LITERAL => no lines are suitable for folding (or lineWidth is -1).
  2916. // STYLE_FOLDED => a line > lineWidth and can be folded (and lineWidth != -1).
  2917. function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth, testAmbiguousType) {
  2918. var i;
  2919. var char;
  2920. var hasLineBreak = false;
  2921. var hasFoldableLine = false; // only checked if shouldTrackWidth
  2922. var shouldTrackWidth = lineWidth !== -1;
  2923. var previousLineBreak = -1; // count the first line correctly
  2924. var plain = isPlainSafeFirst(string.charCodeAt(0)) && !isWhitespace(string.charCodeAt(string.length - 1));
  2925. if (singleLineOnly) {
  2926. // Case: no block styles.
  2927. // Check for disallowed characters to rule out plain and single.
  2928. for (i = 0; i < string.length; i++) {
  2929. char = string.charCodeAt(i);
  2930. if (!isPrintable(char)) {
  2931. return STYLE_DOUBLE;
  2932. }
  2933. plain = plain && isPlainSafe(char);
  2934. }
  2935. } else {
  2936. // Case: block styles permitted.
  2937. for (i = 0; i < string.length; i++) {
  2938. char = string.charCodeAt(i);
  2939. if (char === CHAR_LINE_FEED) {
  2940. hasLineBreak = true; // Check if any line can be folded.
  2941. if (shouldTrackWidth) {
  2942. hasFoldableLine = hasFoldableLine || // Foldable line = too long, and not more-indented.
  2943. i - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !== ' ';
  2944. previousLineBreak = i;
  2945. }
  2946. } else if (!isPrintable(char)) {
  2947. return STYLE_DOUBLE;
  2948. }
  2949. plain = plain && isPlainSafe(char);
  2950. } // in case the end is missing a \n
  2951. hasFoldableLine = hasFoldableLine || shouldTrackWidth && i - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !== ' ';
  2952. } // Although every style can represent \n without escaping, prefer block styles
  2953. // for multiline, since they're more readable and they don't add empty lines.
  2954. // Also prefer folding a super-long line.
  2955. if (!hasLineBreak && !hasFoldableLine) {
  2956. // Strings interpretable as another type have to be quoted;
  2957. // e.g. the string 'true' vs. the boolean true.
  2958. return plain && !testAmbiguousType(string) ? STYLE_PLAIN : STYLE_SINGLE;
  2959. } // Edge case: block indentation indicator can only have one digit.
  2960. if (indentPerLevel > 9 && needIndentIndicator(string)) {
  2961. return STYLE_DOUBLE;
  2962. } // At this point we know block styles are valid.
  2963. // Prefer literal style unless we want to fold.
  2964. return hasFoldableLine ? STYLE_FOLDED : STYLE_LITERAL;
  2965. } // Note: line breaking/folding is implemented for only the folded style.
  2966. // NB. We drop the last trailing newline (if any) of a returned block scalar
  2967. // since the dumper adds its own newline. This always works:
  2968. // • No ending newline => unaffected; already using strip "-" chomping.
  2969. // • Ending newline => removed then restored.
  2970. // Importantly, this keeps the "+" chomp indicator from gaining an extra line.
  2971. function writeScalar(state, string, level, iskey) {
  2972. state.dump = function () {
  2973. if (string.length === 0) {
  2974. return "''";
  2975. }
  2976. if (!state.noCompatMode && DEPRECATED_BOOLEANS_SYNTAX.indexOf(string) !== -1) {
  2977. return "'" + string + "'";
  2978. }
  2979. var indent = state.indent * Math.max(1, level); // no 0-indent scalars
  2980. // As indentation gets deeper, let the width decrease monotonically
  2981. // to the lower bound min(state.lineWidth, 40).
  2982. // Note that this implies
  2983. // state.lineWidth ≤ 40 + state.indent: width is fixed at the lower bound.
  2984. // state.lineWidth > 40 + state.indent: width decreases until the lower bound.
  2985. // This behaves better than a constant minimum width which disallows narrower options,
  2986. // or an indent threshold which causes the width to suddenly increase.
  2987. 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.
  2988. var singleLineOnly = iskey // No block styles in flow mode.
  2989. || state.flowLevel > -1 && level >= state.flowLevel;
  2990. function testAmbiguity(string) {
  2991. return testImplicitResolving(state, string);
  2992. }
  2993. switch (chooseScalarStyle(string, singleLineOnly, state.indent, lineWidth, testAmbiguity)) {
  2994. case STYLE_PLAIN:
  2995. return string;
  2996. case STYLE_SINGLE:
  2997. return "'" + string.replace(/'/g, "''") + "'";
  2998. case STYLE_LITERAL:
  2999. return '|' + blockHeader(string, state.indent) + dropEndingNewline(indentString(string, indent));
  3000. case STYLE_FOLDED:
  3001. return '>' + blockHeader(string, state.indent) + dropEndingNewline(indentString(foldString(string, lineWidth), indent));
  3002. case STYLE_DOUBLE:
  3003. return '"' + escapeString(string, lineWidth) + '"';
  3004. default:
  3005. throw new exception('impossible error: invalid scalar style');
  3006. }
  3007. }();
  3008. } // Pre-conditions: string is valid for a block scalar, 1 <= indentPerLevel <= 9.
  3009. function blockHeader(string, indentPerLevel) {
  3010. var indentIndicator = needIndentIndicator(string) ? String(indentPerLevel) : ''; // note the special case: the string '\n' counts as a "trailing" empty line.
  3011. var clip = string[string.length - 1] === '\n';
  3012. var keep = clip && (string[string.length - 2] === '\n' || string === '\n');
  3013. var chomp = keep ? '+' : clip ? '' : '-';
  3014. return indentIndicator + chomp + '\n';
  3015. } // (See the note for writeScalar.)
  3016. function dropEndingNewline(string) {
  3017. return string[string.length - 1] === '\n' ? string.slice(0, -1) : string;
  3018. } // Note: a long line without a suitable break point will exceed the width limit.
  3019. // Pre-conditions: every char in str isPrintable, str.length > 0, width > 0.
  3020. function foldString(string, width) {
  3021. // In folded style, $k$ consecutive newlines output as $k+1$ newlines—
  3022. // unless they're before or after a more-indented line, or at the very
  3023. // beginning or end, in which case $k$ maps to $k$.
  3024. // Therefore, parse each chunk as newline(s) followed by a content line.
  3025. var lineRe = /(\n+)([^\n]*)/g; // first line (possibly an empty line)
  3026. var result = function () {
  3027. var nextLF = string.indexOf('\n');
  3028. nextLF = nextLF !== -1 ? nextLF : string.length;
  3029. lineRe.lastIndex = nextLF;
  3030. return foldLine(string.slice(0, nextLF), width);
  3031. }(); // If we haven't reached the first content line yet, don't add an extra \n.
  3032. var prevMoreIndented = string[0] === '\n' || string[0] === ' ';
  3033. var moreIndented; // rest of the lines
  3034. var match;
  3035. while (match = lineRe.exec(string)) {
  3036. var prefix = match[1],
  3037. line = match[2];
  3038. moreIndented = line[0] === ' ';
  3039. result += prefix + (!prevMoreIndented && !moreIndented && line !== '' ? '\n' : '') + foldLine(line, width);
  3040. prevMoreIndented = moreIndented;
  3041. }
  3042. return result;
  3043. } // Greedy line breaking.
  3044. // Picks the longest line under the limit each time,
  3045. // otherwise settles for the shortest line over the limit.
  3046. // NB. More-indented lines *cannot* be folded, as that would add an extra \n.
  3047. function foldLine(line, width) {
  3048. if (line === '' || line[0] === ' ') return line; // Since a more-indented line adds a \n, breaks can't be followed by a space.
  3049. var breakRe = / [^ ]/g; // note: the match index will always be <= length-2.
  3050. var match; // start is an inclusive index. end, curr, and next are exclusive.
  3051. var start = 0,
  3052. end,
  3053. curr = 0,
  3054. next = 0;
  3055. var result = ''; // Invariants: 0 <= start <= length-1.
  3056. // 0 <= curr <= next <= max(0, length-2). curr - start <= width.
  3057. // Inside the loop:
  3058. // A match implies length >= 2, so curr and next are <= length-2.
  3059. while (match = breakRe.exec(line)) {
  3060. next = match.index; // maintain invariant: curr - start <= width
  3061. if (next - start > width) {
  3062. end = curr > start ? curr : next; // derive end <= length-2
  3063. result += '\n' + line.slice(start, end); // skip the space that was output as \n
  3064. start = end + 1; // derive start <= length-1
  3065. }
  3066. curr = next;
  3067. } // By the invariants, start <= length-1, so there is something left over.
  3068. // It is either the whole string or a part starting from non-whitespace.
  3069. result += '\n'; // Insert a break if the remainder is too long and there is a break available.
  3070. if (line.length - start > width && curr > start) {
  3071. result += line.slice(start, curr) + '\n' + line.slice(curr + 1);
  3072. } else {
  3073. result += line.slice(start);
  3074. }
  3075. return result.slice(1); // drop extra \n joiner
  3076. } // Escapes a double-quoted string.
  3077. function escapeString(string) {
  3078. var result = '';
  3079. var char, nextChar;
  3080. var escapeSeq;
  3081. for (var i = 0; i < string.length; i++) {
  3082. char = string.charCodeAt(i); // Check for surrogate pairs (reference Unicode 3.0 section "3.7 Surrogates").
  3083. if (char >= 0xD800 && char <= 0xDBFF
  3084. /* high surrogate */
  3085. ) {
  3086. nextChar = string.charCodeAt(i + 1);
  3087. if (nextChar >= 0xDC00 && nextChar <= 0xDFFF
  3088. /* low surrogate */
  3089. ) {
  3090. // Combine the surrogate pair and store it escaped.
  3091. result += encodeHex((char - 0xD800) * 0x400 + nextChar - 0xDC00 + 0x10000); // Advance index one extra since we already used that char here.
  3092. i++;
  3093. continue;
  3094. }
  3095. }
  3096. escapeSeq = ESCAPE_SEQUENCES[char];
  3097. result += !escapeSeq && isPrintable(char) ? string[i] : escapeSeq || encodeHex(char);
  3098. }
  3099. return result;
  3100. }
  3101. function writeFlowSequence(state, level, object) {
  3102. var _result = '',
  3103. _tag = state.tag,
  3104. index,
  3105. length;
  3106. for (index = 0, length = object.length; index < length; index += 1) {
  3107. // Write only valid elements.
  3108. if (writeNode(state, level, object[index], false, false)) {
  3109. if (index !== 0) _result += ',' + (!state.condenseFlow ? ' ' : '');
  3110. _result += state.dump;
  3111. }
  3112. }
  3113. state.tag = _tag;
  3114. state.dump = '[' + _result + ']';
  3115. }
  3116. function writeBlockSequence(state, level, object, compact) {
  3117. var _result = '',
  3118. _tag = state.tag,
  3119. index,
  3120. length;
  3121. for (index = 0, length = object.length; index < length; index += 1) {
  3122. // Write only valid elements.
  3123. if (writeNode(state, level + 1, object[index], true, true)) {
  3124. if (!compact || index !== 0) {
  3125. _result += generateNextLine(state, level);
  3126. }
  3127. if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
  3128. _result += '-';
  3129. } else {
  3130. _result += '- ';
  3131. }
  3132. _result += state.dump;
  3133. }
  3134. }
  3135. state.tag = _tag;
  3136. state.dump = _result || '[]'; // Empty sequence if no valid values.
  3137. }
  3138. function writeFlowMapping(state, level, object) {
  3139. var _result = '',
  3140. _tag = state.tag,
  3141. objectKeyList = Object.keys(object),
  3142. index,
  3143. length,
  3144. objectKey,
  3145. objectValue,
  3146. pairBuffer;
  3147. for (index = 0, length = objectKeyList.length; index < length; index += 1) {
  3148. pairBuffer = state.condenseFlow ? '"' : '';
  3149. if (index !== 0) pairBuffer += ', ';
  3150. objectKey = objectKeyList[index];
  3151. objectValue = object[objectKey];
  3152. if (!writeNode(state, level, objectKey, false, false)) {
  3153. continue; // Skip this pair because of invalid key;
  3154. }
  3155. if (state.dump.length > 1024) pairBuffer += '? ';
  3156. pairBuffer += state.dump + (state.condenseFlow ? '"' : '') + ':' + (state.condenseFlow ? '' : ' ');
  3157. if (!writeNode(state, level, objectValue, false, false)) {
  3158. continue; // Skip this pair because of invalid value.
  3159. }
  3160. pairBuffer += state.dump; // Both key and value are valid.
  3161. _result += pairBuffer;
  3162. }
  3163. state.tag = _tag;
  3164. state.dump = '{' + _result + '}';
  3165. }
  3166. function writeBlockMapping(state, level, object, compact) {
  3167. var _result = '',
  3168. _tag = state.tag,
  3169. objectKeyList = Object.keys(object),
  3170. index,
  3171. length,
  3172. objectKey,
  3173. objectValue,
  3174. explicitPair,
  3175. pairBuffer; // Allow sorting keys so that the output file is deterministic
  3176. if (state.sortKeys === true) {
  3177. // Default sorting
  3178. objectKeyList.sort();
  3179. } else if (typeof state.sortKeys === 'function') {
  3180. // Custom sort function
  3181. objectKeyList.sort(state.sortKeys);
  3182. } else if (state.sortKeys) {
  3183. // Something is wrong
  3184. throw new exception('sortKeys must be a boolean or a function');
  3185. }
  3186. for (index = 0, length = objectKeyList.length; index < length; index += 1) {
  3187. pairBuffer = '';
  3188. if (!compact || index !== 0) {
  3189. pairBuffer += generateNextLine(state, level);
  3190. }
  3191. objectKey = objectKeyList[index];
  3192. objectValue = object[objectKey];
  3193. if (!writeNode(state, level + 1, objectKey, true, true, true)) {
  3194. continue; // Skip this pair because of invalid key.
  3195. }
  3196. explicitPair = state.tag !== null && state.tag !== '?' || state.dump && state.dump.length > 1024;
  3197. if (explicitPair) {
  3198. if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
  3199. pairBuffer += '?';
  3200. } else {
  3201. pairBuffer += '? ';
  3202. }
  3203. }
  3204. pairBuffer += state.dump;
  3205. if (explicitPair) {
  3206. pairBuffer += generateNextLine(state, level);
  3207. }
  3208. if (!writeNode(state, level + 1, objectValue, true, explicitPair)) {
  3209. continue; // Skip this pair because of invalid value.
  3210. }
  3211. if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
  3212. pairBuffer += ':';
  3213. } else {
  3214. pairBuffer += ': ';
  3215. }
  3216. pairBuffer += state.dump; // Both key and value are valid.
  3217. _result += pairBuffer;
  3218. }
  3219. state.tag = _tag;
  3220. state.dump = _result || '{}'; // Empty mapping if no valid pairs.
  3221. }
  3222. function detectType(state, object, explicit) {
  3223. var _result, typeList, index, length, type, style;
  3224. typeList = explicit ? state.explicitTypes : state.implicitTypes;
  3225. for (index = 0, length = typeList.length; index < length; index += 1) {
  3226. type = typeList[index];
  3227. if ((type.instanceOf || type.predicate) && (!type.instanceOf || typeof object === 'object' && object instanceof type.instanceOf) && (!type.predicate || type.predicate(object))) {
  3228. state.tag = explicit ? type.tag : '?';
  3229. if (type.represent) {
  3230. style = state.styleMap[type.tag] || type.defaultStyle;
  3231. if (_toString$2.call(type.represent) === '[object Function]') {
  3232. _result = type.represent(object, style);
  3233. } else if (_hasOwnProperty$3.call(type.represent, style)) {
  3234. _result = type.represent[style](object, style);
  3235. } else {
  3236. throw new exception('!<' + type.tag + '> tag resolver accepts not "' + style + '" style');
  3237. }
  3238. state.dump = _result;
  3239. }
  3240. return true;
  3241. }
  3242. }
  3243. return false;
  3244. } // Serializes `object` and writes it to global `result`.
  3245. // Returns true on success, or false on invalid object.
  3246. //
  3247. function writeNode(state, level, object, block, compact, iskey) {
  3248. state.tag = null;
  3249. state.dump = object;
  3250. if (!detectType(state, object, false)) {
  3251. detectType(state, object, true);
  3252. }
  3253. var type = _toString$2.call(state.dump);
  3254. if (block) {
  3255. block = state.flowLevel < 0 || state.flowLevel > level;
  3256. }
  3257. var objectOrArray = type === '[object Object]' || type === '[object Array]',
  3258. duplicateIndex,
  3259. duplicate;
  3260. if (objectOrArray) {
  3261. duplicateIndex = state.duplicates.indexOf(object);
  3262. duplicate = duplicateIndex !== -1;
  3263. }
  3264. if (state.tag !== null && state.tag !== '?' || duplicate || state.indent !== 2 && level > 0) {
  3265. compact = false;
  3266. }
  3267. if (duplicate && state.usedDuplicates[duplicateIndex]) {
  3268. state.dump = '*ref_' + duplicateIndex;
  3269. } else {
  3270. if (objectOrArray && duplicate && !state.usedDuplicates[duplicateIndex]) {
  3271. state.usedDuplicates[duplicateIndex] = true;
  3272. }
  3273. if (type === '[object Object]') {
  3274. if (block && Object.keys(state.dump).length !== 0) {
  3275. writeBlockMapping(state, level, state.dump, compact);
  3276. if (duplicate) {
  3277. state.dump = '&ref_' + duplicateIndex + state.dump;
  3278. }
  3279. } else {
  3280. writeFlowMapping(state, level, state.dump);
  3281. if (duplicate) {
  3282. state.dump = '&ref_' + duplicateIndex + ' ' + state.dump;
  3283. }
  3284. }
  3285. } else if (type === '[object Array]') {
  3286. if (block && state.dump.length !== 0) {
  3287. writeBlockSequence(state, level, state.dump, compact);
  3288. if (duplicate) {
  3289. state.dump = '&ref_' + duplicateIndex + state.dump;
  3290. }
  3291. } else {
  3292. writeFlowSequence(state, level, state.dump);
  3293. if (duplicate) {
  3294. state.dump = '&ref_' + duplicateIndex + ' ' + state.dump;
  3295. }
  3296. }
  3297. } else if (type === '[object String]') {
  3298. if (state.tag !== '?') {
  3299. writeScalar(state, state.dump, level, iskey);
  3300. }
  3301. } else {
  3302. if (state.skipInvalid) return false;
  3303. throw new exception('unacceptable kind of an object to dump ' + type);
  3304. }
  3305. if (state.tag !== null && state.tag !== '?') {
  3306. state.dump = '!<' + state.tag + '> ' + state.dump;
  3307. }
  3308. }
  3309. return true;
  3310. }
  3311. function getDuplicateReferences(object, state) {
  3312. var objects = [],
  3313. duplicatesIndexes = [],
  3314. index,
  3315. length;
  3316. inspectNode(object, objects, duplicatesIndexes);
  3317. for (index = 0, length = duplicatesIndexes.length; index < length; index += 1) {
  3318. state.duplicates.push(objects[duplicatesIndexes[index]]);
  3319. }
  3320. state.usedDuplicates = new Array(length);
  3321. }
  3322. function inspectNode(object, objects, duplicatesIndexes) {
  3323. var objectKeyList, index, length;
  3324. if (object !== null && typeof object === 'object') {
  3325. index = objects.indexOf(object);
  3326. if (index !== -1) {
  3327. if (duplicatesIndexes.indexOf(index) === -1) {
  3328. duplicatesIndexes.push(index);
  3329. }
  3330. } else {
  3331. objects.push(object);
  3332. if (Array.isArray(object)) {
  3333. for (index = 0, length = object.length; index < length; index += 1) {
  3334. inspectNode(object[index], objects, duplicatesIndexes);
  3335. }
  3336. } else {
  3337. objectKeyList = Object.keys(object);
  3338. for (index = 0, length = objectKeyList.length; index < length; index += 1) {
  3339. inspectNode(object[objectKeyList[index]], objects, duplicatesIndexes);
  3340. }
  3341. }
  3342. }
  3343. }
  3344. }
  3345. function dump$1(input, options) {
  3346. options = options || {};
  3347. var state = new State$1(options);
  3348. if (!state.noRefs) getDuplicateReferences(input, state);
  3349. if (writeNode(state, 0, input, true, true)) return state.dump + '\n';
  3350. return '';
  3351. }
  3352. function safeDump$1(input, options) {
  3353. return dump$1(input, common.extend({
  3354. schema: default_safe
  3355. }, options));
  3356. }
  3357. var dump_1 = dump$1;
  3358. var safeDump_1 = safeDump$1;
  3359. var dumper = {
  3360. dump: dump_1,
  3361. safeDump: safeDump_1
  3362. };
  3363. function deprecated(name) {
  3364. return function () {
  3365. throw new Error('Function ' + name + ' is deprecated and cannot be used.');
  3366. };
  3367. }
  3368. var Type = type;
  3369. var Schema = schema;
  3370. var FAILSAFE_SCHEMA = failsafe;
  3371. var JSON_SCHEMA = json;
  3372. var CORE_SCHEMA = core;
  3373. var DEFAULT_SAFE_SCHEMA = default_safe;
  3374. var DEFAULT_FULL_SCHEMA = default_full;
  3375. var load = loader.load;
  3376. var loadAll = loader.loadAll;
  3377. var safeLoad = loader.safeLoad;
  3378. var safeLoadAll = loader.safeLoadAll;
  3379. var dump = dumper.dump;
  3380. var safeDump = dumper.safeDump;
  3381. var YAMLException = exception; // Deprecated schema names from JS-YAML 2.0.x
  3382. var MINIMAL_SCHEMA = failsafe;
  3383. var SAFE_SCHEMA = default_safe;
  3384. var DEFAULT_SCHEMA = default_full; // Deprecated functions from JS-YAML 1.x.x
  3385. var scan = deprecated('scan');
  3386. var parse = deprecated('parse');
  3387. var compose = deprecated('compose');
  3388. var addConstructor = deprecated('addConstructor');
  3389. var jsYaml$2 = {
  3390. Type: Type,
  3391. Schema: Schema,
  3392. FAILSAFE_SCHEMA: FAILSAFE_SCHEMA,
  3393. JSON_SCHEMA: JSON_SCHEMA,
  3394. CORE_SCHEMA: CORE_SCHEMA,
  3395. DEFAULT_SAFE_SCHEMA: DEFAULT_SAFE_SCHEMA,
  3396. DEFAULT_FULL_SCHEMA: DEFAULT_FULL_SCHEMA,
  3397. load: load,
  3398. loadAll: loadAll,
  3399. safeLoad: safeLoad,
  3400. safeLoadAll: safeLoadAll,
  3401. dump: dump,
  3402. safeDump: safeDump,
  3403. YAMLException: YAMLException,
  3404. MINIMAL_SCHEMA: MINIMAL_SCHEMA,
  3405. SAFE_SCHEMA: SAFE_SCHEMA,
  3406. DEFAULT_SCHEMA: DEFAULT_SCHEMA,
  3407. scan: scan,
  3408. parse: parse,
  3409. compose: compose,
  3410. addConstructor: addConstructor
  3411. };
  3412. var jsYaml = jsYaml$2;
  3413. var resolveFrom_1 = createCommonjsModule(function (module) {
  3414. 'use strict';
  3415. var resolveFrom = function resolveFrom(fromDir, moduleId, silent) {
  3416. if (typeof fromDir !== 'string') {
  3417. throw new TypeError(`Expected \`fromDir\` to be of type \`string\`, got \`${typeof fromDir}\``);
  3418. }
  3419. if (typeof moduleId !== 'string') {
  3420. throw new TypeError(`Expected \`moduleId\` to be of type \`string\`, got \`${typeof moduleId}\``);
  3421. }
  3422. fromDir = path.resolve(fromDir);
  3423. var fromFile = path.join(fromDir, 'noop.js');
  3424. var resolveFileName = function resolveFileName() {
  3425. return module$1._resolveFilename(moduleId, {
  3426. id: fromFile,
  3427. filename: fromFile,
  3428. paths: module$1._nodeModulePaths(fromDir)
  3429. });
  3430. };
  3431. if (silent) {
  3432. try {
  3433. return resolveFileName();
  3434. } catch (err) {
  3435. return null;
  3436. }
  3437. }
  3438. return resolveFileName();
  3439. };
  3440. module.exports = function (fromDir, moduleId) {
  3441. return resolveFrom(fromDir, moduleId);
  3442. };
  3443. module.exports.silent = function (fromDir, moduleId) {
  3444. return resolveFrom(fromDir, moduleId, true);
  3445. };
  3446. });
  3447. var callsites = createCommonjsModule(function (module) {
  3448. 'use strict';
  3449. module.exports = function () {
  3450. var _ = Error.prepareStackTrace;
  3451. Error.prepareStackTrace = function (_, stack) {
  3452. return stack;
  3453. };
  3454. var stack = new Error().stack.slice(1);
  3455. Error.prepareStackTrace = _;
  3456. return stack;
  3457. };
  3458. });
  3459. var callerCallsite = createCommonjsModule(function (module) {
  3460. 'use strict';
  3461. module.exports = function () {
  3462. var c = callsites();
  3463. var caller;
  3464. for (var i = 0; i < c.length; i++) {
  3465. var hasReceiver = c[i].getTypeName() !== null;
  3466. if (hasReceiver) {
  3467. caller = i;
  3468. break;
  3469. }
  3470. }
  3471. return c[caller];
  3472. };
  3473. });
  3474. var callerPath = function callerPath() {
  3475. return callerCallsite().getFileName();
  3476. };
  3477. var importFresh = createCommonjsModule(function (module) {
  3478. 'use strict';
  3479. module.exports = function (moduleId) {
  3480. if (typeof moduleId !== 'string') {
  3481. throw new TypeError('Expected a string');
  3482. }
  3483. var filePath = resolveFrom_1(path.dirname(callerPath()), moduleId); // Delete itself from module parent
  3484. if (require.cache[filePath] && require.cache[filePath].parent) {
  3485. var i = require.cache[filePath].parent.children.length;
  3486. while (i--) {
  3487. if (require.cache[filePath].parent.children[i].id === filePath) {
  3488. require.cache[filePath].parent.children.splice(i, 1);
  3489. }
  3490. }
  3491. } // Delete module from cache
  3492. delete require.cache[filePath]; // Return fresh module
  3493. return require(filePath);
  3494. };
  3495. });
  3496. function loadJs(filepath) {
  3497. var result = importFresh(filepath);
  3498. return result;
  3499. }
  3500. function loadJson(filepath, content) {
  3501. try {
  3502. return parseJson(content);
  3503. } catch (err) {
  3504. err.message = `JSON Error in ${filepath}:\n${err.message}`;
  3505. throw err;
  3506. }
  3507. }
  3508. function loadYaml(filepath, content) {
  3509. return jsYaml.safeLoad(content, {
  3510. filename: filepath
  3511. });
  3512. }
  3513. var loaders = {
  3514. loadJs,
  3515. loadJson,
  3516. loadYaml
  3517. };
  3518. function readFile(filepath, options) {
  3519. options = options || {};
  3520. var throwNotFound = options.throwNotFound || false;
  3521. return new Promise(function (resolve, reject) {
  3522. fs.readFile(filepath, 'utf8', function (err, content) {
  3523. if (err && err.code === 'ENOENT' && !throwNotFound) {
  3524. return resolve(null);
  3525. }
  3526. if (err) return reject(err);
  3527. resolve(content);
  3528. });
  3529. });
  3530. }
  3531. readFile.sync = function readFileSync(filepath, options) {
  3532. options = options || {};
  3533. var throwNotFound = options.throwNotFound || false;
  3534. try {
  3535. return fs.readFileSync(filepath, 'utf8');
  3536. } catch (err) {
  3537. if (err.code === 'ENOENT' && !throwNotFound) {
  3538. return null;
  3539. }
  3540. throw err;
  3541. }
  3542. };
  3543. var readFile_1 = readFile;
  3544. //
  3545. function cacheWrapper(cache, key, fn) {
  3546. if (!cache) {
  3547. return fn();
  3548. }
  3549. var cached = cache.get(key);
  3550. if (cached !== undefined) {
  3551. return cached;
  3552. }
  3553. var result = fn();
  3554. cache.set(key, result);
  3555. return result;
  3556. }
  3557. var cacheWrapper_1 = cacheWrapper;
  3558. /**
  3559. * async
  3560. */
  3561. function isDirectory(filepath, cb) {
  3562. if (typeof cb !== 'function') {
  3563. throw new Error('expected a callback function');
  3564. }
  3565. if (typeof filepath !== 'string') {
  3566. cb(new Error('expected filepath to be a string'));
  3567. return;
  3568. }
  3569. fs.stat(filepath, function (err, stats) {
  3570. if (err) {
  3571. if (err.code === 'ENOENT') {
  3572. cb(null, false);
  3573. return;
  3574. }
  3575. cb(err);
  3576. return;
  3577. }
  3578. cb(null, stats.isDirectory());
  3579. });
  3580. }
  3581. /**
  3582. * sync
  3583. */
  3584. isDirectory.sync = function isDirectorySync(filepath) {
  3585. if (typeof filepath !== 'string') {
  3586. throw new Error('expected filepath to be a string');
  3587. }
  3588. try {
  3589. var stat = fs.statSync(filepath);
  3590. return stat.isDirectory();
  3591. } catch (err) {
  3592. if (err.code === 'ENOENT') {
  3593. return false;
  3594. } else {
  3595. throw err;
  3596. }
  3597. }
  3598. return false;
  3599. };
  3600. /**
  3601. * Expose `isDirectory`
  3602. */
  3603. var isDirectory_1 = isDirectory;
  3604. function getDirectory(filepath) {
  3605. return new Promise(function (resolve, reject) {
  3606. return isDirectory_1(filepath, function (err, filepathIsDirectory) {
  3607. if (err) {
  3608. return reject(err);
  3609. }
  3610. return resolve(filepathIsDirectory ? filepath : path.dirname(filepath));
  3611. });
  3612. });
  3613. }
  3614. getDirectory.sync = function getDirectorySync(filepath) {
  3615. return isDirectory_1.sync(filepath) ? filepath : path.dirname(filepath);
  3616. };
  3617. var getDirectory_1 = getDirectory;
  3618. var MODE_SYNC = 'sync'; // An object value represents a config object.
  3619. // null represents that the loader did not find anything relevant.
  3620. // undefined represents that the loader found something relevant
  3621. // but it was empty.
  3622. var Explorer =
  3623. /*#__PURE__*/
  3624. function () {
  3625. function Explorer(options) {
  3626. _classCallCheck(this, Explorer);
  3627. this.loadCache = options.cache ? new Map() : null;
  3628. this.loadSyncCache = options.cache ? new Map() : null;
  3629. this.searchCache = options.cache ? new Map() : null;
  3630. this.searchSyncCache = options.cache ? new Map() : null;
  3631. this.config = options;
  3632. this.validateConfig();
  3633. }
  3634. _createClass(Explorer, [{
  3635. key: "clearLoadCache",
  3636. value: function clearLoadCache() {
  3637. if (this.loadCache) {
  3638. this.loadCache.clear();
  3639. }
  3640. if (this.loadSyncCache) {
  3641. this.loadSyncCache.clear();
  3642. }
  3643. }
  3644. }, {
  3645. key: "clearSearchCache",
  3646. value: function clearSearchCache() {
  3647. if (this.searchCache) {
  3648. this.searchCache.clear();
  3649. }
  3650. if (this.searchSyncCache) {
  3651. this.searchSyncCache.clear();
  3652. }
  3653. }
  3654. }, {
  3655. key: "clearCaches",
  3656. value: function clearCaches() {
  3657. this.clearLoadCache();
  3658. this.clearSearchCache();
  3659. }
  3660. }, {
  3661. key: "validateConfig",
  3662. value: function validateConfig() {
  3663. var config = this.config;
  3664. config.searchPlaces.forEach(function (place) {
  3665. var loaderKey = path.extname(place) || 'noExt';
  3666. var loader = config.loaders[loaderKey];
  3667. if (!loader) {
  3668. throw new Error(`No loader specified for ${getExtensionDescription(place)}, so searchPlaces item "${place}" is invalid`);
  3669. }
  3670. });
  3671. }
  3672. }, {
  3673. key: "search",
  3674. value: function search(searchFrom) {
  3675. var _this = this;
  3676. searchFrom = searchFrom || process.cwd();
  3677. return getDirectory_1(searchFrom).then(function (dir) {
  3678. return _this.searchFromDirectory(dir);
  3679. });
  3680. }
  3681. }, {
  3682. key: "searchFromDirectory",
  3683. value: function searchFromDirectory(dir) {
  3684. var _this2 = this;
  3685. var absoluteDir = path.resolve(process.cwd(), dir);
  3686. var run = function run() {
  3687. return _this2.searchDirectory(absoluteDir).then(function (result) {
  3688. var nextDir = _this2.nextDirectoryToSearch(absoluteDir, result);
  3689. if (nextDir) {
  3690. return _this2.searchFromDirectory(nextDir);
  3691. }
  3692. return _this2.config.transform(result);
  3693. });
  3694. };
  3695. if (this.searchCache) {
  3696. return cacheWrapper_1(this.searchCache, absoluteDir, run);
  3697. }
  3698. return run();
  3699. }
  3700. }, {
  3701. key: "searchSync",
  3702. value: function searchSync(searchFrom) {
  3703. searchFrom = searchFrom || process.cwd();
  3704. var dir = getDirectory_1.sync(searchFrom);
  3705. return this.searchFromDirectorySync(dir);
  3706. }
  3707. }, {
  3708. key: "searchFromDirectorySync",
  3709. value: function searchFromDirectorySync(dir) {
  3710. var _this3 = this;
  3711. var absoluteDir = path.resolve(process.cwd(), dir);
  3712. var run = function run() {
  3713. var result = _this3.searchDirectorySync(absoluteDir);
  3714. var nextDir = _this3.nextDirectoryToSearch(absoluteDir, result);
  3715. if (nextDir) {
  3716. return _this3.searchFromDirectorySync(nextDir);
  3717. }
  3718. return _this3.config.transform(result);
  3719. };
  3720. if (this.searchSyncCache) {
  3721. return cacheWrapper_1(this.searchSyncCache, absoluteDir, run);
  3722. }
  3723. return run();
  3724. }
  3725. }, {
  3726. key: "searchDirectory",
  3727. value: function searchDirectory(dir) {
  3728. var _this4 = this;
  3729. return this.config.searchPlaces.reduce(function (prevResultPromise, place) {
  3730. return prevResultPromise.then(function (prevResult) {
  3731. if (_this4.shouldSearchStopWithResult(prevResult)) {
  3732. return prevResult;
  3733. }
  3734. return _this4.loadSearchPlace(dir, place);
  3735. });
  3736. }, Promise.resolve(null));
  3737. }
  3738. }, {
  3739. key: "searchDirectorySync",
  3740. value: function searchDirectorySync(dir) {
  3741. var result = null;
  3742. var _iteratorNormalCompletion = true;
  3743. var _didIteratorError = false;
  3744. var _iteratorError = undefined;
  3745. try {
  3746. for (var _iterator = this.config.searchPlaces[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  3747. var place = _step.value;
  3748. result = this.loadSearchPlaceSync(dir, place);
  3749. if (this.shouldSearchStopWithResult(result)) break;
  3750. }
  3751. } catch (err) {
  3752. _didIteratorError = true;
  3753. _iteratorError = err;
  3754. } finally {
  3755. try {
  3756. if (!_iteratorNormalCompletion && _iterator.return != null) {
  3757. _iterator.return();
  3758. }
  3759. } finally {
  3760. if (_didIteratorError) {
  3761. throw _iteratorError;
  3762. }
  3763. }
  3764. }
  3765. return result;
  3766. }
  3767. }, {
  3768. key: "shouldSearchStopWithResult",
  3769. value: function shouldSearchStopWithResult(result) {
  3770. if (result === null) return false;
  3771. if (result.isEmpty && this.config.ignoreEmptySearchPlaces) return false;
  3772. return true;
  3773. }
  3774. }, {
  3775. key: "loadSearchPlace",
  3776. value: function loadSearchPlace(dir, place) {
  3777. var _this5 = this;
  3778. var filepath = path.join(dir, place);
  3779. return readFile_1(filepath).then(function (content) {
  3780. return _this5.createCosmiconfigResult(filepath, content);
  3781. });
  3782. }
  3783. }, {
  3784. key: "loadSearchPlaceSync",
  3785. value: function loadSearchPlaceSync(dir, place) {
  3786. var filepath = path.join(dir, place);
  3787. var content = readFile_1.sync(filepath);
  3788. return this.createCosmiconfigResultSync(filepath, content);
  3789. }
  3790. }, {
  3791. key: "nextDirectoryToSearch",
  3792. value: function nextDirectoryToSearch(currentDir, currentResult) {
  3793. if (this.shouldSearchStopWithResult(currentResult)) {
  3794. return null;
  3795. }
  3796. var nextDir = nextDirUp(currentDir);
  3797. if (nextDir === currentDir || currentDir === this.config.stopDir) {
  3798. return null;
  3799. }
  3800. return nextDir;
  3801. }
  3802. }, {
  3803. key: "loadPackageProp",
  3804. value: function loadPackageProp(filepath, content) {
  3805. var parsedContent = loaders.loadJson(filepath, content);
  3806. var packagePropValue = parsedContent[this.config.packageProp];
  3807. return packagePropValue || null;
  3808. }
  3809. }, {
  3810. key: "getLoaderEntryForFile",
  3811. value: function getLoaderEntryForFile(filepath) {
  3812. if (path.basename(filepath) === 'package.json') {
  3813. var loader = this.loadPackageProp.bind(this);
  3814. return {
  3815. sync: loader,
  3816. async: loader
  3817. };
  3818. }
  3819. var loaderKey = path.extname(filepath) || 'noExt';
  3820. return this.config.loaders[loaderKey] || {};
  3821. }
  3822. }, {
  3823. key: "getSyncLoaderForFile",
  3824. value: function getSyncLoaderForFile(filepath) {
  3825. var entry = this.getLoaderEntryForFile(filepath);
  3826. if (!entry.sync) {
  3827. throw new Error(`No sync loader specified for ${getExtensionDescription(filepath)}`);
  3828. }
  3829. return entry.sync;
  3830. }
  3831. }, {
  3832. key: "getAsyncLoaderForFile",
  3833. value: function getAsyncLoaderForFile(filepath) {
  3834. var entry = this.getLoaderEntryForFile(filepath);
  3835. var loader = entry.async || entry.sync;
  3836. if (!loader) {
  3837. throw new Error(`No async loader specified for ${getExtensionDescription(filepath)}`);
  3838. }
  3839. return loader;
  3840. }
  3841. }, {
  3842. key: "loadFileContent",
  3843. value: function loadFileContent(mode, filepath, content) {
  3844. if (content === null) {
  3845. return null;
  3846. }
  3847. if (content.trim() === '') {
  3848. return undefined;
  3849. }
  3850. var loader = mode === MODE_SYNC ? this.getSyncLoaderForFile(filepath) : this.getAsyncLoaderForFile(filepath);
  3851. return loader(filepath, content);
  3852. }
  3853. }, {
  3854. key: "loadedContentToCosmiconfigResult",
  3855. value: function loadedContentToCosmiconfigResult(filepath, loadedContent) {
  3856. if (loadedContent === null) {
  3857. return null;
  3858. }
  3859. if (loadedContent === undefined) {
  3860. return {
  3861. filepath,
  3862. config: undefined,
  3863. isEmpty: true
  3864. };
  3865. }
  3866. return {
  3867. config: loadedContent,
  3868. filepath
  3869. };
  3870. }
  3871. }, {
  3872. key: "createCosmiconfigResult",
  3873. value: function createCosmiconfigResult(filepath, content) {
  3874. var _this6 = this;
  3875. return Promise.resolve().then(function () {
  3876. return _this6.loadFileContent('async', filepath, content);
  3877. }).then(function (loaderResult) {
  3878. return _this6.loadedContentToCosmiconfigResult(filepath, loaderResult);
  3879. });
  3880. }
  3881. }, {
  3882. key: "createCosmiconfigResultSync",
  3883. value: function createCosmiconfigResultSync(filepath, content) {
  3884. var loaderResult = this.loadFileContent('sync', filepath, content);
  3885. return this.loadedContentToCosmiconfigResult(filepath, loaderResult);
  3886. }
  3887. }, {
  3888. key: "validateFilePath",
  3889. value: function validateFilePath(filepath) {
  3890. if (!filepath) {
  3891. throw new Error('load and loadSync must pass a non-empty string');
  3892. }
  3893. }
  3894. }, {
  3895. key: "load",
  3896. value: function load(filepath) {
  3897. var _this7 = this;
  3898. return Promise.resolve().then(function () {
  3899. _this7.validateFilePath(filepath);
  3900. var absoluteFilePath = path.resolve(process.cwd(), filepath);
  3901. return cacheWrapper_1(_this7.loadCache, absoluteFilePath, function () {
  3902. return readFile_1(absoluteFilePath, {
  3903. throwNotFound: true
  3904. }).then(function (content) {
  3905. return _this7.createCosmiconfigResult(absoluteFilePath, content);
  3906. }).then(_this7.config.transform);
  3907. });
  3908. });
  3909. }
  3910. }, {
  3911. key: "loadSync",
  3912. value: function loadSync(filepath) {
  3913. var _this8 = this;
  3914. this.validateFilePath(filepath);
  3915. var absoluteFilePath = path.resolve(process.cwd(), filepath);
  3916. return cacheWrapper_1(this.loadSyncCache, absoluteFilePath, function () {
  3917. var content = readFile_1.sync(absoluteFilePath, {
  3918. throwNotFound: true
  3919. });
  3920. var result = _this8.createCosmiconfigResultSync(absoluteFilePath, content);
  3921. return _this8.config.transform(result);
  3922. });
  3923. }
  3924. }]);
  3925. return Explorer;
  3926. }();
  3927. var createExplorer = function createExplorer(options) {
  3928. var explorer = new Explorer(options);
  3929. return {
  3930. search: explorer.search.bind(explorer),
  3931. searchSync: explorer.searchSync.bind(explorer),
  3932. load: explorer.load.bind(explorer),
  3933. loadSync: explorer.loadSync.bind(explorer),
  3934. clearLoadCache: explorer.clearLoadCache.bind(explorer),
  3935. clearSearchCache: explorer.clearSearchCache.bind(explorer),
  3936. clearCaches: explorer.clearCaches.bind(explorer)
  3937. };
  3938. };
  3939. function nextDirUp(dir) {
  3940. return path.dirname(dir);
  3941. }
  3942. function getExtensionDescription(filepath) {
  3943. var ext = path.extname(filepath);
  3944. return ext ? `extension "${ext}"` : 'files without extensions';
  3945. }
  3946. var dist = cosmiconfig;
  3947. function cosmiconfig(moduleName, options) {
  3948. options = options || {};
  3949. var defaults = {
  3950. packageProp: moduleName,
  3951. searchPlaces: ['package.json', `.${moduleName}rc`, `.${moduleName}rc.json`, `.${moduleName}rc.yaml`, `.${moduleName}rc.yml`, `.${moduleName}rc.js`, `${moduleName}.config.js`],
  3952. ignoreEmptySearchPlaces: true,
  3953. stopDir: os.homedir(),
  3954. cache: true,
  3955. transform: identity
  3956. };
  3957. var normalizedOptions = Object.assign({}, defaults, options, {
  3958. loaders: normalizeLoaders(options.loaders)
  3959. });
  3960. return createExplorer(normalizedOptions);
  3961. }
  3962. cosmiconfig.loadJs = loaders.loadJs;
  3963. cosmiconfig.loadJson = loaders.loadJson;
  3964. cosmiconfig.loadYaml = loaders.loadYaml;
  3965. function normalizeLoaders(rawLoaders) {
  3966. var defaults = {
  3967. '.js': {
  3968. sync: loaders.loadJs,
  3969. async: loaders.loadJs
  3970. },
  3971. '.json': {
  3972. sync: loaders.loadJson,
  3973. async: loaders.loadJson
  3974. },
  3975. '.yaml': {
  3976. sync: loaders.loadYaml,
  3977. async: loaders.loadYaml
  3978. },
  3979. '.yml': {
  3980. sync: loaders.loadYaml,
  3981. async: loaders.loadYaml
  3982. },
  3983. noExt: {
  3984. sync: loaders.loadYaml,
  3985. async: loaders.loadYaml
  3986. }
  3987. };
  3988. if (!rawLoaders) {
  3989. return defaults;
  3990. }
  3991. return Object.keys(rawLoaders).reduce(function (result, ext) {
  3992. var entry = rawLoaders && rawLoaders[ext];
  3993. if (typeof entry === 'function') {
  3994. result[ext] = {
  3995. sync: entry,
  3996. async: entry
  3997. };
  3998. } else {
  3999. result[ext] = entry;
  4000. }
  4001. return result;
  4002. }, defaults);
  4003. }
  4004. function identity(x) {
  4005. return x;
  4006. }
  4007. var findParentDir$1 = createCommonjsModule(function (module, exports) {
  4008. 'use strict';
  4009. var exists = fs.exists || path.exists,
  4010. existsSync = fs.existsSync || path.existsSync;
  4011. function splitPath(path$$2) {
  4012. var parts = path$$2.split(/(\/|\\)/);
  4013. if (!parts.length) return parts; // when path starts with a slash, the first part is empty string
  4014. return !parts[0].length ? parts.slice(1) : parts;
  4015. }
  4016. exports = module.exports = function (currentFullPath, clue, cb) {
  4017. function testDir(parts) {
  4018. if (parts.length === 0) return cb(null, null);
  4019. var p = parts.join('');
  4020. exists(path.join(p, clue), function (itdoes) {
  4021. if (itdoes) return cb(null, p);
  4022. testDir(parts.slice(0, -1));
  4023. });
  4024. }
  4025. testDir(splitPath(currentFullPath));
  4026. };
  4027. exports.sync = function (currentFullPath, clue) {
  4028. function testDir(parts) {
  4029. if (parts.length === 0) return null;
  4030. var p = parts.join('');
  4031. var itdoes = existsSync(path.join(p, clue));
  4032. return itdoes ? p : testDir(parts.slice(0, -1));
  4033. }
  4034. return testDir(splitPath(currentFullPath));
  4035. };
  4036. });
  4037. var bufferStream = createCommonjsModule(function (module) {
  4038. 'use strict';
  4039. var PassThrough = stream.PassThrough;
  4040. module.exports = function (opts) {
  4041. opts = Object.assign({}, opts);
  4042. var array = opts.array;
  4043. var encoding = opts.encoding;
  4044. var buffer = encoding === 'buffer';
  4045. var objectMode = false;
  4046. if (array) {
  4047. objectMode = !(encoding || buffer);
  4048. } else {
  4049. encoding = encoding || 'utf8';
  4050. }
  4051. if (buffer) {
  4052. encoding = null;
  4053. }
  4054. var len = 0;
  4055. var ret = [];
  4056. var stream$$1 = new PassThrough({
  4057. objectMode
  4058. });
  4059. if (encoding) {
  4060. stream$$1.setEncoding(encoding);
  4061. }
  4062. stream$$1.on('data', function (chunk) {
  4063. ret.push(chunk);
  4064. if (objectMode) {
  4065. len = ret.length;
  4066. } else {
  4067. len += chunk.length;
  4068. }
  4069. });
  4070. stream$$1.getBufferedValue = function () {
  4071. if (array) {
  4072. return ret;
  4073. }
  4074. return buffer ? Buffer.concat(ret, len) : ret.join('');
  4075. };
  4076. stream$$1.getBufferedLength = function () {
  4077. return len;
  4078. };
  4079. return stream$$1;
  4080. };
  4081. });
  4082. function getStream(inputStream, opts) {
  4083. if (!inputStream) {
  4084. return Promise.reject(new Error('Expected a stream'));
  4085. }
  4086. opts = Object.assign({
  4087. maxBuffer: Infinity
  4088. }, opts);
  4089. var maxBuffer = opts.maxBuffer;
  4090. var stream$$1;
  4091. var clean;
  4092. var p = new Promise(function (resolve, reject) {
  4093. var error = function error(err) {
  4094. if (err) {
  4095. // null check
  4096. err.bufferedData = stream$$1.getBufferedValue();
  4097. }
  4098. reject(err);
  4099. };
  4100. stream$$1 = bufferStream(opts);
  4101. inputStream.once('error', error);
  4102. inputStream.pipe(stream$$1);
  4103. stream$$1.on('data', function () {
  4104. if (stream$$1.getBufferedLength() > maxBuffer) {
  4105. reject(new Error('maxBuffer exceeded'));
  4106. }
  4107. });
  4108. stream$$1.once('error', error);
  4109. stream$$1.on('end', resolve);
  4110. clean = function clean() {
  4111. // some streams doesn't implement the `stream.Readable` interface correctly
  4112. if (inputStream.unpipe) {
  4113. inputStream.unpipe(stream$$1);
  4114. }
  4115. };
  4116. });
  4117. p.then(clean, clean);
  4118. return p.then(function () {
  4119. return stream$$1.getBufferedValue();
  4120. });
  4121. }
  4122. var getStream_1 = getStream;
  4123. var buffer = function buffer(stream$$1, opts) {
  4124. return getStream(stream$$1, Object.assign({}, opts, {
  4125. encoding: 'buffer'
  4126. }));
  4127. };
  4128. var array = function array(stream$$1, opts) {
  4129. return getStream(stream$$1, Object.assign({}, opts, {
  4130. array: true
  4131. }));
  4132. };
  4133. getStream_1.buffer = buffer;
  4134. getStream_1.array = array;
  4135. var vendors = [{
  4136. "name": "AppVeyor",
  4137. "constant": "APPVEYOR",
  4138. "env": "APPVEYOR",
  4139. "pr": "APPVEYOR_PULL_REQUEST_NUMBER"
  4140. }, {
  4141. "name": "Azure Pipelines",
  4142. "constant": "AZURE_PIPELINES",
  4143. "env": "SYSTEM_TEAMFOUNDATIONCOLLECTIONURI",
  4144. "pr": "SYSTEM_PULLREQUEST_PULLREQUESTID"
  4145. }, {
  4146. "name": "Bamboo",
  4147. "constant": "BAMBOO",
  4148. "env": "bamboo_planKey"
  4149. }, {
  4150. "name": "Bitbucket Pipelines",
  4151. "constant": "BITBUCKET",
  4152. "env": "BITBUCKET_COMMIT",
  4153. "pr": "BITBUCKET_PR_ID"
  4154. }, {
  4155. "name": "Bitrise",
  4156. "constant": "BITRISE",
  4157. "env": "BITRISE_IO",
  4158. "pr": "BITRISE_PULL_REQUEST"
  4159. }, {
  4160. "name": "Buddy",
  4161. "constant": "BUDDY",
  4162. "env": "BUDDY_WORKSPACE_ID",
  4163. "pr": "BUDDY_EXECUTION_PULL_REQUEST_ID"
  4164. }, {
  4165. "name": "Buildkite",
  4166. "constant": "BUILDKITE",
  4167. "env": "BUILDKITE",
  4168. "pr": {
  4169. "env": "BUILDKITE_PULL_REQUEST",
  4170. "ne": "false"
  4171. }
  4172. }, {
  4173. "name": "CircleCI",
  4174. "constant": "CIRCLE",
  4175. "env": "CIRCLECI",
  4176. "pr": "CIRCLE_PULL_REQUEST"
  4177. }, {
  4178. "name": "Cirrus CI",
  4179. "constant": "CIRRUS",
  4180. "env": "CIRRUS_CI",
  4181. "pr": "CIRRUS_PR"
  4182. }, {
  4183. "name": "AWS CodeBuild",
  4184. "constant": "CODEBUILD",
  4185. "env": "CODEBUILD_BUILD_ARN"
  4186. }, {
  4187. "name": "Codeship",
  4188. "constant": "CODESHIP",
  4189. "env": {
  4190. "CI_NAME": "codeship"
  4191. }
  4192. }, {
  4193. "name": "Drone",
  4194. "constant": "DRONE",
  4195. "env": "DRONE",
  4196. "pr": {
  4197. "DRONE_BUILD_EVENT": "pull_request"
  4198. }
  4199. }, {
  4200. "name": "dsari",
  4201. "constant": "DSARI",
  4202. "env": "DSARI"
  4203. }, {
  4204. "name": "GitLab CI",
  4205. "constant": "GITLAB",
  4206. "env": "GITLAB_CI"
  4207. }, {
  4208. "name": "GoCD",
  4209. "constant": "GOCD",
  4210. "env": "GO_PIPELINE_LABEL"
  4211. }, {
  4212. "name": "Hudson",
  4213. "constant": "HUDSON",
  4214. "env": "HUDSON_URL"
  4215. }, {
  4216. "name": "Jenkins",
  4217. "constant": "JENKINS",
  4218. "env": ["JENKINS_URL", "BUILD_ID"],
  4219. "pr": {
  4220. "any": ["ghprbPullId", "CHANGE_ID"]
  4221. }
  4222. }, {
  4223. "name": "Magnum CI",
  4224. "constant": "MAGNUM",
  4225. "env": "MAGNUM"
  4226. }, {
  4227. "name": "Netlify CI",
  4228. "constant": "NETLIFY",
  4229. "env": "NETLIFY_BUILD_BASE",
  4230. "pr": {
  4231. "env": "PULL_REQUEST",
  4232. "ne": "false"
  4233. }
  4234. }, {
  4235. "name": "Sail CI",
  4236. "constant": "SAIL",
  4237. "env": "SAILCI",
  4238. "pr": "SAIL_PULL_REQUEST_NUMBER"
  4239. }, {
  4240. "name": "Semaphore",
  4241. "constant": "SEMAPHORE",
  4242. "env": "SEMAPHORE",
  4243. "pr": "PULL_REQUEST_NUMBER"
  4244. }, {
  4245. "name": "Shippable",
  4246. "constant": "SHIPPABLE",
  4247. "env": "SHIPPABLE",
  4248. "pr": {
  4249. "IS_PULL_REQUEST": "true"
  4250. }
  4251. }, {
  4252. "name": "Solano CI",
  4253. "constant": "SOLANO",
  4254. "env": "TDDIUM",
  4255. "pr": "TDDIUM_PR_ID"
  4256. }, {
  4257. "name": "Strider CD",
  4258. "constant": "STRIDER",
  4259. "env": "STRIDER"
  4260. }, {
  4261. "name": "TaskCluster",
  4262. "constant": "TASKCLUSTER",
  4263. "env": ["TASK_ID", "RUN_ID"]
  4264. }, {
  4265. "name": "TeamCity",
  4266. "constant": "TEAMCITY",
  4267. "env": "TEAMCITY_VERSION"
  4268. }, {
  4269. "name": "Travis CI",
  4270. "constant": "TRAVIS",
  4271. "env": "TRAVIS",
  4272. "pr": {
  4273. "env": "TRAVIS_PULL_REQUEST",
  4274. "ne": "false"
  4275. }
  4276. }];
  4277. var vendors$1 = Object.freeze({
  4278. default: vendors
  4279. });
  4280. var vendors$2 = ( vendors$1 && vendors ) || vendors$1;
  4281. var ciInfo = createCommonjsModule(function (module, exports) {
  4282. 'use strict';
  4283. var env = process.env; // Used for testing only
  4284. Object.defineProperty(exports, '_vendors', {
  4285. value: vendors$2.map(function (v) {
  4286. return v.constant;
  4287. })
  4288. });
  4289. exports.name = null;
  4290. exports.isPR = null;
  4291. vendors$2.forEach(function (vendor) {
  4292. var envs = Array.isArray(vendor.env) ? vendor.env : [vendor.env];
  4293. var isCI = envs.every(function (obj) {
  4294. return checkEnv(obj);
  4295. });
  4296. exports[vendor.constant] = isCI;
  4297. if (isCI) {
  4298. exports.name = vendor.name;
  4299. switch (typeof vendor.pr) {
  4300. case 'string':
  4301. // "pr": "CIRRUS_PR"
  4302. exports.isPR = !!env[vendor.pr];
  4303. break;
  4304. case 'object':
  4305. if ('env' in vendor.pr) {
  4306. // "pr": { "env": "BUILDKITE_PULL_REQUEST", "ne": "false" }
  4307. exports.isPR = vendor.pr.env in env && env[vendor.pr.env] !== vendor.pr.ne;
  4308. } else if ('any' in vendor.pr) {
  4309. // "pr": { "any": ["ghprbPullId", "CHANGE_ID"] }
  4310. exports.isPR = vendor.pr.any.some(function (key) {
  4311. return !!env[key];
  4312. });
  4313. } else {
  4314. // "pr": { "DRONE_BUILD_EVENT": "pull_request" }
  4315. exports.isPR = checkEnv(vendor.pr);
  4316. }
  4317. break;
  4318. default:
  4319. // PR detection not supported for this vendor
  4320. exports.isPR = null;
  4321. }
  4322. }
  4323. });
  4324. exports.isCI = !!(env.CI || // Travis CI, CircleCI, Cirrus CI, Gitlab CI, Appveyor, CodeShip, dsari
  4325. env.CONTINUOUS_INTEGRATION || // Travis CI, Cirrus CI
  4326. env.BUILD_NUMBER || // Jenkins, TeamCity
  4327. env.RUN_ID || // TaskCluster, dsari
  4328. exports.name || false);
  4329. function checkEnv(obj) {
  4330. if (typeof obj === 'string') return !!env[obj];
  4331. return Object.keys(obj).every(function (k) {
  4332. return env[k] === obj[k];
  4333. });
  4334. }
  4335. });
  4336. var isCi = ciInfo.isCI;
  4337. var findParentDir = findParentDir$1.sync;
  4338. var thirdParty = {
  4339. cosmiconfig: dist,
  4340. findParentDir,
  4341. getStream: getStream_1,
  4342. isCI:
  4343. /* istanbul ignore next */
  4344. function isCI() {
  4345. return isCi;
  4346. }
  4347. };
  4348. module.exports = thirdParty;