UNPKG

@scalar/api-reference

Version:

Generate beautiful API references from OpenAPI documents

29 lines (28 loc) 919 B
import { isDefined as p, isJsonString as r } from "@scalar/oas-utils/helpers"; import { toJson as d, normalize as s, toYaml as w } from "@scalar/openapi-parser"; function f(e, t) { return t && !r(e) ? d(s(e)) : !t && r(e) ? w(s(e)) : e; } function v() { try { return new MouseEvent("click", { bubbles: !0, cancelable: !0, view: window }); } catch { return new MouseEvent("click", { bubbles: !0, cancelable: !0 }); } } function y(e, t, c) { const o = c === "json" || !p(c) && r(e), l = f(e, o), i = o ? ".json" : ".yaml", u = o ? "application/json" : "application/x-yaml", m = t ? t + i : "openapi" + i, b = new Blob([l], { type: u }), a = URL.createObjectURL(b), n = document.createElement("a"); n.href = a, n.download = m, n.dispatchEvent(v()), setTimeout(() => { window.URL.revokeObjectURL(a), n.remove(); }, 100); } export { y as downloadDocument };