/
githubmirror
/
ChatGPT-Next-Web
Обзор
Документация
Войти
/
githubmirror
/
ChatGPT-Next-Web
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
app/utils/format.ts
28 строк
843 B
Yidadaa
feat: add upstash redis cloud sync
18 сен 2023, 22:18
18 сен 2023, 22:18
83fed42
Код
Авторство
О чём код?
export function prettyObject(msg: any) { const obj = msg; if (typeof msg !== "string") { msg = JSON.stringify(msg, null, " "); } if (msg === "{}") { return obj.toString(); } if (msg.startsWith("```json")) { return msg; } return ["```json", msg, "```"].join("\n"); } export function* chunks(s: string, maxBytes = 1000 * 1000) { const decoder = new TextDecoder("utf-8"); let buf = new TextEncoder().encode(s); while (buf.length) { let i = buf.lastIndexOf(32, maxBytes + 1); // If no space found, try forward search if (i < 0) i = buf.indexOf(32, maxBytes); // If there's no space at all, take all if (i < 0) i = buf.length; // This is a safe cut-off point; never half-way a multi-byte yield decoder.decode(buf.slice(0, i)); buf = buf.slice(i + 1); // Skip space (if any) } }