third-party.js 148 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495
  1. 'use strict';
  2. function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
  3. var stream = _interopDefault(require('stream'));
  4. var os = _interopDefault(require('os'));
  5. var path = _interopDefault(require('path'));
  6. var fs = _interopDefault(require('fs'));
  7. var util = _interopDefault(require('util'));
  8. var module$1 = _interopDefault(require('module'));
  9. function commonjsRequire () {
  10. throw new Error('Dynamic requires are not currently supported by rollup-plugin-commonjs');
  11. }
  12. function createCommonjsModule(fn, module) {
  13. return module = { exports: {} }, fn(module, module.exports), module.exports;
  14. }
  15. var bufferStream = createCommonjsModule(function (module) {
  16. 'use strict';
  17. const PassThrough = stream.PassThrough;
  18. module.exports = opts => {
  19. opts = Object.assign({}, opts);
  20. const array = opts.array;
  21. let encoding = opts.encoding;
  22. const buffer = encoding === 'buffer';
  23. let objectMode = false;
  24. if (array) {
  25. objectMode = !(encoding || buffer);
  26. } else {
  27. encoding = encoding || 'utf8';
  28. }
  29. if (buffer) {
  30. encoding = null;
  31. }
  32. let len = 0;
  33. const ret = [];
  34. const stream$$1 = new PassThrough({objectMode});
  35. if (encoding) {
  36. stream$$1.setEncoding(encoding);
  37. }
  38. stream$$1.on('data', chunk => {
  39. ret.push(chunk);
  40. if (objectMode) {
  41. len = ret.length;
  42. } else {
  43. len += chunk.length;
  44. }
  45. });
  46. stream$$1.getBufferedValue = () => {
  47. if (array) {
  48. return ret;
  49. }
  50. return buffer ? Buffer.concat(ret, len) : ret.join('');
  51. };
  52. stream$$1.getBufferedLength = () => len;
  53. return stream$$1;
  54. };
  55. });
  56. function getStream(inputStream, opts) {
  57. if (!inputStream) {
  58. return Promise.reject(new Error('Expected a stream'));
  59. }
  60. opts = Object.assign({maxBuffer: Infinity}, opts);
  61. const maxBuffer = opts.maxBuffer;
  62. let stream$$1;
  63. let clean;
  64. const p = new Promise((resolve, reject) => {
  65. const error = err => {
  66. if (err) { // null check
  67. err.bufferedData = stream$$1.getBufferedValue();
  68. }
  69. reject(err);
  70. };
  71. stream$$1 = bufferStream(opts);
  72. inputStream.once('error', error);
  73. inputStream.pipe(stream$$1);
  74. stream$$1.on('data', () => {
  75. if (stream$$1.getBufferedLength() > maxBuffer) {
  76. reject(new Error('maxBuffer exceeded'));
  77. }
  78. });
  79. stream$$1.once('error', error);
  80. stream$$1.on('end', resolve);
  81. clean = () => {
  82. // some streams doesn't implement the `stream.Readable` interface correctly
  83. if (inputStream.unpipe) {
  84. inputStream.unpipe(stream$$1);
  85. }
  86. };
  87. });
  88. p.then(clean, clean);
  89. return p.then(() => stream$$1.getBufferedValue());
  90. }
  91. var getStream_1 = getStream;
  92. var buffer = (stream$$1, opts) => getStream(stream$$1, Object.assign({}, opts, {encoding: 'buffer'}));
  93. var array = (stream$$1, opts) => getStream(stream$$1, Object.assign({}, opts, {array: true}));
  94. getStream_1.buffer = buffer;
  95. getStream_1.array = array;
  96. function readFile(filepath , options ) {
  97. options = options || {};
  98. const throwNotFound = options.throwNotFound || false;
  99. return new Promise((resolve, reject) => {
  100. fs.readFile(filepath, 'utf8', (err, content) => {
  101. if (err && err.code === 'ENOENT' && !throwNotFound) {
  102. return resolve(null);
  103. }
  104. if (err) return reject(err);
  105. resolve(content);
  106. });
  107. });
  108. }
  109. readFile.sync = function readFileSync(
  110. filepath ,
  111. options
  112. ) {
  113. options = options || {};
  114. const throwNotFound = options.throwNotFound || false;
  115. try {
  116. return fs.readFileSync(filepath, 'utf8');
  117. } catch (err) {
  118. if (err.code === 'ENOENT' && !throwNotFound) {
  119. return null;
  120. }
  121. throw err;
  122. }
  123. };
  124. var readFile_1 = readFile;
  125. var isArrayish = function isArrayish(obj) {
  126. if (!obj) {
  127. return false;
  128. }
  129. return obj instanceof Array || Array.isArray(obj) ||
  130. (obj.length >= 0 && obj.splice instanceof Function);
  131. };
  132. var errorEx = function errorEx(name, properties) {
  133. if (!name || name.constructor !== String) {
  134. properties = name || {};
  135. name = Error.name;
  136. }
  137. var errorExError = function ErrorEXError(message) {
  138. if (!this) {
  139. return new ErrorEXError(message);
  140. }
  141. message = message instanceof Error
  142. ? message.message
  143. : (message || this.message);
  144. Error.call(this, message);
  145. Error.captureStackTrace(this, errorExError);
  146. this.name = name;
  147. Object.defineProperty(this, 'message', {
  148. configurable: true,
  149. enumerable: false,
  150. get: function () {
  151. var newMessage = message.split(/\r?\n/g);
  152. for (var key in properties) {
  153. if (!properties.hasOwnProperty(key)) {
  154. continue;
  155. }
  156. var modifier = properties[key];
  157. if ('message' in modifier) {
  158. newMessage = modifier.message(this[key], newMessage) || newMessage;
  159. if (!isArrayish(newMessage)) {
  160. newMessage = [newMessage];
  161. }
  162. }
  163. }
  164. return newMessage.join('\n');
  165. },
  166. set: function (v) {
  167. message = v;
  168. }
  169. });
  170. var stackDescriptor = Object.getOwnPropertyDescriptor(this, 'stack');
  171. var stackGetter = stackDescriptor.get;
  172. var stackValue = stackDescriptor.value;
  173. delete stackDescriptor.value;
  174. delete stackDescriptor.writable;
  175. stackDescriptor.get = function () {
  176. var stack = (stackGetter)
  177. ? stackGetter.call(this).split(/\r?\n+/g)
  178. : stackValue.split(/\r?\n+/g);
  179. // starting in Node 7, the stack builder caches the message.
  180. // just replace it.
  181. stack[0] = this.name + ': ' + this.message;
  182. var lineCount = 1;
  183. for (var key in properties) {
  184. if (!properties.hasOwnProperty(key)) {
  185. continue;
  186. }
  187. var modifier = properties[key];
  188. if ('line' in modifier) {
  189. var line = modifier.line(this[key]);
  190. if (line) {
  191. stack.splice(lineCount++, 0, ' ' + line);
  192. }
  193. }
  194. if ('stack' in modifier) {
  195. modifier.stack(this[key], stack);
  196. }
  197. }
  198. return stack.join('\n');
  199. };
  200. Object.defineProperty(this, 'stack', stackDescriptor);
  201. };
  202. if (Object.setPrototypeOf) {
  203. Object.setPrototypeOf(errorExError.prototype, Error.prototype);
  204. Object.setPrototypeOf(errorExError, Error);
  205. } else {
  206. util.inherits(errorExError, Error);
  207. }
  208. return errorExError;
  209. };
  210. errorEx.append = function (str, def) {
  211. return {
  212. message: function (v, message) {
  213. v = v || def;
  214. if (v) {
  215. message[0] += ' ' + str.replace('%s', v.toString());
  216. }
  217. return message;
  218. }
  219. };
  220. };
  221. errorEx.line = function (str, def) {
  222. return {
  223. line: function (v) {
  224. v = v || def;
  225. if (v) {
  226. return str.replace('%s', v.toString());
  227. }
  228. return null;
  229. }
  230. };
  231. };
  232. var errorEx_1 = errorEx;
  233. var unicode = createCommonjsModule(function (module) {
  234. // This is autogenerated with esprima tools, see:
  235. // https://github.com/ariya/esprima/blob/master/esprima.js
  236. //
  237. // PS: oh God, I hate Unicode
  238. // ECMAScript 5.1/Unicode v6.3.0 NonAsciiIdentifierStart:
  239. var Uni = module.exports;
  240. module.exports.isWhiteSpace = function isWhiteSpace(x) {
  241. // section 7.2, table 2
  242. return x === '\u0020'
  243. || x === '\u00A0'
  244. || x === '\uFEFF' // <-- this is not a Unicode WS, only a JS one
  245. || (x >= '\u0009' && x <= '\u000D') // 9 A B C D
  246. // + whitespace characters from unicode, category Zs
  247. || x === '\u1680'
  248. || x === '\u180E'
  249. || (x >= '\u2000' && x <= '\u200A') // 0 1 2 3 4 5 6 7 8 9 A
  250. || x === '\u2028'
  251. || x === '\u2029'
  252. || x === '\u202F'
  253. || x === '\u205F'
  254. || x === '\u3000'
  255. };
  256. module.exports.isWhiteSpaceJSON = function isWhiteSpaceJSON(x) {
  257. return x === '\u0020'
  258. || x === '\u0009'
  259. || x === '\u000A'
  260. || x === '\u000D'
  261. };
  262. module.exports.isLineTerminator = function isLineTerminator(x) {
  263. // ok, here is the part when JSON is wrong
  264. // section 7.3, table 3
  265. return x === '\u000A'
  266. || x === '\u000D'
  267. || x === '\u2028'
  268. || x === '\u2029'
  269. };
  270. module.exports.isLineTerminatorJSON = function isLineTerminatorJSON(x) {
  271. return x === '\u000A'
  272. || x === '\u000D'
  273. };
  274. module.exports.isIdentifierStart = function isIdentifierStart(x) {
  275. return x === '$'
  276. || x === '_'
  277. || (x >= 'A' && x <= 'Z')
  278. || (x >= 'a' && x <= 'z')
  279. || (x >= '\u0080' && Uni.NonAsciiIdentifierStart.test(x))
  280. };
  281. module.exports.isIdentifierPart = function isIdentifierPart(x) {
  282. return x === '$'
  283. || x === '_'
  284. || (x >= 'A' && x <= 'Z')
  285. || (x >= 'a' && x <= 'z')
  286. || (x >= '0' && x <= '9') // <-- addition to Start
  287. || (x >= '\u0080' && Uni.NonAsciiIdentifierPart.test(x))
  288. };
  289. module.exports.NonAsciiIdentifierStart = /[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u0527\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u08A0\u08A2-\u08AC\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0977\u0979-\u097F\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C33\u0C35-\u0C39\u0C3D\u0C58\u0C59\u0C60\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D60\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F4\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F0\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191C\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19C1-\u19C7\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FCC\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA697\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA78E\uA790-\uA793\uA7A0-\uA7AA\uA7F8-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA80-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uABC0-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]/;
  290. // ECMAScript 5.1/Unicode v6.3.0 NonAsciiIdentifierPart:
  291. module.exports.NonAsciiIdentifierPart = /[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376\u0377\u037A-\u037D\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u0483-\u0487\u048A-\u0527\u0531-\u0556\u0559\u0561-\u0587\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u05D0-\u05EA\u05F0-\u05F2\u0610-\u061A\u0620-\u0669\u066E-\u06D3\u06D5-\u06DC\u06DF-\u06E8\u06EA-\u06FC\u06FF\u0710-\u074A\u074D-\u07B1\u07C0-\u07F5\u07FA\u0800-\u082D\u0840-\u085B\u08A0\u08A2-\u08AC\u08E4-\u08FE\u0900-\u0963\u0966-\u096F\u0971-\u0977\u0979-\u097F\u0981-\u0983\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BC-\u09C4\u09C7\u09C8\u09CB-\u09CE\u09D7\u09DC\u09DD\u09DF-\u09E3\u09E6-\u09F1\u0A01-\u0A03\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A59-\u0A5C\u0A5E\u0A66-\u0A75\u0A81-\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABC-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AD0\u0AE0-\u0AE3\u0AE6-\u0AEF\u0B01-\u0B03\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3C-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B5C\u0B5D\u0B5F-\u0B63\u0B66-\u0B6F\u0B71\u0B82\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD0\u0BD7\u0BE6-\u0BEF\u0C01-\u0C03\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C33\u0C35-\u0C39\u0C3D-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C58\u0C59\u0C60-\u0C63\u0C66-\u0C6F\u0C82\u0C83\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBC-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CDE\u0CE0-\u0CE3\u0CE6-\u0CEF\u0CF1\u0CF2\u0D02\u0D03\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D-\u0D44\u0D46-\u0D48\u0D4A-\u0D4E\u0D57\u0D60-\u0D63\u0D66-\u0D6F\u0D7A-\u0D7F\u0D82\u0D83\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E01-\u0E3A\u0E40-\u0E4E\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB9\u0EBB-\u0EBD\u0EC0-\u0EC4\u0EC6\u0EC8-\u0ECD\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E-\u0F47\u0F49-\u0F6C\u0F71-\u0F84\u0F86-\u0F97\u0F99-\u0FBC\u0FC6\u1000-\u1049\u1050-\u109D\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u135D-\u135F\u1380-\u138F\u13A0-\u13F4\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F0\u1700-\u170C\u170E-\u1714\u1720-\u1734\u1740-\u1753\u1760-\u176C\u176E-\u1770\u1772\u1773\u1780-\u17D3\u17D7\u17DC\u17DD\u17E0-\u17E9\u180B-\u180D\u1810-\u1819\u1820-\u1877\u1880-\u18AA\u18B0-\u18F5\u1900-\u191C\u1920-\u192B\u1930-\u193B\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19D9\u1A00-\u1A1B\u1A20-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AA7\u1B00-\u1B4B\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1BF3\u1C00-\u1C37\u1C40-\u1C49\u1C4D-\u1C7D\u1CD0-\u1CD2\u1CD4-\u1CF6\u1D00-\u1DE6\u1DFC-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u200C\u200D\u203F\u2040\u2054\u2071\u207F\u2090-\u209C\u20D0-\u20DC\u20E1\u20E5-\u20F0\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D7F-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2DE0-\u2DFF\u2E2F\u3005-\u3007\u3021-\u302F\u3031-\u3035\u3038-\u303C\u3041-\u3096\u3099\u309A\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FCC\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66F\uA674-\uA67D\uA67F-\uA697\uA69F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA78E\uA790-\uA793\uA7A0-\uA7AA\uA7F8-\uA827\uA840-\uA873\uA880-\uA8C4\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\uA900-\uA92D\uA930-\uA953\uA960-\uA97C\uA980-\uA9C0\uA9CF-\uA9D9\uAA00-\uAA36\uAA40-\uAA4D\uAA50-\uAA59\uAA60-\uAA76\uAA7A\uAA7B\uAA80-\uAAC2\uAADB-\uAADD\uAAE0-\uAAEF\uAAF2-\uAAF6\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uABC0-\uABEA\uABEC\uABED\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE00-\uFE0F\uFE20-\uFE26\uFE33\uFE34\uFE4D-\uFE4F\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF3F\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]/;
  292. });
  293. var parse_1 = createCommonjsModule(function (module) {
  294. /*
  295. * Author: Alex Kocharin <alex@kocharin.ru>
  296. * GIT: https://github.com/rlidwka/jju
  297. * License: WTFPL, grab your copy here: http://www.wtfpl.net/txt/copying/
  298. */
  299. // RTFM: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf
  300. function isHexDigit(x) {
  301. return (x >= '0' && x <= '9')
  302. || (x >= 'A' && x <= 'F')
  303. || (x >= 'a' && x <= 'f')
  304. }
  305. function isOctDigit(x) {
  306. return x >= '0' && x <= '7'
  307. }
  308. function isDecDigit(x) {
  309. return x >= '0' && x <= '9'
  310. }
  311. var unescapeMap = {
  312. '\'': '\'',
  313. '"' : '"',
  314. '\\': '\\',
  315. 'b' : '\b',
  316. 'f' : '\f',
  317. 'n' : '\n',
  318. 'r' : '\r',
  319. 't' : '\t',
  320. 'v' : '\v',
  321. '/' : '/',
  322. };
  323. function formatError(input, msg, position, lineno, column, json5) {
  324. var result = msg + ' at ' + (lineno + 1) + ':' + (column + 1)
  325. , tmppos = position - column - 1
  326. , srcline = ''
  327. , underline = '';
  328. var isLineTerminator = json5 ? unicode.isLineTerminator : unicode.isLineTerminatorJSON;
  329. // output no more than 70 characters before the wrong ones
  330. if (tmppos < position - 70) {
  331. tmppos = position - 70;
  332. }
  333. while (1) {
  334. var chr = input[++tmppos];
  335. if (isLineTerminator(chr) || tmppos === input.length) {
  336. if (position >= tmppos) {
  337. // ending line error, so show it after the last char
  338. underline += '^';
  339. }
  340. break
  341. }
  342. srcline += chr;
  343. if (position === tmppos) {
  344. underline += '^';
  345. } else if (position > tmppos) {
  346. underline += input[tmppos] === '\t' ? '\t' : ' ';
  347. }
  348. // output no more than 78 characters on the string
  349. if (srcline.length > 78) break
  350. }
  351. return result + '\n' + srcline + '\n' + underline
  352. }
  353. function parse(input, options) {
  354. // parse as a standard JSON mode
  355. var json5 = !(options.mode === 'json' || options.legacy);
  356. var isLineTerminator = json5 ? unicode.isLineTerminator : unicode.isLineTerminatorJSON;
  357. var isWhiteSpace = json5 ? unicode.isWhiteSpace : unicode.isWhiteSpaceJSON;
  358. var length = input.length
  359. , lineno = 0
  360. , linestart = 0
  361. , position = 0
  362. , stack = [];
  363. var tokenStart = function() {};
  364. var tokenEnd = function(v) {return v};
  365. /* tokenize({
  366. raw: '...',
  367. type: 'whitespace'|'comment'|'key'|'literal'|'separator'|'newline',
  368. value: 'number'|'string'|'whatever',
  369. path: [...],
  370. })
  371. */
  372. if (options._tokenize) {
  373. (function() {
  374. var start = null;
  375. tokenStart = function() {
  376. if (start !== null) throw Error('internal error, token overlap')
  377. start = position;
  378. };
  379. tokenEnd = function(v, type) {
  380. if (start != position) {
  381. var hash = {
  382. raw: input.substr(start, position-start),
  383. type: type,
  384. stack: stack.slice(0),
  385. };
  386. if (v !== undefined) hash.value = v;
  387. options._tokenize.call(null, hash);
  388. }
  389. start = null;
  390. return v
  391. };
  392. })();
  393. }
  394. function fail(msg) {
  395. var column = position - linestart;
  396. if (!msg) {
  397. if (position < length) {
  398. var token = '\'' +
  399. JSON
  400. .stringify(input[position])
  401. .replace(/^"|"$/g, '')
  402. .replace(/'/g, "\\'")
  403. .replace(/\\"/g, '"')
  404. + '\'';
  405. if (!msg) msg = 'Unexpected token ' + token;
  406. } else {
  407. if (!msg) msg = 'Unexpected end of input';
  408. }
  409. }
  410. var error = SyntaxError(formatError(input, msg, position, lineno, column, json5));
  411. error.row = lineno + 1;
  412. error.column = column + 1;
  413. throw error
  414. }
  415. function newline(chr) {
  416. // account for <cr><lf>
  417. if (chr === '\r' && input[position] === '\n') position++;
  418. linestart = position;
  419. lineno++;
  420. }
  421. function parseGeneric() {
  422. var result;
  423. while (position < length) {
  424. tokenStart();
  425. var chr = input[position++];
  426. if (chr === '"' || (chr === '\'' && json5)) {
  427. return tokenEnd(parseString(chr), 'literal')
  428. } else if (chr === '{') {
  429. tokenEnd(undefined, 'separator');
  430. return parseObject()
  431. } else if (chr === '[') {
  432. tokenEnd(undefined, 'separator');
  433. return parseArray()
  434. } else if (chr === '-'
  435. || chr === '.'
  436. || isDecDigit(chr)
  437. // + number Infinity NaN
  438. || (json5 && (chr === '+' || chr === 'I' || chr === 'N'))
  439. ) {
  440. return tokenEnd(parseNumber(), 'literal')
  441. } else if (chr === 'n') {
  442. parseKeyword('null');
  443. return tokenEnd(null, 'literal')
  444. } else if (chr === 't') {
  445. parseKeyword('true');
  446. return tokenEnd(true, 'literal')
  447. } else if (chr === 'f') {
  448. parseKeyword('false');
  449. return tokenEnd(false, 'literal')
  450. } else {
  451. position--;
  452. return tokenEnd(undefined)
  453. }
  454. }
  455. }
  456. function parseKey() {
  457. var result;
  458. while (position < length) {
  459. tokenStart();
  460. var chr = input[position++];
  461. if (chr === '"' || (chr === '\'' && json5)) {
  462. return tokenEnd(parseString(chr), 'key')
  463. } else if (chr === '{') {
  464. tokenEnd(undefined, 'separator');
  465. return parseObject()
  466. } else if (chr === '[') {
  467. tokenEnd(undefined, 'separator');
  468. return parseArray()
  469. } else if (chr === '.'
  470. || isDecDigit(chr)
  471. ) {
  472. return tokenEnd(parseNumber(true), 'key')
  473. } else if (json5
  474. && unicode.isIdentifierStart(chr) || (chr === '\\' && input[position] === 'u')) {
  475. // unicode char or a unicode sequence
  476. var rollback = position - 1;
  477. var result = parseIdentifier();
  478. if (result === undefined) {
  479. position = rollback;
  480. return tokenEnd(undefined)
  481. } else {
  482. return tokenEnd(result, 'key')
  483. }
  484. } else {
  485. position--;
  486. return tokenEnd(undefined)
  487. }
  488. }
  489. }
  490. function skipWhiteSpace() {
  491. tokenStart();
  492. while (position < length) {
  493. var chr = input[position++];
  494. if (isLineTerminator(chr)) {
  495. position--;
  496. tokenEnd(undefined, 'whitespace');
  497. tokenStart();
  498. position++;
  499. newline(chr);
  500. tokenEnd(undefined, 'newline');
  501. tokenStart();
  502. } else if (isWhiteSpace(chr)) {
  503. // nothing
  504. } else if (chr === '/'
  505. && json5
  506. && (input[position] === '/' || input[position] === '*')
  507. ) {
  508. position--;
  509. tokenEnd(undefined, 'whitespace');
  510. tokenStart();
  511. position++;
  512. skipComment(input[position++] === '*');
  513. tokenEnd(undefined, 'comment');
  514. tokenStart();
  515. } else {
  516. position--;
  517. break
  518. }
  519. }
  520. return tokenEnd(undefined, 'whitespace')
  521. }
  522. function skipComment(multi) {
  523. while (position < length) {
  524. var chr = input[position++];
  525. if (isLineTerminator(chr)) {
  526. // LineTerminator is an end of singleline comment
  527. if (!multi) {
  528. // let parent function deal with newline
  529. position--;
  530. return
  531. }
  532. newline(chr);
  533. } else if (chr === '*' && multi) {
  534. // end of multiline comment
  535. if (input[position] === '/') {
  536. position++;
  537. return
  538. }
  539. } else {
  540. // nothing
  541. }
  542. }
  543. if (multi) {
  544. fail('Unclosed multiline comment');
  545. }
  546. }
  547. function parseKeyword(keyword) {
  548. // keyword[0] is not checked because it should've checked earlier
  549. var _pos = position;
  550. var len = keyword.length;
  551. for (var i=1; i<len; i++) {
  552. if (position >= length || keyword[i] != input[position]) {
  553. position = _pos-1;
  554. fail();
  555. }
  556. position++;
  557. }
  558. }
  559. function parseObject() {
  560. var result = options.null_prototype ? Object.create(null) : {}
  561. , empty_object = {}
  562. , is_non_empty = false;
  563. while (position < length) {
  564. skipWhiteSpace();
  565. var item1 = parseKey();
  566. skipWhiteSpace();
  567. tokenStart();
  568. var chr = input[position++];
  569. tokenEnd(undefined, 'separator');
  570. if (chr === '}' && item1 === undefined) {
  571. if (!json5 && is_non_empty) {
  572. position--;
  573. fail('Trailing comma in object');
  574. }
  575. return result
  576. } else if (chr === ':' && item1 !== undefined) {
  577. skipWhiteSpace();
  578. stack.push(item1);
  579. var item2 = parseGeneric();
  580. stack.pop();
  581. if (item2 === undefined) fail('No value found for key ' + item1);
  582. if (typeof(item1) !== 'string') {
  583. if (!json5 || typeof(item1) !== 'number') {
  584. fail('Wrong key type: ' + item1);
  585. }
  586. }
  587. if ((item1 in empty_object || empty_object[item1] != null) && options.reserved_keys !== 'replace') {
  588. if (options.reserved_keys === 'throw') {
  589. fail('Reserved key: ' + item1);
  590. } else {
  591. // silently ignore it
  592. }
  593. } else {
  594. if (typeof(options.reviver) === 'function') {
  595. item2 = options.reviver.call(null, item1, item2);
  596. }
  597. if (item2 !== undefined) {
  598. is_non_empty = true;
  599. Object.defineProperty(result, item1, {
  600. value: item2,
  601. enumerable: true,
  602. configurable: true,
  603. writable: true,
  604. });
  605. }
  606. }
  607. skipWhiteSpace();
  608. tokenStart();
  609. var chr = input[position++];
  610. tokenEnd(undefined, 'separator');
  611. if (chr === ',') {
  612. continue
  613. } else if (chr === '}') {
  614. return result
  615. } else {
  616. fail();
  617. }
  618. } else {
  619. position--;
  620. fail();
  621. }
  622. }
  623. fail();
  624. }
  625. function parseArray() {
  626. var result = [];
  627. while (position < length) {
  628. skipWhiteSpace();
  629. stack.push(result.length);
  630. var item = parseGeneric();
  631. stack.pop();
  632. skipWhiteSpace();
  633. tokenStart();
  634. var chr = input[position++];
  635. tokenEnd(undefined, 'separator');
  636. if (item !== undefined) {
  637. if (typeof(options.reviver) === 'function') {
  638. item = options.reviver.call(null, String(result.length), item);
  639. }
  640. if (item === undefined) {
  641. result.length++;
  642. item = true; // hack for check below, not included into result
  643. } else {
  644. result.push(item);
  645. }
  646. }
  647. if (chr === ',') {
  648. if (item === undefined) {
  649. fail('Elisions are not supported');
  650. }
  651. } else if (chr === ']') {
  652. if (!json5 && item === undefined && result.length) {
  653. position--;
  654. fail('Trailing comma in array');
  655. }
  656. return result
  657. } else {
  658. position--;
  659. fail();
  660. }
  661. }
  662. }
  663. function parseNumber() {
  664. // rewind because we don't know first char
  665. position--;
  666. var start = position
  667. , chr = input[position++]
  668. , t;
  669. var to_num = function(is_octal) {
  670. var str = input.substr(start, position - start);
  671. if (is_octal) {
  672. var result = parseInt(str.replace(/^0o?/, ''), 8);
  673. } else {
  674. var result = Number(str);
  675. }
  676. if (Number.isNaN(result)) {
  677. position--;
  678. fail('Bad numeric literal - "' + input.substr(start, position - start + 1) + '"');
  679. } else if (!json5 && !str.match(/^-?(0|[1-9][0-9]*)(\.[0-9]+)?(e[+-]?[0-9]+)?$/i)) {
  680. // additional restrictions imposed by json
  681. position--;
  682. fail('Non-json numeric literal - "' + input.substr(start, position - start + 1) + '"');
  683. } else {
  684. return result
  685. }
  686. };
  687. // ex: -5982475.249875e+29384
  688. // ^ skipping this
  689. if (chr === '-' || (chr === '+' && json5)) chr = input[position++];
  690. if (chr === 'N' && json5) {
  691. parseKeyword('NaN');
  692. return NaN
  693. }
  694. if (chr === 'I' && json5) {
  695. parseKeyword('Infinity');
  696. // returning +inf or -inf
  697. return to_num()
  698. }
  699. if (chr >= '1' && chr <= '9') {
  700. // ex: -5982475.249875e+29384
  701. // ^^^ skipping these
  702. while (position < length && isDecDigit(input[position])) position++;
  703. chr = input[position++];
  704. }
  705. // special case for leading zero: 0.123456
  706. if (chr === '0') {
  707. chr = input[position++];
  708. // new syntax, "0o777" old syntax, "0777"
  709. var is_octal = chr === 'o' || chr === 'O' || isOctDigit(chr);
  710. var is_hex = chr === 'x' || chr === 'X';
  711. if (json5 && (is_octal || is_hex)) {
  712. while (position < length
  713. && (is_hex ? isHexDigit : isOctDigit)( input[position] )
  714. ) position++;
  715. var sign = 1;
  716. if (input[start] === '-') {
  717. sign = -1;
  718. start++;
  719. } else if (input[start] === '+') {
  720. start++;
  721. }
  722. return sign * to_num(is_octal)
  723. }
  724. }
  725. if (chr === '.') {
  726. // ex: -5982475.249875e+29384
  727. // ^^^ skipping these
  728. while (position < length && isDecDigit(input[position])) position++;
  729. chr = input[position++];
  730. }
  731. if (chr === 'e' || chr === 'E') {
  732. chr = input[position++];
  733. if (chr === '-' || chr === '+') position++;
  734. // ex: -5982475.249875e+29384
  735. // ^^^ skipping these
  736. while (position < length && isDecDigit(input[position])) position++;
  737. chr = input[position++];
  738. }
  739. // we have char in the buffer, so count for it
  740. position--;
  741. return to_num()
  742. }
  743. function parseIdentifier() {
  744. // rewind because we don't know first char
  745. position--;
  746. var result = '';
  747. while (position < length) {
  748. var chr = input[position++];
  749. if (chr === '\\'
  750. && input[position] === 'u'
  751. && isHexDigit(input[position+1])
  752. && isHexDigit(input[position+2])
  753. && isHexDigit(input[position+3])
  754. && isHexDigit(input[position+4])
  755. ) {
  756. // UnicodeEscapeSequence
  757. chr = String.fromCharCode(parseInt(input.substr(position+1, 4), 16));
  758. position += 5;
  759. }
  760. if (result.length) {
  761. // identifier started
  762. if (unicode.isIdentifierPart(chr)) {
  763. result += chr;
  764. } else {
  765. position--;
  766. return result
  767. }
  768. } else {
  769. if (unicode.isIdentifierStart(chr)) {
  770. result += chr;
  771. } else {
  772. return undefined
  773. }
  774. }
  775. }
  776. fail();
  777. }
  778. function parseString(endChar) {
  779. // 7.8.4 of ES262 spec
  780. var result = '';
  781. while (position < length) {
  782. var chr = input[position++];
  783. if (chr === endChar) {
  784. return result
  785. } else if (chr === '\\') {
  786. if (position >= length) fail();
  787. chr = input[position++];
  788. if (unescapeMap[chr] && (json5 || (chr != 'v' && chr != "'"))) {
  789. result += unescapeMap[chr];
  790. } else if (json5 && isLineTerminator(chr)) {
  791. // line continuation
  792. newline(chr);
  793. } else if (chr === 'u' || (chr === 'x' && json5)) {
  794. // unicode/character escape sequence
  795. var off = chr === 'u' ? 4 : 2;
  796. // validation for \uXXXX
  797. for (var i=0; i<off; i++) {
  798. if (position >= length) fail();
  799. if (!isHexDigit(input[position])) fail('Bad escape sequence');
  800. position++;
  801. }
  802. result += String.fromCharCode(parseInt(input.substr(position-off, off), 16));
  803. } else if (json5 && isOctDigit(chr)) {
  804. if (chr < '4' && isOctDigit(input[position]) && isOctDigit(input[position+1])) {
  805. // three-digit octal
  806. var digits = 3;
  807. } else if (isOctDigit(input[position])) {
  808. // two-digit octal
  809. var digits = 2;
  810. } else {
  811. var digits = 1;
  812. }
  813. position += digits - 1;
  814. result += String.fromCharCode(parseInt(input.substr(position-digits, digits), 8));
  815. /*if (!isOctDigit(input[position])) {
  816. // \0 is allowed still
  817. result += '\0'
  818. } else {
  819. fail('Octal literals are not supported')
  820. }*/
  821. } else if (json5) {
  822. // \X -> x
  823. result += chr;
  824. } else {
  825. position--;
  826. fail();
  827. }
  828. } else if (isLineTerminator(chr)) {
  829. fail();
  830. } else {
  831. if (!json5 && chr.charCodeAt(0) < 32) {
  832. position--;
  833. fail('Unexpected control character');
  834. }
  835. // SourceCharacter but not one of " or \ or LineTerminator
  836. result += chr;
  837. }
  838. }
  839. fail();
  840. }
  841. skipWhiteSpace();
  842. var return_value = parseGeneric();
  843. if (return_value !== undefined || position < length) {
  844. skipWhiteSpace();
  845. if (position >= length) {
  846. if (typeof(options.reviver) === 'function') {
  847. return_value = options.reviver.call(null, '', return_value);
  848. }
  849. return return_value
  850. } else {
  851. fail();
  852. }
  853. } else {
  854. if (position) {
  855. fail('No data, only a whitespace');
  856. } else {
  857. fail('No data, empty input');
  858. }
  859. }
  860. }
  861. /*
  862. * parse(text, options)
  863. * or
  864. * parse(text, reviver)
  865. *
  866. * where:
  867. * text - string
  868. * options - object
  869. * reviver - function
  870. */
  871. module.exports.parse = function parseJSON(input, options) {
  872. // support legacy functions
  873. if (typeof(options) === 'function') {
  874. options = {
  875. reviver: options
  876. };
  877. }
  878. if (input === undefined) {
  879. // parse(stringify(x)) should be equal x
  880. // with JSON functions it is not 'cause of undefined
  881. // so we're fixing it
  882. return undefined
  883. }
  884. // JSON.parse compat
  885. if (typeof(input) !== 'string') input = String(input);
  886. if (options == null) options = {};
  887. if (options.reserved_keys == null) options.reserved_keys = 'ignore';
  888. if (options.reserved_keys === 'throw' || options.reserved_keys === 'ignore') {
  889. if (options.null_prototype == null) {
  890. options.null_prototype = true;
  891. }
  892. }
  893. try {
  894. return parse(input, options)
  895. } catch(err) {
  896. // jju is a recursive parser, so JSON.parse("{{{{{{{") could blow up the stack
  897. //
  898. // this catch is used to skip all those internal calls
  899. if (err instanceof SyntaxError && err.row != null && err.column != null) {
  900. var old_err = err;
  901. err = SyntaxError(old_err.message);
  902. err.column = old_err.column;
  903. err.row = old_err.row;
  904. }
  905. throw err
  906. }
  907. };
  908. module.exports.tokenize = function tokenizeJSON(input, options) {
  909. if (options == null) options = {};
  910. options._tokenize = function(smth) {
  911. if (options._addstack) smth.stack.unshift.apply(smth.stack, options._addstack);
  912. tokens.push(smth);
  913. };
  914. var tokens = [];
  915. tokens.data = module.exports.parse(input, options);
  916. return tokens
  917. };
  918. });
  919. var parseJson = createCommonjsModule(function (module) {
  920. 'use strict';
  921. function appendPosition(message) {
  922. const posRe = / at (\d+:\d+) in/;
  923. const numbers = posRe.exec(message);
  924. return message.replace(posRe, ' in') + ':' + numbers[1];
  925. }
  926. const JSONError = errorEx_1('JSONError', {
  927. fileName: errorEx_1.append('in %s'),
  928. appendPosition: {
  929. message: (shouldAppend, original) => {
  930. if (shouldAppend) {
  931. original[0] = appendPosition(original[0]);
  932. }
  933. return original;
  934. }
  935. }
  936. });
  937. module.exports = (input, reviver, filename) => {
  938. if (typeof reviver === 'string') {
  939. filename = reviver;
  940. reviver = null;
  941. }
  942. try {
  943. try {
  944. return JSON.parse(input, reviver);
  945. } catch (err) {
  946. parse_1.parse(input, {
  947. mode: 'json',
  948. reviver
  949. });
  950. throw err;
  951. }
  952. } catch (err) {
  953. const jsonErr = new JSONError(err);
  954. if (filename) {
  955. jsonErr.fileName = filename;
  956. jsonErr.appendPosition = true;
  957. }
  958. throw jsonErr;
  959. }
  960. };
  961. });
  962. var parseJson_1 = function parseJsonWrapper(
  963. json ,
  964. filepath
  965. ) {
  966. try {
  967. return parseJson(json);
  968. } catch (err) {
  969. err.message = `JSON Error in ${filepath}:\n${err.message}`;
  970. throw err;
  971. }
  972. };
  973. var loadPackageProp = function loadPackageProp(
  974. packageDir ,
  975. options
  976. ) {
  977. const packagePath = path.join(packageDir, 'package.json');
  978. function parseContent(content ) {
  979. if (!content) return null;
  980. const parsedContent = parseJson_1(content, packagePath);
  981. const packagePropValue = parsedContent[options.packageProp];
  982. if (!packagePropValue) return null;
  983. return {
  984. config: packagePropValue,
  985. filepath: packagePath,
  986. };
  987. }
  988. return !options.sync
  989. ? readFile_1(packagePath).then(parseContent)
  990. : parseContent(readFile_1.sync(packagePath));
  991. };
  992. function isNothing(subject) {
  993. return (typeof subject === 'undefined') || (subject === null);
  994. }
  995. function isObject(subject) {
  996. return (typeof subject === 'object') && (subject !== null);
  997. }
  998. function toArray(sequence) {
  999. if (Array.isArray(sequence)) return sequence;
  1000. else if (isNothing(sequence)) return [];
  1001. return [ sequence ];
  1002. }
  1003. function extend(target, source) {
  1004. var index, length, key, sourceKeys;
  1005. if (source) {
  1006. sourceKeys = Object.keys(source);
  1007. for (index = 0, length = sourceKeys.length; index < length; index += 1) {
  1008. key = sourceKeys[index];
  1009. target[key] = source[key];
  1010. }
  1011. }
  1012. return target;
  1013. }
  1014. function repeat(string, count) {
  1015. var result = '', cycle;
  1016. for (cycle = 0; cycle < count; cycle += 1) {
  1017. result += string;
  1018. }
  1019. return result;
  1020. }
  1021. function isNegativeZero(number) {
  1022. return (number === 0) && (Number.NEGATIVE_INFINITY === 1 / number);
  1023. }
  1024. var isNothing_1 = isNothing;
  1025. var isObject_1 = isObject;
  1026. var toArray_1 = toArray;
  1027. var repeat_1 = repeat;
  1028. var isNegativeZero_1 = isNegativeZero;
  1029. var extend_1 = extend;
  1030. var common = {
  1031. isNothing: isNothing_1,
  1032. isObject: isObject_1,
  1033. toArray: toArray_1,
  1034. repeat: repeat_1,
  1035. isNegativeZero: isNegativeZero_1,
  1036. extend: extend_1
  1037. };
  1038. // YAML error class. http://stackoverflow.com/questions/8458984
  1039. //
  1040. function YAMLException$1(reason, mark) {
  1041. // Super constructor
  1042. Error.call(this);
  1043. this.name = 'YAMLException';
  1044. this.reason = reason;
  1045. this.mark = mark;
  1046. this.message = (this.reason || '(unknown reason)') + (this.mark ? ' ' + this.mark.toString() : '');
  1047. // Include stack trace in error object
  1048. if (Error.captureStackTrace) {
  1049. // Chrome and NodeJS
  1050. Error.captureStackTrace(this, this.constructor);
  1051. } else {
  1052. // FF, IE 10+ and Safari 6+. Fallback for others
  1053. this.stack = (new Error()).stack || '';
  1054. }
  1055. }
  1056. // Inherit from Error
  1057. YAMLException$1.prototype = Object.create(Error.prototype);
  1058. YAMLException$1.prototype.constructor = YAMLException$1;
  1059. YAMLException$1.prototype.toString = function toString(compact) {
  1060. var result = this.name + ': ';
  1061. result += this.reason || '(unknown reason)';
  1062. if (!compact && this.mark) {
  1063. result += ' ' + this.mark.toString();
  1064. }
  1065. return result;
  1066. };
  1067. var exception = YAMLException$1;
  1068. function Mark(name, buffer, position, line, column) {
  1069. this.name = name;
  1070. this.buffer = buffer;
  1071. this.position = position;
  1072. this.line = line;
  1073. this.column = column;
  1074. }
  1075. Mark.prototype.getSnippet = function getSnippet(indent, maxLength) {
  1076. var head, start, tail, end, snippet;
  1077. if (!this.buffer) return null;
  1078. indent = indent || 4;
  1079. maxLength = maxLength || 75;
  1080. head = '';
  1081. start = this.position;
  1082. while (start > 0 && '\x00\r\n\x85\u2028\u2029'.indexOf(this.buffer.charAt(start - 1)) === -1) {
  1083. start -= 1;
  1084. if (this.position - start > (maxLength / 2 - 1)) {
  1085. head = ' ... ';
  1086. start += 5;
  1087. break;
  1088. }
  1089. }
  1090. tail = '';
  1091. end = this.position;
  1092. while (end < this.buffer.length && '\x00\r\n\x85\u2028\u2029'.indexOf(this.buffer.charAt(end)) === -1) {
  1093. end += 1;
  1094. if (end - this.position > (maxLength / 2 - 1)) {
  1095. tail = ' ... ';
  1096. end -= 5;
  1097. break;
  1098. }
  1099. }
  1100. snippet = this.buffer.slice(start, end);
  1101. return common.repeat(' ', indent) + head + snippet + tail + '\n' +
  1102. common.repeat(' ', indent + this.position - start + head.length) + '^';
  1103. };
  1104. Mark.prototype.toString = function toString(compact) {
  1105. var snippet, where = '';
  1106. if (this.name) {
  1107. where += 'in "' + this.name + '" ';
  1108. }
  1109. where += 'at line ' + (this.line + 1) + ', column ' + (this.column + 1);
  1110. if (!compact) {
  1111. snippet = this.getSnippet();
  1112. if (snippet) {
  1113. where += ':\n' + snippet;
  1114. }
  1115. }
  1116. return where;
  1117. };
  1118. var mark = Mark;
  1119. var TYPE_CONSTRUCTOR_OPTIONS = [
  1120. 'kind',
  1121. 'resolve',
  1122. 'construct',
  1123. 'instanceOf',
  1124. 'predicate',
  1125. 'represent',
  1126. 'defaultStyle',
  1127. 'styleAliases'
  1128. ];
  1129. var YAML_NODE_KINDS = [
  1130. 'scalar',
  1131. 'sequence',
  1132. 'mapping'
  1133. ];
  1134. function compileStyleAliases(map) {
  1135. var result = {};
  1136. if (map !== null) {
  1137. Object.keys(map).forEach(function (style) {
  1138. map[style].forEach(function (alias) {
  1139. result[String(alias)] = style;
  1140. });
  1141. });
  1142. }
  1143. return result;
  1144. }
  1145. function Type$1(tag, options) {
  1146. options = options || {};
  1147. Object.keys(options).forEach(function (name) {
  1148. if (TYPE_CONSTRUCTOR_OPTIONS.indexOf(name) === -1) {
  1149. throw new exception('Unknown option "' + name + '" is met in definition of "' + tag + '" YAML type.');
  1150. }
  1151. });
  1152. // TODO: Add tag format check.
  1153. this.tag = tag;
  1154. this.kind = options['kind'] || null;
  1155. this.resolve = options['resolve'] || function () { return true; };
  1156. this.construct = options['construct'] || function (data) { return data; };
  1157. this.instanceOf = options['instanceOf'] || null;
  1158. this.predicate = options['predicate'] || null;
  1159. this.represent = options['represent'] || null;
  1160. this.defaultStyle = options['defaultStyle'] || null;
  1161. this.styleAliases = compileStyleAliases(options['styleAliases'] || null);
  1162. if (YAML_NODE_KINDS.indexOf(this.kind) === -1) {
  1163. throw new exception('Unknown kind "' + this.kind + '" is specified for "' + tag + '" YAML type.');
  1164. }
  1165. }
  1166. var type = Type$1;
  1167. /*eslint-disable max-len*/
  1168. function compileList(schema, name, result) {
  1169. var exclude = [];
  1170. schema.include.forEach(function (includedSchema) {
  1171. result = compileList(includedSchema, name, result);
  1172. });
  1173. schema[name].forEach(function (currentType) {
  1174. result.forEach(function (previousType, previousIndex) {
  1175. if (previousType.tag === currentType.tag && previousType.kind === currentType.kind) {
  1176. exclude.push(previousIndex);
  1177. }
  1178. });
  1179. result.push(currentType);
  1180. });
  1181. return result.filter(function (type$$1, index) {
  1182. return exclude.indexOf(index) === -1;
  1183. });
  1184. }
  1185. function compileMap(/* lists... */) {
  1186. var result = {
  1187. scalar: {},
  1188. sequence: {},
  1189. mapping: {},
  1190. fallback: {}
  1191. }, index, length;
  1192. function collectType(type$$1) {
  1193. result[type$$1.kind][type$$1.tag] = result['fallback'][type$$1.tag] = type$$1;
  1194. }
  1195. for (index = 0, length = arguments.length; index < length; index += 1) {
  1196. arguments[index].forEach(collectType);
  1197. }
  1198. return result;
  1199. }
  1200. function Schema$1(definition) {
  1201. this.include = definition.include || [];
  1202. this.implicit = definition.implicit || [];
  1203. this.explicit = definition.explicit || [];
  1204. this.implicit.forEach(function (type$$1) {
  1205. if (type$$1.loadKind && type$$1.loadKind !== 'scalar') {
  1206. throw new exception('There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.');
  1207. }
  1208. });
  1209. this.compiledImplicit = compileList(this, 'implicit', []);
  1210. this.compiledExplicit = compileList(this, 'explicit', []);
  1211. this.compiledTypeMap = compileMap(this.compiledImplicit, this.compiledExplicit);
  1212. }
  1213. Schema$1.DEFAULT = null;
  1214. Schema$1.create = function createSchema() {
  1215. var schemas, types;
  1216. switch (arguments.length) {
  1217. case 1:
  1218. schemas = Schema$1.DEFAULT;
  1219. types = arguments[0];
  1220. break;
  1221. case 2:
  1222. schemas = arguments[0];
  1223. types = arguments[1];
  1224. break;
  1225. default:
  1226. throw new exception('Wrong number of arguments for Schema.create function');
  1227. }
  1228. schemas = common.toArray(schemas);
  1229. types = common.toArray(types);
  1230. if (!schemas.every(function (schema) { return schema instanceof Schema$1; })) {
  1231. throw new exception('Specified list of super schemas (or a single Schema object) contains a non-Schema object.');
  1232. }
  1233. if (!types.every(function (type$$1) { return type$$1 instanceof type; })) {
  1234. throw new exception('Specified list of YAML types (or a single Type object) contains a non-Type object.');
  1235. }
  1236. return new Schema$1({
  1237. include: schemas,
  1238. explicit: types
  1239. });
  1240. };
  1241. var schema = Schema$1;
  1242. var str = new type('tag:yaml.org,2002:str', {
  1243. kind: 'scalar',
  1244. construct: function (data) { return data !== null ? data : ''; }
  1245. });
  1246. var seq = new type('tag:yaml.org,2002:seq', {
  1247. kind: 'sequence',
  1248. construct: function (data) { return data !== null ? data : []; }
  1249. });
  1250. var map = new type('tag:yaml.org,2002:map', {
  1251. kind: 'mapping',
  1252. construct: function (data) { return data !== null ? data : {}; }
  1253. });
  1254. var failsafe = new schema({
  1255. explicit: [
  1256. str,
  1257. seq,
  1258. map
  1259. ]
  1260. });
  1261. function resolveYamlNull(data) {
  1262. if (data === null) return true;
  1263. var max = data.length;
  1264. return (max === 1 && data === '~') ||
  1265. (max === 4 && (data === 'null' || data === 'Null' || data === 'NULL'));
  1266. }
  1267. function constructYamlNull() {
  1268. return null;
  1269. }
  1270. function isNull(object) {
  1271. return object === null;
  1272. }
  1273. var _null = new type('tag:yaml.org,2002:null', {
  1274. kind: 'scalar',
  1275. resolve: resolveYamlNull,
  1276. construct: constructYamlNull,
  1277. predicate: isNull,
  1278. represent: {
  1279. canonical: function () { return '~'; },
  1280. lowercase: function () { return 'null'; },
  1281. uppercase: function () { return 'NULL'; },
  1282. camelcase: function () { return 'Null'; }
  1283. },
  1284. defaultStyle: 'lowercase'
  1285. });
  1286. function resolveYamlBoolean(data) {
  1287. if (data === null) return false;
  1288. var max = data.length;
  1289. return (max === 4 && (data === 'true' || data === 'True' || data === 'TRUE')) ||
  1290. (max === 5 && (data === 'false' || data === 'False' || data === 'FALSE'));
  1291. }
  1292. function constructYamlBoolean(data) {
  1293. return data === 'true' ||
  1294. data === 'True' ||
  1295. data === 'TRUE';
  1296. }
  1297. function isBoolean(object) {
  1298. return Object.prototype.toString.call(object) === '[object Boolean]';
  1299. }
  1300. var bool = new type('tag:yaml.org,2002:bool', {
  1301. kind: 'scalar',
  1302. resolve: resolveYamlBoolean,
  1303. construct: constructYamlBoolean,
  1304. predicate: isBoolean,
  1305. represent: {
  1306. lowercase: function (object) { return object ? 'true' : 'false'; },
  1307. uppercase: function (object) { return object ? 'TRUE' : 'FALSE'; },
  1308. camelcase: function (object) { return object ? 'True' : 'False'; }
  1309. },
  1310. defaultStyle: 'lowercase'
  1311. });
  1312. function isHexCode(c) {
  1313. return ((0x30/* 0 */ <= c) && (c <= 0x39/* 9 */)) ||
  1314. ((0x41/* A */ <= c) && (c <= 0x46/* F */)) ||
  1315. ((0x61/* a */ <= c) && (c <= 0x66/* f */));
  1316. }
  1317. function isOctCode(c) {
  1318. return ((0x30/* 0 */ <= c) && (c <= 0x37/* 7 */));
  1319. }
  1320. function isDecCode(c) {
  1321. return ((0x30/* 0 */ <= c) && (c <= 0x39/* 9 */));
  1322. }
  1323. function resolveYamlInteger(data) {
  1324. if (data === null) return false;
  1325. var max = data.length,
  1326. index = 0,
  1327. hasDigits = false,
  1328. ch;
  1329. if (!max) return false;
  1330. ch = data[index];
  1331. // sign
  1332. if (ch === '-' || ch === '+') {
  1333. ch = data[++index];
  1334. }
  1335. if (ch === '0') {
  1336. // 0
  1337. if (index + 1 === max) return true;
  1338. ch = data[++index];
  1339. // base 2, base 8, base 16
  1340. if (ch === 'b') {
  1341. // base 2
  1342. index++;
  1343. for (; index < max; index++) {
  1344. ch = data[index];
  1345. if (ch === '_') continue;
  1346. if (ch !== '0' && ch !== '1') return false;
  1347. hasDigits = true;
  1348. }
  1349. return hasDigits && ch !== '_';
  1350. }
  1351. if (ch === 'x') {
  1352. // base 16
  1353. index++;
  1354. for (; index < max; index++) {
  1355. ch = data[index];
  1356. if (ch === '_') continue;
  1357. if (!isHexCode(data.charCodeAt(index))) return false;
  1358. hasDigits = true;
  1359. }
  1360. return hasDigits && ch !== '_';
  1361. }
  1362. // base 8
  1363. for (; index < max; index++) {
  1364. ch = data[index];
  1365. if (ch === '_') continue;
  1366. if (!isOctCode(data.charCodeAt(index))) return false;
  1367. hasDigits = true;
  1368. }
  1369. return hasDigits && ch !== '_';
  1370. }
  1371. // base 10 (except 0) or base 60
  1372. // value should not start with `_`;
  1373. if (ch === '_') return false;
  1374. for (; index < max; index++) {
  1375. ch = data[index];
  1376. if (ch === '_') continue;
  1377. if (ch === ':') break;
  1378. if (!isDecCode(data.charCodeAt(index))) {
  1379. return false;
  1380. }
  1381. hasDigits = true;
  1382. }
  1383. // Should have digits and should not end with `_`
  1384. if (!hasDigits || ch === '_') return false;
  1385. // if !base60 - done;
  1386. if (ch !== ':') return true;
  1387. // base60 almost not used, no needs to optimize
  1388. return /^(:[0-5]?[0-9])+$/.test(data.slice(index));
  1389. }
  1390. function constructYamlInteger(data) {
  1391. var value = data, sign = 1, ch, base, digits = [];
  1392. if (value.indexOf('_') !== -1) {
  1393. value = value.replace(/_/g, '');
  1394. }
  1395. ch = value[0];
  1396. if (ch === '-' || ch === '+') {
  1397. if (ch === '-') sign = -1;
  1398. value = value.slice(1);
  1399. ch = value[0];
  1400. }
  1401. if (value === '0') return 0;
  1402. if (ch === '0') {
  1403. if (value[1] === 'b') return sign * parseInt(value.slice(2), 2);
  1404. if (value[1] === 'x') return sign * parseInt(value, 16);
  1405. return sign * parseInt(value, 8);
  1406. }
  1407. if (value.indexOf(':') !== -1) {
  1408. value.split(':').forEach(function (v) {
  1409. digits.unshift(parseInt(v, 10));
  1410. });
  1411. value = 0;
  1412. base = 1;
  1413. digits.forEach(function (d) {
  1414. value += (d * base);
  1415. base *= 60;
  1416. });
  1417. return sign * value;
  1418. }
  1419. return sign * parseInt(value, 10);
  1420. }
  1421. function isInteger(object) {
  1422. return (Object.prototype.toString.call(object)) === '[object Number]' &&
  1423. (object % 1 === 0 && !common.isNegativeZero(object));
  1424. }
  1425. var int_1 = new type('tag:yaml.org,2002:int', {
  1426. kind: 'scalar',
  1427. resolve: resolveYamlInteger,
  1428. construct: constructYamlInteger,
  1429. predicate: isInteger,
  1430. represent: {
  1431. binary: function (object) { return '0b' + object.toString(2); },
  1432. octal: function (object) { return '0' + object.toString(8); },
  1433. decimal: function (object) { return object.toString(10); },
  1434. hexadecimal: function (object) { return '0x' + object.toString(16).toUpperCase(); }
  1435. },
  1436. defaultStyle: 'decimal',
  1437. styleAliases: {
  1438. binary: [ 2, 'bin' ],
  1439. octal: [ 8, 'oct' ],
  1440. decimal: [ 10, 'dec' ],
  1441. hexadecimal: [ 16, 'hex' ]
  1442. }
  1443. });
  1444. var YAML_FLOAT_PATTERN = new RegExp(
  1445. // 2.5e4, 2.5 and integers
  1446. '^(?:[-+]?(?:0|[1-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?' +
  1447. // .2e4, .2
  1448. // special case, seems not from spec
  1449. '|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?' +
  1450. // 20:59
  1451. '|[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]*' +
  1452. // .inf
  1453. '|[-+]?\\.(?:inf|Inf|INF)' +
  1454. // .nan
  1455. '|\\.(?:nan|NaN|NAN))$');
  1456. function resolveYamlFloat(data) {
  1457. if (data === null) return false;
  1458. if (!YAML_FLOAT_PATTERN.test(data) ||
  1459. // Quick hack to not allow integers end with `_`
  1460. // Probably should update regexp & check speed
  1461. data[data.length - 1] === '_') {
  1462. return false;
  1463. }
  1464. return true;
  1465. }
  1466. function constructYamlFloat(data) {
  1467. var value, sign, base, digits;
  1468. value = data.replace(/_/g, '').toLowerCase();
  1469. sign = value[0] === '-' ? -1 : 1;
  1470. digits = [];
  1471. if ('+-'.indexOf(value[0]) >= 0) {
  1472. value = value.slice(1);
  1473. }
  1474. if (value === '.inf') {
  1475. return (sign === 1) ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
  1476. } else if (value === '.nan') {
  1477. return NaN;
  1478. } else if (value.indexOf(':') >= 0) {
  1479. value.split(':').forEach(function (v) {
  1480. digits.unshift(parseFloat(v, 10));
  1481. });
  1482. value = 0.0;
  1483. base = 1;
  1484. digits.forEach(function (d) {
  1485. value += d * base;
  1486. base *= 60;
  1487. });
  1488. return sign * value;
  1489. }
  1490. return sign * parseFloat(value, 10);
  1491. }
  1492. var SCIENTIFIC_WITHOUT_DOT = /^[-+]?[0-9]+e/;
  1493. function representYamlFloat(object, style) {
  1494. var res;
  1495. if (isNaN(object)) {
  1496. switch (style) {
  1497. case 'lowercase': return '.nan';
  1498. case 'uppercase': return '.NAN';
  1499. case 'camelcase': return '.NaN';
  1500. }
  1501. } else if (Number.POSITIVE_INFINITY === object) {
  1502. switch (style) {
  1503. case 'lowercase': return '.inf';
  1504. case 'uppercase': return '.INF';
  1505. case 'camelcase': return '.Inf';
  1506. }
  1507. } else if (Number.NEGATIVE_INFINITY === object) {
  1508. switch (style) {
  1509. case 'lowercase': return '-.inf';
  1510. case 'uppercase': return '-.INF';
  1511. case 'camelcase': return '-.Inf';
  1512. }
  1513. } else if (common.isNegativeZero(object)) {
  1514. return '-0.0';
  1515. }
  1516. res = object.toString(10);
  1517. // JS stringifier can build scientific format without dots: 5e-100,
  1518. // while YAML requres dot: 5.e-100. Fix it with simple hack
  1519. return SCIENTIFIC_WITHOUT_DOT.test(res) ? res.replace('e', '.e') : res;
  1520. }
  1521. function isFloat(object) {
  1522. return (Object.prototype.toString.call(object) === '[object Number]') &&
  1523. (object % 1 !== 0 || common.isNegativeZero(object));
  1524. }
  1525. var float_1 = new type('tag:yaml.org,2002:float', {
  1526. kind: 'scalar',
  1527. resolve: resolveYamlFloat,
  1528. construct: constructYamlFloat,
  1529. predicate: isFloat,
  1530. represent: representYamlFloat,
  1531. defaultStyle: 'lowercase'
  1532. });
  1533. var json = new schema({
  1534. include: [
  1535. failsafe
  1536. ],
  1537. implicit: [
  1538. _null,
  1539. bool,
  1540. int_1,
  1541. float_1
  1542. ]
  1543. });
  1544. var core = new schema({
  1545. include: [
  1546. json
  1547. ]
  1548. });
  1549. var YAML_DATE_REGEXP = new RegExp(
  1550. '^([0-9][0-9][0-9][0-9])' + // [1] year
  1551. '-([0-9][0-9])' + // [2] month
  1552. '-([0-9][0-9])$'); // [3] day
  1553. var YAML_TIMESTAMP_REGEXP = new RegExp(
  1554. '^([0-9][0-9][0-9][0-9])' + // [1] year
  1555. '-([0-9][0-9]?)' + // [2] month
  1556. '-([0-9][0-9]?)' + // [3] day
  1557. '(?:[Tt]|[ \\t]+)' + // ...
  1558. '([0-9][0-9]?)' + // [4] hour
  1559. ':([0-9][0-9])' + // [5] minute
  1560. ':([0-9][0-9])' + // [6] second
  1561. '(?:\\.([0-9]*))?' + // [7] fraction
  1562. '(?:[ \\t]*(Z|([-+])([0-9][0-9]?)' + // [8] tz [9] tz_sign [10] tz_hour
  1563. '(?::([0-9][0-9]))?))?$'); // [11] tz_minute
  1564. function resolveYamlTimestamp(data) {
  1565. if (data === null) return false;
  1566. if (YAML_DATE_REGEXP.exec(data) !== null) return true;
  1567. if (YAML_TIMESTAMP_REGEXP.exec(data) !== null) return true;
  1568. return false;
  1569. }
  1570. function constructYamlTimestamp(data) {
  1571. var match, year, month, day, hour, minute, second, fraction = 0,
  1572. delta = null, tz_hour, tz_minute, date;
  1573. match = YAML_DATE_REGEXP.exec(data);
  1574. if (match === null) match = YAML_TIMESTAMP_REGEXP.exec(data);
  1575. if (match === null) throw new Error('Date resolve error');
  1576. // match: [1] year [2] month [3] day
  1577. year = +(match[1]);
  1578. month = +(match[2]) - 1; // JS month starts with 0
  1579. day = +(match[3]);
  1580. if (!match[4]) { // no hour
  1581. return new Date(Date.UTC(year, month, day));
  1582. }
  1583. // match: [4] hour [5] minute [6] second [7] fraction
  1584. hour = +(match[4]);
  1585. minute = +(match[5]);
  1586. second = +(match[6]);
  1587. if (match[7]) {
  1588. fraction = match[7].slice(0, 3);
  1589. while (fraction.length < 3) { // milli-seconds
  1590. fraction += '0';
  1591. }
  1592. fraction = +fraction;
  1593. }
  1594. // match: [8] tz [9] tz_sign [10] tz_hour [11] tz_minute
  1595. if (match[9]) {
  1596. tz_hour = +(match[10]);
  1597. tz_minute = +(match[11] || 0);
  1598. delta = (tz_hour * 60 + tz_minute) * 60000; // delta in mili-seconds
  1599. if (match[9] === '-') delta = -delta;
  1600. }
  1601. date = new Date(Date.UTC(year, month, day, hour, minute, second, fraction));
  1602. if (delta) date.setTime(date.getTime() - delta);
  1603. return date;
  1604. }
  1605. function representYamlTimestamp(object /*, style*/) {
  1606. return object.toISOString();
  1607. }
  1608. var timestamp = new type('tag:yaml.org,2002:timestamp', {
  1609. kind: 'scalar',
  1610. resolve: resolveYamlTimestamp,
  1611. construct: constructYamlTimestamp,
  1612. instanceOf: Date,
  1613. represent: representYamlTimestamp
  1614. });
  1615. function resolveYamlMerge(data) {
  1616. return data === '<<' || data === null;
  1617. }
  1618. var merge = new type('tag:yaml.org,2002:merge', {
  1619. kind: 'scalar',
  1620. resolve: resolveYamlMerge
  1621. });
  1622. /*eslint-disable no-bitwise*/
  1623. var NodeBuffer;
  1624. try {
  1625. // A trick for browserified version, to not include `Buffer` shim
  1626. var _require = commonjsRequire;
  1627. NodeBuffer = _require('buffer').Buffer;
  1628. } catch (__) {}
  1629. // [ 64, 65, 66 ] -> [ padding, CR, LF ]
  1630. var BASE64_MAP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\n\r';
  1631. function resolveYamlBinary(data) {
  1632. if (data === null) return false;
  1633. var code, idx, bitlen = 0, max = data.length, map = BASE64_MAP;
  1634. // Convert one by one.
  1635. for (idx = 0; idx < max; idx++) {
  1636. code = map.indexOf(data.charAt(idx));
  1637. // Skip CR/LF
  1638. if (code > 64) continue;
  1639. // Fail on illegal characters
  1640. if (code < 0) return false;
  1641. bitlen += 6;
  1642. }
  1643. // If there are any bits left, source was corrupted
  1644. return (bitlen % 8) === 0;
  1645. }
  1646. function constructYamlBinary(data) {
  1647. var idx, tailbits,
  1648. input = data.replace(/[\r\n=]/g, ''), // remove CR/LF & padding to simplify scan
  1649. max = input.length,
  1650. map = BASE64_MAP,
  1651. bits = 0,
  1652. result = [];
  1653. // Collect by 6*4 bits (3 bytes)
  1654. for (idx = 0; idx < max; idx++) {
  1655. if ((idx % 4 === 0) && idx) {
  1656. result.push((bits >> 16) & 0xFF);
  1657. result.push((bits >> 8) & 0xFF);
  1658. result.push(bits & 0xFF);
  1659. }
  1660. bits = (bits << 6) | map.indexOf(input.charAt(idx));
  1661. }
  1662. // Dump tail
  1663. tailbits = (max % 4) * 6;
  1664. if (tailbits === 0) {
  1665. result.push((bits >> 16) & 0xFF);
  1666. result.push((bits >> 8) & 0xFF);
  1667. result.push(bits & 0xFF);
  1668. } else if (tailbits === 18) {
  1669. result.push((bits >> 10) & 0xFF);
  1670. result.push((bits >> 2) & 0xFF);
  1671. } else if (tailbits === 12) {
  1672. result.push((bits >> 4) & 0xFF);
  1673. }
  1674. // Wrap into Buffer for NodeJS and leave Array for browser
  1675. if (NodeBuffer) {
  1676. // Support node 6.+ Buffer API when available
  1677. return NodeBuffer.from ? NodeBuffer.from(result) : new NodeBuffer(result);
  1678. }
  1679. return result;
  1680. }
  1681. function representYamlBinary(object /*, style*/) {
  1682. var result = '', bits = 0, idx, tail,
  1683. max = object.length,
  1684. map = BASE64_MAP;
  1685. // Convert every three bytes to 4 ASCII characters.
  1686. for (idx = 0; idx < max; idx++) {
  1687. if ((idx % 3 === 0) && idx) {
  1688. result += map[(bits >> 18) & 0x3F];
  1689. result += map[(bits >> 12) & 0x3F];
  1690. result += map[(bits >> 6) & 0x3F];
  1691. result += map[bits & 0x3F];
  1692. }
  1693. bits = (bits << 8) + object[idx];
  1694. }
  1695. // Dump tail
  1696. tail = max % 3;
  1697. if (tail === 0) {
  1698. result += map[(bits >> 18) & 0x3F];
  1699. result += map[(bits >> 12) & 0x3F];
  1700. result += map[(bits >> 6) & 0x3F];
  1701. result += map[bits & 0x3F];
  1702. } else if (tail === 2) {
  1703. result += map[(bits >> 10) & 0x3F];
  1704. result += map[(bits >> 4) & 0x3F];
  1705. result += map[(bits << 2) & 0x3F];
  1706. result += map[64];
  1707. } else if (tail === 1) {
  1708. result += map[(bits >> 2) & 0x3F];
  1709. result += map[(bits << 4) & 0x3F];
  1710. result += map[64];
  1711. result += map[64];
  1712. }
  1713. return result;
  1714. }
  1715. function isBinary(object) {
  1716. return NodeBuffer && NodeBuffer.isBuffer(object);
  1717. }
  1718. var binary = new type('tag:yaml.org,2002:binary', {
  1719. kind: 'scalar',
  1720. resolve: resolveYamlBinary,
  1721. construct: constructYamlBinary,
  1722. predicate: isBinary,
  1723. represent: representYamlBinary
  1724. });
  1725. var _hasOwnProperty$1 = Object.prototype.hasOwnProperty;
  1726. var _toString = Object.prototype.toString;
  1727. function resolveYamlOmap(data) {
  1728. if (data === null) return true;
  1729. var objectKeys = [], index, length, pair, pairKey, pairHasKey,
  1730. object = data;
  1731. for (index = 0, length = object.length; index < length; index += 1) {
  1732. pair = object[index];
  1733. pairHasKey = false;
  1734. if (_toString.call(pair) !== '[object Object]') return false;
  1735. for (pairKey in pair) {
  1736. if (_hasOwnProperty$1.call(pair, pairKey)) {
  1737. if (!pairHasKey) pairHasKey = true;
  1738. else return false;
  1739. }
  1740. }
  1741. if (!pairHasKey) return false;
  1742. if (objectKeys.indexOf(pairKey) === -1) objectKeys.push(pairKey);
  1743. else return false;
  1744. }
  1745. return true;
  1746. }
  1747. function constructYamlOmap(data) {
  1748. return data !== null ? data : [];
  1749. }
  1750. var omap = new type('tag:yaml.org,2002:omap', {
  1751. kind: 'sequence',
  1752. resolve: resolveYamlOmap,
  1753. construct: constructYamlOmap
  1754. });
  1755. var _toString$1 = Object.prototype.toString;
  1756. function resolveYamlPairs(data) {
  1757. if (data === null) return true;
  1758. var index, length, pair, keys, result,
  1759. object = data;
  1760. result = new Array(object.length);
  1761. for (index = 0, length = object.length; index < length; index += 1) {
  1762. pair = object[index];
  1763. if (_toString$1.call(pair) !== '[object Object]') return false;
  1764. keys = Object.keys(pair);
  1765. if (keys.length !== 1) return false;
  1766. result[index] = [ keys[0], pair[keys[0]] ];
  1767. }
  1768. return true;
  1769. }
  1770. function constructYamlPairs(data) {
  1771. if (data === null) return [];
  1772. var index, length, pair, keys, result,
  1773. object = data;
  1774. result = new Array(object.length);
  1775. for (index = 0, length = object.length; index < length; index += 1) {
  1776. pair = object[index];
  1777. keys = Object.keys(pair);
  1778. result[index] = [ keys[0], pair[keys[0]] ];
  1779. }
  1780. return result;
  1781. }
  1782. var pairs = new type('tag:yaml.org,2002:pairs', {
  1783. kind: 'sequence',
  1784. resolve: resolveYamlPairs,
  1785. construct: constructYamlPairs
  1786. });
  1787. var _hasOwnProperty$2 = Object.prototype.hasOwnProperty;
  1788. function resolveYamlSet(data) {
  1789. if (data === null) return true;
  1790. var key, object = data;
  1791. for (key in object) {
  1792. if (_hasOwnProperty$2.call(object, key)) {
  1793. if (object[key] !== null) return false;
  1794. }
  1795. }
  1796. return true;
  1797. }
  1798. function constructYamlSet(data) {
  1799. return data !== null ? data : {};
  1800. }
  1801. var set = new type('tag:yaml.org,2002:set', {
  1802. kind: 'mapping',
  1803. resolve: resolveYamlSet,
  1804. construct: constructYamlSet
  1805. });
  1806. var default_safe = new schema({
  1807. include: [
  1808. core
  1809. ],
  1810. implicit: [
  1811. timestamp,
  1812. merge
  1813. ],
  1814. explicit: [
  1815. binary,
  1816. omap,
  1817. pairs,
  1818. set
  1819. ]
  1820. });
  1821. function resolveJavascriptUndefined() {
  1822. return true;
  1823. }
  1824. function constructJavascriptUndefined() {
  1825. /*eslint-disable no-undefined*/
  1826. return undefined;
  1827. }
  1828. function representJavascriptUndefined() {
  1829. return '';
  1830. }
  1831. function isUndefined(object) {
  1832. return typeof object === 'undefined';
  1833. }
  1834. var _undefined = new type('tag:yaml.org,2002:js/undefined', {
  1835. kind: 'scalar',
  1836. resolve: resolveJavascriptUndefined,
  1837. construct: constructJavascriptUndefined,
  1838. predicate: isUndefined,
  1839. represent: representJavascriptUndefined
  1840. });
  1841. function resolveJavascriptRegExp(data) {
  1842. if (data === null) return false;
  1843. if (data.length === 0) return false;
  1844. var regexp = data,
  1845. tail = /\/([gim]*)$/.exec(data),
  1846. modifiers = '';
  1847. // if regexp starts with '/' it can have modifiers and must be properly closed
  1848. // `/foo/gim` - modifiers tail can be maximum 3 chars
  1849. if (regexp[0] === '/') {
  1850. if (tail) modifiers = tail[1];
  1851. if (modifiers.length > 3) return false;
  1852. // if expression starts with /, is should be properly terminated
  1853. if (regexp[regexp.length - modifiers.length - 1] !== '/') return false;
  1854. }
  1855. return true;
  1856. }
  1857. function constructJavascriptRegExp(data) {
  1858. var regexp = data,
  1859. tail = /\/([gim]*)$/.exec(data),
  1860. modifiers = '';
  1861. // `/foo/gim` - tail can be maximum 4 chars
  1862. if (regexp[0] === '/') {
  1863. if (tail) modifiers = tail[1];
  1864. regexp = regexp.slice(1, regexp.length - modifiers.length - 1);
  1865. }
  1866. return new RegExp(regexp, modifiers);
  1867. }
  1868. function representJavascriptRegExp(object /*, style*/) {
  1869. var result = '/' + object.source + '/';
  1870. if (object.global) result += 'g';
  1871. if (object.multiline) result += 'm';
  1872. if (object.ignoreCase) result += 'i';
  1873. return result;
  1874. }
  1875. function isRegExp(object) {
  1876. return Object.prototype.toString.call(object) === '[object RegExp]';
  1877. }
  1878. var regexp = new type('tag:yaml.org,2002:js/regexp', {
  1879. kind: 'scalar',
  1880. resolve: resolveJavascriptRegExp,
  1881. construct: constructJavascriptRegExp,
  1882. predicate: isRegExp,
  1883. represent: representJavascriptRegExp
  1884. });
  1885. var esprima;
  1886. // Browserified version does not have esprima
  1887. //
  1888. // 1. For node.js just require module as deps
  1889. // 2. For browser try to require mudule via external AMD system.
  1890. // If not found - try to fallback to window.esprima. If not
  1891. // found too - then fail to parse.
  1892. //
  1893. try {
  1894. // workaround to exclude package from browserify list.
  1895. var _require$1 = commonjsRequire;
  1896. esprima = _require$1('esprima');
  1897. } catch (_) {
  1898. /*global window */
  1899. if (typeof window !== 'undefined') esprima = window.esprima;
  1900. }
  1901. function resolveJavascriptFunction(data) {
  1902. if (data === null) return false;
  1903. try {
  1904. var source = '(' + data + ')',
  1905. ast = esprima.parse(source, { range: true });
  1906. if (ast.type !== 'Program' ||
  1907. ast.body.length !== 1 ||
  1908. ast.body[0].type !== 'ExpressionStatement' ||
  1909. ast.body[0].expression.type !== 'FunctionExpression') {
  1910. return false;
  1911. }
  1912. return true;
  1913. } catch (err) {
  1914. return false;
  1915. }
  1916. }
  1917. function constructJavascriptFunction(data) {
  1918. /*jslint evil:true*/
  1919. var source = '(' + data + ')',
  1920. ast = esprima.parse(source, { range: true }),
  1921. params = [],
  1922. body;
  1923. if (ast.type !== 'Program' ||
  1924. ast.body.length !== 1 ||
  1925. ast.body[0].type !== 'ExpressionStatement' ||
  1926. ast.body[0].expression.type !== 'FunctionExpression') {
  1927. throw new Error('Failed to resolve function');
  1928. }
  1929. ast.body[0].expression.params.forEach(function (param) {
  1930. params.push(param.name);
  1931. });
  1932. body = ast.body[0].expression.body.range;
  1933. // Esprima's ranges include the first '{' and the last '}' characters on
  1934. // function expressions. So cut them out.
  1935. /*eslint-disable no-new-func*/
  1936. return new Function(params, source.slice(body[0] + 1, body[1] - 1));
  1937. }
  1938. function representJavascriptFunction(object /*, style*/) {
  1939. return object.toString();
  1940. }
  1941. function isFunction(object) {
  1942. return Object.prototype.toString.call(object) === '[object Function]';
  1943. }
  1944. var _function = new type('tag:yaml.org,2002:js/function', {
  1945. kind: 'scalar',
  1946. resolve: resolveJavascriptFunction,
  1947. construct: constructJavascriptFunction,
  1948. predicate: isFunction,
  1949. represent: representJavascriptFunction
  1950. });
  1951. var default_full = schema.DEFAULT = new schema({
  1952. include: [
  1953. default_safe
  1954. ],
  1955. explicit: [
  1956. _undefined,
  1957. regexp,
  1958. _function
  1959. ]
  1960. });
  1961. /*eslint-disable max-len,no-use-before-define*/
  1962. var _hasOwnProperty = Object.prototype.hasOwnProperty;
  1963. var CONTEXT_FLOW_IN = 1;
  1964. var CONTEXT_FLOW_OUT = 2;
  1965. var CONTEXT_BLOCK_IN = 3;
  1966. var CONTEXT_BLOCK_OUT = 4;
  1967. var CHOMPING_CLIP = 1;
  1968. var CHOMPING_STRIP = 2;
  1969. var CHOMPING_KEEP = 3;
  1970. var PATTERN_NON_PRINTABLE = /[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/;
  1971. var PATTERN_NON_ASCII_LINE_BREAKS = /[\x85\u2028\u2029]/;
  1972. var PATTERN_FLOW_INDICATORS = /[,\[\]\{\}]/;
  1973. var PATTERN_TAG_HANDLE = /^(?:!|!!|![a-z\-]+!)$/i;
  1974. var PATTERN_TAG_URI = /^(?:!|[^,\[\]\{\}])(?:%[0-9a-f]{2}|[0-9a-z\-#;\/\?:@&=\+\$,_\.!~\*'\(\)\[\]])*$/i;
  1975. function is_EOL(c) {
  1976. return (c === 0x0A/* LF */) || (c === 0x0D/* CR */);
  1977. }
  1978. function is_WHITE_SPACE(c) {
  1979. return (c === 0x09/* Tab */) || (c === 0x20/* Space */);
  1980. }
  1981. function is_WS_OR_EOL(c) {
  1982. return (c === 0x09/* Tab */) ||
  1983. (c === 0x20/* Space */) ||
  1984. (c === 0x0A/* LF */) ||
  1985. (c === 0x0D/* CR */);
  1986. }
  1987. function is_FLOW_INDICATOR(c) {
  1988. return c === 0x2C/* , */ ||
  1989. c === 0x5B/* [ */ ||
  1990. c === 0x5D/* ] */ ||
  1991. c === 0x7B/* { */ ||
  1992. c === 0x7D/* } */;
  1993. }
  1994. function fromHexCode(c) {
  1995. var lc;
  1996. if ((0x30/* 0 */ <= c) && (c <= 0x39/* 9 */)) {
  1997. return c - 0x30;
  1998. }
  1999. /*eslint-disable no-bitwise*/
  2000. lc = c | 0x20;
  2001. if ((0x61/* a */ <= lc) && (lc <= 0x66/* f */)) {
  2002. return lc - 0x61 + 10;
  2003. }
  2004. return -1;
  2005. }
  2006. function escapedHexLen(c) {
  2007. if (c === 0x78/* x */) { return 2; }
  2008. if (c === 0x75/* u */) { return 4; }
  2009. if (c === 0x55/* U */) { return 8; }
  2010. return 0;
  2011. }
  2012. function fromDecimalCode(c) {
  2013. if ((0x30/* 0 */ <= c) && (c <= 0x39/* 9 */)) {
  2014. return c - 0x30;
  2015. }
  2016. return -1;
  2017. }
  2018. function simpleEscapeSequence(c) {
  2019. /* eslint-disable indent */
  2020. return (c === 0x30/* 0 */) ? '\x00' :
  2021. (c === 0x61/* a */) ? '\x07' :
  2022. (c === 0x62/* b */) ? '\x08' :
  2023. (c === 0x74/* t */) ? '\x09' :
  2024. (c === 0x09/* Tab */) ? '\x09' :
  2025. (c === 0x6E/* n */) ? '\x0A' :
  2026. (c === 0x76/* v */) ? '\x0B' :
  2027. (c === 0x66/* f */) ? '\x0C' :
  2028. (c === 0x72/* r */) ? '\x0D' :
  2029. (c === 0x65/* e */) ? '\x1B' :
  2030. (c === 0x20/* Space */) ? ' ' :
  2031. (c === 0x22/* " */) ? '\x22' :
  2032. (c === 0x2F/* / */) ? '/' :
  2033. (c === 0x5C/* \ */) ? '\x5C' :
  2034. (c === 0x4E/* N */) ? '\x85' :
  2035. (c === 0x5F/* _ */) ? '\xA0' :
  2036. (c === 0x4C/* L */) ? '\u2028' :
  2037. (c === 0x50/* P */) ? '\u2029' : '';
  2038. }
  2039. function charFromCodepoint(c) {
  2040. if (c <= 0xFFFF) {
  2041. return String.fromCharCode(c);
  2042. }
  2043. // Encode UTF-16 surrogate pair
  2044. // https://en.wikipedia.org/wiki/UTF-16#Code_points_U.2B010000_to_U.2B10FFFF
  2045. return String.fromCharCode(
  2046. ((c - 0x010000) >> 10) + 0xD800,
  2047. ((c - 0x010000) & 0x03FF) + 0xDC00
  2048. );
  2049. }
  2050. var simpleEscapeCheck = new Array(256); // integer, for fast access
  2051. var simpleEscapeMap = new Array(256);
  2052. for (var i = 0; i < 256; i++) {
  2053. simpleEscapeCheck[i] = simpleEscapeSequence(i) ? 1 : 0;
  2054. simpleEscapeMap[i] = simpleEscapeSequence(i);
  2055. }
  2056. function State(input, options) {
  2057. this.input = input;
  2058. this.filename = options['filename'] || null;
  2059. this.schema = options['schema'] || default_full;
  2060. this.onWarning = options['onWarning'] || null;
  2061. this.legacy = options['legacy'] || false;
  2062. this.json = options['json'] || false;
  2063. this.listener = options['listener'] || null;
  2064. this.implicitTypes = this.schema.compiledImplicit;
  2065. this.typeMap = this.schema.compiledTypeMap;
  2066. this.length = input.length;
  2067. this.position = 0;
  2068. this.line = 0;
  2069. this.lineStart = 0;
  2070. this.lineIndent = 0;
  2071. this.documents = [];
  2072. /*
  2073. this.version;
  2074. this.checkLineBreaks;
  2075. this.tagMap;
  2076. this.anchorMap;
  2077. this.tag;
  2078. this.anchor;
  2079. this.kind;
  2080. this.result;*/
  2081. }
  2082. function generateError(state, message) {
  2083. return new exception(
  2084. message,
  2085. new mark(state.filename, state.input, state.position, state.line, (state.position - state.lineStart)));
  2086. }
  2087. function throwError(state, message) {
  2088. throw generateError(state, message);
  2089. }
  2090. function throwWarning(state, message) {
  2091. if (state.onWarning) {
  2092. state.onWarning.call(null, generateError(state, message));
  2093. }
  2094. }
  2095. var directiveHandlers = {
  2096. YAML: function handleYamlDirective(state, name, args) {
  2097. var match, major, minor;
  2098. if (state.version !== null) {
  2099. throwError(state, 'duplication of %YAML directive');
  2100. }
  2101. if (args.length !== 1) {
  2102. throwError(state, 'YAML directive accepts exactly one argument');
  2103. }
  2104. match = /^([0-9]+)\.([0-9]+)$/.exec(args[0]);
  2105. if (match === null) {
  2106. throwError(state, 'ill-formed argument of the YAML directive');
  2107. }
  2108. major = parseInt(match[1], 10);
  2109. minor = parseInt(match[2], 10);
  2110. if (major !== 1) {
  2111. throwError(state, 'unacceptable YAML version of the document');
  2112. }
  2113. state.version = args[0];
  2114. state.checkLineBreaks = (minor < 2);
  2115. if (minor !== 1 && minor !== 2) {
  2116. throwWarning(state, 'unsupported YAML version of the document');
  2117. }
  2118. },
  2119. TAG: function handleTagDirective(state, name, args) {
  2120. var handle, prefix;
  2121. if (args.length !== 2) {
  2122. throwError(state, 'TAG directive accepts exactly two arguments');
  2123. }
  2124. handle = args[0];
  2125. prefix = args[1];
  2126. if (!PATTERN_TAG_HANDLE.test(handle)) {
  2127. throwError(state, 'ill-formed tag handle (first argument) of the TAG directive');
  2128. }
  2129. if (_hasOwnProperty.call(state.tagMap, handle)) {
  2130. throwError(state, 'there is a previously declared suffix for "' + handle + '" tag handle');
  2131. }
  2132. if (!PATTERN_TAG_URI.test(prefix)) {
  2133. throwError(state, 'ill-formed tag prefix (second argument) of the TAG directive');
  2134. }
  2135. state.tagMap[handle] = prefix;
  2136. }
  2137. };
  2138. function captureSegment(state, start, end, checkJson) {
  2139. var _position, _length, _character, _result;
  2140. if (start < end) {
  2141. _result = state.input.slice(start, end);
  2142. if (checkJson) {
  2143. for (_position = 0, _length = _result.length; _position < _length; _position += 1) {
  2144. _character = _result.charCodeAt(_position);
  2145. if (!(_character === 0x09 ||
  2146. (0x20 <= _character && _character <= 0x10FFFF))) {
  2147. throwError(state, 'expected valid JSON character');
  2148. }
  2149. }
  2150. } else if (PATTERN_NON_PRINTABLE.test(_result)) {
  2151. throwError(state, 'the stream contains non-printable characters');
  2152. }
  2153. state.result += _result;
  2154. }
  2155. }
  2156. function mergeMappings(state, destination, source, overridableKeys) {
  2157. var sourceKeys, key, index, quantity;
  2158. if (!common.isObject(source)) {
  2159. throwError(state, 'cannot merge mappings; the provided source object is unacceptable');
  2160. }
  2161. sourceKeys = Object.keys(source);
  2162. for (index = 0, quantity = sourceKeys.length; index < quantity; index += 1) {
  2163. key = sourceKeys[index];
  2164. if (!_hasOwnProperty.call(destination, key)) {
  2165. destination[key] = source[key];
  2166. overridableKeys[key] = true;
  2167. }
  2168. }
  2169. }
  2170. function storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, startLine, startPos) {
  2171. var index, quantity;
  2172. keyNode = String(keyNode);
  2173. if (_result === null) {
  2174. _result = {};
  2175. }
  2176. if (keyTag === 'tag:yaml.org,2002:merge') {
  2177. if (Array.isArray(valueNode)) {
  2178. for (index = 0, quantity = valueNode.length; index < quantity; index += 1) {
  2179. mergeMappings(state, _result, valueNode[index], overridableKeys);
  2180. }
  2181. } else {
  2182. mergeMappings(state, _result, valueNode, overridableKeys);
  2183. }
  2184. } else {
  2185. if (!state.json &&
  2186. !_hasOwnProperty.call(overridableKeys, keyNode) &&
  2187. _hasOwnProperty.call(_result, keyNode)) {
  2188. state.line = startLine || state.line;
  2189. state.position = startPos || state.position;
  2190. throwError(state, 'duplicated mapping key');
  2191. }
  2192. _result[keyNode] = valueNode;
  2193. delete overridableKeys[keyNode];
  2194. }
  2195. return _result;
  2196. }
  2197. function readLineBreak(state) {
  2198. var ch;
  2199. ch = state.input.charCodeAt(state.position);
  2200. if (ch === 0x0A/* LF */) {
  2201. state.position++;
  2202. } else if (ch === 0x0D/* CR */) {
  2203. state.position++;
  2204. if (state.input.charCodeAt(state.position) === 0x0A/* LF */) {
  2205. state.position++;
  2206. }
  2207. } else {
  2208. throwError(state, 'a line break is expected');
  2209. }
  2210. state.line += 1;
  2211. state.lineStart = state.position;
  2212. }
  2213. function skipSeparationSpace(state, allowComments, checkIndent) {
  2214. var lineBreaks = 0,
  2215. ch = state.input.charCodeAt(state.position);
  2216. while (ch !== 0) {
  2217. while (is_WHITE_SPACE(ch)) {
  2218. ch = state.input.charCodeAt(++state.position);
  2219. }
  2220. if (allowComments && ch === 0x23/* # */) {
  2221. do {
  2222. ch = state.input.charCodeAt(++state.position);
  2223. } while (ch !== 0x0A/* LF */ && ch !== 0x0D/* CR */ && ch !== 0);
  2224. }
  2225. if (is_EOL(ch)) {
  2226. readLineBreak(state);
  2227. ch = state.input.charCodeAt(state.position);
  2228. lineBreaks++;
  2229. state.lineIndent = 0;
  2230. while (ch === 0x20/* Space */) {
  2231. state.lineIndent++;
  2232. ch = state.input.charCodeAt(++state.position);
  2233. }
  2234. } else {
  2235. break;
  2236. }
  2237. }
  2238. if (checkIndent !== -1 && lineBreaks !== 0 && state.lineIndent < checkIndent) {
  2239. throwWarning(state, 'deficient indentation');
  2240. }
  2241. return lineBreaks;
  2242. }
  2243. function testDocumentSeparator(state) {
  2244. var _position = state.position,
  2245. ch;
  2246. ch = state.input.charCodeAt(_position);
  2247. // Condition state.position === state.lineStart is tested
  2248. // in parent on each call, for efficiency. No needs to test here again.
  2249. if ((ch === 0x2D/* - */ || ch === 0x2E/* . */) &&
  2250. ch === state.input.charCodeAt(_position + 1) &&
  2251. ch === state.input.charCodeAt(_position + 2)) {
  2252. _position += 3;
  2253. ch = state.input.charCodeAt(_position);
  2254. if (ch === 0 || is_WS_OR_EOL(ch)) {
  2255. return true;
  2256. }
  2257. }
  2258. return false;
  2259. }
  2260. function writeFoldedLines(state, count) {
  2261. if (count === 1) {
  2262. state.result += ' ';
  2263. } else if (count > 1) {
  2264. state.result += common.repeat('\n', count - 1);
  2265. }
  2266. }
  2267. function readPlainScalar(state, nodeIndent, withinFlowCollection) {
  2268. var preceding,
  2269. following,
  2270. captureStart,
  2271. captureEnd,
  2272. hasPendingContent,
  2273. _line,
  2274. _lineStart,
  2275. _lineIndent,
  2276. _kind = state.kind,
  2277. _result = state.result,
  2278. ch;
  2279. ch = state.input.charCodeAt(state.position);
  2280. if (is_WS_OR_EOL(ch) ||
  2281. is_FLOW_INDICATOR(ch) ||
  2282. ch === 0x23/* # */ ||
  2283. ch === 0x26/* & */ ||
  2284. ch === 0x2A/* * */ ||
  2285. ch === 0x21/* ! */ ||
  2286. ch === 0x7C/* | */ ||
  2287. ch === 0x3E/* > */ ||
  2288. ch === 0x27/* ' */ ||
  2289. ch === 0x22/* " */ ||
  2290. ch === 0x25/* % */ ||
  2291. ch === 0x40/* @ */ ||
  2292. ch === 0x60/* ` */) {
  2293. return false;
  2294. }
  2295. if (ch === 0x3F/* ? */ || ch === 0x2D/* - */) {
  2296. following = state.input.charCodeAt(state.position + 1);
  2297. if (is_WS_OR_EOL(following) ||
  2298. withinFlowCollection && is_FLOW_INDICATOR(following)) {
  2299. return false;
  2300. }
  2301. }
  2302. state.kind = 'scalar';
  2303. state.result = '';
  2304. captureStart = captureEnd = state.position;
  2305. hasPendingContent = false;
  2306. while (ch !== 0) {
  2307. if (ch === 0x3A/* : */) {
  2308. following = state.input.charCodeAt(state.position + 1);
  2309. if (is_WS_OR_EOL(following) ||
  2310. withinFlowCollection && is_FLOW_INDICATOR(following)) {
  2311. break;
  2312. }
  2313. } else if (ch === 0x23/* # */) {
  2314. preceding = state.input.charCodeAt(state.position - 1);
  2315. if (is_WS_OR_EOL(preceding)) {
  2316. break;
  2317. }
  2318. } else if ((state.position === state.lineStart && testDocumentSeparator(state)) ||
  2319. withinFlowCollection && is_FLOW_INDICATOR(ch)) {
  2320. break;
  2321. } else if (is_EOL(ch)) {
  2322. _line = state.line;
  2323. _lineStart = state.lineStart;
  2324. _lineIndent = state.lineIndent;
  2325. skipSeparationSpace(state, false, -1);
  2326. if (state.lineIndent >= nodeIndent) {
  2327. hasPendingContent = true;
  2328. ch = state.input.charCodeAt(state.position);
  2329. continue;
  2330. } else {
  2331. state.position = captureEnd;
  2332. state.line = _line;
  2333. state.lineStart = _lineStart;
  2334. state.lineIndent = _lineIndent;
  2335. break;
  2336. }
  2337. }
  2338. if (hasPendingContent) {
  2339. captureSegment(state, captureStart, captureEnd, false);
  2340. writeFoldedLines(state, state.line - _line);
  2341. captureStart = captureEnd = state.position;
  2342. hasPendingContent = false;
  2343. }
  2344. if (!is_WHITE_SPACE(ch)) {
  2345. captureEnd = state.position + 1;
  2346. }
  2347. ch = state.input.charCodeAt(++state.position);
  2348. }
  2349. captureSegment(state, captureStart, captureEnd, false);
  2350. if (state.result) {
  2351. return true;
  2352. }
  2353. state.kind = _kind;
  2354. state.result = _result;
  2355. return false;
  2356. }
  2357. function readSingleQuotedScalar(state, nodeIndent) {
  2358. var ch,
  2359. captureStart, captureEnd;
  2360. ch = state.input.charCodeAt(state.position);
  2361. if (ch !== 0x27/* ' */) {
  2362. return false;
  2363. }
  2364. state.kind = 'scalar';
  2365. state.result = '';
  2366. state.position++;
  2367. captureStart = captureEnd = state.position;
  2368. while ((ch = state.input.charCodeAt(state.position)) !== 0) {
  2369. if (ch === 0x27/* ' */) {
  2370. captureSegment(state, captureStart, state.position, true);
  2371. ch = state.input.charCodeAt(++state.position);
  2372. if (ch === 0x27/* ' */) {
  2373. captureStart = state.position;
  2374. state.position++;
  2375. captureEnd = state.position;
  2376. } else {
  2377. return true;
  2378. }
  2379. } else if (is_EOL(ch)) {
  2380. captureSegment(state, captureStart, captureEnd, true);
  2381. writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
  2382. captureStart = captureEnd = state.position;
  2383. } else if (state.position === state.lineStart && testDocumentSeparator(state)) {
  2384. throwError(state, 'unexpected end of the document within a single quoted scalar');
  2385. } else {
  2386. state.position++;
  2387. captureEnd = state.position;
  2388. }
  2389. }
  2390. throwError(state, 'unexpected end of the stream within a single quoted scalar');
  2391. }
  2392. function readDoubleQuotedScalar(state, nodeIndent) {
  2393. var captureStart,
  2394. captureEnd,
  2395. hexLength,
  2396. hexResult,
  2397. tmp,
  2398. ch;
  2399. ch = state.input.charCodeAt(state.position);
  2400. if (ch !== 0x22/* " */) {
  2401. return false;
  2402. }
  2403. state.kind = 'scalar';
  2404. state.result = '';
  2405. state.position++;
  2406. captureStart = captureEnd = state.position;
  2407. while ((ch = state.input.charCodeAt(state.position)) !== 0) {
  2408. if (ch === 0x22/* " */) {
  2409. captureSegment(state, captureStart, state.position, true);
  2410. state.position++;
  2411. return true;
  2412. } else if (ch === 0x5C/* \ */) {
  2413. captureSegment(state, captureStart, state.position, true);
  2414. ch = state.input.charCodeAt(++state.position);
  2415. if (is_EOL(ch)) {
  2416. skipSeparationSpace(state, false, nodeIndent);
  2417. // TODO: rework to inline fn with no type cast?
  2418. } else if (ch < 256 && simpleEscapeCheck[ch]) {
  2419. state.result += simpleEscapeMap[ch];
  2420. state.position++;
  2421. } else if ((tmp = escapedHexLen(ch)) > 0) {
  2422. hexLength = tmp;
  2423. hexResult = 0;
  2424. for (; hexLength > 0; hexLength--) {
  2425. ch = state.input.charCodeAt(++state.position);
  2426. if ((tmp = fromHexCode(ch)) >= 0) {
  2427. hexResult = (hexResult << 4) + tmp;
  2428. } else {
  2429. throwError(state, 'expected hexadecimal character');
  2430. }
  2431. }
  2432. state.result += charFromCodepoint(hexResult);
  2433. state.position++;
  2434. } else {
  2435. throwError(state, 'unknown escape sequence');
  2436. }
  2437. captureStart = captureEnd = state.position;
  2438. } else if (is_EOL(ch)) {
  2439. captureSegment(state, captureStart, captureEnd, true);
  2440. writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
  2441. captureStart = captureEnd = state.position;
  2442. } else if (state.position === state.lineStart && testDocumentSeparator(state)) {
  2443. throwError(state, 'unexpected end of the document within a double quoted scalar');
  2444. } else {
  2445. state.position++;
  2446. captureEnd = state.position;
  2447. }
  2448. }
  2449. throwError(state, 'unexpected end of the stream within a double quoted scalar');
  2450. }
  2451. function readFlowCollection(state, nodeIndent) {
  2452. var readNext = true,
  2453. _line,
  2454. _tag = state.tag,
  2455. _result,
  2456. _anchor = state.anchor,
  2457. following,
  2458. terminator,
  2459. isPair,
  2460. isExplicitPair,
  2461. isMapping,
  2462. overridableKeys = {},
  2463. keyNode,
  2464. keyTag,
  2465. valueNode,
  2466. ch;
  2467. ch = state.input.charCodeAt(state.position);
  2468. if (ch === 0x5B/* [ */) {
  2469. terminator = 0x5D;/* ] */
  2470. isMapping = false;
  2471. _result = [];
  2472. } else if (ch === 0x7B/* { */) {
  2473. terminator = 0x7D;/* } */
  2474. isMapping = true;
  2475. _result = {};
  2476. } else {
  2477. return false;
  2478. }
  2479. if (state.anchor !== null) {
  2480. state.anchorMap[state.anchor] = _result;
  2481. }
  2482. ch = state.input.charCodeAt(++state.position);
  2483. while (ch !== 0) {
  2484. skipSeparationSpace(state, true, nodeIndent);
  2485. ch = state.input.charCodeAt(state.position);
  2486. if (ch === terminator) {
  2487. state.position++;
  2488. state.tag = _tag;
  2489. state.anchor = _anchor;
  2490. state.kind = isMapping ? 'mapping' : 'sequence';
  2491. state.result = _result;
  2492. return true;
  2493. } else if (!readNext) {
  2494. throwError(state, 'missed comma between flow collection entries');
  2495. }
  2496. keyTag = keyNode = valueNode = null;
  2497. isPair = isExplicitPair = false;
  2498. if (ch === 0x3F/* ? */) {
  2499. following = state.input.charCodeAt(state.position + 1);
  2500. if (is_WS_OR_EOL(following)) {
  2501. isPair = isExplicitPair = true;
  2502. state.position++;
  2503. skipSeparationSpace(state, true, nodeIndent);
  2504. }
  2505. }
  2506. _line = state.line;
  2507. composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
  2508. keyTag = state.tag;
  2509. keyNode = state.result;
  2510. skipSeparationSpace(state, true, nodeIndent);
  2511. ch = state.input.charCodeAt(state.position);
  2512. if ((isExplicitPair || state.line === _line) && ch === 0x3A/* : */) {
  2513. isPair = true;
  2514. ch = state.input.charCodeAt(++state.position);
  2515. skipSeparationSpace(state, true, nodeIndent);
  2516. composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
  2517. valueNode = state.result;
  2518. }
  2519. if (isMapping) {
  2520. storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode);
  2521. } else if (isPair) {
  2522. _result.push(storeMappingPair(state, null, overridableKeys, keyTag, keyNode, valueNode));
  2523. } else {
  2524. _result.push(keyNode);
  2525. }
  2526. skipSeparationSpace(state, true, nodeIndent);
  2527. ch = state.input.charCodeAt(state.position);
  2528. if (ch === 0x2C/* , */) {
  2529. readNext = true;
  2530. ch = state.input.charCodeAt(++state.position);
  2531. } else {
  2532. readNext = false;
  2533. }
  2534. }
  2535. throwError(state, 'unexpected end of the stream within a flow collection');
  2536. }
  2537. function readBlockScalar(state, nodeIndent) {
  2538. var captureStart,
  2539. folding,
  2540. chomping = CHOMPING_CLIP,
  2541. didReadContent = false,
  2542. detectedIndent = false,
  2543. textIndent = nodeIndent,
  2544. emptyLines = 0,
  2545. atMoreIndented = false,
  2546. tmp,
  2547. ch;
  2548. ch = state.input.charCodeAt(state.position);
  2549. if (ch === 0x7C/* | */) {
  2550. folding = false;
  2551. } else if (ch === 0x3E/* > */) {
  2552. folding = true;
  2553. } else {
  2554. return false;
  2555. }
  2556. state.kind = 'scalar';
  2557. state.result = '';
  2558. while (ch !== 0) {
  2559. ch = state.input.charCodeAt(++state.position);
  2560. if (ch === 0x2B/* + */ || ch === 0x2D/* - */) {
  2561. if (CHOMPING_CLIP === chomping) {
  2562. chomping = (ch === 0x2B/* + */) ? CHOMPING_KEEP : CHOMPING_STRIP;
  2563. } else {
  2564. throwError(state, 'repeat of a chomping mode identifier');
  2565. }
  2566. } else if ((tmp = fromDecimalCode(ch)) >= 0) {
  2567. if (tmp === 0) {
  2568. throwError(state, 'bad explicit indentation width of a block scalar; it cannot be less than one');
  2569. } else if (!detectedIndent) {
  2570. textIndent = nodeIndent + tmp - 1;
  2571. detectedIndent = true;
  2572. } else {
  2573. throwError(state, 'repeat of an indentation width identifier');
  2574. }
  2575. } else {
  2576. break;
  2577. }
  2578. }
  2579. if (is_WHITE_SPACE(ch)) {
  2580. do { ch = state.input.charCodeAt(++state.position); }
  2581. while (is_WHITE_SPACE(ch));
  2582. if (ch === 0x23/* # */) {
  2583. do { ch = state.input.charCodeAt(++state.position); }
  2584. while (!is_EOL(ch) && (ch !== 0));
  2585. }
  2586. }
  2587. while (ch !== 0) {
  2588. readLineBreak(state);
  2589. state.lineIndent = 0;
  2590. ch = state.input.charCodeAt(state.position);
  2591. while ((!detectedIndent || state.lineIndent < textIndent) &&
  2592. (ch === 0x20/* Space */)) {
  2593. state.lineIndent++;
  2594. ch = state.input.charCodeAt(++state.position);
  2595. }
  2596. if (!detectedIndent && state.lineIndent > textIndent) {
  2597. textIndent = state.lineIndent;
  2598. }
  2599. if (is_EOL(ch)) {
  2600. emptyLines++;
  2601. continue;
  2602. }
  2603. // End of the scalar.
  2604. if (state.lineIndent < textIndent) {
  2605. // Perform the chomping.
  2606. if (chomping === CHOMPING_KEEP) {
  2607. state.result += common.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines);
  2608. } else if (chomping === CHOMPING_CLIP) {
  2609. if (didReadContent) { // i.e. only if the scalar is not empty.
  2610. state.result += '\n';
  2611. }
  2612. }
  2613. // Break this `while` cycle and go to the funciton's epilogue.
  2614. break;
  2615. }
  2616. // Folded style: use fancy rules to handle line breaks.
  2617. if (folding) {
  2618. // Lines starting with white space characters (more-indented lines) are not folded.
  2619. if (is_WHITE_SPACE(ch)) {
  2620. atMoreIndented = true;
  2621. // except for the first content line (cf. Example 8.1)
  2622. state.result += common.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines);
  2623. // End of more-indented block.
  2624. } else if (atMoreIndented) {
  2625. atMoreIndented = false;
  2626. state.result += common.repeat('\n', emptyLines + 1);
  2627. // Just one line break - perceive as the same line.
  2628. } else if (emptyLines === 0) {
  2629. if (didReadContent) { // i.e. only if we have already read some scalar content.
  2630. state.result += ' ';
  2631. }
  2632. // Several line breaks - perceive as different lines.
  2633. } else {
  2634. state.result += common.repeat('\n', emptyLines);
  2635. }
  2636. // Literal style: just add exact number of line breaks between content lines.
  2637. } else {
  2638. // Keep all line breaks except the header line break.
  2639. state.result += common.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines);
  2640. }
  2641. didReadContent = true;
  2642. detectedIndent = true;
  2643. emptyLines = 0;
  2644. captureStart = state.position;
  2645. while (!is_EOL(ch) && (ch !== 0)) {
  2646. ch = state.input.charCodeAt(++state.position);
  2647. }
  2648. captureSegment(state, captureStart, state.position, false);
  2649. }
  2650. return true;
  2651. }
  2652. function readBlockSequence(state, nodeIndent) {
  2653. var _line,
  2654. _tag = state.tag,
  2655. _anchor = state.anchor,
  2656. _result = [],
  2657. following,
  2658. detected = false,
  2659. ch;
  2660. if (state.anchor !== null) {
  2661. state.anchorMap[state.anchor] = _result;
  2662. }
  2663. ch = state.input.charCodeAt(state.position);
  2664. while (ch !== 0) {
  2665. if (ch !== 0x2D/* - */) {
  2666. break;
  2667. }
  2668. following = state.input.charCodeAt(state.position + 1);
  2669. if (!is_WS_OR_EOL(following)) {
  2670. break;
  2671. }
  2672. detected = true;
  2673. state.position++;
  2674. if (skipSeparationSpace(state, true, -1)) {
  2675. if (state.lineIndent <= nodeIndent) {
  2676. _result.push(null);
  2677. ch = state.input.charCodeAt(state.position);
  2678. continue;
  2679. }
  2680. }
  2681. _line = state.line;
  2682. composeNode(state, nodeIndent, CONTEXT_BLOCK_IN, false, true);
  2683. _result.push(state.result);
  2684. skipSeparationSpace(state, true, -1);
  2685. ch = state.input.charCodeAt(state.position);
  2686. if ((state.line === _line || state.lineIndent > nodeIndent) && (ch !== 0)) {
  2687. throwError(state, 'bad indentation of a sequence entry');
  2688. } else if (state.lineIndent < nodeIndent) {
  2689. break;
  2690. }
  2691. }
  2692. if (detected) {
  2693. state.tag = _tag;
  2694. state.anchor = _anchor;
  2695. state.kind = 'sequence';
  2696. state.result = _result;
  2697. return true;
  2698. }
  2699. return false;
  2700. }
  2701. function readBlockMapping(state, nodeIndent, flowIndent) {
  2702. var following,
  2703. allowCompact,
  2704. _line,
  2705. _pos,
  2706. _tag = state.tag,
  2707. _anchor = state.anchor,
  2708. _result = {},
  2709. overridableKeys = {},
  2710. keyTag = null,
  2711. keyNode = null,
  2712. valueNode = null,
  2713. atExplicitKey = false,
  2714. detected = false,
  2715. ch;
  2716. if (state.anchor !== null) {
  2717. state.anchorMap[state.anchor] = _result;
  2718. }
  2719. ch = state.input.charCodeAt(state.position);
  2720. while (ch !== 0) {
  2721. following = state.input.charCodeAt(state.position + 1);
  2722. _line = state.line; // Save the current line.
  2723. _pos = state.position;
  2724. //
  2725. // Explicit notation case. There are two separate blocks:
  2726. // first for the key (denoted by "?") and second for the value (denoted by ":")
  2727. //
  2728. if ((ch === 0x3F/* ? */ || ch === 0x3A/* : */) && is_WS_OR_EOL(following)) {
  2729. if (ch === 0x3F/* ? */) {
  2730. if (atExplicitKey) {
  2731. storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null);
  2732. keyTag = keyNode = valueNode = null;
  2733. }
  2734. detected = true;
  2735. atExplicitKey = true;
  2736. allowCompact = true;
  2737. } else if (atExplicitKey) {
  2738. // i.e. 0x3A/* : */ === character after the explicit key.
  2739. atExplicitKey = false;
  2740. allowCompact = true;
  2741. } else {
  2742. throwError(state, 'incomplete explicit mapping pair; a key node is missed');
  2743. }
  2744. state.position += 1;
  2745. ch = following;
  2746. //
  2747. // Implicit notation case. Flow-style node as the key first, then ":", and the value.
  2748. //
  2749. } else if (composeNode(state, flowIndent, CONTEXT_FLOW_OUT, false, true)) {
  2750. if (state.line === _line) {
  2751. ch = state.input.charCodeAt(state.position);
  2752. while (is_WHITE_SPACE(ch)) {
  2753. ch = state.input.charCodeAt(++state.position);
  2754. }
  2755. if (ch === 0x3A/* : */) {
  2756. ch = state.input.charCodeAt(++state.position);
  2757. if (!is_WS_OR_EOL(ch)) {
  2758. throwError(state, 'a whitespace character is expected after the key-value separator within a block mapping');
  2759. }
  2760. if (atExplicitKey) {
  2761. storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null);
  2762. keyTag = keyNode = valueNode = null;
  2763. }
  2764. detected = true;
  2765. atExplicitKey = false;
  2766. allowCompact = false;
  2767. keyTag = state.tag;
  2768. keyNode = state.result;
  2769. } else if (detected) {
  2770. throwError(state, 'can not read an implicit mapping pair; a colon is missed');
  2771. } else {
  2772. state.tag = _tag;
  2773. state.anchor = _anchor;
  2774. return true; // Keep the result of `composeNode`.
  2775. }
  2776. } else if (detected) {
  2777. throwError(state, 'can not read a block mapping entry; a multiline key may not be an implicit key');
  2778. } else {
  2779. state.tag = _tag;
  2780. state.anchor = _anchor;
  2781. return true; // Keep the result of `composeNode`.
  2782. }
  2783. } else {
  2784. break; // Reading is done. Go to the epilogue.
  2785. }
  2786. //
  2787. // Common reading code for both explicit and implicit notations.
  2788. //
  2789. if (state.line === _line || state.lineIndent > nodeIndent) {
  2790. if (composeNode(state, nodeIndent, CONTEXT_BLOCK_OUT, true, allowCompact)) {
  2791. if (atExplicitKey) {
  2792. keyNode = state.result;
  2793. } else {
  2794. valueNode = state.result;
  2795. }
  2796. }
  2797. if (!atExplicitKey) {
  2798. storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, _line, _pos);
  2799. keyTag = keyNode = valueNode = null;
  2800. }
  2801. skipSeparationSpace(state, true, -1);
  2802. ch = state.input.charCodeAt(state.position);
  2803. }
  2804. if (state.lineIndent > nodeIndent && (ch !== 0)) {
  2805. throwError(state, 'bad indentation of a mapping entry');
  2806. } else if (state.lineIndent < nodeIndent) {
  2807. break;
  2808. }
  2809. }
  2810. //
  2811. // Epilogue.
  2812. //
  2813. // Special case: last mapping's node contains only the key in explicit notation.
  2814. if (atExplicitKey) {
  2815. storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null);
  2816. }
  2817. // Expose the resulting mapping.
  2818. if (detected) {
  2819. state.tag = _tag;
  2820. state.anchor = _anchor;
  2821. state.kind = 'mapping';
  2822. state.result = _result;
  2823. }
  2824. return detected;
  2825. }
  2826. function readTagProperty(state) {
  2827. var _position,
  2828. isVerbatim = false,
  2829. isNamed = false,
  2830. tagHandle,
  2831. tagName,
  2832. ch;
  2833. ch = state.input.charCodeAt(state.position);
  2834. if (ch !== 0x21/* ! */) return false;
  2835. if (state.tag !== null) {
  2836. throwError(state, 'duplication of a tag property');
  2837. }
  2838. ch = state.input.charCodeAt(++state.position);
  2839. if (ch === 0x3C/* < */) {
  2840. isVerbatim = true;
  2841. ch = state.input.charCodeAt(++state.position);
  2842. } else if (ch === 0x21/* ! */) {
  2843. isNamed = true;
  2844. tagHandle = '!!';
  2845. ch = state.input.charCodeAt(++state.position);
  2846. } else {
  2847. tagHandle = '!';
  2848. }
  2849. _position = state.position;
  2850. if (isVerbatim) {
  2851. do { ch = state.input.charCodeAt(++state.position); }
  2852. while (ch !== 0 && ch !== 0x3E/* > */);
  2853. if (state.position < state.length) {
  2854. tagName = state.input.slice(_position, state.position);
  2855. ch = state.input.charCodeAt(++state.position);
  2856. } else {
  2857. throwError(state, 'unexpected end of the stream within a verbatim tag');
  2858. }
  2859. } else {
  2860. while (ch !== 0 && !is_WS_OR_EOL(ch)) {
  2861. if (ch === 0x21/* ! */) {
  2862. if (!isNamed) {
  2863. tagHandle = state.input.slice(_position - 1, state.position + 1);
  2864. if (!PATTERN_TAG_HANDLE.test(tagHandle)) {
  2865. throwError(state, 'named tag handle cannot contain such characters');
  2866. }
  2867. isNamed = true;
  2868. _position = state.position + 1;
  2869. } else {
  2870. throwError(state, 'tag suffix cannot contain exclamation marks');
  2871. }
  2872. }
  2873. ch = state.input.charCodeAt(++state.position);
  2874. }
  2875. tagName = state.input.slice(_position, state.position);
  2876. if (PATTERN_FLOW_INDICATORS.test(tagName)) {
  2877. throwError(state, 'tag suffix cannot contain flow indicator characters');
  2878. }
  2879. }
  2880. if (tagName && !PATTERN_TAG_URI.test(tagName)) {
  2881. throwError(state, 'tag name cannot contain such characters: ' + tagName);
  2882. }
  2883. if (isVerbatim) {
  2884. state.tag = tagName;
  2885. } else if (_hasOwnProperty.call(state.tagMap, tagHandle)) {
  2886. state.tag = state.tagMap[tagHandle] + tagName;
  2887. } else if (tagHandle === '!') {
  2888. state.tag = '!' + tagName;
  2889. } else if (tagHandle === '!!') {
  2890. state.tag = 'tag:yaml.org,2002:' + tagName;
  2891. } else {
  2892. throwError(state, 'undeclared tag handle "' + tagHandle + '"');
  2893. }
  2894. return true;
  2895. }
  2896. function readAnchorProperty(state) {
  2897. var _position,
  2898. ch;
  2899. ch = state.input.charCodeAt(state.position);
  2900. if (ch !== 0x26/* & */) return false;
  2901. if (state.anchor !== null) {
  2902. throwError(state, 'duplication of an anchor property');
  2903. }
  2904. ch = state.input.charCodeAt(++state.position);
  2905. _position = state.position;
  2906. while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
  2907. ch = state.input.charCodeAt(++state.position);
  2908. }
  2909. if (state.position === _position) {
  2910. throwError(state, 'name of an anchor node must contain at least one character');
  2911. }
  2912. state.anchor = state.input.slice(_position, state.position);
  2913. return true;
  2914. }
  2915. function readAlias(state) {
  2916. var _position, alias,
  2917. ch;
  2918. ch = state.input.charCodeAt(state.position);
  2919. if (ch !== 0x2A/* * */) return false;
  2920. ch = state.input.charCodeAt(++state.position);
  2921. _position = state.position;
  2922. while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
  2923. ch = state.input.charCodeAt(++state.position);
  2924. }
  2925. if (state.position === _position) {
  2926. throwError(state, 'name of an alias node must contain at least one character');
  2927. }
  2928. alias = state.input.slice(_position, state.position);
  2929. if (!state.anchorMap.hasOwnProperty(alias)) {
  2930. throwError(state, 'unidentified alias "' + alias + '"');
  2931. }
  2932. state.result = state.anchorMap[alias];
  2933. skipSeparationSpace(state, true, -1);
  2934. return true;
  2935. }
  2936. function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact) {
  2937. var allowBlockStyles,
  2938. allowBlockScalars,
  2939. allowBlockCollections,
  2940. indentStatus = 1, // 1: this>parent, 0: this=parent, -1: this<parent
  2941. atNewLine = false,
  2942. hasContent = false,
  2943. typeIndex,
  2944. typeQuantity,
  2945. type,
  2946. flowIndent,
  2947. blockIndent;
  2948. if (state.listener !== null) {
  2949. state.listener('open', state);
  2950. }
  2951. state.tag = null;
  2952. state.anchor = null;
  2953. state.kind = null;
  2954. state.result = null;
  2955. allowBlockStyles = allowBlockScalars = allowBlockCollections =
  2956. CONTEXT_BLOCK_OUT === nodeContext ||
  2957. CONTEXT_BLOCK_IN === nodeContext;
  2958. if (allowToSeek) {
  2959. if (skipSeparationSpace(state, true, -1)) {
  2960. atNewLine = true;
  2961. if (state.lineIndent > parentIndent) {
  2962. indentStatus = 1;
  2963. } else if (state.lineIndent === parentIndent) {
  2964. indentStatus = 0;
  2965. } else if (state.lineIndent < parentIndent) {
  2966. indentStatus = -1;
  2967. }
  2968. }
  2969. }
  2970. if (indentStatus === 1) {
  2971. while (readTagProperty(state) || readAnchorProperty(state)) {
  2972. if (skipSeparationSpace(state, true, -1)) {
  2973. atNewLine = true;
  2974. allowBlockCollections = allowBlockStyles;
  2975. if (state.lineIndent > parentIndent) {
  2976. indentStatus = 1;
  2977. } else if (state.lineIndent === parentIndent) {
  2978. indentStatus = 0;
  2979. } else if (state.lineIndent < parentIndent) {
  2980. indentStatus = -1;
  2981. }
  2982. } else {
  2983. allowBlockCollections = false;
  2984. }
  2985. }
  2986. }
  2987. if (allowBlockCollections) {
  2988. allowBlockCollections = atNewLine || allowCompact;
  2989. }
  2990. if (indentStatus === 1 || CONTEXT_BLOCK_OUT === nodeContext) {
  2991. if (CONTEXT_FLOW_IN === nodeContext || CONTEXT_FLOW_OUT === nodeContext) {
  2992. flowIndent = parentIndent;
  2993. } else {
  2994. flowIndent = parentIndent + 1;
  2995. }
  2996. blockIndent = state.position - state.lineStart;
  2997. if (indentStatus === 1) {
  2998. if (allowBlockCollections &&
  2999. (readBlockSequence(state, blockIndent) ||
  3000. readBlockMapping(state, blockIndent, flowIndent)) ||
  3001. readFlowCollection(state, flowIndent)) {
  3002. hasContent = true;
  3003. } else {
  3004. if ((allowBlockScalars && readBlockScalar(state, flowIndent)) ||
  3005. readSingleQuotedScalar(state, flowIndent) ||
  3006. readDoubleQuotedScalar(state, flowIndent)) {
  3007. hasContent = true;
  3008. } else if (readAlias(state)) {
  3009. hasContent = true;
  3010. if (state.tag !== null || state.anchor !== null) {
  3011. throwError(state, 'alias node should not have any properties');
  3012. }
  3013. } else if (readPlainScalar(state, flowIndent, CONTEXT_FLOW_IN === nodeContext)) {
  3014. hasContent = true;
  3015. if (state.tag === null) {
  3016. state.tag = '?';
  3017. }
  3018. }
  3019. if (state.anchor !== null) {
  3020. state.anchorMap[state.anchor] = state.result;
  3021. }
  3022. }
  3023. } else if (indentStatus === 0) {
  3024. // Special case: block sequences are allowed to have same indentation level as the parent.
  3025. // http://www.yaml.org/spec/1.2/spec.html#id2799784
  3026. hasContent = allowBlockCollections && readBlockSequence(state, blockIndent);
  3027. }
  3028. }
  3029. if (state.tag !== null && state.tag !== '!') {
  3030. if (state.tag === '?') {
  3031. for (typeIndex = 0, typeQuantity = state.implicitTypes.length; typeIndex < typeQuantity; typeIndex += 1) {
  3032. type = state.implicitTypes[typeIndex];
  3033. // Implicit resolving is not allowed for non-scalar types, and '?'
  3034. // non-specific tag is only assigned to plain scalars. So, it isn't
  3035. // needed to check for 'kind' conformity.
  3036. if (type.resolve(state.result)) { // `state.result` updated in resolver if matched
  3037. state.result = type.construct(state.result);
  3038. state.tag = type.tag;
  3039. if (state.anchor !== null) {
  3040. state.anchorMap[state.anchor] = state.result;
  3041. }
  3042. break;
  3043. }
  3044. }
  3045. } else if (_hasOwnProperty.call(state.typeMap[state.kind || 'fallback'], state.tag)) {
  3046. type = state.typeMap[state.kind || 'fallback'][state.tag];
  3047. if (state.result !== null && type.kind !== state.kind) {
  3048. throwError(state, 'unacceptable node kind for !<' + state.tag + '> tag; it should be "' + type.kind + '", not "' + state.kind + '"');
  3049. }
  3050. if (!type.resolve(state.result)) { // `state.result` updated in resolver if matched
  3051. throwError(state, 'cannot resolve a node with !<' + state.tag + '> explicit tag');
  3052. } else {
  3053. state.result = type.construct(state.result);
  3054. if (state.anchor !== null) {
  3055. state.anchorMap[state.anchor] = state.result;
  3056. }
  3057. }
  3058. } else {
  3059. throwError(state, 'unknown tag !<' + state.tag + '>');
  3060. }
  3061. }
  3062. if (state.listener !== null) {
  3063. state.listener('close', state);
  3064. }
  3065. return state.tag !== null || state.anchor !== null || hasContent;
  3066. }
  3067. function readDocument(state) {
  3068. var documentStart = state.position,
  3069. _position,
  3070. directiveName,
  3071. directiveArgs,
  3072. hasDirectives = false,
  3073. ch;
  3074. state.version = null;
  3075. state.checkLineBreaks = state.legacy;
  3076. state.tagMap = {};
  3077. state.anchorMap = {};
  3078. while ((ch = state.input.charCodeAt(state.position)) !== 0) {
  3079. skipSeparationSpace(state, true, -1);
  3080. ch = state.input.charCodeAt(state.position);
  3081. if (state.lineIndent > 0 || ch !== 0x25/* % */) {
  3082. break;
  3083. }
  3084. hasDirectives = true;
  3085. ch = state.input.charCodeAt(++state.position);
  3086. _position = state.position;
  3087. while (ch !== 0 && !is_WS_OR_EOL(ch)) {
  3088. ch = state.input.charCodeAt(++state.position);
  3089. }
  3090. directiveName = state.input.slice(_position, state.position);
  3091. directiveArgs = [];
  3092. if (directiveName.length < 1) {
  3093. throwError(state, 'directive name must not be less than one character in length');
  3094. }
  3095. while (ch !== 0) {
  3096. while (is_WHITE_SPACE(ch)) {
  3097. ch = state.input.charCodeAt(++state.position);
  3098. }
  3099. if (ch === 0x23/* # */) {
  3100. do { ch = state.input.charCodeAt(++state.position); }
  3101. while (ch !== 0 && !is_EOL(ch));
  3102. break;
  3103. }
  3104. if (is_EOL(ch)) break;
  3105. _position = state.position;
  3106. while (ch !== 0 && !is_WS_OR_EOL(ch)) {
  3107. ch = state.input.charCodeAt(++state.position);
  3108. }
  3109. directiveArgs.push(state.input.slice(_position, state.position));
  3110. }
  3111. if (ch !== 0) readLineBreak(state);
  3112. if (_hasOwnProperty.call(directiveHandlers, directiveName)) {
  3113. directiveHandlers[directiveName](state, directiveName, directiveArgs);
  3114. } else {
  3115. throwWarning(state, 'unknown document directive "' + directiveName + '"');
  3116. }
  3117. }
  3118. skipSeparationSpace(state, true, -1);
  3119. if (state.lineIndent === 0 &&
  3120. state.input.charCodeAt(state.position) === 0x2D/* - */ &&
  3121. state.input.charCodeAt(state.position + 1) === 0x2D/* - */ &&
  3122. state.input.charCodeAt(state.position + 2) === 0x2D/* - */) {
  3123. state.position += 3;
  3124. skipSeparationSpace(state, true, -1);
  3125. } else if (hasDirectives) {
  3126. throwError(state, 'directives end mark is expected');
  3127. }
  3128. composeNode(state, state.lineIndent - 1, CONTEXT_BLOCK_OUT, false, true);
  3129. skipSeparationSpace(state, true, -1);
  3130. if (state.checkLineBreaks &&
  3131. PATTERN_NON_ASCII_LINE_BREAKS.test(state.input.slice(documentStart, state.position))) {
  3132. throwWarning(state, 'non-ASCII line breaks are interpreted as content');
  3133. }
  3134. state.documents.push(state.result);
  3135. if (state.position === state.lineStart && testDocumentSeparator(state)) {
  3136. if (state.input.charCodeAt(state.position) === 0x2E/* . */) {
  3137. state.position += 3;
  3138. skipSeparationSpace(state, true, -1);
  3139. }
  3140. return;
  3141. }
  3142. if (state.position < (state.length - 1)) {
  3143. throwError(state, 'end of the stream or a document separator is expected');
  3144. } else {
  3145. return;
  3146. }
  3147. }
  3148. function loadDocuments(input, options) {
  3149. input = String(input);
  3150. options = options || {};
  3151. if (input.length !== 0) {
  3152. // Add tailing `\n` if not exists
  3153. if (input.charCodeAt(input.length - 1) !== 0x0A/* LF */ &&
  3154. input.charCodeAt(input.length - 1) !== 0x0D/* CR */) {
  3155. input += '\n';
  3156. }
  3157. // Strip BOM
  3158. if (input.charCodeAt(0) === 0xFEFF) {
  3159. input = input.slice(1);
  3160. }
  3161. }
  3162. var state = new State(input, options);
  3163. // Use 0 as string terminator. That significantly simplifies bounds check.
  3164. state.input += '\0';
  3165. while (state.input.charCodeAt(state.position) === 0x20/* Space */) {
  3166. state.lineIndent += 1;
  3167. state.position += 1;
  3168. }
  3169. while (state.position < (state.length - 1)) {
  3170. readDocument(state);
  3171. }
  3172. return state.documents;
  3173. }
  3174. function loadAll$1(input, iterator, options) {
  3175. var documents = loadDocuments(input, options), index, length;
  3176. if (typeof iterator !== 'function') {
  3177. return documents;
  3178. }
  3179. for (index = 0, length = documents.length; index < length; index += 1) {
  3180. iterator(documents[index]);
  3181. }
  3182. }
  3183. function load$1(input, options) {
  3184. var documents = loadDocuments(input, options);
  3185. if (documents.length === 0) {
  3186. /*eslint-disable no-undefined*/
  3187. return undefined;
  3188. } else if (documents.length === 1) {
  3189. return documents[0];
  3190. }
  3191. throw new exception('expected a single document in the stream, but found more');
  3192. }
  3193. function safeLoadAll$1(input, output, options) {
  3194. if (typeof output === 'function') {
  3195. loadAll$1(input, output, common.extend({ schema: default_safe }, options));
  3196. } else {
  3197. return loadAll$1(input, common.extend({ schema: default_safe }, options));
  3198. }
  3199. }
  3200. function safeLoad$1(input, options) {
  3201. return load$1(input, common.extend({ schema: default_safe }, options));
  3202. }
  3203. var loadAll_1 = loadAll$1;
  3204. var load_1 = load$1;
  3205. var safeLoadAll_1 = safeLoadAll$1;
  3206. var safeLoad_1 = safeLoad$1;
  3207. var loader = {
  3208. loadAll: loadAll_1,
  3209. load: load_1,
  3210. safeLoadAll: safeLoadAll_1,
  3211. safeLoad: safeLoad_1
  3212. };
  3213. /*eslint-disable no-use-before-define*/
  3214. var _toString$2 = Object.prototype.toString;
  3215. var _hasOwnProperty$3 = Object.prototype.hasOwnProperty;
  3216. var CHAR_TAB = 0x09; /* Tab */
  3217. var CHAR_LINE_FEED = 0x0A; /* LF */
  3218. var CHAR_SPACE = 0x20; /* Space */
  3219. var CHAR_EXCLAMATION = 0x21; /* ! */
  3220. var CHAR_DOUBLE_QUOTE = 0x22; /* " */
  3221. var CHAR_SHARP = 0x23; /* # */
  3222. var CHAR_PERCENT = 0x25; /* % */
  3223. var CHAR_AMPERSAND = 0x26; /* & */
  3224. var CHAR_SINGLE_QUOTE = 0x27; /* ' */
  3225. var CHAR_ASTERISK = 0x2A; /* * */
  3226. var CHAR_COMMA = 0x2C; /* , */
  3227. var CHAR_MINUS = 0x2D; /* - */
  3228. var CHAR_COLON = 0x3A; /* : */
  3229. var CHAR_GREATER_THAN = 0x3E; /* > */
  3230. var CHAR_QUESTION = 0x3F; /* ? */
  3231. var CHAR_COMMERCIAL_AT = 0x40; /* @ */
  3232. var CHAR_LEFT_SQUARE_BRACKET = 0x5B; /* [ */
  3233. var CHAR_RIGHT_SQUARE_BRACKET = 0x5D; /* ] */
  3234. var CHAR_GRAVE_ACCENT = 0x60; /* ` */
  3235. var CHAR_LEFT_CURLY_BRACKET = 0x7B; /* { */
  3236. var CHAR_VERTICAL_LINE = 0x7C; /* | */
  3237. var CHAR_RIGHT_CURLY_BRACKET = 0x7D; /* } */
  3238. var ESCAPE_SEQUENCES = {};
  3239. ESCAPE_SEQUENCES[0x00] = '\\0';
  3240. ESCAPE_SEQUENCES[0x07] = '\\a';
  3241. ESCAPE_SEQUENCES[0x08] = '\\b';
  3242. ESCAPE_SEQUENCES[0x09] = '\\t';
  3243. ESCAPE_SEQUENCES[0x0A] = '\\n';
  3244. ESCAPE_SEQUENCES[0x0B] = '\\v';
  3245. ESCAPE_SEQUENCES[0x0C] = '\\f';
  3246. ESCAPE_SEQUENCES[0x0D] = '\\r';
  3247. ESCAPE_SEQUENCES[0x1B] = '\\e';
  3248. ESCAPE_SEQUENCES[0x22] = '\\"';
  3249. ESCAPE_SEQUENCES[0x5C] = '\\\\';
  3250. ESCAPE_SEQUENCES[0x85] = '\\N';
  3251. ESCAPE_SEQUENCES[0xA0] = '\\_';
  3252. ESCAPE_SEQUENCES[0x2028] = '\\L';
  3253. ESCAPE_SEQUENCES[0x2029] = '\\P';
  3254. var DEPRECATED_BOOLEANS_SYNTAX = [
  3255. 'y', 'Y', 'yes', 'Yes', 'YES', 'on', 'On', 'ON',
  3256. 'n', 'N', 'no', 'No', 'NO', 'off', 'Off', 'OFF'
  3257. ];
  3258. function compileStyleMap(schema, map) {
  3259. var result, keys, index, length, tag, style, type;
  3260. if (map === null) return {};
  3261. result = {};
  3262. keys = Object.keys(map);
  3263. for (index = 0, length = keys.length; index < length; index += 1) {
  3264. tag = keys[index];
  3265. style = String(map[tag]);
  3266. if (tag.slice(0, 2) === '!!') {
  3267. tag = 'tag:yaml.org,2002:' + tag.slice(2);
  3268. }
  3269. type = schema.compiledTypeMap['fallback'][tag];
  3270. if (type && _hasOwnProperty$3.call(type.styleAliases, style)) {
  3271. style = type.styleAliases[style];
  3272. }
  3273. result[tag] = style;
  3274. }
  3275. return result;
  3276. }
  3277. function encodeHex(character) {
  3278. var string, handle, length;
  3279. string = character.toString(16).toUpperCase();
  3280. if (character <= 0xFF) {
  3281. handle = 'x';
  3282. length = 2;
  3283. } else if (character <= 0xFFFF) {
  3284. handle = 'u';
  3285. length = 4;
  3286. } else if (character <= 0xFFFFFFFF) {
  3287. handle = 'U';
  3288. length = 8;
  3289. } else {
  3290. throw new exception('code point within a string may not be greater than 0xFFFFFFFF');
  3291. }
  3292. return '\\' + handle + common.repeat('0', length - string.length) + string;
  3293. }
  3294. function State$1(options) {
  3295. this.schema = options['schema'] || default_full;
  3296. this.indent = Math.max(1, (options['indent'] || 2));
  3297. this.skipInvalid = options['skipInvalid'] || false;
  3298. this.flowLevel = (common.isNothing(options['flowLevel']) ? -1 : options['flowLevel']);
  3299. this.styleMap = compileStyleMap(this.schema, options['styles'] || null);
  3300. this.sortKeys = options['sortKeys'] || false;
  3301. this.lineWidth = options['lineWidth'] || 80;
  3302. this.noRefs = options['noRefs'] || false;
  3303. this.noCompatMode = options['noCompatMode'] || false;
  3304. this.condenseFlow = options['condenseFlow'] || false;
  3305. this.implicitTypes = this.schema.compiledImplicit;
  3306. this.explicitTypes = this.schema.compiledExplicit;
  3307. this.tag = null;
  3308. this.result = '';
  3309. this.duplicates = [];
  3310. this.usedDuplicates = null;
  3311. }
  3312. // Indents every line in a string. Empty lines (\n only) are not indented.
  3313. function indentString(string, spaces) {
  3314. var ind = common.repeat(' ', spaces),
  3315. position = 0,
  3316. next = -1,
  3317. result = '',
  3318. line,
  3319. length = string.length;
  3320. while (position < length) {
  3321. next = string.indexOf('\n', position);
  3322. if (next === -1) {
  3323. line = string.slice(position);
  3324. position = length;
  3325. } else {
  3326. line = string.slice(position, next + 1);
  3327. position = next + 1;
  3328. }
  3329. if (line.length && line !== '\n') result += ind;
  3330. result += line;
  3331. }
  3332. return result;
  3333. }
  3334. function generateNextLine(state, level) {
  3335. return '\n' + common.repeat(' ', state.indent * level);
  3336. }
  3337. function testImplicitResolving(state, str) {
  3338. var index, length, type;
  3339. for (index = 0, length = state.implicitTypes.length; index < length; index += 1) {
  3340. type = state.implicitTypes[index];
  3341. if (type.resolve(str)) {
  3342. return true;
  3343. }
  3344. }
  3345. return false;
  3346. }
  3347. // [33] s-white ::= s-space | s-tab
  3348. function isWhitespace(c) {
  3349. return c === CHAR_SPACE || c === CHAR_TAB;
  3350. }
  3351. // Returns true if the character can be printed without escaping.
  3352. // From YAML 1.2: "any allowed characters known to be non-printable
  3353. // should also be escaped. [However,] This isn’t mandatory"
  3354. // Derived from nb-char - \t - #x85 - #xA0 - #x2028 - #x2029.
  3355. function isPrintable(c) {
  3356. return (0x00020 <= c && c <= 0x00007E)
  3357. || ((0x000A1 <= c && c <= 0x00D7FF) && c !== 0x2028 && c !== 0x2029)
  3358. || ((0x0E000 <= c && c <= 0x00FFFD) && c !== 0xFEFF /* BOM */)
  3359. || (0x10000 <= c && c <= 0x10FFFF);
  3360. }
  3361. // Simplified test for values allowed after the first character in plain style.
  3362. function isPlainSafe(c) {
  3363. // Uses a subset of nb-char - c-flow-indicator - ":" - "#"
  3364. // where nb-char ::= c-printable - b-char - c-byte-order-mark.
  3365. return isPrintable(c) && c !== 0xFEFF
  3366. // - c-flow-indicator
  3367. && c !== CHAR_COMMA
  3368. && c !== CHAR_LEFT_SQUARE_BRACKET
  3369. && c !== CHAR_RIGHT_SQUARE_BRACKET
  3370. && c !== CHAR_LEFT_CURLY_BRACKET
  3371. && c !== CHAR_RIGHT_CURLY_BRACKET
  3372. // - ":" - "#"
  3373. && c !== CHAR_COLON
  3374. && c !== CHAR_SHARP;
  3375. }
  3376. // Simplified test for values allowed as the first character in plain style.
  3377. function isPlainSafeFirst(c) {
  3378. // Uses a subset of ns-char - c-indicator
  3379. // where ns-char = nb-char - s-white.
  3380. return isPrintable(c) && c !== 0xFEFF
  3381. && !isWhitespace(c) // - s-white
  3382. // - (c-indicator ::=
  3383. // “-” | “?” | “:” | “,” | “[” | “]” | “{” | “}”
  3384. && c !== CHAR_MINUS
  3385. && c !== CHAR_QUESTION
  3386. && c !== CHAR_COLON
  3387. && c !== CHAR_COMMA
  3388. && c !== CHAR_LEFT_SQUARE_BRACKET
  3389. && c !== CHAR_RIGHT_SQUARE_BRACKET
  3390. && c !== CHAR_LEFT_CURLY_BRACKET
  3391. && c !== CHAR_RIGHT_CURLY_BRACKET
  3392. // | “#” | “&” | “*” | “!” | “|” | “>” | “'” | “"”
  3393. && c !== CHAR_SHARP
  3394. && c !== CHAR_AMPERSAND
  3395. && c !== CHAR_ASTERISK
  3396. && c !== CHAR_EXCLAMATION
  3397. && c !== CHAR_VERTICAL_LINE
  3398. && c !== CHAR_GREATER_THAN
  3399. && c !== CHAR_SINGLE_QUOTE
  3400. && c !== CHAR_DOUBLE_QUOTE
  3401. // | “%” | “@” | “`”)
  3402. && c !== CHAR_PERCENT
  3403. && c !== CHAR_COMMERCIAL_AT
  3404. && c !== CHAR_GRAVE_ACCENT;
  3405. }
  3406. var STYLE_PLAIN = 1;
  3407. var STYLE_SINGLE = 2;
  3408. var STYLE_LITERAL = 3;
  3409. var STYLE_FOLDED = 4;
  3410. var STYLE_DOUBLE = 5;
  3411. // Determines which scalar styles are possible and returns the preferred style.
  3412. // lineWidth = -1 => no limit.
  3413. // Pre-conditions: str.length > 0.
  3414. // Post-conditions:
  3415. // STYLE_PLAIN or STYLE_SINGLE => no \n are in the string.
  3416. // STYLE_LITERAL => no lines are suitable for folding (or lineWidth is -1).
  3417. // STYLE_FOLDED => a line > lineWidth and can be folded (and lineWidth != -1).
  3418. function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth, testAmbiguousType) {
  3419. var i;
  3420. var char;
  3421. var hasLineBreak = false;
  3422. var hasFoldableLine = false; // only checked if shouldTrackWidth
  3423. var shouldTrackWidth = lineWidth !== -1;
  3424. var previousLineBreak = -1; // count the first line correctly
  3425. var plain = isPlainSafeFirst(string.charCodeAt(0))
  3426. && !isWhitespace(string.charCodeAt(string.length - 1));
  3427. if (singleLineOnly) {
  3428. // Case: no block styles.
  3429. // Check for disallowed characters to rule out plain and single.
  3430. for (i = 0; i < string.length; i++) {
  3431. char = string.charCodeAt(i);
  3432. if (!isPrintable(char)) {
  3433. return STYLE_DOUBLE;
  3434. }
  3435. plain = plain && isPlainSafe(char);
  3436. }
  3437. } else {
  3438. // Case: block styles permitted.
  3439. for (i = 0; i < string.length; i++) {
  3440. char = string.charCodeAt(i);
  3441. if (char === CHAR_LINE_FEED) {
  3442. hasLineBreak = true;
  3443. // Check if any line can be folded.
  3444. if (shouldTrackWidth) {
  3445. hasFoldableLine = hasFoldableLine ||
  3446. // Foldable line = too long, and not more-indented.
  3447. (i - previousLineBreak - 1 > lineWidth &&
  3448. string[previousLineBreak + 1] !== ' ');
  3449. previousLineBreak = i;
  3450. }
  3451. } else if (!isPrintable(char)) {
  3452. return STYLE_DOUBLE;
  3453. }
  3454. plain = plain && isPlainSafe(char);
  3455. }
  3456. // in case the end is missing a \n
  3457. hasFoldableLine = hasFoldableLine || (shouldTrackWidth &&
  3458. (i - previousLineBreak - 1 > lineWidth &&
  3459. string[previousLineBreak + 1] !== ' '));
  3460. }
  3461. // Although every style can represent \n without escaping, prefer block styles
  3462. // for multiline, since they're more readable and they don't add empty lines.
  3463. // Also prefer folding a super-long line.
  3464. if (!hasLineBreak && !hasFoldableLine) {
  3465. // Strings interpretable as another type have to be quoted;
  3466. // e.g. the string 'true' vs. the boolean true.
  3467. return plain && !testAmbiguousType(string)
  3468. ? STYLE_PLAIN : STYLE_SINGLE;
  3469. }
  3470. // Edge case: block indentation indicator can only have one digit.
  3471. if (string[0] === ' ' && indentPerLevel > 9) {
  3472. return STYLE_DOUBLE;
  3473. }
  3474. // At this point we know block styles are valid.
  3475. // Prefer literal style unless we want to fold.
  3476. return hasFoldableLine ? STYLE_FOLDED : STYLE_LITERAL;
  3477. }
  3478. // Note: line breaking/folding is implemented for only the folded style.
  3479. // NB. We drop the last trailing newline (if any) of a returned block scalar
  3480. // since the dumper adds its own newline. This always works:
  3481. // • No ending newline => unaffected; already using strip "-" chomping.
  3482. // • Ending newline => removed then restored.
  3483. // Importantly, this keeps the "+" chomp indicator from gaining an extra line.
  3484. function writeScalar(state, string, level, iskey) {
  3485. state.dump = (function () {
  3486. if (string.length === 0) {
  3487. return "''";
  3488. }
  3489. if (!state.noCompatMode &&
  3490. DEPRECATED_BOOLEANS_SYNTAX.indexOf(string) !== -1) {
  3491. return "'" + string + "'";
  3492. }
  3493. var indent = state.indent * Math.max(1, level); // no 0-indent scalars
  3494. // As indentation gets deeper, let the width decrease monotonically
  3495. // to the lower bound min(state.lineWidth, 40).
  3496. // Note that this implies
  3497. // state.lineWidth ≤ 40 + state.indent: width is fixed at the lower bound.
  3498. // state.lineWidth > 40 + state.indent: width decreases until the lower bound.
  3499. // This behaves better than a constant minimum width which disallows narrower options,
  3500. // or an indent threshold which causes the width to suddenly increase.
  3501. var lineWidth = state.lineWidth === -1
  3502. ? -1 : Math.max(Math.min(state.lineWidth, 40), state.lineWidth - indent);
  3503. // Without knowing if keys are implicit/explicit, assume implicit for safety.
  3504. var singleLineOnly = iskey
  3505. // No block styles in flow mode.
  3506. || (state.flowLevel > -1 && level >= state.flowLevel);
  3507. function testAmbiguity(string) {
  3508. return testImplicitResolving(state, string);
  3509. }
  3510. switch (chooseScalarStyle(string, singleLineOnly, state.indent, lineWidth, testAmbiguity)) {
  3511. case STYLE_PLAIN:
  3512. return string;
  3513. case STYLE_SINGLE:
  3514. return "'" + string.replace(/'/g, "''") + "'";
  3515. case STYLE_LITERAL:
  3516. return '|' + blockHeader(string, state.indent)
  3517. + dropEndingNewline(indentString(string, indent));
  3518. case STYLE_FOLDED:
  3519. return '>' + blockHeader(string, state.indent)
  3520. + dropEndingNewline(indentString(foldString(string, lineWidth), indent));
  3521. case STYLE_DOUBLE:
  3522. return '"' + escapeString(string, lineWidth) + '"';
  3523. default:
  3524. throw new exception('impossible error: invalid scalar style');
  3525. }
  3526. }());
  3527. }
  3528. // Pre-conditions: string is valid for a block scalar, 1 <= indentPerLevel <= 9.
  3529. function blockHeader(string, indentPerLevel) {
  3530. var indentIndicator = (string[0] === ' ') ? String(indentPerLevel) : '';
  3531. // note the special case: the string '\n' counts as a "trailing" empty line.
  3532. var clip = string[string.length - 1] === '\n';
  3533. var keep = clip && (string[string.length - 2] === '\n' || string === '\n');
  3534. var chomp = keep ? '+' : (clip ? '' : '-');
  3535. return indentIndicator + chomp + '\n';
  3536. }
  3537. // (See the note for writeScalar.)
  3538. function dropEndingNewline(string) {
  3539. return string[string.length - 1] === '\n' ? string.slice(0, -1) : string;
  3540. }
  3541. // Note: a long line without a suitable break point will exceed the width limit.
  3542. // Pre-conditions: every char in str isPrintable, str.length > 0, width > 0.
  3543. function foldString(string, width) {
  3544. // In folded style, $k$ consecutive newlines output as $k+1$ newlines—
  3545. // unless they're before or after a more-indented line, or at the very
  3546. // beginning or end, in which case $k$ maps to $k$.
  3547. // Therefore, parse each chunk as newline(s) followed by a content line.
  3548. var lineRe = /(\n+)([^\n]*)/g;
  3549. // first line (possibly an empty line)
  3550. var result = (function () {
  3551. var nextLF = string.indexOf('\n');
  3552. nextLF = nextLF !== -1 ? nextLF : string.length;
  3553. lineRe.lastIndex = nextLF;
  3554. return foldLine(string.slice(0, nextLF), width);
  3555. }());
  3556. // If we haven't reached the first content line yet, don't add an extra \n.
  3557. var prevMoreIndented = string[0] === '\n' || string[0] === ' ';
  3558. var moreIndented;
  3559. // rest of the lines
  3560. var match;
  3561. while ((match = lineRe.exec(string))) {
  3562. var prefix = match[1], line = match[2];
  3563. moreIndented = (line[0] === ' ');
  3564. result += prefix
  3565. + (!prevMoreIndented && !moreIndented && line !== ''
  3566. ? '\n' : '')
  3567. + foldLine(line, width);
  3568. prevMoreIndented = moreIndented;
  3569. }
  3570. return result;
  3571. }
  3572. // Greedy line breaking.
  3573. // Picks the longest line under the limit each time,
  3574. // otherwise settles for the shortest line over the limit.
  3575. // NB. More-indented lines *cannot* be folded, as that would add an extra \n.
  3576. function foldLine(line, width) {
  3577. if (line === '' || line[0] === ' ') return line;
  3578. // Since a more-indented line adds a \n, breaks can't be followed by a space.
  3579. var breakRe = / [^ ]/g; // note: the match index will always be <= length-2.
  3580. var match;
  3581. // start is an inclusive index. end, curr, and next are exclusive.
  3582. var start = 0, end, curr = 0, next = 0;
  3583. var result = '';
  3584. // Invariants: 0 <= start <= length-1.
  3585. // 0 <= curr <= next <= max(0, length-2). curr - start <= width.
  3586. // Inside the loop:
  3587. // A match implies length >= 2, so curr and next are <= length-2.
  3588. while ((match = breakRe.exec(line))) {
  3589. next = match.index;
  3590. // maintain invariant: curr - start <= width
  3591. if (next - start > width) {
  3592. end = (curr > start) ? curr : next; // derive end <= length-2
  3593. result += '\n' + line.slice(start, end);
  3594. // skip the space that was output as \n
  3595. start = end + 1; // derive start <= length-1
  3596. }
  3597. curr = next;
  3598. }
  3599. // By the invariants, start <= length-1, so there is something left over.
  3600. // It is either the whole string or a part starting from non-whitespace.
  3601. result += '\n';
  3602. // Insert a break if the remainder is too long and there is a break available.
  3603. if (line.length - start > width && curr > start) {
  3604. result += line.slice(start, curr) + '\n' + line.slice(curr + 1);
  3605. } else {
  3606. result += line.slice(start);
  3607. }
  3608. return result.slice(1); // drop extra \n joiner
  3609. }
  3610. // Escapes a double-quoted string.
  3611. function escapeString(string) {
  3612. var result = '';
  3613. var char;
  3614. var escapeSeq;
  3615. for (var i = 0; i < string.length; i++) {
  3616. char = string.charCodeAt(i);
  3617. escapeSeq = ESCAPE_SEQUENCES[char];
  3618. result += !escapeSeq && isPrintable(char)
  3619. ? string[i]
  3620. : escapeSeq || encodeHex(char);
  3621. }
  3622. return result;
  3623. }
  3624. function writeFlowSequence(state, level, object) {
  3625. var _result = '',
  3626. _tag = state.tag,
  3627. index,
  3628. length;
  3629. for (index = 0, length = object.length; index < length; index += 1) {
  3630. // Write only valid elements.
  3631. if (writeNode(state, level, object[index], false, false)) {
  3632. if (index !== 0) _result += ',' + (!state.condenseFlow ? ' ' : '');
  3633. _result += state.dump;
  3634. }
  3635. }
  3636. state.tag = _tag;
  3637. state.dump = '[' + _result + ']';
  3638. }
  3639. function writeBlockSequence(state, level, object, compact) {
  3640. var _result = '',
  3641. _tag = state.tag,
  3642. index,
  3643. length;
  3644. for (index = 0, length = object.length; index < length; index += 1) {
  3645. // Write only valid elements.
  3646. if (writeNode(state, level + 1, object[index], true, true)) {
  3647. if (!compact || index !== 0) {
  3648. _result += generateNextLine(state, level);
  3649. }
  3650. if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
  3651. _result += '-';
  3652. } else {
  3653. _result += '- ';
  3654. }
  3655. _result += state.dump;
  3656. }
  3657. }
  3658. state.tag = _tag;
  3659. state.dump = _result || '[]'; // Empty sequence if no valid values.
  3660. }
  3661. function writeFlowMapping(state, level, object) {
  3662. var _result = '',
  3663. _tag = state.tag,
  3664. objectKeyList = Object.keys(object),
  3665. index,
  3666. length,
  3667. objectKey,
  3668. objectValue,
  3669. pairBuffer;
  3670. for (index = 0, length = objectKeyList.length; index < length; index += 1) {
  3671. pairBuffer = '';
  3672. if (index !== 0) pairBuffer += ', ';
  3673. objectKey = objectKeyList[index];
  3674. objectValue = object[objectKey];
  3675. if (!writeNode(state, level, objectKey, false, false)) {
  3676. continue; // Skip this pair because of invalid key;
  3677. }
  3678. if (state.dump.length > 1024) pairBuffer += '? ';
  3679. pairBuffer += state.dump + ':' + (state.condenseFlow ? '' : ' ');
  3680. if (!writeNode(state, level, objectValue, false, false)) {
  3681. continue; // Skip this pair because of invalid value.
  3682. }
  3683. pairBuffer += state.dump;
  3684. // Both key and value are valid.
  3685. _result += pairBuffer;
  3686. }
  3687. state.tag = _tag;
  3688. state.dump = '{' + _result + '}';
  3689. }
  3690. function writeBlockMapping(state, level, object, compact) {
  3691. var _result = '',
  3692. _tag = state.tag,
  3693. objectKeyList = Object.keys(object),
  3694. index,
  3695. length,
  3696. objectKey,
  3697. objectValue,
  3698. explicitPair,
  3699. pairBuffer;
  3700. // Allow sorting keys so that the output file is deterministic
  3701. if (state.sortKeys === true) {
  3702. // Default sorting
  3703. objectKeyList.sort();
  3704. } else if (typeof state.sortKeys === 'function') {
  3705. // Custom sort function
  3706. objectKeyList.sort(state.sortKeys);
  3707. } else if (state.sortKeys) {
  3708. // Something is wrong
  3709. throw new exception('sortKeys must be a boolean or a function');
  3710. }
  3711. for (index = 0, length = objectKeyList.length; index < length; index += 1) {
  3712. pairBuffer = '';
  3713. if (!compact || index !== 0) {
  3714. pairBuffer += generateNextLine(state, level);
  3715. }
  3716. objectKey = objectKeyList[index];
  3717. objectValue = object[objectKey];
  3718. if (!writeNode(state, level + 1, objectKey, true, true, true)) {
  3719. continue; // Skip this pair because of invalid key.
  3720. }
  3721. explicitPair = (state.tag !== null && state.tag !== '?') ||
  3722. (state.dump && state.dump.length > 1024);
  3723. if (explicitPair) {
  3724. if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
  3725. pairBuffer += '?';
  3726. } else {
  3727. pairBuffer += '? ';
  3728. }
  3729. }
  3730. pairBuffer += state.dump;
  3731. if (explicitPair) {
  3732. pairBuffer += generateNextLine(state, level);
  3733. }
  3734. if (!writeNode(state, level + 1, objectValue, true, explicitPair)) {
  3735. continue; // Skip this pair because of invalid value.
  3736. }
  3737. if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
  3738. pairBuffer += ':';
  3739. } else {
  3740. pairBuffer += ': ';
  3741. }
  3742. pairBuffer += state.dump;
  3743. // Both key and value are valid.
  3744. _result += pairBuffer;
  3745. }
  3746. state.tag = _tag;
  3747. state.dump = _result || '{}'; // Empty mapping if no valid pairs.
  3748. }
  3749. function detectType(state, object, explicit) {
  3750. var _result, typeList, index, length, type, style;
  3751. typeList = explicit ? state.explicitTypes : state.implicitTypes;
  3752. for (index = 0, length = typeList.length; index < length; index += 1) {
  3753. type = typeList[index];
  3754. if ((type.instanceOf || type.predicate) &&
  3755. (!type.instanceOf || ((typeof object === 'object') && (object instanceof type.instanceOf))) &&
  3756. (!type.predicate || type.predicate(object))) {
  3757. state.tag = explicit ? type.tag : '?';
  3758. if (type.represent) {
  3759. style = state.styleMap[type.tag] || type.defaultStyle;
  3760. if (_toString$2.call(type.represent) === '[object Function]') {
  3761. _result = type.represent(object, style);
  3762. } else if (_hasOwnProperty$3.call(type.represent, style)) {
  3763. _result = type.represent[style](object, style);
  3764. } else {
  3765. throw new exception('!<' + type.tag + '> tag resolver accepts not "' + style + '" style');
  3766. }
  3767. state.dump = _result;
  3768. }
  3769. return true;
  3770. }
  3771. }
  3772. return false;
  3773. }
  3774. // Serializes `object` and writes it to global `result`.
  3775. // Returns true on success, or false on invalid object.
  3776. //
  3777. function writeNode(state, level, object, block, compact, iskey) {
  3778. state.tag = null;
  3779. state.dump = object;
  3780. if (!detectType(state, object, false)) {
  3781. detectType(state, object, true);
  3782. }
  3783. var type = _toString$2.call(state.dump);
  3784. if (block) {
  3785. block = (state.flowLevel < 0 || state.flowLevel > level);
  3786. }
  3787. var objectOrArray = type === '[object Object]' || type === '[object Array]',
  3788. duplicateIndex,
  3789. duplicate;
  3790. if (objectOrArray) {
  3791. duplicateIndex = state.duplicates.indexOf(object);
  3792. duplicate = duplicateIndex !== -1;
  3793. }
  3794. if ((state.tag !== null && state.tag !== '?') || duplicate || (state.indent !== 2 && level > 0)) {
  3795. compact = false;
  3796. }
  3797. if (duplicate && state.usedDuplicates[duplicateIndex]) {
  3798. state.dump = '*ref_' + duplicateIndex;
  3799. } else {
  3800. if (objectOrArray && duplicate && !state.usedDuplicates[duplicateIndex]) {
  3801. state.usedDuplicates[duplicateIndex] = true;
  3802. }
  3803. if (type === '[object Object]') {
  3804. if (block && (Object.keys(state.dump).length !== 0)) {
  3805. writeBlockMapping(state, level, state.dump, compact);
  3806. if (duplicate) {
  3807. state.dump = '&ref_' + duplicateIndex + state.dump;
  3808. }
  3809. } else {
  3810. writeFlowMapping(state, level, state.dump);
  3811. if (duplicate) {
  3812. state.dump = '&ref_' + duplicateIndex + ' ' + state.dump;
  3813. }
  3814. }
  3815. } else if (type === '[object Array]') {
  3816. if (block && (state.dump.length !== 0)) {
  3817. writeBlockSequence(state, level, state.dump, compact);
  3818. if (duplicate) {
  3819. state.dump = '&ref_' + duplicateIndex + state.dump;
  3820. }
  3821. } else {
  3822. writeFlowSequence(state, level, state.dump);
  3823. if (duplicate) {
  3824. state.dump = '&ref_' + duplicateIndex + ' ' + state.dump;
  3825. }
  3826. }
  3827. } else if (type === '[object String]') {
  3828. if (state.tag !== '?') {
  3829. writeScalar(state, state.dump, level, iskey);
  3830. }
  3831. } else {
  3832. if (state.skipInvalid) return false;
  3833. throw new exception('unacceptable kind of an object to dump ' + type);
  3834. }
  3835. if (state.tag !== null && state.tag !== '?') {
  3836. state.dump = '!<' + state.tag + '> ' + state.dump;
  3837. }
  3838. }
  3839. return true;
  3840. }
  3841. function getDuplicateReferences(object, state) {
  3842. var objects = [],
  3843. duplicatesIndexes = [],
  3844. index,
  3845. length;
  3846. inspectNode(object, objects, duplicatesIndexes);
  3847. for (index = 0, length = duplicatesIndexes.length; index < length; index += 1) {
  3848. state.duplicates.push(objects[duplicatesIndexes[index]]);
  3849. }
  3850. state.usedDuplicates = new Array(length);
  3851. }
  3852. function inspectNode(object, objects, duplicatesIndexes) {
  3853. var objectKeyList,
  3854. index,
  3855. length;
  3856. if (object !== null && typeof object === 'object') {
  3857. index = objects.indexOf(object);
  3858. if (index !== -1) {
  3859. if (duplicatesIndexes.indexOf(index) === -1) {
  3860. duplicatesIndexes.push(index);
  3861. }
  3862. } else {
  3863. objects.push(object);
  3864. if (Array.isArray(object)) {
  3865. for (index = 0, length = object.length; index < length; index += 1) {
  3866. inspectNode(object[index], objects, duplicatesIndexes);
  3867. }
  3868. } else {
  3869. objectKeyList = Object.keys(object);
  3870. for (index = 0, length = objectKeyList.length; index < length; index += 1) {
  3871. inspectNode(object[objectKeyList[index]], objects, duplicatesIndexes);
  3872. }
  3873. }
  3874. }
  3875. }
  3876. }
  3877. function dump$1(input, options) {
  3878. options = options || {};
  3879. var state = new State$1(options);
  3880. if (!state.noRefs) getDuplicateReferences(input, state);
  3881. if (writeNode(state, 0, input, true, true)) return state.dump + '\n';
  3882. return '';
  3883. }
  3884. function safeDump$1(input, options) {
  3885. return dump$1(input, common.extend({ schema: default_safe }, options));
  3886. }
  3887. var dump_1 = dump$1;
  3888. var safeDump_1 = safeDump$1;
  3889. var dumper = {
  3890. dump: dump_1,
  3891. safeDump: safeDump_1
  3892. };
  3893. function deprecated(name) {
  3894. return function () {
  3895. throw new Error('Function ' + name + ' is deprecated and cannot be used.');
  3896. };
  3897. }
  3898. var Type = type;
  3899. var Schema = schema;
  3900. var FAILSAFE_SCHEMA = failsafe;
  3901. var JSON_SCHEMA = json;
  3902. var CORE_SCHEMA = core;
  3903. var DEFAULT_SAFE_SCHEMA = default_safe;
  3904. var DEFAULT_FULL_SCHEMA = default_full;
  3905. var load = loader.load;
  3906. var loadAll = loader.loadAll;
  3907. var safeLoad = loader.safeLoad;
  3908. var safeLoadAll = loader.safeLoadAll;
  3909. var dump = dumper.dump;
  3910. var safeDump = dumper.safeDump;
  3911. var YAMLException = exception;
  3912. // Deprecated schema names from JS-YAML 2.0.x
  3913. var MINIMAL_SCHEMA = failsafe;
  3914. var SAFE_SCHEMA = default_safe;
  3915. var DEFAULT_SCHEMA = default_full;
  3916. // Deprecated functions from JS-YAML 1.x.x
  3917. var scan = deprecated('scan');
  3918. var parse = deprecated('parse');
  3919. var compose = deprecated('compose');
  3920. var addConstructor = deprecated('addConstructor');
  3921. var jsYaml$2 = {
  3922. Type: Type,
  3923. Schema: Schema,
  3924. FAILSAFE_SCHEMA: FAILSAFE_SCHEMA,
  3925. JSON_SCHEMA: JSON_SCHEMA,
  3926. CORE_SCHEMA: CORE_SCHEMA,
  3927. DEFAULT_SAFE_SCHEMA: DEFAULT_SAFE_SCHEMA,
  3928. DEFAULT_FULL_SCHEMA: DEFAULT_FULL_SCHEMA,
  3929. load: load,
  3930. loadAll: loadAll,
  3931. safeLoad: safeLoad,
  3932. safeLoadAll: safeLoadAll,
  3933. dump: dump,
  3934. safeDump: safeDump,
  3935. YAMLException: YAMLException,
  3936. MINIMAL_SCHEMA: MINIMAL_SCHEMA,
  3937. SAFE_SCHEMA: SAFE_SCHEMA,
  3938. DEFAULT_SCHEMA: DEFAULT_SCHEMA,
  3939. scan: scan,
  3940. parse: parse,
  3941. compose: compose,
  3942. addConstructor: addConstructor
  3943. };
  3944. var jsYaml = jsYaml$2;
  3945. var requireFromString = createCommonjsModule(function (module) {
  3946. 'use strict';
  3947. module.exports = function requireFromString(code, filename, opts) {
  3948. if (typeof filename === 'object') {
  3949. opts = filename;
  3950. filename = undefined;
  3951. }
  3952. opts = opts || {};
  3953. filename = filename || '';
  3954. opts.appendPaths = opts.appendPaths || [];
  3955. opts.prependPaths = opts.prependPaths || [];
  3956. if (typeof code !== 'string') {
  3957. throw new Error('code must be a string, not ' + typeof code);
  3958. }
  3959. var paths = module$1._nodeModulePaths(path.dirname(filename));
  3960. var parent = (module.parent || module);
  3961. var m = new module$1(filename, parent);
  3962. m.filename = filename;
  3963. m.paths = [].concat(opts.prependPaths).concat(paths).concat(opts.appendPaths);
  3964. m._compile(code, filename);
  3965. var exports = m.exports;
  3966. parent.children && parent.children.splice(parent.children.indexOf(m), 1);
  3967. return exports;
  3968. };
  3969. });
  3970. //
  3971. const chainFuncsAsync = (result, func) => result.then(func);
  3972. const chainFuncsSync = (result, func) => func(result);
  3973. /**
  3974. * Runs the given functions sequentially. If the `init` param is a promise,
  3975. * functions are chained using `p.then()`. Otherwise, functions are chained by passing
  3976. * the result of each function to the next.
  3977. */
  3978. var funcRunner = function funcRunner(
  3979. init ,
  3980. funcs
  3981. ) {
  3982. const isAsync = init instanceof Promise;
  3983. return funcs.reduce(
  3984. isAsync === true ? chainFuncsAsync : chainFuncsSync,
  3985. init
  3986. );
  3987. };
  3988. var loadRc = function loadRc(
  3989. filepath ,
  3990. options
  3991. ) {
  3992. if (!options.sync) {
  3993. return readFile_1(filepath)
  3994. .then(parseExtensionlessRcFile)
  3995. .then(checkExtensionlessRcResult);
  3996. } else {
  3997. return checkExtensionlessRcResult(
  3998. parseExtensionlessRcFile(readFile_1.sync(filepath))
  3999. );
  4000. }
  4001. function checkExtensionlessRcResult(result) {
  4002. if (result) return result;
  4003. if (options.rcExtensions) return loadRcWithExtensions();
  4004. return null;
  4005. }
  4006. function parseExtensionlessRcFile(content ) {
  4007. if (!content) return null;
  4008. const pasedConfig = options.rcStrictJson
  4009. ? parseJson_1(content, filepath)
  4010. : jsYaml.safeLoad(content, { filename: filepath });
  4011. return {
  4012. config: pasedConfig,
  4013. filepath,
  4014. };
  4015. }
  4016. function loadRcWithExtensions() {
  4017. let foundConfig = null;
  4018. return funcRunner(readRcFile('json'), [
  4019. (jsonContent ) => {
  4020. // Since this is the first try, config cannot have been found, so don't
  4021. // check `if (foundConfig)`.
  4022. if (jsonContent) {
  4023. const successFilepath = `${filepath}.json`;
  4024. foundConfig = {
  4025. config: parseJson_1(jsonContent, successFilepath),
  4026. filepath: successFilepath,
  4027. };
  4028. } else {
  4029. return readRcFile('yaml');
  4030. }
  4031. },
  4032. (yamlContent ) => {
  4033. if (foundConfig) {
  4034. return;
  4035. } else if (yamlContent) {
  4036. const successFilepath = `${filepath}.yaml`;
  4037. foundConfig = {
  4038. config: jsYaml.safeLoad(yamlContent, { filename: successFilepath }),
  4039. filepath: successFilepath,
  4040. };
  4041. } else {
  4042. return readRcFile('yml');
  4043. }
  4044. },
  4045. (ymlContent ) => {
  4046. if (foundConfig) {
  4047. return;
  4048. } else if (ymlContent) {
  4049. const successFilepath = `${filepath}.yml`;
  4050. foundConfig = {
  4051. config: jsYaml.safeLoad(ymlContent, { filename: successFilepath }),
  4052. filepath: successFilepath,
  4053. };
  4054. } else {
  4055. return readRcFile('js');
  4056. }
  4057. },
  4058. (jsContent ) => {
  4059. if (foundConfig) {
  4060. return;
  4061. } else if (jsContent) {
  4062. const successFilepath = `${filepath}.js`;
  4063. foundConfig = {
  4064. config: requireFromString(jsContent, successFilepath),
  4065. filepath: successFilepath,
  4066. };
  4067. } else {
  4068. return;
  4069. }
  4070. },
  4071. () => foundConfig,
  4072. ]);
  4073. }
  4074. function readRcFile(extension ) {
  4075. const filepathWithExtension = `${filepath}.${extension}`;
  4076. return !options.sync
  4077. ? readFile_1(filepathWithExtension)
  4078. : readFile_1.sync(filepathWithExtension);
  4079. }
  4080. };
  4081. var loadJs = function loadJs(
  4082. filepath ,
  4083. options
  4084. ) {
  4085. function parseJsFile(content ) {
  4086. if (!content) return null;
  4087. return {
  4088. config: requireFromString(content, filepath),
  4089. filepath,
  4090. };
  4091. }
  4092. return !options.sync
  4093. ? readFile_1(filepath).then(parseJsFile)
  4094. : parseJsFile(readFile_1.sync(filepath));
  4095. };
  4096. var loadDefinedFile = function loadDefinedFile(
  4097. filepath ,
  4098. options
  4099. ) {
  4100. function parseContent(content ) {
  4101. if (!content) {
  4102. throw new Error(`Config file is empty! Filepath - "${filepath}".`);
  4103. }
  4104. let parsedConfig;
  4105. switch (options.format || inferFormat(filepath)) {
  4106. case 'json':
  4107. parsedConfig = parseJson_1(content, filepath);
  4108. break;
  4109. case 'yaml':
  4110. parsedConfig = jsYaml.safeLoad(content, {
  4111. filename: filepath,
  4112. });
  4113. break;
  4114. case 'js':
  4115. parsedConfig = requireFromString(content, filepath);
  4116. break;
  4117. default:
  4118. parsedConfig = tryAllParsing(content, filepath);
  4119. }
  4120. if (!parsedConfig) {
  4121. throw new Error(`Failed to parse "${filepath}" as JSON, JS, or YAML.`);
  4122. }
  4123. return {
  4124. config: parsedConfig,
  4125. filepath,
  4126. };
  4127. }
  4128. return !options.sync
  4129. ? readFile_1(filepath, { throwNotFound: true }).then(parseContent)
  4130. : parseContent(readFile_1.sync(filepath, { throwNotFound: true }));
  4131. };
  4132. function inferFormat(filepath ) {
  4133. switch (path.extname(filepath)) {
  4134. case '.js':
  4135. return 'js';
  4136. case '.json':
  4137. return 'json';
  4138. // istanbul ignore next
  4139. case '.yml':
  4140. case '.yaml':
  4141. return 'yaml';
  4142. default:
  4143. return undefined;
  4144. }
  4145. }
  4146. function tryAllParsing(content , filepath ) {
  4147. return tryYaml(content, filepath, () => {
  4148. return tryRequire(content, filepath, () => {
  4149. return null;
  4150. });
  4151. });
  4152. }
  4153. function tryYaml(content , filepath , cb ) {
  4154. try {
  4155. const result = jsYaml.safeLoad(content, {
  4156. filename: filepath,
  4157. });
  4158. if (typeof result === 'string') {
  4159. return cb();
  4160. }
  4161. return result;
  4162. } catch (e) {
  4163. return cb();
  4164. }
  4165. }
  4166. function tryRequire(content , filepath , cb ) {
  4167. try {
  4168. return requireFromString(content, filepath);
  4169. } catch (e) {
  4170. return cb();
  4171. }
  4172. }
  4173. /**
  4174. * async
  4175. */
  4176. function isDirectory(filepath, cb) {
  4177. if (typeof cb !== 'function') {
  4178. throw new Error('expected a callback function');
  4179. }
  4180. if (typeof filepath !== 'string') {
  4181. cb(new Error('expected filepath to be a string'));
  4182. return;
  4183. }
  4184. fs.stat(filepath, function(err, stats) {
  4185. if (err) {
  4186. if (err.code === 'ENOENT') {
  4187. cb(null, false);
  4188. return;
  4189. }
  4190. cb(err);
  4191. return;
  4192. }
  4193. cb(null, stats.isDirectory());
  4194. });
  4195. }
  4196. /**
  4197. * sync
  4198. */
  4199. isDirectory.sync = function isDirectorySync(filepath) {
  4200. if (typeof filepath !== 'string') {
  4201. throw new Error('expected filepath to be a string');
  4202. }
  4203. try {
  4204. var stat = fs.statSync(filepath);
  4205. return stat.isDirectory();
  4206. } catch (err) {
  4207. if (err.code === 'ENOENT') {
  4208. return false;
  4209. } else {
  4210. throw err;
  4211. }
  4212. }
  4213. return false;
  4214. };
  4215. /**
  4216. * Expose `isDirectory`
  4217. */
  4218. var isDirectory_1 = isDirectory;
  4219. var getDirectory = function getDirectory(
  4220. filepath ,
  4221. sync
  4222. ) {
  4223. if (sync === true) {
  4224. return isDirectory_1.sync(filepath) ? filepath : path.dirname(filepath);
  4225. }
  4226. return new Promise((resolve, reject) => {
  4227. return isDirectory_1(filepath, (err, filepathIsDirectory) => {
  4228. if (err) {
  4229. return reject(err);
  4230. }
  4231. return resolve(filepathIsDirectory ? filepath : path.dirname(filepath));
  4232. });
  4233. });
  4234. };
  4235. var createExplorer = function createExplorer(options
  4236. ) {
  4237. // When `options.sync` is `false` (default),
  4238. // these cache Promises that resolve with results, not the results themselves.
  4239. const fileCache = options.cache ? new Map() : null;
  4240. const directoryCache = options.cache ? new Map() : null;
  4241. const transform = options.transform || identity;
  4242. const packageProp = options.packageProp;
  4243. function clearFileCache() {
  4244. if (fileCache) fileCache.clear();
  4245. }
  4246. function clearDirectoryCache() {
  4247. if (directoryCache) directoryCache.clear();
  4248. }
  4249. function clearCaches() {
  4250. clearFileCache();
  4251. clearDirectoryCache();
  4252. }
  4253. function throwError(error) {
  4254. if (options.sync) {
  4255. throw error;
  4256. } else {
  4257. return Promise.reject(error);
  4258. }
  4259. }
  4260. function load(
  4261. searchPath ,
  4262. configPath
  4263. ) {
  4264. if (!configPath && options.configPath) {
  4265. configPath = options.configPath;
  4266. }
  4267. if (configPath) {
  4268. const absoluteConfigPath = path.resolve(process.cwd(), configPath);
  4269. if (fileCache && fileCache.has(absoluteConfigPath)) {
  4270. return fileCache.get(absoluteConfigPath);
  4271. }
  4272. let load;
  4273. if (path.basename(absoluteConfigPath) === 'package.json') {
  4274. if (!packageProp) {
  4275. return throwError(
  4276. new Error(
  4277. 'Please specify the packageProp option. The configPath argument cannot point to a package.json file if packageProp is false.'
  4278. )
  4279. );
  4280. }
  4281. load = () =>
  4282. loadPackageProp(path.dirname(absoluteConfigPath), {
  4283. packageProp,
  4284. sync: options.sync,
  4285. });
  4286. } else {
  4287. load = () =>
  4288. loadDefinedFile(absoluteConfigPath, {
  4289. sync: options.sync,
  4290. format: options.format,
  4291. });
  4292. }
  4293. const loadResult = load();
  4294. const result =
  4295. loadResult instanceof Promise
  4296. ? loadResult.then(transform)
  4297. : transform(loadResult);
  4298. if (fileCache) fileCache.set(absoluteConfigPath, result);
  4299. return result;
  4300. }
  4301. if (!searchPath) return !options.sync ? Promise.resolve(null) : null;
  4302. const absoluteSearchPath = path.resolve(process.cwd(), searchPath);
  4303. const searchPathDir = getDirectory(absoluteSearchPath, options.sync);
  4304. return searchPathDir instanceof Promise
  4305. ? searchPathDir.then(searchDirectory)
  4306. : searchDirectory(searchPathDir);
  4307. }
  4308. function searchDirectory(
  4309. directory
  4310. ) {
  4311. if (directoryCache && directoryCache.has(directory)) {
  4312. return directoryCache.get(directory);
  4313. }
  4314. const result = funcRunner(!options.sync ? Promise.resolve() : undefined, [
  4315. () => {
  4316. if (!packageProp) return;
  4317. return loadPackageProp(directory, {
  4318. packageProp,
  4319. sync: options.sync,
  4320. });
  4321. },
  4322. result => {
  4323. if (result || !options.rc) return result;
  4324. return loadRc(path.join(directory, options.rc), {
  4325. sync: options.sync,
  4326. rcStrictJson: options.rcStrictJson,
  4327. rcExtensions: options.rcExtensions,
  4328. });
  4329. },
  4330. result => {
  4331. if (result || !options.js) return result;
  4332. return loadJs(path.join(directory, options.js), { sync: options.sync });
  4333. },
  4334. result => {
  4335. if (result) return result;
  4336. const nextDirectory = path.dirname(directory);
  4337. if (nextDirectory === directory || directory === options.stopDir)
  4338. return null;
  4339. return searchDirectory(nextDirectory);
  4340. },
  4341. transform,
  4342. ]);
  4343. if (directoryCache) directoryCache.set(directory, result);
  4344. return result;
  4345. }
  4346. return {
  4347. load,
  4348. clearFileCache,
  4349. clearDirectoryCache,
  4350. clearCaches,
  4351. };
  4352. };
  4353. function identity(x) {
  4354. return x;
  4355. }
  4356. const homedir = os.homedir();
  4357. var dist = function cosmiconfig(
  4358. moduleName ,
  4359. options
  4360. ) {
  4361. options = Object.assign(
  4362. {},
  4363. {
  4364. packageProp: moduleName,
  4365. rc: `.${moduleName}rc`,
  4366. js: `${moduleName}.config.js`,
  4367. rcStrictJson: false,
  4368. stopDir: homedir,
  4369. cache: true,
  4370. sync: false,
  4371. },
  4372. options
  4373. );
  4374. return createExplorer(options);
  4375. };
  4376. var thirdParty = {
  4377. getStream: getStream_1,
  4378. cosmiconfig: dist
  4379. };
  4380. module.exports = thirdParty;