Skip to content

Commit

Permalink
New release
Browse files Browse the repository at this point in the history
  • Loading branch information
asafdav committed Apr 25, 2015
1 parent d34fdf0 commit e84432f
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ng-csv",
"version": "0.3.2",
"version": "0.3.3",
"main": "build/ng-csv.min.js",
"dependencies": {
"angular": "~1",
Expand Down
39 changes: 37 additions & 2 deletions build/ng-csv.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ angular.module('ngCsv.services').
var EOL = '\r\n';
var BOM = "\ufeff";

var specialChars = {
'\\t': '\t',
'\\b': '\b',
'\\v': '\v',
'\\f': '\f',
'\\r': '\r'
};

/**
* Stringify one field
* @param data
Expand Down Expand Up @@ -94,7 +102,7 @@ angular.module('ngCsv.services').
var csvContent = "";

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

angular.forEach(arrData, function (row, index) {
angular.forEach(arrData, function (oldRow, index) {
var row = angular.copy(arrData[index]);
var dataString, infoArray;

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

return def.promise;
};

/**
* Helper function to check if input is really a special character
* @param input
* @returns {boolean}
*/
this.isSpecialChar = function(input){
return specialChars[input] !== undefined;
};

/**
* Helper function to get what the special character was supposed to be
* since Angular escapes the first backslash
* @param input
* @returns {special character string}
*/
this.getSpecialChar = function (input) {
return specialChars[input];
};


}]);
/**
* ng-csv module
Expand Down Expand Up @@ -200,8 +230,13 @@ angular.module('ngCsv.directives').
addByteOrderMarker: $scope.addByteOrderMarker
};
if (angular.isDefined($attrs.csvHeader)) options.header = $scope.$eval($scope.header);


options.fieldSep = $scope.fieldSep ? $scope.fieldSep : ",";

// Replaces any badly formatted special character string with correct special character
options.fieldSep = CSV.isSpecialChar(options.fieldSep) ? CSV.getSpecialChar(options.fieldSep) : options.fieldSep;

return options;
}

Expand Down
4 changes: 2 additions & 2 deletions build/ng-csv.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ng-csv",
"version": "0.3.2",
"version": "0.3.3",
"main": "build/ng-csv.min.js",
"description": "Simple directive that turns arrays and objects into downloadable CSV files",
"repository": {
Expand Down

0 comments on commit e84432f

Please sign in to comment.