UNPKG

3.01 kBTypeScriptView Raw
1/**
2 * Copyright (C) 2016-2019 Michael Kourlas
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16import { IStringOptions } from "../options";
17import XmlAttributeText, { IXmlAttributeTextOptions } from "./XmlAttributeText";
18import XmlCharRef, { IXmlCharRefOptions } from "./XmlCharRef";
19import XmlEntityRef, { IXmlEntityRefOptions } from "./XmlEntityRef";
20/**
21 * The options used to create a new attribute.
22 */
23export interface IXmlAttributeOptions {
24 /**
25 * The name of the attribute.
26 */
27 name: string;
28 /**
29 * Whether to replace any invalid characters in the name of the attribute
30 * with the Unicode replacement character. By default, this is disabled.
31 */
32 replaceInvalidCharsInName?: boolean;
33}
34/**
35 * Represents an attribute.
36 *
37 * An attribute is part of the start tag of an element and is
38 * structured as follows, where `{name}` is the name of the attribute and
39 * `{value}` is the value of the attribute:
40 *
41 * ```xml
42 * <element {name}="{value}">
43 * ```
44 *
45 * The `{name}` value is a property of this node, while the `{value}` property
46 * consists of the children of this node.
47 *
48 * Attributes can have an unlimited number of attribute text, character
49 * references, and entity references.
50 */
51export default class XmlAttribute<Parent> {
52 private readonly _children;
53 private readonly _replaceInvalidCharsInName;
54 private readonly _parent;
55 private readonly _validation;
56 private _name;
57 constructor(parent: Parent, validation: boolean, options: IXmlAttributeOptions);
58 /**
59 * Gets the name of this attribute.
60 */
61 get name(): string;
62 /**
63 * Sets the name of this attribute.
64 */
65 set name(name: string);
66 /**
67 * Adds a character reference to this attribute and returns the new
68 * character reference.
69 */
70 charRef(options: IXmlCharRefOptions): XmlCharRef<this>;
71 /**
72 * Adds an entity reference to this attribute and returns the new entity
73 * reference.
74 */
75 entityRef(options: IXmlEntityRefOptions): XmlEntityRef<this>;
76 /**
77 * Adds attribute text to this attribute and returns the new text.
78 */
79 text(options: IXmlAttributeTextOptions): XmlAttributeText<this>;
80 /**
81 * Returns an XML string representation of this attribute.
82 */
83 toString(options?: IStringOptions): string;
84 /**
85 * Returns the parent of this attribute.
86 */
87 up(): Parent;
88}