third-party.js 148 KB

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