fixing serializeCSV to pass test
This commit is contained in:
parent
0500672f19
commit
f7e79e08fd
@ -179,7 +179,7 @@ this.recline.Backend.CSV = this.recline.Backend.CSV || {};
|
||||
if (field === null) {
|
||||
// If field is null set to empty string
|
||||
field = '';
|
||||
} else if (typeof field === "string") {
|
||||
} else if (typeof field === "string" && rxNeedsQuoting.test(field)) {
|
||||
// Convert string to delimited string
|
||||
field = delimiter + field + delimiter;
|
||||
} else if (typeof field === "number") {
|
||||
@ -212,25 +212,6 @@ this.recline.Backend.CSV = this.recline.Backend.CSV || {};
|
||||
return out;
|
||||
};
|
||||
|
||||
var rxHasComma = /^\d+$/,
|
||||
rxIsFloat = /^\d*\.\d+$|^\d+\.\d*$/,
|
||||
// If a string has leading or trailing space,
|
||||
// contains a comma double quote or a newline
|
||||
// it needs to be quoted in CSV output
|
||||
rxNeedsQuoting = /^\s|\s$|,|"|\n/,
|
||||
trim = (function () {
|
||||
// Fx 3.1 has a native trim function, it's about 10x faster, use it if it exists
|
||||
if (String.prototype.trim) {
|
||||
return function (s) {
|
||||
return s.trim();
|
||||
};
|
||||
} else {
|
||||
return function (s) {
|
||||
return s.replace(/^\s*/, '').replace(/\s*$/, '');
|
||||
};
|
||||
}
|
||||
}());
|
||||
|
||||
var rxIsInt = /^\d+$/,
|
||||
rxIsFloat = /^\d*\.\d+$|^\d+\.\d*$/,
|
||||
// If a string has leading or trailing space,
|
||||
|
||||
@ -73,7 +73,7 @@ test("serializeCSV", function() {
|
||||
|
||||
var array = recline.Backend.CSV.serializeCSV(csv);
|
||||
var exp = '"Jones, Jay",10\n' +
|
||||
'"Xyz ""ABC"" O\'Brien",11:35\n' +
|
||||
'"Xyz \"ABC\" O\'Brien",11:35\n' +
|
||||
'"Other, AN",12:35\n';
|
||||
deepEqual(array, exp);
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user