Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use -r dsv to get dsv to work

commit 22ddd2553defa3d206555cb4658143803f652f0a 1 parent 18eb09e
@tmcw tmcw authored
View
2  Makefile
@@ -1,4 +1,4 @@
all: csv2geojson.js
csv2geojson.js: index.js package.json
- browserify -s csv2geojson index.js > csv2geojson.js
+ browserify -t brfs -r dsv -s csv2geojson index.js > csv2geojson.js
View
134 csv2geojson.js
@@ -1,6 +1,6 @@
(function(e){if("function"==typeof bootstrap)bootstrap("csv2geojson",e);else if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else if("undefined"!=typeof ses){if(!ses.ok())return;ses.makeCsv2geojson=e}else"undefined"!=typeof window?window.csv2geojson=e():global.csv2geojson=e()})(function(){var define,ses,bootstrap,module,exports;
return (function(e,t,n){function i(n,s){if(!t[n]){if(!e[n]){var o=typeof require=="function"&&require;if(!s&&o)return o(n,!0);if(r)return r(n,!0);throw new Error("Cannot find module '"+n+"'")}var u=t[n]={exports:{}};e[n][0].call(u.exports,function(t){var r=e[n][1][t];return i(r?r:t)},u,u.exports)}return t[n].exports}var r=typeof require=="function"&&require;for(var s=0;s<n.length;s++)i(n[s]);return i})({1:[function(require,module,exports){
-var dsv = require('./dsv');
+var dsv = require('dsv');
function isLat(f) { return !!f.match(/(Lat)(itude)?/gi); }
function isLon(f) { return !!f.match(/(L)(on|lng)(gitude)?/i); }
@@ -74,7 +74,7 @@ function csv2geojson(x, options, callback) {
callback(errors.length ? errors: null, featurecollection);
}
-function toline(gj) {
+function toLine(gj) {
var features = gj.features;
var line = {
type: 'Feature',
@@ -93,7 +93,7 @@ function toline(gj) {
};
}
-function topolygon(gj) {
+function toPolygon(gj) {
var features = gj.features;
var poly = {
type: 'Feature',
@@ -119,129 +119,19 @@ module.exports = {
tsv: dsv.tsv.parse,
dsv: dsv,
csv2geojson: csv2geojson,
- toline: toline,
- topolygon: topolygon
+ toLine: toLine,
+ toPolygon: toPolygon
};
-},{"./dsv":2}],2:[function(require,module,exports){
-module.exports = dsv;
-
-dsv.version = "0.0.2";
-
-dsv.tsv = dsv("\t");
-dsv.csv = dsv(",");
-
-function dsv(delimiter) {
- var dsv = {},
- reFormat = new RegExp("[\"" + delimiter + "\n]"),
- delimiterCode = delimiter.charCodeAt(0);
-
- dsv.parse = function(text, f) {
- var o;
- return dsv.parseRows(text, function(row, i) {
- if (o) return o(row, i - 1);
- var a = new Function("d", "return {" + row.map(function(name, i) {
- return JSON.stringify(name) + ": d[" + i + "]";
- }).join(",") + "}");
- o = f ? function(row, i) { return f(a(row), i); } : a;
- });
- };
-
- dsv.parseRows = function(text, f) {
- var EOL = {}, // sentinel value for end-of-line
- EOF = {}, // sentinel value for end-of-file
- rows = [], // output rows
- N = text.length,
- I = 0, // current character index
- n = 0, // the current line number
- t, // the current token
- eol; // is the current token followed by EOL?
-
- function token() {
- if (I >= N) return EOF; // special case: end of file
- if (eol) return eol = false, EOL; // special case: end of line
-
- // special case: quotes
- var j = I;
- if (text.charCodeAt(j) === 34) {
- var i = j;
- while (i++ < N) {
- if (text.charCodeAt(i) === 34) {
- if (text.charCodeAt(i + 1) !== 34) break;
- ++i;
- }
- }
- I = i + 2;
- var c = text.charCodeAt(i + 1);
- if (c === 13) {
- eol = true;
- if (text.charCodeAt(i + 2) === 10) ++I;
- } else if (c === 10) {
- eol = true;
- }
- return text.substring(j + 1, i).replace(/""/g, "\"");
- }
-
- // common case: find next delimiter or newline
- while (I < N) {
- var c = text.charCodeAt(I++), k = 1;
- if (c === 10) eol = true; // \n
- else if (c === 13) { eol = true; if (text.charCodeAt(I) === 10) ++I, ++k; } // \r|\r\n
- else if (c !== delimiterCode) continue;
- return text.substring(j, I - k);
- }
-
- // special case: last token before EOF
- return text.substring(j);
- }
+},{"dsv":"kPifln"}],"dsv":[function(require,module,exports){
+module.exports=require('kPifln');
+},{}],"kPifln":[function(require,module,exports){
+var fs = require("fs");
- while ((t = token()) !== EOF) {
- var a = [];
- while (t !== EOL && t !== EOF) {
- a.push(t);
- t = token();
- }
- if (f && !(a = f(a, n++))) continue;
- rows.push(a);
- }
+module.exports = new Function("dsv.version = \"0.0.2\";\n\ndsv.tsv = dsv(\"\\t\");\ndsv.csv = dsv(\",\");\n\nfunction dsv(delimiter) {\n var dsv = {},\n reFormat = new RegExp(\"[\\\"\" + delimiter + \"\\n]\"),\n delimiterCode = delimiter.charCodeAt(0);\n\n dsv.parse = function(text, f) {\n var o;\n return dsv.parseRows(text, function(row, i) {\n if (o) return o(row, i - 1);\n var a = new Function(\"d\", \"return {\" + row.map(function(name, i) {\n return JSON.stringify(name) + \": d[\" + i + \"]\";\n }).join(\",\") + \"}\");\n o = f ? function(row, i) { return f(a(row), i); } : a;\n });\n };\n\n dsv.parseRows = function(text, f) {\n var EOL = {}, // sentinel value for end-of-line\n EOF = {}, // sentinel value for end-of-file\n rows = [], // output rows\n N = text.length,\n I = 0, // current character index\n n = 0, // the current line number\n t, // the current token\n eol; // is the current token followed by EOL?\n\n function token() {\n if (I >= N) return EOF; // special case: end of file\n if (eol) return eol = false, EOL; // special case: end of line\n\n // special case: quotes\n var j = I;\n if (text.charCodeAt(j) === 34) {\n var i = j;\n while (i++ < N) {\n if (text.charCodeAt(i) === 34) {\n if (text.charCodeAt(i + 1) !== 34) break;\n ++i;\n }\n }\n I = i + 2;\n var c = text.charCodeAt(i + 1);\n if (c === 13) {\n eol = true;\n if (text.charCodeAt(i + 2) === 10) ++I;\n } else if (c === 10) {\n eol = true;\n }\n return text.substring(j + 1, i).replace(/\"\"/g, \"\\\"\");\n }\n\n // common case: find next delimiter or newline\n while (I < N) {\n var c = text.charCodeAt(I++), k = 1;\n if (c === 10) eol = true; // \\n\n else if (c === 13) { eol = true; if (text.charCodeAt(I) === 10) ++I, ++k; } // \\r|\\r\\n\n else if (c !== delimiterCode) continue;\n return text.substring(j, I - k);\n }\n\n // special case: last token before EOF\n return text.substring(j);\n }\n\n while ((t = token()) !== EOF) {\n var a = [];\n while (t !== EOL && t !== EOF) {\n a.push(t);\n t = token();\n }\n if (f && !(a = f(a, n++))) continue;\n rows.push(a);\n }\n\n return rows;\n };\n\n dsv.format = function(rows) {\n if (Array.isArray(rows[0])) return dsv.formatRows(rows); // deprecated; use formatRows\n var fieldSet = {}, fields = [];\n\n // Compute unique fields in order of discovery.\n rows.forEach(function(row) {\n for (var field in row) {\n if (!(field in fieldSet)) {\n fields.push(fieldSet[field] = field);\n }\n }\n });\n\n return [fields.map(formatValue).join(delimiter)].concat(rows.map(function(row) {\n return fields.map(function(field) {\n return formatValue(row[field]);\n }).join(delimiter);\n })).join(\"\\n\");\n };\n\n dsv.formatRows = function(rows) {\n return rows.map(formatRow).join(\"\\n\");\n };\n\n function formatRow(row) {\n return row.map(formatValue).join(delimiter);\n }\n\n function formatValue(text) {\n return reFormat.test(text) ? \"\\\"\" + text.replace(/\\\"/g, \"\\\"\\\"\") + \"\\\"\" : text;\n }\n\n return dsv;\n}\n" + ";return dsv")();
- return rows;
- };
-
- dsv.format = function(rows) {
- if (Array.isArray(rows[0])) return dsv.formatRows(rows); // deprecated; use formatRows
- var fieldSet = {}, fields = [];
-
- // Compute unique fields in order of discovery.
- rows.forEach(function(row) {
- for (var field in row) {
- if (!(field in fieldSet)) {
- fields.push(fieldSet[field] = field);
- }
- }
- });
-
- return [fields.map(formatValue).join(delimiter)].concat(rows.map(function(row) {
- return fields.map(function(field) {
- return formatValue(row[field]);
- }).join(delimiter);
- })).join("\n");
- };
-
- dsv.formatRows = function(rows) {
- return rows.map(formatRow).join("\n");
- };
-
- function formatRow(row) {
- return row.map(formatValue).join(delimiter);
- }
-
- function formatValue(text) {
- return reFormat.test(text) ? "\"" + text.replace(/\"/g, "\"\"") + "\"" : text;
- }
-
- return dsv;
-}
+},{"fs":2}],2:[function(require,module,exports){
+// nothing to see here... no file methods for the browser
},{}]},{},[1])(1)
});
View
6 index.js
@@ -1,4 +1,4 @@
-var dsv = require('./dsv');
+var dsv = require('dsv');
function isLat(f) { return !!f.match(/(Lat)(itude)?/gi); }
function isLon(f) { return !!f.match(/(L)(on|lng)(gitude)?/i); }
@@ -117,6 +117,6 @@ module.exports = {
tsv: dsv.tsv.parse,
dsv: dsv,
csv2geojson: csv2geojson,
- toLine: toline,
- toPolygon: topolygon
+ toLine: toLine,
+ toPolygon: toPolygon
};
View
4 package.json
@@ -20,6 +20,8 @@
"mocha-phantomjs": "~1.1.1"
},
"dependencies": {
- "optimist": "~0.4.0"
+ "optimist": "~0.4.0",
+ "dsv": "0.0.2",
+ "brfs": "0.0.7"
}
}
View
3  site/site.js
@@ -61,7 +61,8 @@ if (typeof(window.FileReader) !== 'undefined') {
$('#dragdrop-enabled').show();
}
-$(window).on('drop', function(e) {
+$('#page').on('drop', function(e) {
+ console.log('here');
e.stopPropagation();
e.preventDefault();
$('#overlay').hide();
Please sign in to comment.
Something went wrong with that request. Please try again.