UNPKG

ant-design-x-vue-next

Version:

Ant Design X for Vue — community continuation aligned with @ant-design/x

77 lines (75 loc) 1.97 kB
const d = ` `, p = ` `, S = ":", f = (r) => (r ?? "").trim() !== ""; function h(r = d) { let e = ""; return new TransformStream({ transform(t, u) { e += t; const s = e.split(r); s.slice(0, -1).forEach((a) => { f(a) && u.enqueue(a); }), e = s[s.length - 1]; }, flush(t) { f(e) && t.enqueue(e); } }); } function T(r = p, e = S) { return new TransformStream({ transform(t, u) { const a = t.split(r).reduce((i, n) => { const o = n.indexOf(e); if (o === -1) return f(n) && console.warn( `[XStream] The key-value separator "${e}" is not found in the sse line: ${n}` ), i; const c = n.slice(0, o).trim(); if (!f(c)) return i; const l = n.slice(o + 1).trim(); return { ...i, [c]: l }; }, {}); Object.keys(a).length !== 0 && u.enqueue(a); } }); } function A() { if (typeof TextDecoderStream < "u") return new TextDecoderStream(); const r = new TextDecoder("utf-8"); return new TransformStream({ transform(e, t) { t.enqueue(r.decode(e, { stream: !0 })); }, flush(e) { e.enqueue(r.decode()); } }); } function R(r) { const { readableStream: e, transformStream: t, streamSeparator: u, partSeparator: s, kvSeparator: a } = r; if (!(e instanceof ReadableStream)) throw new Error("The options.readableStream must be an instance of ReadableStream."); const i = A(), n = t ? e.pipeThrough(i).pipeThrough(t) : e.pipeThrough(i).pipeThrough(h(u)).pipeThrough(T(s, a)); return n[Symbol.asyncIterator] = async function* () { const o = this.getReader(); let c = !1; try { for (; ; ) { const { done: l, value: m } = await o.read(); if (l) { c = !0; break; } m && (yield m); } } finally { c || o.cancel().catch(() => { }), o.releaseLock(); } }, n; } export { R as default };