1.3.0 • Published 3 years ago

adaptive-loading-helper v1.3.0

Weekly downloads
5
License
MIT
Repository
github
Last release
3 years ago

Build Status Known Vulnerabilities Downloads npm license

Adaptive loading helper 🚀

Helper util to get info about the target platform performance

Use Cases

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

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

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

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

        //4g does not mean fast!
        if (adaptiveData.network.connection === '4g' || adaptiveData.network.downlink > 6) {
            await import('./costly-module.js');
        }
  6. 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}
1.2.3

3 years ago

1.2.2

3 years ago

1.3.0

3 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.1.0

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago