https://github.com/hyperlink/ups-status
Node.Js API to get status of UPS connected to your MacOS
https://github.com/hyperlink/ups-status
Last synced: over 1 year ago
JSON representation
Node.Js API to get status of UPS connected to your MacOS
- Host: GitHub
- URL: https://github.com/hyperlink/ups-status
- Owner: hyperlink
- License: mit
- Created: 2021-11-13T23:57:25.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-11-16T13:17:28.000Z (over 4 years ago)
- Last Synced: 2025-02-24T12:41:25.284Z (over 1 year ago)
- Language: TypeScript
- Size: 12.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# UPS Status 🔌 for Node JS

[](#)
[](https://twitter.com/hyperlink)
Node.Js API to get status of UPS connected to your MacOS
## Install
```sh
npm install @hyperlink/ups-status
```
## Usage
Two different ways to use this module. You can Promise interface or EventEmitter interface.
### Promise interface
```js
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.
```js
import { UpsEmitter } from '@hyperlink/ups-status';
const ups = new UpsEmitter();
ups.on('ac', isOnAc => console.log('computer is on ac:', isOnAc));
```
## Author
👤 **Xiaoxin Lu **
* Twitter: [@hyperlink](https://twitter.com/hyperlink)
* Github: [@hyperlink](https://github.com/hyperlink)
## Show your support
Give a ⭐️ if this project helped you!