yaml.js 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893
  1. (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  2. var Dumper, Inline, Utils;
  3. Utils = require('./Utils');
  4. Inline = require('./Inline');
  5. Dumper = (function() {
  6. function Dumper() {}
  7. Dumper.indentation = 4;
  8. Dumper.prototype.dump = function(input, inline, indent, exceptionOnInvalidType, objectEncoder) {
  9. var i, key, len, output, prefix, value, willBeInlined;
  10. if (inline == null) {
  11. inline = 0;
  12. }
  13. if (indent == null) {
  14. indent = 0;
  15. }
  16. if (exceptionOnInvalidType == null) {
  17. exceptionOnInvalidType = false;
  18. }
  19. if (objectEncoder == null) {
  20. objectEncoder = null;
  21. }
  22. output = '';
  23. prefix = (indent ? Utils.strRepeat(' ', indent) : '');
  24. if (inline <= 0 || typeof input !== 'object' || input instanceof Date || Utils.isEmpty(input)) {
  25. output += prefix + Inline.dump(input, exceptionOnInvalidType, objectEncoder);
  26. } else {
  27. if (input instanceof Array) {
  28. for (i = 0, len = input.length; i < len; i++) {
  29. value = input[i];
  30. willBeInlined = inline - 1 <= 0 || typeof value !== 'object' || Utils.isEmpty(value);
  31. output += prefix + '-' + (willBeInlined ? ' ' : "\n") + this.dump(value, inline - 1, (willBeInlined ? 0 : indent + this.indentation), exceptionOnInvalidType, objectEncoder) + (willBeInlined ? "\n" : '');
  32. }
  33. } else {
  34. for (key in input) {
  35. value = input[key];
  36. willBeInlined = inline - 1 <= 0 || typeof value !== 'object' || Utils.isEmpty(value);
  37. output += prefix + Inline.dump(key, exceptionOnInvalidType, objectEncoder) + ':' + (willBeInlined ? ' ' : "\n") + this.dump(value, inline - 1, (willBeInlined ? 0 : indent + this.indentation), exceptionOnInvalidType, objectEncoder) + (willBeInlined ? "\n" : '');
  38. }
  39. }
  40. }
  41. return output;
  42. };
  43. return Dumper;
  44. })();
  45. module.exports = Dumper;
  46. },{"./Inline":6,"./Utils":10}],2:[function(require,module,exports){
  47. var Escaper, Pattern;
  48. Pattern = require('./Pattern');
  49. Escaper = (function() {
  50. var ch;
  51. function Escaper() {}
  52. Escaper.LIST_ESCAPEES = ['\\', '\\\\', '\\"', '"', "\x00", "\x01", "\x02", "\x03", "\x04", "\x05", "\x06", "\x07", "\x08", "\x09", "\x0a", "\x0b", "\x0c", "\x0d", "\x0e", "\x0f", "\x10", "\x11", "\x12", "\x13", "\x14", "\x15", "\x16", "\x17", "\x18", "\x19", "\x1a", "\x1b", "\x1c", "\x1d", "\x1e", "\x1f", (ch = String.fromCharCode)(0x0085), ch(0x00A0), ch(0x2028), ch(0x2029)];
  53. Escaper.LIST_ESCAPED = ['\\\\', '\\"', '\\"', '\\"', "\\0", "\\x01", "\\x02", "\\x03", "\\x04", "\\x05", "\\x06", "\\a", "\\b", "\\t", "\\n", "\\v", "\\f", "\\r", "\\x0e", "\\x0f", "\\x10", "\\x11", "\\x12", "\\x13", "\\x14", "\\x15", "\\x16", "\\x17", "\\x18", "\\x19", "\\x1a", "\\e", "\\x1c", "\\x1d", "\\x1e", "\\x1f", "\\N", "\\_", "\\L", "\\P"];
  54. Escaper.MAPPING_ESCAPEES_TO_ESCAPED = (function() {
  55. var i, j, mapping, ref;
  56. mapping = {};
  57. for (i = j = 0, ref = Escaper.LIST_ESCAPEES.length; 0 <= ref ? j < ref : j > ref; i = 0 <= ref ? ++j : --j) {
  58. mapping[Escaper.LIST_ESCAPEES[i]] = Escaper.LIST_ESCAPED[i];
  59. }
  60. return mapping;
  61. })();
  62. Escaper.PATTERN_CHARACTERS_TO_ESCAPE = new Pattern('[\\x00-\\x1f]|\xc2\x85|\xc2\xa0|\xe2\x80\xa8|\xe2\x80\xa9');
  63. Escaper.PATTERN_MAPPING_ESCAPEES = new Pattern(Escaper.LIST_ESCAPEES.join('|').split('\\').join('\\\\'));
  64. Escaper.PATTERN_SINGLE_QUOTING = new Pattern('[\\s\'":{}[\\],&*#?]|^[-?|<>=!%@`]');
  65. Escaper.requiresDoubleQuoting = function(value) {
  66. return this.PATTERN_CHARACTERS_TO_ESCAPE.test(value);
  67. };
  68. Escaper.escapeWithDoubleQuotes = function(value) {
  69. var result;
  70. result = this.PATTERN_MAPPING_ESCAPEES.replace(value, (function(_this) {
  71. return function(str) {
  72. return _this.MAPPING_ESCAPEES_TO_ESCAPED[str];
  73. };
  74. })(this));
  75. return '"' + result + '"';
  76. };
  77. Escaper.requiresSingleQuoting = function(value) {
  78. return this.PATTERN_SINGLE_QUOTING.test(value);
  79. };
  80. Escaper.escapeWithSingleQuotes = function(value) {
  81. return "'" + value.replace(/'/g, "''") + "'";
  82. };
  83. return Escaper;
  84. })();
  85. module.exports = Escaper;
  86. },{"./Pattern":8}],3:[function(require,module,exports){
  87. var DumpException,
  88. extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
  89. hasProp = {}.hasOwnProperty;
  90. DumpException = (function(superClass) {
  91. extend(DumpException, superClass);
  92. function DumpException(message, parsedLine, snippet) {
  93. this.message = message;
  94. this.parsedLine = parsedLine;
  95. this.snippet = snippet;
  96. }
  97. DumpException.prototype.toString = function() {
  98. if ((this.parsedLine != null) && (this.snippet != null)) {
  99. return '<DumpException> ' + this.message + ' (line ' + this.parsedLine + ': \'' + this.snippet + '\')';
  100. } else {
  101. return '<DumpException> ' + this.message;
  102. }
  103. };
  104. return DumpException;
  105. })(Error);
  106. module.exports = DumpException;
  107. },{}],4:[function(require,module,exports){
  108. var ParseException,
  109. extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
  110. hasProp = {}.hasOwnProperty;
  111. ParseException = (function(superClass) {
  112. extend(ParseException, superClass);
  113. function ParseException(message, parsedLine, snippet) {
  114. this.message = message;
  115. this.parsedLine = parsedLine;
  116. this.snippet = snippet;
  117. }
  118. ParseException.prototype.toString = function() {
  119. if ((this.parsedLine != null) && (this.snippet != null)) {
  120. return '<ParseException> ' + this.message + ' (line ' + this.parsedLine + ': \'' + this.snippet + '\')';
  121. } else {
  122. return '<ParseException> ' + this.message;
  123. }
  124. };
  125. return ParseException;
  126. })(Error);
  127. module.exports = ParseException;
  128. },{}],5:[function(require,module,exports){
  129. var ParseMore,
  130. extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
  131. hasProp = {}.hasOwnProperty;
  132. ParseMore = (function(superClass) {
  133. extend(ParseMore, superClass);
  134. function ParseMore(message, parsedLine, snippet) {
  135. this.message = message;
  136. this.parsedLine = parsedLine;
  137. this.snippet = snippet;
  138. }
  139. ParseMore.prototype.toString = function() {
  140. if ((this.parsedLine != null) && (this.snippet != null)) {
  141. return '<ParseMore> ' + this.message + ' (line ' + this.parsedLine + ': \'' + this.snippet + '\')';
  142. } else {
  143. return '<ParseMore> ' + this.message;
  144. }
  145. };
  146. return ParseMore;
  147. })(Error);
  148. module.exports = ParseMore;
  149. },{}],6:[function(require,module,exports){
  150. var DumpException, Escaper, Inline, ParseException, ParseMore, Pattern, Unescaper, Utils,
  151. indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
  152. Pattern = require('./Pattern');
  153. Unescaper = require('./Unescaper');
  154. Escaper = require('./Escaper');
  155. Utils = require('./Utils');
  156. ParseException = require('./Exception/ParseException');
  157. ParseMore = require('./Exception/ParseMore');
  158. DumpException = require('./Exception/DumpException');
  159. Inline = (function() {
  160. function Inline() {}
  161. Inline.REGEX_QUOTED_STRING = '(?:"(?:[^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'(?:[^\']*(?:\'\'[^\']*)*)\')';
  162. Inline.PATTERN_TRAILING_COMMENTS = new Pattern('^\\s*#.*$');
  163. Inline.PATTERN_QUOTED_SCALAR = new Pattern('^' + Inline.REGEX_QUOTED_STRING);
  164. Inline.PATTERN_THOUSAND_NUMERIC_SCALAR = new Pattern('^(-|\\+)?[0-9,]+(\\.[0-9]+)?$');
  165. Inline.PATTERN_SCALAR_BY_DELIMITERS = {};
  166. Inline.settings = {};
  167. Inline.configure = function(exceptionOnInvalidType, objectDecoder) {
  168. if (exceptionOnInvalidType == null) {
  169. exceptionOnInvalidType = null;
  170. }
  171. if (objectDecoder == null) {
  172. objectDecoder = null;
  173. }
  174. this.settings.exceptionOnInvalidType = exceptionOnInvalidType;
  175. this.settings.objectDecoder = objectDecoder;
  176. };
  177. Inline.parse = function(value, exceptionOnInvalidType, objectDecoder) {
  178. var context, result;
  179. if (exceptionOnInvalidType == null) {
  180. exceptionOnInvalidType = false;
  181. }
  182. if (objectDecoder == null) {
  183. objectDecoder = null;
  184. }
  185. this.settings.exceptionOnInvalidType = exceptionOnInvalidType;
  186. this.settings.objectDecoder = objectDecoder;
  187. if (value == null) {
  188. return '';
  189. }
  190. value = Utils.trim(value);
  191. if (0 === value.length) {
  192. return '';
  193. }
  194. context = {
  195. exceptionOnInvalidType: exceptionOnInvalidType,
  196. objectDecoder: objectDecoder,
  197. i: 0
  198. };
  199. switch (value.charAt(0)) {
  200. case '[':
  201. result = this.parseSequence(value, context);
  202. ++context.i;
  203. break;
  204. case '{':
  205. result = this.parseMapping(value, context);
  206. ++context.i;
  207. break;
  208. default:
  209. result = this.parseScalar(value, null, ['"', "'"], context);
  210. }
  211. if (this.PATTERN_TRAILING_COMMENTS.replace(value.slice(context.i), '') !== '') {
  212. throw new ParseException('Unexpected characters near "' + value.slice(context.i) + '".');
  213. }
  214. return result;
  215. };
  216. Inline.dump = function(value, exceptionOnInvalidType, objectEncoder) {
  217. var ref, result, type;
  218. if (exceptionOnInvalidType == null) {
  219. exceptionOnInvalidType = false;
  220. }
  221. if (objectEncoder == null) {
  222. objectEncoder = null;
  223. }
  224. if (value == null) {
  225. return 'null';
  226. }
  227. type = typeof value;
  228. if (type === 'object') {
  229. if (value instanceof Date) {
  230. return value.toISOString();
  231. } else if (objectEncoder != null) {
  232. result = objectEncoder(value);
  233. if (typeof result === 'string' || (result != null)) {
  234. return result;
  235. }
  236. }
  237. return this.dumpObject(value);
  238. }
  239. if (type === 'boolean') {
  240. return (value ? 'true' : 'false');
  241. }
  242. if (Utils.isDigits(value)) {
  243. return (type === 'string' ? "'" + value + "'" : String(parseInt(value)));
  244. }
  245. if (Utils.isNumeric(value)) {
  246. return (type === 'string' ? "'" + value + "'" : String(parseFloat(value)));
  247. }
  248. if (type === 'number') {
  249. return (value === Infinity ? '.Inf' : (value === -Infinity ? '-.Inf' : (isNaN(value) ? '.NaN' : value)));
  250. }
  251. if (Escaper.requiresDoubleQuoting(value)) {
  252. return Escaper.escapeWithDoubleQuotes(value);
  253. }
  254. if (Escaper.requiresSingleQuoting(value)) {
  255. return Escaper.escapeWithSingleQuotes(value);
  256. }
  257. if ('' === value) {
  258. return '""';
  259. }
  260. if (Utils.PATTERN_DATE.test(value)) {
  261. return "'" + value + "'";
  262. }
  263. if ((ref = value.toLowerCase()) === 'null' || ref === '~' || ref === 'true' || ref === 'false') {
  264. return "'" + value + "'";
  265. }
  266. return value;
  267. };
  268. Inline.dumpObject = function(value, exceptionOnInvalidType, objectSupport) {
  269. var j, key, len1, output, val;
  270. if (objectSupport == null) {
  271. objectSupport = null;
  272. }
  273. if (value instanceof Array) {
  274. output = [];
  275. for (j = 0, len1 = value.length; j < len1; j++) {
  276. val = value[j];
  277. output.push(this.dump(val));
  278. }
  279. return '[' + output.join(', ') + ']';
  280. } else {
  281. output = [];
  282. for (key in value) {
  283. val = value[key];
  284. output.push(this.dump(key) + ': ' + this.dump(val));
  285. }
  286. return '{' + output.join(', ') + '}';
  287. }
  288. };
  289. Inline.parseScalar = function(scalar, delimiters, stringDelimiters, context, evaluate) {
  290. var i, joinedDelimiters, match, output, pattern, ref, ref1, strpos, tmp;
  291. if (delimiters == null) {
  292. delimiters = null;
  293. }
  294. if (stringDelimiters == null) {
  295. stringDelimiters = ['"', "'"];
  296. }
  297. if (context == null) {
  298. context = null;
  299. }
  300. if (evaluate == null) {
  301. evaluate = true;
  302. }
  303. if (context == null) {
  304. context = {
  305. exceptionOnInvalidType: this.settings.exceptionOnInvalidType,
  306. objectDecoder: this.settings.objectDecoder,
  307. i: 0
  308. };
  309. }
  310. i = context.i;
  311. if (ref = scalar.charAt(i), indexOf.call(stringDelimiters, ref) >= 0) {
  312. output = this.parseQuotedScalar(scalar, context);
  313. i = context.i;
  314. if (delimiters != null) {
  315. tmp = Utils.ltrim(scalar.slice(i), ' ');
  316. if (!(ref1 = tmp.charAt(0), indexOf.call(delimiters, ref1) >= 0)) {
  317. throw new ParseException('Unexpected characters (' + scalar.slice(i) + ').');
  318. }
  319. }
  320. } else {
  321. if (!delimiters) {
  322. output = scalar.slice(i);
  323. i += output.length;
  324. strpos = output.indexOf(' #');
  325. if (strpos !== -1) {
  326. output = Utils.rtrim(output.slice(0, strpos));
  327. }
  328. } else {
  329. joinedDelimiters = delimiters.join('|');
  330. pattern = this.PATTERN_SCALAR_BY_DELIMITERS[joinedDelimiters];
  331. if (pattern == null) {
  332. pattern = new Pattern('^(.+?)(' + joinedDelimiters + ')');
  333. this.PATTERN_SCALAR_BY_DELIMITERS[joinedDelimiters] = pattern;
  334. }
  335. if (match = pattern.exec(scalar.slice(i))) {
  336. output = match[1];
  337. i += output.length;
  338. } else {
  339. throw new ParseException('Malformed inline YAML string (' + scalar + ').');
  340. }
  341. }
  342. if (evaluate) {
  343. output = this.evaluateScalar(output, context);
  344. }
  345. }
  346. context.i = i;
  347. return output;
  348. };
  349. Inline.parseQuotedScalar = function(scalar, context) {
  350. var i, match, output;
  351. i = context.i;
  352. if (!(match = this.PATTERN_QUOTED_SCALAR.exec(scalar.slice(i)))) {
  353. throw new ParseMore('Malformed inline YAML string (' + scalar.slice(i) + ').');
  354. }
  355. output = match[0].substr(1, match[0].length - 2);
  356. if ('"' === scalar.charAt(i)) {
  357. output = Unescaper.unescapeDoubleQuotedString(output);
  358. } else {
  359. output = Unescaper.unescapeSingleQuotedString(output);
  360. }
  361. i += match[0].length;
  362. context.i = i;
  363. return output;
  364. };
  365. Inline.parseSequence = function(sequence, context) {
  366. var e, error, i, isQuoted, len, output, ref, value;
  367. output = [];
  368. len = sequence.length;
  369. i = context.i;
  370. i += 1;
  371. while (i < len) {
  372. context.i = i;
  373. switch (sequence.charAt(i)) {
  374. case '[':
  375. output.push(this.parseSequence(sequence, context));
  376. i = context.i;
  377. break;
  378. case '{':
  379. output.push(this.parseMapping(sequence, context));
  380. i = context.i;
  381. break;
  382. case ']':
  383. return output;
  384. case ',':
  385. case ' ':
  386. case "\n":
  387. break;
  388. default:
  389. isQuoted = ((ref = sequence.charAt(i)) === '"' || ref === "'");
  390. value = this.parseScalar(sequence, [',', ']'], ['"', "'"], context);
  391. i = context.i;
  392. if (!isQuoted && typeof value === 'string' && (value.indexOf(': ') !== -1 || value.indexOf(":\n") !== -1)) {
  393. try {
  394. value = this.parseMapping('{' + value + '}');
  395. } catch (error) {
  396. e = error;
  397. }
  398. }
  399. output.push(value);
  400. --i;
  401. }
  402. ++i;
  403. }
  404. throw new ParseMore('Malformed inline YAML string ' + sequence);
  405. };
  406. Inline.parseMapping = function(mapping, context) {
  407. var done, i, key, len, output, shouldContinueWhileLoop, value;
  408. output = {};
  409. len = mapping.length;
  410. i = context.i;
  411. i += 1;
  412. shouldContinueWhileLoop = false;
  413. while (i < len) {
  414. context.i = i;
  415. switch (mapping.charAt(i)) {
  416. case ' ':
  417. case ',':
  418. case "\n":
  419. ++i;
  420. context.i = i;
  421. shouldContinueWhileLoop = true;
  422. break;
  423. case '}':
  424. return output;
  425. }
  426. if (shouldContinueWhileLoop) {
  427. shouldContinueWhileLoop = false;
  428. continue;
  429. }
  430. key = this.parseScalar(mapping, [':', ' ', "\n"], ['"', "'"], context, false);
  431. i = context.i;
  432. done = false;
  433. while (i < len) {
  434. context.i = i;
  435. switch (mapping.charAt(i)) {
  436. case '[':
  437. value = this.parseSequence(mapping, context);
  438. i = context.i;
  439. if (output[key] === void 0) {
  440. output[key] = value;
  441. }
  442. done = true;
  443. break;
  444. case '{':
  445. value = this.parseMapping(mapping, context);
  446. i = context.i;
  447. if (output[key] === void 0) {
  448. output[key] = value;
  449. }
  450. done = true;
  451. break;
  452. case ':':
  453. case ' ':
  454. case "\n":
  455. break;
  456. default:
  457. value = this.parseScalar(mapping, [',', '}'], ['"', "'"], context);
  458. i = context.i;
  459. if (output[key] === void 0) {
  460. output[key] = value;
  461. }
  462. done = true;
  463. --i;
  464. }
  465. ++i;
  466. if (done) {
  467. break;
  468. }
  469. }
  470. }
  471. throw new ParseMore('Malformed inline YAML string ' + mapping);
  472. };
  473. Inline.evaluateScalar = function(scalar, context) {
  474. var cast, date, exceptionOnInvalidType, firstChar, firstSpace, firstWord, objectDecoder, raw, scalarLower, subValue, trimmedScalar;
  475. scalar = Utils.trim(scalar);
  476. scalarLower = scalar.toLowerCase();
  477. switch (scalarLower) {
  478. case 'null':
  479. case '':
  480. case '~':
  481. return null;
  482. case 'true':
  483. return true;
  484. case 'false':
  485. return false;
  486. case '.inf':
  487. return Infinity;
  488. case '.nan':
  489. return NaN;
  490. case '-.inf':
  491. return Infinity;
  492. default:
  493. firstChar = scalarLower.charAt(0);
  494. switch (firstChar) {
  495. case '!':
  496. firstSpace = scalar.indexOf(' ');
  497. if (firstSpace === -1) {
  498. firstWord = scalarLower;
  499. } else {
  500. firstWord = scalarLower.slice(0, firstSpace);
  501. }
  502. switch (firstWord) {
  503. case '!':
  504. if (firstSpace !== -1) {
  505. return parseInt(this.parseScalar(scalar.slice(2)));
  506. }
  507. return null;
  508. case '!str':
  509. return Utils.ltrim(scalar.slice(4));
  510. case '!!str':
  511. return Utils.ltrim(scalar.slice(5));
  512. case '!!int':
  513. return parseInt(this.parseScalar(scalar.slice(5)));
  514. case '!!bool':
  515. return Utils.parseBoolean(this.parseScalar(scalar.slice(6)), false);
  516. case '!!float':
  517. return parseFloat(this.parseScalar(scalar.slice(7)));
  518. case '!!timestamp':
  519. return Utils.stringToDate(Utils.ltrim(scalar.slice(11)));
  520. default:
  521. if (context == null) {
  522. context = {
  523. exceptionOnInvalidType: this.settings.exceptionOnInvalidType,
  524. objectDecoder: this.settings.objectDecoder,
  525. i: 0
  526. };
  527. }
  528. objectDecoder = context.objectDecoder, exceptionOnInvalidType = context.exceptionOnInvalidType;
  529. if (objectDecoder) {
  530. trimmedScalar = Utils.rtrim(scalar);
  531. firstSpace = trimmedScalar.indexOf(' ');
  532. if (firstSpace === -1) {
  533. return objectDecoder(trimmedScalar, null);
  534. } else {
  535. subValue = Utils.ltrim(trimmedScalar.slice(firstSpace + 1));
  536. if (!(subValue.length > 0)) {
  537. subValue = null;
  538. }
  539. return objectDecoder(trimmedScalar.slice(0, firstSpace), subValue);
  540. }
  541. }
  542. if (exceptionOnInvalidType) {
  543. throw new ParseException('Custom object support when parsing a YAML file has been disabled.');
  544. }
  545. return null;
  546. }
  547. break;
  548. case '0':
  549. if ('0x' === scalar.slice(0, 2)) {
  550. return Utils.hexDec(scalar);
  551. } else if (Utils.isDigits(scalar)) {
  552. return Utils.octDec(scalar);
  553. } else if (Utils.isNumeric(scalar)) {
  554. return parseFloat(scalar);
  555. } else {
  556. return scalar;
  557. }
  558. break;
  559. case '+':
  560. if (Utils.isDigits(scalar)) {
  561. raw = scalar;
  562. cast = parseInt(raw);
  563. if (raw === String(cast)) {
  564. return cast;
  565. } else {
  566. return raw;
  567. }
  568. } else if (Utils.isNumeric(scalar)) {
  569. return parseFloat(scalar);
  570. } else if (this.PATTERN_THOUSAND_NUMERIC_SCALAR.test(scalar)) {
  571. return parseFloat(scalar.replace(',', ''));
  572. }
  573. return scalar;
  574. case '-':
  575. if (Utils.isDigits(scalar.slice(1))) {
  576. if ('0' === scalar.charAt(1)) {
  577. return -Utils.octDec(scalar.slice(1));
  578. } else {
  579. raw = scalar.slice(1);
  580. cast = parseInt(raw);
  581. if (raw === String(cast)) {
  582. return -cast;
  583. } else {
  584. return -raw;
  585. }
  586. }
  587. } else if (Utils.isNumeric(scalar)) {
  588. return parseFloat(scalar);
  589. } else if (this.PATTERN_THOUSAND_NUMERIC_SCALAR.test(scalar)) {
  590. return parseFloat(scalar.replace(',', ''));
  591. }
  592. return scalar;
  593. default:
  594. if (date = Utils.stringToDate(scalar)) {
  595. return date;
  596. } else if (Utils.isNumeric(scalar)) {
  597. return parseFloat(scalar);
  598. } else if (this.PATTERN_THOUSAND_NUMERIC_SCALAR.test(scalar)) {
  599. return parseFloat(scalar.replace(',', ''));
  600. }
  601. return scalar;
  602. }
  603. }
  604. };
  605. return Inline;
  606. })();
  607. module.exports = Inline;
  608. },{"./Escaper":2,"./Exception/DumpException":3,"./Exception/ParseException":4,"./Exception/ParseMore":5,"./Pattern":8,"./Unescaper":9,"./Utils":10}],7:[function(require,module,exports){
  609. var Inline, ParseException, ParseMore, Parser, Pattern, Utils;
  610. Inline = require('./Inline');
  611. Pattern = require('./Pattern');
  612. Utils = require('./Utils');
  613. ParseException = require('./Exception/ParseException');
  614. ParseMore = require('./Exception/ParseMore');
  615. Parser = (function() {
  616. Parser.prototype.PATTERN_FOLDED_SCALAR_ALL = new Pattern('^(?:(?<type>![^\\|>]*)\\s+)?(?<separator>\\||>)(?<modifiers>\\+|\\-|\\d+|\\+\\d+|\\-\\d+|\\d+\\+|\\d+\\-)?(?<comments> +#.*)?$');
  617. Parser.prototype.PATTERN_FOLDED_SCALAR_END = new Pattern('(?<separator>\\||>)(?<modifiers>\\+|\\-|\\d+|\\+\\d+|\\-\\d+|\\d+\\+|\\d+\\-)?(?<comments> +#.*)?$');
  618. Parser.prototype.PATTERN_SEQUENCE_ITEM = new Pattern('^\\-((?<leadspaces>\\s+)(?<value>.+?))?\\s*$');
  619. Parser.prototype.PATTERN_ANCHOR_VALUE = new Pattern('^&(?<ref>[^ ]+) *(?<value>.*)');
  620. Parser.prototype.PATTERN_COMPACT_NOTATION = new Pattern('^(?<key>' + Inline.REGEX_QUOTED_STRING + '|[^ \'"\\{\\[].*?) *\\:(\\s+(?<value>.+?))?\\s*$');
  621. Parser.prototype.PATTERN_MAPPING_ITEM = new Pattern('^(?<key>' + Inline.REGEX_QUOTED_STRING + '|[^ \'"\\[\\{].*?) *\\:(\\s+(?<value>.+?))?\\s*$');
  622. Parser.prototype.PATTERN_DECIMAL = new Pattern('\\d+');
  623. Parser.prototype.PATTERN_INDENT_SPACES = new Pattern('^ +');
  624. Parser.prototype.PATTERN_TRAILING_LINES = new Pattern('(\n*)$');
  625. Parser.prototype.PATTERN_YAML_HEADER = new Pattern('^\\%YAML[: ][\\d\\.]+.*\n', 'm');
  626. Parser.prototype.PATTERN_LEADING_COMMENTS = new Pattern('^(\\#.*?\n)+', 'm');
  627. Parser.prototype.PATTERN_DOCUMENT_MARKER_START = new Pattern('^\\-\\-\\-.*?\n', 'm');
  628. Parser.prototype.PATTERN_DOCUMENT_MARKER_END = new Pattern('^\\.\\.\\.\\s*$', 'm');
  629. Parser.prototype.PATTERN_FOLDED_SCALAR_BY_INDENTATION = {};
  630. Parser.prototype.CONTEXT_NONE = 0;
  631. Parser.prototype.CONTEXT_SEQUENCE = 1;
  632. Parser.prototype.CONTEXT_MAPPING = 2;
  633. function Parser(offset) {
  634. this.offset = offset != null ? offset : 0;
  635. this.lines = [];
  636. this.currentLineNb = -1;
  637. this.currentLine = '';
  638. this.refs = {};
  639. }
  640. Parser.prototype.parse = function(value, exceptionOnInvalidType, objectDecoder) {
  641. var alias, allowOverwrite, block, c, context, data, e, error, error1, error2, first, i, indent, isRef, j, k, key, l, lastKey, len, len1, len2, len3, lineCount, m, matches, mergeNode, n, name, parsed, parsedItem, parser, ref, ref1, ref2, refName, refValue, val, values;
  642. if (exceptionOnInvalidType == null) {
  643. exceptionOnInvalidType = false;
  644. }
  645. if (objectDecoder == null) {
  646. objectDecoder = null;
  647. }
  648. this.currentLineNb = -1;
  649. this.currentLine = '';
  650. this.lines = this.cleanup(value).split("\n");
  651. data = null;
  652. context = this.CONTEXT_NONE;
  653. allowOverwrite = false;
  654. while (this.moveToNextLine()) {
  655. if (this.isCurrentLineEmpty()) {
  656. continue;
  657. }
  658. if ("\t" === this.currentLine[0]) {
  659. throw new ParseException('A YAML file cannot contain tabs as indentation.', this.getRealCurrentLineNb() + 1, this.currentLine);
  660. }
  661. isRef = mergeNode = false;
  662. if (values = this.PATTERN_SEQUENCE_ITEM.exec(this.currentLine)) {
  663. if (this.CONTEXT_MAPPING === context) {
  664. throw new ParseException('You cannot define a sequence item when in a mapping');
  665. }
  666. context = this.CONTEXT_SEQUENCE;
  667. if (data == null) {
  668. data = [];
  669. }
  670. if ((values.value != null) && (matches = this.PATTERN_ANCHOR_VALUE.exec(values.value))) {
  671. isRef = matches.ref;
  672. values.value = matches.value;
  673. }
  674. if (!(values.value != null) || '' === Utils.trim(values.value, ' ') || Utils.ltrim(values.value, ' ').indexOf('#') === 0) {
  675. if (this.currentLineNb < this.lines.length - 1 && !this.isNextLineUnIndentedCollection()) {
  676. c = this.getRealCurrentLineNb() + 1;
  677. parser = new Parser(c);
  678. parser.refs = this.refs;
  679. data.push(parser.parse(this.getNextEmbedBlock(null, true), exceptionOnInvalidType, objectDecoder));
  680. } else {
  681. data.push(null);
  682. }
  683. } else {
  684. if (((ref = values.leadspaces) != null ? ref.length : void 0) && (matches = this.PATTERN_COMPACT_NOTATION.exec(values.value))) {
  685. c = this.getRealCurrentLineNb();
  686. parser = new Parser(c);
  687. parser.refs = this.refs;
  688. block = values.value;
  689. indent = this.getCurrentLineIndentation();
  690. if (this.isNextLineIndented(false)) {
  691. block += "\n" + this.getNextEmbedBlock(indent + values.leadspaces.length + 1, true);
  692. }
  693. data.push(parser.parse(block, exceptionOnInvalidType, objectDecoder));
  694. } else {
  695. data.push(this.parseValue(values.value, exceptionOnInvalidType, objectDecoder));
  696. }
  697. }
  698. } else if ((values = this.PATTERN_MAPPING_ITEM.exec(this.currentLine)) && values.key.indexOf(' #') === -1) {
  699. if (this.CONTEXT_SEQUENCE === context) {
  700. throw new ParseException('You cannot define a mapping item when in a sequence');
  701. }
  702. context = this.CONTEXT_MAPPING;
  703. if (data == null) {
  704. data = {};
  705. }
  706. Inline.configure(exceptionOnInvalidType, objectDecoder);
  707. try {
  708. key = Inline.parseScalar(values.key);
  709. } catch (error) {
  710. e = error;
  711. e.parsedLine = this.getRealCurrentLineNb() + 1;
  712. e.snippet = this.currentLine;
  713. throw e;
  714. }
  715. if ('<<' === key) {
  716. mergeNode = true;
  717. allowOverwrite = true;
  718. if (((ref1 = values.value) != null ? ref1.indexOf('*') : void 0) === 0) {
  719. refName = values.value.slice(1);
  720. if (this.refs[refName] == null) {
  721. throw new ParseException('Reference "' + refName + '" does not exist.', this.getRealCurrentLineNb() + 1, this.currentLine);
  722. }
  723. refValue = this.refs[refName];
  724. if (typeof refValue !== 'object') {
  725. throw new ParseException('YAML merge keys used with a scalar value instead of an object.', this.getRealCurrentLineNb() + 1, this.currentLine);
  726. }
  727. if (refValue instanceof Array) {
  728. for (i = j = 0, len = refValue.length; j < len; i = ++j) {
  729. value = refValue[i];
  730. if (data[name = String(i)] == null) {
  731. data[name] = value;
  732. }
  733. }
  734. } else {
  735. for (key in refValue) {
  736. value = refValue[key];
  737. if (data[key] == null) {
  738. data[key] = value;
  739. }
  740. }
  741. }
  742. } else {
  743. if ((values.value != null) && values.value !== '') {
  744. value = values.value;
  745. } else {
  746. value = this.getNextEmbedBlock();
  747. }
  748. c = this.getRealCurrentLineNb() + 1;
  749. parser = new Parser(c);
  750. parser.refs = this.refs;
  751. parsed = parser.parse(value, exceptionOnInvalidType);
  752. if (typeof parsed !== 'object') {
  753. throw new ParseException('YAML merge keys used with a scalar value instead of an object.', this.getRealCurrentLineNb() + 1, this.currentLine);
  754. }
  755. if (parsed instanceof Array) {
  756. for (l = 0, len1 = parsed.length; l < len1; l++) {
  757. parsedItem = parsed[l];
  758. if (typeof parsedItem !== 'object') {
  759. throw new ParseException('Merge items must be objects.', this.getRealCurrentLineNb() + 1, parsedItem);
  760. }
  761. if (parsedItem instanceof Array) {
  762. for (i = m = 0, len2 = parsedItem.length; m < len2; i = ++m) {
  763. value = parsedItem[i];
  764. k = String(i);
  765. if (!data.hasOwnProperty(k)) {
  766. data[k] = value;
  767. }
  768. }
  769. } else {
  770. for (key in parsedItem) {
  771. value = parsedItem[key];
  772. if (!data.hasOwnProperty(key)) {
  773. data[key] = value;
  774. }
  775. }
  776. }
  777. }
  778. } else {
  779. for (key in parsed) {
  780. value = parsed[key];
  781. if (!data.hasOwnProperty(key)) {
  782. data[key] = value;
  783. }
  784. }
  785. }
  786. }
  787. } else if ((values.value != null) && (matches = this.PATTERN_ANCHOR_VALUE.exec(values.value))) {
  788. isRef = matches.ref;
  789. values.value = matches.value;
  790. }
  791. if (mergeNode) {
  792. } else if (!(values.value != null) || '' === Utils.trim(values.value, ' ') || Utils.ltrim(values.value, ' ').indexOf('#') === 0) {
  793. if (!(this.isNextLineIndented()) && !(this.isNextLineUnIndentedCollection())) {
  794. if (allowOverwrite || data[key] === void 0) {
  795. data[key] = null;
  796. }
  797. } else {
  798. c = this.getRealCurrentLineNb() + 1;
  799. parser = new Parser(c);
  800. parser.refs = this.refs;
  801. val = parser.parse(this.getNextEmbedBlock(), exceptionOnInvalidType, objectDecoder);
  802. if (allowOverwrite || data[key] === void 0) {
  803. data[key] = val;
  804. }
  805. }
  806. } else {
  807. val = this.parseValue(values.value, exceptionOnInvalidType, objectDecoder);
  808. if (allowOverwrite || data[key] === void 0) {
  809. data[key] = val;
  810. }
  811. }
  812. } else {
  813. lineCount = this.lines.length;
  814. if (1 === lineCount || (2 === lineCount && Utils.isEmpty(this.lines[1]))) {
  815. try {
  816. value = Inline.parse(this.lines[0], exceptionOnInvalidType, objectDecoder);
  817. } catch (error1) {
  818. e = error1;
  819. e.parsedLine = this.getRealCurrentLineNb() + 1;
  820. e.snippet = this.currentLine;
  821. throw e;
  822. }
  823. if (typeof value === 'object') {
  824. if (value instanceof Array) {
  825. first = value[0];
  826. } else {
  827. for (key in value) {
  828. first = value[key];
  829. break;
  830. }
  831. }
  832. if (typeof first === 'string' && first.indexOf('*') === 0) {
  833. data = [];
  834. for (n = 0, len3 = value.length; n < len3; n++) {
  835. alias = value[n];
  836. data.push(this.refs[alias.slice(1)]);
  837. }
  838. value = data;
  839. }
  840. }
  841. return value;
  842. } else if ((ref2 = Utils.ltrim(value).charAt(0)) === '[' || ref2 === '{') {
  843. try {
  844. return Inline.parse(value, exceptionOnInvalidType, objectDecoder);
  845. } catch (error2) {
  846. e = error2;
  847. e.parsedLine = this.getRealCurrentLineNb() + 1;
  848. e.snippet = this.currentLine;
  849. throw e;
  850. }
  851. }
  852. throw new ParseException('Unable to parse.', this.getRealCurrentLineNb() + 1, this.currentLine);
  853. }
  854. if (isRef) {
  855. if (data instanceof Array) {
  856. this.refs[isRef] = data[data.length - 1];
  857. } else {
  858. lastKey = null;
  859. for (key in data) {
  860. lastKey = key;
  861. }
  862. this.refs[isRef] = data[lastKey];
  863. }
  864. }
  865. }
  866. if (Utils.isEmpty(data)) {
  867. return null;
  868. } else {
  869. return data;
  870. }
  871. };
  872. Parser.prototype.getRealCurrentLineNb = function() {
  873. return this.currentLineNb + this.offset;
  874. };
  875. Parser.prototype.getCurrentLineIndentation = function() {
  876. return this.currentLine.length - Utils.ltrim(this.currentLine, ' ').length;
  877. };
  878. Parser.prototype.getNextEmbedBlock = function(indentation, includeUnindentedCollection) {
  879. var data, indent, isItUnindentedCollection, newIndent, removeComments, removeCommentsPattern, unindentedEmbedBlock;
  880. if (indentation == null) {
  881. indentation = null;
  882. }
  883. if (includeUnindentedCollection == null) {
  884. includeUnindentedCollection = false;
  885. }
  886. this.moveToNextLine();
  887. if (indentation == null) {
  888. newIndent = this.getCurrentLineIndentation();
  889. unindentedEmbedBlock = this.isStringUnIndentedCollectionItem(this.currentLine);
  890. if (!(this.isCurrentLineEmpty()) && 0 === newIndent && !unindentedEmbedBlock) {
  891. throw new ParseException('Indentation problem.', this.getRealCurrentLineNb() + 1, this.currentLine);
  892. }
  893. } else {
  894. newIndent = indentation;
  895. }
  896. data = [this.currentLine.slice(newIndent)];
  897. if (!includeUnindentedCollection) {
  898. isItUnindentedCollection = this.isStringUnIndentedCollectionItem(this.currentLine);
  899. }
  900. removeCommentsPattern = this.PATTERN_FOLDED_SCALAR_END;
  901. removeComments = !removeCommentsPattern.test(this.currentLine);
  902. while (this.moveToNextLine()) {
  903. indent = this.getCurrentLineIndentation();
  904. if (indent === newIndent) {
  905. removeComments = !removeCommentsPattern.test(this.currentLine);
  906. }
  907. if (removeComments && this.isCurrentLineComment()) {
  908. continue;
  909. }
  910. if (this.isCurrentLineBlank()) {
  911. data.push(this.currentLine.slice(newIndent));
  912. continue;
  913. }
  914. if (isItUnindentedCollection && !this.isStringUnIndentedCollectionItem(this.currentLine) && indent === newIndent) {
  915. this.moveToPreviousLine();
  916. break;
  917. }
  918. if (indent >= newIndent) {
  919. data.push(this.currentLine.slice(newIndent));
  920. } else if (Utils.ltrim(this.currentLine).charAt(0) === '#') {
  921. } else if (0 === indent) {
  922. this.moveToPreviousLine();
  923. break;
  924. } else {
  925. throw new ParseException('Indentation problem.', this.getRealCurrentLineNb() + 1, this.currentLine);
  926. }
  927. }
  928. return data.join("\n");
  929. };
  930. Parser.prototype.moveToNextLine = function() {
  931. if (this.currentLineNb >= this.lines.length - 1) {
  932. return false;
  933. }
  934. this.currentLine = this.lines[++this.currentLineNb];
  935. return true;
  936. };
  937. Parser.prototype.moveToPreviousLine = function() {
  938. this.currentLine = this.lines[--this.currentLineNb];
  939. };
  940. Parser.prototype.parseValue = function(value, exceptionOnInvalidType, objectDecoder) {
  941. var e, error, foldedIndent, matches, modifiers, pos, ref, ref1, val;
  942. if (0 === value.indexOf('*')) {
  943. pos = value.indexOf('#');
  944. if (pos !== -1) {
  945. value = value.substr(1, pos - 2);
  946. } else {
  947. value = value.slice(1);
  948. }
  949. if (this.refs[value] === void 0) {
  950. throw new ParseException('Reference "' + value + '" does not exist.', this.currentLine);
  951. }
  952. return this.refs[value];
  953. }
  954. if (matches = this.PATTERN_FOLDED_SCALAR_ALL.exec(value)) {
  955. modifiers = (ref = matches.modifiers) != null ? ref : '';
  956. foldedIndent = Math.abs(parseInt(modifiers));
  957. if (isNaN(foldedIndent)) {
  958. foldedIndent = 0;
  959. }
  960. val = this.parseFoldedScalar(matches.separator, this.PATTERN_DECIMAL.replace(modifiers, ''), foldedIndent);
  961. if (matches.type != null) {
  962. Inline.configure(exceptionOnInvalidType, objectDecoder);
  963. return Inline.parseScalar(matches.type + ' ' + val);
  964. } else {
  965. return val;
  966. }
  967. }
  968. if ((ref1 = value.charAt(0)) === '[' || ref1 === '{' || ref1 === '"' || ref1 === "'") {
  969. while (true) {
  970. try {
  971. return Inline.parse(value, exceptionOnInvalidType, objectDecoder);
  972. } catch (error) {
  973. e = error;
  974. if (e instanceof ParseMore && this.moveToNextLine()) {
  975. value += "\n" + Utils.trim(this.currentLine, ' ');
  976. } else {
  977. e.parsedLine = this.getRealCurrentLineNb() + 1;
  978. e.snippet = this.currentLine;
  979. throw e;
  980. }
  981. }
  982. }
  983. } else {
  984. if (this.isNextLineIndented()) {
  985. value += "\n" + this.getNextEmbedBlock();
  986. }
  987. return Inline.parse(value, exceptionOnInvalidType, objectDecoder);
  988. }
  989. };
  990. Parser.prototype.parseFoldedScalar = function(separator, indicator, indentation) {
  991. var isCurrentLineBlank, j, len, line, matches, newText, notEOF, pattern, ref, text;
  992. if (indicator == null) {
  993. indicator = '';
  994. }
  995. if (indentation == null) {
  996. indentation = 0;
  997. }
  998. notEOF = this.moveToNextLine();
  999. if (!notEOF) {
  1000. return '';
  1001. }
  1002. isCurrentLineBlank = this.isCurrentLineBlank();
  1003. text = '';
  1004. while (notEOF && isCurrentLineBlank) {
  1005. if (notEOF = this.moveToNextLine()) {
  1006. text += "\n";
  1007. isCurrentLineBlank = this.isCurrentLineBlank();
  1008. }
  1009. }
  1010. if (0 === indentation) {
  1011. if (matches = this.PATTERN_INDENT_SPACES.exec(this.currentLine)) {
  1012. indentation = matches[0].length;
  1013. }
  1014. }
  1015. if (indentation > 0) {
  1016. pattern = this.PATTERN_FOLDED_SCALAR_BY_INDENTATION[indentation];
  1017. if (pattern == null) {
  1018. pattern = new Pattern('^ {' + indentation + '}(.*)$');
  1019. Parser.prototype.PATTERN_FOLDED_SCALAR_BY_INDENTATION[indentation] = pattern;
  1020. }
  1021. while (notEOF && (isCurrentLineBlank || (matches = pattern.exec(this.currentLine)))) {
  1022. if (isCurrentLineBlank) {
  1023. text += this.currentLine.slice(indentation);
  1024. } else {
  1025. text += matches[1];
  1026. }
  1027. if (notEOF = this.moveToNextLine()) {
  1028. text += "\n";
  1029. isCurrentLineBlank = this.isCurrentLineBlank();
  1030. }
  1031. }
  1032. } else if (notEOF) {
  1033. text += "\n";
  1034. }
  1035. if (notEOF) {
  1036. this.moveToPreviousLine();
  1037. }
  1038. if ('>' === separator) {
  1039. newText = '';
  1040. ref = text.split("\n");
  1041. for (j = 0, len = ref.length; j < len; j++) {
  1042. line = ref[j];
  1043. if (line.length === 0 || line.charAt(0) === ' ') {
  1044. newText = Utils.rtrim(newText, ' ') + line + "\n";
  1045. } else {
  1046. newText += line + ' ';
  1047. }
  1048. }
  1049. text = newText;
  1050. }
  1051. if ('+' !== indicator) {
  1052. text = Utils.rtrim(text);
  1053. }
  1054. if ('' === indicator) {
  1055. text = this.PATTERN_TRAILING_LINES.replace(text, "\n");
  1056. } else if ('-' === indicator) {
  1057. text = this.PATTERN_TRAILING_LINES.replace(text, '');
  1058. }
  1059. return text;
  1060. };
  1061. Parser.prototype.isNextLineIndented = function(ignoreComments) {
  1062. var EOF, currentIndentation, ret;
  1063. if (ignoreComments == null) {
  1064. ignoreComments = true;
  1065. }
  1066. currentIndentation = this.getCurrentLineIndentation();
  1067. EOF = !this.moveToNextLine();
  1068. if (ignoreComments) {
  1069. while (!EOF && this.isCurrentLineEmpty()) {
  1070. EOF = !this.moveToNextLine();
  1071. }
  1072. } else {
  1073. while (!EOF && this.isCurrentLineBlank()) {
  1074. EOF = !this.moveToNextLine();
  1075. }
  1076. }
  1077. if (EOF) {
  1078. return false;
  1079. }
  1080. ret = false;
  1081. if (this.getCurrentLineIndentation() > currentIndentation) {
  1082. ret = true;
  1083. }
  1084. this.moveToPreviousLine();
  1085. return ret;
  1086. };
  1087. Parser.prototype.isCurrentLineEmpty = function() {
  1088. var trimmedLine;
  1089. trimmedLine = Utils.trim(this.currentLine, ' ');
  1090. return trimmedLine.length === 0 || trimmedLine.charAt(0) === '#';
  1091. };
  1092. Parser.prototype.isCurrentLineBlank = function() {
  1093. return '' === Utils.trim(this.currentLine, ' ');
  1094. };
  1095. Parser.prototype.isCurrentLineComment = function() {
  1096. var ltrimmedLine;
  1097. ltrimmedLine = Utils.ltrim(this.currentLine, ' ');
  1098. return ltrimmedLine.charAt(0) === '#';
  1099. };
  1100. Parser.prototype.cleanup = function(value) {
  1101. var count, i, indent, j, l, len, len1, line, lines, ref, ref1, ref2, smallestIndent, trimmedValue;
  1102. if (value.indexOf("\r") !== -1) {
  1103. value = value.split("\r\n").join("\n").split("\r").join("\n");
  1104. }
  1105. count = 0;
  1106. ref = this.PATTERN_YAML_HEADER.replaceAll(value, ''), value = ref[0], count = ref[1];
  1107. this.offset += count;
  1108. ref1 = this.PATTERN_LEADING_COMMENTS.replaceAll(value, '', 1), trimmedValue = ref1[0], count = ref1[1];
  1109. if (count === 1) {
  1110. this.offset += Utils.subStrCount(value, "\n") - Utils.subStrCount(trimmedValue, "\n");
  1111. value = trimmedValue;
  1112. }
  1113. ref2 = this.PATTERN_DOCUMENT_MARKER_START.replaceAll(value, '', 1), trimmedValue = ref2[0], count = ref2[1];
  1114. if (count === 1) {
  1115. this.offset += Utils.subStrCount(value, "\n") - Utils.subStrCount(trimmedValue, "\n");
  1116. value = trimmedValue;
  1117. value = this.PATTERN_DOCUMENT_MARKER_END.replace(value, '');
  1118. }
  1119. lines = value.split("\n");
  1120. smallestIndent = -1;
  1121. for (j = 0, len = lines.length; j < len; j++) {
  1122. line = lines[j];
  1123. if (Utils.trim(line, ' ').length === 0) {
  1124. continue;
  1125. }
  1126. indent = line.length - Utils.ltrim(line).length;
  1127. if (smallestIndent === -1 || indent < smallestIndent) {
  1128. smallestIndent = indent;
  1129. }
  1130. }
  1131. if (smallestIndent > 0) {
  1132. for (i = l = 0, len1 = lines.length; l < len1; i = ++l) {
  1133. line = lines[i];
  1134. lines[i] = line.slice(smallestIndent);
  1135. }
  1136. value = lines.join("\n");
  1137. }
  1138. return value;
  1139. };
  1140. Parser.prototype.isNextLineUnIndentedCollection = function(currentIndentation) {
  1141. var notEOF, ret;
  1142. if (currentIndentation == null) {
  1143. currentIndentation = null;
  1144. }
  1145. if (currentIndentation == null) {
  1146. currentIndentation = this.getCurrentLineIndentation();
  1147. }
  1148. notEOF = this.moveToNextLine();
  1149. while (notEOF && this.isCurrentLineEmpty()) {
  1150. notEOF = this.moveToNextLine();
  1151. }
  1152. if (false === notEOF) {
  1153. return false;
  1154. }
  1155. ret = false;
  1156. if (this.getCurrentLineIndentation() === currentIndentation && this.isStringUnIndentedCollectionItem(this.currentLine)) {
  1157. ret = true;
  1158. }
  1159. this.moveToPreviousLine();
  1160. return ret;
  1161. };
  1162. Parser.prototype.isStringUnIndentedCollectionItem = function() {
  1163. return this.currentLine === '-' || this.currentLine.slice(0, 2) === '- ';
  1164. };
  1165. return Parser;
  1166. })();
  1167. module.exports = Parser;
  1168. },{"./Exception/ParseException":4,"./Exception/ParseMore":5,"./Inline":6,"./Pattern":8,"./Utils":10}],8:[function(require,module,exports){
  1169. var Pattern;
  1170. Pattern = (function() {
  1171. Pattern.prototype.regex = null;
  1172. Pattern.prototype.rawRegex = null;
  1173. Pattern.prototype.cleanedRegex = null;
  1174. Pattern.prototype.mapping = null;
  1175. function Pattern(rawRegex, modifiers) {
  1176. var _char, capturingBracketNumber, cleanedRegex, i, len, mapping, name, part, subChar;
  1177. if (modifiers == null) {
  1178. modifiers = '';
  1179. }
  1180. cleanedRegex = '';
  1181. len = rawRegex.length;
  1182. mapping = null;
  1183. capturingBracketNumber = 0;
  1184. i = 0;
  1185. while (i < len) {
  1186. _char = rawRegex.charAt(i);
  1187. if (_char === '\\') {
  1188. cleanedRegex += rawRegex.slice(i, +(i + 1) + 1 || 9e9);
  1189. i++;
  1190. } else if (_char === '(') {
  1191. if (i < len - 2) {
  1192. part = rawRegex.slice(i, +(i + 2) + 1 || 9e9);
  1193. if (part === '(?:') {
  1194. i += 2;
  1195. cleanedRegex += part;
  1196. } else if (part === '(?<') {
  1197. capturingBracketNumber++;
  1198. i += 2;
  1199. name = '';
  1200. while (i + 1 < len) {
  1201. subChar = rawRegex.charAt(i + 1);
  1202. if (subChar === '>') {
  1203. cleanedRegex += '(';
  1204. i++;
  1205. if (name.length > 0) {
  1206. if (mapping == null) {
  1207. mapping = {};
  1208. }
  1209. mapping[name] = capturingBracketNumber;
  1210. }
  1211. break;
  1212. } else {
  1213. name += subChar;
  1214. }
  1215. i++;
  1216. }
  1217. } else {
  1218. cleanedRegex += _char;
  1219. capturingBracketNumber++;
  1220. }
  1221. } else {
  1222. cleanedRegex += _char;
  1223. }
  1224. } else {
  1225. cleanedRegex += _char;
  1226. }
  1227. i++;
  1228. }
  1229. this.rawRegex = rawRegex;
  1230. this.cleanedRegex = cleanedRegex;
  1231. this.regex = new RegExp(this.cleanedRegex, 'g' + modifiers.replace('g', ''));
  1232. this.mapping = mapping;
  1233. }
  1234. Pattern.prototype.exec = function(str) {
  1235. var index, matches, name, ref;
  1236. this.regex.lastIndex = 0;
  1237. matches = this.regex.exec(str);
  1238. if (matches == null) {
  1239. return null;
  1240. }
  1241. if (this.mapping != null) {
  1242. ref = this.mapping;
  1243. for (name in ref) {
  1244. index = ref[name];
  1245. matches[name] = matches[index];
  1246. }
  1247. }
  1248. return matches;
  1249. };
  1250. Pattern.prototype.test = function(str) {
  1251. this.regex.lastIndex = 0;
  1252. return this.regex.test(str);
  1253. };
  1254. Pattern.prototype.replace = function(str, replacement) {
  1255. this.regex.lastIndex = 0;
  1256. return str.replace(this.regex, replacement);
  1257. };
  1258. Pattern.prototype.replaceAll = function(str, replacement, limit) {
  1259. var count;
  1260. if (limit == null) {
  1261. limit = 0;
  1262. }
  1263. this.regex.lastIndex = 0;
  1264. count = 0;
  1265. while (this.regex.test(str) && (limit === 0 || count < limit)) {
  1266. this.regex.lastIndex = 0;
  1267. str = str.replace(this.regex, replacement);
  1268. count++;
  1269. }
  1270. return [str, count];
  1271. };
  1272. return Pattern;
  1273. })();
  1274. module.exports = Pattern;
  1275. },{}],9:[function(require,module,exports){
  1276. var Pattern, Unescaper, Utils;
  1277. Utils = require('./Utils');
  1278. Pattern = require('./Pattern');
  1279. Unescaper = (function() {
  1280. function Unescaper() {}
  1281. Unescaper.PATTERN_ESCAPED_CHARACTER = new Pattern('\\\\([0abt\tnvfre "\\/\\\\N_LP]|x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8})');
  1282. Unescaper.unescapeSingleQuotedString = function(value) {
  1283. return value.replace(/\'\'/g, '\'');
  1284. };
  1285. Unescaper.unescapeDoubleQuotedString = function(value) {
  1286. if (this._unescapeCallback == null) {
  1287. this._unescapeCallback = (function(_this) {
  1288. return function(str) {
  1289. return _this.unescapeCharacter(str);
  1290. };
  1291. })(this);
  1292. }
  1293. return this.PATTERN_ESCAPED_CHARACTER.replace(value, this._unescapeCallback);
  1294. };
  1295. Unescaper.unescapeCharacter = function(value) {
  1296. var ch;
  1297. ch = String.fromCharCode;
  1298. switch (value.charAt(1)) {
  1299. case '0':
  1300. return ch(0);
  1301. case 'a':
  1302. return ch(7);
  1303. case 'b':
  1304. return ch(8);
  1305. case 't':
  1306. return "\t";
  1307. case "\t":
  1308. return "\t";
  1309. case 'n':
  1310. return "\n";
  1311. case 'v':
  1312. return ch(11);
  1313. case 'f':
  1314. return ch(12);
  1315. case 'r':
  1316. return ch(13);
  1317. case 'e':
  1318. return ch(27);
  1319. case ' ':
  1320. return ' ';
  1321. case '"':
  1322. return '"';
  1323. case '/':
  1324. return '/';
  1325. case '\\':
  1326. return '\\';
  1327. case 'N':
  1328. return ch(0x0085);
  1329. case '_':
  1330. return ch(0x00A0);
  1331. case 'L':
  1332. return ch(0x2028);
  1333. case 'P':
  1334. return ch(0x2029);
  1335. case 'x':
  1336. return Utils.utf8chr(Utils.hexDec(value.substr(2, 2)));
  1337. case 'u':
  1338. return Utils.utf8chr(Utils.hexDec(value.substr(2, 4)));
  1339. case 'U':
  1340. return Utils.utf8chr(Utils.hexDec(value.substr(2, 8)));
  1341. default:
  1342. return '';
  1343. }
  1344. };
  1345. return Unescaper;
  1346. })();
  1347. module.exports = Unescaper;
  1348. },{"./Pattern":8,"./Utils":10}],10:[function(require,module,exports){
  1349. var Pattern, Utils,
  1350. hasProp = {}.hasOwnProperty;
  1351. Pattern = require('./Pattern');
  1352. Utils = (function() {
  1353. function Utils() {}
  1354. Utils.REGEX_LEFT_TRIM_BY_CHAR = {};
  1355. Utils.REGEX_RIGHT_TRIM_BY_CHAR = {};
  1356. Utils.REGEX_SPACES = /\s+/g;
  1357. Utils.REGEX_DIGITS = /^\d+$/;
  1358. Utils.REGEX_OCTAL = /[^0-7]/gi;
  1359. Utils.REGEX_HEXADECIMAL = /[^a-f0-9]/gi;
  1360. Utils.PATTERN_DATE = new Pattern('^' + '(?<year>[0-9][0-9][0-9][0-9])' + '-(?<month>[0-9][0-9]?)' + '-(?<day>[0-9][0-9]?)' + '(?:(?:[Tt]|[ \t]+)' + '(?<hour>[0-9][0-9]?)' + ':(?<minute>[0-9][0-9])' + ':(?<second>[0-9][0-9])' + '(?:\.(?<fraction>[0-9]*))?' + '(?:[ \t]*(?<tz>Z|(?<tz_sign>[-+])(?<tz_hour>[0-9][0-9]?)' + '(?::(?<tz_minute>[0-9][0-9]))?))?)?' + '$', 'i');
  1361. Utils.LOCAL_TIMEZONE_OFFSET = new Date().getTimezoneOffset() * 60 * 1000;
  1362. Utils.trim = function(str, _char) {
  1363. var regexLeft, regexRight;
  1364. if (_char == null) {
  1365. _char = '\\s';
  1366. }
  1367. regexLeft = this.REGEX_LEFT_TRIM_BY_CHAR[_char];
  1368. if (regexLeft == null) {
  1369. this.REGEX_LEFT_TRIM_BY_CHAR[_char] = regexLeft = new RegExp('^' + _char + '' + _char + '*');
  1370. }
  1371. regexLeft.lastIndex = 0;
  1372. regexRight = this.REGEX_RIGHT_TRIM_BY_CHAR[_char];
  1373. if (regexRight == null) {
  1374. this.REGEX_RIGHT_TRIM_BY_CHAR[_char] = regexRight = new RegExp(_char + '' + _char + '*$');
  1375. }
  1376. regexRight.lastIndex = 0;
  1377. return str.replace(regexLeft, '').replace(regexRight, '');
  1378. };
  1379. Utils.ltrim = function(str, _char) {
  1380. var regexLeft;
  1381. if (_char == null) {
  1382. _char = '\\s';
  1383. }
  1384. regexLeft = this.REGEX_LEFT_TRIM_BY_CHAR[_char];
  1385. if (regexLeft == null) {
  1386. this.REGEX_LEFT_TRIM_BY_CHAR[_char] = regexLeft = new RegExp('^' + _char + '' + _char + '*');
  1387. }
  1388. regexLeft.lastIndex = 0;
  1389. return str.replace(regexLeft, '');
  1390. };
  1391. Utils.rtrim = function(str, _char) {
  1392. var regexRight;
  1393. if (_char == null) {
  1394. _char = '\\s';
  1395. }
  1396. regexRight = this.REGEX_RIGHT_TRIM_BY_CHAR[_char];
  1397. if (regexRight == null) {
  1398. this.REGEX_RIGHT_TRIM_BY_CHAR[_char] = regexRight = new RegExp(_char + '' + _char + '*$');
  1399. }
  1400. regexRight.lastIndex = 0;
  1401. return str.replace(regexRight, '');
  1402. };
  1403. Utils.isEmpty = function(value) {
  1404. return !value || value === '' || value === '0' || (value instanceof Array && value.length === 0) || this.isEmptyObject(value);
  1405. };
  1406. Utils.isEmptyObject = function(value) {
  1407. var k;
  1408. return value instanceof Object && ((function() {
  1409. var results;
  1410. results = [];
  1411. for (k in value) {
  1412. if (!hasProp.call(value, k)) continue;
  1413. results.push(k);
  1414. }
  1415. return results;
  1416. })()).length === 0;
  1417. };
  1418. Utils.subStrCount = function(string, subString, start, length) {
  1419. var c, i, j, len, ref, sublen;
  1420. c = 0;
  1421. string = '' + string;
  1422. subString = '' + subString;
  1423. if (start != null) {
  1424. string = string.slice(start);
  1425. }
  1426. if (length != null) {
  1427. string = string.slice(0, length);
  1428. }
  1429. len = string.length;
  1430. sublen = subString.length;
  1431. for (i = j = 0, ref = len; 0 <= ref ? j < ref : j > ref; i = 0 <= ref ? ++j : --j) {
  1432. if (subString === string.slice(i, sublen)) {
  1433. c++;
  1434. i += sublen - 1;
  1435. }
  1436. }
  1437. return c;
  1438. };
  1439. Utils.isDigits = function(input) {
  1440. this.REGEX_DIGITS.lastIndex = 0;
  1441. return this.REGEX_DIGITS.test(input);
  1442. };
  1443. Utils.octDec = function(input) {
  1444. this.REGEX_OCTAL.lastIndex = 0;
  1445. return parseInt((input + '').replace(this.REGEX_OCTAL, ''), 8);
  1446. };
  1447. Utils.hexDec = function(input) {
  1448. this.REGEX_HEXADECIMAL.lastIndex = 0;
  1449. input = this.trim(input);
  1450. if ((input + '').slice(0, 2) === '0x') {
  1451. input = (input + '').slice(2);
  1452. }
  1453. return parseInt((input + '').replace(this.REGEX_HEXADECIMAL, ''), 16);
  1454. };
  1455. Utils.utf8chr = function(c) {
  1456. var ch;
  1457. ch = String.fromCharCode;
  1458. if (0x80 > (c %= 0x200000)) {
  1459. return ch(c);
  1460. }
  1461. if (0x800 > c) {
  1462. return ch(0xC0 | c >> 6) + ch(0x80 | c & 0x3F);
  1463. }
  1464. if (0x10000 > c) {
  1465. return ch(0xE0 | c >> 12) + ch(0x80 | c >> 6 & 0x3F) + ch(0x80 | c & 0x3F);
  1466. }
  1467. return ch(0xF0 | c >> 18) + ch(0x80 | c >> 12 & 0x3F) + ch(0x80 | c >> 6 & 0x3F) + ch(0x80 | c & 0x3F);
  1468. };
  1469. Utils.parseBoolean = function(input, strict) {
  1470. var lowerInput;
  1471. if (strict == null) {
  1472. strict = true;
  1473. }
  1474. if (typeof input === 'string') {
  1475. lowerInput = input.toLowerCase();
  1476. if (!strict) {
  1477. if (lowerInput === 'no') {
  1478. return false;
  1479. }
  1480. }
  1481. if (lowerInput === '0') {
  1482. return false;
  1483. }
  1484. if (lowerInput === 'false') {
  1485. return false;
  1486. }
  1487. if (lowerInput === '') {
  1488. return false;
  1489. }
  1490. return true;
  1491. }
  1492. return !!input;
  1493. };
  1494. Utils.isNumeric = function(input) {
  1495. this.REGEX_SPACES.lastIndex = 0;
  1496. return typeof input === 'number' || typeof input === 'string' && !isNaN(input) && input.replace(this.REGEX_SPACES, '') !== '';
  1497. };
  1498. Utils.stringToDate = function(str) {
  1499. var date, day, fraction, hour, info, minute, month, second, tz_hour, tz_minute, tz_offset, year;
  1500. if (!(str != null ? str.length : void 0)) {
  1501. return null;
  1502. }
  1503. info = this.PATTERN_DATE.exec(str);
  1504. if (!info) {
  1505. return null;
  1506. }
  1507. year = parseInt(info.year, 10);
  1508. month = parseInt(info.month, 10) - 1;
  1509. day = parseInt(info.day, 10);
  1510. if (info.hour == null) {
  1511. date = new Date(Date.UTC(year, month, day));
  1512. return date;
  1513. }
  1514. hour = parseInt(info.hour, 10);
  1515. minute = parseInt(info.minute, 10);
  1516. second = parseInt(info.second, 10);
  1517. if (info.fraction != null) {
  1518. fraction = info.fraction.slice(0, 3);
  1519. while (fraction.length < 3) {
  1520. fraction += '0';
  1521. }
  1522. fraction = parseInt(fraction, 10);
  1523. } else {
  1524. fraction = 0;
  1525. }
  1526. if (info.tz != null) {
  1527. tz_hour = parseInt(info.tz_hour, 10);
  1528. if (info.tz_minute != null) {
  1529. tz_minute = parseInt(info.tz_minute, 10);
  1530. } else {
  1531. tz_minute = 0;
  1532. }
  1533. tz_offset = (tz_hour * 60 + tz_minute) * 60000;
  1534. if ('-' === info.tz_sign) {
  1535. tz_offset *= -1;
  1536. }
  1537. }
  1538. date = new Date(Date.UTC(year, month, day, hour, minute, second, fraction));
  1539. if (tz_offset) {
  1540. date.setTime(date.getTime() - tz_offset);
  1541. }
  1542. return date;
  1543. };
  1544. Utils.strRepeat = function(str, number) {
  1545. var i, res;
  1546. res = '';
  1547. i = 0;
  1548. while (i < number) {
  1549. res += str;
  1550. i++;
  1551. }
  1552. return res;
  1553. };
  1554. Utils.getStringFromFile = function(path, callback) {
  1555. var data, fs, j, len1, name, ref, req, xhr;
  1556. if (callback == null) {
  1557. callback = null;
  1558. }
  1559. xhr = null;
  1560. if (typeof window !== "undefined" && window !== null) {
  1561. if (window.XMLHttpRequest) {
  1562. xhr = new XMLHttpRequest();
  1563. } else if (window.ActiveXObject) {
  1564. ref = ["Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.3.0", "Msxml2.XMLHTTP", "Microsoft.XMLHTTP"];
  1565. for (j = 0, len1 = ref.length; j < len1; j++) {
  1566. name = ref[j];
  1567. try {
  1568. xhr = new ActiveXObject(name);
  1569. } catch (undefined) {}
  1570. }
  1571. }
  1572. }
  1573. if (xhr != null) {
  1574. if (callback != null) {
  1575. xhr.onreadystatechange = function() {
  1576. if (xhr.readyState === 4) {
  1577. if (xhr.status === 200 || xhr.status === 0) {
  1578. return callback(xhr.responseText);
  1579. } else {
  1580. return callback(null);
  1581. }
  1582. }
  1583. };
  1584. xhr.open('GET', path, true);
  1585. return xhr.send(null);
  1586. } else {
  1587. xhr.open('GET', path, false);
  1588. xhr.send(null);
  1589. if (xhr.status === 200 || xhr.status === 0) {
  1590. return xhr.responseText;
  1591. }
  1592. return null;
  1593. }
  1594. } else {
  1595. req = require;
  1596. fs = req('fs');
  1597. if (callback != null) {
  1598. return fs.readFile(path, function(err, data) {
  1599. if (err) {
  1600. return callback(null);
  1601. } else {
  1602. return callback(String(data));
  1603. }
  1604. });
  1605. } else {
  1606. data = fs.readFileSync(path);
  1607. if (data != null) {
  1608. return String(data);
  1609. }
  1610. return null;
  1611. }
  1612. }
  1613. };
  1614. return Utils;
  1615. })();
  1616. module.exports = Utils;
  1617. },{"./Pattern":8}],11:[function(require,module,exports){
  1618. var Dumper, Parser, Utils, Yaml;
  1619. Parser = require('./Parser');
  1620. Dumper = require('./Dumper');
  1621. Utils = require('./Utils');
  1622. Yaml = (function() {
  1623. function Yaml() {}
  1624. Yaml.parse = function(input, exceptionOnInvalidType, objectDecoder) {
  1625. if (exceptionOnInvalidType == null) {
  1626. exceptionOnInvalidType = false;
  1627. }
  1628. if (objectDecoder == null) {
  1629. objectDecoder = null;
  1630. }
  1631. return new Parser().parse(input, exceptionOnInvalidType, objectDecoder);
  1632. };
  1633. Yaml.parseFile = function(path, callback, exceptionOnInvalidType, objectDecoder) {
  1634. var input;
  1635. if (callback == null) {
  1636. callback = null;
  1637. }
  1638. if (exceptionOnInvalidType == null) {
  1639. exceptionOnInvalidType = false;
  1640. }
  1641. if (objectDecoder == null) {
  1642. objectDecoder = null;
  1643. }
  1644. if (callback != null) {
  1645. return Utils.getStringFromFile(path, (function(_this) {
  1646. return function(input) {
  1647. var result;
  1648. result = null;
  1649. if (input != null) {
  1650. result = _this.parse(input, exceptionOnInvalidType, objectDecoder);
  1651. }
  1652. callback(result);
  1653. };
  1654. })(this));
  1655. } else {
  1656. input = Utils.getStringFromFile(path);
  1657. if (input != null) {
  1658. return this.parse(input, exceptionOnInvalidType, objectDecoder);
  1659. }
  1660. return null;
  1661. }
  1662. };
  1663. Yaml.dump = function(input, inline, indent, exceptionOnInvalidType, objectEncoder) {
  1664. var yaml;
  1665. if (inline == null) {
  1666. inline = 2;
  1667. }
  1668. if (indent == null) {
  1669. indent = 4;
  1670. }
  1671. if (exceptionOnInvalidType == null) {
  1672. exceptionOnInvalidType = false;
  1673. }
  1674. if (objectEncoder == null) {
  1675. objectEncoder = null;
  1676. }
  1677. yaml = new Dumper();
  1678. yaml.indentation = indent;
  1679. return yaml.dump(input, inline, 0, exceptionOnInvalidType, objectEncoder);
  1680. };
  1681. Yaml.stringify = function(input, inline, indent, exceptionOnInvalidType, objectEncoder) {
  1682. return this.dump(input, inline, indent, exceptionOnInvalidType, objectEncoder);
  1683. };
  1684. Yaml.load = function(path, callback, exceptionOnInvalidType, objectDecoder) {
  1685. return this.parseFile(path, callback, exceptionOnInvalidType, objectDecoder);
  1686. };
  1687. return Yaml;
  1688. })();
  1689. if (typeof window !== "undefined" && window !== null) {
  1690. window.YAML = Yaml;
  1691. }
  1692. if (typeof window === "undefined" || window === null) {
  1693. this.YAML = Yaml;
  1694. }
  1695. module.exports = Yaml;
  1696. },{"./Dumper":1,"./Parser":7,"./Utils":10}]},{},[11]);