options.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. "use strict";
  2. /**
  3. * Copyright (C) 2016-2020 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. */
  17. Object.defineProperty(exports, "__esModule", { value: true });
  18. exports.WrapHandlers = exports.TypeHandlers = exports.FormatOptions = exports.DtdOptions = exports.DeclarationOptions = exports.Options = void 0;
  19. var utils_1 = require("./utils");
  20. /**
  21. * Implementation of the IOptions interface used to provide default values
  22. * to fields.
  23. */
  24. var Options = /** @class */ (function () {
  25. function Options(options) {
  26. if (options === void 0) { options = {}; }
  27. this.aliasString = "=";
  28. this.attributeString = "@";
  29. this.cdataInvalidChars = false;
  30. this.cdataKeys = [];
  31. this.replaceInvalidChars = false;
  32. this.useSelfClosingTagIfEmpty = true;
  33. this.validation = true;
  34. this.valueString = "#";
  35. if (!(0, utils_1.isUndefined)(options.validation)) {
  36. this.validation = options.validation;
  37. }
  38. if (!(0, utils_1.isUndefined)(options.aliasString)) {
  39. this.aliasString = options.aliasString;
  40. }
  41. if (!(0, utils_1.isUndefined)(options.attributeString)) {
  42. this.attributeString = options.attributeString;
  43. }
  44. if (!(0, utils_1.isUndefined)(options.cdataInvalidChars)) {
  45. this.cdataInvalidChars = options.cdataInvalidChars;
  46. }
  47. if (!(0, utils_1.isUndefined)(options.cdataKeys)) {
  48. this.cdataKeys = options.cdataKeys;
  49. }
  50. this.declaration = new DeclarationOptions(options.declaration);
  51. this.dtd = new DtdOptions(this.validation, options.dtd);
  52. this.format = new FormatOptions(options.format);
  53. if (!(0, utils_1.isUndefined)(options.replaceInvalidChars)) {
  54. this.replaceInvalidChars = options.replaceInvalidChars;
  55. }
  56. this.typeHandlers = new TypeHandlers(options.typeHandlers);
  57. if (!(0, utils_1.isUndefined)(options.useSelfClosingTagIfEmpty)) {
  58. this.useSelfClosingTagIfEmpty = options.useSelfClosingTagIfEmpty;
  59. }
  60. if (!(0, utils_1.isUndefined)(options.valueString)) {
  61. this.valueString = options.valueString;
  62. }
  63. this.wrapHandlers = new WrapHandlers(options.wrapHandlers);
  64. }
  65. return Options;
  66. }());
  67. exports.Options = Options;
  68. /**
  69. * Implementation of the IDeclarationOptions interface used to provide default
  70. * values to fields.
  71. */
  72. var DeclarationOptions = /** @class */ (function () {
  73. function DeclarationOptions(declarationOptions) {
  74. if (declarationOptions === void 0) { declarationOptions = {}; }
  75. this.include = true;
  76. if (!(0, utils_1.isUndefined)(declarationOptions.include)) {
  77. this.include = declarationOptions.include;
  78. }
  79. // Validation performed by xmlcreate
  80. this.encoding = declarationOptions.encoding;
  81. this.standalone = declarationOptions.standalone;
  82. this.version = declarationOptions.version;
  83. }
  84. return DeclarationOptions;
  85. }());
  86. exports.DeclarationOptions = DeclarationOptions;
  87. /**
  88. * Implementation of the IDtdOptions interface used to provide default values
  89. * to fields.
  90. */
  91. var DtdOptions = /** @class */ (function () {
  92. function DtdOptions(validation, dtdOptions) {
  93. if (dtdOptions === void 0) { dtdOptions = {}; }
  94. this.include = false;
  95. if (!(0, utils_1.isUndefined)(dtdOptions.include)) {
  96. this.include = dtdOptions.include;
  97. }
  98. if (validation && (0, utils_1.isUndefined)(dtdOptions.name) && this.include) {
  99. throw new Error("options.dtd.name should be defined if" +
  100. " options.dtd.include is true");
  101. }
  102. this.name = dtdOptions.name;
  103. this.sysId = dtdOptions.sysId;
  104. this.pubId = dtdOptions.pubId;
  105. }
  106. return DtdOptions;
  107. }());
  108. exports.DtdOptions = DtdOptions;
  109. /**
  110. * Implementation of the IFormatOptions interface used to provide default values
  111. * to fields.
  112. */
  113. var FormatOptions = /** @class */ (function () {
  114. function FormatOptions(formatOptions) {
  115. if (formatOptions === void 0) { formatOptions = {}; }
  116. this.doubleQuotes = formatOptions.doubleQuotes;
  117. this.indent = formatOptions.indent;
  118. this.newline = formatOptions.newline;
  119. this.pretty = formatOptions.pretty;
  120. }
  121. return FormatOptions;
  122. }());
  123. exports.FormatOptions = FormatOptions;
  124. /**
  125. * Implementation of the ITypeHandlers interface used to provide default values
  126. * to fields.
  127. */
  128. var TypeHandlers = /** @class */ (function () {
  129. function TypeHandlers(typeHandlers) {
  130. if (typeHandlers === void 0) { typeHandlers = {}; }
  131. for (var key in typeHandlers) {
  132. if (Object.prototype.hasOwnProperty.call(typeHandlers, key)) {
  133. this[key] = typeHandlers[key];
  134. }
  135. }
  136. }
  137. return TypeHandlers;
  138. }());
  139. exports.TypeHandlers = TypeHandlers;
  140. /**
  141. * Implementation of the IWrapHandlers interface used to provide default values
  142. * to fields.
  143. */
  144. var WrapHandlers = /** @class */ (function () {
  145. function WrapHandlers(wrapHandlers) {
  146. if (wrapHandlers === void 0) { wrapHandlers = {}; }
  147. for (var key in wrapHandlers) {
  148. if (Object.prototype.hasOwnProperty.call(wrapHandlers, key)) {
  149. this[key] = wrapHandlers[key];
  150. }
  151. }
  152. }
  153. return WrapHandlers;
  154. }());
  155. exports.WrapHandlers = WrapHandlers;