{"size": 512, "ext": "js", "max_stars_repo_path": "frontend/controllers/linkify_controller.js", "max_stars_repo_name": "btrd/anycable_rails_demo", "max_stars_repo_stars_event_min_datetime": "2020-06-25T20:36:29.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-28T23:57:13.000Z", "max_issues_repo_path": "frontend/controllers/linkify_controller.js", "max_issues_repo_name": "btrd/anycable_rails_demo", "max_issues_repo_issues_event_min_datetime": "2020-06-26T07:07:02.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-05T23:17:44.000Z", "max_forks_repo_path": "frontend/controllers/linkify_controller.js", "max_forks_repo_name": "btrd/anycable_rails_demo", "max_forks_repo_forks_event_min_datetime": "2020-07-12T08:10:41.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-08T01:35:30.000Z"}
{"max_stars_count": 150, "max_issues_count": 10, "max_forks_count": 31, "avg_line_length": 24.380952381, "max_line_length": 87, "alphanum_fraction": 0.623046875}
import { Controller } from "stimulus";
import linkifyStr from 'linkifyjs/string';

const MAX_SIZE = 25;

export default class extends Controller {
  connect() {
    if (this.linkfied) return;
    this.element.innerHTML = linkifyStr(this.element.innerText, {format: this.format});
    this.linkfied = true;
  }

  format(value, type) {
    value = value.replace(/^\w+:\/\//, "");
    if (type === "url" && value.length > MAX_SIZE) {
      value = value.slice(0, MAX_SIZE - 2) + "…";
    }
    return value;
  }
}
