js-yaml.js 100 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858
  1. /* js-yaml 3.5.5 https://github.com/nodeca/js-yaml */(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.jsyaml = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  2. 'use strict';
  3. var loader = require('./js-yaml/loader');
  4. var dumper = require('./js-yaml/dumper');
  5. function deprecated(name) {
  6. return function () {
  7. throw new Error('Function ' + name + ' is deprecated and cannot be used.');
  8. };
  9. }
  10. module.exports.Type = require('./js-yaml/type');
  11. module.exports.Schema = require('./js-yaml/schema');
  12. module.exports.FAILSAFE_SCHEMA = require('./js-yaml/schema/failsafe');
  13. module.exports.JSON_SCHEMA = require('./js-yaml/schema/json');
  14. module.exports.CORE_SCHEMA = require('./js-yaml/schema/core');
  15. module.exports.DEFAULT_SAFE_SCHEMA = require('./js-yaml/schema/default_safe');
  16. module.exports.DEFAULT_FULL_SCHEMA = require('./js-yaml/schema/default_full');
  17. module.exports.load = loader.load;
  18. module.exports.loadAll = loader.loadAll;
  19. module.exports.safeLoad = loader.safeLoad;
  20. module.exports.safeLoadAll = loader.safeLoadAll;
  21. module.exports.dump = dumper.dump;
  22. module.exports.safeDump = dumper.safeDump;
  23. module.exports.YAMLException = require('./js-yaml/exception');
  24. // Deprecated schema names from JS-YAML 2.0.x
  25. module.exports.MINIMAL_SCHEMA = require('./js-yaml/schema/failsafe');
  26. module.exports.SAFE_SCHEMA = require('./js-yaml/schema/default_safe');
  27. module.exports.DEFAULT_SCHEMA = require('./js-yaml/schema/default_full');
  28. // Deprecated functions from JS-YAML 1.x.x
  29. module.exports.scan = deprecated('scan');
  30. module.exports.parse = deprecated('parse');
  31. module.exports.compose = deprecated('compose');
  32. module.exports.addConstructor = deprecated('addConstructor');
  33. },{"./js-yaml/dumper":3,"./js-yaml/exception":4,"./js-yaml/loader":5,"./js-yaml/schema":7,"./js-yaml/schema/core":8,"./js-yaml/schema/default_full":9,"./js-yaml/schema/default_safe":10,"./js-yaml/schema/failsafe":11,"./js-yaml/schema/json":12,"./js-yaml/type":13}],2:[function(require,module,exports){
  34. 'use strict';
  35. function isNothing(subject) {
  36. return (typeof subject === 'undefined') || (subject === null);
  37. }
  38. function isObject(subject) {
  39. return (typeof subject === 'object') && (subject !== null);
  40. }
  41. function toArray(sequence) {
  42. if (Array.isArray(sequence)) return sequence;
  43. else if (isNothing(sequence)) return [];
  44. return [ sequence ];
  45. }
  46. function extend(target, source) {
  47. var index, length, key, sourceKeys;
  48. if (source) {
  49. sourceKeys = Object.keys(source);
  50. for (index = 0, length = sourceKeys.length; index < length; index += 1) {
  51. key = sourceKeys[index];
  52. target[key] = source[key];
  53. }
  54. }
  55. return target;
  56. }
  57. function repeat(string, count) {
  58. var result = '', cycle;
  59. for (cycle = 0; cycle < count; cycle += 1) {
  60. result += string;
  61. }
  62. return result;
  63. }
  64. function isNegativeZero(number) {
  65. return (number === 0) && (Number.NEGATIVE_INFINITY === 1 / number);
  66. }
  67. module.exports.isNothing = isNothing;
  68. module.exports.isObject = isObject;
  69. module.exports.toArray = toArray;
  70. module.exports.repeat = repeat;
  71. module.exports.isNegativeZero = isNegativeZero;
  72. module.exports.extend = extend;
  73. },{}],3:[function(require,module,exports){
  74. 'use strict';
  75. /*eslint-disable no-use-before-define*/
  76. var common = require('./common');
  77. var YAMLException = require('./exception');
  78. var DEFAULT_FULL_SCHEMA = require('./schema/default_full');
  79. var DEFAULT_SAFE_SCHEMA = require('./schema/default_safe');
  80. var _toString = Object.prototype.toString;
  81. var _hasOwnProperty = Object.prototype.hasOwnProperty;
  82. var CHAR_TAB = 0x09; /* Tab */
  83. var CHAR_LINE_FEED = 0x0A; /* LF */
  84. var CHAR_CARRIAGE_RETURN = 0x0D; /* CR */
  85. var CHAR_SPACE = 0x20; /* Space */
  86. var CHAR_EXCLAMATION = 0x21; /* ! */
  87. var CHAR_DOUBLE_QUOTE = 0x22; /* " */
  88. var CHAR_SHARP = 0x23; /* # */
  89. var CHAR_PERCENT = 0x25; /* % */
  90. var CHAR_AMPERSAND = 0x26; /* & */
  91. var CHAR_SINGLE_QUOTE = 0x27; /* ' */
  92. var CHAR_ASTERISK = 0x2A; /* * */
  93. var CHAR_COMMA = 0x2C; /* , */
  94. var CHAR_MINUS = 0x2D; /* - */
  95. var CHAR_COLON = 0x3A; /* : */
  96. var CHAR_GREATER_THAN = 0x3E; /* > */
  97. var CHAR_QUESTION = 0x3F; /* ? */
  98. var CHAR_COMMERCIAL_AT = 0x40; /* @ */
  99. var CHAR_LEFT_SQUARE_BRACKET = 0x5B; /* [ */
  100. var CHAR_RIGHT_SQUARE_BRACKET = 0x5D; /* ] */
  101. var CHAR_GRAVE_ACCENT = 0x60; /* ` */
  102. var CHAR_LEFT_CURLY_BRACKET = 0x7B; /* { */
  103. var CHAR_VERTICAL_LINE = 0x7C; /* | */
  104. var CHAR_RIGHT_CURLY_BRACKET = 0x7D; /* } */
  105. var ESCAPE_SEQUENCES = {};
  106. ESCAPE_SEQUENCES[0x00] = '\\0';
  107. ESCAPE_SEQUENCES[0x07] = '\\a';
  108. ESCAPE_SEQUENCES[0x08] = '\\b';
  109. ESCAPE_SEQUENCES[0x09] = '\\t';
  110. ESCAPE_SEQUENCES[0x0A] = '\\n';
  111. ESCAPE_SEQUENCES[0x0B] = '\\v';
  112. ESCAPE_SEQUENCES[0x0C] = '\\f';
  113. ESCAPE_SEQUENCES[0x0D] = '\\r';
  114. ESCAPE_SEQUENCES[0x1B] = '\\e';
  115. ESCAPE_SEQUENCES[0x22] = '\\"';
  116. ESCAPE_SEQUENCES[0x5C] = '\\\\';
  117. ESCAPE_SEQUENCES[0x85] = '\\N';
  118. ESCAPE_SEQUENCES[0xA0] = '\\_';
  119. ESCAPE_SEQUENCES[0x2028] = '\\L';
  120. ESCAPE_SEQUENCES[0x2029] = '\\P';
  121. var DEPRECATED_BOOLEANS_SYNTAX = [
  122. 'y', 'Y', 'yes', 'Yes', 'YES', 'on', 'On', 'ON',
  123. 'n', 'N', 'no', 'No', 'NO', 'off', 'Off', 'OFF'
  124. ];
  125. function compileStyleMap(schema, map) {
  126. var result, keys, index, length, tag, style, type;
  127. if (map === null) return {};
  128. result = {};
  129. keys = Object.keys(map);
  130. for (index = 0, length = keys.length; index < length; index += 1) {
  131. tag = keys[index];
  132. style = String(map[tag]);
  133. if (tag.slice(0, 2) === '!!') {
  134. tag = 'tag:yaml.org,2002:' + tag.slice(2);
  135. }
  136. type = schema.compiledTypeMap[tag];
  137. if (type && _hasOwnProperty.call(type.styleAliases, style)) {
  138. style = type.styleAliases[style];
  139. }
  140. result[tag] = style;
  141. }
  142. return result;
  143. }
  144. function encodeHex(character) {
  145. var string, handle, length;
  146. string = character.toString(16).toUpperCase();
  147. if (character <= 0xFF) {
  148. handle = 'x';
  149. length = 2;
  150. } else if (character <= 0xFFFF) {
  151. handle = 'u';
  152. length = 4;
  153. } else if (character <= 0xFFFFFFFF) {
  154. handle = 'U';
  155. length = 8;
  156. } else {
  157. throw new YAMLException('code point within a string may not be greater than 0xFFFFFFFF');
  158. }
  159. return '\\' + handle + common.repeat('0', length - string.length) + string;
  160. }
  161. function State(options) {
  162. this.schema = options['schema'] || DEFAULT_FULL_SCHEMA;
  163. this.indent = Math.max(1, (options['indent'] || 2));
  164. this.skipInvalid = options['skipInvalid'] || false;
  165. this.flowLevel = (common.isNothing(options['flowLevel']) ? -1 : options['flowLevel']);
  166. this.styleMap = compileStyleMap(this.schema, options['styles'] || null);
  167. this.sortKeys = options['sortKeys'] || false;
  168. this.lineWidth = options['lineWidth'] || 80;
  169. this.noRefs = options['noRefs'] || false;
  170. this.noCompatMode = options['noCompatMode'] || false;
  171. this.implicitTypes = this.schema.compiledImplicit;
  172. this.explicitTypes = this.schema.compiledExplicit;
  173. this.tag = null;
  174. this.result = '';
  175. this.duplicates = [];
  176. this.usedDuplicates = null;
  177. }
  178. function indentString(string, spaces) {
  179. var ind = common.repeat(' ', spaces),
  180. position = 0,
  181. next = -1,
  182. result = '',
  183. line,
  184. length = string.length;
  185. while (position < length) {
  186. next = string.indexOf('\n', position);
  187. if (next === -1) {
  188. line = string.slice(position);
  189. position = length;
  190. } else {
  191. line = string.slice(position, next + 1);
  192. position = next + 1;
  193. }
  194. if (line.length && line !== '\n') result += ind;
  195. result += line;
  196. }
  197. return result;
  198. }
  199. function generateNextLine(state, level) {
  200. return '\n' + common.repeat(' ', state.indent * level);
  201. }
  202. function testImplicitResolving(state, str) {
  203. var index, length, type;
  204. for (index = 0, length = state.implicitTypes.length; index < length; index += 1) {
  205. type = state.implicitTypes[index];
  206. if (type.resolve(str)) {
  207. return true;
  208. }
  209. }
  210. return false;
  211. }
  212. function StringBuilder(source) {
  213. this.source = source;
  214. this.result = '';
  215. this.checkpoint = 0;
  216. }
  217. StringBuilder.prototype.takeUpTo = function (position) {
  218. var er;
  219. if (position < this.checkpoint) {
  220. er = new Error('position should be > checkpoint');
  221. er.position = position;
  222. er.checkpoint = this.checkpoint;
  223. throw er;
  224. }
  225. this.result += this.source.slice(this.checkpoint, position);
  226. this.checkpoint = position;
  227. return this;
  228. };
  229. StringBuilder.prototype.escapeChar = function () {
  230. var character, esc;
  231. character = this.source.charCodeAt(this.checkpoint);
  232. esc = ESCAPE_SEQUENCES[character] || encodeHex(character);
  233. this.result += esc;
  234. this.checkpoint += 1;
  235. return this;
  236. };
  237. StringBuilder.prototype.finish = function () {
  238. if (this.source.length > this.checkpoint) {
  239. this.takeUpTo(this.source.length);
  240. }
  241. };
  242. function writeScalar(state, object, level, iskey) {
  243. var simple, first, spaceWrap, folded, literal, single, double,
  244. sawLineFeed, linePosition, longestLine, indent, max, character,
  245. position, escapeSeq, hexEsc, previous, lineLength, modifier,
  246. trailingLineBreaks, result;
  247. if (object.length === 0) {
  248. state.dump = "''";
  249. return;
  250. }
  251. if (!state.noCompatMode &&
  252. DEPRECATED_BOOLEANS_SYNTAX.indexOf(object) !== -1) {
  253. state.dump = "'" + object + "'";
  254. return;
  255. }
  256. simple = true;
  257. first = object.length ? object.charCodeAt(0) : 0;
  258. spaceWrap = (CHAR_SPACE === first ||
  259. CHAR_SPACE === object.charCodeAt(object.length - 1));
  260. // Simplified check for restricted first characters
  261. // http://www.yaml.org/spec/1.2/spec.html#ns-plain-first%28c%29
  262. if (CHAR_MINUS === first ||
  263. CHAR_QUESTION === first ||
  264. CHAR_COMMERCIAL_AT === first ||
  265. CHAR_GRAVE_ACCENT === first) {
  266. simple = false;
  267. }
  268. // Can only use > and | if not wrapped in spaces or is not a key.
  269. // Also, don't use if in flow mode.
  270. if (spaceWrap || (state.flowLevel > -1 && state.flowLevel <= level)) {
  271. if (spaceWrap) simple = false;
  272. folded = false;
  273. literal = false;
  274. } else {
  275. folded = !iskey;
  276. literal = !iskey;
  277. }
  278. single = true;
  279. double = new StringBuilder(object);
  280. sawLineFeed = false;
  281. linePosition = 0;
  282. longestLine = 0;
  283. indent = state.indent * level;
  284. max = state.lineWidth;
  285. // Replace -1 with biggest ingeger number according to
  286. // http://ecma262-5.com/ELS5_HTML.htm#Section_8.5
  287. if (max === -1) max = 9007199254740991;
  288. if (indent < 40) max -= indent;
  289. else max = 40;
  290. for (position = 0; position < object.length; position++) {
  291. character = object.charCodeAt(position);
  292. if (simple) {
  293. // Characters that can never appear in the simple scalar
  294. if (!simpleChar(character)) {
  295. simple = false;
  296. } else {
  297. // Still simple. If we make it all the way through like
  298. // this, then we can just dump the string as-is.
  299. continue;
  300. }
  301. }
  302. if (single && character === CHAR_SINGLE_QUOTE) {
  303. single = false;
  304. }
  305. escapeSeq = ESCAPE_SEQUENCES[character];
  306. hexEsc = needsHexEscape(character);
  307. if (!escapeSeq && !hexEsc) {
  308. continue;
  309. }
  310. if (character !== CHAR_LINE_FEED &&
  311. character !== CHAR_DOUBLE_QUOTE &&
  312. character !== CHAR_SINGLE_QUOTE) {
  313. folded = false;
  314. literal = false;
  315. } else if (character === CHAR_LINE_FEED) {
  316. sawLineFeed = true;
  317. single = false;
  318. if (position > 0) {
  319. previous = object.charCodeAt(position - 1);
  320. if (previous === CHAR_SPACE) {
  321. literal = false;
  322. folded = false;
  323. }
  324. }
  325. if (folded) {
  326. lineLength = position - linePosition;
  327. linePosition = position;
  328. if (lineLength > longestLine) longestLine = lineLength;
  329. }
  330. }
  331. if (character !== CHAR_DOUBLE_QUOTE) single = false;
  332. double.takeUpTo(position);
  333. double.escapeChar();
  334. }
  335. if (simple && testImplicitResolving(state, object)) simple = false;
  336. modifier = '';
  337. if (folded || literal) {
  338. trailingLineBreaks = 0;
  339. if (object.charCodeAt(object.length - 1) === CHAR_LINE_FEED) {
  340. trailingLineBreaks += 1;
  341. if (object.charCodeAt(object.length - 2) === CHAR_LINE_FEED) {
  342. trailingLineBreaks += 1;
  343. }
  344. }
  345. if (trailingLineBreaks === 0) modifier = '-';
  346. else if (trailingLineBreaks === 2) modifier = '+';
  347. }
  348. if (literal && longestLine < max || state.tag !== null) {
  349. folded = false;
  350. }
  351. // If it's literally one line, then don't bother with the literal.
  352. // We may still want to do a fold, though, if it's a super long line.
  353. if (!sawLineFeed) literal = false;
  354. if (simple) {
  355. state.dump = object;
  356. } else if (single) {
  357. state.dump = '\'' + object + '\'';
  358. } else if (folded) {
  359. result = fold(object, max);
  360. state.dump = '>' + modifier + '\n' + indentString(result, indent);
  361. } else if (literal) {
  362. if (!modifier) object = object.replace(/\n$/, '');
  363. state.dump = '|' + modifier + '\n' + indentString(object, indent);
  364. } else if (double) {
  365. double.finish();
  366. state.dump = '"' + double.result + '"';
  367. } else {
  368. throw new Error('Failed to dump scalar value');
  369. }
  370. return;
  371. }
  372. // The `trailing` var is a regexp match of any trailing `\n` characters.
  373. //
  374. // There are three cases we care about:
  375. //
  376. // 1. One trailing `\n` on the string. Just use `|` or `>`.
  377. // This is the assumed default. (trailing = null)
  378. // 2. No trailing `\n` on the string. Use `|-` or `>-` to "chomp" the end.
  379. // 3. More than one trailing `\n` on the string. Use `|+` or `>+`.
  380. //
  381. // In the case of `>+`, these line breaks are *not* doubled (like the line
  382. // breaks within the string), so it's important to only end with the exact
  383. // same number as we started.
  384. function fold(object, max) {
  385. var result = '',
  386. position = 0,
  387. length = object.length,
  388. trailing = /\n+$/.exec(object),
  389. newLine;
  390. if (trailing) {
  391. length = trailing.index + 1;
  392. }
  393. while (position < length) {
  394. newLine = object.indexOf('\n', position);
  395. if (newLine > length || newLine === -1) {
  396. if (result) result += '\n\n';
  397. result += foldLine(object.slice(position, length), max);
  398. position = length;
  399. } else {
  400. if (result) result += '\n\n';
  401. result += foldLine(object.slice(position, newLine), max);
  402. position = newLine + 1;
  403. }
  404. }
  405. if (trailing && trailing[0] !== '\n') result += trailing[0];
  406. return result;
  407. }
  408. function foldLine(line, max) {
  409. if (line === '') return line;
  410. var foldRe = /[^\s] [^\s]/g,
  411. result = '',
  412. prevMatch = 0,
  413. foldStart = 0,
  414. match = foldRe.exec(line),
  415. index,
  416. foldEnd,
  417. folded;
  418. while (match) {
  419. index = match.index;
  420. // when we cross the max len, if the previous match would've
  421. // been ok, use that one, and carry on. If there was no previous
  422. // match on this fold section, then just have a long line.
  423. if (index - foldStart > max) {
  424. if (prevMatch !== foldStart) foldEnd = prevMatch;
  425. else foldEnd = index;
  426. if (result) result += '\n';
  427. folded = line.slice(foldStart, foldEnd);
  428. result += folded;
  429. foldStart = foldEnd + 1;
  430. }
  431. prevMatch = index + 1;
  432. match = foldRe.exec(line);
  433. }
  434. if (result) result += '\n';
  435. // if we end up with one last word at the end, then the last bit might
  436. // be slightly bigger than we wanted, because we exited out of the loop.
  437. if (foldStart !== prevMatch && line.length - foldStart > max) {
  438. result += line.slice(foldStart, prevMatch) + '\n' +
  439. line.slice(prevMatch + 1);
  440. } else {
  441. result += line.slice(foldStart);
  442. }
  443. return result;
  444. }
  445. // Returns true if character can be found in a simple scalar
  446. function simpleChar(character) {
  447. return CHAR_TAB !== character &&
  448. CHAR_LINE_FEED !== character &&
  449. CHAR_CARRIAGE_RETURN !== character &&
  450. CHAR_COMMA !== character &&
  451. CHAR_LEFT_SQUARE_BRACKET !== character &&
  452. CHAR_RIGHT_SQUARE_BRACKET !== character &&
  453. CHAR_LEFT_CURLY_BRACKET !== character &&
  454. CHAR_RIGHT_CURLY_BRACKET !== character &&
  455. CHAR_SHARP !== character &&
  456. CHAR_AMPERSAND !== character &&
  457. CHAR_ASTERISK !== character &&
  458. CHAR_EXCLAMATION !== character &&
  459. CHAR_VERTICAL_LINE !== character &&
  460. CHAR_GREATER_THAN !== character &&
  461. CHAR_SINGLE_QUOTE !== character &&
  462. CHAR_DOUBLE_QUOTE !== character &&
  463. CHAR_PERCENT !== character &&
  464. CHAR_COLON !== character &&
  465. !ESCAPE_SEQUENCES[character] &&
  466. !needsHexEscape(character);
  467. }
  468. // Returns true if the character code needs to be escaped.
  469. function needsHexEscape(character) {
  470. return !((0x00020 <= character && character <= 0x00007E) ||
  471. (character === 0x00085) ||
  472. (0x000A0 <= character && character <= 0x00D7FF) ||
  473. (0x0E000 <= character && character <= 0x00FFFD) ||
  474. (0x10000 <= character && character <= 0x10FFFF));
  475. }
  476. function writeFlowSequence(state, level, object) {
  477. var _result = '',
  478. _tag = state.tag,
  479. index,
  480. length;
  481. for (index = 0, length = object.length; index < length; index += 1) {
  482. // Write only valid elements.
  483. if (writeNode(state, level, object[index], false, false)) {
  484. if (index !== 0) _result += ', ';
  485. _result += state.dump;
  486. }
  487. }
  488. state.tag = _tag;
  489. state.dump = '[' + _result + ']';
  490. }
  491. function writeBlockSequence(state, level, object, compact) {
  492. var _result = '',
  493. _tag = state.tag,
  494. index,
  495. length;
  496. for (index = 0, length = object.length; index < length; index += 1) {
  497. // Write only valid elements.
  498. if (writeNode(state, level + 1, object[index], true, true)) {
  499. if (!compact || index !== 0) {
  500. _result += generateNextLine(state, level);
  501. }
  502. _result += '- ' + state.dump;
  503. }
  504. }
  505. state.tag = _tag;
  506. state.dump = _result || '[]'; // Empty sequence if no valid values.
  507. }
  508. function writeFlowMapping(state, level, object) {
  509. var _result = '',
  510. _tag = state.tag,
  511. objectKeyList = Object.keys(object),
  512. index,
  513. length,
  514. objectKey,
  515. objectValue,
  516. pairBuffer;
  517. for (index = 0, length = objectKeyList.length; index < length; index += 1) {
  518. pairBuffer = '';
  519. if (index !== 0) pairBuffer += ', ';
  520. objectKey = objectKeyList[index];
  521. objectValue = object[objectKey];
  522. if (!writeNode(state, level, objectKey, false, false)) {
  523. continue; // Skip this pair because of invalid key;
  524. }
  525. if (state.dump.length > 1024) pairBuffer += '? ';
  526. pairBuffer += state.dump + ': ';
  527. if (!writeNode(state, level, objectValue, false, false)) {
  528. continue; // Skip this pair because of invalid value.
  529. }
  530. pairBuffer += state.dump;
  531. // Both key and value are valid.
  532. _result += pairBuffer;
  533. }
  534. state.tag = _tag;
  535. state.dump = '{' + _result + '}';
  536. }
  537. function writeBlockMapping(state, level, object, compact) {
  538. var _result = '',
  539. _tag = state.tag,
  540. objectKeyList = Object.keys(object),
  541. index,
  542. length,
  543. objectKey,
  544. objectValue,
  545. explicitPair,
  546. pairBuffer;
  547. // Allow sorting keys so that the output file is deterministic
  548. if (state.sortKeys === true) {
  549. // Default sorting
  550. objectKeyList.sort();
  551. } else if (typeof state.sortKeys === 'function') {
  552. // Custom sort function
  553. objectKeyList.sort(state.sortKeys);
  554. } else if (state.sortKeys) {
  555. // Something is wrong
  556. throw new YAMLException('sortKeys must be a boolean or a function');
  557. }
  558. for (index = 0, length = objectKeyList.length; index < length; index += 1) {
  559. pairBuffer = '';
  560. if (!compact || index !== 0) {
  561. pairBuffer += generateNextLine(state, level);
  562. }
  563. objectKey = objectKeyList[index];
  564. objectValue = object[objectKey];
  565. if (!writeNode(state, level + 1, objectKey, true, true, true)) {
  566. continue; // Skip this pair because of invalid key.
  567. }
  568. explicitPair = (state.tag !== null && state.tag !== '?') ||
  569. (state.dump && state.dump.length > 1024);
  570. if (explicitPair) {
  571. if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
  572. pairBuffer += '?';
  573. } else {
  574. pairBuffer += '? ';
  575. }
  576. }
  577. pairBuffer += state.dump;
  578. if (explicitPair) {
  579. pairBuffer += generateNextLine(state, level);
  580. }
  581. if (!writeNode(state, level + 1, objectValue, true, explicitPair)) {
  582. continue; // Skip this pair because of invalid value.
  583. }
  584. if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
  585. pairBuffer += ':';
  586. } else {
  587. pairBuffer += ': ';
  588. }
  589. pairBuffer += state.dump;
  590. // Both key and value are valid.
  591. _result += pairBuffer;
  592. }
  593. state.tag = _tag;
  594. state.dump = _result || '{}'; // Empty mapping if no valid pairs.
  595. }
  596. function detectType(state, object, explicit) {
  597. var _result, typeList, index, length, type, style;
  598. typeList = explicit ? state.explicitTypes : state.implicitTypes;
  599. for (index = 0, length = typeList.length; index < length; index += 1) {
  600. type = typeList[index];
  601. if ((type.instanceOf || type.predicate) &&
  602. (!type.instanceOf || ((typeof object === 'object') && (object instanceof type.instanceOf))) &&
  603. (!type.predicate || type.predicate(object))) {
  604. state.tag = explicit ? type.tag : '?';
  605. if (type.represent) {
  606. style = state.styleMap[type.tag] || type.defaultStyle;
  607. if (_toString.call(type.represent) === '[object Function]') {
  608. _result = type.represent(object, style);
  609. } else if (_hasOwnProperty.call(type.represent, style)) {
  610. _result = type.represent[style](object, style);
  611. } else {
  612. throw new YAMLException('!<' + type.tag + '> tag resolver accepts not "' + style + '" style');
  613. }
  614. state.dump = _result;
  615. }
  616. return true;
  617. }
  618. }
  619. return false;
  620. }
  621. // Serializes `object` and writes it to global `result`.
  622. // Returns true on success, or false on invalid object.
  623. //
  624. function writeNode(state, level, object, block, compact, iskey) {
  625. state.tag = null;
  626. state.dump = object;
  627. if (!detectType(state, object, false)) {
  628. detectType(state, object, true);
  629. }
  630. var type = _toString.call(state.dump);
  631. if (block) {
  632. block = (state.flowLevel < 0 || state.flowLevel > level);
  633. }
  634. var objectOrArray = type === '[object Object]' || type === '[object Array]',
  635. duplicateIndex,
  636. duplicate;
  637. if (objectOrArray) {
  638. duplicateIndex = state.duplicates.indexOf(object);
  639. duplicate = duplicateIndex !== -1;
  640. }
  641. if ((state.tag !== null && state.tag !== '?') || duplicate || (state.indent !== 2 && level > 0)) {
  642. compact = false;
  643. }
  644. if (duplicate && state.usedDuplicates[duplicateIndex]) {
  645. state.dump = '*ref_' + duplicateIndex;
  646. } else {
  647. if (objectOrArray && duplicate && !state.usedDuplicates[duplicateIndex]) {
  648. state.usedDuplicates[duplicateIndex] = true;
  649. }
  650. if (type === '[object Object]') {
  651. if (block && (Object.keys(state.dump).length !== 0)) {
  652. writeBlockMapping(state, level, state.dump, compact);
  653. if (duplicate) {
  654. state.dump = '&ref_' + duplicateIndex + state.dump;
  655. }
  656. } else {
  657. writeFlowMapping(state, level, state.dump);
  658. if (duplicate) {
  659. state.dump = '&ref_' + duplicateIndex + ' ' + state.dump;
  660. }
  661. }
  662. } else if (type === '[object Array]') {
  663. if (block && (state.dump.length !== 0)) {
  664. writeBlockSequence(state, level, state.dump, compact);
  665. if (duplicate) {
  666. state.dump = '&ref_' + duplicateIndex + state.dump;
  667. }
  668. } else {
  669. writeFlowSequence(state, level, state.dump);
  670. if (duplicate) {
  671. state.dump = '&ref_' + duplicateIndex + ' ' + state.dump;
  672. }
  673. }
  674. } else if (type === '[object String]') {
  675. if (state.tag !== '?') {
  676. writeScalar(state, state.dump, level, iskey);
  677. }
  678. } else {
  679. if (state.skipInvalid) return false;
  680. throw new YAMLException('unacceptable kind of an object to dump ' + type);
  681. }
  682. if (state.tag !== null && state.tag !== '?') {
  683. state.dump = '!<' + state.tag + '> ' + state.dump;
  684. }
  685. }
  686. return true;
  687. }
  688. function getDuplicateReferences(object, state) {
  689. var objects = [],
  690. duplicatesIndexes = [],
  691. index,
  692. length;
  693. inspectNode(object, objects, duplicatesIndexes);
  694. for (index = 0, length = duplicatesIndexes.length; index < length; index += 1) {
  695. state.duplicates.push(objects[duplicatesIndexes[index]]);
  696. }
  697. state.usedDuplicates = new Array(length);
  698. }
  699. function inspectNode(object, objects, duplicatesIndexes) {
  700. var objectKeyList,
  701. index,
  702. length;
  703. if (object !== null && typeof object === 'object') {
  704. index = objects.indexOf(object);
  705. if (index !== -1) {
  706. if (duplicatesIndexes.indexOf(index) === -1) {
  707. duplicatesIndexes.push(index);
  708. }
  709. } else {
  710. objects.push(object);
  711. if (Array.isArray(object)) {
  712. for (index = 0, length = object.length; index < length; index += 1) {
  713. inspectNode(object[index], objects, duplicatesIndexes);
  714. }
  715. } else {
  716. objectKeyList = Object.keys(object);
  717. for (index = 0, length = objectKeyList.length; index < length; index += 1) {
  718. inspectNode(object[objectKeyList[index]], objects, duplicatesIndexes);
  719. }
  720. }
  721. }
  722. }
  723. }
  724. function dump(input, options) {
  725. options = options || {};
  726. var state = new State(options);
  727. if (!state.noRefs) getDuplicateReferences(input, state);
  728. if (writeNode(state, 0, input, true, true)) return state.dump + '\n';
  729. return '';
  730. }
  731. function safeDump(input, options) {
  732. return dump(input, common.extend({ schema: DEFAULT_SAFE_SCHEMA }, options));
  733. }
  734. module.exports.dump = dump;
  735. module.exports.safeDump = safeDump;
  736. },{"./common":2,"./exception":4,"./schema/default_full":9,"./schema/default_safe":10}],4:[function(require,module,exports){
  737. // YAML error class. http://stackoverflow.com/questions/8458984
  738. //
  739. 'use strict';
  740. function YAMLException(reason, mark) {
  741. // Super constructor
  742. Error.call(this);
  743. // Include stack trace in error object
  744. if (Error.captureStackTrace) {
  745. // Chrome and NodeJS
  746. Error.captureStackTrace(this, this.constructor);
  747. } else {
  748. // FF, IE 10+ and Safari 6+. Fallback for others
  749. this.stack = (new Error()).stack || '';
  750. }
  751. this.name = 'YAMLException';
  752. this.reason = reason;
  753. this.mark = mark;
  754. this.message = (this.reason || '(unknown reason)') + (this.mark ? ' ' + this.mark.toString() : '');
  755. }
  756. // Inherit from Error
  757. YAMLException.prototype = Object.create(Error.prototype);
  758. YAMLException.prototype.constructor = YAMLException;
  759. YAMLException.prototype.toString = function toString(compact) {
  760. var result = this.name + ': ';
  761. result += this.reason || '(unknown reason)';
  762. if (!compact && this.mark) {
  763. result += ' ' + this.mark.toString();
  764. }
  765. return result;
  766. };
  767. module.exports = YAMLException;
  768. },{}],5:[function(require,module,exports){
  769. 'use strict';
  770. /*eslint-disable max-len,no-use-before-define*/
  771. var common = require('./common');
  772. var YAMLException = require('./exception');
  773. var Mark = require('./mark');
  774. var DEFAULT_SAFE_SCHEMA = require('./schema/default_safe');
  775. var DEFAULT_FULL_SCHEMA = require('./schema/default_full');
  776. var _hasOwnProperty = Object.prototype.hasOwnProperty;
  777. var CONTEXT_FLOW_IN = 1;
  778. var CONTEXT_FLOW_OUT = 2;
  779. var CONTEXT_BLOCK_IN = 3;
  780. var CONTEXT_BLOCK_OUT = 4;
  781. var CHOMPING_CLIP = 1;
  782. var CHOMPING_STRIP = 2;
  783. var CHOMPING_KEEP = 3;
  784. var PATTERN_NON_PRINTABLE = /[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/;
  785. var PATTERN_NON_ASCII_LINE_BREAKS = /[\x85\u2028\u2029]/;
  786. var PATTERN_FLOW_INDICATORS = /[,\[\]\{\}]/;
  787. var PATTERN_TAG_HANDLE = /^(?:!|!!|![a-z\-]+!)$/i;
  788. var PATTERN_TAG_URI = /^(?:!|[^,\[\]\{\}])(?:%[0-9a-f]{2}|[0-9a-z\-#;\/\?:@&=\+\$,_\.!~\*'\(\)\[\]])*$/i;
  789. function is_EOL(c) {
  790. return (c === 0x0A/* LF */) || (c === 0x0D/* CR */);
  791. }
  792. function is_WHITE_SPACE(c) {
  793. return (c === 0x09/* Tab */) || (c === 0x20/* Space */);
  794. }
  795. function is_WS_OR_EOL(c) {
  796. return (c === 0x09/* Tab */) ||
  797. (c === 0x20/* Space */) ||
  798. (c === 0x0A/* LF */) ||
  799. (c === 0x0D/* CR */);
  800. }
  801. function is_FLOW_INDICATOR(c) {
  802. return c === 0x2C/* , */ ||
  803. c === 0x5B/* [ */ ||
  804. c === 0x5D/* ] */ ||
  805. c === 0x7B/* { */ ||
  806. c === 0x7D/* } */;
  807. }
  808. function fromHexCode(c) {
  809. var lc;
  810. if ((0x30/* 0 */ <= c) && (c <= 0x39/* 9 */)) {
  811. return c - 0x30;
  812. }
  813. /*eslint-disable no-bitwise*/
  814. lc = c | 0x20;
  815. if ((0x61/* a */ <= lc) && (lc <= 0x66/* f */)) {
  816. return lc - 0x61 + 10;
  817. }
  818. return -1;
  819. }
  820. function escapedHexLen(c) {
  821. if (c === 0x78/* x */) { return 2; }
  822. if (c === 0x75/* u */) { return 4; }
  823. if (c === 0x55/* U */) { return 8; }
  824. return 0;
  825. }
  826. function fromDecimalCode(c) {
  827. if ((0x30/* 0 */ <= c) && (c <= 0x39/* 9 */)) {
  828. return c - 0x30;
  829. }
  830. return -1;
  831. }
  832. function simpleEscapeSequence(c) {
  833. return (c === 0x30/* 0 */) ? '\x00' :
  834. (c === 0x61/* a */) ? '\x07' :
  835. (c === 0x62/* b */) ? '\x08' :
  836. (c === 0x74/* t */) ? '\x09' :
  837. (c === 0x09/* Tab */) ? '\x09' :
  838. (c === 0x6E/* n */) ? '\x0A' :
  839. (c === 0x76/* v */) ? '\x0B' :
  840. (c === 0x66/* f */) ? '\x0C' :
  841. (c === 0x72/* r */) ? '\x0D' :
  842. (c === 0x65/* e */) ? '\x1B' :
  843. (c === 0x20/* Space */) ? ' ' :
  844. (c === 0x22/* " */) ? '\x22' :
  845. (c === 0x2F/* / */) ? '/' :
  846. (c === 0x5C/* \ */) ? '\x5C' :
  847. (c === 0x4E/* N */) ? '\x85' :
  848. (c === 0x5F/* _ */) ? '\xA0' :
  849. (c === 0x4C/* L */) ? '\u2028' :
  850. (c === 0x50/* P */) ? '\u2029' : '';
  851. }
  852. function charFromCodepoint(c) {
  853. if (c <= 0xFFFF) {
  854. return String.fromCharCode(c);
  855. }
  856. // Encode UTF-16 surrogate pair
  857. // https://en.wikipedia.org/wiki/UTF-16#Code_points_U.2B010000_to_U.2B10FFFF
  858. return String.fromCharCode(((c - 0x010000) >> 10) + 0xD800,
  859. ((c - 0x010000) & 0x03FF) + 0xDC00);
  860. }
  861. var simpleEscapeCheck = new Array(256); // integer, for fast access
  862. var simpleEscapeMap = new Array(256);
  863. for (var i = 0; i < 256; i++) {
  864. simpleEscapeCheck[i] = simpleEscapeSequence(i) ? 1 : 0;
  865. simpleEscapeMap[i] = simpleEscapeSequence(i);
  866. }
  867. function State(input, options) {
  868. this.input = input;
  869. this.filename = options['filename'] || null;
  870. this.schema = options['schema'] || DEFAULT_FULL_SCHEMA;
  871. this.onWarning = options['onWarning'] || null;
  872. this.legacy = options['legacy'] || false;
  873. this.json = options['json'] || false;
  874. this.listener = options['listener'] || null;
  875. this.implicitTypes = this.schema.compiledImplicit;
  876. this.typeMap = this.schema.compiledTypeMap;
  877. this.length = input.length;
  878. this.position = 0;
  879. this.line = 0;
  880. this.lineStart = 0;
  881. this.lineIndent = 0;
  882. this.documents = [];
  883. /*
  884. this.version;
  885. this.checkLineBreaks;
  886. this.tagMap;
  887. this.anchorMap;
  888. this.tag;
  889. this.anchor;
  890. this.kind;
  891. this.result;*/
  892. }
  893. function generateError(state, message) {
  894. return new YAMLException(
  895. message,
  896. new Mark(state.filename, state.input, state.position, state.line, (state.position - state.lineStart)));
  897. }
  898. function throwError(state, message) {
  899. throw generateError(state, message);
  900. }
  901. function throwWarning(state, message) {
  902. if (state.onWarning) {
  903. state.onWarning.call(null, generateError(state, message));
  904. }
  905. }
  906. var directiveHandlers = {
  907. YAML: function handleYamlDirective(state, name, args) {
  908. var match, major, minor;
  909. if (state.version !== null) {
  910. throwError(state, 'duplication of %YAML directive');
  911. }
  912. if (args.length !== 1) {
  913. throwError(state, 'YAML directive accepts exactly one argument');
  914. }
  915. match = /^([0-9]+)\.([0-9]+)$/.exec(args[0]);
  916. if (match === null) {
  917. throwError(state, 'ill-formed argument of the YAML directive');
  918. }
  919. major = parseInt(match[1], 10);
  920. minor = parseInt(match[2], 10);
  921. if (major !== 1) {
  922. throwError(state, 'unacceptable YAML version of the document');
  923. }
  924. state.version = args[0];
  925. state.checkLineBreaks = (minor < 2);
  926. if (minor !== 1 && minor !== 2) {
  927. throwWarning(state, 'unsupported YAML version of the document');
  928. }
  929. },
  930. TAG: function handleTagDirective(state, name, args) {
  931. var handle, prefix;
  932. if (args.length !== 2) {
  933. throwError(state, 'TAG directive accepts exactly two arguments');
  934. }
  935. handle = args[0];
  936. prefix = args[1];
  937. if (!PATTERN_TAG_HANDLE.test(handle)) {
  938. throwError(state, 'ill-formed tag handle (first argument) of the TAG directive');
  939. }
  940. if (_hasOwnProperty.call(state.tagMap, handle)) {
  941. throwError(state, 'there is a previously declared suffix for "' + handle + '" tag handle');
  942. }
  943. if (!PATTERN_TAG_URI.test(prefix)) {
  944. throwError(state, 'ill-formed tag prefix (second argument) of the TAG directive');
  945. }
  946. state.tagMap[handle] = prefix;
  947. }
  948. };
  949. function captureSegment(state, start, end, checkJson) {
  950. var _position, _length, _character, _result;
  951. if (start < end) {
  952. _result = state.input.slice(start, end);
  953. if (checkJson) {
  954. for (_position = 0, _length = _result.length;
  955. _position < _length;
  956. _position += 1) {
  957. _character = _result.charCodeAt(_position);
  958. if (!(_character === 0x09 ||
  959. (0x20 <= _character && _character <= 0x10FFFF))) {
  960. throwError(state, 'expected valid JSON character');
  961. }
  962. }
  963. } else if (PATTERN_NON_PRINTABLE.test(_result)) {
  964. throwError(state, 'the stream contains non-printable characters');
  965. }
  966. state.result += _result;
  967. }
  968. }
  969. function mergeMappings(state, destination, source, overridableKeys) {
  970. var sourceKeys, key, index, quantity;
  971. if (!common.isObject(source)) {
  972. throwError(state, 'cannot merge mappings; the provided source object is unacceptable');
  973. }
  974. sourceKeys = Object.keys(source);
  975. for (index = 0, quantity = sourceKeys.length; index < quantity; index += 1) {
  976. key = sourceKeys[index];
  977. if (!_hasOwnProperty.call(destination, key)) {
  978. destination[key] = source[key];
  979. overridableKeys[key] = true;
  980. }
  981. }
  982. }
  983. function storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode) {
  984. var index, quantity;
  985. keyNode = String(keyNode);
  986. if (_result === null) {
  987. _result = {};
  988. }
  989. if (keyTag === 'tag:yaml.org,2002:merge') {
  990. if (Array.isArray(valueNode)) {
  991. for (index = 0, quantity = valueNode.length; index < quantity; index += 1) {
  992. mergeMappings(state, _result, valueNode[index], overridableKeys);
  993. }
  994. } else {
  995. mergeMappings(state, _result, valueNode, overridableKeys);
  996. }
  997. } else {
  998. if (!state.json &&
  999. !_hasOwnProperty.call(overridableKeys, keyNode) &&
  1000. _hasOwnProperty.call(_result, keyNode)) {
  1001. throwError(state, 'duplicated mapping key');
  1002. }
  1003. _result[keyNode] = valueNode;
  1004. delete overridableKeys[keyNode];
  1005. }
  1006. return _result;
  1007. }
  1008. function readLineBreak(state) {
  1009. var ch;
  1010. ch = state.input.charCodeAt(state.position);
  1011. if (ch === 0x0A/* LF */) {
  1012. state.position++;
  1013. } else if (ch === 0x0D/* CR */) {
  1014. state.position++;
  1015. if (state.input.charCodeAt(state.position) === 0x0A/* LF */) {
  1016. state.position++;
  1017. }
  1018. } else {
  1019. throwError(state, 'a line break is expected');
  1020. }
  1021. state.line += 1;
  1022. state.lineStart = state.position;
  1023. }
  1024. function skipSeparationSpace(state, allowComments, checkIndent) {
  1025. var lineBreaks = 0,
  1026. ch = state.input.charCodeAt(state.position);
  1027. while (ch !== 0) {
  1028. while (is_WHITE_SPACE(ch)) {
  1029. ch = state.input.charCodeAt(++state.position);
  1030. }
  1031. if (allowComments && ch === 0x23/* # */) {
  1032. do {
  1033. ch = state.input.charCodeAt(++state.position);
  1034. } while (ch !== 0x0A/* LF */ && ch !== 0x0D/* CR */ && ch !== 0);
  1035. }
  1036. if (is_EOL(ch)) {
  1037. readLineBreak(state);
  1038. ch = state.input.charCodeAt(state.position);
  1039. lineBreaks++;
  1040. state.lineIndent = 0;
  1041. while (ch === 0x20/* Space */) {
  1042. state.lineIndent++;
  1043. ch = state.input.charCodeAt(++state.position);
  1044. }
  1045. } else {
  1046. break;
  1047. }
  1048. }
  1049. if (checkIndent !== -1 && lineBreaks !== 0 && state.lineIndent < checkIndent) {
  1050. throwWarning(state, 'deficient indentation');
  1051. }
  1052. return lineBreaks;
  1053. }
  1054. function testDocumentSeparator(state) {
  1055. var _position = state.position,
  1056. ch;
  1057. ch = state.input.charCodeAt(_position);
  1058. // Condition state.position === state.lineStart is tested
  1059. // in parent on each call, for efficiency. No needs to test here again.
  1060. if ((ch === 0x2D/* - */ || ch === 0x2E/* . */) &&
  1061. ch === state.input.charCodeAt(_position + 1) &&
  1062. ch === state.input.charCodeAt(_position + 2)) {
  1063. _position += 3;
  1064. ch = state.input.charCodeAt(_position);
  1065. if (ch === 0 || is_WS_OR_EOL(ch)) {
  1066. return true;
  1067. }
  1068. }
  1069. return false;
  1070. }
  1071. function writeFoldedLines(state, count) {
  1072. if (count === 1) {
  1073. state.result += ' ';
  1074. } else if (count > 1) {
  1075. state.result += common.repeat('\n', count - 1);
  1076. }
  1077. }
  1078. function readPlainScalar(state, nodeIndent, withinFlowCollection) {
  1079. var preceding,
  1080. following,
  1081. captureStart,
  1082. captureEnd,
  1083. hasPendingContent,
  1084. _line,
  1085. _lineStart,
  1086. _lineIndent,
  1087. _kind = state.kind,
  1088. _result = state.result,
  1089. ch;
  1090. ch = state.input.charCodeAt(state.position);
  1091. if (is_WS_OR_EOL(ch) ||
  1092. is_FLOW_INDICATOR(ch) ||
  1093. ch === 0x23/* # */ ||
  1094. ch === 0x26/* & */ ||
  1095. ch === 0x2A/* * */ ||
  1096. ch === 0x21/* ! */ ||
  1097. ch === 0x7C/* | */ ||
  1098. ch === 0x3E/* > */ ||
  1099. ch === 0x27/* ' */ ||
  1100. ch === 0x22/* " */ ||
  1101. ch === 0x25/* % */ ||
  1102. ch === 0x40/* @ */ ||
  1103. ch === 0x60/* ` */) {
  1104. return false;
  1105. }
  1106. if (ch === 0x3F/* ? */ || ch === 0x2D/* - */) {
  1107. following = state.input.charCodeAt(state.position + 1);
  1108. if (is_WS_OR_EOL(following) ||
  1109. withinFlowCollection && is_FLOW_INDICATOR(following)) {
  1110. return false;
  1111. }
  1112. }
  1113. state.kind = 'scalar';
  1114. state.result = '';
  1115. captureStart = captureEnd = state.position;
  1116. hasPendingContent = false;
  1117. while (ch !== 0) {
  1118. if (ch === 0x3A/* : */) {
  1119. following = state.input.charCodeAt(state.position + 1);
  1120. if (is_WS_OR_EOL(following) ||
  1121. withinFlowCollection && is_FLOW_INDICATOR(following)) {
  1122. break;
  1123. }
  1124. } else if (ch === 0x23/* # */) {
  1125. preceding = state.input.charCodeAt(state.position - 1);
  1126. if (is_WS_OR_EOL(preceding)) {
  1127. break;
  1128. }
  1129. } else if ((state.position === state.lineStart && testDocumentSeparator(state)) ||
  1130. withinFlowCollection && is_FLOW_INDICATOR(ch)) {
  1131. break;
  1132. } else if (is_EOL(ch)) {
  1133. _line = state.line;
  1134. _lineStart = state.lineStart;
  1135. _lineIndent = state.lineIndent;
  1136. skipSeparationSpace(state, false, -1);
  1137. if (state.lineIndent >= nodeIndent) {
  1138. hasPendingContent = true;
  1139. ch = state.input.charCodeAt(state.position);
  1140. continue;
  1141. } else {
  1142. state.position = captureEnd;
  1143. state.line = _line;
  1144. state.lineStart = _lineStart;
  1145. state.lineIndent = _lineIndent;
  1146. break;
  1147. }
  1148. }
  1149. if (hasPendingContent) {
  1150. captureSegment(state, captureStart, captureEnd, false);
  1151. writeFoldedLines(state, state.line - _line);
  1152. captureStart = captureEnd = state.position;
  1153. hasPendingContent = false;
  1154. }
  1155. if (!is_WHITE_SPACE(ch)) {
  1156. captureEnd = state.position + 1;
  1157. }
  1158. ch = state.input.charCodeAt(++state.position);
  1159. }
  1160. captureSegment(state, captureStart, captureEnd, false);
  1161. if (state.result) {
  1162. return true;
  1163. }
  1164. state.kind = _kind;
  1165. state.result = _result;
  1166. return false;
  1167. }
  1168. function readSingleQuotedScalar(state, nodeIndent) {
  1169. var ch,
  1170. captureStart, captureEnd;
  1171. ch = state.input.charCodeAt(state.position);
  1172. if (ch !== 0x27/* ' */) {
  1173. return false;
  1174. }
  1175. state.kind = 'scalar';
  1176. state.result = '';
  1177. state.position++;
  1178. captureStart = captureEnd = state.position;
  1179. while ((ch = state.input.charCodeAt(state.position)) !== 0) {
  1180. if (ch === 0x27/* ' */) {
  1181. captureSegment(state, captureStart, state.position, true);
  1182. ch = state.input.charCodeAt(++state.position);
  1183. if (ch === 0x27/* ' */) {
  1184. captureStart = captureEnd = state.position;
  1185. state.position++;
  1186. } else {
  1187. return true;
  1188. }
  1189. } else if (is_EOL(ch)) {
  1190. captureSegment(state, captureStart, captureEnd, true);
  1191. writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
  1192. captureStart = captureEnd = state.position;
  1193. } else if (state.position === state.lineStart && testDocumentSeparator(state)) {
  1194. throwError(state, 'unexpected end of the document within a single quoted scalar');
  1195. } else {
  1196. state.position++;
  1197. captureEnd = state.position;
  1198. }
  1199. }
  1200. throwError(state, 'unexpected end of the stream within a single quoted scalar');
  1201. }
  1202. function readDoubleQuotedScalar(state, nodeIndent) {
  1203. var captureStart,
  1204. captureEnd,
  1205. hexLength,
  1206. hexResult,
  1207. tmp,
  1208. ch;
  1209. ch = state.input.charCodeAt(state.position);
  1210. if (ch !== 0x22/* " */) {
  1211. return false;
  1212. }
  1213. state.kind = 'scalar';
  1214. state.result = '';
  1215. state.position++;
  1216. captureStart = captureEnd = state.position;
  1217. while ((ch = state.input.charCodeAt(state.position)) !== 0) {
  1218. if (ch === 0x22/* " */) {
  1219. captureSegment(state, captureStart, state.position, true);
  1220. state.position++;
  1221. return true;
  1222. } else if (ch === 0x5C/* \ */) {
  1223. captureSegment(state, captureStart, state.position, true);
  1224. ch = state.input.charCodeAt(++state.position);
  1225. if (is_EOL(ch)) {
  1226. skipSeparationSpace(state, false, nodeIndent);
  1227. // TODO: rework to inline fn with no type cast?
  1228. } else if (ch < 256 && simpleEscapeCheck[ch]) {
  1229. state.result += simpleEscapeMap[ch];
  1230. state.position++;
  1231. } else if ((tmp = escapedHexLen(ch)) > 0) {
  1232. hexLength = tmp;
  1233. hexResult = 0;
  1234. for (; hexLength > 0; hexLength--) {
  1235. ch = state.input.charCodeAt(++state.position);
  1236. if ((tmp = fromHexCode(ch)) >= 0) {
  1237. hexResult = (hexResult << 4) + tmp;
  1238. } else {
  1239. throwError(state, 'expected hexadecimal character');
  1240. }
  1241. }
  1242. state.result += charFromCodepoint(hexResult);
  1243. state.position++;
  1244. } else {
  1245. throwError(state, 'unknown escape sequence');
  1246. }
  1247. captureStart = captureEnd = state.position;
  1248. } else if (is_EOL(ch)) {
  1249. captureSegment(state, captureStart, captureEnd, true);
  1250. writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
  1251. captureStart = captureEnd = state.position;
  1252. } else if (state.position === state.lineStart && testDocumentSeparator(state)) {
  1253. throwError(state, 'unexpected end of the document within a double quoted scalar');
  1254. } else {
  1255. state.position++;
  1256. captureEnd = state.position;
  1257. }
  1258. }
  1259. throwError(state, 'unexpected end of the stream within a double quoted scalar');
  1260. }
  1261. function readFlowCollection(state, nodeIndent) {
  1262. var readNext = true,
  1263. _line,
  1264. _tag = state.tag,
  1265. _result,
  1266. _anchor = state.anchor,
  1267. following,
  1268. terminator,
  1269. isPair,
  1270. isExplicitPair,
  1271. isMapping,
  1272. overridableKeys = {},
  1273. keyNode,
  1274. keyTag,
  1275. valueNode,
  1276. ch;
  1277. ch = state.input.charCodeAt(state.position);
  1278. if (ch === 0x5B/* [ */) {
  1279. terminator = 0x5D;/* ] */
  1280. isMapping = false;
  1281. _result = [];
  1282. } else if (ch === 0x7B/* { */) {
  1283. terminator = 0x7D;/* } */
  1284. isMapping = true;
  1285. _result = {};
  1286. } else {
  1287. return false;
  1288. }
  1289. if (state.anchor !== null) {
  1290. state.anchorMap[state.anchor] = _result;
  1291. }
  1292. ch = state.input.charCodeAt(++state.position);
  1293. while (ch !== 0) {
  1294. skipSeparationSpace(state, true, nodeIndent);
  1295. ch = state.input.charCodeAt(state.position);
  1296. if (ch === terminator) {
  1297. state.position++;
  1298. state.tag = _tag;
  1299. state.anchor = _anchor;
  1300. state.kind = isMapping ? 'mapping' : 'sequence';
  1301. state.result = _result;
  1302. return true;
  1303. } else if (!readNext) {
  1304. throwError(state, 'missed comma between flow collection entries');
  1305. }
  1306. keyTag = keyNode = valueNode = null;
  1307. isPair = isExplicitPair = false;
  1308. if (ch === 0x3F/* ? */) {
  1309. following = state.input.charCodeAt(state.position + 1);
  1310. if (is_WS_OR_EOL(following)) {
  1311. isPair = isExplicitPair = true;
  1312. state.position++;
  1313. skipSeparationSpace(state, true, nodeIndent);
  1314. }
  1315. }
  1316. _line = state.line;
  1317. composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
  1318. keyTag = state.tag;
  1319. keyNode = state.result;
  1320. skipSeparationSpace(state, true, nodeIndent);
  1321. ch = state.input.charCodeAt(state.position);
  1322. if ((isExplicitPair || state.line === _line) && ch === 0x3A/* : */) {
  1323. isPair = true;
  1324. ch = state.input.charCodeAt(++state.position);
  1325. skipSeparationSpace(state, true, nodeIndent);
  1326. composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
  1327. valueNode = state.result;
  1328. }
  1329. if (isMapping) {
  1330. storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode);
  1331. } else if (isPair) {
  1332. _result.push(storeMappingPair(state, null, overridableKeys, keyTag, keyNode, valueNode));
  1333. } else {
  1334. _result.push(keyNode);
  1335. }
  1336. skipSeparationSpace(state, true, nodeIndent);
  1337. ch = state.input.charCodeAt(state.position);
  1338. if (ch === 0x2C/* , */) {
  1339. readNext = true;
  1340. ch = state.input.charCodeAt(++state.position);
  1341. } else {
  1342. readNext = false;
  1343. }
  1344. }
  1345. throwError(state, 'unexpected end of the stream within a flow collection');
  1346. }
  1347. function readBlockScalar(state, nodeIndent) {
  1348. var captureStart,
  1349. folding,
  1350. chomping = CHOMPING_CLIP,
  1351. detectedIndent = false,
  1352. textIndent = nodeIndent,
  1353. emptyLines = 0,
  1354. atMoreIndented = false,
  1355. tmp,
  1356. ch;
  1357. ch = state.input.charCodeAt(state.position);
  1358. if (ch === 0x7C/* | */) {
  1359. folding = false;
  1360. } else if (ch === 0x3E/* > */) {
  1361. folding = true;
  1362. } else {
  1363. return false;
  1364. }
  1365. state.kind = 'scalar';
  1366. state.result = '';
  1367. while (ch !== 0) {
  1368. ch = state.input.charCodeAt(++state.position);
  1369. if (ch === 0x2B/* + */ || ch === 0x2D/* - */) {
  1370. if (CHOMPING_CLIP === chomping) {
  1371. chomping = (ch === 0x2B/* + */) ? CHOMPING_KEEP : CHOMPING_STRIP;
  1372. } else {
  1373. throwError(state, 'repeat of a chomping mode identifier');
  1374. }
  1375. } else if ((tmp = fromDecimalCode(ch)) >= 0) {
  1376. if (tmp === 0) {
  1377. throwError(state, 'bad explicit indentation width of a block scalar; it cannot be less than one');
  1378. } else if (!detectedIndent) {
  1379. textIndent = nodeIndent + tmp - 1;
  1380. detectedIndent = true;
  1381. } else {
  1382. throwError(state, 'repeat of an indentation width identifier');
  1383. }
  1384. } else {
  1385. break;
  1386. }
  1387. }
  1388. if (is_WHITE_SPACE(ch)) {
  1389. do { ch = state.input.charCodeAt(++state.position); }
  1390. while (is_WHITE_SPACE(ch));
  1391. if (ch === 0x23/* # */) {
  1392. do { ch = state.input.charCodeAt(++state.position); }
  1393. while (!is_EOL(ch) && (ch !== 0));
  1394. }
  1395. }
  1396. while (ch !== 0) {
  1397. readLineBreak(state);
  1398. state.lineIndent = 0;
  1399. ch = state.input.charCodeAt(state.position);
  1400. while ((!detectedIndent || state.lineIndent < textIndent) &&
  1401. (ch === 0x20/* Space */)) {
  1402. state.lineIndent++;
  1403. ch = state.input.charCodeAt(++state.position);
  1404. }
  1405. if (!detectedIndent && state.lineIndent > textIndent) {
  1406. textIndent = state.lineIndent;
  1407. }
  1408. if (is_EOL(ch)) {
  1409. emptyLines++;
  1410. continue;
  1411. }
  1412. // End of the scalar.
  1413. if (state.lineIndent < textIndent) {
  1414. // Perform the chomping.
  1415. if (chomping === CHOMPING_KEEP) {
  1416. state.result += common.repeat('\n', emptyLines);
  1417. } else if (chomping === CHOMPING_CLIP) {
  1418. if (detectedIndent) { // i.e. only if the scalar is not empty.
  1419. state.result += '\n';
  1420. }
  1421. }
  1422. // Break this `while` cycle and go to the funciton's epilogue.
  1423. break;
  1424. }
  1425. // Folded style: use fancy rules to handle line breaks.
  1426. if (folding) {
  1427. // Lines starting with white space characters (more-indented lines) are not folded.
  1428. if (is_WHITE_SPACE(ch)) {
  1429. atMoreIndented = true;
  1430. state.result += common.repeat('\n', emptyLines + 1);
  1431. // End of more-indented block.
  1432. } else if (atMoreIndented) {
  1433. atMoreIndented = false;
  1434. state.result += common.repeat('\n', emptyLines + 1);
  1435. // Just one line break - perceive as the same line.
  1436. } else if (emptyLines === 0) {
  1437. if (detectedIndent) { // i.e. only if we have already read some scalar content.
  1438. state.result += ' ';
  1439. }
  1440. // Several line breaks - perceive as different lines.
  1441. } else {
  1442. state.result += common.repeat('\n', emptyLines);
  1443. }
  1444. // Literal style: just add exact number of line breaks between content lines.
  1445. } else if (detectedIndent) {
  1446. // If current line isn't the first one - count line break from the last content line.
  1447. state.result += common.repeat('\n', emptyLines + 1);
  1448. } else {
  1449. // In case of the first content line - count only empty lines.
  1450. state.result += common.repeat('\n', emptyLines);
  1451. }
  1452. detectedIndent = true;
  1453. emptyLines = 0;
  1454. captureStart = state.position;
  1455. while (!is_EOL(ch) && (ch !== 0)) {
  1456. ch = state.input.charCodeAt(++state.position);
  1457. }
  1458. captureSegment(state, captureStart, state.position, false);
  1459. }
  1460. return true;
  1461. }
  1462. function readBlockSequence(state, nodeIndent) {
  1463. var _line,
  1464. _tag = state.tag,
  1465. _anchor = state.anchor,
  1466. _result = [],
  1467. following,
  1468. detected = false,
  1469. ch;
  1470. if (state.anchor !== null) {
  1471. state.anchorMap[state.anchor] = _result;
  1472. }
  1473. ch = state.input.charCodeAt(state.position);
  1474. while (ch !== 0) {
  1475. if (ch !== 0x2D/* - */) {
  1476. break;
  1477. }
  1478. following = state.input.charCodeAt(state.position + 1);
  1479. if (!is_WS_OR_EOL(following)) {
  1480. break;
  1481. }
  1482. detected = true;
  1483. state.position++;
  1484. if (skipSeparationSpace(state, true, -1)) {
  1485. if (state.lineIndent <= nodeIndent) {
  1486. _result.push(null);
  1487. ch = state.input.charCodeAt(state.position);
  1488. continue;
  1489. }
  1490. }
  1491. _line = state.line;
  1492. composeNode(state, nodeIndent, CONTEXT_BLOCK_IN, false, true);
  1493. _result.push(state.result);
  1494. skipSeparationSpace(state, true, -1);
  1495. ch = state.input.charCodeAt(state.position);
  1496. if ((state.line === _line || state.lineIndent > nodeIndent) && (ch !== 0)) {
  1497. throwError(state, 'bad indentation of a sequence entry');
  1498. } else if (state.lineIndent < nodeIndent) {
  1499. break;
  1500. }
  1501. }
  1502. if (detected) {
  1503. state.tag = _tag;
  1504. state.anchor = _anchor;
  1505. state.kind = 'sequence';
  1506. state.result = _result;
  1507. return true;
  1508. }
  1509. return false;
  1510. }
  1511. function readBlockMapping(state, nodeIndent, flowIndent) {
  1512. var following,
  1513. allowCompact,
  1514. _line,
  1515. _tag = state.tag,
  1516. _anchor = state.anchor,
  1517. _result = {},
  1518. overridableKeys = {},
  1519. keyTag = null,
  1520. keyNode = null,
  1521. valueNode = null,
  1522. atExplicitKey = false,
  1523. detected = false,
  1524. ch;
  1525. if (state.anchor !== null) {
  1526. state.anchorMap[state.anchor] = _result;
  1527. }
  1528. ch = state.input.charCodeAt(state.position);
  1529. while (ch !== 0) {
  1530. following = state.input.charCodeAt(state.position + 1);
  1531. _line = state.line; // Save the current line.
  1532. //
  1533. // Explicit notation case. There are two separate blocks:
  1534. // first for the key (denoted by "?") and second for the value (denoted by ":")
  1535. //
  1536. if ((ch === 0x3F/* ? */ || ch === 0x3A/* : */) && is_WS_OR_EOL(following)) {
  1537. if (ch === 0x3F/* ? */) {
  1538. if (atExplicitKey) {
  1539. storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null);
  1540. keyTag = keyNode = valueNode = null;
  1541. }
  1542. detected = true;
  1543. atExplicitKey = true;
  1544. allowCompact = true;
  1545. } else if (atExplicitKey) {
  1546. // i.e. 0x3A/* : */ === character after the explicit key.
  1547. atExplicitKey = false;
  1548. allowCompact = true;
  1549. } else {
  1550. throwError(state, 'incomplete explicit mapping pair; a key node is missed');
  1551. }
  1552. state.position += 1;
  1553. ch = following;
  1554. //
  1555. // Implicit notation case. Flow-style node as the key first, then ":", and the value.
  1556. //
  1557. } else if (composeNode(state, flowIndent, CONTEXT_FLOW_OUT, false, true)) {
  1558. if (state.line === _line) {
  1559. ch = state.input.charCodeAt(state.position);
  1560. while (is_WHITE_SPACE(ch)) {
  1561. ch = state.input.charCodeAt(++state.position);
  1562. }
  1563. if (ch === 0x3A/* : */) {
  1564. ch = state.input.charCodeAt(++state.position);
  1565. if (!is_WS_OR_EOL(ch)) {
  1566. throwError(state, 'a whitespace character is expected after the key-value separator within a block mapping');
  1567. }
  1568. if (atExplicitKey) {
  1569. storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null);
  1570. keyTag = keyNode = valueNode = null;
  1571. }
  1572. detected = true;
  1573. atExplicitKey = false;
  1574. allowCompact = false;
  1575. keyTag = state.tag;
  1576. keyNode = state.result;
  1577. } else if (detected) {
  1578. throwError(state, 'can not read an implicit mapping pair; a colon is missed');
  1579. } else {
  1580. state.tag = _tag;
  1581. state.anchor = _anchor;
  1582. return true; // Keep the result of `composeNode`.
  1583. }
  1584. } else if (detected) {
  1585. throwError(state, 'can not read a block mapping entry; a multiline key may not be an implicit key');
  1586. } else {
  1587. state.tag = _tag;
  1588. state.anchor = _anchor;
  1589. return true; // Keep the result of `composeNode`.
  1590. }
  1591. } else {
  1592. break; // Reading is done. Go to the epilogue.
  1593. }
  1594. //
  1595. // Common reading code for both explicit and implicit notations.
  1596. //
  1597. if (state.line === _line || state.lineIndent > nodeIndent) {
  1598. if (composeNode(state, nodeIndent, CONTEXT_BLOCK_OUT, true, allowCompact)) {
  1599. if (atExplicitKey) {
  1600. keyNode = state.result;
  1601. } else {
  1602. valueNode = state.result;
  1603. }
  1604. }
  1605. if (!atExplicitKey) {
  1606. storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode);
  1607. keyTag = keyNode = valueNode = null;
  1608. }
  1609. skipSeparationSpace(state, true, -1);
  1610. ch = state.input.charCodeAt(state.position);
  1611. }
  1612. if (state.lineIndent > nodeIndent && (ch !== 0)) {
  1613. throwError(state, 'bad indentation of a mapping entry');
  1614. } else if (state.lineIndent < nodeIndent) {
  1615. break;
  1616. }
  1617. }
  1618. //
  1619. // Epilogue.
  1620. //
  1621. // Special case: last mapping's node contains only the key in explicit notation.
  1622. if (atExplicitKey) {
  1623. storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null);
  1624. }
  1625. // Expose the resulting mapping.
  1626. if (detected) {
  1627. state.tag = _tag;
  1628. state.anchor = _anchor;
  1629. state.kind = 'mapping';
  1630. state.result = _result;
  1631. }
  1632. return detected;
  1633. }
  1634. function readTagProperty(state) {
  1635. var _position,
  1636. isVerbatim = false,
  1637. isNamed = false,
  1638. tagHandle,
  1639. tagName,
  1640. ch;
  1641. ch = state.input.charCodeAt(state.position);
  1642. if (ch !== 0x21/* ! */) return false;
  1643. if (state.tag !== null) {
  1644. throwError(state, 'duplication of a tag property');
  1645. }
  1646. ch = state.input.charCodeAt(++state.position);
  1647. if (ch === 0x3C/* < */) {
  1648. isVerbatim = true;
  1649. ch = state.input.charCodeAt(++state.position);
  1650. } else if (ch === 0x21/* ! */) {
  1651. isNamed = true;
  1652. tagHandle = '!!';
  1653. ch = state.input.charCodeAt(++state.position);
  1654. } else {
  1655. tagHandle = '!';
  1656. }
  1657. _position = state.position;
  1658. if (isVerbatim) {
  1659. do { ch = state.input.charCodeAt(++state.position); }
  1660. while (ch !== 0 && ch !== 0x3E/* > */);
  1661. if (state.position < state.length) {
  1662. tagName = state.input.slice(_position, state.position);
  1663. ch = state.input.charCodeAt(++state.position);
  1664. } else {
  1665. throwError(state, 'unexpected end of the stream within a verbatim tag');
  1666. }
  1667. } else {
  1668. while (ch !== 0 && !is_WS_OR_EOL(ch)) {
  1669. if (ch === 0x21/* ! */) {
  1670. if (!isNamed) {
  1671. tagHandle = state.input.slice(_position - 1, state.position + 1);
  1672. if (!PATTERN_TAG_HANDLE.test(tagHandle)) {
  1673. throwError(state, 'named tag handle cannot contain such characters');
  1674. }
  1675. isNamed = true;
  1676. _position = state.position + 1;
  1677. } else {
  1678. throwError(state, 'tag suffix cannot contain exclamation marks');
  1679. }
  1680. }
  1681. ch = state.input.charCodeAt(++state.position);
  1682. }
  1683. tagName = state.input.slice(_position, state.position);
  1684. if (PATTERN_FLOW_INDICATORS.test(tagName)) {
  1685. throwError(state, 'tag suffix cannot contain flow indicator characters');
  1686. }
  1687. }
  1688. if (tagName && !PATTERN_TAG_URI.test(tagName)) {
  1689. throwError(state, 'tag name cannot contain such characters: ' + tagName);
  1690. }
  1691. if (isVerbatim) {
  1692. state.tag = tagName;
  1693. } else if (_hasOwnProperty.call(state.tagMap, tagHandle)) {
  1694. state.tag = state.tagMap[tagHandle] + tagName;
  1695. } else if (tagHandle === '!') {
  1696. state.tag = '!' + tagName;
  1697. } else if (tagHandle === '!!') {
  1698. state.tag = 'tag:yaml.org,2002:' + tagName;
  1699. } else {
  1700. throwError(state, 'undeclared tag handle "' + tagHandle + '"');
  1701. }
  1702. return true;
  1703. }
  1704. function readAnchorProperty(state) {
  1705. var _position,
  1706. ch;
  1707. ch = state.input.charCodeAt(state.position);
  1708. if (ch !== 0x26/* & */) return false;
  1709. if (state.anchor !== null) {
  1710. throwError(state, 'duplication of an anchor property');
  1711. }
  1712. ch = state.input.charCodeAt(++state.position);
  1713. _position = state.position;
  1714. while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
  1715. ch = state.input.charCodeAt(++state.position);
  1716. }
  1717. if (state.position === _position) {
  1718. throwError(state, 'name of an anchor node must contain at least one character');
  1719. }
  1720. state.anchor = state.input.slice(_position, state.position);
  1721. return true;
  1722. }
  1723. function readAlias(state) {
  1724. var _position, alias,
  1725. ch;
  1726. ch = state.input.charCodeAt(state.position);
  1727. if (ch !== 0x2A/* * */) return false;
  1728. ch = state.input.charCodeAt(++state.position);
  1729. _position = state.position;
  1730. while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
  1731. ch = state.input.charCodeAt(++state.position);
  1732. }
  1733. if (state.position === _position) {
  1734. throwError(state, 'name of an alias node must contain at least one character');
  1735. }
  1736. alias = state.input.slice(_position, state.position);
  1737. if (!state.anchorMap.hasOwnProperty(alias)) {
  1738. throwError(state, 'unidentified alias "' + alias + '"');
  1739. }
  1740. state.result = state.anchorMap[alias];
  1741. skipSeparationSpace(state, true, -1);
  1742. return true;
  1743. }
  1744. function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact) {
  1745. var allowBlockStyles,
  1746. allowBlockScalars,
  1747. allowBlockCollections,
  1748. indentStatus = 1, // 1: this>parent, 0: this=parent, -1: this<parent
  1749. atNewLine = false,
  1750. hasContent = false,
  1751. typeIndex,
  1752. typeQuantity,
  1753. type,
  1754. flowIndent,
  1755. blockIndent;
  1756. if (state.listener !== null) {
  1757. state.listener('open', state);
  1758. }
  1759. state.tag = null;
  1760. state.anchor = null;
  1761. state.kind = null;
  1762. state.result = null;
  1763. allowBlockStyles = allowBlockScalars = allowBlockCollections =
  1764. CONTEXT_BLOCK_OUT === nodeContext ||
  1765. CONTEXT_BLOCK_IN === nodeContext;
  1766. if (allowToSeek) {
  1767. if (skipSeparationSpace(state, true, -1)) {
  1768. atNewLine = true;
  1769. if (state.lineIndent > parentIndent) {
  1770. indentStatus = 1;
  1771. } else if (state.lineIndent === parentIndent) {
  1772. indentStatus = 0;
  1773. } else if (state.lineIndent < parentIndent) {
  1774. indentStatus = -1;
  1775. }
  1776. }
  1777. }
  1778. if (indentStatus === 1) {
  1779. while (readTagProperty(state) || readAnchorProperty(state)) {
  1780. if (skipSeparationSpace(state, true, -1)) {
  1781. atNewLine = true;
  1782. allowBlockCollections = allowBlockStyles;
  1783. if (state.lineIndent > parentIndent) {
  1784. indentStatus = 1;
  1785. } else if (state.lineIndent === parentIndent) {
  1786. indentStatus = 0;
  1787. } else if (state.lineIndent < parentIndent) {
  1788. indentStatus = -1;
  1789. }
  1790. } else {
  1791. allowBlockCollections = false;
  1792. }
  1793. }
  1794. }
  1795. if (allowBlockCollections) {
  1796. allowBlockCollections = atNewLine || allowCompact;
  1797. }
  1798. if (indentStatus === 1 || CONTEXT_BLOCK_OUT === nodeContext) {
  1799. if (CONTEXT_FLOW_IN === nodeContext || CONTEXT_FLOW_OUT === nodeContext) {
  1800. flowIndent = parentIndent;
  1801. } else {
  1802. flowIndent = parentIndent + 1;
  1803. }
  1804. blockIndent = state.position - state.lineStart;
  1805. if (indentStatus === 1) {
  1806. if (allowBlockCollections &&
  1807. (readBlockSequence(state, blockIndent) ||
  1808. readBlockMapping(state, blockIndent, flowIndent)) ||
  1809. readFlowCollection(state, flowIndent)) {
  1810. hasContent = true;
  1811. } else {
  1812. if ((allowBlockScalars && readBlockScalar(state, flowIndent)) ||
  1813. readSingleQuotedScalar(state, flowIndent) ||
  1814. readDoubleQuotedScalar(state, flowIndent)) {
  1815. hasContent = true;
  1816. } else if (readAlias(state)) {
  1817. hasContent = true;
  1818. if (state.tag !== null || state.anchor !== null) {
  1819. throwError(state, 'alias node should not have any properties');
  1820. }
  1821. } else if (readPlainScalar(state, flowIndent, CONTEXT_FLOW_IN === nodeContext)) {
  1822. hasContent = true;
  1823. if (state.tag === null) {
  1824. state.tag = '?';
  1825. }
  1826. }
  1827. if (state.anchor !== null) {
  1828. state.anchorMap[state.anchor] = state.result;
  1829. }
  1830. }
  1831. } else if (indentStatus === 0) {
  1832. // Special case: block sequences are allowed to have same indentation level as the parent.
  1833. // http://www.yaml.org/spec/1.2/spec.html#id2799784
  1834. hasContent = allowBlockCollections && readBlockSequence(state, blockIndent);
  1835. }
  1836. }
  1837. if (state.tag !== null && state.tag !== '!') {
  1838. if (state.tag === '?') {
  1839. for (typeIndex = 0, typeQuantity = state.implicitTypes.length;
  1840. typeIndex < typeQuantity;
  1841. typeIndex += 1) {
  1842. type = state.implicitTypes[typeIndex];
  1843. // Implicit resolving is not allowed for non-scalar types, and '?'
  1844. // non-specific tag is only assigned to plain scalars. So, it isn't
  1845. // needed to check for 'kind' conformity.
  1846. if (type.resolve(state.result)) { // `state.result` updated in resolver if matched
  1847. state.result = type.construct(state.result);
  1848. state.tag = type.tag;
  1849. if (state.anchor !== null) {
  1850. state.anchorMap[state.anchor] = state.result;
  1851. }
  1852. break;
  1853. }
  1854. }
  1855. } else if (_hasOwnProperty.call(state.typeMap, state.tag)) {
  1856. type = state.typeMap[state.tag];
  1857. if (state.result !== null && type.kind !== state.kind) {
  1858. throwError(state, 'unacceptable node kind for !<' + state.tag + '> tag; it should be "' + type.kind + '", not "' + state.kind + '"');
  1859. }
  1860. if (!type.resolve(state.result)) { // `state.result` updated in resolver if matched
  1861. throwError(state, 'cannot resolve a node with !<' + state.tag + '> explicit tag');
  1862. } else {
  1863. state.result = type.construct(state.result);
  1864. if (state.anchor !== null) {
  1865. state.anchorMap[state.anchor] = state.result;
  1866. }
  1867. }
  1868. } else {
  1869. throwError(state, 'unknown tag !<' + state.tag + '>');
  1870. }
  1871. }
  1872. if (state.listener !== null) {
  1873. state.listener('close', state);
  1874. }
  1875. return state.tag !== null || state.anchor !== null || hasContent;
  1876. }
  1877. function readDocument(state) {
  1878. var documentStart = state.position,
  1879. _position,
  1880. directiveName,
  1881. directiveArgs,
  1882. hasDirectives = false,
  1883. ch;
  1884. state.version = null;
  1885. state.checkLineBreaks = state.legacy;
  1886. state.tagMap = {};
  1887. state.anchorMap = {};
  1888. while ((ch = state.input.charCodeAt(state.position)) !== 0) {
  1889. skipSeparationSpace(state, true, -1);
  1890. ch = state.input.charCodeAt(state.position);
  1891. if (state.lineIndent > 0 || ch !== 0x25/* % */) {
  1892. break;
  1893. }
  1894. hasDirectives = true;
  1895. ch = state.input.charCodeAt(++state.position);
  1896. _position = state.position;
  1897. while (ch !== 0 && !is_WS_OR_EOL(ch)) {
  1898. ch = state.input.charCodeAt(++state.position);
  1899. }
  1900. directiveName = state.input.slice(_position, state.position);
  1901. directiveArgs = [];
  1902. if (directiveName.length < 1) {
  1903. throwError(state, 'directive name must not be less than one character in length');
  1904. }
  1905. while (ch !== 0) {
  1906. while (is_WHITE_SPACE(ch)) {
  1907. ch = state.input.charCodeAt(++state.position);
  1908. }
  1909. if (ch === 0x23/* # */) {
  1910. do { ch = state.input.charCodeAt(++state.position); }
  1911. while (ch !== 0 && !is_EOL(ch));
  1912. break;
  1913. }
  1914. if (is_EOL(ch)) break;
  1915. _position = state.position;
  1916. while (ch !== 0 && !is_WS_OR_EOL(ch)) {
  1917. ch = state.input.charCodeAt(++state.position);
  1918. }
  1919. directiveArgs.push(state.input.slice(_position, state.position));
  1920. }
  1921. if (ch !== 0) readLineBreak(state);
  1922. if (_hasOwnProperty.call(directiveHandlers, directiveName)) {
  1923. directiveHandlers[directiveName](state, directiveName, directiveArgs);
  1924. } else {
  1925. throwWarning(state, 'unknown document directive "' + directiveName + '"');
  1926. }
  1927. }
  1928. skipSeparationSpace(state, true, -1);
  1929. if (state.lineIndent === 0 &&
  1930. state.input.charCodeAt(state.position) === 0x2D/* - */ &&
  1931. state.input.charCodeAt(state.position + 1) === 0x2D/* - */ &&
  1932. state.input.charCodeAt(state.position + 2) === 0x2D/* - */) {
  1933. state.position += 3;
  1934. skipSeparationSpace(state, true, -1);
  1935. } else if (hasDirectives) {
  1936. throwError(state, 'directives end mark is expected');
  1937. }
  1938. composeNode(state, state.lineIndent - 1, CONTEXT_BLOCK_OUT, false, true);
  1939. skipSeparationSpace(state, true, -1);
  1940. if (state.checkLineBreaks &&
  1941. PATTERN_NON_ASCII_LINE_BREAKS.test(state.input.slice(documentStart, state.position))) {
  1942. throwWarning(state, 'non-ASCII line breaks are interpreted as content');
  1943. }
  1944. state.documents.push(state.result);
  1945. if (state.position === state.lineStart && testDocumentSeparator(state)) {
  1946. if (state.input.charCodeAt(state.position) === 0x2E/* . */) {
  1947. state.position += 3;
  1948. skipSeparationSpace(state, true, -1);
  1949. }
  1950. return;
  1951. }
  1952. if (state.position < (state.length - 1)) {
  1953. throwError(state, 'end of the stream or a document separator is expected');
  1954. } else {
  1955. return;
  1956. }
  1957. }
  1958. function loadDocuments(input, options) {
  1959. input = String(input);
  1960. options = options || {};
  1961. if (input.length !== 0) {
  1962. // Add tailing `\n` if not exists
  1963. if (input.charCodeAt(input.length - 1) !== 0x0A/* LF */ &&
  1964. input.charCodeAt(input.length - 1) !== 0x0D/* CR */) {
  1965. input += '\n';
  1966. }
  1967. // Strip BOM
  1968. if (input.charCodeAt(0) === 0xFEFF) {
  1969. input = input.slice(1);
  1970. }
  1971. }
  1972. var state = new State(input, options);
  1973. // Use 0 as string terminator. That significantly simplifies bounds check.
  1974. state.input += '\0';
  1975. while (state.input.charCodeAt(state.position) === 0x20/* Space */) {
  1976. state.lineIndent += 1;
  1977. state.position += 1;
  1978. }
  1979. while (state.position < (state.length - 1)) {
  1980. readDocument(state);
  1981. }
  1982. return state.documents;
  1983. }
  1984. function loadAll(input, iterator, options) {
  1985. var documents = loadDocuments(input, options), index, length;
  1986. for (index = 0, length = documents.length; index < length; index += 1) {
  1987. iterator(documents[index]);
  1988. }
  1989. }
  1990. function load(input, options) {
  1991. var documents = loadDocuments(input, options);
  1992. if (documents.length === 0) {
  1993. /*eslint-disable no-undefined*/
  1994. return undefined;
  1995. } else if (documents.length === 1) {
  1996. return documents[0];
  1997. }
  1998. throw new YAMLException('expected a single document in the stream, but found more');
  1999. }
  2000. function safeLoadAll(input, output, options) {
  2001. loadAll(input, output, common.extend({ schema: DEFAULT_SAFE_SCHEMA }, options));
  2002. }
  2003. function safeLoad(input, options) {
  2004. return load(input, common.extend({ schema: DEFAULT_SAFE_SCHEMA }, options));
  2005. }
  2006. module.exports.loadAll = loadAll;
  2007. module.exports.load = load;
  2008. module.exports.safeLoadAll = safeLoadAll;
  2009. module.exports.safeLoad = safeLoad;
  2010. },{"./common":2,"./exception":4,"./mark":6,"./schema/default_full":9,"./schema/default_safe":10}],6:[function(require,module,exports){
  2011. 'use strict';
  2012. var common = require('./common');
  2013. function Mark(name, buffer, position, line, column) {
  2014. this.name = name;
  2015. this.buffer = buffer;
  2016. this.position = position;
  2017. this.line = line;
  2018. this.column = column;
  2019. }
  2020. Mark.prototype.getSnippet = function getSnippet(indent, maxLength) {
  2021. var head, start, tail, end, snippet;
  2022. if (!this.buffer) return null;
  2023. indent = indent || 4;
  2024. maxLength = maxLength || 75;
  2025. head = '';
  2026. start = this.position;
  2027. while (start > 0 && '\x00\r\n\x85\u2028\u2029'.indexOf(this.buffer.charAt(start - 1)) === -1) {
  2028. start -= 1;
  2029. if (this.position - start > (maxLength / 2 - 1)) {
  2030. head = ' ... ';
  2031. start += 5;
  2032. break;
  2033. }
  2034. }
  2035. tail = '';
  2036. end = this.position;
  2037. while (end < this.buffer.length && '\x00\r\n\x85\u2028\u2029'.indexOf(this.buffer.charAt(end)) === -1) {
  2038. end += 1;
  2039. if (end - this.position > (maxLength / 2 - 1)) {
  2040. tail = ' ... ';
  2041. end -= 5;
  2042. break;
  2043. }
  2044. }
  2045. snippet = this.buffer.slice(start, end);
  2046. return common.repeat(' ', indent) + head + snippet + tail + '\n' +
  2047. common.repeat(' ', indent + this.position - start + head.length) + '^';
  2048. };
  2049. Mark.prototype.toString = function toString(compact) {
  2050. var snippet, where = '';
  2051. if (this.name) {
  2052. where += 'in "' + this.name + '" ';
  2053. }
  2054. where += 'at line ' + (this.line + 1) + ', column ' + (this.column + 1);
  2055. if (!compact) {
  2056. snippet = this.getSnippet();
  2057. if (snippet) {
  2058. where += ':\n' + snippet;
  2059. }
  2060. }
  2061. return where;
  2062. };
  2063. module.exports = Mark;
  2064. },{"./common":2}],7:[function(require,module,exports){
  2065. 'use strict';
  2066. /*eslint-disable max-len*/
  2067. var common = require('./common');
  2068. var YAMLException = require('./exception');
  2069. var Type = require('./type');
  2070. function compileList(schema, name, result) {
  2071. var exclude = [];
  2072. schema.include.forEach(function (includedSchema) {
  2073. result = compileList(includedSchema, name, result);
  2074. });
  2075. schema[name].forEach(function (currentType) {
  2076. result.forEach(function (previousType, previousIndex) {
  2077. if (previousType.tag === currentType.tag) {
  2078. exclude.push(previousIndex);
  2079. }
  2080. });
  2081. result.push(currentType);
  2082. });
  2083. return result.filter(function (type, index) {
  2084. return exclude.indexOf(index) === -1;
  2085. });
  2086. }
  2087. function compileMap(/* lists... */) {
  2088. var result = {}, index, length;
  2089. function collectType(type) {
  2090. result[type.tag] = type;
  2091. }
  2092. for (index = 0, length = arguments.length; index < length; index += 1) {
  2093. arguments[index].forEach(collectType);
  2094. }
  2095. return result;
  2096. }
  2097. function Schema(definition) {
  2098. this.include = definition.include || [];
  2099. this.implicit = definition.implicit || [];
  2100. this.explicit = definition.explicit || [];
  2101. this.implicit.forEach(function (type) {
  2102. if (type.loadKind && type.loadKind !== 'scalar') {
  2103. throw new YAMLException('There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.');
  2104. }
  2105. });
  2106. this.compiledImplicit = compileList(this, 'implicit', []);
  2107. this.compiledExplicit = compileList(this, 'explicit', []);
  2108. this.compiledTypeMap = compileMap(this.compiledImplicit, this.compiledExplicit);
  2109. }
  2110. Schema.DEFAULT = null;
  2111. Schema.create = function createSchema() {
  2112. var schemas, types;
  2113. switch (arguments.length) {
  2114. case 1:
  2115. schemas = Schema.DEFAULT;
  2116. types = arguments[0];
  2117. break;
  2118. case 2:
  2119. schemas = arguments[0];
  2120. types = arguments[1];
  2121. break;
  2122. default:
  2123. throw new YAMLException('Wrong number of arguments for Schema.create function');
  2124. }
  2125. schemas = common.toArray(schemas);
  2126. types = common.toArray(types);
  2127. if (!schemas.every(function (schema) { return schema instanceof Schema; })) {
  2128. throw new YAMLException('Specified list of super schemas (or a single Schema object) contains a non-Schema object.');
  2129. }
  2130. if (!types.every(function (type) { return type instanceof Type; })) {
  2131. throw new YAMLException('Specified list of YAML types (or a single Type object) contains a non-Type object.');
  2132. }
  2133. return new Schema({
  2134. include: schemas,
  2135. explicit: types
  2136. });
  2137. };
  2138. module.exports = Schema;
  2139. },{"./common":2,"./exception":4,"./type":13}],8:[function(require,module,exports){
  2140. // Standard YAML's Core schema.
  2141. // http://www.yaml.org/spec/1.2/spec.html#id2804923
  2142. //
  2143. // NOTE: JS-YAML does not support schema-specific tag resolution restrictions.
  2144. // So, Core schema has no distinctions from JSON schema is JS-YAML.
  2145. 'use strict';
  2146. var Schema = require('../schema');
  2147. module.exports = new Schema({
  2148. include: [
  2149. require('./json')
  2150. ]
  2151. });
  2152. },{"../schema":7,"./json":12}],9:[function(require,module,exports){
  2153. // JS-YAML's default schema for `load` function.
  2154. // It is not described in the YAML specification.
  2155. //
  2156. // This schema is based on JS-YAML's default safe schema and includes
  2157. // JavaScript-specific types: !!js/undefined, !!js/regexp and !!js/function.
  2158. //
  2159. // Also this schema is used as default base schema at `Schema.create` function.
  2160. 'use strict';
  2161. var Schema = require('../schema');
  2162. module.exports = Schema.DEFAULT = new Schema({
  2163. include: [
  2164. require('./default_safe')
  2165. ],
  2166. explicit: [
  2167. require('../type/js/undefined'),
  2168. require('../type/js/regexp'),
  2169. require('../type/js/function')
  2170. ]
  2171. });
  2172. },{"../schema":7,"../type/js/function":18,"../type/js/regexp":19,"../type/js/undefined":20,"./default_safe":10}],10:[function(require,module,exports){
  2173. // JS-YAML's default schema for `safeLoad` function.
  2174. // It is not described in the YAML specification.
  2175. //
  2176. // This schema is based on standard YAML's Core schema and includes most of
  2177. // extra types described at YAML tag repository. (http://yaml.org/type/)
  2178. 'use strict';
  2179. var Schema = require('../schema');
  2180. module.exports = new Schema({
  2181. include: [
  2182. require('./core')
  2183. ],
  2184. implicit: [
  2185. require('../type/timestamp'),
  2186. require('../type/merge')
  2187. ],
  2188. explicit: [
  2189. require('../type/binary'),
  2190. require('../type/omap'),
  2191. require('../type/pairs'),
  2192. require('../type/set')
  2193. ]
  2194. });
  2195. },{"../schema":7,"../type/binary":14,"../type/merge":22,"../type/omap":24,"../type/pairs":25,"../type/set":27,"../type/timestamp":29,"./core":8}],11:[function(require,module,exports){
  2196. // Standard YAML's Failsafe schema.
  2197. // http://www.yaml.org/spec/1.2/spec.html#id2802346
  2198. 'use strict';
  2199. var Schema = require('../schema');
  2200. module.exports = new Schema({
  2201. explicit: [
  2202. require('../type/str'),
  2203. require('../type/seq'),
  2204. require('../type/map')
  2205. ]
  2206. });
  2207. },{"../schema":7,"../type/map":21,"../type/seq":26,"../type/str":28}],12:[function(require,module,exports){
  2208. // Standard YAML's JSON schema.
  2209. // http://www.yaml.org/spec/1.2/spec.html#id2803231
  2210. //
  2211. // NOTE: JS-YAML does not support schema-specific tag resolution restrictions.
  2212. // So, this schema is not such strict as defined in the YAML specification.
  2213. // It allows numbers in binary notaion, use `Null` and `NULL` as `null`, etc.
  2214. 'use strict';
  2215. var Schema = require('../schema');
  2216. module.exports = new Schema({
  2217. include: [
  2218. require('./failsafe')
  2219. ],
  2220. implicit: [
  2221. require('../type/null'),
  2222. require('../type/bool'),
  2223. require('../type/int'),
  2224. require('../type/float')
  2225. ]
  2226. });
  2227. },{"../schema":7,"../type/bool":15,"../type/float":16,"../type/int":17,"../type/null":23,"./failsafe":11}],13:[function(require,module,exports){
  2228. 'use strict';
  2229. var YAMLException = require('./exception');
  2230. var TYPE_CONSTRUCTOR_OPTIONS = [
  2231. 'kind',
  2232. 'resolve',
  2233. 'construct',
  2234. 'instanceOf',
  2235. 'predicate',
  2236. 'represent',
  2237. 'defaultStyle',
  2238. 'styleAliases'
  2239. ];
  2240. var YAML_NODE_KINDS = [
  2241. 'scalar',
  2242. 'sequence',
  2243. 'mapping'
  2244. ];
  2245. function compileStyleAliases(map) {
  2246. var result = {};
  2247. if (map !== null) {
  2248. Object.keys(map).forEach(function (style) {
  2249. map[style].forEach(function (alias) {
  2250. result[String(alias)] = style;
  2251. });
  2252. });
  2253. }
  2254. return result;
  2255. }
  2256. function Type(tag, options) {
  2257. options = options || {};
  2258. Object.keys(options).forEach(function (name) {
  2259. if (TYPE_CONSTRUCTOR_OPTIONS.indexOf(name) === -1) {
  2260. throw new YAMLException('Unknown option "' + name + '" is met in definition of "' + tag + '" YAML type.');
  2261. }
  2262. });
  2263. // TODO: Add tag format check.
  2264. this.tag = tag;
  2265. this.kind = options['kind'] || null;
  2266. this.resolve = options['resolve'] || function () { return true; };
  2267. this.construct = options['construct'] || function (data) { return data; };
  2268. this.instanceOf = options['instanceOf'] || null;
  2269. this.predicate = options['predicate'] || null;
  2270. this.represent = options['represent'] || null;
  2271. this.defaultStyle = options['defaultStyle'] || null;
  2272. this.styleAliases = compileStyleAliases(options['styleAliases'] || null);
  2273. if (YAML_NODE_KINDS.indexOf(this.kind) === -1) {
  2274. throw new YAMLException('Unknown kind "' + this.kind + '" is specified for "' + tag + '" YAML type.');
  2275. }
  2276. }
  2277. module.exports = Type;
  2278. },{"./exception":4}],14:[function(require,module,exports){
  2279. 'use strict';
  2280. /*eslint-disable no-bitwise*/
  2281. // A trick for browserified version.
  2282. // Since we make browserifier to ignore `buffer` module, NodeBuffer will be undefined
  2283. var NodeBuffer = require('buffer').Buffer;
  2284. var Type = require('../type');
  2285. // [ 64, 65, 66 ] -> [ padding, CR, LF ]
  2286. var BASE64_MAP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\n\r';
  2287. function resolveYamlBinary(data) {
  2288. if (data === null) return false;
  2289. var code, idx, bitlen = 0, max = data.length, map = BASE64_MAP;
  2290. // Convert one by one.
  2291. for (idx = 0; idx < max; idx++) {
  2292. code = map.indexOf(data.charAt(idx));
  2293. // Skip CR/LF
  2294. if (code > 64) continue;
  2295. // Fail on illegal characters
  2296. if (code < 0) return false;
  2297. bitlen += 6;
  2298. }
  2299. // If there are any bits left, source was corrupted
  2300. return (bitlen % 8) === 0;
  2301. }
  2302. function constructYamlBinary(data) {
  2303. var idx, tailbits,
  2304. input = data.replace(/[\r\n=]/g, ''), // remove CR/LF & padding to simplify scan
  2305. max = input.length,
  2306. map = BASE64_MAP,
  2307. bits = 0,
  2308. result = [];
  2309. // Collect by 6*4 bits (3 bytes)
  2310. for (idx = 0; idx < max; idx++) {
  2311. if ((idx % 4 === 0) && idx) {
  2312. result.push((bits >> 16) & 0xFF);
  2313. result.push((bits >> 8) & 0xFF);
  2314. result.push(bits & 0xFF);
  2315. }
  2316. bits = (bits << 6) | map.indexOf(input.charAt(idx));
  2317. }
  2318. // Dump tail
  2319. tailbits = (max % 4) * 6;
  2320. if (tailbits === 0) {
  2321. result.push((bits >> 16) & 0xFF);
  2322. result.push((bits >> 8) & 0xFF);
  2323. result.push(bits & 0xFF);
  2324. } else if (tailbits === 18) {
  2325. result.push((bits >> 10) & 0xFF);
  2326. result.push((bits >> 2) & 0xFF);
  2327. } else if (tailbits === 12) {
  2328. result.push((bits >> 4) & 0xFF);
  2329. }
  2330. // Wrap into Buffer for NodeJS and leave Array for browser
  2331. if (NodeBuffer) return new NodeBuffer(result);
  2332. return result;
  2333. }
  2334. function representYamlBinary(object /*, style*/) {
  2335. var result = '', bits = 0, idx, tail,
  2336. max = object.length,
  2337. map = BASE64_MAP;
  2338. // Convert every three bytes to 4 ASCII characters.
  2339. for (idx = 0; idx < max; idx++) {
  2340. if ((idx % 3 === 0) && idx) {
  2341. result += map[(bits >> 18) & 0x3F];
  2342. result += map[(bits >> 12) & 0x3F];
  2343. result += map[(bits >> 6) & 0x3F];
  2344. result += map[bits & 0x3F];
  2345. }
  2346. bits = (bits << 8) + object[idx];
  2347. }
  2348. // Dump tail
  2349. tail = max % 3;
  2350. if (tail === 0) {
  2351. result += map[(bits >> 18) & 0x3F];
  2352. result += map[(bits >> 12) & 0x3F];
  2353. result += map[(bits >> 6) & 0x3F];
  2354. result += map[bits & 0x3F];
  2355. } else if (tail === 2) {
  2356. result += map[(bits >> 10) & 0x3F];
  2357. result += map[(bits >> 4) & 0x3F];
  2358. result += map[(bits << 2) & 0x3F];
  2359. result += map[64];
  2360. } else if (tail === 1) {
  2361. result += map[(bits >> 2) & 0x3F];
  2362. result += map[(bits << 4) & 0x3F];
  2363. result += map[64];
  2364. result += map[64];
  2365. }
  2366. return result;
  2367. }
  2368. function isBinary(object) {
  2369. return NodeBuffer && NodeBuffer.isBuffer(object);
  2370. }
  2371. module.exports = new Type('tag:yaml.org,2002:binary', {
  2372. kind: 'scalar',
  2373. resolve: resolveYamlBinary,
  2374. construct: constructYamlBinary,
  2375. predicate: isBinary,
  2376. represent: representYamlBinary
  2377. });
  2378. },{"../type":13,"buffer":30}],15:[function(require,module,exports){
  2379. 'use strict';
  2380. var Type = require('../type');
  2381. function resolveYamlBoolean(data) {
  2382. if (data === null) return false;
  2383. var max = data.length;
  2384. return (max === 4 && (data === 'true' || data === 'True' || data === 'TRUE')) ||
  2385. (max === 5 && (data === 'false' || data === 'False' || data === 'FALSE'));
  2386. }
  2387. function constructYamlBoolean(data) {
  2388. return data === 'true' ||
  2389. data === 'True' ||
  2390. data === 'TRUE';
  2391. }
  2392. function isBoolean(object) {
  2393. return Object.prototype.toString.call(object) === '[object Boolean]';
  2394. }
  2395. module.exports = new Type('tag:yaml.org,2002:bool', {
  2396. kind: 'scalar',
  2397. resolve: resolveYamlBoolean,
  2398. construct: constructYamlBoolean,
  2399. predicate: isBoolean,
  2400. represent: {
  2401. lowercase: function (object) { return object ? 'true' : 'false'; },
  2402. uppercase: function (object) { return object ? 'TRUE' : 'FALSE'; },
  2403. camelcase: function (object) { return object ? 'True' : 'False'; }
  2404. },
  2405. defaultStyle: 'lowercase'
  2406. });
  2407. },{"../type":13}],16:[function(require,module,exports){
  2408. 'use strict';
  2409. var common = require('../common');
  2410. var Type = require('../type');
  2411. var YAML_FLOAT_PATTERN = new RegExp(
  2412. '^(?:[-+]?(?:[0-9][0-9_]*)\\.[0-9_]*(?:[eE][-+][0-9]+)?' +
  2413. '|\\.[0-9_]+(?:[eE][-+][0-9]+)?' +
  2414. '|[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]*' +
  2415. '|[-+]?\\.(?:inf|Inf|INF)' +
  2416. '|\\.(?:nan|NaN|NAN))$');
  2417. function resolveYamlFloat(data) {
  2418. if (data === null) return false;
  2419. if (!YAML_FLOAT_PATTERN.test(data)) return false;
  2420. return true;
  2421. }
  2422. function constructYamlFloat(data) {
  2423. var value, sign, base, digits;
  2424. value = data.replace(/_/g, '').toLowerCase();
  2425. sign = value[0] === '-' ? -1 : 1;
  2426. digits = [];
  2427. if ('+-'.indexOf(value[0]) >= 0) {
  2428. value = value.slice(1);
  2429. }
  2430. if (value === '.inf') {
  2431. return (sign === 1) ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
  2432. } else if (value === '.nan') {
  2433. return NaN;
  2434. } else if (value.indexOf(':') >= 0) {
  2435. value.split(':').forEach(function (v) {
  2436. digits.unshift(parseFloat(v, 10));
  2437. });
  2438. value = 0.0;
  2439. base = 1;
  2440. digits.forEach(function (d) {
  2441. value += d * base;
  2442. base *= 60;
  2443. });
  2444. return sign * value;
  2445. }
  2446. return sign * parseFloat(value, 10);
  2447. }
  2448. var SCIENTIFIC_WITHOUT_DOT = /^[-+]?[0-9]+e/;
  2449. function representYamlFloat(object, style) {
  2450. var res;
  2451. if (isNaN(object)) {
  2452. switch (style) {
  2453. case 'lowercase': return '.nan';
  2454. case 'uppercase': return '.NAN';
  2455. case 'camelcase': return '.NaN';
  2456. }
  2457. } else if (Number.POSITIVE_INFINITY === object) {
  2458. switch (style) {
  2459. case 'lowercase': return '.inf';
  2460. case 'uppercase': return '.INF';
  2461. case 'camelcase': return '.Inf';
  2462. }
  2463. } else if (Number.NEGATIVE_INFINITY === object) {
  2464. switch (style) {
  2465. case 'lowercase': return '-.inf';
  2466. case 'uppercase': return '-.INF';
  2467. case 'camelcase': return '-.Inf';
  2468. }
  2469. } else if (common.isNegativeZero(object)) {
  2470. return '-0.0';
  2471. }
  2472. res = object.toString(10);
  2473. // JS stringifier can build scientific format without dots: 5e-100,
  2474. // while YAML requres dot: 5.e-100. Fix it with simple hack
  2475. return SCIENTIFIC_WITHOUT_DOT.test(res) ? res.replace('e', '.e') : res;
  2476. }
  2477. function isFloat(object) {
  2478. return (Object.prototype.toString.call(object) === '[object Number]') &&
  2479. (object % 1 !== 0 || common.isNegativeZero(object));
  2480. }
  2481. module.exports = new Type('tag:yaml.org,2002:float', {
  2482. kind: 'scalar',
  2483. resolve: resolveYamlFloat,
  2484. construct: constructYamlFloat,
  2485. predicate: isFloat,
  2486. represent: representYamlFloat,
  2487. defaultStyle: 'lowercase'
  2488. });
  2489. },{"../common":2,"../type":13}],17:[function(require,module,exports){
  2490. 'use strict';
  2491. var common = require('../common');
  2492. var Type = require('../type');
  2493. function isHexCode(c) {
  2494. return ((0x30/* 0 */ <= c) && (c <= 0x39/* 9 */)) ||
  2495. ((0x41/* A */ <= c) && (c <= 0x46/* F */)) ||
  2496. ((0x61/* a */ <= c) && (c <= 0x66/* f */));
  2497. }
  2498. function isOctCode(c) {
  2499. return ((0x30/* 0 */ <= c) && (c <= 0x37/* 7 */));
  2500. }
  2501. function isDecCode(c) {
  2502. return ((0x30/* 0 */ <= c) && (c <= 0x39/* 9 */));
  2503. }
  2504. function resolveYamlInteger(data) {
  2505. if (data === null) return false;
  2506. var max = data.length,
  2507. index = 0,
  2508. hasDigits = false,
  2509. ch;
  2510. if (!max) return false;
  2511. ch = data[index];
  2512. // sign
  2513. if (ch === '-' || ch === '+') {
  2514. ch = data[++index];
  2515. }
  2516. if (ch === '0') {
  2517. // 0
  2518. if (index + 1 === max) return true;
  2519. ch = data[++index];
  2520. // base 2, base 8, base 16
  2521. if (ch === 'b') {
  2522. // base 2
  2523. index++;
  2524. for (; index < max; index++) {
  2525. ch = data[index];
  2526. if (ch === '_') continue;
  2527. if (ch !== '0' && ch !== '1') return false;
  2528. hasDigits = true;
  2529. }
  2530. return hasDigits;
  2531. }
  2532. if (ch === 'x') {
  2533. // base 16
  2534. index++;
  2535. for (; index < max; index++) {
  2536. ch = data[index];
  2537. if (ch === '_') continue;
  2538. if (!isHexCode(data.charCodeAt(index))) return false;
  2539. hasDigits = true;
  2540. }
  2541. return hasDigits;
  2542. }
  2543. // base 8
  2544. for (; index < max; index++) {
  2545. ch = data[index];
  2546. if (ch === '_') continue;
  2547. if (!isOctCode(data.charCodeAt(index))) return false;
  2548. hasDigits = true;
  2549. }
  2550. return hasDigits;
  2551. }
  2552. // base 10 (except 0) or base 60
  2553. for (; index < max; index++) {
  2554. ch = data[index];
  2555. if (ch === '_') continue;
  2556. if (ch === ':') break;
  2557. if (!isDecCode(data.charCodeAt(index))) {
  2558. return false;
  2559. }
  2560. hasDigits = true;
  2561. }
  2562. if (!hasDigits) return false;
  2563. // if !base60 - done;
  2564. if (ch !== ':') return true;
  2565. // base60 almost not used, no needs to optimize
  2566. return /^(:[0-5]?[0-9])+$/.test(data.slice(index));
  2567. }
  2568. function constructYamlInteger(data) {
  2569. var value = data, sign = 1, ch, base, digits = [];
  2570. if (value.indexOf('_') !== -1) {
  2571. value = value.replace(/_/g, '');
  2572. }
  2573. ch = value[0];
  2574. if (ch === '-' || ch === '+') {
  2575. if (ch === '-') sign = -1;
  2576. value = value.slice(1);
  2577. ch = value[0];
  2578. }
  2579. if (value === '0') return 0;
  2580. if (ch === '0') {
  2581. if (value[1] === 'b') return sign * parseInt(value.slice(2), 2);
  2582. if (value[1] === 'x') return sign * parseInt(value, 16);
  2583. return sign * parseInt(value, 8);
  2584. }
  2585. if (value.indexOf(':') !== -1) {
  2586. value.split(':').forEach(function (v) {
  2587. digits.unshift(parseInt(v, 10));
  2588. });
  2589. value = 0;
  2590. base = 1;
  2591. digits.forEach(function (d) {
  2592. value += (d * base);
  2593. base *= 60;
  2594. });
  2595. return sign * value;
  2596. }
  2597. return sign * parseInt(value, 10);
  2598. }
  2599. function isInteger(object) {
  2600. return (Object.prototype.toString.call(object)) === '[object Number]' &&
  2601. (object % 1 === 0 && !common.isNegativeZero(object));
  2602. }
  2603. module.exports = new Type('tag:yaml.org,2002:int', {
  2604. kind: 'scalar',
  2605. resolve: resolveYamlInteger,
  2606. construct: constructYamlInteger,
  2607. predicate: isInteger,
  2608. represent: {
  2609. binary: function (object) { return '0b' + object.toString(2); },
  2610. octal: function (object) { return '0' + object.toString(8); },
  2611. decimal: function (object) { return object.toString(10); },
  2612. hexadecimal: function (object) { return '0x' + object.toString(16).toUpperCase(); }
  2613. },
  2614. defaultStyle: 'decimal',
  2615. styleAliases: {
  2616. binary: [ 2, 'bin' ],
  2617. octal: [ 8, 'oct' ],
  2618. decimal: [ 10, 'dec' ],
  2619. hexadecimal: [ 16, 'hex' ]
  2620. }
  2621. });
  2622. },{"../common":2,"../type":13}],18:[function(require,module,exports){
  2623. 'use strict';
  2624. var esprima;
  2625. // Browserified version does not have esprima
  2626. //
  2627. // 1. For node.js just require module as deps
  2628. // 2. For browser try to require mudule via external AMD system.
  2629. // If not found - try to fallback to window.esprima. If not
  2630. // found too - then fail to parse.
  2631. //
  2632. try {
  2633. // workaround to exclude package from browserify list.
  2634. var _require = require;
  2635. esprima = _require('esprima');
  2636. } catch (_) {
  2637. /*global window */
  2638. if (typeof window !== 'undefined') esprima = window.esprima;
  2639. }
  2640. var Type = require('../../type');
  2641. function resolveJavascriptFunction(data) {
  2642. if (data === null) return false;
  2643. try {
  2644. var source = '(' + data + ')',
  2645. ast = esprima.parse(source, { range: true });
  2646. if (ast.type !== 'Program' ||
  2647. ast.body.length !== 1 ||
  2648. ast.body[0].type !== 'ExpressionStatement' ||
  2649. ast.body[0].expression.type !== 'FunctionExpression') {
  2650. return false;
  2651. }
  2652. return true;
  2653. } catch (err) {
  2654. return false;
  2655. }
  2656. }
  2657. function constructJavascriptFunction(data) {
  2658. /*jslint evil:true*/
  2659. var source = '(' + data + ')',
  2660. ast = esprima.parse(source, { range: true }),
  2661. params = [],
  2662. body;
  2663. if (ast.type !== 'Program' ||
  2664. ast.body.length !== 1 ||
  2665. ast.body[0].type !== 'ExpressionStatement' ||
  2666. ast.body[0].expression.type !== 'FunctionExpression') {
  2667. throw new Error('Failed to resolve function');
  2668. }
  2669. ast.body[0].expression.params.forEach(function (param) {
  2670. params.push(param.name);
  2671. });
  2672. body = ast.body[0].expression.body.range;
  2673. // Esprima's ranges include the first '{' and the last '}' characters on
  2674. // function expressions. So cut them out.
  2675. /*eslint-disable no-new-func*/
  2676. return new Function(params, source.slice(body[0] + 1, body[1] - 1));
  2677. }
  2678. function representJavascriptFunction(object /*, style*/) {
  2679. return object.toString();
  2680. }
  2681. function isFunction(object) {
  2682. return Object.prototype.toString.call(object) === '[object Function]';
  2683. }
  2684. module.exports = new Type('tag:yaml.org,2002:js/function', {
  2685. kind: 'scalar',
  2686. resolve: resolveJavascriptFunction,
  2687. construct: constructJavascriptFunction,
  2688. predicate: isFunction,
  2689. represent: representJavascriptFunction
  2690. });
  2691. },{"../../type":13}],19:[function(require,module,exports){
  2692. 'use strict';
  2693. var Type = require('../../type');
  2694. function resolveJavascriptRegExp(data) {
  2695. if (data === null) return false;
  2696. if (data.length === 0) return false;
  2697. var regexp = data,
  2698. tail = /\/([gim]*)$/.exec(data),
  2699. modifiers = '';
  2700. // if regexp starts with '/' it can have modifiers and must be properly closed
  2701. // `/foo/gim` - modifiers tail can be maximum 3 chars
  2702. if (regexp[0] === '/') {
  2703. if (tail) modifiers = tail[1];
  2704. if (modifiers.length > 3) return false;
  2705. // if expression starts with /, is should be properly terminated
  2706. if (regexp[regexp.length - modifiers.length - 1] !== '/') return false;
  2707. }
  2708. return true;
  2709. }
  2710. function constructJavascriptRegExp(data) {
  2711. var regexp = data,
  2712. tail = /\/([gim]*)$/.exec(data),
  2713. modifiers = '';
  2714. // `/foo/gim` - tail can be maximum 4 chars
  2715. if (regexp[0] === '/') {
  2716. if (tail) modifiers = tail[1];
  2717. regexp = regexp.slice(1, regexp.length - modifiers.length - 1);
  2718. }
  2719. return new RegExp(regexp, modifiers);
  2720. }
  2721. function representJavascriptRegExp(object /*, style*/) {
  2722. var result = '/' + object.source + '/';
  2723. if (object.global) result += 'g';
  2724. if (object.multiline) result += 'm';
  2725. if (object.ignoreCase) result += 'i';
  2726. return result;
  2727. }
  2728. function isRegExp(object) {
  2729. return Object.prototype.toString.call(object) === '[object RegExp]';
  2730. }
  2731. module.exports = new Type('tag:yaml.org,2002:js/regexp', {
  2732. kind: 'scalar',
  2733. resolve: resolveJavascriptRegExp,
  2734. construct: constructJavascriptRegExp,
  2735. predicate: isRegExp,
  2736. represent: representJavascriptRegExp
  2737. });
  2738. },{"../../type":13}],20:[function(require,module,exports){
  2739. 'use strict';
  2740. var Type = require('../../type');
  2741. function resolveJavascriptUndefined() {
  2742. return true;
  2743. }
  2744. function constructJavascriptUndefined() {
  2745. /*eslint-disable no-undefined*/
  2746. return undefined;
  2747. }
  2748. function representJavascriptUndefined() {
  2749. return '';
  2750. }
  2751. function isUndefined(object) {
  2752. return typeof object === 'undefined';
  2753. }
  2754. module.exports = new Type('tag:yaml.org,2002:js/undefined', {
  2755. kind: 'scalar',
  2756. resolve: resolveJavascriptUndefined,
  2757. construct: constructJavascriptUndefined,
  2758. predicate: isUndefined,
  2759. represent: representJavascriptUndefined
  2760. });
  2761. },{"../../type":13}],21:[function(require,module,exports){
  2762. 'use strict';
  2763. var Type = require('../type');
  2764. module.exports = new Type('tag:yaml.org,2002:map', {
  2765. kind: 'mapping',
  2766. construct: function (data) { return data !== null ? data : {}; }
  2767. });
  2768. },{"../type":13}],22:[function(require,module,exports){
  2769. 'use strict';
  2770. var Type = require('../type');
  2771. function resolveYamlMerge(data) {
  2772. return data === '<<' || data === null;
  2773. }
  2774. module.exports = new Type('tag:yaml.org,2002:merge', {
  2775. kind: 'scalar',
  2776. resolve: resolveYamlMerge
  2777. });
  2778. },{"../type":13}],23:[function(require,module,exports){
  2779. 'use strict';
  2780. var Type = require('../type');
  2781. function resolveYamlNull(data) {
  2782. if (data === null) return true;
  2783. var max = data.length;
  2784. return (max === 1 && data === '~') ||
  2785. (max === 4 && (data === 'null' || data === 'Null' || data === 'NULL'));
  2786. }
  2787. function constructYamlNull() {
  2788. return null;
  2789. }
  2790. function isNull(object) {
  2791. return object === null;
  2792. }
  2793. module.exports = new Type('tag:yaml.org,2002:null', {
  2794. kind: 'scalar',
  2795. resolve: resolveYamlNull,
  2796. construct: constructYamlNull,
  2797. predicate: isNull,
  2798. represent: {
  2799. canonical: function () { return '~'; },
  2800. lowercase: function () { return 'null'; },
  2801. uppercase: function () { return 'NULL'; },
  2802. camelcase: function () { return 'Null'; }
  2803. },
  2804. defaultStyle: 'lowercase'
  2805. });
  2806. },{"../type":13}],24:[function(require,module,exports){
  2807. 'use strict';
  2808. var Type = require('../type');
  2809. var _hasOwnProperty = Object.prototype.hasOwnProperty;
  2810. var _toString = Object.prototype.toString;
  2811. function resolveYamlOmap(data) {
  2812. if (data === null) return true;
  2813. var objectKeys = [], index, length, pair, pairKey, pairHasKey,
  2814. object = data;
  2815. for (index = 0, length = object.length; index < length; index += 1) {
  2816. pair = object[index];
  2817. pairHasKey = false;
  2818. if (_toString.call(pair) !== '[object Object]') return false;
  2819. for (pairKey in pair) {
  2820. if (_hasOwnProperty.call(pair, pairKey)) {
  2821. if (!pairHasKey) pairHasKey = true;
  2822. else return false;
  2823. }
  2824. }
  2825. if (!pairHasKey) return false;
  2826. if (objectKeys.indexOf(pairKey) === -1) objectKeys.push(pairKey);
  2827. else return false;
  2828. }
  2829. return true;
  2830. }
  2831. function constructYamlOmap(data) {
  2832. return data !== null ? data : [];
  2833. }
  2834. module.exports = new Type('tag:yaml.org,2002:omap', {
  2835. kind: 'sequence',
  2836. resolve: resolveYamlOmap,
  2837. construct: constructYamlOmap
  2838. });
  2839. },{"../type":13}],25:[function(require,module,exports){
  2840. 'use strict';
  2841. var Type = require('../type');
  2842. var _toString = Object.prototype.toString;
  2843. function resolveYamlPairs(data) {
  2844. if (data === null) return true;
  2845. var index, length, pair, keys, result,
  2846. object = data;
  2847. result = new Array(object.length);
  2848. for (index = 0, length = object.length; index < length; index += 1) {
  2849. pair = object[index];
  2850. if (_toString.call(pair) !== '[object Object]') return false;
  2851. keys = Object.keys(pair);
  2852. if (keys.length !== 1) return false;
  2853. result[index] = [ keys[0], pair[keys[0]] ];
  2854. }
  2855. return true;
  2856. }
  2857. function constructYamlPairs(data) {
  2858. if (data === null) return [];
  2859. var index, length, pair, keys, result,
  2860. object = data;
  2861. result = new Array(object.length);
  2862. for (index = 0, length = object.length; index < length; index += 1) {
  2863. pair = object[index];
  2864. keys = Object.keys(pair);
  2865. result[index] = [ keys[0], pair[keys[0]] ];
  2866. }
  2867. return result;
  2868. }
  2869. module.exports = new Type('tag:yaml.org,2002:pairs', {
  2870. kind: 'sequence',
  2871. resolve: resolveYamlPairs,
  2872. construct: constructYamlPairs
  2873. });
  2874. },{"../type":13}],26:[function(require,module,exports){
  2875. 'use strict';
  2876. var Type = require('../type');
  2877. module.exports = new Type('tag:yaml.org,2002:seq', {
  2878. kind: 'sequence',
  2879. construct: function (data) { return data !== null ? data : []; }
  2880. });
  2881. },{"../type":13}],27:[function(require,module,exports){
  2882. 'use strict';
  2883. var Type = require('../type');
  2884. var _hasOwnProperty = Object.prototype.hasOwnProperty;
  2885. function resolveYamlSet(data) {
  2886. if (data === null) return true;
  2887. var key, object = data;
  2888. for (key in object) {
  2889. if (_hasOwnProperty.call(object, key)) {
  2890. if (object[key] !== null) return false;
  2891. }
  2892. }
  2893. return true;
  2894. }
  2895. function constructYamlSet(data) {
  2896. return data !== null ? data : {};
  2897. }
  2898. module.exports = new Type('tag:yaml.org,2002:set', {
  2899. kind: 'mapping',
  2900. resolve: resolveYamlSet,
  2901. construct: constructYamlSet
  2902. });
  2903. },{"../type":13}],28:[function(require,module,exports){
  2904. 'use strict';
  2905. var Type = require('../type');
  2906. module.exports = new Type('tag:yaml.org,2002:str', {
  2907. kind: 'scalar',
  2908. construct: function (data) { return data !== null ? data : ''; }
  2909. });
  2910. },{"../type":13}],29:[function(require,module,exports){
  2911. 'use strict';
  2912. var Type = require('../type');
  2913. var YAML_DATE_REGEXP = new RegExp(
  2914. '^([0-9][0-9][0-9][0-9])' + // [1] year
  2915. '-([0-9][0-9])' + // [2] month
  2916. '-([0-9][0-9])$'); // [3] day
  2917. var YAML_TIMESTAMP_REGEXP = new RegExp(
  2918. '^([0-9][0-9][0-9][0-9])' + // [1] year
  2919. '-([0-9][0-9]?)' + // [2] month
  2920. '-([0-9][0-9]?)' + // [3] day
  2921. '(?:[Tt]|[ \\t]+)' + // ...
  2922. '([0-9][0-9]?)' + // [4] hour
  2923. ':([0-9][0-9])' + // [5] minute
  2924. ':([0-9][0-9])' + // [6] second
  2925. '(?:\\.([0-9]*))?' + // [7] fraction
  2926. '(?:[ \\t]*(Z|([-+])([0-9][0-9]?)' + // [8] tz [9] tz_sign [10] tz_hour
  2927. '(?::([0-9][0-9]))?))?$'); // [11] tz_minute
  2928. function resolveYamlTimestamp(data) {
  2929. if (data === null) return false;
  2930. if (YAML_DATE_REGEXP.exec(data) !== null) return true;
  2931. if (YAML_TIMESTAMP_REGEXP.exec(data) !== null) return true;
  2932. return false;
  2933. }
  2934. function constructYamlTimestamp(data) {
  2935. var match, year, month, day, hour, minute, second, fraction = 0,
  2936. delta = null, tz_hour, tz_minute, date;
  2937. match = YAML_DATE_REGEXP.exec(data);
  2938. if (match === null) match = YAML_TIMESTAMP_REGEXP.exec(data);
  2939. if (match === null) throw new Error('Date resolve error');
  2940. // match: [1] year [2] month [3] day
  2941. year = +(match[1]);
  2942. month = +(match[2]) - 1; // JS month starts with 0
  2943. day = +(match[3]);
  2944. if (!match[4]) { // no hour
  2945. return new Date(Date.UTC(year, month, day));
  2946. }
  2947. // match: [4] hour [5] minute [6] second [7] fraction
  2948. hour = +(match[4]);
  2949. minute = +(match[5]);
  2950. second = +(match[6]);
  2951. if (match[7]) {
  2952. fraction = match[7].slice(0, 3);
  2953. while (fraction.length < 3) { // milli-seconds
  2954. fraction += '0';
  2955. }
  2956. fraction = +fraction;
  2957. }
  2958. // match: [8] tz [9] tz_sign [10] tz_hour [11] tz_minute
  2959. if (match[9]) {
  2960. tz_hour = +(match[10]);
  2961. tz_minute = +(match[11] || 0);
  2962. delta = (tz_hour * 60 + tz_minute) * 60000; // delta in mili-seconds
  2963. if (match[9] === '-') delta = -delta;
  2964. }
  2965. date = new Date(Date.UTC(year, month, day, hour, minute, second, fraction));
  2966. if (delta) date.setTime(date.getTime() - delta);
  2967. return date;
  2968. }
  2969. function representYamlTimestamp(object /*, style*/) {
  2970. return object.toISOString();
  2971. }
  2972. module.exports = new Type('tag:yaml.org,2002:timestamp', {
  2973. kind: 'scalar',
  2974. resolve: resolveYamlTimestamp,
  2975. construct: constructYamlTimestamp,
  2976. instanceOf: Date,
  2977. represent: representYamlTimestamp
  2978. });
  2979. },{"../type":13}],30:[function(require,module,exports){
  2980. },{}],"/":[function(require,module,exports){
  2981. 'use strict';
  2982. var yaml = require('./lib/js-yaml.js');
  2983. module.exports = yaml;
  2984. },{"./lib/js-yaml.js":1}]},{},[])("/")
  2985. });