{"size": 1018, "ext": "js", "max_stars_repo_path": "src/components/Link.js", "max_stars_repo_name": "pke/tracly-app-test", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/components/Link.js", "max_issues_repo_name": "pke/tracly-app-test", "max_issues_repo_issues_event_min_datetime": "2020-07-19T05:16:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-25T23:59:50.000Z", "max_forks_repo_path": "src/components/Link.js", "max_forks_repo_name": "pke/tracly-app-test", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 49, "max_forks_count": null, "avg_line_length": 24.8292682927, "max_line_length": 96, "alphanum_fraction": 0.6178781925}
import React from "react"
import PropTypes from "prop-types"

const isExternal = href => /^(https?:\/\/|tel:|mailto:)/.test(href)

export default function Link({
  href,
  children = href,
  style,
  target,
  rel = "",
  external = isExternal(href),
  ...props
}) {
  // Enforce save browsing
  // https://mathiasbynens.github.io/rel-noopener/
  if ("_blank" === target) {
    rel = (rel || "noopener noreferrer")
    if (rel.indexOf("noopener") === -1) {
      rel = rel + " noopener"
    }
  }

  if (external) {
    if (!rel || rel.indexOf("external") === -1) {
      rel = rel + " external"
    }
  }
  return <a href={href} style={style} target={target} rel={rel.trim()} {...props}>{children}</a>
}
Link.propTypes = {
  href: PropTypes.string.isRequired,
  target: PropTypes.oneOf(["_self", "_blank", "_parent", "_top"]),
  rel: PropTypes.string,
  external: PropTypes.bool,
  children: PropTypes.node,
  style: PropTypes.object,
  /** CSS class names to style the component. */
  className: PropTypes.string,
}
