adaptive-loading-helper

1.3.0 • Public • Published

Build Status Known Vulnerabilities Downloads npm license

Adaptive loading helper 🚀

Helper util to get info about the target platform performance

Use Cases

  1. 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');
        }
  2. CPU 💻

        if (adaptiveData.cpu > 4) {
            await import('./costly-module.js');
        }
  3. Memory 📝

        if (adaptiveData.memory > 1) {
            await import('./costly-module.js');
        }
  4. Storage 💾

        const fiftyMegabytesInBytes = 50 * 1e+6;
    
        if (adaptiveData.quota > fiftyMegabytesInBytes) {
            await import('./costly-module.js');
        }
  5. Network 🌐

        //4g does not mean fast!
        if (adaptiveData.network.connection === '4g' || adaptiveData.network.downlink > 6) {
            await import('./costly-module.js');
        }
  6. Mobile 📱

        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}

Readme

Keywords

Package Sidebar

Install

npm i adaptive-loading-helper

Weekly Downloads

2

Version

1.3.0

License

MIT

Unpacked Size

11.9 kB

Total Files

8

Last publish

Collaborators

  • fjancsi