Merge pull request #13 from abdennour/fix-special-characters-bug

Fix special characters bug : it closes #10
This commit is contained in:
abdennour 2017-04-13 22:16:10 +03:00 committed by GitHub
commit 6e52b4cd9e
8 changed files with 4264 additions and 30 deletions

4226
cdn/react-csv-1.0.6.js Normal file

File diff suppressed because it is too large Load diff

3
cdn/react-csv-1.0.6.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View file

@ -220,7 +220,7 @@ var toCSV = exports.toCSV = function toCSV(data, headers, separator) {
};
var buildURI = exports.buildURI = function buildURI(data, headers, separator) {
return encodeURI('data:text/csv;charset=utf-8,' + toCSV(data, headers, separator));
return encodeURI('data:text/csv;charset=utf-8,\uFEFF,' + toCSV(data, headers, separator));
};
},{}],5:[function(require,module,exports){
'use strict';
@ -861,6 +861,17 @@ var fourArgumentPooler = function (a1, a2, a3, a4) {
}
};
var fiveArgumentPooler = function (a1, a2, a3, a4, a5) {
var Klass = this;
if (Klass.instancePool.length) {
var instance = Klass.instancePool.pop();
Klass.call(instance, a1, a2, a3, a4, a5);
return instance;
} else {
return new Klass(a1, a2, a3, a4, a5);
}
};
var standardReleaser = function (instance) {
var Klass = this;
!(instance instanceof Klass) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Trying to release an instance into a pool of a different type.') : _prodInvariant('25') : void 0;
@ -900,7 +911,8 @@ var PooledClass = {
oneArgumentPooler: oneArgumentPooler,
twoArgumentPooler: twoArgumentPooler,
threeArgumentPooler: threeArgumentPooler,
fourArgumentPooler: fourArgumentPooler
fourArgumentPooler: fourArgumentPooler,
fiveArgumentPooler: fiveArgumentPooler
};
module.exports = PooledClass;
@ -3094,14 +3106,7 @@ var ReactElementValidator = {
// We warn in this case but don't throw. We expect the element creation to
// succeed and there will likely be errors in render.
if (!validType) {
if (typeof type !== 'function' && typeof type !== 'string') {
var info = '';
if (type === undefined || typeof type === 'object' && type !== null && Object.keys(type).length === 0) {
info += ' You likely forgot to export your component from the file ' + 'it\'s defined in.';
}
info += getDeclarationErrorAddendum();
process.env.NODE_ENV !== 'production' ? warning(false, 'React.createElement: type is invalid -- expected a string (for ' + 'built-in components) or a class/function (for composite ' + 'components) but got: %s.%s', type == null ? type : typeof type, info) : void 0;
}
process.env.NODE_ENV !== 'production' ? warning(false, 'React.createElement: type should not be null, undefined, boolean, or ' + 'number. It should be a string (for DOM elements) or a ReactClass ' + '(for composite components).%s', getDeclarationErrorAddendum()) : void 0;
}
var element = ReactElement.createElement.apply(this, arguments);
@ -3797,7 +3802,7 @@ module.exports = ReactPureComponent;
'use strict';
module.exports = '15.4.2';
module.exports = '15.4.1';
},{}],31:[function(require,module,exports){
(function (process){
/**

File diff suppressed because one or more lines are too long

View file

@ -1,6 +1,6 @@
{
"name": "react-csv",
"version": "1.0.5",
"version": "1.0.6",
"description": "Build CSV files on the fly basing on Array/literal object of data ",
"main": "index.js",
"jsnext:main": "src/index.js",
@ -59,7 +59,7 @@
"console-info": "0.0.4",
"coveralls": "^2.11.15",
"css-loader": "^0.26.1",
"enzyme": "^2.6.0",
"enzyme": "2.7.1",
"expect": "^1.20.2",
"extract-text-webpack-plugin": "^1.0.1",
"isparta-loader": "^2.0.0",
@ -67,10 +67,10 @@
"jsdom-global": "2.1.0",
"mocha": "^3.2.0",
"mocha-lcov-reporter": "^1.2.0",
"react": "^15.4.1",
"react": "15.4.1",
"react-addons-test-utils": "^15.4.1",
"react-docgen": "^2.13.0",
"react-dom": "^15.4.1",
"react-dom": "15.4.1",
"react-styleguidist": "^4.6.3",
"sass-loader": "^4.0.2",
"sinon": "^1.17.6",

View file

@ -3,16 +3,16 @@ import {CSVLink, CSVDownload} from 'react-csv';
import Table from './Table.jsx';
const csvHeaders = [
"Company","Contact","Country"
"Company","جهة الإتصال ","王玉普"
]
const csvData =[
['Alfreds Futterkiste' ,'Maria Anders', 'Germany'] ,
['Rathath IT', 'Abdennour TM' , 'Tunisia'] ,
['Laughing Bacchus Winecellars', 'Yoshi Tannamuri' , 'Canada'],
['Rathath IT', 'Abdennour TM' , 'تونس'] ,
['Sinopec', '王玉普' , '中国'],
['Auto1', 'Petter' , 'Germany'] ,
['Estifeda', 'Yousri K' , 'Tunisia'] ,
['Nine 10ᵗʰ', 'Amjed Idris' , 'Saudi Arabia'] ,
['Tamkeen', 'Mohamed Alshibi' , 'Saudi Arabia'] ,
['Estifeda', 'Yousri K' , 'تونس'] ,
['Nine 10ᵗʰ', 'Amjed Idris' , 'المملكة العربية السعودية '] ,
['Tamkeen', 'Mohamed Alshibi' , 'المملكة العربية السعودية'] ,
['Packet Publishing', 'David Become' , 'UK'] ,
['Software hourse', 'Soro' , 'Poland']
];

View file

@ -41,6 +41,6 @@ export const toCSV = (data, headers, separator) => {
};
export const buildURI = ((data, headers, separator) => encodeURI(
`data:text/csv;charset=utf-8,${toCSV(data, headers, separator)}`
`data:text/csv;charset=utf-8,\uFEFF,${toCSV(data, headers, separator)}`
)
);

View file

@ -241,19 +241,19 @@ describe(`core::buildURI`, () =>{
});
it(`generates CSV string according to "separator"`, () => {
const prefixCsvURI= `data:text/csv;charset=utf-8,`;
const prefixCsvURI= `data:text/csv;charset=utf-8,\uFEFF,`;
const expectedSepartorCount = fixtures.arrays.map(row => row.length -1).reduce((total, next) =>total + next, 0);
let separator = ';';
let fullURI = buildURI(fixtures.arrays,null , separator);
let fullURI = buildURI(fixtures.arrays, null , separator);
expect(
fullURI.slice(prefixCsvURI.length).match(/;/g).length
).toEqual(expectedSepartorCount);
separator = ',';
fullURI = buildURI(fixtures.arrays,null , separator);
separator = ':'; // any separator
fullURI = buildURI(fixtures.arrays, null , separator);
expect(
fullURI.slice(prefixCsvURI.length).match(/,/g).length
fullURI.slice(prefixCsvURI.length).match(/:/g).length
).toEqual(expectedSepartorCount);
});