const csv = rows.map(cols => cols.join(','))
.join('\n')
because we are too lazy to write the more correct, const esc = cell => `"${String(cell).replace(/"/g, '""')}"`
const csv = rows.map(cols => cols.map(esc).join(','))
.join('\n')
(And perhaps something slightly more efficient but slower that only quotes each cell when it needs to be escaped.)I caught myself doing it the other day, Go has a JSON library and here I was too lazy to define a struct,
w.WriteHeader(500)
fmt.Fprintf(w, `{"error": %q}`, err.Error())
Is %q a JSON-compatible format? I have no idea without reading some source code! Almost certainly it won't \u-encode weird characters. That might be OK, I think the only stuff you really have to escape in JSON strings is newlines, backslashes, and double quotes? And %q probably handles those. Maybe it breaks on ASCII control characters...But yeah, we are meant to always use a library because we have deadlines and we are willing to compromise a whole lot of quality to deliver on them.