{"size": 1758, "ext": "js", "max_stars_repo_path": "dist/tasklist.js", "max_stars_repo_name": "increments/tasklist.js", "max_stars_repo_stars_event_min_datetime": "2015-04-08T07:56:40.000Z", "max_stars_repo_stars_event_max_datetime": "2018-12-21T17:15:58.000Z", "max_issues_repo_path": "dist/tasklist.js", "max_issues_repo_name": "increments/tasklist.js", "max_issues_repo_issues_event_min_datetime": "2015-03-09T10:58:16.000Z", "max_issues_repo_issues_event_max_datetime": "2015-03-16T12:00:13.000Z", "max_forks_repo_path": "dist/tasklist.js", "max_forks_repo_name": "increments/tasklist.js", "max_forks_repo_forks_event_min_datetime": "2015-03-09T11:19:36.000Z", "max_forks_repo_forks_event_max_datetime": "2019-08-19T07:26:35.000Z"}
{"max_stars_count": 12, "max_issues_count": 3, "max_forks_count": 3, "avg_line_length": 28.3548387097, "max_line_length": 146, "alphanum_fraction": 0.4914675768}
(function (global) {
  var tasklist = {};

  tasklist.codeBlockPattern = /^(`{3}(?:.+)?\n)([\S\s]*?)(\n`{3})$/gm;

  tasklist.linePattern = /^(?:\s*(?:>\s*)*(?:[-+*]|(?:\d+\.)))\s*(\[ \]|\[x\])\s+(?!\(.*?\))(?=(?:\[.*?\]\s*(?:\[.*?\]|\(.*?\))\s*)*(?:[^\[]|$))/;

  // ## tasklist.convert(String, Integer, Boolean)
  // Takes Markdown text, checkbox index that starts from 1, and checked flag,
  // then returns converted Markdown text.
  //
  // ```js
  // tasklist.convert(
  //   '- [ ] foo\n' +
  //   '- [ ] bar\n' +
  //   '- [ ] baz',
  //   2,
  //   true
  // )
  // // results in:
  // // - [ ] foo
  // // - [x] bar
  // // - [ ] baz
  // ```
  tasklist.convert = function (markdownText, checkboxIndex, isChecked) {
    var lines = markdownText.split('\n');
    var taskIndex = 0;
    var sanitizedLines = markdownText.replace(
      tasklist.codeBlockPattern,
      function (str, pattern1, pattern2, pattern3) {
        return pattern1 + pattern2.replace(/^/gm, 'SANITIZED') + pattern3;
      }
    ).split('\n');
    var resultLines = [];
    var line;
    for (var i = 0, length = lines.length; i < length; i++) {
      line = lines[i];
      if (line === sanitizedLines[i] && line.match(tasklist.linePattern)) {
        taskIndex++;
        if (taskIndex === checkboxIndex) {
          if (isChecked) {
            resultLines.push(line.replace(/\[ \]/, '[x]'));
          } else {
            resultLines.push(line.replace(/\[x\]/, '[ ]'));
          }
        } else {
          resultLines.push(line);
        }
      } else {
        resultLines.push(line);
      }
    }
    return resultLines.join('\n');
  };

  if (typeof module == 'undefined') {
    global.tasklist = tasklist;
  } else {
    module.exports = tasklist;
  }
})(this);
