yaml.js 59 KB

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