devicer.js 1.0.10 → 1.0.11
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/package.json
CHANGED
package/src/libs/confidence.js
CHANGED
package/src/libs/confidence.ts
CHANGED
|
@@ -45,7 +45,9 @@ export function compareArrays(
|
|
|
45
45
|
);
|
|
46
46
|
fields += subData[0] - 1; // Subtract 1 for the index itself
|
|
47
47
|
matches += subData[1];
|
|
48
|
-
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
else if (
|
|
49
51
|
(typeof sortedArr1[i] == "object" && sortedArr1[i]) &&
|
|
50
52
|
(typeof sortedArr2[i] == "object" && sortedArr2[i])
|
|
51
53
|
) {
|
|
@@ -92,13 +94,15 @@ export function compareDatasets(
|
|
|
92
94
|
);
|
|
93
95
|
fields += subData[0] - 1; // Subtract 1 for the key itself
|
|
94
96
|
matches += subData[1];
|
|
95
|
-
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
else if (Array.isArray(data1[key]) && Array.isArray(data2[key])) {
|
|
96
100
|
const subData = compareArrays(data1[key], data2[key], max_depth - 1);
|
|
97
101
|
fields += subData[0] - 1; // Subtract 1 for the key itself
|
|
98
102
|
matches += subData[1];
|
|
99
103
|
}
|
|
100
104
|
|
|
101
|
-
if (data1[key] == data2[key]) {
|
|
105
|
+
else if (data1[key] == data2[key]) {
|
|
102
106
|
matches++;
|
|
103
107
|
}
|
|
104
108
|
}
|
|
@@ -1,74 +1,92 @@
|
|
|
1
|
-
import { describe,
|
|
2
|
-
import { compareArrays, compareDatasets } from
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { compareArrays, compareDatasets } from "../src/libs/confidence";
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const sampleData1 = {"userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36 Edg/138.0.0.0","platform":"Win32","timezone":"America/Chicago","language":"en-US","languages":["en-US","en","es","la"],"cookieEnabled":true,"doNotTrack":"1","hardwareConcurrency":8,"deviceMemory":8,"product":"Gecko","productSub":"20030107","vendor":"Google Inc.","vendorSub":"unknown","appName":"Netscape","appVersion":"5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36 Edg/138.0.0.0","appCodeName":"Mozilla","appMinorVersion":"unknown","buildID":"unknown","plugins":[{"name":"PDF Viewer","description":"Portable Document Format"},{"name":"Chrome PDF Viewer","description":"Portable Document Format"},{"name":"Chromium PDF Viewer","description":"Portable Document Format"},{"name":"Microsoft Edge PDF Viewer","description":"Portable Document Format"},{"name":"WebKit built-in PDF","description":"Portable Document Format"}],"mimeTypes":[{"type":"application/pdf","suffixes":"pdf","description":"Portable Document Format"},{"type":"text/pdf","suffixes":"pdf","description":"Portable Document Format"}],"screen":{"width":1920,"height":1080,"colorDepth":24,"pixelDepth":24,"orientation":{"type":"landscape-primary","angle":0}},"highEntropyValues":{"architecture":"x86","bitness":"64","brands":[{"brand":"Not)A;Brand","version":"8"},{"brand":"Chromium","version":"138"},{"brand":"Microsoft Edge","version":"138"}],"mobile":false,"model":"","platform":"Windows","platformVersion":"19.0.0","uaFullVersion":"138.0.3351.34"}};
|
|
5
|
+
|
|
6
|
+
const sampleData2 = {"userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36","platform":"Win32","timezone":"America/Chicago","language":"en-US","languages":["en-US","en"],"cookieEnabled":true,"hardwareConcurrency":16,"deviceMemory":8,"product":"Gecko","productSub":"20030107","vendor":"Google Inc.","vendorSub":"unknown","appName":"Netscape","appVersion":"5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36","appCodeName":"Mozilla","appMinorVersion":"unknown","buildID":"unknown","plugins":[{"name":"PDF Viewer","description":"Portable Document Format"},{"name":"Chrome PDF Viewer","description":"Portable Document Format"},{"name":"Chromium PDF Viewer","description":"Portable Document Format"},{"name":"Microsoft Edge PDF Viewer","description":"Portable Document Format"},{"name":"WebKit built-in PDF","description":"Portable Document Format"}],"mimeTypes":[{"type":"application/pdf","suffixes":"pdf","description":"Portable Document Format"},{"type":"text/pdf","suffixes":"pdf","description":"Portable Document Format"}],"screen":{"width":1920,"height":1080,"colorDepth":24,"pixelDepth":24,"orientation":{"type":"landscape-primary","angle":0}},"highEntropyValues":{"architecture":"x86","bitness":"64","brands":[{"brand":"Google Chrome","version":"137"},{"brand":"Chromium","version":"137"},{"brand":"Not/A)Brand","version":"24"}],"mobile":false,"model":"","platform":"Windows","platformVersion":"19.0.0","uaFullVersion":"137.0.7151.119"}};
|
|
7
|
+
|
|
8
|
+
describe("Array Comparison", () => {
|
|
9
|
+
it("should compare two identical arrays", () => {
|
|
6
10
|
const arr1 = [1, 2, 3];
|
|
7
11
|
const arr2 = [1, 2, 3];
|
|
8
12
|
const result = compareArrays(arr1, arr2);
|
|
9
|
-
console.log(
|
|
13
|
+
console.log("Result:", result);
|
|
10
14
|
expect(result).toEqual([3, 3]); // 3 fields, 3 matches
|
|
11
15
|
});
|
|
12
16
|
|
|
13
|
-
it(
|
|
17
|
+
it("should compare two different arrays", () => {
|
|
14
18
|
const arr1 = [1, 2, 3];
|
|
15
19
|
const arr2 = [3, 1, 4];
|
|
16
20
|
const result = compareArrays(arr1, arr2);
|
|
17
|
-
console.log(
|
|
21
|
+
console.log("Result:", result);
|
|
18
22
|
expect(result).toEqual([3, 0]); // 3 fields, 0 matches
|
|
19
23
|
});
|
|
20
24
|
|
|
21
|
-
it(
|
|
25
|
+
it("should handle nested arrays", () => {
|
|
22
26
|
const arr1 = [1, [2, 3], 4];
|
|
23
27
|
const arr2 = [1, [2, 3], 5];
|
|
24
28
|
const result = compareArrays(arr1, arr2);
|
|
25
|
-
console.log(
|
|
29
|
+
console.log("Result:", result);
|
|
26
30
|
expect(result).toEqual([4, 3]); // 4 fields, 3 matches
|
|
27
31
|
});
|
|
28
32
|
|
|
29
|
-
it(
|
|
33
|
+
it("should handle empty arrays", () => {
|
|
30
34
|
const arr1: any[] = [];
|
|
31
35
|
const arr2: any[] = [];
|
|
32
36
|
const result = compareArrays(arr1, arr2);
|
|
33
|
-
console.log(
|
|
37
|
+
console.log("Result:", result);
|
|
34
38
|
expect(result).toEqual([0, 0]); // 0 fields, 0 matches
|
|
35
39
|
});
|
|
36
40
|
|
|
37
|
-
it(
|
|
41
|
+
it("should handle arrays with different lengths", () => {
|
|
38
42
|
const arr1 = [1, 2, 3];
|
|
39
43
|
const arr2 = [1, 2];
|
|
40
44
|
const result = compareArrays(arr1, arr2);
|
|
41
|
-
console.log(
|
|
45
|
+
console.log("Result:", result);
|
|
42
46
|
expect(result).toEqual([2, 2]); // 2 fields, 2 matches
|
|
43
47
|
});
|
|
44
48
|
|
|
45
|
-
it(
|
|
49
|
+
it("should handle arrays with undefined values", () => {
|
|
46
50
|
const arr1 = [1, undefined, 3];
|
|
47
51
|
const arr2 = [1, 2, 3];
|
|
48
52
|
const result = compareArrays(arr1, arr2);
|
|
49
|
-
console.log(
|
|
53
|
+
console.log("Result:", result);
|
|
50
54
|
expect(result).toEqual([3, 2]); // 3 fields, 2 matches
|
|
51
55
|
});
|
|
52
56
|
|
|
53
|
-
it(
|
|
57
|
+
it("should handle nested empty arrays", () => {
|
|
54
58
|
const arr1 = [1, [], [[], []], 3];
|
|
55
59
|
const arr2 = [1, [2], [[], []], 3];
|
|
56
60
|
const result = compareArrays(arr1, arr2);
|
|
57
|
-
console.log(
|
|
61
|
+
console.log("Result:", result);
|
|
58
62
|
expect(result).toEqual([3, 2]); // 3 fields, 2 matches
|
|
59
63
|
});
|
|
60
64
|
|
|
61
|
-
it(
|
|
65
|
+
it("should handle arrays of objects", () => {
|
|
62
66
|
const arr1 = [{ a: 1 }, { b: 2 }];
|
|
63
67
|
const arr2 = [{ a: 1 }, { b: 3 }];
|
|
64
68
|
const result = compareArrays(arr1, arr2);
|
|
65
|
-
console.log(
|
|
69
|
+
console.log("Result:", result);
|
|
66
70
|
expect(result).toEqual([2, 1]); // 2 fields, 1 matches
|
|
67
|
-
})
|
|
71
|
+
});
|
|
68
72
|
|
|
69
|
-
it(
|
|
73
|
+
it("should throw an error for max depth exceeded", () => {
|
|
70
74
|
const arr1 = [1, [2, [3, [4, [5, [6]]]]]];
|
|
71
75
|
const arr2 = [1, [2, [3, [4, [5, [6]]]]]];
|
|
72
|
-
expect(() => compareArrays(arr1, arr2, 0)).toThrow(
|
|
76
|
+
expect(() => compareArrays(arr1, arr2, 0)).toThrow("Max depth exceeded");
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
describe("Dataset Comparison", () => {
|
|
81
|
+
it("should compare two identical datasets", () => {
|
|
82
|
+
const result = compareDatasets(sampleData1, sampleData1);
|
|
83
|
+
console.log("Result:", result);
|
|
84
|
+
expect(result).toEqual([56, 56]); // 20 fields, 20 matches
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("should compare two different datasets", () => {
|
|
88
|
+
const result = compareDatasets(sampleData1, sampleData2);
|
|
89
|
+
console.log("Result:", result);
|
|
90
|
+
expect(result).toEqual([53, 44]); // 20 fields, 10 matches
|
|
73
91
|
});
|
|
74
|
-
});
|
|
92
|
+
});
|
package/tests/confidence.test.ts
CHANGED
|
@@ -89,9 +89,7 @@ describe('Confidence Calculation', () => {
|
|
|
89
89
|
ram: 4096
|
|
90
90
|
},
|
|
91
91
|
timezone: 'Europe/London',
|
|
92
|
-
ip: '178.238.11.6'
|
|
93
|
-
languages: ['en-GB', 'en'],
|
|
94
|
-
userAgent: 'Mozilla/5.0 (compatible; Konqueror/2.2.2-3; Linux)'
|
|
92
|
+
ip: '178.238.11.6'
|
|
95
93
|
};
|
|
96
94
|
const confidence = calculateConfidence(sampleData1, partialData);
|
|
97
95
|
console.log('Confidence for partially similar data:', confidence);
|