1.3.0 • Published 3 years ago
adaptive-loading-helper v1.3.0
Adaptive loading helper 🚀
Helper util to get info about the target platform performance
Use Cases
Battery :battery:
// If the device is currently charging // Or the battery level is more than 20% if (adaptiveData.battery.charging || adaptiveData.battery.level > 0.2) { await import('./costly-module.js'); }
CPU :computer:
if (adaptiveData.cpu > 4) { await import('./costly-module.js'); }
Memory :memo:
if (adaptiveData.memory > 1) { await import('./costly-module.js'); }
Storage :floppy_disk:
const fiftyMegabytesInBytes = 50 * 1e+6; if (adaptiveData.quota > fiftyMegabytesInBytes) { await import('./costly-module.js'); }
Network :globe_with_meridians:
//4g does not mean fast! if (adaptiveData.network.connection === '4g' || adaptiveData.network.downlink > 6) { await import('./costly-module.js'); }
Mobile :iphone:
if (!adaptiveData.isMobile) { await import('./costly-module.js'); }
Example
$ npm install adaptive-loading-helper
const { getAdaptiveLoadingData } = require('adaptive-loading-helper');
// ES2015 modules
import getAdaptiveLoadingData from 'adaptive-loading-helper';
const adaptiveData = await getAdaptiveLoadingData();
console.log(adaptiveData);
// {"battery": {"charging": true, "level": 3}, "cpu": 6, "memory": 8, "network": {"connection": "4g", "downlink": 6}, "quota": 50000000}