dce-reactkit 4.1.2 → 4.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +9 -3
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/helpers/genCSV.d.ts +5 -1
- package/dist/esm/index.js +9 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/helpers/genCSV.d.ts +5 -1
- package/dist/index.d.ts +5 -1
- package/package.json +1 -1
- package/src/helpers/genCSV.test.ts +18 -4
- package/src/helpers/genCSV.ts +11 -5
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
* Generate a CSV file
|
|
3
3
|
* @author Gabe Abrams
|
|
4
4
|
* @param data list of row data in the form of json objects
|
|
5
|
-
* @param columns list of columns to include in the csv
|
|
5
|
+
* @param columns list of columns to include in the csv where each column is an object with:
|
|
6
|
+
* - title: the column title
|
|
7
|
+
* - param: the key in the data object to use for this column
|
|
8
|
+
* - textIfUndefined: optional text to use if the value is undefined (defaults to empty string)
|
|
6
9
|
* @returns multiline csv string
|
|
7
10
|
*/
|
|
8
11
|
declare const genCSV: (data: {
|
|
@@ -10,5 +13,6 @@ declare const genCSV: (data: {
|
|
|
10
13
|
}[], columns: {
|
|
11
14
|
title: string;
|
|
12
15
|
param: string;
|
|
16
|
+
textIfUndefined?: string;
|
|
13
17
|
}[]) => string;
|
|
14
18
|
export default genCSV;
|
package/dist/esm/index.js
CHANGED
|
@@ -3902,7 +3902,10 @@ const escapeCellText = (text) => {
|
|
|
3902
3902
|
* Generate a CSV file
|
|
3903
3903
|
* @author Gabe Abrams
|
|
3904
3904
|
* @param data list of row data in the form of json objects
|
|
3905
|
-
* @param columns list of columns to include in the csv
|
|
3905
|
+
* @param columns list of columns to include in the csv where each column is an object with:
|
|
3906
|
+
* - title: the column title
|
|
3907
|
+
* - param: the key in the data object to use for this column
|
|
3908
|
+
* - textIfUndefined: optional text to use if the value is undefined (defaults to empty string)
|
|
3906
3909
|
* @returns multiline csv string
|
|
3907
3910
|
*/
|
|
3908
3911
|
const genCSV = (data, columns) => {
|
|
@@ -3918,16 +3921,19 @@ const genCSV = (data, columns) => {
|
|
|
3918
3921
|
csv += '\n';
|
|
3919
3922
|
csv += (columns
|
|
3920
3923
|
.map((column) => {
|
|
3924
|
+
var _a;
|
|
3921
3925
|
let contents;
|
|
3922
3926
|
const cell = datum[column.param];
|
|
3923
3927
|
if (typeof cell === 'string'
|
|
3924
3928
|
|| typeof cell === 'number') {
|
|
3925
3929
|
contents = String(cell);
|
|
3926
3930
|
}
|
|
3927
|
-
else if (
|
|
3928
|
-
|| cell === null) {
|
|
3931
|
+
else if (cell === null) {
|
|
3929
3932
|
contents = '';
|
|
3930
3933
|
}
|
|
3934
|
+
else if (typeof cell === 'undefined') {
|
|
3935
|
+
contents = ((_a = column.textIfUndefined) !== null && _a !== void 0 ? _a : '');
|
|
3936
|
+
}
|
|
3931
3937
|
else if (typeof cell === 'object') {
|
|
3932
3938
|
contents = JSON.stringify(cell);
|
|
3933
3939
|
}
|