diff --git a/CHANGELOG.md b/CHANGELOG.md index 045aaa9..2714b38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ For major (breaking) changes - version 3 and 2 see end of page. | Version | Date | Comment | | -------------- | -------------- | -------- | +| 4.27.6 | 2020-10-02 | `get()` fixed when results are in arrays | | 4.27.5 | 2020-09-18 | `cpuTemperature()` fix try catch (linux) | | 4.27.4 | 2020-09-16 | `networkInterfaceDefault()` optimization (macOS) | | 4.27.3 | 2020-08-26 | updated typescript typings | diff --git a/docs/history.html b/docs/history.html index 56f2054..2de30e9 100644 --- a/docs/history.html +++ b/docs/history.html @@ -83,6 +83,11 @@ + + 4.27.6 + 2020-10-02 + get() fixed when results are in arrays + 4.27.5 2020-09-18 diff --git a/docs/index.html b/docs/index.html index d0de8c6..b44c512 100644 --- a/docs/index.html +++ b/docs/index.html @@ -168,7 +168,7 @@
systeminformation
-
Current Version: 4.27.5
+
Current Version: 4.27.6
diff --git a/lib/filesystem.js b/lib/filesystem.js index dbe594b..e67284d 100755 --- a/lib/filesystem.js +++ b/lib/filesystem.js @@ -253,7 +253,7 @@ function parseBlk(lines) { let data = []; lines.filter(line => line !== '').forEach((line) => { - line = util.decodeEscapeSequence(line); + line = decodeURIComponent(line.replace(/\\x/g, '%')); line = line.replace(/\\/g, '\\\\'); let disk = JSON.parse(line); data.push({ diff --git a/lib/index.js b/lib/index.js index 2b3a2a6..91045df 100755 --- a/lib/index.js +++ b/lib/index.js @@ -331,13 +331,28 @@ function get(valueObject, callback) { result[key] = data[i]; } else { const keys = valueObject[key].replace(/,/g, ' ').replace(/ +/g, ' ').split(' '); - const partialRes = {}; - keys.forEach(k => { - if ({}.hasOwnProperty.call(data[i], k)) { - partialRes[k] = data[i][k]; - } - }); - result[key] = partialRes; + if (Array.isArray(data[i])) { + // result is in an array, go through all elements of array and pick only the right ones + const partialArray = []; + data[i].forEach(element => { + const partialRes = {}; + keys.forEach(k => { + if ({}.hasOwnProperty.call(element, k)) { + partialRes[k] = element[k]; + } + }); + partialArray.push(partialRes); + }); + result[key] = partialArray; + } else { + const partialRes = {}; + keys.forEach(k => { + if ({}.hasOwnProperty.call(data[i], k)) { + partialRes[k] = data[i][k]; + } + }); + result[key] = partialRes; + } } i++; } @@ -355,7 +370,7 @@ function observe(valueObject, interval, callback) { const result = setInterval(() => { get(valueObject).then(data => { if (JSON.stringify(_data) !== JSON.stringify(data)) { - _data = Object.assign({}, data ); + _data = Object.assign({}, data); callback(data); } });