{"size": 657, "ext": "js", "max_stars_repo_path": "src/calculatePPI.js", "max_stars_repo_name": "ivitivan/ppi-calculator", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/calculatePPI.js", "max_issues_repo_name": "ivitivan/ppi-calculator", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/calculatePPI.js", "max_forks_repo_name": "ivitivan/ppi-calculator", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 32.85, "max_line_length": 80, "alphanum_fraction": 0.6712328767}
import {parseResolutionString} from './parseResolutionString'

export const calculatePPI = ({
  resolutionString = '', // resolution string like 1920x1080
  diagonalSize, // screen diagonal size in inches
  width, // screen width in pixels
  height, // screen height in pixels
}) => {
  if (resolutionString !== '' && diagonalSize !== undefined) {
    const {width, height} = parseResolutionString({resolutionString})

    return calculatePPI({width, height, diagonalSize})
  } else if (width > 0 && height > 0 && diagonalSize > 0) {
    return Math.round(
      (Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2)) / diagonalSize) * 100
    ) / 100
  }
}

