All files / _types.ts

100.00% Branches 0/0
100.00% Lines 1/1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
x1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 














































// Imports
import type { Nullable } from "@libs/typing"

/** XML text node. */
export type xml_text = {
  /** Parent node. */
  readonly ["~parent"]: xml_node
  /** Tag name (`~text` for text nodes, `~cdata` for CDATA nodes and `~comment` for comment nodes). */
  readonly ["~name"]: string
  /** Text content. */
  ["#text"]: string
}

/** XML node. */
export type xml_node = {
  /** Tag name (`~xml` for XML prolog, other nodes will be given their respective tag name). */
  readonly ["~name"]: string
  /** Child nodes. */
  readonly ["~children"]: Array<xml_node | xml_text>
  /** Comments. */
  readonly ["#comments"]?: Array<string>
  /** Text content. */
  readonly ["#text"]: string
  // Signature
  [key: string]: unknown
}

/** XML document. */
export type xml_document = xml_node & {
  /** XML version. */
  ["@version"]?: `1.${number}`
  /** XML character encoding. */
  ["@encoding"]?: string
  /** XML standalone. */
  ["@standalone"]?: "yes" | "no"
  /** XML doctype. */
  ["#doctype"]?: xml_node
  /** XML instructions. */
  ["#instructions"]?: { [key: string]: xml_node | Array<xml_node> }
}

/** Synchronous reader. */
export type ReaderSync = { readSync(buffer: Uint8Array): Nullable<number> }

/** A laxer type for what can be stringified. We won’t ever create this, but we’ll accept it. */
export type stringifyable = Partial<Omit<xml_document, "@version" | "@standalone"> & { "@version": string; "@standalone": string }>

// Exports
export type { Nullable }