From 752b41b9dc88747bebc97d181bf815f8c1c88d7e Mon Sep 17 00:00:00 2001 From: Rotzbua Date: Tue, 28 May 2024 14:42:28 +0200 Subject: [PATCH] fix: `JSON.stringify` replacer argument replacer argument can be array or function otherwise it should be e.g. `null` --- lib/commands/init/index.js | 2 +- lib/commands/remove.js | 2 +- lib/commands/search.js | 2 +- lib/commands/target.js | 2 +- lib/result.js | 18 +++++++++--------- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/commands/init/index.js b/lib/commands/init/index.js index 0b23aa0..21bfb8a 100644 --- a/lib/commands/init/index.js +++ b/lib/commands/init/index.js @@ -285,7 +285,7 @@ async function command(argv, result) { type: "credentials", users: securityResponses.users }; - config.adminAuth = JSON.stringify(adminAuth,"",4).replace(/\n/g,"\n "); + config.adminAuth = JSON.stringify(adminAuth, null, 4).replace(/\n/g,"\n "); } const projectsResponses = await promptProjects(); diff --git a/lib/commands/remove.js b/lib/commands/remove.js index ca6cb64..3c903f2 100644 --- a/lib/commands/remove.js +++ b/lib/commands/remove.js @@ -25,7 +25,7 @@ function command(argv,result) { method: "DELETE" }).then(function() { if (argv.json) { - result.log(JSON.stringify({message: "Uninstalled " + module}," ",4)); + result.log(JSON.stringify({message: "Uninstalled " + module}, null, 4)); } else { result.log("Uninstalled " + module); } diff --git a/lib/commands/search.js b/lib/commands/search.js index 72c8a02..f17f3e0 100644 --- a/lib/commands/search.js +++ b/lib/commands/search.js @@ -50,7 +50,7 @@ function command(argv,result) { description: m.n.description, version: (m.n['dist-tags']&& m.n['dist-tags'].latest)?m.n['dist-tags'].latest:undefined, updated_at: m.n.updated_at - };})," ",4)); + };}), null, 4)); } else { matches.forEach(function(m) { result.log(m.label); diff --git a/lib/commands/target.js b/lib/commands/target.js index ca0d855..df3653c 100644 --- a/lib/commands/target.js +++ b/lib/commands/target.js @@ -30,7 +30,7 @@ function command(argv,result) { config.target(target); } if (argv.json) { - result.log(JSON.stringify({target: config.target()}," ",4)); + result.log(JSON.stringify({target: config.target()}, null, 4)); } else { result.log("Target: " + config.target()); } diff --git a/lib/result.js b/lib/result.js index d48997d..5a744f6 100644 --- a/lib/result.js +++ b/lib/result.js @@ -30,7 +30,7 @@ function logDetails(result) { function logModule(result) { if (outputFormat === "json") { - console.log(JSON.stringify(result,' ',4)); + console.log(JSON.stringify(result, null, 4)); return; } var table = plainTable({plain:true}); @@ -43,7 +43,7 @@ function logModule(result) { function logList(result) { if (outputFormat === "json") { - console.log(JSON.stringify(result,' ',4)); + console.log(JSON.stringify(result, null, 4)); return; } if (result.nodes) { // summary of node-module @@ -55,7 +55,7 @@ function logList(result) { function logNodeSet(node) { if (outputFormat === "json") { - console.log(JSON.stringify(node,' ',4)); + console.log(JSON.stringify(node, null, 4)); return; } if (Array.isArray(node)) { @@ -76,7 +76,7 @@ function logNodeSet(node) { function logNodeList(nodes) { if (outputFormat === "json") { - console.log(JSON.stringify(nodes,' ',4)); + console.log(JSON.stringify(nodes, null, 4)); return; } if (!Array.isArray(nodes)) { @@ -120,7 +120,7 @@ function logNodeList(nodes) { function logProjectList(projects) { if (outputFormat === "json") { - console.log(JSON.stringify(projects,' ',4)); + console.log(JSON.stringify(projects, null, 4)); return; } var projectList = projects.projects || []; @@ -156,27 +156,27 @@ module.exports = { if (msg.response) { if (msg.response.status === 401) { if (outputFormat === "json") { - console.log(JSON.stringify({error:"Not logged in. Use 'login' to log in.", status: 401}," ",4)); + console.log(JSON.stringify({error:"Not logged in. Use 'login' to log in.", status: 401}, null, 4)); } else { console.warn("Not logged in. Use 'login' to log in."); } } else if (msg.response.data) { if (msg.response.status === 404 && !msg.response.data.message) { if (outputFormat === "json") { - console.log(JSON.stringify({error:"Node-RED Admin API not found. Use 'target' to set API location", status: 404}," ",4)); + console.log(JSON.stringify({error:"Node-RED Admin API not found. Use 'target' to set API location", status: 404}, null, 4)); } else { console.warn("Node-RED Admin API not found. Use 'target' to set API location"); } } else { if (outputFormat === "json") { - console.log(JSON.stringify({error:msg.response.data.message, status: msg.response.status}," ",4)); + console.log(JSON.stringify({error:msg.response.data.message, status: msg.response.status}, null, 4)); } else { console.warn(msg.response.status+": "+msg.response.data.message); } } } else { if (outputFormat === "json") { - console.log(JSON.stringify({error:msg.toString(), status: msg.response.status}," ",4)); + console.log(JSON.stringify({error:msg.toString(), status: msg.response.status}, null, 4)); } else { console.warn(msg.response.status+": "+msg.toString()); }