third-party.js 135 KB

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