1 |
|
2 | var Dumper, Parser, Utils, Yaml;
|
3 |
|
4 | Parser = require('./Parser');
|
5 |
|
6 | Dumper = require('./Dumper');
|
7 |
|
8 | Utils = require('./Utils');
|
9 |
|
10 | Yaml = (function() {
|
11 | function Yaml() {}
|
12 |
|
13 | Yaml.parse = function(input, exceptionOnInvalidType, objectDecoder) {
|
14 | if (exceptionOnInvalidType == null) {
|
15 | exceptionOnInvalidType = false;
|
16 | }
|
17 | if (objectDecoder == null) {
|
18 | objectDecoder = null;
|
19 | }
|
20 | return new Parser().parse(input, exceptionOnInvalidType, objectDecoder);
|
21 | };
|
22 |
|
23 | Yaml.parseFile = function(path, callback, exceptionOnInvalidType, objectDecoder) {
|
24 | var input;
|
25 | if (callback == null) {
|
26 | callback = null;
|
27 | }
|
28 | if (exceptionOnInvalidType == null) {
|
29 | exceptionOnInvalidType = false;
|
30 | }
|
31 | if (objectDecoder == null) {
|
32 | objectDecoder = null;
|
33 | }
|
34 | if (callback != null) {
|
35 | return Utils.getStringFromFile(path, (function(_this) {
|
36 | return function(input) {
|
37 | var result;
|
38 | result = null;
|
39 | if (input != null) {
|
40 | result = _this.parse(input, exceptionOnInvalidType, objectDecoder);
|
41 | }
|
42 | callback(result);
|
43 | };
|
44 | })(this));
|
45 | } else {
|
46 | input = Utils.getStringFromFile(path);
|
47 | if (input != null) {
|
48 | return this.parse(input, exceptionOnInvalidType, objectDecoder);
|
49 | }
|
50 | return null;
|
51 | }
|
52 | };
|
53 |
|
54 | Yaml.dump = function(input, inline, indent, exceptionOnInvalidType, objectEncoder) {
|
55 | var yaml;
|
56 | if (inline == null) {
|
57 | inline = 2;
|
58 | }
|
59 | if (indent == null) {
|
60 | indent = 4;
|
61 | }
|
62 | if (exceptionOnInvalidType == null) {
|
63 | exceptionOnInvalidType = false;
|
64 | }
|
65 | if (objectEncoder == null) {
|
66 | objectEncoder = null;
|
67 | }
|
68 | yaml = new Dumper();
|
69 | yaml.indentation = indent;
|
70 | return yaml.dump(input, inline, 0, exceptionOnInvalidType, objectEncoder);
|
71 | };
|
72 |
|
73 | Yaml.register = function() {
|
74 | var require_handler;
|
75 | require_handler = function(module, filename) {
|
76 | return module.exports = YAML.parseFile(filename);
|
77 | };
|
78 | if ((typeof require !== "undefined" && require !== null ? require.extensions : void 0) != null) {
|
79 | require.extensions['.yml'] = require_handler;
|
80 | return require.extensions['.yaml'] = require_handler;
|
81 | }
|
82 | };
|
83 |
|
84 | Yaml.stringify = function(input, inline, indent, exceptionOnInvalidType, objectEncoder) {
|
85 | return this.dump(input, inline, indent, exceptionOnInvalidType, objectEncoder);
|
86 | };
|
87 |
|
88 | Yaml.load = function(path, callback, exceptionOnInvalidType, objectDecoder) {
|
89 | return this.parseFile(path, callback, exceptionOnInvalidType, objectDecoder);
|
90 | };
|
91 |
|
92 | return Yaml;
|
93 |
|
94 | })();
|
95 |
|
96 | if (typeof window !== "undefined" && window !== null) {
|
97 | window.YAML = Yaml;
|
98 | }
|
99 |
|
100 | module.exports = Yaml;
|