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