{"size": 1102, "ext": "js", "max_stars_repo_path": "src/js/utils/Utils.js", "max_stars_repo_name": "videomark/videomark-log-view", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/js/utils/Utils.js", "max_issues_repo_name": "videomark/videomark-log-view", "max_issues_repo_issues_event_min_datetime": "2019-11-13T01:56:37.000Z", "max_issues_repo_issues_event_max_datetime": "2020-05-07T07:02:37.000Z", "max_forks_repo_path": "src/js/utils/Utils.js", "max_forks_repo_name": "videomark/videomark-log-view", "max_forks_repo_forks_event_min_datetime": "2019-02-07T04:23:09.000Z", "max_forks_repo_forks_event_max_datetime": "2019-02-07T04:23:09.000Z"}
{"max_stars_count": null, "max_issues_count": 12, "max_forks_count": 1, "avg_line_length": 33.3939393939, "max_line_length": 77, "alphanum_fraction": 0.6705989111}
import videoPlatforms from "./videoPlatforms";

export const urlToVideoPlatform = (url) => {
  try {
    const { host } = new URL(url);
    return videoPlatforms.find((platform) => platform.host.test(host)) || {};
  } catch (e) {
    if (e instanceof TypeError) return {};
    throw e;
  }
};

export const isDevelop = () => process.env.NODE_ENV === "development";
export const isMobile = () =>
  window.sodium !== undefined && window.chrome.storage === undefined;
export const isExtension = () =>
  window.sodium === undefined && window.chrome.storage !== undefined;
export const isWeb = () =>
  window.sodium === undefined && window.chrome.storage === undefined;

export const sizeFormat = (bytes, exponent) => {
  const divider = 1024 ** exponent;
  // 整数部が4桁になったら少数部は省く
  const fraction = bytes >= divider * 1000 ? 0 : 2;
  return new Intl.NumberFormat("en-US", {
    maximumFractionDigits: fraction,
    minimumFractionDigits: fraction,
  }).format(bytes / divider);
};

export const gigaSizeFormat = (bytes) => sizeFormat(bytes, 3);
export const megaSizeFormat = (bytes) => sizeFormat(bytes, 2);
