MCPcopy Create free account
hub / github.com/idank/explainshell / d3_dsv

Function d3_dsv

explainshell/web/static/js/d3.v3.js:1689–1790  ·  view source on GitHub ↗
(delimiter, mimeType)

Source from the content-addressed store, hash-verified

1687 } : callback;
1688 }
1689 function d3_dsv(delimiter, mimeType) {
1690 var reFormat = new RegExp('["' + delimiter + "\n]"), delimiterCode = delimiter.charCodeAt(0);
1691 function dsv(url, row, callback) {
1692 if (arguments.length < 3) callback = row, row = null;
1693 var xhr = d3.xhr(url, mimeType, callback);
1694 xhr.row = function(_) {
1695 return arguments.length ? xhr.response((row = _) == null ? response : typedResponse(_)) : row;
1696 };
1697 return xhr.row(row);
1698 }
1699 function response(request) {
1700 return dsv.parse(request.responseText);
1701 }
1702 function typedResponse(f) {
1703 return function(request) {
1704 return dsv.parse(request.responseText, f);
1705 };
1706 }
1707 dsv.parse = function(text, f) {
1708 var o;
1709 return dsv.parseRows(text, function(row, i) {
1710 if (o) return o(row, i - 1);
1711 var a = new Function("d", "return {" + row.map(function(name, i) {
1712 return JSON.stringify(name) + ": d[" + i + "]";
1713 }).join(",") + "}");
1714 o = f ? function(row, i) {
1715 return f(a(row), i);
1716 } : a;
1717 });
1718 };
1719 dsv.parseRows = function(text, f) {
1720 var EOL = {}, EOF = {}, rows = [], N = text.length, I = 0, n = 0, t, eol;
1721 function token() {
1722 if (I >= N) return EOF;
1723 if (eol) return eol = false, EOL;
1724 var j = I;
1725 if (text.charCodeAt(j) === 34) {
1726 var i = j;
1727 while (i++ < N) {
1728 if (text.charCodeAt(i) === 34) {
1729 if (text.charCodeAt(i + 1) !== 34) break;
1730 ++i;
1731 }
1732 }
1733 I = i + 2;
1734 var c = text.charCodeAt(i + 1);
1735 if (c === 13) {
1736 eol = true;
1737 if (text.charCodeAt(i + 2) === 10) ++I;
1738 } else if (c === 10) {
1739 eol = true;
1740 }
1741 return text.substring(j + 1, i).replace(/""/g, '"');
1742 }
1743 while (I < N) {
1744 var c = text.charCodeAt(I++), k = 1;
1745 if (c === 10) eol = true; else if (c === 13) {
1746 eol = true;

Callers 1

d3.v3.jsFile · 0.85

Calls 6

tokenFunction · 0.85
formatValueFunction · 0.85
addMethod · 0.80
oFunction · 0.70
fFunction · 0.70
aFunction · 0.70

Tested by

no test coverage detected