dce-reactkit 4.1.1 → 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 +14 -4
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/helpers/genCSV.d.ts +5 -1
- package/dist/cjs/types/helpers/getTimeInfoInET.d.ts +2 -1
- package/dist/esm/index.js +14 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/helpers/genCSV.d.ts +5 -1
- package/dist/esm/types/helpers/getTimeInfoInET.d.ts +2 -1
- package/dist/index.d.ts +7 -2
- package/package.json +1 -1
- package/src/helpers/genCSV.test.ts +18 -4
- package/src/helpers/genCSV.ts +11 -5
- package/src/helpers/getTimeInfoInET.ts +8 -1
|
@@ -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;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @author Gabe Abrams
|
|
5
5
|
* @param [dateOrTimestamp=now] the date to get info on or a ms since epoch timestamp
|
|
6
6
|
* @returns object with timestamp (ms since epoch) and numbers
|
|
7
|
-
* corresponding to ET time values for year, month, day, hour, hour12, minute, isPM
|
|
7
|
+
* corresponding to ET time values for year, month, day, hour, hour12, minute, second, isPM
|
|
8
8
|
* where hour is in 24hr time and hour12 is in 12hr time.
|
|
9
9
|
*/
|
|
10
10
|
declare const getTimeInfoInET: (dateOrTimestamp?: Date | number) => {
|
|
@@ -15,6 +15,7 @@ declare const getTimeInfoInET: (dateOrTimestamp?: Date | number) => {
|
|
|
15
15
|
hour: number;
|
|
16
16
|
hour12: number;
|
|
17
17
|
minute: number;
|
|
18
|
+
second: number;
|
|
18
19
|
isPM: boolean;
|
|
19
20
|
};
|
|
20
21
|
export default getTimeInfoInET;
|
package/dist/index.d.ts
CHANGED
|
@@ -996,7 +996,7 @@ declare const getOrdinal: (num: number) => string;
|
|
|
996
996
|
* @author Gabe Abrams
|
|
997
997
|
* @param [dateOrTimestamp=now] the date to get info on or a ms since epoch timestamp
|
|
998
998
|
* @returns object with timestamp (ms since epoch) and numbers
|
|
999
|
-
* corresponding to ET time values for year, month, day, hour, hour12, minute, isPM
|
|
999
|
+
* corresponding to ET time values for year, month, day, hour, hour12, minute, second, isPM
|
|
1000
1000
|
* where hour is in 24hr time and hour12 is in 12hr time.
|
|
1001
1001
|
*/
|
|
1002
1002
|
declare const getTimeInfoInET: (dateOrTimestamp?: Date | number) => {
|
|
@@ -1007,6 +1007,7 @@ declare const getTimeInfoInET: (dateOrTimestamp?: Date | number) => {
|
|
|
1007
1007
|
hour: number;
|
|
1008
1008
|
hour12: number;
|
|
1009
1009
|
minute: number;
|
|
1010
|
+
second: number;
|
|
1010
1011
|
isPM: boolean;
|
|
1011
1012
|
};
|
|
1012
1013
|
|
|
@@ -1268,7 +1269,10 @@ declare const getMonthName: (month: number) => {
|
|
|
1268
1269
|
* Generate a CSV file
|
|
1269
1270
|
* @author Gabe Abrams
|
|
1270
1271
|
* @param data list of row data in the form of json objects
|
|
1271
|
-
* @param columns list of columns to include in the csv
|
|
1272
|
+
* @param columns list of columns to include in the csv where each column is an object with:
|
|
1273
|
+
* - title: the column title
|
|
1274
|
+
* - param: the key in the data object to use for this column
|
|
1275
|
+
* - textIfUndefined: optional text to use if the value is undefined (defaults to empty string)
|
|
1272
1276
|
* @returns multiline csv string
|
|
1273
1277
|
*/
|
|
1274
1278
|
declare const genCSV: (data: {
|
|
@@ -1276,6 +1280,7 @@ declare const genCSV: (data: {
|
|
|
1276
1280
|
}[], columns: {
|
|
1277
1281
|
title: string;
|
|
1278
1282
|
param: string;
|
|
1283
|
+
textIfUndefined?: string;
|
|
1279
1284
|
}[]) => string;
|
|
1280
1285
|
|
|
1281
1286
|
/**
|
package/package.json
CHANGED
|
@@ -23,7 +23,7 @@ describe('genCSV', () => {
|
|
|
23
23
|
{ name: 'Bob', age: 30, email: 'bob@example.com' },
|
|
24
24
|
{ name: 'Charlie', age: 35, email: 'charlie@example.com' },
|
|
25
25
|
];
|
|
26
|
-
const expected =
|
|
26
|
+
const expected = 'Name,Age,Email\nAlice,25,alice@example.com\nBob,30,bob@example.com\nCharlie,35,charlie@example.com';
|
|
27
27
|
const result = genCSV(data, columns);
|
|
28
28
|
expect(result).toEqual(expected);
|
|
29
29
|
});
|
|
@@ -39,7 +39,7 @@ describe('genCSV', () => {
|
|
|
39
39
|
{ name: 'Bob', age: null, email: 'bob@example.com' },
|
|
40
40
|
{ name: 'Charlie', age: 35, email: undefined },
|
|
41
41
|
];
|
|
42
|
-
const expected =
|
|
42
|
+
const expected = 'Name,Age,Email\nAlice,,\nBob,,bob@example.com\nCharlie,35,';
|
|
43
43
|
const result = genCSV(data, columns);
|
|
44
44
|
expect(result).toEqual(expected);
|
|
45
45
|
});
|
|
@@ -54,8 +54,22 @@ describe('genCSV', () => {
|
|
|
54
54
|
{ name: 'Bob', data: [1, 2, 3] },
|
|
55
55
|
{ name: 'Charlie', data: null },
|
|
56
56
|
];
|
|
57
|
-
const expected =
|
|
57
|
+
const expected = 'Name,Data\nAlice,"{""foo"":""bar""}"\nBob,"[1,2,3]"\nCharlie,';
|
|
58
58
|
const result = genCSV(data, columns);
|
|
59
59
|
expect(result).toEqual(expected);
|
|
60
60
|
});
|
|
61
|
-
|
|
61
|
+
|
|
62
|
+
it('should use textIfUndefined for undefined values', () => {
|
|
63
|
+
const columns = [
|
|
64
|
+
{ title: 'Name', param: 'name' },
|
|
65
|
+
{ title: 'Age', param: 'age', textIfUndefined: 'N/A' },
|
|
66
|
+
];
|
|
67
|
+
const data = [
|
|
68
|
+
{ name: 'Alice', age: undefined },
|
|
69
|
+
{ name: 'Bob', age: 30 },
|
|
70
|
+
];
|
|
71
|
+
const expected = 'Name,Age\nAlice,N/A\nBob,30';
|
|
72
|
+
const result = genCSV(data, columns);
|
|
73
|
+
expect(result).toEqual(expected);
|
|
74
|
+
});
|
|
75
|
+
});
|
package/src/helpers/genCSV.ts
CHANGED
|
@@ -21,7 +21,10 @@ const escapeCellText = (text: string): string => {
|
|
|
21
21
|
* Generate a CSV file
|
|
22
22
|
* @author Gabe Abrams
|
|
23
23
|
* @param data list of row data in the form of json objects
|
|
24
|
-
* @param columns list of columns to include in the csv
|
|
24
|
+
* @param columns list of columns to include in the csv where each column is an object with:
|
|
25
|
+
* - title: the column title
|
|
26
|
+
* - param: the key in the data object to use for this column
|
|
27
|
+
* - textIfUndefined: optional text to use if the value is undefined (defaults to empty string)
|
|
25
28
|
* @returns multiline csv string
|
|
26
29
|
*/
|
|
27
30
|
const genCSV = (
|
|
@@ -31,6 +34,7 @@ const genCSV = (
|
|
|
31
34
|
columns: {
|
|
32
35
|
title: string,
|
|
33
36
|
param: string,
|
|
37
|
+
textIfUndefined?: string,
|
|
34
38
|
}[],
|
|
35
39
|
): string => {
|
|
36
40
|
let csv = '';
|
|
@@ -57,11 +61,13 @@ const genCSV = (
|
|
|
57
61
|
|| typeof cell === 'number'
|
|
58
62
|
) {
|
|
59
63
|
contents = String(cell);
|
|
60
|
-
} else if (
|
|
61
|
-
typeof cell === 'undefined'
|
|
62
|
-
|| cell === null
|
|
63
|
-
) {
|
|
64
|
+
} else if (cell === null) {
|
|
64
65
|
contents = '';
|
|
66
|
+
} else if (typeof cell === 'undefined') {
|
|
67
|
+
contents = (
|
|
68
|
+
column.textIfUndefined
|
|
69
|
+
?? ''
|
|
70
|
+
);
|
|
65
71
|
} else if (typeof cell === 'object') {
|
|
66
72
|
contents = JSON.stringify(cell);
|
|
67
73
|
} else {
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @author Gabe Abrams
|
|
5
5
|
* @param [dateOrTimestamp=now] the date to get info on or a ms since epoch timestamp
|
|
6
6
|
* @returns object with timestamp (ms since epoch) and numbers
|
|
7
|
-
* corresponding to ET time values for year, month, day, hour, hour12, minute, isPM
|
|
7
|
+
* corresponding to ET time values for year, month, day, hour, hour12, minute, second, isPM
|
|
8
8
|
* where hour is in 24hr time and hour12 is in 12hr time.
|
|
9
9
|
*/
|
|
10
10
|
const getTimeInfoInET = (dateOrTimestamp?: Date | number): {
|
|
@@ -15,6 +15,7 @@ const getTimeInfoInET = (dateOrTimestamp?: Date | number): {
|
|
|
15
15
|
hour: number,
|
|
16
16
|
hour12: number,
|
|
17
17
|
minute: number,
|
|
18
|
+
second: number,
|
|
18
19
|
isPM: boolean,
|
|
19
20
|
} => {
|
|
20
21
|
// Create a time string
|
|
@@ -45,6 +46,11 @@ const getTimeInfoInET = (dateOrTimestamp?: Date | number): {
|
|
|
45
46
|
const month = Number.parseInt(monthStr, 10);
|
|
46
47
|
const day = Number.parseInt(dayStr, 10);
|
|
47
48
|
const minute = Number.parseInt(minStr, 10);
|
|
49
|
+
const second = (
|
|
50
|
+
ending.split(' ')[0]
|
|
51
|
+
? Number.parseInt(ending.split(' ')[0], 10)
|
|
52
|
+
: 0
|
|
53
|
+
);
|
|
48
54
|
const hour12 = Number.parseInt(hourStr, 10);
|
|
49
55
|
// Convert from am/pm to 24hr
|
|
50
56
|
const isAM = ending.toLowerCase().includes('am');
|
|
@@ -66,6 +72,7 @@ const getTimeInfoInET = (dateOrTimestamp?: Date | number): {
|
|
|
66
72
|
hour12,
|
|
67
73
|
isPM,
|
|
68
74
|
minute,
|
|
75
|
+
second,
|
|
69
76
|
};
|
|
70
77
|
};
|
|
71
78
|
|