{"size": 458, "ext": "js", "max_stars_repo_path": "packages/gitbook-core/src/lib/getPayload.js", "max_stars_repo_name": "GerHobbelt/gitbook", "max_stars_repo_stars_event_min_datetime": "2017-06-12T01:06:07.000Z", "max_stars_repo_stars_event_max_datetime": "2017-06-12T01:06:10.000Z", "max_issues_repo_path": "packages/gitbook-core/src/lib/getPayload.js", "max_issues_repo_name": "itwanggj/gitbook", "max_issues_repo_issues_event_min_datetime": "2020-10-20T12:46:26.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-11T23:13:37.000Z", "max_forks_repo_path": "packages/gitbook-core/src/lib/getPayload.js", "max_forks_repo_name": "itwanggj/gitbook", "max_forks_repo_forks_event_min_datetime": "2017-02-12T13:40:18.000Z", "max_forks_repo_forks_event_max_datetime": "2019-06-18T14:48:45.000Z"}
{"max_stars_count": 2, "max_issues_count": 5, "max_forks_count": 12, "avg_line_length": 22.9, "max_line_length": 81, "alphanum_fraction": 0.6506550218}

/**
 * Get the payload for a GitBook page
 * @param  {String|DOMDocument} html
 * @return {Object}
 */
function getPayload(html) {
    if (typeof html === 'string') {
        const parser = new DOMParser();
        html = parser.parseFromString(html, 'text/html');
    }

    const script = html.querySelector('script[type="application/payload+json"]');
    const payload = JSON.parse(script.innerHTML);

    return payload;
}

module.exports = getPayload;
