A zero-dependency utility to check if a Mac is connected to a power outlet or running on battery. This is a lightweight replacement for is-charging, which has 27 dependencies and critical vulnerabilities that cannot be patched.
This utility is useful if your application needs to know whether it can run in full capacity (drawing lots of power) or if it should switch to a low-capacity mode.
- Zero dependencies
- Safe and secure
- Simple API
npm install telia-oss/osx-is-chargingimport { isCharging } from 'osx-is-charging';
async function checkChargingStatus() {
try {
const charging = await isCharging();
console.log('Is charging:', charging);
} catch (error) {
console.error('Error:', error.message);
}
}
checkChargingStatus();See example.js for a complete example.
MIT