Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
217 changed files
with
42,670 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
*.tgz | ||
*.swp | ||
*.swo | ||
README.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.git* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
language: node_js | ||
node_js: | ||
- 0.6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Copyright 2011 Nicolas Thouvenin <nthouvenin@gmail.com> | ||
|
||
This project is free software released under the MIT/X11 license: | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
|
||
# XMLWriter for NodeJS | ||
|
||
[![Build Status](https://secure.travis-ci.org/touv/node-csv-tools.png?branch=master)](http://travis-ci.org/touv/node-csv-tools) | ||
|
||
It's a collection of javascript tools for any kind of CSV. It tries to be tolerant. | ||
It can be used in a browser or with nodejs. | ||
|
||
## Contributors | ||
|
||
* [Nicolas Thouvenin](https://github.com/touv) | ||
|
||
# Installation | ||
|
||
With [npm](http://npmjs.org) do: | ||
|
||
$ # Coming soon | ||
|
||
|
||
# Examples | ||
|
||
|
||
# Tests | ||
|
||
Use [mocha](https://github.com/visionmedia/mocha) to run the tests. | ||
|
||
$ npm install mocha | ||
$ mocha test | ||
|
||
# API Documentation | ||
|
||
|
||
# Also | ||
|
||
* https://npmjs.org/browse/keyword/csv | ||
* http://www.uselesscode.org/javascript/csv/ | ||
* https://github.com/archan937/csonv.js | ||
|
||
# License | ||
|
||
[MIT/X11](./LICENSE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('./lib/csv.js'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
'use strict'; | ||
|
||
function reducer(item, memo, sep) { | ||
var foo = '' | ||
, c = new RegExp(sep, 'g') | ||
, q = new RegExp('"', 'g') | ||
, n = new RegExp('\n', 'g'); | ||
|
||
if (!item) { | ||
item = ''; | ||
} | ||
if (typeof item != 'string') { | ||
var s = item.toString(); | ||
if (s == '[object Object]') { | ||
item = JSON.stringify(item); | ||
if (item == '{}') { | ||
item = ''; | ||
} | ||
} | ||
else { | ||
item = s; | ||
} | ||
} | ||
if (memo) { | ||
foo = memo + sep; | ||
} | ||
if (item.search(c) >= 0 || item.search(q) >= 0 || item.search(n) >= 0) { | ||
foo += '"' + item.replace(q, '""') + '"'; | ||
} | ||
else { | ||
foo += ''+item; | ||
} | ||
return foo; | ||
} | ||
|
||
|
||
exports.separator = function(data) | ||
{ | ||
var separators = [{c: 0, v: ','}, {c: 0, v: ';'}, {c: 0, v: '|'}, {c: 0, v: '\t'}, {c:0, v:null}]; | ||
separators.forEach(function (item, indice) { | ||
item.c += data.split(item.v).length; | ||
} | ||
); | ||
var max = 0; | ||
var separator = separators.reduce(function (prev, cur) { | ||
if (cur.c >= max) { | ||
max = cur.c; | ||
return cur.v; | ||
} | ||
else { | ||
return prev; | ||
} | ||
}, null | ||
); | ||
return separator; | ||
} | ||
|
||
|
||
exports.stringify = function(input, sep) { | ||
var ret = ''; | ||
sep = sep || ","; | ||
if (Array.isArray(input)) { | ||
input.forEach(function(item) { | ||
ret = reducer(item, ret, sep); | ||
}); | ||
} | ||
else if (typeof input == 'object') { | ||
for (var key in input) { | ||
if (input.hasOwnProperty(key)) { | ||
ret = reducer(input[key], ret, sep); | ||
} | ||
} | ||
} | ||
else { | ||
ret = reducer(input, ret, sep); | ||
} | ||
return ret + "\r\n"; | ||
} | ||
|
||
exports.parse = function(input, sep) { | ||
|
||
var output = [], | ||
remainder = exports.forEach(sep, function(row, index) { | ||
|
||
}) | ||
} | ||
|
||
|
||
exports.forEach = function(input, sep, callback) { | ||
|
||
} | ||
|
||
exports.read = function(input, sep, callback) { | ||
sep = sep || ","; | ||
var fields = [], reminderIndex = 0, token = '', endingIndex = 0, endingLine = 0, startingIndex = 0, | ||
sepx = new RegExp('[^\\s'+sep+']+.'); | ||
|
||
// console.log('input:', input); | ||
// console.log('input.length:', input.length); | ||
// console.log('sep:', sep); | ||
while (startingIndex <= input.length ) { | ||
endingIndex = input.indexOf(sep, startingIndex); | ||
endingLine = input.indexOf('\n', startingIndex); | ||
// console.log('startingIndex:', startingIndex); | ||
// console.log('endingIndex:', endingIndex); | ||
// console.log('endingLine:', endingLine); | ||
|
||
if (endingIndex < 0) { | ||
endingIndex = input.length; | ||
} | ||
token = input.slice(startingIndex, endingIndex).trim(); | ||
// console.log('token:', token); | ||
if (token.charAt(0) == '"' && token.charAt(token.length - 1) == '"') { | ||
// D : "token" | ||
fields.push(token.slice(1, -1)); | ||
startingIndex = endingIndex + 1; | ||
} | ||
else if (token.charAt(0) == '"') { | ||
// A : "token | ||
// | ||
var s = input.slice(startingIndex + 1); | ||
if (s.indexOf('"') < 0) { | ||
reminderIndex = startingIndex; | ||
callback(fields); | ||
return reminderIndex; | ||
} | ||
else { | ||
var i = s.search(/[^\"]\"(?!\")/) + 1; | ||
fields.push(input.slice(startingIndex + 1, startingIndex + i + 1)); | ||
var j = input.slice(startingIndex + i + 2).search(sepx); | ||
startingIndex += i + 2 + (j >= 0 ? j : 0); | ||
} | ||
} | ||
else if (token.charAt(token.length - 1) == '"') { | ||
// C : token" | ||
fields.push(input.slice(startingIndex, endingIndex)); | ||
startingIndex = endingIndex + 1; | ||
} | ||
else { | ||
// B : token | ||
// console.log(endingLine, '<', endingIndex); | ||
if (endingLine >= 0 && endingLine < endingIndex) { | ||
fields.push(input.slice(startingIndex, endingLine)); | ||
reminderIndex = endingLine + 1; | ||
callback(fields); | ||
return reminderIndex; | ||
} | ||
fields.push(input.slice(startingIndex, endingIndex)); | ||
startingIndex = endingIndex + 1; | ||
} | ||
} | ||
reminderIndex = null; | ||
callback(fields); | ||
return reminderIndex; | ||
} | ||
|
||
exports.fetch = function(input, sep) { | ||
|
||
var output; | ||
exports.read(input, sep, function(fields) { | ||
output = fields; | ||
}); | ||
return output; | ||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.