UNPKG

1.39 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.Value = void 0;
7var _util = require("./util.js");
8/**
9 * Value object.
10 */
11class Value {
12 /**
13 * Value type.
14 */
15
16 /**
17 * Tag names.
18 */
19
20 /**
21 * Value constructor.
22 */
23 constructor() {}
24
25 /**
26 * Value type.
27 *
28 * @returns Type string.
29 */
30 get type() {
31 return this.constructor.TYPE;
32 }
33
34 /**
35 * Cast to specific type or null.
36 *
37 * @param Type Type constructor.
38 * @returns This object or null.
39 */
40 castTo(Type) {
41 return this.type === Type.TYPE ? this : null;
42 }
43
44 /**
45 * Cast to specific type or throw.
46 *
47 * @param Type Type constructor.
48 * @returns This object.
49 */
50 castAs(Type) {
51 const casted = this.castTo(Type);
52 if (!casted) {
53 throw new Error(`Cannot cast type '${this.type}' to '${Type.TYPE}'`);
54 }
55 return casted;
56 }
57
58 /**
59 * Decode document from string.
60 *
61 * @param xml XML string.
62 */
63 fromXml(xml) {
64 const {
65 documentElement
66 } = (0, _util.xmlDecode)(xml);
67 this.fromXmlElement(documentElement);
68 }
69
70 /**
71 * Decode value from element.
72 *
73 * @param element XML element.
74 */
75
76 /**
77 * Encode Value to string.
78 *
79 * @param options Options object.
80 * @param depth Indent depth.
81 * @returns Xml string.
82 */
83}
84exports.Value = Value;
85//# sourceMappingURL=value.js.map
\No newline at end of file