@hyperlink/ups-status

Node.Js API to get status of UPS connected to your MacOS

Usage no npm install needed!

<script type="module">
  import hyperlinkUpsStatus from 'https://cdn.skypack.dev/@hyperlink/ups-status';
</script>

README

UPS Status 🔌 for Node JS

Version License: ISC Twitter: hyperlink

Node.Js API to get status of UPS connected to your MacOS

Install

npm install @hyperlink/ups-status

Usage

Two different ways to use this module. You can Promise interface or EventEmitter interface.

Promise interface

import { isOnBattery, isOnAc } from '@hyperlink/ups-status';

// in some async function
if (await isOnBattery()) {
  console.log('Mac is running on Battery');
} else {
  console.log('Mac is on AC');
}

// or

// in some async function
if (await isOnAc()) {
  console.log('Mac is on AC');
  } else {
  console.log('Mac is running on Battery');
}

EventEmitter interface.

UpsEmitter will emit 'ac' event with true or false value when AC is connected or not.

import { UpsEmitter } from '@hyperlink/ups-status';

const ups = new UpsEmitter();
ups.on('ac', isOnAc => console.log('computer is on ac:', isOnAc));

Author

👤 Xiaoxin Lu javascript@yahoo.com

Show your support

Give a ⭐️ if this project helped you!