From bb58e99ffe26f9f3e386412055cf7b05ba7216a1 Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Wed, 8 Aug 2018 07:11:31 +0200 Subject: [PATCH] cpuTemperature() optimized parsing --- CHANGELOG.md | 1 + README.md | 1 + lib/cpu.js | 5 +++-- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d637b0f..0075feb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -100,6 +100,7 @@ Other changes | Version | Date | Comment | | -------------- | -------------- | -------- | +| 3.42.9 | 2018-08-08 | `cpuTemperature()` optimized parsing | | 3.42.8 | 2018-08-03 | updated docs | | 3.42.7 | 2018-08-03 | `processes()` optimized parsing ps name | | 3.42.6 | 2018-08-03 | `processes()` bugfix parsing ps linux | diff --git a/README.md b/README.md index dd63c56..74c9e9d 100644 --- a/README.md +++ b/README.md @@ -564,6 +564,7 @@ Written by Sebastian Hildebrandt [sebhildebrandt](https://github.com/sebhildebra - Adam Reis [adamreisnz](https://github.com/adamreisnz) - Jimi M [ItsJimi](https://github.com/ItsJimi) - Git² [GitSquared](https://github.com/GitSquared) +- weiyin [weiyin](https://github.com/weiyin) OSX Temperature: credits here are going to: diff --git a/lib/cpu.js b/lib/cpu.js index 3616509..5167312 100644 --- a/lib/cpu.js +++ b/lib/cpu.js @@ -464,10 +464,11 @@ function cpuTemperature(callback) { lines.forEach(function (line) { let regex = /[+-]([^°]*)/g; let temps = line.match(regex); - if (line.split(':')[0].toUpperCase().indexOf('PHYSICAL') !== -1) { + let firstPart = line.split(':')[0].toUpperCase(); + if (firstPart.indexOf('PHYSICAL') !== -1 || firstPart.indexOf('PACKAGE') !== -1) { result.main = parseFloat(temps); } - if (line.split(':')[0].toUpperCase().indexOf('CORE ') !== -1) { + if (firstPart.indexOf('CORE ') !== -1) { result.cores.push(parseFloat(temps)); } });