Skip to content

Commit

Permalink
Merge pull request #253 from Barma-lej/dev
Browse files Browse the repository at this point in the history
Added `stopPropagation` and `wifiStrenghtToQuality`
  • Loading branch information
Barma-lej committed Jan 10, 2024
2 parents 2302f05 + 806b4f5 commit 2ba55f9
Showing 1 changed file with 113 additions and 0 deletions.
113 changes: 113 additions & 0 deletions src/helpers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Helpers file

export const stopPropagation = (ev) => ev.stopPropagation();

/**
* Checking whether an object
* @param {Object} Value to check
Expand All @@ -8,3 +10,114 @@
export function isObject(obj) {
return Object.prototype.toString.call(obj) === '[object Object]';
}

/**
* Convert WiFi signal strength (dBm) to WiFi Quality (%)
* @param {integer} WiFi signal strength in dBm
* @return {Boolean}
*/
export function wifiStrenghtToQuality(rssi) {
const qualtable = {
1: 100,
2: 100,
3: 100,
4: 100,
5: 100,
6: 100,
7: 100,
8: 100,
9: 100,
10: 100,
11: 100,
12: 100,
13: 100,
14: 100,
15: 100,
16: 100,
17: 100,
18: 100,
19: 100,
20: 100,
21: 99,
22: 99,
23: 99,
24: 98,
25: 98,
26: 98,
27: 97,
28: 97,
29: 96,
30: 96,
31: 95,
32: 95,
33: 94,
34: 93,
35: 93,
36: 92,
37: 91,
38: 90,
39: 90,
40: 89,
41: 88,
42: 87,
43: 86,
44: 85,
45: 84,
46: 83,
47: 82,
48: 81,
49: 80,
50: 79,
51: 78,
52: 76,
53: 75,
54: 74,
55: 73,
56: 71,
57: 70,
58: 69,
59: 67,
60: 66,
61: 64,
62: 63,
63: 61,
64: 60,
65: 58,
66: 56,
67: 55,
68: 53,
69: 51,
70: 50,
71: 48,
72: 46,
73: 44,
74: 42,
75: 40,
76: 38,
77: 36,
78: 34,
79: 32,
80: 30,
81: 28,
82: 26,
83: 24,
84: 22,
85: 20,
86: 17,
87: 15,
88: 13,
89: 10,
90: 8,
91: 6,
92: 3,
93: 1,
94: 1,
95: 1,
96: 1,
97: 1,
98: 1,
99: 1,
100: 1,
};
return rssi < 0 && rssi > -101 ? qualtable[Math.abs(rssi)] + ' %' : 0;
}

0 comments on commit 2ba55f9

Please sign in to comment.