Got CSV in your javascript? Use agnes.
The only things that will survive the forthcoming nuclear+zombie apocalypse are cockroaches, javascript and CSV.
So I've written an open source javascript library, agnes.js, that the cockroaches can use for dealing with CSV from javascript. And in the brief pre-apocalypse era you can use it too.
Download the zip
I've written before about how CSV starts off looking easy, but quickly descends into a world of insanity. So in javascript land, let agnes handle all the nasty quirks and edge cases (embedded delimiters, qualifiers, nulls and so on).
I wrote a bunch of unit tests to go with it, so you can tell exactly what it does with each weird bit of input you can throw at it.
You can download it from agnes.codeplex.com
This was a particularly fun little bus project, and what I like best about agnes is the content you get when you download her.
The readme file has executable examples, that work by having a chunk of code displayed in a div, which is the exact code that is grabbed and executed when you click 'Try it'.
Browse source code
I like the unit tests that come with it, and the little unit test runner. I could've gone really overboard with it, but I stopped myself before it went too far.
And I like the sample that performs Csv to Json conversion, back and forth, back and forth. My favourite part of that is using html entities in the button titles, for left and right arrows.
Try it out
Now that I've got agnes out of the way, hopefully I can focus on my new bilion dollar idea, youmustget.com
'Goran' on Sun, 27 Nov 2011 09:53:41 GMT, sez: You had me at function Handbag takes parameter Purse :)
'Johnny Fuery' on Fri, 03 Aug 2012 23:13:55 GMT, sez:
This test case fails:
"Title", "Start Time", "Start Date", "Notes"
"Sample One", "09:30 AM", "2012-09-09", "Will do.
Look, line feeds in this last field.
Yup."
The issue is due to the default stripping of the fieldDelim (double quote by default) in toArray().
This fix works for me, starting at line 105 in agnes.js:
_agnes.csvToArray2d = function(lines, rowDelim, fieldDelim) {
var lineArray;
rowDelim = rowDelim || this.rowDelimiter();
fieldDelim = fieldDelim || ",";
_p.purse.stripQuote = false; // jfuery was here
lineArray = this.toArray(lines, rowDelim);
_p.purse.stripQuote = true; // jfuery was here
This didn't quite seem worthy of a pull request. Maybe if it was on github I'd have done it...
Hope this is helpful.
'lb' on Wed, 15 Aug 2012 12:48:31 GMT, sez: @Johnny Fuery
Thanks for excellent research finding the bug and the fix.
I've patched agnes, and updated the code at codeplex, plus put out a new release.
I fixed it in a slightly different way, and added more unit tests to catch the problem.
cheers!
lb
'types of cooking oil' on Mon, 24 Sep 2012 09:59:23 GMT, sez: so I am sure this website will form the well-known in the future.
|
Articles
A Computer Simulation of Creative Work, or 'How To Get Nothing Done'
NimbleText 1.9 -- BoomTown!
Line Endings.
**This** is how you pivot
Art of the command-line helper
Go and read a book.
Slurp up mega-traffic by writing scalable, timeless search-bait
Do *NOT* try this Hacking Script at home
The 'Should I automate it?' Calculator
aaron swartz: the early works
Finding (and removing) duplicate files on your hard drive
Harvey, a .net chat server built with RabbitMQ
LeonBambrick.com
So your domain has been stolen. What now?
kv can remember it for you, wholesale
Hello IT Department
Dialog Between a Man and His Vista Laptop
NimbleText 1.6, Codename Jetboat
On Task Hoarding and Todo Bankruptcy
Developer UI Done Right: Mercurial Commandline!
Rediscovering the Amstrad CPC 6128
Just Wally
The Correct Order for a First Time Viewing of The Lord Of The Rings
A new era for Android.
Mind-boggling Demo of New Gaming Genre, aka Folder-Based Hangman, aka Fun with Recursion
Got CSV in your javascript? Use agnes.
Complete secretGeek Archives
TimeSnapper: automatic screenshot journal
25 steps for building a Micro-ISV
3 Minute Guide Series
Universal Troubleshooting Checklist
Top 10 SecretGeek articles
ShinyPower Now at CodePlex
RealTime Online CSS Editor
Gradient Maker
How to be depressed
You are not inadequate.
Recommended Reading
 the little schemer
The Best Software Writing I
The Business Of Software (Eric Sink)
Recommended blogs
Jeff Atwood
Joseph Cooney
Phil Haack
Scott Hanselman
Julia Lerman
Rhys Parry
Joel Pobar
OJ Reeves
Eric Sink
Aggregated Links
proggit
dzone
hacker news
dot net kicks
Human Link Machines
interesting finds
a continuous learner's weblog
arjan's world
weekly link post
LogEnvy - event logs made sexy
Computer, Unlocked. A rapid computer customization resource
Aussie Bushwalking
BrisParks :: best parks for kids in brisbane
PhysioTec, Brisbane Specialist Physiotherapy & Pilates
|