@splitsoftware/splitio-commons 0.1.1-canary.6 → 0.1.1-rc.18
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/cjs/evaluator/matchers/matcherTypes.js +4 -4
- package/cjs/evaluator/matchersTransform/index.js +11 -11
- package/cjs/evaluator/value/sanitize.js +6 -6
- package/cjs/listeners/browser.js +5 -2
- package/cjs/listeners/node.js +9 -2
- package/cjs/logger/constants.js +3 -1
- package/cjs/logger/messages/error.js +3 -2
- package/cjs/logger/messages/info.js +2 -2
- package/cjs/logger/messages/warn.js +2 -1
- package/cjs/readiness/readinessManager.js +10 -7
- package/cjs/sdkFactory/index.js +1 -1
- package/cjs/services/splitApi.js +9 -1
- package/cjs/services/splitHttpClient.js +5 -4
- package/cjs/storages/AbstractSplitsCacheSync.js +1 -1
- package/cjs/storages/inLocalStorage/index.js +5 -2
- package/cjs/storages/inMemory/InMemoryStorage.js +2 -0
- package/cjs/storages/inMemory/InMemoryStorageCS.js +2 -0
- package/cjs/storages/inRedis/SplitsCacheInRedis.js +6 -2
- package/cjs/storages/inRedis/index.js +5 -2
- package/cjs/storages/pluggable/SplitsCachePluggable.js +6 -2
- package/cjs/storages/pluggable/inMemoryWrapper.js +6 -7
- package/cjs/storages/pluggable/index.js +5 -2
- package/cjs/storages/pluggable/wrapperAdapter.js +0 -1
- package/cjs/sync/offline/splitsParser/splitsParserFromFile.js +92 -89
- package/cjs/sync/offline/splitsParser/splitsParserFromSettings.js +45 -42
- package/cjs/sync/offline/syncTasks/fromObjectSyncTask.js +14 -4
- package/cjs/sync/polling/fetchers/segmentChangesFetcher.js +0 -8
- package/cjs/sync/polling/updaters/mySegmentsUpdater.js +30 -10
- package/cjs/sync/polling/updaters/segmentChangesUpdater.js +2 -4
- package/cjs/sync/streaming/SSEClient/index.js +38 -20
- package/cjs/sync/streaming/SSEHandler/NotificationKeeper.js +7 -0
- package/cjs/sync/streaming/SSEHandler/NotificationParser.js +4 -1
- package/cjs/sync/streaming/SSEHandler/index.js +8 -9
- package/cjs/sync/streaming/SSEHandler/types.js +14 -0
- package/cjs/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.js +5 -5
- package/cjs/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.js +2 -1
- package/cjs/sync/streaming/UpdateWorkers/SplitsUpdateWorker.js +5 -3
- package/cjs/sync/streaming/constants.js +3 -1
- package/cjs/sync/streaming/mySegmentsV2utils.js +75 -0
- package/cjs/sync/streaming/pushManager.js +148 -40
- package/cjs/sync/submitters/metricsSyncTask.js +1 -1
- package/cjs/sync/submitters/submitterSyncTask.js +2 -2
- package/cjs/sync/syncManagerFromFile.js +15 -0
- package/cjs/sync/syncManagerFromObject.js +14 -0
- package/cjs/sync/syncManagerOffline.js +3 -3
- package/cjs/sync/syncManagerOnline.js +18 -5
- package/cjs/sync/syncTask.js +1 -1
- package/cjs/trackers/impressionObserver/ImpressionObserver.js +0 -2
- package/cjs/trackers/impressionObserver/buildKey.js +3 -9
- package/cjs/trackers/impressionObserver/impressionObserverCS.js +2 -2
- package/cjs/trackers/impressionObserver/impressionObserverSS.js +3 -3
- package/cjs/utils/constants/index.js +4 -1
- package/cjs/utils/decompress/index.js +427 -0
- package/cjs/utils/murmur3/{commons.js → common.js} +2 -6
- package/cjs/utils/murmur3/murmur3.js +11 -12
- package/cjs/utils/murmur3/murmur3_128.js +7 -142
- package/cjs/utils/murmur3/murmur3_128_x86.js +154 -0
- package/cjs/utils/murmur3/murmur3_64.js +36 -0
- package/cjs/utils/murmur3/utfx.js +100 -106
- package/cjs/utils/promise/wrapper.js +14 -11
- package/cjs/utils/settingsValidation/index.js +5 -2
- package/cjs/utils/settingsValidation/localhost/index.js +20 -0
- package/cjs/utils/settingsValidation/splitFilters.js +0 -1
- package/cjs/utils/settingsValidation/storage/storageCS.js +18 -8
- package/cjs/utils/settingsValidation/url.js +1 -1
- package/esm/evaluator/matchers/matcherTypes.js +2 -2
- package/esm/evaluator/matchersTransform/index.js +12 -12
- package/esm/evaluator/value/sanitize.js +7 -7
- package/esm/listeners/browser.js +5 -2
- package/esm/listeners/node.js +9 -2
- package/esm/logger/constants.js +2 -0
- package/esm/logger/messages/error.js +3 -2
- package/esm/logger/messages/info.js +2 -2
- package/esm/logger/messages/warn.js +2 -1
- package/esm/readiness/readinessManager.js +10 -7
- package/esm/sdkFactory/index.js +1 -1
- package/esm/services/splitApi.js +9 -1
- package/esm/services/splitHttpClient.js +5 -4
- package/esm/storages/AbstractSplitsCacheSync.js +1 -1
- package/esm/storages/inLocalStorage/index.js +5 -2
- package/esm/storages/inMemory/InMemoryStorage.js +2 -0
- package/esm/storages/inMemory/InMemoryStorageCS.js +2 -0
- package/esm/storages/inRedis/SplitsCacheInRedis.js +6 -2
- package/esm/storages/inRedis/index.js +5 -2
- package/esm/storages/pluggable/SplitsCachePluggable.js +6 -2
- package/esm/storages/pluggable/inMemoryWrapper.js +6 -7
- package/esm/storages/pluggable/index.js +5 -2
- package/esm/storages/pluggable/wrapperAdapter.js +0 -1
- package/esm/sync/offline/splitsParser/splitsParserFromFile.js +90 -88
- package/esm/sync/offline/splitsParser/splitsParserFromSettings.js +43 -41
- package/esm/sync/offline/syncTasks/fromObjectSyncTask.js +15 -5
- package/esm/sync/polling/fetchers/segmentChangesFetcher.js +0 -8
- package/esm/sync/polling/updaters/mySegmentsUpdater.js +30 -10
- package/esm/sync/polling/updaters/segmentChangesUpdater.js +2 -4
- package/esm/sync/streaming/SSEClient/index.js +38 -20
- package/esm/sync/streaming/SSEHandler/NotificationKeeper.js +7 -0
- package/esm/sync/streaming/SSEHandler/NotificationParser.js +4 -1
- package/esm/sync/streaming/SSEHandler/index.js +9 -10
- package/esm/sync/streaming/SSEHandler/types.js +13 -1
- package/esm/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.js +5 -5
- package/esm/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.js +2 -1
- package/esm/sync/streaming/UpdateWorkers/SplitsUpdateWorker.js +5 -3
- package/esm/sync/streaming/constants.js +2 -0
- package/esm/sync/streaming/mySegmentsV2utils.js +69 -0
- package/esm/sync/streaming/pushManager.js +150 -42
- package/esm/sync/submitters/metricsSyncTask.js +1 -1
- package/esm/sync/submitters/submitterSyncTask.js +2 -2
- package/esm/sync/syncManagerFromFile.js +11 -0
- package/esm/sync/syncManagerFromObject.js +10 -0
- package/esm/sync/syncManagerOffline.js +3 -3
- package/esm/sync/syncManagerOnline.js +18 -5
- package/esm/sync/syncTask.js +1 -1
- package/esm/trackers/impressionObserver/ImpressionObserver.js +0 -2
- package/esm/trackers/impressionObserver/buildKey.js +2 -9
- package/esm/trackers/impressionObserver/impressionObserverCS.js +2 -2
- package/esm/trackers/impressionObserver/impressionObserverSS.js +3 -3
- package/esm/utils/constants/index.js +3 -0
- package/esm/utils/decompress/index.js +424 -0
- package/esm/utils/murmur3/{commons.js → common.js} +1 -4
- package/esm/utils/murmur3/murmur3.js +1 -2
- package/esm/utils/murmur3/murmur3_128.js +7 -142
- package/esm/utils/murmur3/murmur3_128_x86.js +150 -0
- package/esm/utils/murmur3/murmur3_64.js +32 -0
- package/esm/utils/murmur3/utfx.js +96 -106
- package/esm/utils/promise/wrapper.js +14 -11
- package/esm/utils/settingsValidation/index.js +5 -2
- package/esm/utils/settingsValidation/localhost/index.js +16 -0
- package/esm/utils/settingsValidation/splitFilters.js +0 -1
- package/esm/utils/settingsValidation/storage/storageCS.js +16 -7
- package/esm/utils/settingsValidation/url.js +1 -1
- package/package.json +5 -5
- package/src/evaluator/matchers/matcherTypes.ts +2 -2
- package/src/evaluator/matchersTransform/index.ts +12 -12
- package/src/evaluator/value/sanitize.ts +7 -7
- package/src/listeners/browser.ts +5 -2
- package/src/listeners/node.ts +14 -2
- package/src/logger/constants.ts +2 -0
- package/src/logger/messages/error.ts +3 -2
- package/src/logger/messages/info.ts +2 -2
- package/src/logger/messages/warn.ts +3 -1
- package/src/readiness/readinessManager.ts +9 -7
- package/src/sdkFactory/index.ts +1 -1
- package/src/sdkFactory/types.ts +4 -5
- package/src/services/splitApi.ts +12 -3
- package/src/services/splitHttpClient.ts +6 -5
- package/src/services/types.ts +7 -3
- package/src/storages/AbstractSplitsCacheSync.ts +1 -1
- package/src/storages/inLocalStorage/index.ts +8 -4
- package/src/storages/inMemory/InMemoryStorage.ts +3 -0
- package/src/storages/inMemory/InMemoryStorageCS.ts +3 -0
- package/src/storages/inRedis/SplitsCacheInRedis.ts +3 -1
- package/src/storages/inRedis/index.ts +8 -4
- package/src/storages/pluggable/SegmentsCachePluggable.ts +1 -1
- package/src/storages/pluggable/SplitsCachePluggable.ts +3 -1
- package/src/storages/pluggable/inMemoryWrapper.ts +6 -7
- package/src/storages/pluggable/index.ts +8 -4
- package/src/storages/pluggable/wrapperAdapter.ts +0 -1
- package/src/storages/types.ts +18 -15
- package/src/sync/offline/splitsParser/splitsParserFromFile.ts +110 -105
- package/src/sync/offline/splitsParser/splitsParserFromSettings.ts +45 -41
- package/src/sync/offline/syncTasks/fromObjectSyncTask.ts +15 -5
- package/src/sync/polling/fetchers/segmentChangesFetcher.ts +0 -7
- package/src/sync/polling/types.ts +2 -1
- package/src/sync/polling/updaters/mySegmentsUpdater.ts +28 -10
- package/src/sync/polling/updaters/segmentChangesUpdater.ts +2 -3
- package/src/sync/streaming/AuthClient/types.ts +3 -0
- package/src/sync/streaming/SSEClient/index.ts +43 -23
- package/src/sync/streaming/SSEClient/types.ts +0 -1
- package/src/sync/streaming/SSEHandler/NotificationKeeper.ts +8 -0
- package/src/sync/streaming/SSEHandler/NotificationParser.ts +4 -2
- package/src/sync/streaming/SSEHandler/index.ts +11 -20
- package/src/sync/streaming/SSEHandler/types.ts +37 -3
- package/src/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.ts +7 -6
- package/src/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.ts +2 -1
- package/src/sync/streaming/UpdateWorkers/SplitsUpdateWorker.ts +4 -3
- package/src/sync/streaming/UpdateWorkers/types.ts +1 -1
- package/src/sync/streaming/constants.ts +2 -0
- package/src/sync/streaming/mySegmentsV2utils.ts +77 -0
- package/src/sync/streaming/pushManager.ts +145 -42
- package/src/sync/streaming/types.ts +14 -22
- package/src/sync/submitters/metricsSyncTask.ts +1 -1
- package/src/sync/submitters/submitterSyncTask.ts +2 -1
- package/src/sync/syncManagerFromFile.ts +13 -0
- package/src/sync/syncManagerFromObject.ts +12 -0
- package/src/sync/syncManagerOffline.ts +3 -3
- package/src/sync/syncManagerOnline.ts +19 -5
- package/src/sync/syncTask.ts +1 -1
- package/src/sync/types.ts +3 -1
- package/src/trackers/impressionObserver/ImpressionObserver.ts +4 -6
- package/src/trackers/impressionObserver/buildKey.ts +2 -16
- package/src/trackers/impressionObserver/impressionObserverCS.ts +2 -2
- package/src/trackers/impressionObserver/impressionObserverSS.ts +3 -3
- package/src/types.ts +16 -2
- package/src/utils/constants/index.ts +6 -1
- package/src/utils/decompress/index.ts +429 -0
- package/src/utils/lang/index.ts +1 -1
- package/src/utils/murmur3/{commons.ts → common.ts} +1 -5
- package/src/utils/murmur3/murmur3.ts +5 -5
- package/src/utils/murmur3/murmur3_128.ts +7 -180
- package/src/utils/murmur3/murmur3_128_x86.ts +188 -0
- package/src/utils/murmur3/murmur3_64.ts +36 -0
- package/src/utils/murmur3/utfx.ts +92 -110
- package/src/utils/promise/wrapper.ts +12 -9
- package/src/utils/settingsValidation/index.ts +8 -4
- package/src/utils/settingsValidation/localhost/index.ts +19 -0
- package/src/utils/settingsValidation/splitFilters.ts +0 -1
- package/src/utils/settingsValidation/storage/storageCS.ts +21 -8
- package/src/utils/settingsValidation/types.ts +2 -11
- package/src/utils/settingsValidation/url.ts +1 -1
- package/types/evaluator/matchers/matcherTypes.d.ts +2 -2
- package/types/listeners/browser.d.ts +3 -3
- package/types/listeners/node.d.ts +3 -2
- package/types/logger/constants.d.ts +2 -0
- package/types/sdkFactory/types.d.ts +4 -5
- package/types/services/types.d.ts +4 -0
- package/types/storages/inLocalStorage/index.d.ts +2 -2
- package/types/storages/inMemory/InMemoryStorage.d.ts +3 -0
- package/types/storages/inMemory/InMemoryStorageCS.d.ts +3 -0
- package/types/storages/inRedis/index.d.ts +2 -2
- package/types/storages/pluggable/index.d.ts +2 -2
- package/types/storages/types.d.ts +15 -15
- package/types/sync/offline/splitsParser/splitsParserFromFile.d.ts +2 -7
- package/types/sync/offline/splitsParser/splitsParserFromSettings.d.ts +1 -5
- package/types/sync/polling/types.d.ts +2 -1
- package/types/sync/streaming/AuthClient/indexV1.d.ts +12 -0
- package/types/sync/streaming/AuthClient/indexV2.d.ts +8 -0
- package/types/sync/streaming/AuthClient/types.d.ts +2 -0
- package/types/sync/streaming/SSEClient/index.d.ts +9 -12
- package/types/sync/streaming/SSEClient/types.d.ts +0 -1
- package/types/sync/streaming/SSEHandler/NotificationParser.d.ts +3 -2
- package/types/sync/streaming/SSEHandler/types.d.ts +30 -2
- package/types/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.d.ts +4 -3
- package/types/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.d.ts +2 -1
- package/types/sync/streaming/UpdateWorkers/SplitsUpdateWorker.d.ts +3 -2
- package/types/sync/streaming/UpdateWorkers/types.d.ts +1 -1
- package/types/sync/streaming/constants.d.ts +3 -1
- package/types/sync/streaming/mySegmentsV2utils.d.ts +27 -0
- package/types/sync/streaming/pushManagerNoUsers.d.ts +13 -0
- package/types/sync/streaming/types.d.ts +9 -5
- package/types/sync/submitters/submitterSyncTask.d.ts +1 -1
- package/types/sync/syncManagerFromFile.d.ts +2 -0
- package/types/sync/syncManagerFromObject.d.ts +2 -0
- package/types/sync/syncManagerOffline.d.ts +1 -1
- package/types/sync/syncTask.d.ts +1 -1
- package/types/sync/types.d.ts +2 -0
- package/types/trackers/impressionObserver/ImpressionObserver.d.ts +2 -2
- package/types/trackers/impressionObserver/buildKey.d.ts +1 -1
- package/types/trackers/impressionObserver/impressionObserverCS.d.ts +2 -2
- package/types/trackers/impressionObserver/impressionObserverSS.d.ts +2 -2
- package/types/types.d.ts +16 -2
- package/types/utils/constants/index.d.ts +5 -1
- package/types/utils/decompress/index.d.ts +16 -0
- package/types/utils/lang/index.d.ts +1 -1
- package/types/utils/murmur3/common.d.ts +12 -0
- package/types/utils/murmur3/murmur3.d.ts +2 -2
- package/types/utils/murmur3/murmur3_128.d.ts +5 -0
- package/types/utils/murmur3/murmur3_128_x86.d.ts +7 -0
- package/types/utils/murmur3/murmur3_64.d.ts +10 -0
- package/types/utils/murmur3/utfx.d.ts +24 -6
- package/types/utils/settingsValidation/index.d.ts +3 -2
- package/types/utils/settingsValidation/localhost/index.d.ts +9 -0
- package/types/utils/settingsValidation/storage/storageCS.d.ts +7 -1
- package/types/utils/settingsValidation/types.d.ts +2 -10
- package/cjs/sync/streaming/pushManagerCS.js +0 -178
- package/cjs/sync/streaming/pushManagerSS.js +0 -128
- package/esm/sync/streaming/pushManagerCS.js +0 -174
- package/esm/sync/streaming/pushManagerSS.js +0 -124
- package/src/sync/streaming/pushManagerCS.ts +0 -237
- package/src/sync/streaming/pushManagerSS.ts +0 -177
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
/* eslint-disable no-fallthrough */
|
|
2
|
-
import { UTF16ToUTF8
|
|
3
|
-
|
|
4
|
-
const X64 = 'x64';
|
|
5
|
-
const X86 = 'x86';
|
|
6
|
-
const X64_ARCHS = ['arm64', 'ppc64', 'x64', 's390x', 'mipsel'];
|
|
7
|
-
const isX64 = getArchType() === X64;
|
|
2
|
+
import { UTF16ToUTF8 } from './common';
|
|
8
3
|
|
|
9
4
|
/*
|
|
10
5
|
* +----------------------------------------------------------------------------------+
|
|
@@ -149,171 +144,6 @@ function _x64Fmix(h: number[]): number[] {
|
|
|
149
144
|
|
|
150
145
|
// PUBLIC FUNCTIONS
|
|
151
146
|
// ----------------
|
|
152
|
-
function hash128x86(key?: string, seed?: number) {
|
|
153
|
-
//
|
|
154
|
-
// Given a string and an optional seed as an int, returns a 128 bit
|
|
155
|
-
// hash using the x86 flavor of MurmurHash3, as an unsigned hex.
|
|
156
|
-
//
|
|
157
|
-
|
|
158
|
-
key = key || '';
|
|
159
|
-
seed = seed || 0;
|
|
160
|
-
|
|
161
|
-
var remainder = key.length % 16;
|
|
162
|
-
var bytes = key.length - remainder;
|
|
163
|
-
|
|
164
|
-
var h1 = seed;
|
|
165
|
-
var h2 = seed;
|
|
166
|
-
var h3 = seed;
|
|
167
|
-
var h4 = seed;
|
|
168
|
-
|
|
169
|
-
var k1 = 0;
|
|
170
|
-
var k2 = 0;
|
|
171
|
-
var k3 = 0;
|
|
172
|
-
var k4 = 0;
|
|
173
|
-
|
|
174
|
-
var c1 = 0x239b961b;
|
|
175
|
-
var c2 = 0xab0e9789;
|
|
176
|
-
var c3 = 0x38b34ae5;
|
|
177
|
-
var c4 = 0xa1e38b93;
|
|
178
|
-
|
|
179
|
-
for (var i = 0; i < bytes; i = i + 16) {
|
|
180
|
-
k1 = ((key.charCodeAt(i) & 0xff)) | ((key.charCodeAt(i + 1) & 0xff) << 8) | ((key.charCodeAt(i + 2) & 0xff) << 16) | ((key.charCodeAt(i + 3) & 0xff) << 24);
|
|
181
|
-
k2 = ((key.charCodeAt(i + 4) & 0xff)) | ((key.charCodeAt(i + 5) & 0xff) << 8) | ((key.charCodeAt(i + 6) & 0xff) << 16) | ((key.charCodeAt(i + 7) & 0xff) << 24);
|
|
182
|
-
k3 = ((key.charCodeAt(i + 8) & 0xff)) | ((key.charCodeAt(i + 9) & 0xff) << 8) | ((key.charCodeAt(i + 10) & 0xff) << 16) | ((key.charCodeAt(i + 11) & 0xff) << 24);
|
|
183
|
-
k4 = ((key.charCodeAt(i + 12) & 0xff)) | ((key.charCodeAt(i + 13) & 0xff) << 8) | ((key.charCodeAt(i + 14) & 0xff) << 16) | ((key.charCodeAt(i + 15) & 0xff) << 24);
|
|
184
|
-
|
|
185
|
-
k1 = x86Multiply(k1, c1);
|
|
186
|
-
k1 = x86Rotl(k1, 15);
|
|
187
|
-
k1 = x86Multiply(k1, c2);
|
|
188
|
-
h1 ^= k1;
|
|
189
|
-
|
|
190
|
-
h1 = x86Rotl(h1, 19);
|
|
191
|
-
h1 += h2;
|
|
192
|
-
h1 = x86Multiply(h1, 5) + 0x561ccd1b;
|
|
193
|
-
|
|
194
|
-
k2 = x86Multiply(k2, c2);
|
|
195
|
-
k2 = x86Rotl(k2, 16);
|
|
196
|
-
k2 = x86Multiply(k2, c3);
|
|
197
|
-
h2 ^= k2;
|
|
198
|
-
|
|
199
|
-
h2 = x86Rotl(h2, 17);
|
|
200
|
-
h2 += h3;
|
|
201
|
-
h2 = x86Multiply(h2, 5) + 0x0bcaa747;
|
|
202
|
-
|
|
203
|
-
k3 = x86Multiply(k3, c3);
|
|
204
|
-
k3 = x86Rotl(k3, 17);
|
|
205
|
-
k3 = x86Multiply(k3, c4);
|
|
206
|
-
h3 ^= k3;
|
|
207
|
-
|
|
208
|
-
h3 = x86Rotl(h3, 15);
|
|
209
|
-
h3 += h4;
|
|
210
|
-
h3 = x86Multiply(h3, 5) + 0x96cd1c35;
|
|
211
|
-
|
|
212
|
-
k4 = x86Multiply(k4, c4);
|
|
213
|
-
k4 = x86Rotl(k4, 18);
|
|
214
|
-
k4 = x86Multiply(k4, c1);
|
|
215
|
-
h4 ^= k4;
|
|
216
|
-
|
|
217
|
-
h4 = x86Rotl(h4, 13);
|
|
218
|
-
h4 += h1;
|
|
219
|
-
h4 = x86Multiply(h4, 5) + 0x32ac3b17;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
k1 = 0;
|
|
223
|
-
k2 = 0;
|
|
224
|
-
k3 = 0;
|
|
225
|
-
k4 = 0;
|
|
226
|
-
|
|
227
|
-
switch (remainder) {
|
|
228
|
-
case 15:
|
|
229
|
-
k4 ^= key.charCodeAt(i + 14) << 16;
|
|
230
|
-
|
|
231
|
-
case 14:
|
|
232
|
-
k4 ^= key.charCodeAt(i + 13) << 8;
|
|
233
|
-
|
|
234
|
-
case 13:
|
|
235
|
-
k4 ^= key.charCodeAt(i + 12);
|
|
236
|
-
k4 = x86Multiply(k4, c4);
|
|
237
|
-
k4 = x86Rotl(k4, 18);
|
|
238
|
-
k4 = x86Multiply(k4, c1);
|
|
239
|
-
h4 ^= k4;
|
|
240
|
-
|
|
241
|
-
case 12:
|
|
242
|
-
k3 ^= key.charCodeAt(i + 11) << 24;
|
|
243
|
-
|
|
244
|
-
case 11:
|
|
245
|
-
k3 ^= key.charCodeAt(i + 10) << 16;
|
|
246
|
-
|
|
247
|
-
case 10:
|
|
248
|
-
k3 ^= key.charCodeAt(i + 9) << 8;
|
|
249
|
-
|
|
250
|
-
case 9:
|
|
251
|
-
k3 ^= key.charCodeAt(i + 8);
|
|
252
|
-
k3 = x86Multiply(k3, c3);
|
|
253
|
-
k3 = x86Rotl(k3, 17);
|
|
254
|
-
k3 = x86Multiply(k3, c4);
|
|
255
|
-
h3 ^= k3;
|
|
256
|
-
|
|
257
|
-
case 8:
|
|
258
|
-
k2 ^= key.charCodeAt(i + 7) << 24;
|
|
259
|
-
|
|
260
|
-
case 7:
|
|
261
|
-
k2 ^= key.charCodeAt(i + 6) << 16;
|
|
262
|
-
|
|
263
|
-
case 6:
|
|
264
|
-
k2 ^= key.charCodeAt(i + 5) << 8;
|
|
265
|
-
|
|
266
|
-
case 5:
|
|
267
|
-
k2 ^= key.charCodeAt(i + 4);
|
|
268
|
-
k2 = x86Multiply(k2, c2);
|
|
269
|
-
k2 = x86Rotl(k2, 16);
|
|
270
|
-
k2 = x86Multiply(k2, c3);
|
|
271
|
-
h2 ^= k2;
|
|
272
|
-
|
|
273
|
-
case 4:
|
|
274
|
-
k1 ^= key.charCodeAt(i + 3) << 24;
|
|
275
|
-
|
|
276
|
-
case 3:
|
|
277
|
-
k1 ^= key.charCodeAt(i + 2) << 16;
|
|
278
|
-
|
|
279
|
-
case 2:
|
|
280
|
-
k1 ^= key.charCodeAt(i + 1) << 8;
|
|
281
|
-
|
|
282
|
-
case 1:
|
|
283
|
-
k1 ^= key.charCodeAt(i);
|
|
284
|
-
k1 = x86Multiply(k1, c1);
|
|
285
|
-
k1 = x86Rotl(k1, 15);
|
|
286
|
-
k1 = x86Multiply(k1, c2);
|
|
287
|
-
h1 ^= k1;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
h1 ^= key.length;
|
|
291
|
-
h2 ^= key.length;
|
|
292
|
-
h3 ^= key.length;
|
|
293
|
-
h4 ^= key.length;
|
|
294
|
-
|
|
295
|
-
h1 += h2;
|
|
296
|
-
h1 += h3;
|
|
297
|
-
h1 += h4;
|
|
298
|
-
h2 += h1;
|
|
299
|
-
h3 += h1;
|
|
300
|
-
h4 += h1;
|
|
301
|
-
|
|
302
|
-
h1 = x86Fmix(h1);
|
|
303
|
-
h2 = x86Fmix(h2);
|
|
304
|
-
h3 = x86Fmix(h3);
|
|
305
|
-
h4 = x86Fmix(h4);
|
|
306
|
-
|
|
307
|
-
h1 += h2;
|
|
308
|
-
h1 += h3;
|
|
309
|
-
h1 += h4;
|
|
310
|
-
h2 += h1;
|
|
311
|
-
h3 += h1;
|
|
312
|
-
h4 += h1;
|
|
313
|
-
|
|
314
|
-
return ('00000000' + (h1 >>> 0).toString(16)).slice(-8) + ('00000000' + (h2 >>> 0).toString(16)).slice(-8) + ('00000000' + (h3 >>> 0).toString(16)).slice(-8) + ('00000000' + (h4 >>> 0).toString(16)).slice(-8);
|
|
315
|
-
}
|
|
316
|
-
|
|
317
147
|
function hash128x64(key?: string, seed?: number) {
|
|
318
148
|
//
|
|
319
149
|
// Given a string and an optional seed as an int, returns a 128 bit
|
|
@@ -433,14 +263,11 @@ function hash128x64(key?: string, seed?: number) {
|
|
|
433
263
|
return ('00000000' + (h1[0] >>> 0).toString(16)).slice(-8) + ('00000000' + (h1[1] >>> 0).toString(16)).slice(-8) + ('00000000' + (h2[0] >>> 0).toString(16)).slice(-8) + ('00000000' + (h2[1] >>> 0).toString(16)).slice(-8);
|
|
434
264
|
}
|
|
435
265
|
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
return (X64_ARCHS.indexOf(arch) > -1) ? X64 : X86;
|
|
442
|
-
}
|
|
443
|
-
|
|
266
|
+
/**
|
|
267
|
+
* x64 version of Murmur3 for 128bits.
|
|
268
|
+
*
|
|
269
|
+
* @param {string} str
|
|
270
|
+
*/
|
|
444
271
|
export function hash128(str: string, seed?: number): string {
|
|
445
|
-
return
|
|
272
|
+
return hash128x64(UTF16ToUTF8(str), (seed as number) >>> 0);
|
|
446
273
|
}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/* eslint-disable no-fallthrough */
|
|
2
|
+
import { UTF16ToUTF8, x86Fmix, x86Multiply, x86Rotl } from './common';
|
|
3
|
+
|
|
4
|
+
/*!
|
|
5
|
+
* +----------------------------------------------------------------------------------+
|
|
6
|
+
* | murmurHash3.js v3.0.0 (http://github.com/karanlyons/murmurHash3.js) |
|
|
7
|
+
* | A TypeScript/JavaScript implementation of MurmurHash3's hashing algorithms. |
|
|
8
|
+
* |----------------------------------------------------------------------------------|
|
|
9
|
+
* | Copyright (c) 2012-2020 Karan Lyons. Freely distributable under the MIT license. |
|
|
10
|
+
* +----------------------------------------------------------------------------------+
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
// PUBLIC FUNCTIONS
|
|
14
|
+
// ----------------
|
|
15
|
+
function hash128x86(key?: string, seed?: number): string {
|
|
16
|
+
//
|
|
17
|
+
// Given a string and an optional seed as an int, returns a 128 bit
|
|
18
|
+
// hash using the x86 flavor of MurmurHash3, as an unsigned hex.
|
|
19
|
+
//
|
|
20
|
+
|
|
21
|
+
key = key || '';
|
|
22
|
+
seed = seed || 0;
|
|
23
|
+
|
|
24
|
+
var remainder = key.length % 16;
|
|
25
|
+
var bytes = key.length - remainder;
|
|
26
|
+
|
|
27
|
+
var h1 = seed;
|
|
28
|
+
var h2 = seed;
|
|
29
|
+
var h3 = seed;
|
|
30
|
+
var h4 = seed;
|
|
31
|
+
|
|
32
|
+
var k1 = 0;
|
|
33
|
+
var k2 = 0;
|
|
34
|
+
var k3 = 0;
|
|
35
|
+
var k4 = 0;
|
|
36
|
+
|
|
37
|
+
var c1 = 0x239b961b;
|
|
38
|
+
var c2 = 0xab0e9789;
|
|
39
|
+
var c3 = 0x38b34ae5;
|
|
40
|
+
var c4 = 0xa1e38b93;
|
|
41
|
+
|
|
42
|
+
for (var i = 0; i < bytes; i = i + 16) {
|
|
43
|
+
k1 = ((key.charCodeAt(i) & 0xff)) | ((key.charCodeAt(i + 1) & 0xff) << 8) | ((key.charCodeAt(i + 2) & 0xff) << 16) | ((key.charCodeAt(i + 3) & 0xff) << 24);
|
|
44
|
+
k2 = ((key.charCodeAt(i + 4) & 0xff)) | ((key.charCodeAt(i + 5) & 0xff) << 8) | ((key.charCodeAt(i + 6) & 0xff) << 16) | ((key.charCodeAt(i + 7) & 0xff) << 24);
|
|
45
|
+
k3 = ((key.charCodeAt(i + 8) & 0xff)) | ((key.charCodeAt(i + 9) & 0xff) << 8) | ((key.charCodeAt(i + 10) & 0xff) << 16) | ((key.charCodeAt(i + 11) & 0xff) << 24);
|
|
46
|
+
k4 = ((key.charCodeAt(i + 12) & 0xff)) | ((key.charCodeAt(i + 13) & 0xff) << 8) | ((key.charCodeAt(i + 14) & 0xff) << 16) | ((key.charCodeAt(i + 15) & 0xff) << 24);
|
|
47
|
+
|
|
48
|
+
k1 = x86Multiply(k1, c1);
|
|
49
|
+
k1 = x86Rotl(k1, 15);
|
|
50
|
+
k1 = x86Multiply(k1, c2);
|
|
51
|
+
h1 ^= k1;
|
|
52
|
+
|
|
53
|
+
h1 = x86Rotl(h1, 19);
|
|
54
|
+
h1 += h2;
|
|
55
|
+
h1 = x86Multiply(h1, 5) + 0x561ccd1b;
|
|
56
|
+
|
|
57
|
+
k2 = x86Multiply(k2, c2);
|
|
58
|
+
k2 = x86Rotl(k2, 16);
|
|
59
|
+
k2 = x86Multiply(k2, c3);
|
|
60
|
+
h2 ^= k2;
|
|
61
|
+
|
|
62
|
+
h2 = x86Rotl(h2, 17);
|
|
63
|
+
h2 += h3;
|
|
64
|
+
h2 = x86Multiply(h2, 5) + 0x0bcaa747;
|
|
65
|
+
|
|
66
|
+
k3 = x86Multiply(k3, c3);
|
|
67
|
+
k3 = x86Rotl(k3, 17);
|
|
68
|
+
k3 = x86Multiply(k3, c4);
|
|
69
|
+
h3 ^= k3;
|
|
70
|
+
|
|
71
|
+
h3 = x86Rotl(h3, 15);
|
|
72
|
+
h3 += h4;
|
|
73
|
+
h3 = x86Multiply(h3, 5) + 0x96cd1c35;
|
|
74
|
+
|
|
75
|
+
k4 = x86Multiply(k4, c4);
|
|
76
|
+
k4 = x86Rotl(k4, 18);
|
|
77
|
+
k4 = x86Multiply(k4, c1);
|
|
78
|
+
h4 ^= k4;
|
|
79
|
+
|
|
80
|
+
h4 = x86Rotl(h4, 13);
|
|
81
|
+
h4 += h1;
|
|
82
|
+
h4 = x86Multiply(h4, 5) + 0x32ac3b17;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
k1 = 0;
|
|
86
|
+
k2 = 0;
|
|
87
|
+
k3 = 0;
|
|
88
|
+
k4 = 0;
|
|
89
|
+
|
|
90
|
+
switch (remainder) {
|
|
91
|
+
case 15:
|
|
92
|
+
k4 ^= key.charCodeAt(i + 14) << 16;
|
|
93
|
+
|
|
94
|
+
case 14:
|
|
95
|
+
k4 ^= key.charCodeAt(i + 13) << 8;
|
|
96
|
+
|
|
97
|
+
case 13:
|
|
98
|
+
k4 ^= key.charCodeAt(i + 12);
|
|
99
|
+
k4 = x86Multiply(k4, c4);
|
|
100
|
+
k4 = x86Rotl(k4, 18);
|
|
101
|
+
k4 = x86Multiply(k4, c1);
|
|
102
|
+
h4 ^= k4;
|
|
103
|
+
|
|
104
|
+
case 12:
|
|
105
|
+
k3 ^= key.charCodeAt(i + 11) << 24;
|
|
106
|
+
|
|
107
|
+
case 11:
|
|
108
|
+
k3 ^= key.charCodeAt(i + 10) << 16;
|
|
109
|
+
|
|
110
|
+
case 10:
|
|
111
|
+
k3 ^= key.charCodeAt(i + 9) << 8;
|
|
112
|
+
|
|
113
|
+
case 9:
|
|
114
|
+
k3 ^= key.charCodeAt(i + 8);
|
|
115
|
+
k3 = x86Multiply(k3, c3);
|
|
116
|
+
k3 = x86Rotl(k3, 17);
|
|
117
|
+
k3 = x86Multiply(k3, c4);
|
|
118
|
+
h3 ^= k3;
|
|
119
|
+
|
|
120
|
+
case 8:
|
|
121
|
+
k2 ^= key.charCodeAt(i + 7) << 24;
|
|
122
|
+
|
|
123
|
+
case 7:
|
|
124
|
+
k2 ^= key.charCodeAt(i + 6) << 16;
|
|
125
|
+
|
|
126
|
+
case 6:
|
|
127
|
+
k2 ^= key.charCodeAt(i + 5) << 8;
|
|
128
|
+
|
|
129
|
+
case 5:
|
|
130
|
+
k2 ^= key.charCodeAt(i + 4);
|
|
131
|
+
k2 = x86Multiply(k2, c2);
|
|
132
|
+
k2 = x86Rotl(k2, 16);
|
|
133
|
+
k2 = x86Multiply(k2, c3);
|
|
134
|
+
h2 ^= k2;
|
|
135
|
+
|
|
136
|
+
case 4:
|
|
137
|
+
k1 ^= key.charCodeAt(i + 3) << 24;
|
|
138
|
+
|
|
139
|
+
case 3:
|
|
140
|
+
k1 ^= key.charCodeAt(i + 2) << 16;
|
|
141
|
+
|
|
142
|
+
case 2:
|
|
143
|
+
k1 ^= key.charCodeAt(i + 1) << 8;
|
|
144
|
+
|
|
145
|
+
case 1:
|
|
146
|
+
k1 ^= key.charCodeAt(i);
|
|
147
|
+
k1 = x86Multiply(k1, c1);
|
|
148
|
+
k1 = x86Rotl(k1, 15);
|
|
149
|
+
k1 = x86Multiply(k1, c2);
|
|
150
|
+
h1 ^= k1;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
h1 ^= key.length;
|
|
154
|
+
h2 ^= key.length;
|
|
155
|
+
h3 ^= key.length;
|
|
156
|
+
h4 ^= key.length;
|
|
157
|
+
|
|
158
|
+
h1 += h2;
|
|
159
|
+
h1 += h3;
|
|
160
|
+
h1 += h4;
|
|
161
|
+
h2 += h1;
|
|
162
|
+
h3 += h1;
|
|
163
|
+
h4 += h1;
|
|
164
|
+
|
|
165
|
+
h1 = x86Fmix(h1);
|
|
166
|
+
h2 = x86Fmix(h2);
|
|
167
|
+
h3 = x86Fmix(h3);
|
|
168
|
+
h4 = x86Fmix(h4);
|
|
169
|
+
|
|
170
|
+
h1 += h2;
|
|
171
|
+
h1 += h3;
|
|
172
|
+
h1 += h4;
|
|
173
|
+
h2 += h1;
|
|
174
|
+
h3 += h1;
|
|
175
|
+
h4 += h1;
|
|
176
|
+
|
|
177
|
+
return ('00000000' + (h1 >>> 0).toString(16)).slice(-8) + ('00000000' + (h2 >>> 0).toString(16)).slice(-8) + ('00000000' + (h3 >>> 0).toString(16)).slice(-8) + ('00000000' + (h4 >>> 0).toString(16)).slice(-8);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* x86 version of Murmur3 for 128bits.
|
|
182
|
+
* Used by hashImpression128 because in JS it is more efficient than the x64 version, no matter the underlying OS/CPU arch.
|
|
183
|
+
*
|
|
184
|
+
* @param {string} str
|
|
185
|
+
*/
|
|
186
|
+
export function hash128(str: string, seed?: number): string {
|
|
187
|
+
return hash128x86(UTF16ToUTF8(str), (seed as number) >>> 0);
|
|
188
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { hash128 } from './murmur3_128';
|
|
2
|
+
|
|
3
|
+
export type Hash64 = { hex: string, dec: string };
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Use instead of parseInt, to not lose precision when converting big integers (greater than 2^53 - 1)
|
|
7
|
+
*/
|
|
8
|
+
function hex2dec(s: string): string {
|
|
9
|
+
let i, j, digits = [0], carry;
|
|
10
|
+
for (i = 0; i < s.length; i += 1) {
|
|
11
|
+
carry = parseInt(s.charAt(i), 16);
|
|
12
|
+
for (j = digits.length - 1; j >= 0; j -= 1) {
|
|
13
|
+
digits[j] = digits[j] * 16 + carry;
|
|
14
|
+
carry = digits[j] / 10 | 0;
|
|
15
|
+
digits[j] %= 10;
|
|
16
|
+
}
|
|
17
|
+
while (carry > 0) {
|
|
18
|
+
digits.unshift(carry % 10);
|
|
19
|
+
carry = carry / 10 | 0;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return digits.join('');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Gets the higher 64 bits of the x64 version of Murmur3 for 128bits, as decimal and hexadecimal number strings.
|
|
27
|
+
* Used for MySegments channel V2 notifications.
|
|
28
|
+
* @param {string} str
|
|
29
|
+
*/
|
|
30
|
+
export function hash64(str: string): Hash64 {
|
|
31
|
+
const hex = hash128(str).slice(0, 16);
|
|
32
|
+
return {
|
|
33
|
+
hex, // BoundedFetchRequest notification
|
|
34
|
+
dec: hex2dec(hex) // KeyList notification
|
|
35
|
+
};
|
|
36
|
+
}
|
|
@@ -8,128 +8,110 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
export interface utfx {
|
|
11
|
-
stringSource(key: string): () => number | null,
|
|
12
|
-
stringDestination(): (...args: number[]) => string | undefined,
|
|
13
11
|
encodeUTF16toUTF8(src: () => number | null, dst: (...args: number[]) => string | undefined): void,
|
|
14
12
|
|
|
15
|
-
// Internal use
|
|
16
|
-
UTF16toUTF8(src: () => number | null, dst: (cp: number) => void): void,
|
|
17
|
-
encodeUTF8(src: (() => number | null) | number, dst: (cp: number) => void): void
|
|
18
13
|
}
|
|
19
14
|
|
|
20
|
-
export default (function () {
|
|
21
15
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
dst(((cp >> 6) & 0x1F) | 0xC0), dst((cp & 0x3F) | 0x80);
|
|
46
|
-
else if (cp < 0x10000)
|
|
47
|
-
dst(((cp >> 12) & 0x0F) | 0xE0), dst(((cp >> 6) & 0x3F) | 0x80), dst((cp & 0x3F) | 0x80);
|
|
48
|
-
else
|
|
49
|
-
dst(((cp >> 18) & 0x07) | 0xF0), dst(((cp >> 12) & 0x3F) | 0x80), dst(((cp >> 6) & 0x3F) | 0x80), dst((cp & 0x3F) | 0x80);
|
|
50
|
-
cp = null;
|
|
51
|
-
}
|
|
52
|
-
};
|
|
16
|
+
/**
|
|
17
|
+
* Encodes UTF8 code points to UTF8 bytes.
|
|
18
|
+
* @param {(!function():number|null) | number} src Code points source, either as a function returning the next code point
|
|
19
|
+
* respectively `null` if there are no more code points left or a single numeric code point.
|
|
20
|
+
* @param {!function(number)} dst Bytes destination as a function successively called with the next byte
|
|
21
|
+
* @expose
|
|
22
|
+
*/
|
|
23
|
+
function encodeUTF8(src: (() => number | null) | number, dst: (cp: number) => void): void {
|
|
24
|
+
var cp = null;
|
|
25
|
+
if (typeof src === 'number')
|
|
26
|
+
cp = src, src = function () { return null; };
|
|
27
|
+
while (cp !== null || (cp = src()) !== null) {
|
|
28
|
+
if (cp < 0x80)
|
|
29
|
+
dst(cp & 0x7F);
|
|
30
|
+
else if (cp < 0x800)
|
|
31
|
+
dst(((cp >> 6) & 0x1F) | 0xC0), dst((cp & 0x3F) | 0x80);
|
|
32
|
+
else if (cp < 0x10000)
|
|
33
|
+
dst(((cp >> 12) & 0x0F) | 0xE0), dst(((cp >> 6) & 0x3F) | 0x80), dst((cp & 0x3F) | 0x80);
|
|
34
|
+
else
|
|
35
|
+
dst(((cp >> 18) & 0x07) | 0xF0), dst(((cp >> 12) & 0x3F) | 0x80), dst(((cp >> 6) & 0x3F) | 0x80), dst((cp & 0x3F) | 0x80);
|
|
36
|
+
cp = null;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
53
39
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
40
|
+
/**
|
|
41
|
+
* Converts UTF16 characters to UTF8 code points.
|
|
42
|
+
* @param {!function():number|null} src Characters source as a function returning the next char code respectively
|
|
43
|
+
* `null` if there are no more characters left.
|
|
44
|
+
* @param {!function(number)} dst Code points destination as a function successively called with each converted code
|
|
45
|
+
* point.
|
|
46
|
+
* @expose
|
|
47
|
+
*/
|
|
48
|
+
function UTF16toUTF8(src: () => number | null, dst: (cp: number) => void): void {
|
|
49
|
+
var c1, c2 = null;
|
|
50
|
+
// eslint-disable-next-line no-constant-condition
|
|
51
|
+
while (true) {
|
|
52
|
+
if ((c1 = c2 !== null ? c2 : src()) === null)
|
|
53
|
+
break;
|
|
54
|
+
if (c1 >= 0xD800 && c1 <= 0xDFFF) {
|
|
55
|
+
if ((c2 = src()) !== null) {
|
|
56
|
+
if (c2 >= 0xDC00 && c2 <= 0xDFFF) {
|
|
57
|
+
dst((c1 - 0xD800) * 0x400 + c2 - 0xDC00 + 0x10000);
|
|
58
|
+
c2 = null; continue;
|
|
74
59
|
}
|
|
75
60
|
}
|
|
76
|
-
dst(c1);
|
|
77
61
|
}
|
|
78
|
-
|
|
79
|
-
}
|
|
62
|
+
dst(c1);
|
|
63
|
+
}
|
|
64
|
+
if (c2 !== null) dst(c2);
|
|
65
|
+
}
|
|
80
66
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
67
|
+
/**
|
|
68
|
+
* Converts and encodes UTF16 characters to UTF8 bytes.
|
|
69
|
+
* @param {!function():number|null} src Characters source as a function returning the next char code respectively `null`
|
|
70
|
+
* if there are no more characters left.
|
|
71
|
+
* @param {!function(number)} dst Bytes destination as a function successively called with the next byte.
|
|
72
|
+
* @expose
|
|
73
|
+
*/
|
|
74
|
+
export function encodeUTF16toUTF8(src: () => number | null, dst: (...args: number[]) => string | undefined): void {
|
|
75
|
+
UTF16toUTF8(src, function (cp) {
|
|
76
|
+
encodeUTF8(cp, dst);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
93
79
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
80
|
+
/**
|
|
81
|
+
* String.fromCharCode reference for compile time renaming.
|
|
82
|
+
* @type {!function(...[number]):string}
|
|
83
|
+
* @inner
|
|
84
|
+
*/
|
|
85
|
+
var stringFromCharCode = String.fromCharCode;
|
|
100
86
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
};
|
|
87
|
+
/**
|
|
88
|
+
* Creates a source function for a string.
|
|
89
|
+
* @param {string} s String to read from
|
|
90
|
+
* @returns {!function():number|null} Source function returning the next char code respectively `null` if there are
|
|
91
|
+
* no more characters left.
|
|
92
|
+
* @throws {TypeError} If the argument is invalid
|
|
93
|
+
* @expose
|
|
94
|
+
*/
|
|
95
|
+
export function stringSource(s: string): () => number | null {
|
|
96
|
+
if (typeof s !== 'string')
|
|
97
|
+
throw TypeError('Illegal argument: ' + (typeof s));
|
|
98
|
+
var i = 0; return function () {
|
|
99
|
+
return i >= s.length ? null : s.charCodeAt(i++);
|
|
115
100
|
};
|
|
101
|
+
}
|
|
116
102
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
};
|
|
103
|
+
/**
|
|
104
|
+
* Creates a destination function for a string.
|
|
105
|
+
* @returns {function(number=):undefined|string} Destination function successively called with the next char code.
|
|
106
|
+
* Returns the final string when called without arguments.
|
|
107
|
+
* @expose
|
|
108
|
+
*/
|
|
109
|
+
export function stringDestination(): (...args: number[]) => string | undefined {
|
|
110
|
+
const cs: number[] = [], ps: string[] = []; return function () {
|
|
111
|
+
if (arguments.length === 0)
|
|
112
|
+
return ps.join('') + stringFromCharCode.apply(String, cs);
|
|
113
|
+
if (cs.length + arguments.length > 1024)
|
|
114
|
+
ps.push(stringFromCharCode.apply(String, cs)), cs.length = 0; // @ts-ignore
|
|
115
|
+
Array.prototype.push.apply(cs, arguments);
|
|
131
116
|
};
|
|
132
|
-
|
|
133
|
-
return utfx;
|
|
134
|
-
|
|
135
|
-
})();
|
|
117
|
+
}
|
|
@@ -37,16 +37,19 @@ export default function promiseWrapper<T>(customPromise: Promise<T>, defaultOnRe
|
|
|
37
37
|
|
|
38
38
|
const originalThen = newPromise.then;
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
40
|
+
// Using `defineProperty` in case Promise.prototype.then property is not writable
|
|
41
|
+
Object.defineProperty(newPromise, 'then', {
|
|
42
|
+
value: function (onfulfilled: any, onrejected: any) {
|
|
43
|
+
const result: Promise<any> = originalThen.call(newPromise, onfulfilled, onrejected);
|
|
44
|
+
if (typeof onfulfilled === 'function') hasOnFulfilled = true;
|
|
45
|
+
if (typeof onrejected === 'function') {
|
|
46
|
+
hasOnRejected = true;
|
|
47
|
+
return result;
|
|
48
|
+
} else {
|
|
49
|
+
return chain(result);
|
|
50
|
+
}
|
|
48
51
|
}
|
|
49
|
-
};
|
|
52
|
+
});
|
|
50
53
|
|
|
51
54
|
return newPromise;
|
|
52
55
|
}
|