@ginger-ai/ginger-js 0.0.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/README.md +88 -0
- package/dist/ginger.cjs.js +2 -0
- package/dist/ginger.cjs.js.map +1 -0
- package/dist/ginger.esm.d.ts +294 -0
- package/dist/ginger.esm.js +2 -0
- package/dist/ginger.esm.js.map +1 -0
- package/dist/ginger.umd.js +2 -0
- package/dist/ginger.umd.js.map +1 -0
- package/dist/types/behaviour/index.d.ts +49 -0
- package/dist/types/behaviour/index.d.ts.map +1 -0
- package/dist/types/client/index.d.ts +35 -0
- package/dist/types/client/index.d.ts.map +1 -0
- package/dist/types/core/constants.d.ts +5 -0
- package/dist/types/core/constants.d.ts.map +1 -0
- package/dist/types/core/dto/bot-detector.dto.d.ts +30 -0
- package/dist/types/core/dto/bot-detector.dto.d.ts.map +1 -0
- package/dist/types/core/dto/device-detector.dto.d.ts +54 -0
- package/dist/types/core/dto/device-detector.dto.d.ts.map +1 -0
- package/dist/types/core/dto/fingerprint.dto.d.ts +29 -0
- package/dist/types/core/dto/fingerprint.dto.d.ts.map +1 -0
- package/dist/types/core/dto/ginger.dto.d.ts +73 -0
- package/dist/types/core/dto/ginger.dto.d.ts.map +1 -0
- package/dist/types/core/dto/incognito-detector.dto.d.ts +4 -0
- package/dist/types/core/dto/incognito-detector.dto.d.ts.map +1 -0
- package/dist/types/core/dto/index.d.ts +10 -0
- package/dist/types/core/dto/index.d.ts.map +1 -0
- package/dist/types/core/dto/metrics.dto.d.ts +19 -0
- package/dist/types/core/dto/metrics.dto.d.ts.map +1 -0
- package/dist/types/core/dto/os-detector.dto.d.ts +6 -0
- package/dist/types/core/dto/os-detector.dto.d.ts.map +1 -0
- package/dist/types/core/dto/tor-detector.dto.d.ts +5 -0
- package/dist/types/core/dto/tor-detector.dto.d.ts.map +1 -0
- package/dist/types/core/helpers.d.ts +8 -0
- package/dist/types/core/helpers.d.ts.map +1 -0
- package/dist/types/core/http/httpClient.d.ts +28 -0
- package/dist/types/core/http/httpClient.d.ts.map +1 -0
- package/dist/types/core/http/request.d.ts +4 -0
- package/dist/types/core/http/request.d.ts.map +1 -0
- package/dist/types/core/index.d.ts +6 -0
- package/dist/types/core/index.d.ts.map +1 -0
- package/dist/types/core/util/error.d.ts +25 -0
- package/dist/types/core/util/error.d.ts.map +1 -0
- package/dist/types/core/util/generate-requestid.d.ts +2 -0
- package/dist/types/core/util/generate-requestid.d.ts.map +1 -0
- package/dist/types/device/components/audio/audio.d.ts +2 -0
- package/dist/types/device/components/audio/audio.d.ts.map +1 -0
- package/dist/types/device/components/canvas/canvas.d.ts +3 -0
- package/dist/types/device/components/canvas/canvas.d.ts.map +1 -0
- package/dist/types/device/components/extra/extra.d.ts +19 -0
- package/dist/types/device/components/extra/extra.d.ts.map +1 -0
- package/dist/types/device/components/fonts/fonts.d.ts +3 -0
- package/dist/types/device/components/fonts/fonts.d.ts.map +1 -0
- package/dist/types/device/components/hardware/hardware.d.ts +2 -0
- package/dist/types/device/components/hardware/hardware.d.ts.map +1 -0
- package/dist/types/device/components/index.d.ts +15 -0
- package/dist/types/device/components/index.d.ts.map +1 -0
- package/dist/types/device/components/locales/locales.d.ts +2 -0
- package/dist/types/device/components/locales/locales.d.ts.map +1 -0
- package/dist/types/device/components/math/math.d.ts +2 -0
- package/dist/types/device/components/math/math.d.ts.map +1 -0
- package/dist/types/device/components/permissions/permissions.d.ts +3 -0
- package/dist/types/device/components/permissions/permissions.d.ts.map +1 -0
- package/dist/types/device/components/plugins/plugins.d.ts +3 -0
- package/dist/types/device/components/plugins/plugins.d.ts.map +1 -0
- package/dist/types/device/components/screen/screen.d.ts +2 -0
- package/dist/types/device/components/screen/screen.d.ts.map +1 -0
- package/dist/types/device/components/screen/screenResolution.d.ts +16 -0
- package/dist/types/device/components/screen/screenResolution.d.ts.map +1 -0
- package/dist/types/device/components/system/browser.d.ts +22 -0
- package/dist/types/device/components/system/browser.d.ts.map +1 -0
- package/dist/types/device/components/system/emoji.d.ts +2 -0
- package/dist/types/device/components/system/emoji.d.ts.map +1 -0
- package/dist/types/device/components/system/system.d.ts +2 -0
- package/dist/types/device/components/system/system.d.ts.map +1 -0
- package/dist/types/device/components/webgl/imageHash.d.ts +3 -0
- package/dist/types/device/components/webgl/imageHash.d.ts.map +1 -0
- package/dist/types/device/components/webgl/webgl.d.ts +54 -0
- package/dist/types/device/components/webgl/webgl.d.ts.map +1 -0
- package/dist/types/device/factory.d.ts +26 -0
- package/dist/types/device/factory.d.ts.map +1 -0
- package/dist/types/device/index.d.ts +61 -0
- package/dist/types/device/index.d.ts.map +1 -0
- package/dist/types/device/modules/bot.d.ts +9 -0
- package/dist/types/device/modules/bot.d.ts.map +1 -0
- package/dist/types/device/modules/browserDetails.d.ts +6 -0
- package/dist/types/device/modules/browserDetails.d.ts.map +1 -0
- package/dist/types/device/modules/device/analyze-data.d.ts +7 -0
- package/dist/types/device/modules/device/analyze-data.d.ts.map +1 -0
- package/dist/types/device/modules/device/gather-data.d.ts +6 -0
- package/dist/types/device/modules/device/gather-data.d.ts.map +1 -0
- package/dist/types/device/modules/device/helpers.d.ts +9 -0
- package/dist/types/device/modules/device/helpers.d.ts.map +1 -0
- package/dist/types/device/modules/device/index.d.ts +3 -0
- package/dist/types/device/modules/device/index.d.ts.map +1 -0
- package/dist/types/device/modules/fp.d.ts +14 -0
- package/dist/types/device/modules/fp.d.ts.map +1 -0
- package/dist/types/device/modules/incognito.d.ts +7 -0
- package/dist/types/device/modules/incognito.d.ts.map +1 -0
- package/dist/types/device/modules/options.d.ts +12 -0
- package/dist/types/device/modules/options.d.ts.map +1 -0
- package/dist/types/device/modules/os.d.ts +3 -0
- package/dist/types/device/modules/os.d.ts.map +1 -0
- package/dist/types/device/modules/tor.d.ts +4 -0
- package/dist/types/device/modules/tor.d.ts.map +1 -0
- package/dist/types/device/utils/async.d.ts +33 -0
- package/dist/types/device/utils/async.d.ts.map +1 -0
- package/dist/types/device/utils/browser_.d.ts +103 -0
- package/dist/types/device/utils/browser_.d.ts.map +1 -0
- package/dist/types/device/utils/commonPixels.d.ts +2 -0
- package/dist/types/device/utils/commonPixels.d.ts.map +1 -0
- package/dist/types/device/utils/data.d.ts +33 -0
- package/dist/types/device/utils/data.d.ts.map +1 -0
- package/dist/types/device/utils/dom.d.ts +26 -0
- package/dist/types/device/utils/dom.d.ts.map +1 -0
- package/dist/types/device/utils/ephemeralIFrame.d.ts +5 -0
- package/dist/types/device/utils/ephemeralIFrame.d.ts.map +1 -0
- package/dist/types/device/utils/getMostFrequent.d.ts +6 -0
- package/dist/types/device/utils/getMostFrequent.d.ts.map +1 -0
- package/dist/types/device/utils/hash.d.ts +6 -0
- package/dist/types/device/utils/hash.d.ts.map +1 -0
- package/dist/types/device/utils/misc.d.ts +7 -0
- package/dist/types/device/utils/misc.d.ts.map +1 -0
- package/dist/types/device/utils/raceAll.d.ts +9 -0
- package/dist/types/device/utils/raceAll.d.ts.map +1 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.d.ts.map +1 -0
- package/package.json +52 -0
- package/src/behaviour/index.ts +279 -0
- package/src/client/index.ts +132 -0
- package/src/core/constants.ts +4 -0
- package/src/core/dto/bot-detector.dto.ts +32 -0
- package/src/core/dto/device-detector.dto.ts +67 -0
- package/src/core/dto/fingerprint.dto.ts +38 -0
- package/src/core/dto/ginger.dto.ts +89 -0
- package/src/core/dto/incognito-detector.dto.ts +2 -0
- package/src/core/dto/index.ts +18 -0
- package/src/core/dto/metrics.dto.ts +20 -0
- package/src/core/dto/os-detector.dto.ts +5 -0
- package/src/core/dto/tor-detector.dto.ts +4 -0
- package/src/core/helpers.ts +33 -0
- package/src/core/http/httpClient.ts +52 -0
- package/src/core/http/request.ts +32 -0
- package/src/core/index.ts +5 -0
- package/src/core/util/error.ts +40 -0
- package/src/core/util/generate-requestid.ts +63 -0
- package/src/device/components/audio/audio.ts +58 -0
- package/src/device/components/canvas/canvas.ts +88 -0
- package/src/device/components/extra/extra.ts +581 -0
- package/src/device/components/fonts/fonts.ts +143 -0
- package/src/device/components/hardware/hardware.ts +66 -0
- package/src/device/components/index.ts +14 -0
- package/src/device/components/locales/locales.ts +21 -0
- package/src/device/components/math/math.ts +39 -0
- package/src/device/components/permissions/permissions.ts +60 -0
- package/src/device/components/plugins/plugins.ts +22 -0
- package/src/device/components/screen/screen.ts +13 -0
- package/src/device/components/screen/screenResolution.ts +45 -0
- package/src/device/components/system/browser.ts +838 -0
- package/src/device/components/system/emoji.ts +134 -0
- package/src/device/components/system/system.ts +76 -0
- package/src/device/components/webgl/imageHash.ts +144 -0
- package/src/device/components/webgl/webgl.ts +302 -0
- package/src/device/factory.ts +54 -0
- package/src/device/index.ts +60 -0
- package/src/device/modules/bot.ts +25 -0
- package/src/device/modules/browserDetails.ts +11 -0
- package/src/device/modules/device/analyze-data.ts +150 -0
- package/src/device/modules/device/gather-data.ts +92 -0
- package/src/device/modules/device/helpers.ts +123 -0
- package/src/device/modules/device/index.ts +64 -0
- package/src/device/modules/fp.ts +138 -0
- package/src/device/modules/incognito.ts +253 -0
- package/src/device/modules/options.ts +17 -0
- package/src/device/modules/os.ts +15 -0
- package/src/device/modules/tor.ts +41 -0
- package/src/device/utils/async.ts +106 -0
- package/src/device/utils/browser_.ts +347 -0
- package/src/device/utils/commonPixels.ts +38 -0
- package/src/device/utils/data.ts +161 -0
- package/src/device/utils/dom.ts +148 -0
- package/src/device/utils/ephemeralIFrame.ts +35 -0
- package/src/device/utils/getMostFrequent.ts +39 -0
- package/src/device/utils/hash.ts +202 -0
- package/src/device/utils/misc.ts +18 -0
- package/src/device/utils/raceAll.ts +19 -0
- package/src/index.ts +3 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export async function ephemeralIFrame(callback: ({ iframe }: { iframe: Document }) => void): Promise<any> {
|
|
2
|
+
|
|
3
|
+
while (!document.body) {
|
|
4
|
+
await wait(50)
|
|
5
|
+
}
|
|
6
|
+
const iframe = document.createElement('iframe')
|
|
7
|
+
iframe.setAttribute('frameBorder', '0')
|
|
8
|
+
|
|
9
|
+
const style = iframe.style
|
|
10
|
+
style.setProperty('position','fixed');
|
|
11
|
+
style.setProperty('display', 'block', 'important')
|
|
12
|
+
style.setProperty('visibility', 'visible')
|
|
13
|
+
style.setProperty('border', '0');
|
|
14
|
+
style.setProperty('opacity','0');
|
|
15
|
+
|
|
16
|
+
iframe.src = 'about:blank'
|
|
17
|
+
document.body.appendChild(iframe)
|
|
18
|
+
|
|
19
|
+
const iframeDocument = iframe.contentDocument || iframe.contentWindow?.document;
|
|
20
|
+
if (!iframeDocument) {
|
|
21
|
+
throw new Error('Iframe document is not accessible');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Execute the callback function with access to the iframe's document
|
|
25
|
+
callback({ iframe: iframeDocument });
|
|
26
|
+
|
|
27
|
+
// Clean up after running the callback
|
|
28
|
+
setTimeout(() => {
|
|
29
|
+
document.body.removeChild(iframe);
|
|
30
|
+
}, 0);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function wait<T = void>(durationMs: number, resolveWith?: T): Promise<T> {
|
|
34
|
+
return new Promise((resolve) => setTimeout(resolve, durationMs, resolveWith))
|
|
35
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
function mostFrequentValue(arr: any[]): any | null {
|
|
2
|
+
if (arr.length === 0) {
|
|
3
|
+
return null; // Return null for an empty array
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
const frequencyMap: { [key: string]: number } = {};
|
|
7
|
+
|
|
8
|
+
// Count occurrences of each element in the array
|
|
9
|
+
arr.forEach((element) => {
|
|
10
|
+
const key = String(element);
|
|
11
|
+
frequencyMap[key] = (frequencyMap[key] || 0) + 1;
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
let mostFrequent: any = arr[0]; // Assume the first element is the most frequent
|
|
15
|
+
let highestFrequency = 1; // Frequency of the assumed most frequent element
|
|
16
|
+
|
|
17
|
+
// Find the element with the highest frequency
|
|
18
|
+
Object.keys(frequencyMap).forEach((key) => {
|
|
19
|
+
if (frequencyMap[key] > highestFrequency) {
|
|
20
|
+
mostFrequent = key;
|
|
21
|
+
highestFrequency = frequencyMap[key];
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
return mostFrequent;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function mostFrequentValuesInArrayOfDictionaries(arr: { [key: string]: any }[], keys: string[]): { [key: string]: any } {
|
|
29
|
+
const result: { [key: string]: any } = {};
|
|
30
|
+
|
|
31
|
+
keys.forEach((key) => {
|
|
32
|
+
const valuesForKey = arr.map((obj) => (key in obj ? obj[key] : undefined)).filter((val) => val !== undefined);
|
|
33
|
+
const mostFrequentValueForKey = mostFrequentValue(valuesForKey);
|
|
34
|
+
if (mostFrequentValueForKey)
|
|
35
|
+
result[key] = mostFrequentValueForKey;
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code is taken from https://github.com/LinusU/murmur-128/blob/master/index.js
|
|
3
|
+
* But instead of dependencies to encode-utf8 and fmix, I've implemented them here.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
function encodeUtf8(text: string): any {
|
|
7
|
+
const encoder = new TextEncoder();
|
|
8
|
+
return encoder.encode(text).buffer;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function fmix (input : number) : number {
|
|
12
|
+
input ^= (input >>> 16)
|
|
13
|
+
input = Math.imul(input, 0x85ebca6b)
|
|
14
|
+
input ^= (input >>> 13)
|
|
15
|
+
input = Math.imul(input, 0xc2b2ae35)
|
|
16
|
+
input ^= (input >>> 16)
|
|
17
|
+
|
|
18
|
+
return (input >>> 0)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const C = new Uint32Array([
|
|
22
|
+
0x239b961b,
|
|
23
|
+
0xab0e9789,
|
|
24
|
+
0x38b34ae5,
|
|
25
|
+
0xa1e38b93
|
|
26
|
+
])
|
|
27
|
+
|
|
28
|
+
function rotl (m : number, n : number) : number {
|
|
29
|
+
return (m << n) | (m >>> (32 - n))
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function body (key : ArrayBuffer, hash : Uint32Array) {
|
|
33
|
+
const blocks = (key.byteLength / 16) | 0
|
|
34
|
+
const view32 = new Uint32Array(key, 0, blocks * 4)
|
|
35
|
+
|
|
36
|
+
for (let i = 0; i < blocks; i++) {
|
|
37
|
+
const k = view32.subarray(i * 4, (i + 1) * 4)
|
|
38
|
+
|
|
39
|
+
k[0] = Math.imul(k[0], C[0])
|
|
40
|
+
k[0] = rotl(k[0], 15)
|
|
41
|
+
k[0] = Math.imul(k[0], C[1])
|
|
42
|
+
|
|
43
|
+
hash[0] = (hash[0] ^ k[0])
|
|
44
|
+
hash[0] = rotl(hash[0], 19)
|
|
45
|
+
hash[0] = (hash[0] + hash[1])
|
|
46
|
+
hash[0] = Math.imul(hash[0], 5) + 0x561ccd1b
|
|
47
|
+
|
|
48
|
+
k[1] = Math.imul(k[1], C[1])
|
|
49
|
+
k[1] = rotl(k[1], 16)
|
|
50
|
+
k[1] = Math.imul(k[1], C[2])
|
|
51
|
+
|
|
52
|
+
hash[1] = (hash[1] ^ k[1])
|
|
53
|
+
hash[1] = rotl(hash[1], 17)
|
|
54
|
+
hash[1] = (hash[1] + hash[2])
|
|
55
|
+
hash[1] = Math.imul(hash[1], 5) + 0x0bcaa747
|
|
56
|
+
|
|
57
|
+
k[2] = Math.imul(k[2], C[2])
|
|
58
|
+
k[2] = rotl(k[2], 17)
|
|
59
|
+
k[2] = Math.imul(k[2], C[3])
|
|
60
|
+
|
|
61
|
+
hash[2] = (hash[2] ^ k[2])
|
|
62
|
+
hash[2] = rotl(hash[2], 15)
|
|
63
|
+
hash[2] = (hash[2] + hash[3])
|
|
64
|
+
hash[2] = Math.imul(hash[2], 5) + 0x96cd1c35
|
|
65
|
+
|
|
66
|
+
k[3] = Math.imul(k[3], C[3])
|
|
67
|
+
k[3] = rotl(k[3], 18)
|
|
68
|
+
k[3] = Math.imul(k[3], C[0])
|
|
69
|
+
|
|
70
|
+
hash[3] = (hash[3] ^ k[3])
|
|
71
|
+
hash[3] = rotl(hash[3], 13)
|
|
72
|
+
hash[3] = (hash[3] + hash[0])
|
|
73
|
+
hash[3] = Math.imul(hash[3], 5) + 0x32ac3b17
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function tail (key : ArrayBuffer, hash : Uint32Array) {
|
|
78
|
+
const blocks = (key.byteLength / 16) | 0
|
|
79
|
+
const reminder = (key.byteLength % 16)
|
|
80
|
+
|
|
81
|
+
const k = new Uint32Array(4)
|
|
82
|
+
const tail = new Uint8Array(key, blocks * 16, reminder)
|
|
83
|
+
|
|
84
|
+
switch (reminder) {
|
|
85
|
+
case 15:
|
|
86
|
+
k[3] = (k[3] ^ (tail[14] << 16))
|
|
87
|
+
break// fallthrough
|
|
88
|
+
case 14:
|
|
89
|
+
k[3] = (k[3] ^ (tail[13] << 8))
|
|
90
|
+
break// fallthrough
|
|
91
|
+
case 13:
|
|
92
|
+
k[3] = (k[3] ^ (tail[12] << 0))
|
|
93
|
+
|
|
94
|
+
k[3] = Math.imul(k[3], C[3])
|
|
95
|
+
k[3] = rotl(k[3], 18)
|
|
96
|
+
k[3] = Math.imul(k[3], C[0])
|
|
97
|
+
hash[3] = (hash[3] ^ k[3])
|
|
98
|
+
break
|
|
99
|
+
// fallthrough
|
|
100
|
+
case 12:
|
|
101
|
+
k[2] = (k[2] ^ (tail[11] << 24))
|
|
102
|
+
break// fallthrough
|
|
103
|
+
case 11:
|
|
104
|
+
k[2] = (k[2] ^ (tail[10] << 16))
|
|
105
|
+
break// fallthrough
|
|
106
|
+
case 10:
|
|
107
|
+
k[2] = (k[2] ^ (tail[9] << 8))
|
|
108
|
+
break// fallthrough
|
|
109
|
+
case 9:
|
|
110
|
+
k[2] = (k[2] ^ (tail[8] << 0))
|
|
111
|
+
|
|
112
|
+
k[2] = Math.imul(k[2], C[2])
|
|
113
|
+
k[2] = rotl(k[2], 17)
|
|
114
|
+
k[2] = Math.imul(k[2], C[3])
|
|
115
|
+
hash[2] = (hash[2] ^ k[2])
|
|
116
|
+
break
|
|
117
|
+
// fallthrough
|
|
118
|
+
case 8:
|
|
119
|
+
k[1] = (k[1] ^ (tail[7] << 24))
|
|
120
|
+
break// fallthrough
|
|
121
|
+
case 7:
|
|
122
|
+
k[1] = (k[1] ^ (tail[6] << 16))
|
|
123
|
+
break// fallthrough
|
|
124
|
+
case 6:
|
|
125
|
+
k[1] = (k[1] ^ (tail[5] << 8))
|
|
126
|
+
break// fallthrough
|
|
127
|
+
case 5:
|
|
128
|
+
k[1] = (k[1] ^ (tail[4] << 0))
|
|
129
|
+
|
|
130
|
+
k[1] = Math.imul(k[1], C[1])
|
|
131
|
+
k[1] = rotl(k[1], 16)
|
|
132
|
+
k[1] = Math.imul(k[1], C[2])
|
|
133
|
+
hash[1] = (hash[1] ^ k[1])
|
|
134
|
+
break
|
|
135
|
+
// fallthrough
|
|
136
|
+
case 4:
|
|
137
|
+
k[0] = (k[0] ^ (tail[3] << 24))
|
|
138
|
+
break// fallthrough
|
|
139
|
+
case 3:
|
|
140
|
+
k[0] = (k[0] ^ (tail[2] << 16))
|
|
141
|
+
break// fallthrough
|
|
142
|
+
case 2:
|
|
143
|
+
k[0] = (k[0] ^ (tail[1] << 8))
|
|
144
|
+
break// fallthrough
|
|
145
|
+
case 1:
|
|
146
|
+
k[0] = (k[0] ^ (tail[0] << 0))
|
|
147
|
+
|
|
148
|
+
k[0] = Math.imul(k[0], C[0])
|
|
149
|
+
k[0] = rotl(k[0], 15)
|
|
150
|
+
k[0] = Math.imul(k[0], C[1])
|
|
151
|
+
hash[0] = (hash[0] ^ k[0])
|
|
152
|
+
break
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function finalize (key : ArrayBuffer, hash : Uint32Array) {
|
|
157
|
+
hash[0] = (hash[0] ^ key.byteLength)
|
|
158
|
+
hash[1] = (hash[1] ^ key.byteLength)
|
|
159
|
+
hash[2] = (hash[2] ^ key.byteLength)
|
|
160
|
+
hash[3] = (hash[3] ^ key.byteLength)
|
|
161
|
+
|
|
162
|
+
hash[0] = (hash[0] + hash[1]) | 0
|
|
163
|
+
hash[0] = (hash[0] + hash[2]) | 0
|
|
164
|
+
hash[0] = (hash[0] + hash[3]) | 0
|
|
165
|
+
|
|
166
|
+
hash[1] = (hash[1] + hash[0]) | 0
|
|
167
|
+
hash[2] = (hash[2] + hash[0]) | 0
|
|
168
|
+
hash[3] = (hash[3] + hash[0]) | 0
|
|
169
|
+
|
|
170
|
+
hash[0] = fmix(hash[0])
|
|
171
|
+
hash[1] = fmix(hash[1])
|
|
172
|
+
hash[2] = fmix(hash[2])
|
|
173
|
+
hash[3] = fmix(hash[3])
|
|
174
|
+
|
|
175
|
+
hash[0] = (hash[0] + hash[1]) | 0
|
|
176
|
+
hash[0] = (hash[0] + hash[2]) | 0
|
|
177
|
+
hash[0] = (hash[0] + hash[3]) | 0
|
|
178
|
+
|
|
179
|
+
hash[1] = (hash[1] + hash[0]) | 0
|
|
180
|
+
hash[2] = (hash[2] + hash[0]) | 0
|
|
181
|
+
hash[3] = (hash[3] + hash[0]) | 0
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export function hash (key : ArrayBuffer | string, seed = 0) : string {
|
|
185
|
+
seed = (seed ? (seed | 0) : 0)
|
|
186
|
+
|
|
187
|
+
if (typeof key === 'string') {
|
|
188
|
+
key = encodeUtf8(key)
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (!(key instanceof ArrayBuffer)) {
|
|
192
|
+
throw new TypeError('Expected key to be ArrayBuffer or string')
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const hash = new Uint32Array([seed, seed, seed, seed])
|
|
196
|
+
|
|
197
|
+
body(key, hash)
|
|
198
|
+
tail(key, hash)
|
|
199
|
+
finalize(key, hash)
|
|
200
|
+
const byteArray = new Uint8Array(hash.buffer);
|
|
201
|
+
return Array.from(byteArray).map(byte => byte.toString(16).padStart(2, '0')).join('');
|
|
202
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts an error object to a plain object that can be used with `JSON.stringify`.
|
|
3
|
+
* If you just run `JSON.stringify(error)`, you'll get `'{}'`.
|
|
4
|
+
*/
|
|
5
|
+
export function errorToObject(error: Readonly<Error>): Record<string, unknown> {
|
|
6
|
+
return {
|
|
7
|
+
name: error.name,
|
|
8
|
+
message: error.message,
|
|
9
|
+
stack: error.stack?.split('\n'),
|
|
10
|
+
// The fields are not enumerable, so TS is wrong saying that they will be overridden
|
|
11
|
+
...(error as Omit<Error, 'name' | 'message'>),
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function isFunctionNative(func: (...args: unknown[]) => unknown): boolean {
|
|
16
|
+
return /^function\s.*?\{\s*\[native code]\s*}$/.test(String(func))
|
|
17
|
+
}
|
|
18
|
+
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
type DelayedPromise<T> = Promise<T>;
|
|
2
|
+
|
|
3
|
+
export function delay<T>(t: number, val: T): DelayedPromise<T> {
|
|
4
|
+
return new Promise<T>((resolve) => {
|
|
5
|
+
setTimeout(() => resolve(val), t);
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
export interface RaceResult<T> {
|
|
11
|
+
value: T;
|
|
12
|
+
elapsed?: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function raceAll<T>(promises: Promise<T>[], timeoutTime: number, timeoutVal: T): Promise<(T | undefined)[]> {
|
|
16
|
+
return Promise.all(promises.map((p) => {
|
|
17
|
+
return Promise.race([p, delay(timeoutTime, timeoutVal)]);
|
|
18
|
+
}));
|
|
19
|
+
}
|
package/src/index.ts
ADDED