1 | const { walk } = require('../walk');
|
2 |
|
3 | /**
|
4 | * Formats documentation as a JSON string.
|
5 | *
|
6 | * @param {Array<Comment>} comments parsed comments
|
7 | * @returns {Promise<string>}
|
8 | * @name formats.json
|
9 | * @public
|
10 | * @example
|
11 | * var documentation = require('documentation');
|
12 | * var fs = require('fs');
|
13 | *
|
14 | * documentation.build(['index.js'])
|
15 | * .then(documentation.formats.json)
|
16 | * .then(output => {
|
17 | * // output is a string of JSON data
|
18 | * fs.writeFileSync('./output.json', output);
|
19 | * });
|
20 | */
|
21 | function json(comments) {
|
22 | walk(comments, comment => {
|
23 | delete comment.errors;
|
24 | if (comment.context) {
|
25 | delete comment.context.sortKey;
|
26 | }
|
27 | });
|
28 |
|
29 | return Promise.resolve(JSON.stringify(comments, null, 2));
|
30 | }
|
31 |
|
32 | module.exports = json;
|