diff --git a/lib/string.js b/lib/string.js index af5754d..a58a3ac 100644 --- a/lib/string.js +++ b/lib/string.js @@ -446,7 +446,7 @@ string.js - Copyright (C) 2012-2013, JP Richardson return (template+pruneStr).length > str.length ? new S(str) : new S(str.slice(0, template.length)+pruneStr); }, - toCSV: function() { + toCSV: function(options) { var delim = ',', qualifier = '"', escape = '\\', encloseNumbers = true, keys = false; var dataArray = []; @@ -454,15 +454,15 @@ string.js - Copyright (C) 2012-2013, JP Richardson return it !== null && it !== ''; } - if (typeof arguments[0] === 'object') { - delim = arguments[0].delimiter || delim; - delim = arguments[0].separator || delim; - qualifier = arguments[0].qualifier || qualifier; - encloseNumbers = !!arguments[0].encloseNumbers; - escape = arguments[0].escape || escape; - keys = !!arguments[0].keys; - } else if (typeof arguments[0] === 'string') { - delim = arguments[0]; + if (typeof options === 'object') { + delim = options.delimiter === undefined ? delim : options.delimiter; + delim = options.separator === undefined ? delim : options.separator; + qualifier = (options.qualifier === undefined ? qualifier : options.qualifier); + escape = (options.escape === undefined ? escape : options.escape); + encloseNumbers = !!options.encloseNumbers; + keys = !!options.keys; + } else if (typeof options === 'string') { + delim = options; } if (typeof arguments[1] === 'string')