opencode/packages/util/src/open.ts

12 lines
395 B
TypeScript

import open from "open"
export function openUrl(input: string) {
const url = URL.canParse(input) ? new URL(input) : undefined
if (!url || (url.protocol !== "http:" && url.protocol !== "https:"))
return Promise.reject(new Error(`Only http and https links can be opened in the browser: ${input}`))
return open(url.href)
}
export function openPath(path: string) {
return open(path)
}