Got CSV in your javascript? Use agnes.
secretGeek .:dot Nuts about dot Net:.
home .: about .: sign up .: sitemap .: secretGeek RSS

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.




name


website (optional)


enter the word:
 

comment (HTML not allowed)


All viewpoints welcome. Incivility is not tolerated, such comments are deleted.

 

I'm the co-author of TimeSnapper, a life analysis system that stores and plays-back your computer use. It makes timesheet recording a breeze, helps you recover lost work and shows you how to sharpen your act.

 

NimbleText - FREE text manipulation and data extraction

NimbleText is a Powerful FREE Tool

I wrote this, and use it every day for:

  • extracting data from text
  • manipulating text
  • generating code

It makes you look awesome. You should use NimbleText, you handsome devil!

 

Articles

A Computer Simulation of Creative Work, or 'How To Get Nothing Done' A Computer Simulation of Creative Work, or 'How To Get Nothing Done'
NimbleText 1.9 -- BoomTown! NimbleText 1.9 -- BoomTown!
Line Endings. Line Endings.
**This** is how you pivot **This** is how you pivot
Art of the command-line helper Art of the command-line helper
Go and read a book. Go and read a book.
Slurp up mega-traffic by writing scalable, timeless search-bait Slurp up mega-traffic by writing scalable, timeless search-bait
Do *NOT* try this Hacking Script at home Do *NOT* try this Hacking Script at home
The 'Should I automate it?' Calculator The 'Should I automate it?' Calculator
aaron swartz: the early works aaron swartz: the early works
Finding (and removing) duplicate files on your hard drive Finding (and removing) duplicate files on your hard drive
Harvey, a .net chat server built with RabbitMQ Harvey, a .net chat server built with RabbitMQ
LeonBambrick.com LeonBambrick.com
So your domain has been stolen. What now? So your domain has been stolen. What now?
kv can remember it for you, wholesale kv can remember it for you, wholesale
Hello IT Department Hello IT Department
Dialog Between a Man and His Vista Laptop Dialog Between a Man and His Vista Laptop
NimbleText 1.6, Codename Jetboat NimbleText 1.6, Codename Jetboat
On Task Hoarding and Todo Bankruptcy On Task Hoarding and Todo Bankruptcy
Developer UI Done Right: Mercurial Commandline! Developer UI Done Right: Mercurial Commandline!
Rediscovering the Amstrad CPC 6128 Rediscovering the Amstrad CPC 6128
Just Wally Just Wally
The Correct Order for a First Time Viewing of The Lord Of The Rings The Correct Order for a First Time Viewing of The Lord Of The Rings
A new era for Android. A new era for Android.
Mind-boggling Demo of New Gaming Genre, aka Folder-Based Hangman, aka Fun with Recursion Mind-boggling Demo of New Gaming Genre, aka Folder-Based Hangman, aka Fun with Recursion
Got CSV in your javascript? Use agnes. Got CSV in your javascript? Use agnes.

Archives Complete secretGeek Archives

TimeSnapper -- Automated Screenshot Journal TimeSnapper: automatic screenshot journal

25 steps for building a Micro-ISV 25 steps for building a Micro-ISV
3 minute guides -- babysteps in new technologies: powershell, JSON, watir, F# 3 Minute Guide Series
Universal Troubleshooting checklist Universal Troubleshooting Checklist
Top 10 SecretGeek articles Top 10 SecretGeek articles
ShinyPower (help with Powershell) ShinyPower
Now at CodePlex

Realtime CSS Editor, in a browser RealTime Online CSS Editor
Gradient Maker -- a tool for making background images that blend from one colour to another. Forget photoshop, this is the bomb. Gradient Maker


[powered by Google] 


How to be depressed 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

LinkedIn profile
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
 
home .: about .: sign up .: sitemap .: secretGeek RSS .: © Leon Bambrick 2006 .: privacy

home .: about .: sign up .: sitemap .: RSS .: © Leon Bambrick 2006 .: privacy