Permalink
Browse files

_appendField now handles pretty much every type of value passed to it

  • Loading branch information...
1 parent 2747f7e commit 07c75f6437cc52203e166c575f0361c2d567f16d @tedeh tedeh committed Oct 23, 2011
Showing with 9 additions and 6 deletions.
  1. +9 −6 lib/ya-csv.js
View
@@ -213,14 +213,17 @@ function _writeArray(writer, arr) {
};
function _appendField(outArr, writer, field) {
- if (field == null) {
- outArr.push('');
+ // Make sure field is a string
+ if(typeof(field) !== 'string') {
+ // We are not interested in outputting "null" or "undefined"
+ if(typeof(field) !== 'undefined' && field !== null) {
+ field = String(field);
+ } else {
+ outArr.push('');
return;
+ }
}
- if (field.length == undefined){
- //deal with numbers
- field = '' + field;
- }
+
for (var i = 0; i < field.length; i++) {
if (field.charAt(i) === writer.quotechar || field.charAt(i) === writer.escapechar) {
outArr.push(writer.escapechar);

0 comments on commit 07c75f6

Please sign in to comment.