@tutao/tutanota-utils 3.94.0 → 3.94.1
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/dist/ArrayUtils.d.ts +39 -44
- package/dist/ArrayUtils.js +229 -220
- package/dist/AsyncResult.d.ts +15 -17
- package/dist/AsyncResult.js +21 -33
- package/dist/CollectionUtils.d.ts +1 -1
- package/dist/CollectionUtils.js +1 -1
- package/dist/DateUtils.d.ts +18 -18
- package/dist/DateUtils.js +38 -40
- package/dist/Encoding.d.ts +25 -25
- package/dist/Encoding.js +181 -175
- package/dist/LazyLoaded.d.ts +32 -32
- package/dist/LazyLoaded.js +66 -65
- package/dist/MapUtils.d.ts +4 -4
- package/dist/MapUtils.js +25 -24
- package/dist/MathUtils.d.ts +2 -2
- package/dist/MathUtils.js +2 -2
- package/dist/PromiseMap.d.ts +4 -8
- package/dist/PromiseMap.js +50 -49
- package/dist/PromiseUtils.d.ts +16 -19
- package/dist/PromiseUtils.js +76 -72
- package/dist/SortedArray.d.ts +11 -11
- package/dist/SortedArray.js +30 -30
- package/dist/StringUtils.d.ts +14 -14
- package/dist/StringUtils.js +36 -31
- package/dist/TypeRef.d.ts +11 -11
- package/dist/TypeRef.js +15 -15
- package/dist/Utils.d.ts +53 -59
- package/dist/Utils.js +227 -207
- package/dist/index.d.ts +19 -145
- package/dist/index.js +14 -140
- package/dist/tsbuildinfo +1 -1
- package/package.json +3 -2
package/dist/Encoding.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
// TODO rename methods according to their JAVA counterparts (e.g. Uint8Array == bytes, Utf8Uint8Array == bytes...)
|
|
2
2
|
export function uint8ArrayToArrayBuffer(uint8Array) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
if (uint8Array.byteLength === uint8Array.buffer.byteLength) {
|
|
4
|
+
return uint8Array.buffer;
|
|
5
|
+
}
|
|
6
|
+
else {
|
|
7
|
+
return new Uint8Array(uint8Array).buffer; // create a new instance with the correct length, if uint8Array is only a DataView on a longer Array.buffer
|
|
8
|
+
}
|
|
8
9
|
}
|
|
9
10
|
/**
|
|
10
11
|
* Converts a hex coded string into a base64 coded string.
|
|
@@ -13,7 +14,7 @@ export function uint8ArrayToArrayBuffer(uint8Array) {
|
|
|
13
14
|
* @return A base64 encoded string.
|
|
14
15
|
*/
|
|
15
16
|
export function hexToBase64(hex) {
|
|
16
|
-
|
|
17
|
+
return uint8ArrayToBase64(hexToUint8Array(hex));
|
|
17
18
|
}
|
|
18
19
|
/**
|
|
19
20
|
* Converts a base64 coded string into a hex coded string.
|
|
@@ -22,7 +23,7 @@ export function hexToBase64(hex) {
|
|
|
22
23
|
* @return A hex encoded string.
|
|
23
24
|
*/
|
|
24
25
|
export function base64ToHex(base64) {
|
|
25
|
-
|
|
26
|
+
return uint8ArrayToHex(base64ToUint8Array(base64));
|
|
26
27
|
}
|
|
27
28
|
/**
|
|
28
29
|
* Converts a base64 string to a url-conform base64 string. This is used for
|
|
@@ -32,22 +33,22 @@ export function base64ToHex(base64) {
|
|
|
32
33
|
* @return The base64url string.
|
|
33
34
|
*/
|
|
34
35
|
export function base64ToBase64Url(base64) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
let base64url = base64.replace(/\+/g, "-");
|
|
37
|
+
base64url = base64url.replace(/\//g, "_");
|
|
38
|
+
base64url = base64url.replace(/=/g, "");
|
|
39
|
+
return base64url;
|
|
39
40
|
}
|
|
40
41
|
function makeLookup(str) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
const lookup = {};
|
|
43
|
+
for (let i = 0; i < str.length; i++) {
|
|
44
|
+
lookup[str.charAt(i)] = i;
|
|
45
|
+
}
|
|
46
|
+
return lookup;
|
|
46
47
|
}
|
|
47
|
-
const base64Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
|
|
48
|
-
const base64Lookup = makeLookup(base64Alphabet)
|
|
49
|
-
const base64extAlphabet = "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz"
|
|
50
|
-
const base64ExtLookup = makeLookup(base64extAlphabet)
|
|
48
|
+
const base64Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
49
|
+
const base64Lookup = makeLookup(base64Alphabet);
|
|
50
|
+
const base64extAlphabet = "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz";
|
|
51
|
+
const base64ExtLookup = makeLookup(base64extAlphabet);
|
|
51
52
|
/**
|
|
52
53
|
* Converts a base64 string to a base64ext string. Base64ext uses another character set than base64 in order to make it sortable.
|
|
53
54
|
*
|
|
@@ -56,13 +57,13 @@ const base64ExtLookup = makeLookup(base64extAlphabet)
|
|
|
56
57
|
* @return The base64Ext string.
|
|
57
58
|
*/
|
|
58
59
|
export function base64ToBase64Ext(base64) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
60
|
+
base64 = base64.replace(/=/g, "");
|
|
61
|
+
let base64ext = "";
|
|
62
|
+
for (let i = 0; i < base64.length; i++) {
|
|
63
|
+
let index = base64Lookup[base64.charAt(i)];
|
|
64
|
+
base64ext += base64extAlphabet[index];
|
|
65
|
+
}
|
|
66
|
+
return base64ext;
|
|
66
67
|
}
|
|
67
68
|
/**
|
|
68
69
|
* Converts a Base64Ext string to a Base64 string and appends the padding if needed.
|
|
@@ -70,20 +71,22 @@ export function base64ToBase64Ext(base64) {
|
|
|
70
71
|
* @returns The base64 string
|
|
71
72
|
*/
|
|
72
73
|
export function base64ExtToBase64(base64ext) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
74
|
+
let base64 = "";
|
|
75
|
+
for (let i = 0; i < base64ext.length; i++) {
|
|
76
|
+
const index = base64ExtLookup[base64ext.charAt(i)];
|
|
77
|
+
base64 += base64Alphabet[index];
|
|
78
|
+
}
|
|
79
|
+
let padding;
|
|
80
|
+
if (base64.length % 4 === 2) {
|
|
81
|
+
padding = "==";
|
|
82
|
+
}
|
|
83
|
+
else if (base64.length % 4 === 3) {
|
|
84
|
+
padding = "=";
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
padding = "";
|
|
88
|
+
}
|
|
89
|
+
return base64 + padding;
|
|
87
90
|
}
|
|
88
91
|
/**
|
|
89
92
|
* Converts a base64 url string to a "normal" base64 string. This is used for
|
|
@@ -93,77 +96,82 @@ export function base64ExtToBase64(base64ext) {
|
|
|
93
96
|
* @return The base64 string.
|
|
94
97
|
*/
|
|
95
98
|
export function base64UrlToBase64(base64url) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
99
|
+
let base64 = base64url.replace(/-/g, "+");
|
|
100
|
+
base64 = base64.replace(/_/g, "/");
|
|
101
|
+
let nbrOfRemainingChars = base64.length % 4;
|
|
102
|
+
if (nbrOfRemainingChars === 0) {
|
|
103
|
+
return base64;
|
|
104
|
+
}
|
|
105
|
+
else if (nbrOfRemainingChars === 2) {
|
|
106
|
+
return base64 + "==";
|
|
107
|
+
}
|
|
108
|
+
else if (nbrOfRemainingChars === 3) {
|
|
109
|
+
return base64 + "=";
|
|
110
|
+
}
|
|
111
|
+
throw new Error("Illegal base64 string.");
|
|
107
112
|
}
|
|
108
113
|
// just for edge, as it does not support TextEncoder yet
|
|
109
114
|
export function _stringToUtf8Uint8ArrayLegacy(string) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
115
|
+
let fixedString;
|
|
116
|
+
try {
|
|
117
|
+
fixedString = encodeURIComponent(string);
|
|
118
|
+
}
|
|
119
|
+
catch (e) {
|
|
120
|
+
fixedString = encodeURIComponent(_replaceLoneSurrogates(string)); // we filter lone surrogates as trigger URIErrors, otherwise (see https://github.com/tutao/tutanota/issues/618)
|
|
121
|
+
}
|
|
122
|
+
let utf8 = unescape(fixedString);
|
|
123
|
+
let uint8Array = new Uint8Array(utf8.length);
|
|
124
|
+
for (let i = 0; i < utf8.length; i++) {
|
|
125
|
+
uint8Array[i] = utf8.charCodeAt(i);
|
|
126
|
+
}
|
|
127
|
+
return uint8Array;
|
|
122
128
|
}
|
|
123
|
-
const REPLACEMENT_CHAR = "\uFFFD"
|
|
129
|
+
const REPLACEMENT_CHAR = "\uFFFD";
|
|
124
130
|
export function _replaceLoneSurrogates(s) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
131
|
+
if (s == null) {
|
|
132
|
+
return "";
|
|
133
|
+
}
|
|
134
|
+
let result = [];
|
|
135
|
+
for (let i = 0; i < s.length; i++) {
|
|
136
|
+
let code = s.charCodeAt(i);
|
|
137
|
+
let char = s.charAt(i);
|
|
138
|
+
if (0xd800 <= code && code <= 0xdbff) {
|
|
139
|
+
if (s.length === i) {
|
|
140
|
+
// replace high surrogate without following low surrogate
|
|
141
|
+
result.push(REPLACEMENT_CHAR);
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
let next = s.charCodeAt(i + 1);
|
|
145
|
+
if (0xdc00 <= next && next <= 0xdfff) {
|
|
146
|
+
result.push(char);
|
|
147
|
+
result.push(s.charAt(i + 1));
|
|
148
|
+
i++; // valid high and low surrogate, skip next low surrogate check
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
result.push(REPLACEMENT_CHAR);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
else if (0xdc00 <= code && code <= 0xdfff) {
|
|
156
|
+
// replace low surrogate without preceding high surrogate
|
|
157
|
+
result.push(REPLACEMENT_CHAR);
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
result.push(char);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return result.join("");
|
|
154
164
|
}
|
|
155
|
-
const encoder =
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
decode: _utf8Uint8ArrayToStringLegacy,
|
|
166
|
-
}
|
|
165
|
+
const encoder = typeof TextEncoder == "function"
|
|
166
|
+
? new TextEncoder()
|
|
167
|
+
: {
|
|
168
|
+
encode: _stringToUtf8Uint8ArrayLegacy,
|
|
169
|
+
};
|
|
170
|
+
const decoder = typeof TextDecoder == "function"
|
|
171
|
+
? new TextDecoder()
|
|
172
|
+
: {
|
|
173
|
+
decode: _utf8Uint8ArrayToStringLegacy,
|
|
174
|
+
};
|
|
167
175
|
/**
|
|
168
176
|
* Converts a string to a Uint8Array containing a UTF-8 string data.
|
|
169
177
|
*
|
|
@@ -171,16 +179,16 @@ const decoder =
|
|
|
171
179
|
* @return The array.
|
|
172
180
|
*/
|
|
173
181
|
export function stringToUtf8Uint8Array(string) {
|
|
174
|
-
|
|
182
|
+
return encoder.encode(string);
|
|
175
183
|
}
|
|
176
184
|
// just for edge, as it does not support TextDecoder yet
|
|
177
185
|
export function _utf8Uint8ArrayToStringLegacy(uint8Array) {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
186
|
+
let stringArray = [];
|
|
187
|
+
stringArray.length = uint8Array.length;
|
|
188
|
+
for (let i = 0; i < uint8Array.length; i++) {
|
|
189
|
+
stringArray[i] = String.fromCharCode(uint8Array[i]);
|
|
190
|
+
}
|
|
191
|
+
return decodeURIComponent(escape(stringArray.join("")));
|
|
184
192
|
}
|
|
185
193
|
/**
|
|
186
194
|
* Converts an Uint8Array containing UTF-8 string data into a string.
|
|
@@ -189,23 +197,23 @@ export function _utf8Uint8ArrayToStringLegacy(uint8Array) {
|
|
|
189
197
|
* @return The string.
|
|
190
198
|
*/
|
|
191
199
|
export function utf8Uint8ArrayToString(uint8Array) {
|
|
192
|
-
|
|
200
|
+
return decoder.decode(uint8Array);
|
|
193
201
|
}
|
|
194
202
|
export function hexToUint8Array(hex) {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
203
|
+
let bufView = new Uint8Array(hex.length / 2);
|
|
204
|
+
for (let i = 0; i < bufView.byteLength; i++) {
|
|
205
|
+
bufView[i] = parseInt(hex.substring(i * 2, i * 2 + 2), 16);
|
|
206
|
+
}
|
|
207
|
+
return bufView;
|
|
200
208
|
}
|
|
201
|
-
const hexDigits = "0123456789abcdef"
|
|
209
|
+
const hexDigits = "0123456789abcdef";
|
|
202
210
|
export function uint8ArrayToHex(uint8Array) {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
211
|
+
let hex = "";
|
|
212
|
+
for (let i = 0; i < uint8Array.byteLength; i++) {
|
|
213
|
+
let value = uint8Array[i];
|
|
214
|
+
hex += hexDigits[value >> 4] + hexDigits[value & 15];
|
|
215
|
+
}
|
|
216
|
+
return hex;
|
|
209
217
|
}
|
|
210
218
|
/**
|
|
211
219
|
* Converts an Uint8Array to a Base64 encoded string.
|
|
@@ -214,23 +222,23 @@ export function uint8ArrayToHex(uint8Array) {
|
|
|
214
222
|
* @return The Base64 encoded string.
|
|
215
223
|
*/
|
|
216
224
|
export function uint8ArrayToBase64(bytes) {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
225
|
+
if (bytes.length < 512) {
|
|
226
|
+
// Apply fails on big arrays fairly often. We tried it with 60000 but if you're already
|
|
227
|
+
// deep in the stack than we cannot allocate such a big argument array.
|
|
228
|
+
return btoa(String.fromCharCode(...bytes));
|
|
229
|
+
}
|
|
230
|
+
let binary = "";
|
|
231
|
+
const len = bytes.byteLength;
|
|
232
|
+
for (let i = 0; i < len; i++) {
|
|
233
|
+
binary += String.fromCharCode(bytes[i]);
|
|
234
|
+
}
|
|
235
|
+
return btoa(binary);
|
|
228
236
|
}
|
|
229
237
|
export function int8ArrayToBase64(bytes) {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
238
|
+
// Values 0 to 127 are the same for signed and unsigned bytes
|
|
239
|
+
// and -128 to -1 are mapped to the same chars as 128 to 255.
|
|
240
|
+
let converted = new Uint8Array(bytes);
|
|
241
|
+
return uint8ArrayToBase64(converted);
|
|
234
242
|
}
|
|
235
243
|
/**
|
|
236
244
|
* Converts a base64 encoded string to a Uint8Array.
|
|
@@ -239,15 +247,15 @@ export function int8ArrayToBase64(bytes) {
|
|
|
239
247
|
* @return The bytes.
|
|
240
248
|
*/
|
|
241
249
|
export function base64ToUint8Array(base64) {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
250
|
+
if (base64.length % 4 !== 0) {
|
|
251
|
+
throw new Error(`invalid base64 length: ${base64} (${base64.length})`);
|
|
252
|
+
}
|
|
253
|
+
const binaryString = atob(base64);
|
|
254
|
+
const result = new Uint8Array(binaryString.length);
|
|
255
|
+
for (let i = 0; i < binaryString.length; i++) {
|
|
256
|
+
result[i] = binaryString.charCodeAt(i);
|
|
257
|
+
}
|
|
258
|
+
return result;
|
|
251
259
|
}
|
|
252
260
|
/**
|
|
253
261
|
* Converts a Uint8Array containing string data into a string, given the charset the data is in.
|
|
@@ -257,8 +265,8 @@ export function base64ToUint8Array(base64) {
|
|
|
257
265
|
* @return The string
|
|
258
266
|
*/
|
|
259
267
|
export function uint8ArrayToString(charset, bytes) {
|
|
260
|
-
|
|
261
|
-
|
|
268
|
+
const decoder = new TextDecoder(charset);
|
|
269
|
+
return decoder.decode(bytes);
|
|
262
270
|
}
|
|
263
271
|
/**
|
|
264
272
|
* Decodes a quoted-printable piece of text in a given charset.
|
|
@@ -270,31 +278,29 @@ export function uint8ArrayToString(charset, bytes) {
|
|
|
270
278
|
* @returns The text as a JavaScript string
|
|
271
279
|
*/
|
|
272
280
|
export function decodeQuotedPrintable(charset, input) {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
})
|
|
293
|
-
)
|
|
281
|
+
return (input // https://tools.ietf.org/html/rfc2045#section-6.7, rule 3:
|
|
282
|
+
// “Therefore, when decoding a `Quoted-Printable` body, any trailing white
|
|
283
|
+
// space on a line must be deleted, as it will necessarily have been added
|
|
284
|
+
// by intermediate transport agents.”
|
|
285
|
+
.replace(/[\t\x20]$/gm, "") // Remove hard line breaks preceded by `=`. Proper `Quoted-Printable`-
|
|
286
|
+
// encoded data only contains CRLF line endings, but for compatibility
|
|
287
|
+
// reasons we support separate CR and LF too.
|
|
288
|
+
.replace(/=(?:\r\n?|\n|$)/g, "") // Decode escape sequences of the form `=XX` where `XX` is any
|
|
289
|
+
// combination of two hexidecimal digits. For optimal compatibility,
|
|
290
|
+
// lowercase hexadecimal digits are supported as well. See
|
|
291
|
+
// https://tools.ietf.org/html/rfc2045#section-6.7, note 1.
|
|
292
|
+
.replace(/(=([a-fA-F0-9]{2}))+/g, match => {
|
|
293
|
+
const hexValues = match.split(/=/);
|
|
294
|
+
// splitting on '=' is convenient, but adds an empty string at the start due to the first byte
|
|
295
|
+
hexValues.shift();
|
|
296
|
+
const intArray = hexValues.map(char => parseInt(char, 16));
|
|
297
|
+
const bytes = Uint8Array.from(intArray);
|
|
298
|
+
return uint8ArrayToString(charset, bytes);
|
|
299
|
+
}));
|
|
294
300
|
}
|
|
295
301
|
export function decodeBase64(charset, input) {
|
|
296
|
-
|
|
302
|
+
return uint8ArrayToString(charset, base64ToUint8Array(input));
|
|
297
303
|
}
|
|
298
304
|
export function stringToBase64(str) {
|
|
299
|
-
|
|
305
|
+
return uint8ArrayToBase64(stringToUtf8Uint8Array(str));
|
|
300
306
|
}
|
package/dist/LazyLoaded.d.ts
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
import type { lazyAsync } from "./Utils.js"
|
|
1
|
+
import type { lazyAsync } from "./Utils.js";
|
|
2
2
|
/**
|
|
3
3
|
* A wrapper for an object that shall be lazy loaded asynchronously. If loading the object is triggered in parallel (getAsync()) the object is actually only loaded once but returned to all calls of getAsync().
|
|
4
4
|
* If the object was loaded once it is not loaded again.
|
|
5
5
|
*/
|
|
6
6
|
export declare class LazyLoaded<T> {
|
|
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
|
-
|
|
7
|
+
_isLoaded: boolean;
|
|
8
|
+
_loadingPromise: Promise<T> | null;
|
|
9
|
+
_loadedObject: T | null;
|
|
10
|
+
_loadFunction: lazyAsync<T>;
|
|
11
|
+
/**
|
|
12
|
+
* @param loadFunction The function that actually loads the object as soon as getAsync() is called the first time.
|
|
13
|
+
* @param defaultValue The value that shall be returned by getSync() or getLoaded() as long as the object is not loaded yet.
|
|
14
|
+
*/
|
|
15
|
+
constructor(loadFunction: lazyAsync<T>, defaultValue?: T);
|
|
16
|
+
load(): this;
|
|
17
|
+
isLoaded(): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Loads the object if it is not loaded yet. May be called in parallel and takes care that the load function is only called once.
|
|
20
|
+
*/
|
|
21
|
+
getAsync(): Promise<T>;
|
|
22
|
+
/**
|
|
23
|
+
* Returns null if the object is not loaded yet.
|
|
24
|
+
*/
|
|
25
|
+
getSync(): T | null;
|
|
26
|
+
/**
|
|
27
|
+
* Only call this function if you know that the object is already loaded.
|
|
28
|
+
*/
|
|
29
|
+
getLoaded(): T;
|
|
30
|
+
/**
|
|
31
|
+
* Removes the currently loaded object, so it will be loaded again with the next getAsync() call. Does not set any default value.
|
|
32
|
+
*/
|
|
33
|
+
reset(): void;
|
|
34
|
+
/**
|
|
35
|
+
* Loads the object again and replaces the current one
|
|
36
|
+
*/
|
|
37
|
+
reload(): Promise<T>;
|
|
38
38
|
}
|