-
Notifications
You must be signed in to change notification settings - Fork 110
/
Copy pathisLowEnd.ts
33 lines (31 loc) · 823 Bytes
/
isLowEnd.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { getDM, getHC } from './constants';
import { EffectiveConnectionType } from './types';
export const getIsLowEndDevice = (): boolean => {
// If number of logical processors available to run threads <= 4
if (getHC() && getHC() <= 4) {
return true;
}
// If the approximate amount of RAM client device has <= 4
if (getDM() && getDM() <= 4) {
return true;
}
return false;
};
export const getIsLowEndExperience = (
et: EffectiveConnectionType,
sd: boolean,
): boolean => {
// If the effective type of the connection meaning
// one of 'slow-2g', '2g', '3g', or '4g' is !== 4g
switch (et) {
case 'slow-2g':
return true;
case '2g':
return true;
case '3g':
return true;
default:
// Data Saver preference
return getIsLowEndDevice() || sd;
}
};