diff --git a/src/NUTClient.ts b/src/NUTClient.ts index 0da3df2..e5df2b1 100644 --- a/src/NUTClient.ts +++ b/src/NUTClient.ts @@ -89,19 +89,19 @@ export class NUTClient { * @param ups {string} */ async listVariables(ups: UPSName): Promise { - return this.client.listVariables(ups).then((res) => - Object.fromEntries( - res.map((line) => { - const [key, value] = parseLine(line) as [nutVariables, string]; - - if (!key) { - throw new Error('fail to get key from variables'); - } - - return [key, value ?? '']; - }) - ) - ); + return this.client.listVariables(ups).then((res) => { + const variables: nutVariables = {} as nutVariables; + for (const line of res) { + const [key, value] = parseLine(line) as [nutVariables, string]; + + if (!key) { + throw new Error('fail to get key from variables'); + } + + variables[key] = value ?? ''; + } + return variables; + }); } /** @@ -189,19 +189,19 @@ export class NUTClient { * @param ups */ async listWriteableVariables(ups: UPSName): Promise> { - return this.client.listWriteableVariables(ups).then((res) => - Object.fromEntries( - res.map((line) => { - const [key, value] = parseLine(line); - - if (!key) { - throw new Error('fail to get key from variables'); - } - - return [key, value ?? '']; - }) - ) - ); + return this.client.listWriteableVariables(ups).then((res) => { + const variables: Record = {}; + for (const line of res) { + const [key, value] = parseLine(line); + + if (!key) { + throw new Error('fail to get key from variables'); + } + + variables[key] = value ?? ''; + } + return variables; + }); } /**