Skip to content

Commit 6ba4aeb

Browse files
committed
filter and sort
1 parent 41dd431 commit 6ba4aeb

3 files changed

Lines changed: 37 additions & 60 deletions

File tree

es5/jsdoc-parse.js

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,38 @@
11
'use strict';
22

33
var sortArray = require('sort-array');
4-
var fileSet = require('file-set');
5-
var Transform = require('stream').Transform;
64
var transform = require('./transform');
7-
var collectJson = require('collect-json');
8-
var assert = require('assert');
9-
var connect = require('stream-connect');
10-
var fs = require('fs');
5+
var a = require('array-tools');
116

127
exports.parse = parse;
138
exports.getStats = getStats;
149

1510
function parse(jsdocExplainOutput, options) {
11+
options = options || {};
1612
var data = transform(jsdocExplainOutput);
1713

18-
return data;
19-
}
20-
21-
function applyOptions(data, options) {
22-
if (options.stats) {
23-
return JSON.stringify(getStats(data), null, ' ') + '\n';
24-
} else {
25-
data = data.filter(function (item) {
26-
var parent = data.find(function (d) {
27-
return d.id === item.memberof;
28-
}) || {};
29-
if (item.ignore || parent.ignore) {
30-
return false;
31-
} else if (!options.private && item.access === 'private' || parent.access === 'private') {
32-
return false;
33-
} else {
34-
return true;
35-
}
36-
});
37-
38-
if (options['sort-by'] && !a(options['sort-by']).contains('none')) {
39-
data = sort(data, options['sort-by']);
14+
data = data.filter(function (doclet) {
15+
var parent = data.find(function (d) {
16+
return d.id === doclet.memberof;
17+
}) || {};
18+
if (doclet.ignore || parent.ignore) {
19+
return false;
20+
} else if (!options.private && (doclet.access === 'private' || parent.access === 'private')) {
21+
return false;
22+
} else {
23+
return true;
4024
}
41-
return JSON.stringify(data, null, ' ') + '\n';
25+
});
26+
27+
if (options['sort-by'] && !a(options['sort-by']).contains('none')) {
28+
data = sort(data, options['sort-by']);
4229
}
30+
31+
return data;
4332
}
4433

45-
function getStats(data) {
34+
function getStats(jsdocExplainOutput) {
35+
var data = parse(jsdocExplainOutput);
4636
var stats = {
4737
identifiers: {}
4838
};

es5/transform.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ function sort(object, sortFunction) {
309309
}
310310

311311
function sortIdentifier(doclet) {
312-
var fieldOrder = ['id', 'longname', 'name', 'scope', 'kind', 'isExported', 'classdesc', 'augments', 'inherits', 'inherited', 'implements', 'overrides', 'mixes', 'description', 'memberof', 'alias', 'params', 'fires', 'examples', 'returns', 'type', 'defaultvalue', 'readonly', 'thisvalue', 'isEnum', 'properties', 'optional', 'nullable', 'variable', 'author', 'deprecated', 'ignore', 'access', 'requires', 'version', 'since', 'licenses', 'license', 'typicalname', 'category', 'see', 'exceptions', 'codeName', 'todoList', 'customTags', 'chainable', 'meta', 'order'];
312+
var fieldOrder = ['id', 'parentId', 'longname', 'name', 'scope', 'kind', 'isExported', 'classdesc', 'augments', 'inherits', 'inherited', 'implements', 'overrides', 'mixes', 'description', 'memberof', 'alias', 'params', 'fires', 'examples', 'returns', 'type', 'defaultvalue', 'readonly', 'thisvalue', 'isEnum', 'properties', 'optional', 'nullable', 'variable', 'author', 'deprecated', 'ignore', 'access', 'requires', 'version', 'since', 'licenses', 'license', 'typicalname', 'category', 'see', 'exceptions', 'codeName', 'todoList', 'customTags', 'chainable', 'meta', 'order'];
313313
return sort(doclet, function (a, b) {
314314
if (fieldOrder.indexOf(a) === -1 && fieldOrder.indexOf(b) > -1) {
315315
return 1;

lib/jsdoc-parse.js

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,38 +21,25 @@ exports.getStats = getStats
2121
* @param [options.sort-by=[ 'scope', 'category', 'kind', 'order' ]] {string[]} - Sort by one of more fields, e.g. `--sort-by kind category`. Pass the special value `none` to remove the default sort order.
2222
*/
2323
function parse (jsdocExplainOutput, options) {
24-
const data = transform(jsdocExplainOutput)
25-
// sort or filter out private
24+
options = options || {}
25+
let data = transform(jsdocExplainOutput)
2626

27-
return data
28-
}
29-
30-
/**
31-
* @param {string} - input json string
32-
* @param {object} - jsdoc-parse options
33-
* @returns {string} - output json string to be streamed out
34-
* @private
35-
*/
36-
function applyOptions (data, options) {
37-
if (options.stats) {
38-
return JSON.stringify(getStats(data), null, ' ') + '\n'
39-
} else {
40-
data = data.filter(function (item) {
41-
var parent = data.find(d => d.id === item.memberof) || {}
42-
if (item.ignore || parent.ignore) {
43-
return false
44-
} else if (!options.private && item.access === 'private' || parent.access === 'private') {
45-
return false
46-
} else {
47-
return true
48-
}
49-
})
50-
51-
if (options['sort-by'] && !a(options['sort-by']).contains('none')) {
52-
data = sort(data, options['sort-by'])
27+
data = data.filter(function (doclet) {
28+
var parent = data.find(d => d.id === doclet.memberof) || {}
29+
if (doclet.ignore || parent.ignore) {
30+
return false
31+
} else if (!options.private && (doclet.access === 'private' || parent.access === 'private')) {
32+
return false
33+
} else {
34+
return true
5335
}
54-
return JSON.stringify(data, null, ' ') + '\n'
36+
})
37+
38+
if (options['sort-by'] && !a(options['sort-by']).contains('none')) {
39+
data = sort(data, options['sort-by'])
5540
}
41+
42+
return data
5643
}
5744

5845
/**

0 commit comments

Comments
 (0)