diff --git a/CHANGELOG.md b/CHANGELOG.md index 30f4ee1..0f57948 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog + +## Major release - Version 2 + +> New features release + +## Features introduced + +- Adding batteryState() battery level | isCharging +- More lightweight and reliable + ## Major release - Version 1 > initial release @@ -16,6 +26,7 @@ | Version | Date | Comment | | ------- | --------- | ----------------------------------------------------------- | +| 2.1.4 | 2024-5-24 | Adding batteryState() battery level | isCharging | | 1.1.4 | 2024-5-17 | Changing batteryData() to batteryInfo() | | 1.1.3 | 2024-5-02 | Making the code more reliable / adding better error handler | | 1.0.3 | 2024-4-26 | Deleting file shouldn't be there | diff --git a/README.md b/README.md index 6ff5a0d..fbaec80 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,7 @@ - Get battery health (Accurate reads) - Get battery information (Serial number , Battery id , Capacity ..) +- Battery realtime level - Lightweight and reliable ## 🚀 Features will added @@ -56,7 +57,7 @@ - Cross platform support - Getting laptop model - Getting Battery Model -- Battery realtime level +- Battery realtime level (added) - Estimated time for full charge - Estimated time to fully discharge @@ -80,7 +81,7 @@ import the package const bu = require("battery_util"); ``` -get battery information +### Get battery information ```js const bu = require("battery_util"); @@ -104,7 +105,7 @@ bu.batteryInfo() // serialNumber : 204 ``` -get specific data +### Get specific data ```js const bu = require("battery_util"); @@ -115,7 +116,7 @@ bu.batteryInfo() }) .catch(err => { console.log(err); - }); +}); ``` ### data options : @@ -130,6 +131,53 @@ bu.batteryInfo() - serialNumber - more in the future .... +### Get battery state + +```js +const bu = require("battery_util"); + +bu.batteryState() + .then(data => { + console.log(data); + }).catch(err => { + console.log(err); +}); +``` + +### Get battery state avery second + +```js +const bu = require("battery_util"); + +setInterval(() => { +bu.batteryState() + .then(data => { + console.log(data); + }).catch(err => { + console.log(err); +}); +}, 1000); +``` + +### Get specific data + +```js +const bu = require("battery_util"); + +bu.batteryState() + .then(data => { + console.log(data.level); // (Example) 78 + }).catch(err => { + console.log(err); +}); +``` + +### data options : + +- level +- isCharging + + ## 📖 How it works With the help of [Child Process](https://www.npmjs.com/package/childprocess) package we can execute a powershell commend and return data from it (Microsoft battery report) diff --git a/package.json b/package.json index e4df772..cfd5522 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "battery_util", - "version": "1.1.4", + "version": "2.1.4", "description": "nodeJS package to get information about laptop battery", "main": "./lib/index.js", "types": "./lib/index.d.ts",