Skip to content

Commit

Permalink
Merge pull request #43 from Rotzbua/fix_type_json_stringify
Browse files Browse the repository at this point in the history
fix: `JSON.stringify` replacer argument
  • Loading branch information
knolleary authored Jun 3, 2024
2 parents 16b387e + 752b41b commit 53f75d1
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lib/commands/init/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/target.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
18 changes: 9 additions & 9 deletions lib/result.js
Original file line number Diff line number Diff line change
Expand Up @@ -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});
Expand All @@ -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
Expand All @@ -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)) {
Expand All @@ -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)) {
Expand Down Expand Up @@ -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 || [];
Expand Down Expand Up @@ -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());
}
Expand Down

0 comments on commit 53f75d1

Please sign in to comment.