{"size": 1004, "ext": "js", "max_stars_repo_path": "packages/from-jsdoc/lib/collector.js", "max_stars_repo_name": "streamside/scriptappy", "max_stars_repo_stars_event_min_datetime": "2018-08-24T10:44:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-25T10:38:09.000Z", "max_issues_repo_path": "packages/from-jsdoc/lib/collector.js", "max_issues_repo_name": "streamside/scriptappy", "max_issues_repo_issues_event_min_datetime": "2021-09-13T08:33:16.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-21T09:41:19.000Z", "max_forks_repo_path": "packages/from-jsdoc/lib/collector.js", "max_forks_repo_name": "streamside/scriptappy", "max_forks_repo_forks_event_min_datetime": "2018-04-09T11:32:46.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-25T12:37:12.000Z"}
{"max_stars_count": 4, "max_issues_count": 20, "max_forks_count": 7, "avg_line_length": 30.4242424242, "max_line_length": 98, "alphanum_fraction": 0.6513944223}
const { sortObject } = require('./sort');
const { getParamFromComment, getPropertyFromComment } = require('./type-parser');
const collectAndNest = require('./collect-nest');

/* eslint no-param-reassign: 0 */
function collect({ entity }) {
  function collectParamsFromDoc(doc, cfg, opts) {
    (doc.params || []).forEach(param => {
      param.exp = getParamFromComment(param.name, doc.comment);
    });
    const par = collectAndNest({ doc, list: doc.params || [], asArray: true }, cfg, opts, entity);
    par.forEach(p => sortObject(p, cfg));
    return par;
  }

  // collect nested properties
  function collectPropsFromDoc(doc, cfg, opts) {
    (doc.properties || []).forEach(prop => {
      prop.exp = getPropertyFromComment(prop.name, doc.comment);
    });
    const o = { entries: collectAndNest({ doc, list: doc.properties }, cfg, opts, entity) };
    sortObject(o, cfg);
    return o.entries;
  }

  return {
    collectParamsFromDoc,
    collectPropsFromDoc,
  };
}

module.exports = collect;
