Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

js-yaml.js 106KB

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