UNPKG

5.99 kBJavaScriptView Raw
1"use strict";
2/**
3 * Copyright (C) 2016-2019 Michael Kourlas
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17Object.defineProperty(exports, "__esModule", { value: true });
18var utils_1 = require("./utils");
19/**
20 * Implementation of the IOptions interface used to provide default values
21 * to fields.
22 *
23 * @private
24 */
25var Options = /** @class */ (function () {
26 function Options(options) {
27 if (options === void 0) { options = {}; }
28 this.aliasString = "=";
29 this.attributeString = "@";
30 this.cdataInvalidChars = false;
31 this.cdataKeys = [];
32 this.replaceInvalidChars = false;
33 this.useSelfClosingTagIfEmpty = true;
34 this.validation = true;
35 this.valueString = "#";
36 if (!utils_1.isUndefined(options.validation)) {
37 this.validation = options.validation;
38 }
39 if (!utils_1.isUndefined(options.aliasString)) {
40 this.aliasString = options.aliasString;
41 }
42 if (!utils_1.isUndefined(options.attributeString)) {
43 this.attributeString = options.attributeString;
44 }
45 if (!utils_1.isUndefined(options.cdataInvalidChars)) {
46 this.cdataInvalidChars = options.cdataInvalidChars;
47 }
48 if (!utils_1.isUndefined(options.cdataKeys)) {
49 this.cdataKeys = options.cdataKeys;
50 }
51 this.declaration = new DeclarationOptions(options.declaration);
52 this.dtd = new DtdOptions(this.validation, options.dtd);
53 this.format = new FormatOptions(options.format);
54 if (!utils_1.isUndefined(options.replaceInvalidChars)) {
55 this.replaceInvalidChars = options.replaceInvalidChars;
56 }
57 this.typeHandlers = new TypeHandlers(options.typeHandlers);
58 if (!utils_1.isUndefined(options.useSelfClosingTagIfEmpty)) {
59 this.useSelfClosingTagIfEmpty = options.useSelfClosingTagIfEmpty;
60 }
61 if (!utils_1.isUndefined(options.valueString)) {
62 this.valueString = options.valueString;
63 }
64 this.wrapHandlers = new WrapHandlers(options.wrapHandlers);
65 }
66 return Options;
67}());
68exports.Options = Options;
69/**
70 * Implementation of the IDeclarationOptions interface used to provide default
71 * values to fields.
72 *
73 * @private
74 */
75var DeclarationOptions = /** @class */ (function () {
76 function DeclarationOptions(declarationOptions) {
77 if (declarationOptions === void 0) { declarationOptions = {}; }
78 this.include = true;
79 if (!utils_1.isUndefined(declarationOptions.include)) {
80 this.include = declarationOptions.include;
81 }
82 // Validation performed by xmlcreate
83 this.encoding = declarationOptions.encoding;
84 this.standalone = declarationOptions.standalone;
85 this.version = declarationOptions.version;
86 }
87 return DeclarationOptions;
88}());
89exports.DeclarationOptions = DeclarationOptions;
90/**
91 * Implementation of the IDtdOptions interface used to provide default values
92 * to fields.
93 *
94 * @private
95 */
96var DtdOptions = /** @class */ (function () {
97 function DtdOptions(validation, dtdOptions) {
98 if (dtdOptions === void 0) { dtdOptions = {}; }
99 this.include = false;
100 if (!utils_1.isUndefined(dtdOptions.include)) {
101 this.include = dtdOptions.include;
102 }
103 if (validation && utils_1.isUndefined(dtdOptions.name) && this.include) {
104 throw new Error("options.dtd.name should be defined if"
105 + " options.dtd.include is true");
106 }
107 this.name = dtdOptions.name;
108 this.sysId = dtdOptions.sysId;
109 this.pubId = dtdOptions.pubId;
110 }
111 return DtdOptions;
112}());
113exports.DtdOptions = DtdOptions;
114/**
115 * Implementation of the IFormatOptions interface used to provide default values
116 * to fields.
117 *
118 * @private
119 */
120var FormatOptions = /** @class */ (function () {
121 function FormatOptions(formatOptions) {
122 if (formatOptions === void 0) { formatOptions = {}; }
123 this.doubleQuotes = formatOptions.doubleQuotes;
124 this.indent = formatOptions.indent;
125 this.newline = formatOptions.newline;
126 this.pretty = formatOptions.pretty;
127 }
128 return FormatOptions;
129}());
130exports.FormatOptions = FormatOptions;
131/**
132 * Implementation of the ITypeHandlers interface used to provide default values
133 * to fields.
134 *
135 * @private
136 */
137var TypeHandlers = /** @class */ (function () {
138 function TypeHandlers(typeHandlers) {
139 if (typeHandlers === void 0) { typeHandlers = {}; }
140 for (var key in typeHandlers) {
141 if (Object.prototype.hasOwnProperty.call(typeHandlers, key)) {
142 this[key] = typeHandlers[key];
143 }
144 }
145 }
146 return TypeHandlers;
147}());
148exports.TypeHandlers = TypeHandlers;
149/**
150 * Implementation of the IWrapHandlers interface used to provide default values
151 * to fields.
152 *
153 * @private
154 */
155var WrapHandlers = /** @class */ (function () {
156 function WrapHandlers(wrapHandlers) {
157 if (wrapHandlers === void 0) { wrapHandlers = {}; }
158 for (var key in wrapHandlers) {
159 if (Object.prototype.hasOwnProperty.call(wrapHandlers, key)) {
160 this[key] = wrapHandlers[key];
161 }
162 }
163 }
164 return WrapHandlers;
165}());
166exports.WrapHandlers = WrapHandlers;