{"size": 614, "ext": "js", "max_stars_repo_path": "src/utils/index.js", "max_stars_repo_name": "LoTwT/create-vite-node", "max_stars_repo_stars_event_min_datetime": "2021-12-30T11:49:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-30T11:49:27.000Z", "max_issues_repo_path": "src/utils/index.js", "max_issues_repo_name": "LoTwT/create-vite-node", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/utils/index.js", "max_forks_repo_name": "LoTwT/create-vite-node", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 26.6956521739, "max_line_length": 74, "alphanum_fraction": 0.6758957655}
import { fileURLToPath } from "url"
import { dirname } from "path"

// esm transform __dirname
export const toDirname = (importMetaUrl) =>
  dirname(fileURLToPath(importMetaUrl))

/**
 * call function with error handling
 * @param { Function } fn
 * @param { Function } errorCallback
 */
export const callWithErrorHandling = async (fn, errorCallback = null) => {
  try {
    if (typeof fn !== "function") throw new TypeError("invalid function")
    await fn()
  } catch (error) {
    typeof errorCallback === "function" && (await errorCallback())
    console.error(error.message || error)
    process.exit()
  }
}
