source: node_modules/parse-entities/types/index.d.ts

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 16 months ago

Initial commit

  • Property mode set to 100644
File size: 3.1 KB
Line 
1// TypeScript Version: 3.4
2
3declare namespace parseEntities {
4 interface ParseEntitiesOptions<
5 WC = typeof globalThis,
6 TC = typeof globalThis,
7 RC = typeof globalThis
8 > {
9 /**
10 * Additional character to accept (`string?`, default: `''`).
11 * This allows other characters, without error, when following an ampersand.
12 */
13 additional: string
14
15 /**
16 * Whether to parse `value` as an attribute value (`boolean?`, default: `false`).
17 */
18 attribute: boolean
19
20 /**
21 * Whether to allow non-terminated entities (`boolean`, default: `true`).
22 * For example, `&copycat` for `©cat`. This behaviour is spec-compliant but can lead to unexpected results.
23 */
24 nonTerminated: boolean
25
26 /**
27 * Error handler (`Function?`).
28 */
29 warning: ErrorHandler<WC>
30
31 /**
32 * Text handler (`Function?`).
33 */
34 text: TextHandler<TC>
35
36 /**
37 * Reference handler (`Function?`).
38 */
39 reference: ReferenceHandler<RC>
40
41 /**
42 * Context used when invoking `warning` (`'*'`, optional).
43 */
44 warningContext: WC
45
46 /**
47 * Context used when invoking `text` (`'*'`, optional).
48 */
49 textContext: TC
50
51 /**
52 * Context used when invoking `reference` (`'*'`, optional)
53 */
54 referenceContext: RC
55
56 /**
57 * Starting `position` of `value` (`Location` or `Position`, optional). Useful when dealing with values nested in some sort of syntax tree.
58 */
59 position: Position
60 }
61
62 /**
63 * Error handler.
64 */
65 type ErrorHandler<C> = (
66 /**
67 * `this` refers to `warningContext` when given to `parseEntities`.
68 */
69 this: C,
70
71 /**
72 * Human-readable reason for triggering a parse error (`string`).
73 */
74 reason: string,
75
76 /**
77 * Place at which the parse error occurred (`Position`).
78 */
79 position: Position,
80
81 /**
82 * Identifier of reason for triggering a parse error (`number`).
83 */
84 code: number
85 ) => void
86
87 /**
88 * Text handler.
89 */
90 type TextHandler<C> = (
91 /**
92 * `this` refers to `textContext` when given to `parseEntities`.
93 */
94 this: C,
95
96 /**
97 * String of content (`string`).
98 */
99 value: string,
100
101 /**
102 * Location at which `value` starts and ends (`Location`).
103 */
104 location: Location
105 ) => void
106
107 /**
108 * Character reference handler.
109 */
110 type ReferenceHandler<C> = (
111 /**
112 * `this` refers to `textContext` when given to `parseEntities`.
113 */
114 this: C,
115
116 /**
117 * String of content (`string`).
118 */
119 value: string,
120
121 /**
122 * Location at which `value` starts and ends (`Location`).
123 */
124 location: Location,
125
126 /**
127 * Source of character reference (`Location`).
128 */
129 source: Location
130 ) => void
131
132 interface Position {
133 line: number
134 column: number
135 offset: number
136 indent?: number[]
137 }
138
139 interface Location {
140 start: Position
141 end: Position
142 }
143}
144
145/**
146 * Decode special characters in `value`.
147 */
148declare function parseEntities<
149 WC = typeof globalThis,
150 TC = typeof globalThis,
151 RC = typeof globalThis
152>(
153 value: string,
154 options?: Partial<parseEntities.ParseEntitiesOptions<WC, TC, RC>>
155): string
156
157export = parseEntities
Note: See TracBrowser for help on using the repository browser.