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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "devicer.js",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "description": "Open-Source Digital Fingerprinting Middleware",
5
5
  "main": "src/main.js",
6
6
  "scripts": {
@@ -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
  }
@@ -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
- } else if (
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
- } else if (Array.isArray(data1[key]) && Array.isArray(data2[key])) {
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, it, expect } from 'vitest';
2
- import { compareArrays, compareDatasets } from '../src/libs/confidence';
1
+ import { describe, expect, it } from "vitest";
2
+ import { compareArrays, compareDatasets } from "../src/libs/confidence";
3
3
 
4
- describe('Array Comparison', () => {
5
- it('should compare two identical arrays', () => {
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('Result:', result);
13
+ console.log("Result:", result);
10
14
  expect(result).toEqual([3, 3]); // 3 fields, 3 matches
11
15
  });
12
16
 
13
- it('should compare two different arrays', () => {
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('Result:', result);
21
+ console.log("Result:", result);
18
22
  expect(result).toEqual([3, 0]); // 3 fields, 0 matches
19
23
  });
20
24
 
21
- it('should handle nested arrays', () => {
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('Result:', result);
29
+ console.log("Result:", result);
26
30
  expect(result).toEqual([4, 3]); // 4 fields, 3 matches
27
31
  });
28
32
 
29
- it('should handle empty arrays', () => {
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('Result:', result);
37
+ console.log("Result:", result);
34
38
  expect(result).toEqual([0, 0]); // 0 fields, 0 matches
35
39
  });
36
40
 
37
- it('should handle arrays with different lengths', () => {
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('Result:', result);
45
+ console.log("Result:", result);
42
46
  expect(result).toEqual([2, 2]); // 2 fields, 2 matches
43
47
  });
44
48
 
45
- it('should handle arrays with undefined values', () => {
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('Result:', result);
53
+ console.log("Result:", result);
50
54
  expect(result).toEqual([3, 2]); // 3 fields, 2 matches
51
55
  });
52
56
 
53
- it('should handle nested empty arrays', () => {
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('Result:', result);
61
+ console.log("Result:", result);
58
62
  expect(result).toEqual([3, 2]); // 3 fields, 2 matches
59
63
  });
60
64
 
61
- it('should handle arrays of objects', () => {
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('Result:', result);
69
+ console.log("Result:", result);
66
70
  expect(result).toEqual([2, 1]); // 2 fields, 1 matches
67
- })
71
+ });
68
72
 
69
- it('should throw an error for max depth exceeded', () => {
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('Max depth exceeded');
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
+ });
@@ -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);