UNPKG

coldstitch

Version:

A code generation library, that helps you craft code snippets in code for multiple languages

73 lines (72 loc) 1.91 kB
import { s as u, f as c, e as l, C as g, I as y, g as d } from "../index-ZSW9UYQX.js"; function I(e, { from: o, alias: n, defaultImport: i = !1, typeOnly: t = !1 } = {}) { return { namespace: o ?? "", name: e, alias: n, packageName: o, defaultImport: i, typeOnly: t, language: "js", toString: () => n || e }; } function j(e, o = {}) { const { formatter: n } = o, i = u( e, { objectTokens: ["{", "}"], arrayTokens: ["[", "]"], assignToken: ": ", formatKey: (t) => t, formatValue: (t) => { if (n) { const s = n(t); if (s !== void 0) return s; } if (t === null) return "null"; if (t === void 0) return "undefined"; if (typeof t == "string") return `"${l(t)}"`; if (typeof t == "number" || typeof t == "bigint") return t.toString(); if (typeof t == "boolean") return t ? "true" : "false"; throw new Error(`Unsupported value type: ${typeof t}`); } }, c("js") ); return g.fromString(i); } function h(e) { return j(e); } class $ extends y { resolve(o) { const n = d(o); return Object.keys(n).sort().map((s) => { const m = n[s].sort((r, f) => r.name.localeCompare(f.name)), p = m.filter((r) => !r.defaultImport).map((r) => { const f = r.typeOnly ? "type " : ""; return r.alias ? `${f}${r.name} as ${r.alias}` : f + r.name; }).join(", "), a = []; return m.filter((r) => r.defaultImport).forEach((r) => { a.push(r.alias ? `${r.name} as ${r.alias}` : r.name); }), p && (a.length > 0 && a.push(","), a.push("{", p, "}")), `import ${a.join(" ")} from "${s}";`; }).join(` `); } } function k() { return new $(); } export { h as array, k as imports, j as obj, I as typeRef }; //# sourceMappingURL=js.js.map