Skip to content

Commit 752b41b

Browse files
committed
fix: JSON.stringify replacer argument
replacer argument can be array or function otherwise it should be e.g. `null`
1 parent 16b387e commit 752b41b

File tree

5 files changed

+13
-13
lines changed

5 files changed

+13
-13
lines changed

lib/commands/init/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ async function command(argv, result) {
285285
type: "credentials",
286286
users: securityResponses.users
287287
};
288-
config.adminAuth = JSON.stringify(adminAuth,"",4).replace(/\n/g,"\n ");
288+
config.adminAuth = JSON.stringify(adminAuth, null, 4).replace(/\n/g,"\n ");
289289
}
290290

291291
const projectsResponses = await promptProjects();

lib/commands/remove.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function command(argv,result) {
2525
method: "DELETE"
2626
}).then(function() {
2727
if (argv.json) {
28-
result.log(JSON.stringify({message: "Uninstalled " + module}," ",4));
28+
result.log(JSON.stringify({message: "Uninstalled " + module}, null, 4));
2929
} else {
3030
result.log("Uninstalled " + module);
3131
}

lib/commands/search.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function command(argv,result) {
5050
description: m.n.description,
5151
version: (m.n['dist-tags']&& m.n['dist-tags'].latest)?m.n['dist-tags'].latest:undefined,
5252
updated_at: m.n.updated_at
53-
};})," ",4));
53+
};}), null, 4));
5454
} else {
5555
matches.forEach(function(m) {
5656
result.log(m.label);

lib/commands/target.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function command(argv,result) {
3030
config.target(target);
3131
}
3232
if (argv.json) {
33-
result.log(JSON.stringify({target: config.target()}," ",4));
33+
result.log(JSON.stringify({target: config.target()}, null, 4));
3434
} else {
3535
result.log("Target: " + config.target());
3636
}

lib/result.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function logDetails(result) {
3030

3131
function logModule(result) {
3232
if (outputFormat === "json") {
33-
console.log(JSON.stringify(result,' ',4));
33+
console.log(JSON.stringify(result, null, 4));
3434
return;
3535
}
3636
var table = plainTable({plain:true});
@@ -43,7 +43,7 @@ function logModule(result) {
4343

4444
function logList(result) {
4545
if (outputFormat === "json") {
46-
console.log(JSON.stringify(result,' ',4));
46+
console.log(JSON.stringify(result, null, 4));
4747
return;
4848
}
4949
if (result.nodes) { // summary of node-module
@@ -55,7 +55,7 @@ function logList(result) {
5555

5656
function logNodeSet(node) {
5757
if (outputFormat === "json") {
58-
console.log(JSON.stringify(node,' ',4));
58+
console.log(JSON.stringify(node, null, 4));
5959
return;
6060
}
6161
if (Array.isArray(node)) {
@@ -76,7 +76,7 @@ function logNodeSet(node) {
7676

7777
function logNodeList(nodes) {
7878
if (outputFormat === "json") {
79-
console.log(JSON.stringify(nodes,' ',4));
79+
console.log(JSON.stringify(nodes, null, 4));
8080
return;
8181
}
8282
if (!Array.isArray(nodes)) {
@@ -120,7 +120,7 @@ function logNodeList(nodes) {
120120

121121
function logProjectList(projects) {
122122
if (outputFormat === "json") {
123-
console.log(JSON.stringify(projects,' ',4));
123+
console.log(JSON.stringify(projects, null, 4));
124124
return;
125125
}
126126
var projectList = projects.projects || [];
@@ -156,27 +156,27 @@ module.exports = {
156156
if (msg.response) {
157157
if (msg.response.status === 401) {
158158
if (outputFormat === "json") {
159-
console.log(JSON.stringify({error:"Not logged in. Use 'login' to log in.", status: 401}," ",4));
159+
console.log(JSON.stringify({error:"Not logged in. Use 'login' to log in.", status: 401}, null, 4));
160160
} else {
161161
console.warn("Not logged in. Use 'login' to log in.");
162162
}
163163
} else if (msg.response.data) {
164164
if (msg.response.status === 404 && !msg.response.data.message) {
165165
if (outputFormat === "json") {
166-
console.log(JSON.stringify({error:"Node-RED Admin API not found. Use 'target' to set API location", status: 404}," ",4));
166+
console.log(JSON.stringify({error:"Node-RED Admin API not found. Use 'target' to set API location", status: 404}, null, 4));
167167
} else {
168168
console.warn("Node-RED Admin API not found. Use 'target' to set API location");
169169
}
170170
} else {
171171
if (outputFormat === "json") {
172-
console.log(JSON.stringify({error:msg.response.data.message, status: msg.response.status}," ",4));
172+
console.log(JSON.stringify({error:msg.response.data.message, status: msg.response.status}, null, 4));
173173
} else {
174174
console.warn(msg.response.status+": "+msg.response.data.message);
175175
}
176176
}
177177
} else {
178178
if (outputFormat === "json") {
179-
console.log(JSON.stringify({error:msg.toString(), status: msg.response.status}," ",4));
179+
console.log(JSON.stringify({error:msg.toString(), status: msg.response.status}, null, 4));
180180
} else {
181181
console.warn(msg.response.status+": "+msg.toString());
182182
}

0 commit comments

Comments
 (0)