Skip to content

Instantly share code, notes, and snippets.

View amir-ba's full-sized avatar

Amir Baghdoust amir-ba

View GitHub Profile
@amir-ba
amir-ba / ndjson.js
Created November 18, 2022 11:43 — forked from albe/ndjson.js
ndjson fetch API transformer
const parseLine = (line) => {
try {
return JSON.parse(line);
} catch (e) {
}
};
const ucasefirst = (str) => str.charAt(0).toUpperCase() + str.slice(1);
@amir-ba
amir-ba / fetch-chunked.js
Created November 17, 2022 15:20 — forked from jfsiii/fetch-chunked.js
Quick example of using fetch to parse a chunked response
var chunkedUrl = 'https://jigsaw.w3.org/HTTP/ChunkedScript';
fetch(chunkedUrl)
.then(processChunkedResponse)
.then(onChunkedResponseComplete)
.catch(onChunkedResponseError)
;
function onChunkedResponseComplete(result) {
console.log('all done!', result)
}