posthog-js-lite 0.0.5 → 2.0.0-alpha1
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/README.md +2 -24
- package/index.ts +5 -0
- package/lib/index.cjs.js +1473 -0
- package/lib/index.cjs.js.map +1 -0
- package/lib/index.d.ts +177 -0
- package/lib/index.esm.js +1468 -0
- package/lib/index.esm.js.map +1 -0
- package/lib/node_modules/tslib/tslib.es6.d.ts +35 -0
- package/lib/posthog-core/src/eventemitter.d.ts +8 -0
- package/lib/posthog-core/src/index.d.ts +84 -0
- package/lib/posthog-core/src/lz-string.d.ts +8 -0
- package/lib/posthog-core/src/types.d.ts +68 -0
- package/lib/posthog-core/src/utils.d.ts +13 -0
- package/lib/posthog-web/index.d.ts +3 -0
- package/lib/posthog-web/src/context.d.ts +1 -0
- package/lib/posthog-web/src/posthog-web.d.ts +18 -0
- package/lib/posthog-web/src/storage.d.ts +12 -0
- package/package.json +5 -42
- package/src/context.ts +168 -0
- package/src/posthog-web.ts +70 -0
- package/src/storage.ts +115 -0
- package/test/posthog-web.spec.ts +32 -0
- package/tsconfig.json +4 -17
- package/.prettierrc +0 -7
- package/babel.config.js +0 -4
- package/dist/babel.config.d.ts +0 -5
- package/dist/babel.config.js +0 -5
- package/dist/babel.config.js.map +0 -1
- package/dist/package.json +0 -44
- package/dist/src/__tests__/index.d.ts +0 -1
- package/dist/src/__tests__/index.js +0 -48
- package/dist/src/__tests__/index.js.map +0 -1
- package/dist/src/index.d.ts +0 -19
- package/dist/src/index.js +0 -109
- package/dist/src/index.js.map +0 -1
- package/dist/src/targets/browser.d.ts +0 -19
- package/dist/src/targets/browser.js +0 -10
- package/dist/src/targets/browser.js.map +0 -1
- package/dist/src/targets/node.d.ts +0 -19
- package/dist/src/targets/node.js +0 -9
- package/dist/src/targets/node.js.map +0 -1
- package/dist/src/types.d.ts +0 -20
- package/dist/src/types.js +0 -3
- package/dist/src/types.js.map +0 -1
- package/dist/src/utils/context.d.ts +0 -1
- package/dist/src/utils/context.js +0 -187
- package/dist/src/utils/context.js.map +0 -1
- package/dist/src/utils/lz-string.d.ts +0 -14
- package/dist/src/utils/lz-string.js +0 -467
- package/dist/src/utils/lz-string.js.map +0 -1
- package/dist/src/utils/utils.d.ts +0 -3
- package/dist/src/utils/utils.js +0 -29
- package/dist/src/utils/utils.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -2454
- package/src/__tests__/index.js +0 -47
- package/src/index.ts +0 -127
- package/src/targets/browser.ts +0 -17
- package/src/targets/node.ts +0 -6
- package/src/types.ts +0 -22
- package/src/utils/context.ts +0 -163
- package/src/utils/lz-string.js +0 -511
- package/src/utils/utils.ts +0 -28
package/src/utils/lz-string.js
DELETED
|
@@ -1,511 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2013 Pieroxy <pieroxy@pieroxy.net>
|
|
2
|
-
// This work is free. You can redistribute it and/or modify it
|
|
3
|
-
// under the terms of the WTFPL, Version 2
|
|
4
|
-
// For more information see LICENSE.txt or http://www.wtfpl.net/
|
|
5
|
-
//
|
|
6
|
-
// For more information, the home page:
|
|
7
|
-
// http://pieroxy.net/blog/pages/lz-string/testing.html
|
|
8
|
-
//
|
|
9
|
-
// LZ-based compression algorithm, version 1.4.4
|
|
10
|
-
|
|
11
|
-
// private property
|
|
12
|
-
var f = String.fromCharCode
|
|
13
|
-
var keyStrBase64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
|
|
14
|
-
var keyStrUriSafe = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$'
|
|
15
|
-
var baseReverseDic = {}
|
|
16
|
-
|
|
17
|
-
function getBaseValue(alphabet, character) {
|
|
18
|
-
if (!baseReverseDic[alphabet]) {
|
|
19
|
-
baseReverseDic[alphabet] = {}
|
|
20
|
-
for (var i = 0; i < alphabet.length; i++) {
|
|
21
|
-
baseReverseDic[alphabet][alphabet.charAt(i)] = i
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return baseReverseDic[alphabet][character]
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export var LZString = {
|
|
28
|
-
compressToBase64: function (input) {
|
|
29
|
-
if (input == null) return ''
|
|
30
|
-
var res = LZString._compress(input, 6, function (a) {
|
|
31
|
-
return keyStrBase64.charAt(a)
|
|
32
|
-
})
|
|
33
|
-
switch (
|
|
34
|
-
res.length % 4 // To produce valid Base64
|
|
35
|
-
) {
|
|
36
|
-
default: // When could this happen ?
|
|
37
|
-
case 0:
|
|
38
|
-
return res
|
|
39
|
-
case 1:
|
|
40
|
-
return res + '==='
|
|
41
|
-
case 2:
|
|
42
|
-
return res + '=='
|
|
43
|
-
case 3:
|
|
44
|
-
return res + '='
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
|
|
48
|
-
decompressFromBase64: function (input) {
|
|
49
|
-
if (input == null) return ''
|
|
50
|
-
if (input == '') return null
|
|
51
|
-
return LZString._decompress(input.length, 32, function (index) {
|
|
52
|
-
return getBaseValue(keyStrBase64, input.charAt(index))
|
|
53
|
-
})
|
|
54
|
-
},
|
|
55
|
-
|
|
56
|
-
compressToUTF16: function (input) {
|
|
57
|
-
if (input == null) return ''
|
|
58
|
-
return (
|
|
59
|
-
LZString._compress(input, 15, function (a) {
|
|
60
|
-
return f(a + 32)
|
|
61
|
-
}) + ' '
|
|
62
|
-
)
|
|
63
|
-
},
|
|
64
|
-
|
|
65
|
-
decompressFromUTF16: function (compressed) {
|
|
66
|
-
if (compressed == null) return ''
|
|
67
|
-
if (compressed == '') return null
|
|
68
|
-
return LZString._decompress(compressed.length, 16384, function (index) {
|
|
69
|
-
return compressed.charCodeAt(index) - 32
|
|
70
|
-
})
|
|
71
|
-
},
|
|
72
|
-
|
|
73
|
-
//compress into uint8array (UCS-2 big endian format)
|
|
74
|
-
compressToUint8Array: function (uncompressed) {
|
|
75
|
-
var compressed = LZString.compress(uncompressed)
|
|
76
|
-
var buf = new Uint8Array(compressed.length * 2) // 2 bytes per character
|
|
77
|
-
|
|
78
|
-
for (var i = 0, TotalLen = compressed.length; i < TotalLen; i++) {
|
|
79
|
-
var current_value = compressed.charCodeAt(i)
|
|
80
|
-
buf[i * 2] = current_value >>> 8
|
|
81
|
-
buf[i * 2 + 1] = current_value % 256
|
|
82
|
-
}
|
|
83
|
-
return buf
|
|
84
|
-
},
|
|
85
|
-
|
|
86
|
-
//decompress from uint8array (UCS-2 big endian format)
|
|
87
|
-
decompressFromUint8Array: function (compressed) {
|
|
88
|
-
if (compressed === null || compressed === undefined) {
|
|
89
|
-
return LZString.decompress(compressed)
|
|
90
|
-
} else {
|
|
91
|
-
var buf = new Array(compressed.length / 2) // 2 bytes per character
|
|
92
|
-
for (var i = 0, TotalLen = buf.length; i < TotalLen; i++) {
|
|
93
|
-
buf[i] = compressed[i * 2] * 256 + compressed[i * 2 + 1]
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
var result = []
|
|
97
|
-
buf.forEach(function (c) {
|
|
98
|
-
result.push(f(c))
|
|
99
|
-
})
|
|
100
|
-
return LZString.decompress(result.join(''))
|
|
101
|
-
}
|
|
102
|
-
},
|
|
103
|
-
|
|
104
|
-
//compress into a string that is already URI encoded
|
|
105
|
-
compressToEncodedURIComponent: function (input) {
|
|
106
|
-
if (input == null) return ''
|
|
107
|
-
return LZString._compress(input, 6, function (a) {
|
|
108
|
-
return keyStrUriSafe.charAt(a)
|
|
109
|
-
})
|
|
110
|
-
},
|
|
111
|
-
|
|
112
|
-
//decompress from an output of compressToEncodedURIComponent
|
|
113
|
-
decompressFromEncodedURIComponent: function (input) {
|
|
114
|
-
if (input == null) return ''
|
|
115
|
-
if (input == '') return null
|
|
116
|
-
input = input.replace(/ /g, '+')
|
|
117
|
-
return LZString._decompress(input.length, 32, function (index) {
|
|
118
|
-
return getBaseValue(keyStrUriSafe, input.charAt(index))
|
|
119
|
-
})
|
|
120
|
-
},
|
|
121
|
-
|
|
122
|
-
compress: function (uncompressed) {
|
|
123
|
-
return LZString._compress(uncompressed, 16, function (a) {
|
|
124
|
-
return f(a)
|
|
125
|
-
})
|
|
126
|
-
},
|
|
127
|
-
_compress: function (uncompressed, bitsPerChar, getCharFromInt) {
|
|
128
|
-
if (uncompressed == null) return ''
|
|
129
|
-
var i,
|
|
130
|
-
value,
|
|
131
|
-
context_dictionary = {},
|
|
132
|
-
context_dictionaryToCreate = {},
|
|
133
|
-
context_c = '',
|
|
134
|
-
context_wc = '',
|
|
135
|
-
context_w = '',
|
|
136
|
-
context_enlargeIn = 2, // Compensate for the first entry which should not count
|
|
137
|
-
context_dictSize = 3,
|
|
138
|
-
context_numBits = 2,
|
|
139
|
-
context_data = [],
|
|
140
|
-
context_data_val = 0,
|
|
141
|
-
context_data_position = 0,
|
|
142
|
-
ii
|
|
143
|
-
|
|
144
|
-
for (ii = 0; ii < uncompressed.length; ii += 1) {
|
|
145
|
-
context_c = uncompressed.charAt(ii)
|
|
146
|
-
if (!Object.prototype.hasOwnProperty.call(context_dictionary, context_c)) {
|
|
147
|
-
context_dictionary[context_c] = context_dictSize++
|
|
148
|
-
context_dictionaryToCreate[context_c] = true
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
context_wc = context_w + context_c
|
|
152
|
-
if (Object.prototype.hasOwnProperty.call(context_dictionary, context_wc)) {
|
|
153
|
-
context_w = context_wc
|
|
154
|
-
} else {
|
|
155
|
-
if (Object.prototype.hasOwnProperty.call(context_dictionaryToCreate, context_w)) {
|
|
156
|
-
if (context_w.charCodeAt(0) < 256) {
|
|
157
|
-
for (i = 0; i < context_numBits; i++) {
|
|
158
|
-
context_data_val = context_data_val << 1
|
|
159
|
-
if (context_data_position == bitsPerChar - 1) {
|
|
160
|
-
context_data_position = 0
|
|
161
|
-
context_data.push(getCharFromInt(context_data_val))
|
|
162
|
-
context_data_val = 0
|
|
163
|
-
} else {
|
|
164
|
-
context_data_position++
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
value = context_w.charCodeAt(0)
|
|
168
|
-
for (i = 0; i < 8; i++) {
|
|
169
|
-
context_data_val = (context_data_val << 1) | (value & 1)
|
|
170
|
-
if (context_data_position == bitsPerChar - 1) {
|
|
171
|
-
context_data_position = 0
|
|
172
|
-
context_data.push(getCharFromInt(context_data_val))
|
|
173
|
-
context_data_val = 0
|
|
174
|
-
} else {
|
|
175
|
-
context_data_position++
|
|
176
|
-
}
|
|
177
|
-
value = value >> 1
|
|
178
|
-
}
|
|
179
|
-
} else {
|
|
180
|
-
value = 1
|
|
181
|
-
for (i = 0; i < context_numBits; i++) {
|
|
182
|
-
context_data_val = (context_data_val << 1) | value
|
|
183
|
-
if (context_data_position == bitsPerChar - 1) {
|
|
184
|
-
context_data_position = 0
|
|
185
|
-
context_data.push(getCharFromInt(context_data_val))
|
|
186
|
-
context_data_val = 0
|
|
187
|
-
} else {
|
|
188
|
-
context_data_position++
|
|
189
|
-
}
|
|
190
|
-
value = 0
|
|
191
|
-
}
|
|
192
|
-
value = context_w.charCodeAt(0)
|
|
193
|
-
for (i = 0; i < 16; i++) {
|
|
194
|
-
context_data_val = (context_data_val << 1) | (value & 1)
|
|
195
|
-
if (context_data_position == bitsPerChar - 1) {
|
|
196
|
-
context_data_position = 0
|
|
197
|
-
context_data.push(getCharFromInt(context_data_val))
|
|
198
|
-
context_data_val = 0
|
|
199
|
-
} else {
|
|
200
|
-
context_data_position++
|
|
201
|
-
}
|
|
202
|
-
value = value >> 1
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
context_enlargeIn--
|
|
206
|
-
if (context_enlargeIn == 0) {
|
|
207
|
-
context_enlargeIn = Math.pow(2, context_numBits)
|
|
208
|
-
context_numBits++
|
|
209
|
-
}
|
|
210
|
-
delete context_dictionaryToCreate[context_w]
|
|
211
|
-
} else {
|
|
212
|
-
value = context_dictionary[context_w]
|
|
213
|
-
for (i = 0; i < context_numBits; i++) {
|
|
214
|
-
context_data_val = (context_data_val << 1) | (value & 1)
|
|
215
|
-
if (context_data_position == bitsPerChar - 1) {
|
|
216
|
-
context_data_position = 0
|
|
217
|
-
context_data.push(getCharFromInt(context_data_val))
|
|
218
|
-
context_data_val = 0
|
|
219
|
-
} else {
|
|
220
|
-
context_data_position++
|
|
221
|
-
}
|
|
222
|
-
value = value >> 1
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
context_enlargeIn--
|
|
226
|
-
if (context_enlargeIn == 0) {
|
|
227
|
-
context_enlargeIn = Math.pow(2, context_numBits)
|
|
228
|
-
context_numBits++
|
|
229
|
-
}
|
|
230
|
-
// Add wc to the dictionary.
|
|
231
|
-
context_dictionary[context_wc] = context_dictSize++
|
|
232
|
-
context_w = String(context_c)
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
// Output the code for w.
|
|
237
|
-
if (context_w !== '') {
|
|
238
|
-
if (Object.prototype.hasOwnProperty.call(context_dictionaryToCreate, context_w)) {
|
|
239
|
-
if (context_w.charCodeAt(0) < 256) {
|
|
240
|
-
for (i = 0; i < context_numBits; i++) {
|
|
241
|
-
context_data_val = context_data_val << 1
|
|
242
|
-
if (context_data_position == bitsPerChar - 1) {
|
|
243
|
-
context_data_position = 0
|
|
244
|
-
context_data.push(getCharFromInt(context_data_val))
|
|
245
|
-
context_data_val = 0
|
|
246
|
-
} else {
|
|
247
|
-
context_data_position++
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
value = context_w.charCodeAt(0)
|
|
251
|
-
for (i = 0; i < 8; i++) {
|
|
252
|
-
context_data_val = (context_data_val << 1) | (value & 1)
|
|
253
|
-
if (context_data_position == bitsPerChar - 1) {
|
|
254
|
-
context_data_position = 0
|
|
255
|
-
context_data.push(getCharFromInt(context_data_val))
|
|
256
|
-
context_data_val = 0
|
|
257
|
-
} else {
|
|
258
|
-
context_data_position++
|
|
259
|
-
}
|
|
260
|
-
value = value >> 1
|
|
261
|
-
}
|
|
262
|
-
} else {
|
|
263
|
-
value = 1
|
|
264
|
-
for (i = 0; i < context_numBits; i++) {
|
|
265
|
-
context_data_val = (context_data_val << 1) | value
|
|
266
|
-
if (context_data_position == bitsPerChar - 1) {
|
|
267
|
-
context_data_position = 0
|
|
268
|
-
context_data.push(getCharFromInt(context_data_val))
|
|
269
|
-
context_data_val = 0
|
|
270
|
-
} else {
|
|
271
|
-
context_data_position++
|
|
272
|
-
}
|
|
273
|
-
value = 0
|
|
274
|
-
}
|
|
275
|
-
value = context_w.charCodeAt(0)
|
|
276
|
-
for (i = 0; i < 16; i++) {
|
|
277
|
-
context_data_val = (context_data_val << 1) | (value & 1)
|
|
278
|
-
if (context_data_position == bitsPerChar - 1) {
|
|
279
|
-
context_data_position = 0
|
|
280
|
-
context_data.push(getCharFromInt(context_data_val))
|
|
281
|
-
context_data_val = 0
|
|
282
|
-
} else {
|
|
283
|
-
context_data_position++
|
|
284
|
-
}
|
|
285
|
-
value = value >> 1
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
context_enlargeIn--
|
|
289
|
-
if (context_enlargeIn == 0) {
|
|
290
|
-
context_enlargeIn = Math.pow(2, context_numBits)
|
|
291
|
-
context_numBits++
|
|
292
|
-
}
|
|
293
|
-
delete context_dictionaryToCreate[context_w]
|
|
294
|
-
} else {
|
|
295
|
-
value = context_dictionary[context_w]
|
|
296
|
-
for (i = 0; i < context_numBits; i++) {
|
|
297
|
-
context_data_val = (context_data_val << 1) | (value & 1)
|
|
298
|
-
if (context_data_position == bitsPerChar - 1) {
|
|
299
|
-
context_data_position = 0
|
|
300
|
-
context_data.push(getCharFromInt(context_data_val))
|
|
301
|
-
context_data_val = 0
|
|
302
|
-
} else {
|
|
303
|
-
context_data_position++
|
|
304
|
-
}
|
|
305
|
-
value = value >> 1
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
context_enlargeIn--
|
|
309
|
-
if (context_enlargeIn == 0) {
|
|
310
|
-
context_enlargeIn = Math.pow(2, context_numBits)
|
|
311
|
-
context_numBits++
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
// Mark the end of the stream
|
|
316
|
-
value = 2
|
|
317
|
-
for (i = 0; i < context_numBits; i++) {
|
|
318
|
-
context_data_val = (context_data_val << 1) | (value & 1)
|
|
319
|
-
if (context_data_position == bitsPerChar - 1) {
|
|
320
|
-
context_data_position = 0
|
|
321
|
-
context_data.push(getCharFromInt(context_data_val))
|
|
322
|
-
context_data_val = 0
|
|
323
|
-
} else {
|
|
324
|
-
context_data_position++
|
|
325
|
-
}
|
|
326
|
-
value = value >> 1
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
// Flush the last char
|
|
330
|
-
while (true) {
|
|
331
|
-
context_data_val = context_data_val << 1
|
|
332
|
-
if (context_data_position == bitsPerChar - 1) {
|
|
333
|
-
context_data.push(getCharFromInt(context_data_val))
|
|
334
|
-
break
|
|
335
|
-
} else context_data_position++
|
|
336
|
-
}
|
|
337
|
-
return context_data.join('')
|
|
338
|
-
},
|
|
339
|
-
|
|
340
|
-
decompress: function (compressed) {
|
|
341
|
-
if (compressed == null) return ''
|
|
342
|
-
if (compressed == '') return null
|
|
343
|
-
return LZString._decompress(compressed.length, 32768, function (index) {
|
|
344
|
-
return compressed.charCodeAt(index)
|
|
345
|
-
})
|
|
346
|
-
},
|
|
347
|
-
|
|
348
|
-
_decompress: function (length, resetValue, getNextValue) {
|
|
349
|
-
var dictionary = [],
|
|
350
|
-
next,
|
|
351
|
-
enlargeIn = 4,
|
|
352
|
-
dictSize = 4,
|
|
353
|
-
numBits = 3,
|
|
354
|
-
entry = '',
|
|
355
|
-
result = [],
|
|
356
|
-
i,
|
|
357
|
-
w,
|
|
358
|
-
bits,
|
|
359
|
-
resb,
|
|
360
|
-
maxpower,
|
|
361
|
-
power,
|
|
362
|
-
c,
|
|
363
|
-
data = { val: getNextValue(0), position: resetValue, index: 1 }
|
|
364
|
-
|
|
365
|
-
for (i = 0; i < 3; i += 1) {
|
|
366
|
-
dictionary[i] = i
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
bits = 0
|
|
370
|
-
maxpower = Math.pow(2, 2)
|
|
371
|
-
power = 1
|
|
372
|
-
while (power != maxpower) {
|
|
373
|
-
resb = data.val & data.position
|
|
374
|
-
data.position >>= 1
|
|
375
|
-
if (data.position == 0) {
|
|
376
|
-
data.position = resetValue
|
|
377
|
-
data.val = getNextValue(data.index++)
|
|
378
|
-
}
|
|
379
|
-
bits |= (resb > 0 ? 1 : 0) * power
|
|
380
|
-
power <<= 1
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
switch ((next = bits)) {
|
|
384
|
-
case 0:
|
|
385
|
-
bits = 0
|
|
386
|
-
maxpower = Math.pow(2, 8)
|
|
387
|
-
power = 1
|
|
388
|
-
while (power != maxpower) {
|
|
389
|
-
resb = data.val & data.position
|
|
390
|
-
data.position >>= 1
|
|
391
|
-
if (data.position == 0) {
|
|
392
|
-
data.position = resetValue
|
|
393
|
-
data.val = getNextValue(data.index++)
|
|
394
|
-
}
|
|
395
|
-
bits |= (resb > 0 ? 1 : 0) * power
|
|
396
|
-
power <<= 1
|
|
397
|
-
}
|
|
398
|
-
c = f(bits)
|
|
399
|
-
break
|
|
400
|
-
case 1:
|
|
401
|
-
bits = 0
|
|
402
|
-
maxpower = Math.pow(2, 16)
|
|
403
|
-
power = 1
|
|
404
|
-
while (power != maxpower) {
|
|
405
|
-
resb = data.val & data.position
|
|
406
|
-
data.position >>= 1
|
|
407
|
-
if (data.position == 0) {
|
|
408
|
-
data.position = resetValue
|
|
409
|
-
data.val = getNextValue(data.index++)
|
|
410
|
-
}
|
|
411
|
-
bits |= (resb > 0 ? 1 : 0) * power
|
|
412
|
-
power <<= 1
|
|
413
|
-
}
|
|
414
|
-
c = f(bits)
|
|
415
|
-
break
|
|
416
|
-
case 2:
|
|
417
|
-
return ''
|
|
418
|
-
}
|
|
419
|
-
dictionary[3] = c
|
|
420
|
-
w = c
|
|
421
|
-
result.push(c)
|
|
422
|
-
while (true) {
|
|
423
|
-
if (data.index > length) {
|
|
424
|
-
return ''
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
bits = 0
|
|
428
|
-
maxpower = Math.pow(2, numBits)
|
|
429
|
-
power = 1
|
|
430
|
-
while (power != maxpower) {
|
|
431
|
-
resb = data.val & data.position
|
|
432
|
-
data.position >>= 1
|
|
433
|
-
if (data.position == 0) {
|
|
434
|
-
data.position = resetValue
|
|
435
|
-
data.val = getNextValue(data.index++)
|
|
436
|
-
}
|
|
437
|
-
bits |= (resb > 0 ? 1 : 0) * power
|
|
438
|
-
power <<= 1
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
switch ((c = bits)) {
|
|
442
|
-
case 0:
|
|
443
|
-
bits = 0
|
|
444
|
-
maxpower = Math.pow(2, 8)
|
|
445
|
-
power = 1
|
|
446
|
-
while (power != maxpower) {
|
|
447
|
-
resb = data.val & data.position
|
|
448
|
-
data.position >>= 1
|
|
449
|
-
if (data.position == 0) {
|
|
450
|
-
data.position = resetValue
|
|
451
|
-
data.val = getNextValue(data.index++)
|
|
452
|
-
}
|
|
453
|
-
bits |= (resb > 0 ? 1 : 0) * power
|
|
454
|
-
power <<= 1
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
dictionary[dictSize++] = f(bits)
|
|
458
|
-
c = dictSize - 1
|
|
459
|
-
enlargeIn--
|
|
460
|
-
break
|
|
461
|
-
case 1:
|
|
462
|
-
bits = 0
|
|
463
|
-
maxpower = Math.pow(2, 16)
|
|
464
|
-
power = 1
|
|
465
|
-
while (power != maxpower) {
|
|
466
|
-
resb = data.val & data.position
|
|
467
|
-
data.position >>= 1
|
|
468
|
-
if (data.position == 0) {
|
|
469
|
-
data.position = resetValue
|
|
470
|
-
data.val = getNextValue(data.index++)
|
|
471
|
-
}
|
|
472
|
-
bits |= (resb > 0 ? 1 : 0) * power
|
|
473
|
-
power <<= 1
|
|
474
|
-
}
|
|
475
|
-
dictionary[dictSize++] = f(bits)
|
|
476
|
-
c = dictSize - 1
|
|
477
|
-
enlargeIn--
|
|
478
|
-
break
|
|
479
|
-
case 2:
|
|
480
|
-
return result.join('')
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
if (enlargeIn == 0) {
|
|
484
|
-
enlargeIn = Math.pow(2, numBits)
|
|
485
|
-
numBits++
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
if (dictionary[c]) {
|
|
489
|
-
entry = dictionary[c]
|
|
490
|
-
} else {
|
|
491
|
-
if (c === dictSize) {
|
|
492
|
-
entry = w + w.charAt(0)
|
|
493
|
-
} else {
|
|
494
|
-
return null
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
result.push(entry)
|
|
498
|
-
|
|
499
|
-
// Add w+entry[0] to the dictionary.
|
|
500
|
-
dictionary[dictSize++] = w + entry.charAt(0)
|
|
501
|
-
enlargeIn--
|
|
502
|
-
|
|
503
|
-
w = entry
|
|
504
|
-
|
|
505
|
-
if (enlargeIn == 0) {
|
|
506
|
-
enlargeIn = Math.pow(2, numBits)
|
|
507
|
-
numBits++
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
},
|
|
511
|
-
}
|
package/src/utils/utils.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
// https://stackoverflow.com/a/8809472
|
|
2
|
-
export function generateUUID(globalThis: any): string {
|
|
3
|
-
// Public Domain/MIT
|
|
4
|
-
var d = new Date().getTime() //Timestamp
|
|
5
|
-
var d2 =
|
|
6
|
-
(globalThis && globalThis.performance && globalThis.performance.now && globalThis.performance.now() * 1000) || 0 //Time in microseconds since page-load or 0 if unsupported
|
|
7
|
-
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
8
|
-
var r = Math.random() * 16 //random number between 0 and 16
|
|
9
|
-
if (d > 0) {
|
|
10
|
-
//Use timestamp until depleted
|
|
11
|
-
r = (d + r) % 16 | 0
|
|
12
|
-
d = Math.floor(d / 16)
|
|
13
|
-
} else {
|
|
14
|
-
//Use microseconds since page-load if supported
|
|
15
|
-
r = (d2 + r) % 16 | 0
|
|
16
|
-
d2 = Math.floor(d2 / 16)
|
|
17
|
-
}
|
|
18
|
-
return (c === 'x' ? r : (r & 0x3) | 0x8).toString(16)
|
|
19
|
-
})
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function currentTimestamp(): number {
|
|
23
|
-
return new Date().getTime()
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function currentISOTime(): string {
|
|
27
|
-
return new Date().toISOString()
|
|
28
|
-
}
|