js_yaml.js 108 KB

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