Comments (6)
I honestly have very little experience with Node.js so it will take me a while
to get a dev environment setup to to play with this.
I think your problem comes from the way you're calling require. Because jQuery
and jquery-csv assume that they're going to be imported into a global namespace
by default they take care of the assignment on their own.
If you look at the source, all of the jquery-csv code is contained within an
anonymous function closure that is assigned to both the jQuery parameter as
well as the $ variable no matter how you call it.
Take a look at http://docs.jquery.com/Plugins/Authoring to see how it works.
Basically, I don't think you need to assign jquery-csv to a variable because it
should automatically attach to the jquery namespace.
Try this:
var $ = require(jquery);
require('jquery.csv.js');
Both should be callable through the jQuery or the $ variables.
Try it out to see if it works. If not, I'll get a node env setup as soon as I
have the time to get a working implementation established.
The key is, if this gets documented as a use case for jquery-csv it needs to
work with the client-side documentation/guides as closely as possible.
Original comment by [email protected]
on 1 Oct 2012 at 10:53
from jquery-csv.
OK, after further exploration and testing I have a definitive answer.
*Here's how you import jquery-csv:*
var $ = jQuery = require('jquery');
require('./jquery.csv.js');
Basically, calling require() without assigning it runs it in the global
namespace the same as importing via a <script> tag does in the browser.
In the browser jQuery is callable via '$' but is actually assigned to the
'jQuery' variable; that's why both assignments are necessary.
If you want to try it out here's the example code I used for testing:
var fs = require('fs');
var $ = jQuery = require('jquery');
require('./jquery.csv.js');
var file = './example.csv';
fs.readFile(file, 'UTF-8', function(err, csv) {
var data = $.csv.toArrays(csv);
for(var i=0, len=data.length; i<len; i++) {
console.log(data[i]);
}
});
_Note: You'll need to provide your own example.csv file and put it in the same
directory as jquery/jquery-csv but it should work._
What it does is read in a csv file, converts it to a 2D array, and outputs the
data to the console.
If you want to see how the object transform works, provide headers in the first
line of the CSV file and call $.csv.toObjects(csv) instead.
I haven't added any demo's to the project yet but when I do I'll be sure to add
this.
Original comment by [email protected]
on 3 Oct 2012 at 11:13
from jquery-csv.
Original comment by [email protected]
on 3 Oct 2012 at 11:14
- Changed state: Done
from jquery-csv.
Thanks for fixing this. I moved on to using the node-csv-parser though, since
its API fits my use case better.
Link here:
https://github.com/wdavidw/node-csv-parser
Original comment by [email protected]
on 4 Oct 2012 at 12:20
from jquery-csv.
No problem...
Now that I have a Node.js environment up and running I'm going to see if I can
add some solid callback support to make it work in a manner familiar to most
Node programmers.
Node isn't really something I have considered up until you submitted this
issue. I think it'll be interesting to add a demo showing how to implement a
100% JS CSV SaaS (ie client/server) module.
Thank you for your feedback.
Original comment by [email protected]
on 4 Oct 2012 at 10:17
from jquery-csv.
Original comment by [email protected]
on 11 Oct 2012 at 4:08
from jquery-csv.
Related Issues (20)
- doesn't seem to recoginse end of line properly in some cases. HOT 1
- CR line ending are not well treated HOT 1
- Typo in basic-usage.html (fixed in 0.8.0) HOT 2
- Enhancement: Parse CSV in a thread using settimeout HOT 3
- 배열의 기본 속성값(remove)이 포함 됩니다. HOT 1
- Karma test fails - HOT 2
- Failures on test.html file HOT 2
- colNum not reset when onParseValue callback called
- Export $ globally in browser when not already set
- CSVDataError: Illegal State - Only in IE HOT 3
- Using Zurb Foundation 3 causing an error HOT 3
- $.csv.toObjects return garbage value HOT 3
- Parse doesn't handle quotes in the CSV, even if escaped HOT 3
- Hooks relying on a return value of false to skip entries makes parsing values that resolve to false impossible
- CSV file created with Excel for Mac fails HOT 3
- Uncaught ReferenceError: require is not defined
- Generate Motion chart HOT 1
- Options arg not really optional? HOT 2
- TypeError: csv.replace is not a function
- Data Format
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jquery-csv.