Skip to content

Commit e84432f

Browse files
committed
New release
1 parent d34fdf0 commit e84432f

File tree

4 files changed

+41
-6
lines changed

4 files changed

+41
-6
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ng-csv",
3-
"version": "0.3.2",
3+
"version": "0.3.3",
44
"main": "build/ng-csv.min.js",
55
"dependencies": {
66
"angular": "~1",

build/ng-csv.js

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ angular.module('ngCsv.services').
3636
var EOL = '\r\n';
3737
var BOM = "\ufeff";
3838

39+
var specialChars = {
40+
'\\t': '\t',
41+
'\\b': '\b',
42+
'\\v': '\v',
43+
'\\f': '\f',
44+
'\\r': '\r'
45+
};
46+
3947
/**
4048
* Stringify one field
4149
* @param data
@@ -94,7 +102,7 @@ angular.module('ngCsv.services').
94102
var csvContent = "";
95103

96104
var dataPromise = $q.when(data).then(function (responseData) {
97-
responseData = angular.copy(responseData);
105+
//responseData = angular.copy(responseData);//moved to row creation
98106
// Check if there's a provided header array
99107
if (angular.isDefined(options.header) && options.header) {
100108
var encodingArray, headerString;
@@ -117,7 +125,8 @@ angular.module('ngCsv.services').
117125
arrData = responseData();
118126
}
119127

120-
angular.forEach(arrData, function (row, index) {
128+
angular.forEach(arrData, function (oldRow, index) {
129+
var row = angular.copy(arrData[index]);
121130
var dataString, infoArray;
122131

123132
infoArray = [];
@@ -148,6 +157,27 @@ angular.module('ngCsv.services').
148157

149158
return def.promise;
150159
};
160+
161+
/**
162+
* Helper function to check if input is really a special character
163+
* @param input
164+
* @returns {boolean}
165+
*/
166+
this.isSpecialChar = function(input){
167+
return specialChars[input] !== undefined;
168+
};
169+
170+
/**
171+
* Helper function to get what the special character was supposed to be
172+
* since Angular escapes the first backslash
173+
* @param input
174+
* @returns {special character string}
175+
*/
176+
this.getSpecialChar = function (input) {
177+
return specialChars[input];
178+
};
179+
180+
151181
}]);
152182
/**
153183
* ng-csv module
@@ -200,8 +230,13 @@ angular.module('ngCsv.directives').
200230
addByteOrderMarker: $scope.addByteOrderMarker
201231
};
202232
if (angular.isDefined($attrs.csvHeader)) options.header = $scope.$eval($scope.header);
233+
234+
203235
options.fieldSep = $scope.fieldSep ? $scope.fieldSep : ",";
204236

237+
// Replaces any badly formatted special character string with correct special character
238+
options.fieldSep = CSV.isSpecialChar(options.fieldSep) ? CSV.getSpecialChar(options.fieldSep) : options.fieldSep;
239+
205240
return options;
206241
}
207242

build/ng-csv.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ng-csv",
3-
"version": "0.3.2",
3+
"version": "0.3.3",
44
"main": "build/ng-csv.min.js",
55
"description": "Simple directive that turns arrays and objects into downloadable CSV files",
66
"repository": {

0 commit comments

Comments
 (0)