devicer.js 1.0.10 → 1.0.12
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
|
@@ -40,7 +40,7 @@ function compareArrays(arr1, arr2, max_depth = 5) {
|
|
|
40
40
|
fields += subData[0] - 1; // Subtract 1 for the index itself
|
|
41
41
|
matches += subData[1];
|
|
42
42
|
}
|
|
43
|
-
if (
|
|
43
|
+
if (sortedArr1[i] === sortedArr2[i]) {
|
|
44
44
|
matches++;
|
|
45
45
|
}
|
|
46
46
|
}
|
|
@@ -68,7 +68,7 @@ function compareDatasets(data1, data2, max_depth = 5) {
|
|
|
68
68
|
fields += subData[0] - 1; // Subtract 1 for the key itself
|
|
69
69
|
matches += subData[1];
|
|
70
70
|
}
|
|
71
|
-
if (data1[key] == data2[key]) {
|
|
71
|
+
else if (data1[key] == data2[key]) {
|
|
72
72
|
matches++;
|
|
73
73
|
}
|
|
74
74
|
}
|
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
|
) {
|
|
@@ -58,7 +60,7 @@ export function compareArrays(
|
|
|
58
60
|
matches += subData[1];
|
|
59
61
|
}
|
|
60
62
|
|
|
61
|
-
if (
|
|
63
|
+
if (sortedArr1[i] === sortedArr2[i]) {
|
|
62
64
|
matches++;
|
|
63
65
|
}
|
|
64
66
|
}
|
|
@@ -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,82 @@
|
|
|
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
|
-
describe(
|
|
5
|
-
it(
|
|
4
|
+
describe("Array Comparison", () => {
|
|
5
|
+
it("should compare two identical arrays", () => {
|
|
6
6
|
const arr1 = [1, 2, 3];
|
|
7
7
|
const arr2 = [1, 2, 3];
|
|
8
8
|
const result = compareArrays(arr1, arr2);
|
|
9
|
-
console.log(
|
|
9
|
+
console.log("Result:", result);
|
|
10
10
|
expect(result).toEqual([3, 3]); // 3 fields, 3 matches
|
|
11
11
|
});
|
|
12
12
|
|
|
13
|
-
it(
|
|
13
|
+
it("should compare two different arrays", () => {
|
|
14
14
|
const arr1 = [1, 2, 3];
|
|
15
|
-
const arr2 = [
|
|
15
|
+
const arr2 = [6, 5, 4];
|
|
16
16
|
const result = compareArrays(arr1, arr2);
|
|
17
|
-
console.log(
|
|
17
|
+
console.log("Result:", result);
|
|
18
18
|
expect(result).toEqual([3, 0]); // 3 fields, 0 matches
|
|
19
19
|
});
|
|
20
20
|
|
|
21
|
-
it(
|
|
21
|
+
it("should handle shuffled arrays with the same elements", () => {
|
|
22
|
+
const arr1 = [1, 2, 3];
|
|
23
|
+
const arr2 = [3, 2, 1];
|
|
24
|
+
const result = compareArrays(arr1, arr2);
|
|
25
|
+
console.log("Result:", result);
|
|
26
|
+
expect(result).toEqual([3, 3]); // 3 fields, 3 matches
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("should handle nested arrays", () => {
|
|
22
30
|
const arr1 = [1, [2, 3], 4];
|
|
23
31
|
const arr2 = [1, [2, 3], 5];
|
|
24
32
|
const result = compareArrays(arr1, arr2);
|
|
25
|
-
console.log(
|
|
33
|
+
console.log("Result:", result);
|
|
26
34
|
expect(result).toEqual([4, 3]); // 4 fields, 3 matches
|
|
27
35
|
});
|
|
28
36
|
|
|
29
|
-
it(
|
|
37
|
+
it("should handle empty arrays", () => {
|
|
30
38
|
const arr1: any[] = [];
|
|
31
39
|
const arr2: any[] = [];
|
|
32
40
|
const result = compareArrays(arr1, arr2);
|
|
33
|
-
console.log(
|
|
41
|
+
console.log("Result:", result);
|
|
34
42
|
expect(result).toEqual([0, 0]); // 0 fields, 0 matches
|
|
35
43
|
});
|
|
36
44
|
|
|
37
|
-
it(
|
|
45
|
+
it("should handle arrays with different lengths", () => {
|
|
38
46
|
const arr1 = [1, 2, 3];
|
|
39
47
|
const arr2 = [1, 2];
|
|
40
48
|
const result = compareArrays(arr1, arr2);
|
|
41
|
-
console.log(
|
|
49
|
+
console.log("Result:", result);
|
|
42
50
|
expect(result).toEqual([2, 2]); // 2 fields, 2 matches
|
|
43
51
|
});
|
|
44
52
|
|
|
45
|
-
it(
|
|
46
|
-
const arr1 = [1,
|
|
53
|
+
it("should handle arrays with undefined values", () => {
|
|
54
|
+
const arr1 = [1, 2, undefined];
|
|
47
55
|
const arr2 = [1, 2, 3];
|
|
48
56
|
const result = compareArrays(arr1, arr2);
|
|
49
|
-
console.log(
|
|
57
|
+
console.log("Result:", result);
|
|
50
58
|
expect(result).toEqual([3, 2]); // 3 fields, 2 matches
|
|
51
59
|
});
|
|
52
60
|
|
|
53
|
-
it(
|
|
61
|
+
it("should handle nested empty arrays", () => {
|
|
54
62
|
const arr1 = [1, [], [[], []], 3];
|
|
55
63
|
const arr2 = [1, [2], [[], []], 3];
|
|
56
64
|
const result = compareArrays(arr1, arr2);
|
|
57
|
-
console.log(
|
|
65
|
+
console.log("Result:", result);
|
|
58
66
|
expect(result).toEqual([3, 2]); // 3 fields, 2 matches
|
|
59
67
|
});
|
|
60
68
|
|
|
61
|
-
it(
|
|
69
|
+
it("should handle arrays of objects", () => {
|
|
62
70
|
const arr1 = [{ a: 1 }, { b: 2 }];
|
|
63
71
|
const arr2 = [{ a: 1 }, { b: 3 }];
|
|
64
72
|
const result = compareArrays(arr1, arr2);
|
|
65
|
-
console.log(
|
|
73
|
+
console.log("Result:", result);
|
|
66
74
|
expect(result).toEqual([2, 1]); // 2 fields, 1 matches
|
|
67
|
-
})
|
|
75
|
+
});
|
|
68
76
|
|
|
69
|
-
it(
|
|
77
|
+
it("should throw an error for max depth exceeded", () => {
|
|
70
78
|
const arr1 = [1, [2, [3, [4, [5, [6]]]]]];
|
|
71
79
|
const arr2 = [1, [2, [3, [4, [5, [6]]]]]];
|
|
72
|
-
expect(() => compareArrays(arr1, arr2, 0)).toThrow(
|
|
80
|
+
expect(() => compareArrays(arr1, arr2, 0)).toThrow("Max depth exceeded");
|
|
73
81
|
});
|
|
74
|
-
});
|
|
82
|
+
});
|
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);
|