@gglib/utils 0.6.2 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +7 -0
- package/Readme.md +1 -1
- package/dist/bundles/utils.esm.js +1904 -0
- package/dist/bundles/utils.esm.js.map +1 -0
- package/dist/stats.html +211 -170
- package/dist/utils/src/collections/IdMap.d.ts +13 -0
- package/dist/utils/src/collections/IdMap.d.ts.map +1 -0
- package/dist/utils/src/collections/IdMap.js +63 -0
- package/dist/utils/src/collections/IdMap.js.map +1 -0
- package/dist/utils/src/collections/IdSet.d.ts +11 -0
- package/dist/utils/src/collections/IdSet.d.ts.map +1 -0
- package/dist/utils/src/collections/IdSet.js +47 -0
- package/dist/utils/src/collections/IdSet.js.map +1 -0
- package/dist/utils/src/collections/PooledList.d.ts +15 -0
- package/dist/utils/src/collections/PooledList.d.ts.map +1 -0
- package/dist/utils/src/collections/PooledList.js +44 -0
- package/dist/utils/src/collections/PooledList.js.map +1 -0
- package/dist/utils/src/collections/PriorityQueue.d.ts +27 -0
- package/dist/utils/src/collections/PriorityQueue.d.ts.map +1 -0
- package/dist/utils/src/collections/PriorityQueue.js +142 -0
- package/dist/utils/src/collections/PriorityQueue.js.map +1 -0
- package/dist/utils/src/collections/array.d.ts +27 -0
- package/dist/utils/src/collections/array.d.ts.map +1 -0
- package/dist/utils/src/collections/array.js +55 -0
- package/dist/utils/src/collections/array.js.map +1 -0
- package/dist/utils/src/collections/index.d.ts +6 -0
- package/dist/utils/src/collections/index.d.ts.map +1 -0
- package/dist/utils/src/collections/index.js +6 -0
- package/dist/utils/src/collections/index.js.map +1 -0
- package/dist/utils/src/events/bus.d.ts +15 -0
- package/dist/utils/src/events/bus.d.ts.map +1 -0
- package/dist/utils/src/events/bus.js +47 -0
- package/dist/utils/src/events/bus.js.map +1 -0
- package/dist/utils/src/events/channel.d.ts +23 -0
- package/dist/utils/src/events/channel.d.ts.map +1 -0
- package/dist/utils/src/events/channel.js +95 -0
- package/dist/utils/src/events/channel.js.map +1 -0
- package/dist/utils/src/events/emitter.d.ts +14 -0
- package/dist/utils/src/events/emitter.d.ts.map +1 -0
- package/dist/utils/src/events/emitter.js +37 -0
- package/dist/utils/src/events/emitter.js.map +1 -0
- package/dist/utils/src/events/index.d.ts +6 -0
- package/dist/utils/src/events/index.d.ts.map +1 -0
- package/dist/utils/src/events/index.js +6 -0
- package/dist/utils/src/events/index.js.map +1 -0
- package/dist/utils/src/events/source.d.ts +20 -0
- package/dist/utils/src/events/source.d.ts.map +1 -0
- package/dist/utils/src/events/source.js +69 -0
- package/dist/utils/src/events/source.js.map +1 -0
- package/dist/utils/src/events/types.d.ts +3 -0
- package/dist/utils/src/events/types.d.ts.map +1 -0
- package/dist/utils/src/events/types.js +2 -0
- package/dist/utils/src/events/types.js.map +1 -0
- package/dist/utils/src/index.d.ts +5 -9
- package/dist/utils/src/index.d.ts.map +1 -1
- package/dist/utils/src/index.js +5 -9
- package/dist/utils/src/index.js.map +1 -1
- package/dist/utils/src/{BinaryReader.d.ts → reader/BinaryReader.d.ts} +19 -1
- package/dist/utils/src/reader/BinaryReader.d.ts.map +1 -0
- package/dist/utils/src/{BinaryReader.js → reader/BinaryReader.js} +80 -61
- package/dist/utils/src/reader/BinaryReader.js.map +1 -0
- package/dist/utils/src/reader/TextReader.d.ts +245 -0
- package/dist/utils/src/reader/TextReader.d.ts.map +1 -0
- package/dist/utils/src/reader/TextReader.js +465 -0
- package/dist/utils/src/reader/TextReader.js.map +1 -0
- package/dist/utils/src/reader/index.d.ts +3 -0
- package/dist/utils/src/reader/index.d.ts.map +1 -0
- package/dist/utils/src/reader/index.js +3 -0
- package/dist/utils/src/reader/index.js.map +1 -0
- package/dist/utils/src/types/brand.d.ts +26 -0
- package/dist/utils/src/types/brand.d.ts.map +1 -0
- package/dist/utils/src/types/brand.js +4 -0
- package/dist/utils/src/types/brand.js.map +1 -0
- package/dist/utils/src/types/index.d.ts +4 -0
- package/dist/utils/src/types/index.d.ts.map +1 -0
- package/dist/utils/src/types/index.js +4 -0
- package/dist/utils/src/types/index.js.map +1 -0
- package/dist/utils/src/types/json-rpc.d.ts +72 -0
- package/dist/utils/src/types/json-rpc.d.ts.map +1 -0
- package/dist/utils/src/types/json-rpc.js +99 -0
- package/dist/utils/src/types/json-rpc.js.map +1 -0
- package/dist/utils/src/types/rxjs.d.ts +17 -0
- package/dist/utils/src/types/rxjs.d.ts.map +1 -0
- package/dist/utils/src/types/rxjs.js +10 -0
- package/dist/utils/src/types/rxjs.js.map +1 -0
- package/dist/utils/src/uri/index.d.ts +4 -0
- package/dist/utils/src/uri/index.d.ts.map +1 -0
- package/dist/utils/src/uri/index.js +4 -0
- package/dist/utils/src/uri/index.js.map +1 -0
- package/dist/utils/src/uri/merge.d.ts +2 -0
- package/dist/utils/src/uri/merge.d.ts.map +1 -0
- package/dist/utils/src/uri/merge.js +56 -0
- package/dist/utils/src/uri/merge.js.map +1 -0
- package/dist/utils/src/uri/parse.d.ts +129 -0
- package/dist/utils/src/uri/parse.d.ts.map +1 -0
- package/dist/utils/src/uri/parse.js +83 -0
- package/dist/utils/src/uri/parse.js.map +1 -0
- package/dist/utils/src/uri/path.d.ts +22 -0
- package/dist/utils/src/uri/path.d.ts.map +1 -0
- package/dist/utils/src/uri/path.js +34 -0
- package/dist/utils/src/uri/path.js.map +1 -0
- package/dist/utils/src/utils/dom.d.ts +7 -2
- package/dist/utils/src/utils/dom.d.ts.map +1 -1
- package/dist/utils/src/utils/dom.js +59 -63
- package/dist/utils/src/utils/dom.js.map +1 -1
- package/dist/utils/src/utils/index.d.ts +3 -8
- package/dist/utils/src/utils/index.d.ts.map +1 -1
- package/dist/utils/src/utils/index.js +3 -8
- package/dist/utils/src/utils/index.js.map +1 -1
- package/dist/utils/src/utils/logfmt.d.ts +53 -0
- package/dist/utils/src/utils/logfmt.d.ts.map +1 -0
- package/dist/utils/src/utils/logfmt.js +66 -0
- package/dist/utils/src/utils/logfmt.js.map +1 -0
- package/dist/utils/src/utils/loop.d.ts +12 -28
- package/dist/utils/src/utils/loop.d.ts.map +1 -1
- package/dist/utils/src/utils/loop.js +23 -54
- package/dist/utils/src/utils/loop.js.map +1 -1
- package/dist/utils/src/utils/metric.d.ts +23 -0
- package/dist/utils/src/utils/metric.d.ts.map +1 -0
- package/dist/utils/src/utils/metric.js +47 -0
- package/dist/utils/src/utils/metric.js.map +1 -0
- package/dist/utils/src/utils/uuid.js +3 -3
- package/dist/utils/src/utils/uuid.js.map +1 -1
- package/dist/utils/src/utils/worker.d.ts +18 -0
- package/dist/utils/src/utils/worker.d.ts.map +1 -0
- package/dist/utils/src/utils/worker.js +23 -0
- package/dist/utils/src/utils/worker.js.map +1 -0
- package/dist/utils/tsconfig.build.tsbuildinfo +1 -0
- package/package.json +11 -4
- package/dist/bundles/utils.umd.js +0 -1663
- package/dist/bundles/utils.umd.js.map +0 -1
- package/dist/utils/src/BinaryReader.d.ts.map +0 -1
- package/dist/utils/src/BinaryReader.js.map +0 -1
- package/dist/utils/src/BinaryReader.spec.d.ts +0 -2
- package/dist/utils/src/BinaryReader.spec.d.ts.map +0 -1
- package/dist/utils/src/BinaryReader.spec.js +0 -38
- package/dist/utils/src/BinaryReader.spec.js.map +0 -1
- package/dist/utils/src/DataUri.d.ts +0 -36
- package/dist/utils/src/DataUri.d.ts.map +0 -1
- package/dist/utils/src/DataUri.js +0 -45
- package/dist/utils/src/DataUri.js.map +0 -1
- package/dist/utils/src/DataUri.spec.d.ts +0 -2
- package/dist/utils/src/DataUri.spec.d.ts.map +0 -1
- package/dist/utils/src/DataUri.spec.js +0 -34
- package/dist/utils/src/DataUri.spec.js.map +0 -1
- package/dist/utils/src/Events.d.ts +0 -59
- package/dist/utils/src/Events.d.ts.map +0 -1
- package/dist/utils/src/Events.js +0 -125
- package/dist/utils/src/Events.js.map +0 -1
- package/dist/utils/src/Events.spec.d.ts +0 -2
- package/dist/utils/src/Events.spec.d.ts.map +0 -1
- package/dist/utils/src/Events.spec.js +0 -61
- package/dist/utils/src/Events.spec.js.map +0 -1
- package/dist/utils/src/Http.d.ts +0 -56
- package/dist/utils/src/Http.d.ts.map +0 -1
- package/dist/utils/src/Http.js +0 -60
- package/dist/utils/src/Http.js.map +0 -1
- package/dist/utils/src/Http.spec.d.ts +0 -2
- package/dist/utils/src/Http.spec.d.ts.map +0 -1
- package/dist/utils/src/Http.spec.js +0 -23
- package/dist/utils/src/Http.spec.js.map +0 -1
- package/dist/utils/src/Immutable.d.ts +0 -10
- package/dist/utils/src/Immutable.d.ts.map +0 -1
- package/dist/utils/src/Immutable.js +0 -2
- package/dist/utils/src/Immutable.js.map +0 -1
- package/dist/utils/src/JsonRpc.d.ts +0 -35
- package/dist/utils/src/JsonRpc.d.ts.map +0 -1
- package/dist/utils/src/JsonRpc.js +0 -2
- package/dist/utils/src/JsonRpc.js.map +0 -1
- package/dist/utils/src/Log.d.ts +0 -26
- package/dist/utils/src/Log.d.ts.map +0 -1
- package/dist/utils/src/Log.js +0 -77
- package/dist/utils/src/Log.js.map +0 -1
- package/dist/utils/src/TextReader.d.ts +0 -100
- package/dist/utils/src/TextReader.d.ts.map +0 -1
- package/dist/utils/src/TextReader.js +0 -217
- package/dist/utils/src/TextReader.js.map +0 -1
- package/dist/utils/src/TextReader.spec.d.ts +0 -2
- package/dist/utils/src/TextReader.spec.d.ts.map +0 -1
- package/dist/utils/src/TextReader.spec.js +0 -42
- package/dist/utils/src/TextReader.spec.js.map +0 -1
- package/dist/utils/src/Uri.d.ts +0 -29
- package/dist/utils/src/Uri.d.ts.map +0 -1
- package/dist/utils/src/Uri.js +0 -129
- package/dist/utils/src/Uri.js.map +0 -1
- package/dist/utils/src/Uri.spec.d.ts +0 -2
- package/dist/utils/src/Uri.spec.d.ts.map +0 -1
- package/dist/utils/src/Uri.spec.js +0 -43
- package/dist/utils/src/Uri.spec.js.map +0 -1
- package/dist/utils/src/WebWorker.d.ts +0 -105
- package/dist/utils/src/WebWorker.d.ts.map +0 -1
- package/dist/utils/src/WebWorker.js +0 -216
- package/dist/utils/src/WebWorker.js.map +0 -1
- package/dist/utils/src/WebWorker.spec.d.ts +0 -2
- package/dist/utils/src/WebWorker.spec.d.ts.map +0 -1
- package/dist/utils/src/WebWorker.spec.js +0 -30
- package/dist/utils/src/WebWorker.spec.js.map +0 -1
- package/dist/utils/src/utils/array.d.ts +0 -39
- package/dist/utils/src/utils/array.d.ts.map +0 -1
- package/dist/utils/src/utils/array.js +0 -63
- package/dist/utils/src/utils/array.js.map +0 -1
- package/dist/utils/src/utils/get-canvas.d.ts +0 -7
- package/dist/utils/src/utils/get-canvas.d.ts.map +0 -1
- package/dist/utils/src/utils/get-canvas.js +0 -22
- package/dist/utils/src/utils/get-canvas.js.map +0 -1
- package/dist/utils/src/utils/get-option.d.ts +0 -11
- package/dist/utils/src/utils/get-option.d.ts.map +0 -1
- package/dist/utils/src/utils/get-option.js +0 -16
- package/dist/utils/src/utils/get-option.js.map +0 -1
- package/dist/utils/src/utils/getImageData.d.ts +0 -7
- package/dist/utils/src/utils/getImageData.d.ts.map +0 -1
- package/dist/utils/src/utils/getImageData.js +0 -25
- package/dist/utils/src/utils/getImageData.js.map +0 -1
- package/dist/utils/src/utils/getImageData.spec.d.ts +0 -2
- package/dist/utils/src/utils/getImageData.spec.d.ts.map +0 -1
- package/dist/utils/src/utils/getImageData.spec.js +0 -22
- package/dist/utils/src/utils/getImageData.spec.js.map +0 -1
- package/dist/utils/src/utils/hasOwnProperty.d.ts +0 -5
- package/dist/utils/src/utils/hasOwnProperty.d.ts.map +0 -1
- package/dist/utils/src/utils/hasOwnProperty.js +0 -7
- package/dist/utils/src/utils/hasOwnProperty.js.map +0 -1
- package/dist/utils/src/utils/loop.spec.d.ts +0 -2
- package/dist/utils/src/utils/loop.spec.d.ts.map +0 -1
- package/dist/utils/src/utils/loop.spec.js +0 -17
- package/dist/utils/src/utils/loop.spec.js.map +0 -1
- package/dist/utils/src/utils/object.d.ts +0 -23
- package/dist/utils/src/utils/object.d.ts.map +0 -1
- package/dist/utils/src/utils/object.js +0 -90
- package/dist/utils/src/utils/object.js.map +0 -1
- package/dist/utils/src/utils/string.d.ts +0 -19
- package/dist/utils/src/utils/string.d.ts.map +0 -1
- package/dist/utils/src/utils/string.js +0 -25
- package/dist/utils/src/utils/string.js.map +0 -1
- package/dist/utils/src/utils/type.d.ts +0 -58
- package/dist/utils/src/utils/type.d.ts.map +0 -1
- package/dist/utils/src/utils/type.js +0 -17
- package/dist/utils/src/utils/type.js.map +0 -1
- package/dist/utils/tsconfig.tsbuildinfo +0 -510
|
@@ -0,0 +1,465 @@
|
|
|
1
|
+
export const TextCharKind = {
|
|
2
|
+
Whitespace: 0,
|
|
3
|
+
Symbol: 1,
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* A wrapper around a string. Simplifies reading arbitrary formatted text data.
|
|
7
|
+
*
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export class TextReader {
|
|
11
|
+
/**
|
|
12
|
+
* Checks whether the readers position has not reached the end of the string
|
|
13
|
+
*/
|
|
14
|
+
get canRead() {
|
|
15
|
+
return this.index < this.text.length;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Gets the character at the current readers position.
|
|
19
|
+
*/
|
|
20
|
+
get char() {
|
|
21
|
+
return this.text.charAt(this.index);
|
|
22
|
+
}
|
|
23
|
+
get charCode() {
|
|
24
|
+
return this.text.charCodeAt(this.index);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Gets a substring until the end of the string.
|
|
28
|
+
*/
|
|
29
|
+
get rest() {
|
|
30
|
+
return this.text.substring(this.index);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Detects whether the character at current position is a symbol
|
|
34
|
+
*/
|
|
35
|
+
get isSymbol() {
|
|
36
|
+
return this.charMap.get(this.char) === TextCharKind.Symbol;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Detects whether the character at current position is a whitespace
|
|
40
|
+
*/
|
|
41
|
+
get isWhitespace() {
|
|
42
|
+
return this.charMap.get(this.char) === TextCharKind.Whitespace;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Detects whether the character at current position is a '\n'
|
|
46
|
+
*/
|
|
47
|
+
get isNewLine() {
|
|
48
|
+
return this.char === '\n';
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Detects whether the caracter at current position is neither whitespace nor symbol
|
|
52
|
+
*/
|
|
53
|
+
get isToken() {
|
|
54
|
+
return !(this.isWhitespace || this.isSymbol);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Detects whether the caracter at current position is [0-9]
|
|
58
|
+
*/
|
|
59
|
+
get isNumeric() {
|
|
60
|
+
const c = this.charCode;
|
|
61
|
+
return c >= 48 && c <= 57;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Detects whether the caracter at current position is [a-zA-Z]
|
|
65
|
+
*/
|
|
66
|
+
get isAlpha() {
|
|
67
|
+
const c = this.charCode;
|
|
68
|
+
return (c >= 65 && c <= 90) || (c >= 97 && c <= 122);
|
|
69
|
+
}
|
|
70
|
+
get position() {
|
|
71
|
+
return this.index;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Creates a new instance of {@link TextReader}
|
|
75
|
+
*
|
|
76
|
+
* @param text - The text data to read
|
|
77
|
+
*/
|
|
78
|
+
constructor(text, options) {
|
|
79
|
+
var _a, _b;
|
|
80
|
+
this.index = 0;
|
|
81
|
+
this.charMap = new Map();
|
|
82
|
+
this.cachedSets = new Map();
|
|
83
|
+
this.text = text;
|
|
84
|
+
this.options = options;
|
|
85
|
+
const whitespaces = (_a = options === null || options === void 0 ? void 0 : options.whitespaces) !== null && _a !== void 0 ? _a : ' \t\r\n\f';
|
|
86
|
+
whitespaces.split('').forEach((it) => {
|
|
87
|
+
this.charMap.set(it, TextCharKind.Whitespace);
|
|
88
|
+
});
|
|
89
|
+
const symbols = (_b = options === null || options === void 0 ? void 0 : options.symbols) !== null && _b !== void 0 ? _b : '.+-/*%<>[](){}^|&~=!:;,?';
|
|
90
|
+
symbols.split('').forEach((it) => {
|
|
91
|
+
this.charMap.set(it, TextCharKind.Symbol);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
getSet(set) {
|
|
95
|
+
let result = this.cachedSets.get(set);
|
|
96
|
+
if (!result) {
|
|
97
|
+
result = new Set(set.split(''));
|
|
98
|
+
this.cachedSets.set(set, result);
|
|
99
|
+
}
|
|
100
|
+
return result;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Sets the current reader position to the given index
|
|
104
|
+
*/
|
|
105
|
+
seek(index) {
|
|
106
|
+
this.index = index;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Returns the string that is in front of current position
|
|
110
|
+
*
|
|
111
|
+
* @param count - number of characters to peek
|
|
112
|
+
*/
|
|
113
|
+
peek(count) {
|
|
114
|
+
return count == null || count === 1 ? this.char : this.text.substr(this.index, count);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
*
|
|
118
|
+
* @param offset
|
|
119
|
+
* @param count
|
|
120
|
+
* @returns
|
|
121
|
+
*/
|
|
122
|
+
peekOffset(offset, count) {
|
|
123
|
+
return this.text.substr(this.index + offset, count !== null && count !== void 0 ? count : 1);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Returns the text that is in front of current position (see `readText`)
|
|
127
|
+
*/
|
|
128
|
+
peekText() {
|
|
129
|
+
const i = this.index;
|
|
130
|
+
const t = this.readText();
|
|
131
|
+
this.index = i;
|
|
132
|
+
return t;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Returns the token that is in front of current position (see `readToken`)
|
|
136
|
+
*/
|
|
137
|
+
peekToken() {
|
|
138
|
+
const i = this.index;
|
|
139
|
+
const t = this.readToken();
|
|
140
|
+
this.index = i;
|
|
141
|
+
return t;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Return the text from current position until next new line terminator
|
|
145
|
+
*/
|
|
146
|
+
peekLine() {
|
|
147
|
+
const i = this.index;
|
|
148
|
+
const l = this.readLine();
|
|
149
|
+
this.index = i;
|
|
150
|
+
return l;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Moves pointer back to unread the given number of characters
|
|
154
|
+
*/
|
|
155
|
+
unread(count) {
|
|
156
|
+
this.index = Math.max(0, this.index - Math.abs(count));
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Reads the given number of characters.
|
|
160
|
+
*
|
|
161
|
+
* @remarks
|
|
162
|
+
* If the reader is finished reading, an empty string will be returned
|
|
163
|
+
*
|
|
164
|
+
* @returns the string that was read
|
|
165
|
+
*/
|
|
166
|
+
read(count) {
|
|
167
|
+
if (!this.canRead) {
|
|
168
|
+
return '';
|
|
169
|
+
}
|
|
170
|
+
if (count > 1) {
|
|
171
|
+
const result = this.text.substr(this.index, count);
|
|
172
|
+
this.index += count;
|
|
173
|
+
return result;
|
|
174
|
+
}
|
|
175
|
+
const result = this.char;
|
|
176
|
+
this.index++;
|
|
177
|
+
return result;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Skips initial whitespaces and then reads everything until next occurance of a whitespace
|
|
181
|
+
*
|
|
182
|
+
* @returns the string that was read
|
|
183
|
+
*/
|
|
184
|
+
readText() {
|
|
185
|
+
if (!this.canRead) {
|
|
186
|
+
return '';
|
|
187
|
+
}
|
|
188
|
+
this.skipWhitespace();
|
|
189
|
+
const i = this.index;
|
|
190
|
+
this.skipUntilWhitespace();
|
|
191
|
+
return this.text.substr(i, this.index - i).trim();
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Skips initial whitespaces and then reads everything until next occurance of a whitespace or symbol
|
|
195
|
+
*
|
|
196
|
+
* @returns the string that was read
|
|
197
|
+
*/
|
|
198
|
+
readToken() {
|
|
199
|
+
if (!this.canRead) {
|
|
200
|
+
return '';
|
|
201
|
+
}
|
|
202
|
+
this.skipWhitespace();
|
|
203
|
+
const i = this.index;
|
|
204
|
+
this.skipUntilWhitespaceOrSymbol();
|
|
205
|
+
return this.text.substr(i, this.index - i).trim();
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Reads until next occurrence of a new line character and trims the result
|
|
209
|
+
*
|
|
210
|
+
* @param cb - on optional callback that will receive a new reader for the new line
|
|
211
|
+
* @returns the trimmed string that was being read
|
|
212
|
+
*/
|
|
213
|
+
readLine(cb) {
|
|
214
|
+
const line = this.readLineRaw().trim();
|
|
215
|
+
if (cb) {
|
|
216
|
+
cb(this.createReader(line));
|
|
217
|
+
}
|
|
218
|
+
return line;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Reads until next occurrence of a new line character
|
|
222
|
+
*
|
|
223
|
+
* @param cb - on optional callback that will receive a new reader for the new line
|
|
224
|
+
* @returns the string that was being read
|
|
225
|
+
*/
|
|
226
|
+
readLineRaw(cb) {
|
|
227
|
+
if (!this.canRead) {
|
|
228
|
+
return '';
|
|
229
|
+
}
|
|
230
|
+
const i = this.index;
|
|
231
|
+
this.skipUntil('\n');
|
|
232
|
+
this.skip(1);
|
|
233
|
+
const line = this.text.substr(i, this.index - i);
|
|
234
|
+
if (cb) {
|
|
235
|
+
cb(this.createReader(line));
|
|
236
|
+
}
|
|
237
|
+
return line;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Skips leading whitespaces and then reads a block that is determined by the `open` and `close` character.
|
|
241
|
+
*
|
|
242
|
+
* @param start - character set identifying the begin of a block. Usually an opening parenthesis.
|
|
243
|
+
* @param end - character set identifying the end of a block. Usually matching parenthesis.
|
|
244
|
+
* @param cb - a callback to call with a new text reader
|
|
245
|
+
*/
|
|
246
|
+
readBlock(open, close, cb) {
|
|
247
|
+
if (!this.canRead) {
|
|
248
|
+
return '';
|
|
249
|
+
}
|
|
250
|
+
this.skipWhitespace();
|
|
251
|
+
if (this.char !== open) {
|
|
252
|
+
throw new Error(`expected '${open}' at current position but was ${this.char}`);
|
|
253
|
+
}
|
|
254
|
+
let iStart = this.index + 1;
|
|
255
|
+
let iEnd = iStart;
|
|
256
|
+
let depth = 0;
|
|
257
|
+
while (this.canRead) {
|
|
258
|
+
if (this.char === open) {
|
|
259
|
+
depth++;
|
|
260
|
+
}
|
|
261
|
+
if (this.char === close) {
|
|
262
|
+
depth--;
|
|
263
|
+
}
|
|
264
|
+
if (depth === 0) {
|
|
265
|
+
iEnd = this.index;
|
|
266
|
+
this.skip(1);
|
|
267
|
+
break;
|
|
268
|
+
}
|
|
269
|
+
this.skip(1);
|
|
270
|
+
}
|
|
271
|
+
const block = this.text.substring(iStart, iEnd);
|
|
272
|
+
if (cb) {
|
|
273
|
+
cb(this.createReader(block));
|
|
274
|
+
}
|
|
275
|
+
return block;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Reads a sequence of characters that are in given set
|
|
279
|
+
*
|
|
280
|
+
* @param cahrSet - the allowed character set
|
|
281
|
+
* @returns the text being read
|
|
282
|
+
*/
|
|
283
|
+
readWhile(cahrSet) {
|
|
284
|
+
const set = this.getSet(cahrSet);
|
|
285
|
+
const i = this.index;
|
|
286
|
+
while (this.canRead && set.has(this.char)) {
|
|
287
|
+
this.index += 1;
|
|
288
|
+
}
|
|
289
|
+
return this.text.substr(i, this.index - i);
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Reads everything until any character from given charset occurs
|
|
293
|
+
*
|
|
294
|
+
* @param charSet - the character set
|
|
295
|
+
* @param inclusive - wheter to also read the boundary characters
|
|
296
|
+
* @returns the text being read
|
|
297
|
+
*/
|
|
298
|
+
readUntil(charSet, inclusive) {
|
|
299
|
+
const i = this.index;
|
|
300
|
+
this.skipUntil(charSet, inclusive);
|
|
301
|
+
return this.text.substr(i, this.index - i);
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Reads everything until the given sequence occurs
|
|
305
|
+
*
|
|
306
|
+
* @param charSet - the character sequence
|
|
307
|
+
* @param inclusive - wheter to also read the sequence at the end
|
|
308
|
+
* @returns the text being read
|
|
309
|
+
*/
|
|
310
|
+
readUntilText(sequence, inclusive) {
|
|
311
|
+
const i = this.index;
|
|
312
|
+
this.skipUntilSequence(sequence, inclusive);
|
|
313
|
+
return this.text.substr(i, this.index - i);
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Skips the given number of characters
|
|
317
|
+
*
|
|
318
|
+
* @param count - the character count
|
|
319
|
+
*/
|
|
320
|
+
skip(count) {
|
|
321
|
+
this.index += count;
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Skips all whitespace characters
|
|
325
|
+
*/
|
|
326
|
+
skipWhitespace() {
|
|
327
|
+
while (this.canRead && this.isWhitespace) {
|
|
328
|
+
this.index += 1;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Skips all symbol characters
|
|
333
|
+
*/
|
|
334
|
+
skipSymbols() {
|
|
335
|
+
while (this.canRead && this.isSymbol) {
|
|
336
|
+
this.index += 1;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Skips all whitespace and symbol characters
|
|
341
|
+
*/
|
|
342
|
+
skipWhitespaceAndSymbols() {
|
|
343
|
+
while (this.canRead && (this.isWhitespace || this.isSymbol)) {
|
|
344
|
+
this.index += 1;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Skips all characters in given character set
|
|
349
|
+
*
|
|
350
|
+
* @param charset - the characters to skip
|
|
351
|
+
*/
|
|
352
|
+
skipChars(charset) {
|
|
353
|
+
while (this.canRead && charset.indexOf(this.char) >= 0) {
|
|
354
|
+
this.index += 1;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Skips characters until the next whitespace
|
|
359
|
+
*/
|
|
360
|
+
skipUntilWhitespace() {
|
|
361
|
+
while (this.canRead && !this.isWhitespace) {
|
|
362
|
+
this.index += 1;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Skips characters until the next symbol
|
|
367
|
+
*/
|
|
368
|
+
skipUntilSymbol() {
|
|
369
|
+
while (this.canRead && !this.isSymbol) {
|
|
370
|
+
this.index += 1;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Skips characters until the next whitespace or symbol
|
|
375
|
+
*/
|
|
376
|
+
skipUntilWhitespaceOrSymbol() {
|
|
377
|
+
while (this.canRead && !(this.isWhitespace || this.isSymbol)) {
|
|
378
|
+
this.index += 1;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Skips characters until occurrence of one in the given string
|
|
383
|
+
*
|
|
384
|
+
* @param charset - the characters to stop at
|
|
385
|
+
* @param consume -
|
|
386
|
+
*/
|
|
387
|
+
skipUntil(charset, consume) {
|
|
388
|
+
const set = this.getSet(charset);
|
|
389
|
+
while (this.canRead && !set.has(this.char)) {
|
|
390
|
+
this.skip(1);
|
|
391
|
+
}
|
|
392
|
+
if (consume) {
|
|
393
|
+
this.skipChars(charset);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Skips forward until the occurence of given sequence
|
|
398
|
+
*
|
|
399
|
+
* @param sequence - the sequence to search for
|
|
400
|
+
* @param consume - whether to consume the found sequence
|
|
401
|
+
*/
|
|
402
|
+
skipUntilSequence(sequence, consume) {
|
|
403
|
+
while (this.canRead) {
|
|
404
|
+
if (this.char !== sequence[0]) {
|
|
405
|
+
this.skip(1);
|
|
406
|
+
}
|
|
407
|
+
else if (this.peek(sequence.length) === sequence) {
|
|
408
|
+
if (consume) {
|
|
409
|
+
this.skip(sequence.length);
|
|
410
|
+
}
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
else {
|
|
414
|
+
this.skip(1);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* Consumes the next token only if it matches the given value. Otherwise leaves the state untouched.
|
|
420
|
+
*/
|
|
421
|
+
accept(value) {
|
|
422
|
+
const actual = this.peek(value.length);
|
|
423
|
+
if (actual === value) {
|
|
424
|
+
this.index += value.length;
|
|
425
|
+
return value;
|
|
426
|
+
}
|
|
427
|
+
return undefined;
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* Checks whether the value at current position equals the given value
|
|
431
|
+
*
|
|
432
|
+
* @param value
|
|
433
|
+
*/
|
|
434
|
+
assert(value, consume) {
|
|
435
|
+
const actual = this.peek(value.length);
|
|
436
|
+
if (actual !== value) {
|
|
437
|
+
throw new Error(`Expected '${value}' at current position but was '${actual}'\n${this.createErrorText()}`);
|
|
438
|
+
}
|
|
439
|
+
if (consume) {
|
|
440
|
+
this.index += value.length;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* Checks whether the value at current position equals the given value
|
|
445
|
+
*
|
|
446
|
+
* @param value
|
|
447
|
+
*/
|
|
448
|
+
assertChar(value, consume) {
|
|
449
|
+
if (this.char !== value) {
|
|
450
|
+
throw new Error(`Expected '${value}' at current position but was '${this.char}'\n${this.createErrorText()}`);
|
|
451
|
+
}
|
|
452
|
+
if (consume) {
|
|
453
|
+
this.index += 1;
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
createErrorText(offset = 10) {
|
|
457
|
+
const start = Math.max(this.index - 10, 0);
|
|
458
|
+
const end = Math.min(this.index + 10, this.text.length - 1);
|
|
459
|
+
return ' '.repeat(offset) + 'v\n' + `${this.text.substring(start, end)}`;
|
|
460
|
+
}
|
|
461
|
+
createReader(text) {
|
|
462
|
+
return new TextReader(text, this.options);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
//# sourceMappingURL=TextReader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TextReader.js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AC;IACH,CAAC;IAED;;;;OAIG;IACI,UAAU,CAAC,KAAa,EAAE,OAAiB;QAChD,IAAI,IAAI,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;YACxB,MAAM,IAAI,KAAK,CAAC,aAAa,KAAK,kCAAkC,IAAI,CAAC,IAAI,MAAM,IAAI,CAAC,eAAe,EAAE,EAAE,CAAC,CAAA;QAC9G,CAAC;QACD,IAAI,OAAO,EAAE,CAAC;YACZ,IAAI,CAAC,KAAK,IAAI,CAAC,CAAA;QACjB,CAAC;IACH,CAAC;IAEM,eAAe,CAAC,MAAM,GAAG,EAAE;QAChC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,GAAG,EAAE,EAAE,CAAC,CAAC,CAAA;QAC1C,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,GAAG,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;QAC3D,OAAO,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,KAAK,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,CAAA;IAC1E,CAAC;IAEM,YAAY,CAAC,IAAY;QAC9B,OAAO,IAAI,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,CAAA;IAC3C,CAAC;CACF","sourcesContent":["/**\n * Options for the {@link TextReader} constructor\n */\nexport interface TextReaderOptions {\n /**\n * Characters that identify a white space. Default is `' \\t\\r\\n\\f'`.\n */\n whitespaces?: string\n /**\n * Characters that are identified as symbols\n */\n symbols?: string\n}\n\nexport type TextCharKind = number & { __kind__: 'TextCharKind' }\nexport const TextCharKind = {\n Whitespace: 0 as TextCharKind,\n Symbol: 1 as TextCharKind,\n}\n\n/**\n * A wrapper around a string. Simplifies reading arbitrary formatted text data.\n *\n * @public\n */\nexport class TextReader {\n private index: number = 0\n\n /**\n * Checks whether the readers position has not reached the end of the string\n */\n public get canRead(): boolean {\n return this.index < this.text.length\n }\n\n /**\n * Gets the character at the current readers position.\n */\n public get char(): string {\n return this.text.charAt(this.index)\n }\n\n public get charCode(): number {\n return this.text.charCodeAt(this.index)\n }\n /**\n * Gets a substring until the end of the string.\n */\n public get rest(): string {\n return this.text.substring(this.index)\n }\n\n /**\n * Detects whether the character at current position is a symbol\n */\n public get isSymbol() {\n return this.charMap.get(this.char) === TextCharKind.Symbol\n }\n\n /**\n * Detects whether the character at current position is a whitespace\n */\n public get isWhitespace() {\n return this.charMap.get(this.char) === TextCharKind.Whitespace\n }\n\n /**\n * Detects whether the character at current position is a '\\n'\n */\n public get isNewLine() {\n return this.char === '\\n'\n }\n\n /**\n * Detects whether the caracter at current position is neither whitespace nor symbol\n */\n public get isToken() {\n return !(this.isWhitespace || this.isSymbol)\n }\n\n /**\n * Detects whether the caracter at current position is [0-9]\n */\n public get isNumeric() {\n const c = this.charCode\n return c >= 48 && c <= 57\n }\n\n /**\n * Detects whether the caracter at current position is [a-zA-Z]\n */\n public get isAlpha() {\n const c = this.charCode\n return (c >= 65 && c <= 90) || (c >= 97 && c <= 122)\n }\n\n public get position() {\n return this.index\n }\n\n public readonly options: TextReaderOptions\n protected charMap: Map<string, TextCharKind> = new Map()\n protected cachedSets = new Map<string, Set<string>>()\n private readonly text: string\n /**\n * Creates a new instance of {@link TextReader}\n *\n * @param text - The text data to read\n */\n constructor(text: string, options?: TextReaderOptions) {\n this.text = text\n this.options = options\n const whitespaces = options?.whitespaces ?? ' \\t\\r\\n\\f'\n whitespaces.split('').forEach((it) => {\n this.charMap.set(it, TextCharKind.Whitespace)\n })\n const symbols = options?.symbols ?? '.+-/*%<>[](){}^|&~=!:;,?'\n symbols.split('').forEach((it) => {\n this.charMap.set(it, TextCharKind.Symbol)\n })\n }\n\n private getSet(set: string) {\n let result = this.cachedSets.get(set)\n if (!result) {\n result = new Set(set.split(''))\n this.cachedSets.set(set, result)\n }\n return result\n }\n\n /**\n * Sets the current reader position to the given index\n */\n public seek(index: number) {\n this.index = index\n }\n\n /**\n * Returns the string that is in front of current position\n *\n * @param count - number of characters to peek\n */\n public peek(count?: number) {\n return count == null || count === 1 ? this.char : this.text.substr(this.index, count)\n }\n\n /**\n *\n * @param offset\n * @param count\n * @returns\n */\n public peekOffset(offset: number, count?: number) {\n return this.text.substr(this.index + offset, count ?? 1)\n }\n\n /**\n * Returns the text that is in front of current position (see `readText`)\n */\n public peekText() {\n const i = this.index\n const t = this.readText()\n this.index = i\n return t\n }\n\n /**\n * Returns the token that is in front of current position (see `readToken`)\n */\n public peekToken() {\n const i = this.index\n const t = this.readToken()\n this.index = i\n return t\n }\n\n /**\n * Return the text from current position until next new line terminator\n */\n public peekLine() {\n const i = this.index\n const l = this.readLine()\n this.index = i\n return l\n }\n\n /**\n * Moves pointer back to unread the given number of characters\n */\n public unread(count: number) {\n this.index = Math.max(0, this.index - Math.abs(count))\n }\n\n /**\n * Reads the given number of characters.\n *\n * @remarks\n * If the reader is finished reading, an empty string will be returned\n *\n * @returns the string that was read\n */\n public read(count?: number) {\n if (!this.canRead) {\n return ''\n }\n if (count > 1) {\n const result = this.text.substr(this.index, count)\n this.index += count\n return result\n }\n const result = this.char\n this.index++\n return result\n }\n\n /**\n * Skips initial whitespaces and then reads everything until next occurance of a whitespace\n *\n * @returns the string that was read\n */\n public readText() {\n if (!this.canRead) {\n return ''\n }\n this.skipWhitespace()\n const i = this.index\n this.skipUntilWhitespace()\n return this.text.substr(i, this.index - i).trim()\n }\n\n /**\n * Skips initial whitespaces and then reads everything until next occurance of a whitespace or symbol\n *\n * @returns the string that was read\n */\n public readToken() {\n if (!this.canRead) {\n return ''\n }\n this.skipWhitespace()\n const i = this.index\n this.skipUntilWhitespaceOrSymbol()\n return this.text.substr(i, this.index - i).trim()\n }\n\n /**\n * Reads until next occurrence of a new line character and trims the result\n *\n * @param cb - on optional callback that will receive a new reader for the new line\n * @returns the trimmed string that was being read\n */\n public readLine(cb?: (r: TextReader) => void) {\n const line = this.readLineRaw().trim()\n if (cb) {\n cb(this.createReader(line))\n }\n return line\n }\n\n /**\n * Reads until next occurrence of a new line character\n *\n * @param cb - on optional callback that will receive a new reader for the new line\n * @returns the string that was being read\n */\n public readLineRaw(cb?: (r: TextReader) => void) {\n if (!this.canRead) {\n return ''\n }\n const i = this.index\n this.skipUntil('\\n')\n this.skip(1)\n const line = this.text.substr(i, this.index - i)\n if (cb) {\n cb(this.createReader(line))\n }\n return line\n }\n\n /**\n * Skips leading whitespaces and then reads a block that is determined by the `open` and `close` character.\n *\n * @param start - character set identifying the begin of a block. Usually an opening parenthesis.\n * @param end - character set identifying the end of a block. Usually matching parenthesis.\n * @param cb - a callback to call with a new text reader\n */\n public readBlock(open: string, close: string, cb?: (r: TextReader) => void) {\n if (!this.canRead) {\n return ''\n }\n this.skipWhitespace()\n if (this.char !== open) {\n throw new Error(`expected '${open}' at current position but was ${this.char}`)\n }\n\n let iStart = this.index + 1\n let iEnd = iStart\n let depth = 0\n\n while (this.canRead) {\n if (this.char === open) {\n depth++\n }\n if (this.char === close) {\n depth--\n }\n if (depth === 0) {\n iEnd = this.index\n this.skip(1)\n break\n }\n this.skip(1)\n }\n\n const block = this.text.substring(iStart, iEnd)\n\n if (cb) {\n cb(this.createReader(block))\n }\n return block\n }\n\n /**\n * Reads a sequence of characters that are in given set\n *\n * @param cahrSet - the allowed character set\n * @returns the text being read\n */\n public readWhile(cahrSet: string) {\n const set = this.getSet(cahrSet)\n const i = this.index\n while (this.canRead && set.has(this.char)) {\n this.index += 1\n }\n return this.text.substr(i, this.index - i)\n }\n\n /**\n * Reads everything until any character from given charset occurs\n *\n * @param charSet - the character set\n * @param inclusive - wheter to also read the boundary characters\n * @returns the text being read\n */\n public readUntil(charSet: string, inclusive?: boolean) {\n const i = this.index\n this.skipUntil(charSet, inclusive)\n return this.text.substr(i, this.index - i)\n }\n\n /**\n * Reads everything until the given sequence occurs\n *\n * @param charSet - the character sequence\n * @param inclusive - wheter to also read the sequence at the end\n * @returns the text being read\n */\n public readUntilText(sequence: string, inclusive?: boolean) {\n const i = this.index\n this.skipUntilSequence(sequence, inclusive)\n return this.text.substr(i, this.index - i)\n }\n\n /**\n * Skips the given number of characters\n *\n * @param count - the character count\n */\n public skip(count: number) {\n this.index += count\n }\n\n /**\n * Skips all whitespace characters\n */\n public skipWhitespace() {\n while (this.canRead && this.isWhitespace) {\n this.index += 1\n }\n }\n\n /**\n * Skips all symbol characters\n */\n public skipSymbols() {\n while (this.canRead && this.isSymbol) {\n this.index += 1\n }\n }\n\n /**\n * Skips all whitespace and symbol characters\n */\n public skipWhitespaceAndSymbols() {\n while (this.canRead && (this.isWhitespace || this.isSymbol)) {\n this.index += 1\n }\n }\n\n /**\n * Skips all characters in given character set\n *\n * @param charset - the characters to skip\n */\n public skipChars(charset: string) {\n while (this.canRead && charset.indexOf(this.char) >= 0) {\n this.index += 1\n }\n }\n\n /**\n * Skips characters until the next whitespace\n */\n public skipUntilWhitespace() {\n while (this.canRead && !this.isWhitespace) {\n this.index += 1\n }\n }\n\n /**\n * Skips characters until the next symbol\n */\n public skipUntilSymbol() {\n while (this.canRead && !this.isSymbol) {\n this.index += 1\n }\n }\n\n /**\n * Skips characters until the next whitespace or symbol\n */\n public skipUntilWhitespaceOrSymbol() {\n while (this.canRead && !(this.isWhitespace || this.isSymbol)) {\n this.index += 1\n }\n }\n\n /**\n * Skips characters until occurrence of one in the given string\n *\n * @param charset - the characters to stop at\n * @param consume -\n */\n public skipUntil(charset: string, consume?: boolean) {\n const set = this.getSet(charset)\n while (this.canRead && !set.has(this.char)) {\n this.skip(1)\n }\n if (consume) {\n this.skipChars(charset)\n }\n }\n\n /**\n * Skips forward until the occurence of given sequence\n *\n * @param sequence - the sequence to search for\n * @param consume - whether to consume the found sequence\n */\n public skipUntilSequence(sequence: string, consume?: boolean) {\n while (this.canRead) {\n if (this.char !== sequence[0]) {\n this.skip(1)\n } else if (this.peek(sequence.length) === sequence) {\n if (consume) {\n this.skip(sequence.length)\n }\n return\n } else {\n this.skip(1)\n }\n }\n }\n\n /**\n * Consumes the next token only if it matches the given value. Otherwise leaves the state untouched.\n */\n public accept(value: string): string {\n const actual = this.peek(value.length)\n if (actual === value) {\n this.index += value.length\n return value\n }\n return undefined\n }\n\n /**\n * Checks whether the value at current position equals the given value\n *\n * @param value\n */\n public assert(value: string, consume?: boolean) {\n const actual = this.peek(value.length)\n if (actual !== value) {\n throw new Error(`Expected '${value}' at current position but was '${actual}'\\n${this.createErrorText()}`)\n }\n if (consume) {\n this.index += value.length\n }\n }\n\n /**\n * Checks whether the value at current position equals the given value\n *\n * @param value\n */\n public assertChar(value: string, consume?: boolean) {\n if (this.char !== value) {\n throw new Error(`Expected '${value}' at current position but was '${this.char}'\\n${this.createErrorText()}`)\n }\n if (consume) {\n this.index += 1\n }\n }\n\n public createErrorText(offset = 10) {\n const start = Math.max(this.index - 10, 0)\n const end = Math.min(this.index + 10, this.text.length - 1)\n return ' '.repeat(offset) + 'v\\n' + `${this.text.substring(start, end)}`\n }\n\n public createReader(text: string) {\n return new TextReader(text, this.options)\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/reader/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,cAAc,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/reader/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,cAAc,CAAA","sourcesContent":["export * from './BinaryReader'\nexport * from './TextReader'\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A type that has a constructor
|
|
3
|
+
*
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export interface Type<T> extends Function {
|
|
7
|
+
new (...args: any[]): T;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* An abstract class type
|
|
11
|
+
*
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
export interface AbstractType<T> extends Function {
|
|
15
|
+
prototype: T;
|
|
16
|
+
}
|
|
17
|
+
export type Brand<T, B> = T & {
|
|
18
|
+
readonly __brand: B;
|
|
19
|
+
readonly __type?: T;
|
|
20
|
+
};
|
|
21
|
+
export type Unbrand<T> = T extends {
|
|
22
|
+
__type?: infer U;
|
|
23
|
+
} ? U : never;
|
|
24
|
+
export declare function brand<T, B>(value: T): Brand<T, B>;
|
|
25
|
+
export declare function brand<T extends Brand<any, any>>(value: Unbrand<T>): T;
|
|
26
|
+
//# sourceMappingURL=brand.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"brand.d.ts","sourceRoot":"","sources":["../../../../src/types/brand.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,WAAW,IAAI,CAAC,CAAC,CAAE,SAAQ,QAAQ;IACvC,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;CACxB;AAED;;;;GAIG;AACH,MAAM,WAAW,YAAY,CAAC,CAAC,CAAE,SAAQ,QAAQ;IAC/C,SAAS,EAAE,CAAC,CAAA;CACb;AAED,MAAM,MAAM,KAAK,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAC5B,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAA;IACnB,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;CACpB,CAAA;AAED,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,CAAC,SAAS;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC,CAAA;CAAE,GAAG,CAAC,GAAG,KAAK,CAAA;AACnE,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;AAClD,wBAAgB,KAAK,CAAC,CAAC,SAAS,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"brand.js","sourceRoot":"","sources":["../../../../src/types/brand.ts"],"names":[],"mappings":"AA0BA,MAAM,UAAU,KAAK,CAAI,KAAQ;IAC/B,OAAO,KAAK,CAAA;AACd,CAAC","sourcesContent":["/**\n * A type that has a constructor\n *\n * @public\n */\nexport interface Type<T> extends Function {\n new (...args: any[]): T\n}\n\n/**\n * An abstract class type\n *\n * @public\n */\nexport interface AbstractType<T> extends Function {\n prototype: T\n}\n\nexport type Brand<T, B> = T & {\n readonly __brand: B\n readonly __type?: T\n}\n\nexport type Unbrand<T> = T extends { __type?: infer U } ? U : never\nexport function brand<T, B>(value: T): Brand<T, B>\nexport function brand<T extends Brand<any, any>>(value: Unbrand<T>): T\nexport function brand<T>(value: T): T {\n return value\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AACvB,cAAc,YAAY,CAAA;AAC1B,cAAc,QAAQ,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AACvB,cAAc,YAAY,CAAA;AAC1B,cAAc,QAAQ,CAAA","sourcesContent":["export * from './brand'\nexport * from './json-rpc'\nexport * from './rxjs'\n"]}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @public
|
|
3
|
+
*/
|
|
4
|
+
export interface JsonRpcRequest {
|
|
5
|
+
/**
|
|
6
|
+
* The method name to call
|
|
7
|
+
*/
|
|
8
|
+
method: string;
|
|
9
|
+
/**
|
|
10
|
+
* The parameter to be used for the method call
|
|
11
|
+
*/
|
|
12
|
+
params: unknown[] | Record<string, unknown>;
|
|
13
|
+
/**
|
|
14
|
+
* A request id
|
|
15
|
+
*/
|
|
16
|
+
id: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
export interface JsonRpcError {
|
|
22
|
+
/**
|
|
23
|
+
* The error code
|
|
24
|
+
*/
|
|
25
|
+
code: number;
|
|
26
|
+
/**
|
|
27
|
+
* The error message
|
|
28
|
+
*/
|
|
29
|
+
message: string;
|
|
30
|
+
/**
|
|
31
|
+
* The error data
|
|
32
|
+
*/
|
|
33
|
+
data?: unknown;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
38
|
+
export interface JsonRpcResponse<T = unknown> {
|
|
39
|
+
/**
|
|
40
|
+
* A request id
|
|
41
|
+
*/
|
|
42
|
+
id: string;
|
|
43
|
+
/**
|
|
44
|
+
* The result
|
|
45
|
+
*/
|
|
46
|
+
result?: T;
|
|
47
|
+
/**
|
|
48
|
+
* The error
|
|
49
|
+
*/
|
|
50
|
+
error?: JsonRpcError;
|
|
51
|
+
}
|
|
52
|
+
export type JsonRpcDelegate = (task: JsonRpcRequest, transfer: Transferable[]) => void;
|
|
53
|
+
export declare class JsonRpcClient {
|
|
54
|
+
private delegate;
|
|
55
|
+
private pending;
|
|
56
|
+
private idCounter;
|
|
57
|
+
nextId(): string;
|
|
58
|
+
constructor(delegate: JsonRpcDelegate);
|
|
59
|
+
sendRequest<T>(rpc: JsonRpcRequest, transfer?: Transferable[], timeoutMs?: number): Promise<T>;
|
|
60
|
+
handleResponse(response: JsonRpcResponse): void;
|
|
61
|
+
}
|
|
62
|
+
export type JsonRpcWorker = ReturnType<typeof jsonRpcWorker>;
|
|
63
|
+
export declare function jsonRpcWorker({ worker }: {
|
|
64
|
+
worker: Worker;
|
|
65
|
+
}): {
|
|
66
|
+
worker: Worker;
|
|
67
|
+
nextId: () => string;
|
|
68
|
+
request: <T>(rpc: JsonRpcRequest, transfer?: Transferable[], timeoutMs?: number) => Promise<T>;
|
|
69
|
+
};
|
|
70
|
+
export declare function postJsonRpc<T>(target: Window & typeof globalThis, message: JsonRpcRequest | JsonRpcResponse<T> | JsonRpcError): void;
|
|
71
|
+
export declare function jsonRpcHandler(target: Window & typeof globalThis, handler: (request: JsonRpcRequest) => void | any | Promise<any | void>): void;
|
|
72
|
+
//# sourceMappingURL=json-rpc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-rpc.d.ts","sourceRoot":"","sources":["../../../../src/types/json-rpc.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,MAAM,EAAE,MAAM,CAAA;IACd;;OAEG;IACH,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC3C;;OAEG;IACH,EAAE,EAAE,MAAM,CAAA;CACX;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ;;OAEG;IACH,OAAO,EAAE,MAAM,CAAA;IACf;;OAEG;IACH,IAAI,CAAC,EAAE,OAAO,CAAA;CACf;AAED;;GAEG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC,GAAG,OAAO;IAC1C;;OAEG;IACH,EAAE,EAAE,MAAM,CAAA;IACV;;OAEG;IACH,MAAM,CAAC,EAAE,CAAC,CAAA;IACV;;OAEG;IACH,KAAK,CAAC,EAAE,YAAY,CAAA;CACrB;AAqBD,MAAM,MAAM,eAAe,GAAG,CAAC,IAAI,EAAE,cAAc,EAAE,QAAQ,EAAE,YAAY,EAAE,KAAK,IAAI,CAAA;AAEtF,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAiB;IACjC,OAAO,C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