ng2csv 8.0.0 → 9.0.0
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/README.md +42 -61
- package/fesm2022/ng2csv.mjs +112 -156
- package/fesm2022/ng2csv.mjs.map +1 -1
- package/package.json +4 -3
- package/types/ng2csv.d.ts +32 -46
package/README.md
CHANGED
|
@@ -2,66 +2,47 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://github.com/rars/ng2csv/actions/workflows/node.js.yml)
|
|
4
4
|
|
|
5
|
-
Angular
|
|
5
|
+
Angular library for saving CSV files.
|
|
6
6
|
|
|
7
7
|
## Quickstart
|
|
8
8
|
|
|
9
9
|
1. Install `file-saver` and `ng2csv` modules from npm:
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
})
|
|
47
|
-
export class AppComponent {
|
|
48
|
-
public constructor(private ng2Csv: Ng2CsvService) {}
|
|
49
|
-
|
|
50
|
-
public download(): void {
|
|
51
|
-
this.ng2Csv.download([
|
|
52
|
-
{
|
|
53
|
-
id: 1,
|
|
54
|
-
name: 'Alice'
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
id: 2,
|
|
58
|
-
name: 'Bob'
|
|
59
|
-
}
|
|
60
|
-
],
|
|
61
|
-
'names.csv');
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
```
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install file-saver ng2csv --save
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
2. Inject the `Ng2CsvService` into your component:
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { Component, inject } from '@angular/core';
|
|
19
|
+
import { Ng2CsvService } from 'ng2csv';
|
|
20
|
+
|
|
21
|
+
@Component({
|
|
22
|
+
selector: 'app-root',
|
|
23
|
+
templateUrl: './app.component.html',
|
|
24
|
+
styleUrls: ['./app.component.css'],
|
|
25
|
+
})
|
|
26
|
+
export class AppComponent {
|
|
27
|
+
private readonly ng2Csv = inject(Ng2CsvService);
|
|
28
|
+
|
|
29
|
+
public download(): void {
|
|
30
|
+
this.ng2Csv.download(
|
|
31
|
+
[
|
|
32
|
+
{
|
|
33
|
+
id: 1,
|
|
34
|
+
name: 'Alice',
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
id: 2,
|
|
38
|
+
name: 'Bob',
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
'names.csv',
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
```
|
|
65
46
|
|
|
66
47
|
## Configuration
|
|
67
48
|
|
|
@@ -73,12 +54,12 @@ Unless specified, an automatic mapping is used from the data to columns. It does
|
|
|
73
54
|
|
|
74
55
|
You can output a subset of the data's properties to CSV by defining your own custom mapping. This allows you to specify the order columns are written in and what value is written for each row in each column.
|
|
75
56
|
|
|
76
|
-
```
|
|
57
|
+
```ts
|
|
77
58
|
import { OrderedProjectionCsvRowMapper } from 'ng2csv';
|
|
78
59
|
// ...
|
|
79
60
|
const rowMapper = new OrderedProjectionCsvRowMapper<MyType>([
|
|
80
|
-
|
|
81
|
-
|
|
61
|
+
['First Name', (x) => x.Name],
|
|
62
|
+
['Identifier', (x) => 'N' + x.Id.toString()],
|
|
82
63
|
]);
|
|
83
64
|
this.ng2Csv.download(myData, 'file.csv', rowMapper);
|
|
84
65
|
/*
|
|
@@ -93,7 +74,7 @@ this.ng2Csv.download(myData, 'file.csv', rowMapper);
|
|
|
93
74
|
|
|
94
75
|
You can control what character is used to separate columns (e.g. to use ';' or tab separators rather than ',') and whether to include a header row.
|
|
95
76
|
|
|
96
|
-
```
|
|
77
|
+
```ts
|
|
97
78
|
import { CsvConfiguration } from 'ng2csv';
|
|
98
79
|
// ...
|
|
99
80
|
const csvConfig = new CsvConfiguration();
|
|
@@ -106,7 +87,7 @@ this.ng2Csv.download(myData, 'file.csv', undefined, csvConfig);
|
|
|
106
87
|
|
|
107
88
|
You can control how `null` or `undefined` values are written out in config.
|
|
108
89
|
|
|
109
|
-
```
|
|
90
|
+
```ts
|
|
110
91
|
import { CsvConfiguration } from 'ng2csv';
|
|
111
92
|
// ...
|
|
112
93
|
const csvConfig = new CsvConfiguration();
|
package/fesm2022/ng2csv.mjs
CHANGED
|
@@ -1,157 +1,113 @@
|
|
|
1
|
-
import * as i0 from
|
|
2
|
-
import {
|
|
3
|
-
import { saveAs } from
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
import { Service } from "@angular/core";
|
|
3
|
+
import { saveAs } from "file-saver";
|
|
4
|
+
var OrderedProjectionCsvRowMapper = class {
|
|
5
|
+
projections;
|
|
6
|
+
constructor(projections) {
|
|
7
|
+
this.projections = projections;
|
|
8
|
+
}
|
|
9
|
+
getColumnNames() {
|
|
10
|
+
return this.projections.map((x) => x[0]);
|
|
11
|
+
}
|
|
12
|
+
map(obj) {
|
|
13
|
+
return this.projections.map((x) => x[1](obj));
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
var AutoCsvRowMapper = class {
|
|
17
|
+
derivedCsvRowMapper;
|
|
18
|
+
constructor(data) {
|
|
19
|
+
if (!data || data.length === 0) throw new Error("Parameter 'data' must be a non-empty array of objects.");
|
|
20
|
+
if (typeof data[0] !== "object") throw new Error("Parameter 'data' must contain objects.");
|
|
21
|
+
const projections = [];
|
|
22
|
+
const allKeys = this.getAllKeys(data);
|
|
23
|
+
for (const key of allKeys) projections.push([key, this.createProjection(key)]);
|
|
24
|
+
this.derivedCsvRowMapper = new OrderedProjectionCsvRowMapper(projections);
|
|
25
|
+
}
|
|
26
|
+
getColumnNames() {
|
|
27
|
+
return this.derivedCsvRowMapper.getColumnNames();
|
|
28
|
+
}
|
|
29
|
+
map(obj) {
|
|
30
|
+
return this.derivedCsvRowMapper.map(obj);
|
|
31
|
+
}
|
|
32
|
+
createProjection(property) {
|
|
33
|
+
return (x) => {
|
|
34
|
+
if (x && typeof x === "object" && Object.hasOwn(x, property)) {
|
|
35
|
+
const propertyValue = x[property];
|
|
36
|
+
if (propertyValue === void 0 || propertyValue === null) return "";
|
|
37
|
+
return propertyValue.toString();
|
|
38
|
+
} else return "";
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
getAllKeys(objs) {
|
|
42
|
+
const allKeys = {};
|
|
43
|
+
for (const obj of objs) for (const objectKey of Object.keys(obj)) allKeys[objectKey] = 1;
|
|
44
|
+
return Object.keys(allKeys);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
var CsvConfiguration = class {
|
|
48
|
+
delimiter = ",";
|
|
49
|
+
quote = "\"";
|
|
50
|
+
newLine = "\r\n";
|
|
51
|
+
includeHeaderLine = true;
|
|
52
|
+
outputValueForNull = "";
|
|
53
|
+
outputValueForUndefined = "";
|
|
54
|
+
};
|
|
55
|
+
var Ng2CsvService = class Ng2CsvService {
|
|
56
|
+
download(data, filename, csvRowMapper, config = new CsvConfiguration()) {
|
|
57
|
+
const csvData = this.convertToCsv(data, csvRowMapper, config);
|
|
58
|
+
const mimeType = "text/csv; header=" + (config.includeHeaderLine ? "present" : "absent");
|
|
59
|
+
const csvBlob = new Blob([csvData], { type: mimeType });
|
|
60
|
+
saveAs(csvBlob, filename, { autoBom: false });
|
|
61
|
+
}
|
|
62
|
+
convertToCsv(data, csvRowMapper, config = new CsvConfiguration()) {
|
|
63
|
+
if (csvRowMapper === void 0) csvRowMapper = new AutoCsvRowMapper(data);
|
|
64
|
+
const rows = [];
|
|
65
|
+
if (config.includeHeaderLine) {
|
|
66
|
+
const headerFieldSeparator = `${config.quote}${config.delimiter}${config.quote}`;
|
|
67
|
+
rows.push(config.quote + csvRowMapper.getColumnNames().map((x) => this.escapeQuotes(x, config.quote)).join(headerFieldSeparator) + config.quote);
|
|
68
|
+
}
|
|
69
|
+
for (const row of data) rows.push(csvRowMapper.map(row).map((x) => this.mapNullOrUndefinedValues(x, config)).map((x) => this.escapeRowValue(x, config)).join(config.delimiter));
|
|
70
|
+
return rows.join(config.newLine);
|
|
71
|
+
}
|
|
72
|
+
mapNullOrUndefinedValues(value, config) {
|
|
73
|
+
switch (value) {
|
|
74
|
+
case null: return config.outputValueForNull;
|
|
75
|
+
case void 0: return config.outputValueForUndefined;
|
|
76
|
+
default: return value;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
escapeQuotes(value, quoteChar) {
|
|
80
|
+
return value.replace(new RegExp(quoteChar.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "g"), quoteChar + quoteChar);
|
|
81
|
+
}
|
|
82
|
+
escapeRowValue(value, config) {
|
|
83
|
+
if (value.indexOf(config.delimiter) > -1 || value.indexOf(config.quote) > -1) {
|
|
84
|
+
const escapedValue = this.escapeQuotes(value, config.quote);
|
|
85
|
+
return `${config.quote}${escapedValue}${config.quote}`;
|
|
86
|
+
}
|
|
87
|
+
return value;
|
|
88
|
+
}
|
|
89
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
90
|
+
minVersion: "12.0.0",
|
|
91
|
+
version: "22.2.1",
|
|
92
|
+
ngImport: i0,
|
|
93
|
+
type: Ng2CsvService,
|
|
94
|
+
deps: [],
|
|
95
|
+
target: i0.ɵɵFactoryTarget.Service
|
|
96
|
+
});
|
|
97
|
+
static ɵprov = i0.ɵɵngDeclareService({
|
|
98
|
+
minVersion: "22.0.0",
|
|
99
|
+
version: "22.2.1",
|
|
100
|
+
ngImport: i0,
|
|
101
|
+
type: Ng2CsvService
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
105
|
+
minVersion: "12.0.0",
|
|
106
|
+
version: "22.2.1",
|
|
107
|
+
ngImport: i0,
|
|
108
|
+
type: Ng2CsvService,
|
|
109
|
+
decorators: [{ type: Service }]
|
|
110
|
+
});
|
|
111
|
+
export { AutoCsvRowMapper, CsvConfiguration, Ng2CsvService, OrderedProjectionCsvRowMapper };
|
|
4
112
|
|
|
5
|
-
|
|
6
|
-
projections;
|
|
7
|
-
constructor(projections) {
|
|
8
|
-
this.projections = projections;
|
|
9
|
-
}
|
|
10
|
-
getColumnNames() {
|
|
11
|
-
return this.projections.map((x) => x[0]);
|
|
12
|
-
}
|
|
13
|
-
map(obj) {
|
|
14
|
-
return this.projections.map((x) => x[1](obj));
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
class AutoCsvRowMapper {
|
|
19
|
-
derivedCsvRowMapper;
|
|
20
|
-
constructor(data) {
|
|
21
|
-
if (!data || data.length === 0) {
|
|
22
|
-
throw new Error("Parameter 'data' must be a non-empty array of objects.");
|
|
23
|
-
}
|
|
24
|
-
if (typeof data[0] !== 'object') {
|
|
25
|
-
throw new Error("Parameter 'data' must contain objects.");
|
|
26
|
-
}
|
|
27
|
-
const projections = [];
|
|
28
|
-
const allKeys = this.getAllKeys(data);
|
|
29
|
-
for (const key of allKeys) {
|
|
30
|
-
projections.push([key, this.createProjection(key)]);
|
|
31
|
-
}
|
|
32
|
-
this.derivedCsvRowMapper = new OrderedProjectionCsvRowMapper(projections);
|
|
33
|
-
}
|
|
34
|
-
getColumnNames() {
|
|
35
|
-
return this.derivedCsvRowMapper.getColumnNames();
|
|
36
|
-
}
|
|
37
|
-
map(obj) {
|
|
38
|
-
return this.derivedCsvRowMapper.map(obj);
|
|
39
|
-
}
|
|
40
|
-
createProjection(property) {
|
|
41
|
-
return (x) => {
|
|
42
|
-
if (x && typeof x === 'object' && Object.hasOwn(x, property)) {
|
|
43
|
-
const propertyValue = x[property];
|
|
44
|
-
if (propertyValue === undefined || propertyValue === null) {
|
|
45
|
-
return '';
|
|
46
|
-
}
|
|
47
|
-
return propertyValue.toString();
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
return '';
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
getAllKeys(objs) {
|
|
55
|
-
const allKeys = {};
|
|
56
|
-
for (const obj of objs) {
|
|
57
|
-
for (const objectKey of Object.keys(obj)) {
|
|
58
|
-
allKeys[objectKey] = 1;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return Object.keys(allKeys);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
class CsvConfiguration {
|
|
66
|
-
delimiter = ',';
|
|
67
|
-
quote = '"';
|
|
68
|
-
newLine = '\r\n';
|
|
69
|
-
includeHeaderLine = true;
|
|
70
|
-
outputValueForNull = '';
|
|
71
|
-
outputValueForUndefined = '';
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
class Ng2CsvService {
|
|
75
|
-
download(data, filename, csvRowMapper, config = new CsvConfiguration()) {
|
|
76
|
-
const csvData = this.convertToCsv(data, csvRowMapper, config);
|
|
77
|
-
const mimeType = 'text/csv; header=' + (config.includeHeaderLine ? 'present' : 'absent');
|
|
78
|
-
const csvBlob = new Blob([csvData], { type: mimeType });
|
|
79
|
-
saveAs(csvBlob, filename, { autoBom: false });
|
|
80
|
-
}
|
|
81
|
-
convertToCsv(data, csvRowMapper, config = new CsvConfiguration()) {
|
|
82
|
-
if (csvRowMapper === undefined) {
|
|
83
|
-
csvRowMapper = new AutoCsvRowMapper(data);
|
|
84
|
-
}
|
|
85
|
-
const rows = [];
|
|
86
|
-
if (config.includeHeaderLine) {
|
|
87
|
-
const headerFieldSeparator = `${config.quote}${config.delimiter}${config.quote}`;
|
|
88
|
-
rows.push(config.quote +
|
|
89
|
-
csvRowMapper
|
|
90
|
-
.getColumnNames()
|
|
91
|
-
.map((x) => this.escapeQuotes(x, config.quote))
|
|
92
|
-
.join(headerFieldSeparator) +
|
|
93
|
-
config.quote);
|
|
94
|
-
}
|
|
95
|
-
for (const row of data) {
|
|
96
|
-
rows.push(csvRowMapper
|
|
97
|
-
.map(row)
|
|
98
|
-
.map((x) => this.mapNullOrUndefinedValues(x, config))
|
|
99
|
-
.map((x) => this.escapeRowValue(x, config))
|
|
100
|
-
.join(config.delimiter));
|
|
101
|
-
}
|
|
102
|
-
return rows.join(config.newLine);
|
|
103
|
-
}
|
|
104
|
-
mapNullOrUndefinedValues(value, config) {
|
|
105
|
-
switch (value) {
|
|
106
|
-
case null: {
|
|
107
|
-
return config.outputValueForNull;
|
|
108
|
-
}
|
|
109
|
-
case undefined: {
|
|
110
|
-
return config.outputValueForUndefined;
|
|
111
|
-
}
|
|
112
|
-
default: {
|
|
113
|
-
return value;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
escapeQuotes(value, quoteChar) {
|
|
118
|
-
return value.replace(new RegExp(quoteChar.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'g'), quoteChar + quoteChar);
|
|
119
|
-
}
|
|
120
|
-
escapeRowValue(value, config) {
|
|
121
|
-
if (value.indexOf(config.delimiter) > -1 ||
|
|
122
|
-
value.indexOf(config.quote) > -1) {
|
|
123
|
-
const escapedValue = this.escapeQuotes(value, config.quote);
|
|
124
|
-
return `${config.quote}${escapedValue}${config.quote}`;
|
|
125
|
-
}
|
|
126
|
-
return value;
|
|
127
|
-
}
|
|
128
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: Ng2CsvService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
129
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: Ng2CsvService, providedIn: 'root' });
|
|
130
|
-
}
|
|
131
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: Ng2CsvService, decorators: [{
|
|
132
|
-
type: Injectable,
|
|
133
|
-
args: [{
|
|
134
|
-
providedIn: 'root',
|
|
135
|
-
}]
|
|
136
|
-
}] });
|
|
137
|
-
|
|
138
|
-
class Ng2CsvModule {
|
|
139
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: Ng2CsvModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
140
|
-
static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "21.0.6", ngImport: i0, type: Ng2CsvModule });
|
|
141
|
-
static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: Ng2CsvModule });
|
|
142
|
-
}
|
|
143
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: Ng2CsvModule, decorators: [{
|
|
144
|
-
type: NgModule,
|
|
145
|
-
args: [{}]
|
|
146
|
-
}] });
|
|
147
|
-
|
|
148
|
-
/*
|
|
149
|
-
* Public API Surface of ng2csv
|
|
150
|
-
*/
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Generated bundle index. Do not edit.
|
|
154
|
-
*/
|
|
155
|
-
|
|
156
|
-
export { AutoCsvRowMapper, CsvConfiguration, Ng2CsvModule, Ng2CsvService, OrderedProjectionCsvRowMapper };
|
|
157
|
-
//# sourceMappingURL=ng2csv.mjs.map
|
|
113
|
+
//# sourceMappingURL=ng2csv.mjs.map
|
package/fesm2022/ng2csv.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ng2csv.mjs","sources":["../../../projects/ng2csv/src/lib/ordered-projection-csv-row-mapper.class.ts","../../../projects/ng2csv/src/lib/auto-csv-row-mapper.class.ts","../../../projects/ng2csv/src/lib/csv-configuration.class.ts","../../../projects/ng2csv/src/lib/ng2csv.service.ts","../../../projects/ng2csv/src/lib/ng2csv.module.ts","../../../projects/ng2csv/src/public-api.ts","../../../projects/ng2csv/src/ng2csv.ts"],"sourcesContent":["import { ICsvRowMapper } from './csv-row-mapper.interface';\n\nexport class OrderedProjectionCsvRowMapper<T> implements ICsvRowMapper<T> {\n private readonly projections: Array<\n [string, (obj: T) => string | null | undefined]\n >;\n\n public constructor(\n projections: Array<[string, (obj: T) => string | null | undefined]>\n ) {\n this.projections = projections;\n }\n\n public getColumnNames(): string[] {\n return this.projections.map((x) => x[0]);\n }\n\n public map(obj: T): (string | null | undefined)[] {\n return this.projections.map((x) => x[1](obj));\n }\n}\n","import { ICsvRowMapper } from './csv-row-mapper.interface';\nimport { OrderedProjectionCsvRowMapper } from './ordered-projection-csv-row-mapper.class';\n\nexport class AutoCsvRowMapper<T extends object> implements ICsvRowMapper<T> {\n private derivedCsvRowMapper: OrderedProjectionCsvRowMapper<T>;\n\n public constructor(data: T[]) {\n if (!data || data.length === 0) {\n throw new Error(\"Parameter 'data' must be a non-empty array of objects.\");\n }\n\n if (typeof data[0] !== 'object') {\n throw new Error(\"Parameter 'data' must contain objects.\");\n }\n\n const projections: Array<[string, (obj: T) => string]> = [];\n\n const allKeys: string[] = this.getAllKeys(data);\n for (const key of allKeys) {\n projections.push([key, this.createProjection(key)]);\n }\n\n this.derivedCsvRowMapper = new OrderedProjectionCsvRowMapper<T>(\n projections\n );\n }\n\n public getColumnNames(): string[] {\n return this.derivedCsvRowMapper.getColumnNames();\n }\n\n public map(obj: T): (string | null | undefined)[] {\n return this.derivedCsvRowMapper.map(obj);\n }\n\n private createProjection(property: string): (obj: T) => string {\n return (x: T) => {\n if (x && typeof x === 'object' && Object.hasOwn(x, property)) {\n const propertyValue = x[property as keyof T];\n if (propertyValue === undefined || propertyValue === null) {\n return '';\n }\n return propertyValue.toString();\n } else {\n return '';\n }\n };\n }\n\n private getAllKeys(objs: T[]): string[] {\n const allKeys: any = {};\n\n for (const obj of objs) {\n for (const objectKey of Object.keys(obj)) {\n allKeys[objectKey] = 1;\n }\n }\n\n return Object.keys(allKeys);\n }\n}\n","export class CsvConfiguration {\n public delimiter = ',';\n public quote = '\"';\n public newLine = '\\r\\n';\n public includeHeaderLine = true;\n public outputValueForNull = '';\n public outputValueForUndefined = '';\n}\n","import { Injectable } from '@angular/core';\nimport { saveAs } from 'file-saver';\nimport { AutoCsvRowMapper } from './auto-csv-row-mapper.class';\nimport { CsvConfiguration } from './csv-configuration.class';\nimport { ICsvRowMapper } from './csv-row-mapper.interface';\n\n@Injectable({\n providedIn: 'root',\n})\nexport class Ng2CsvService {\n public download<T extends object>(\n data: T[],\n filename: string,\n csvRowMapper?: ICsvRowMapper<T>,\n config: CsvConfiguration = new CsvConfiguration()\n ): void {\n const csvData: string = this.convertToCsv(data, csvRowMapper, config);\n\n const mimeType: string =\n 'text/csv; header=' + (config.includeHeaderLine ? 'present' : 'absent');\n\n const csvBlob: Blob = new Blob([csvData], { type: mimeType });\n saveAs(csvBlob, filename, { autoBom: false });\n }\n\n public convertToCsv<T extends object>(\n data: T[],\n csvRowMapper?: ICsvRowMapper<T>,\n config: CsvConfiguration = new CsvConfiguration()\n ): string {\n if (csvRowMapper === undefined) {\n csvRowMapper = new AutoCsvRowMapper(data);\n }\n\n const rows: string[] = [];\n\n if (config.includeHeaderLine) {\n const headerFieldSeparator = `${config.quote}${config.delimiter}${config.quote}`;\n rows.push(\n config.quote +\n csvRowMapper\n .getColumnNames()\n .map((x) => this.escapeQuotes(x, config.quote))\n .join(headerFieldSeparator) +\n config.quote\n );\n }\n\n for (const row of data) {\n rows.push(\n csvRowMapper\n .map(row)\n .map((x) => this.mapNullOrUndefinedValues(x, config))\n .map((x) => this.escapeRowValue(x, config))\n .join(config.delimiter)\n );\n }\n\n return rows.join(config.newLine);\n }\n\n private mapNullOrUndefinedValues(\n value: string | null | undefined,\n config: CsvConfiguration\n ): string {\n switch (value) {\n case null: {\n return config.outputValueForNull;\n }\n case undefined: {\n return config.outputValueForUndefined;\n }\n default: {\n return value;\n }\n }\n }\n\n private escapeQuotes(value: string, quoteChar: string): string {\n return value.replace(\n new RegExp(quoteChar.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&'), 'g'),\n quoteChar + quoteChar\n );\n }\n\n private escapeRowValue(value: string, config: CsvConfiguration): string {\n if (\n value.indexOf(config.delimiter) > -1 ||\n value.indexOf(config.quote) > -1\n ) {\n const escapedValue = this.escapeQuotes(value, config.quote);\n return `${config.quote}${escapedValue}${config.quote}`;\n }\n return value;\n }\n}\n","import { NgModule } from '@angular/core';\n\n@NgModule({})\nexport class Ng2CsvModule { }\n","/*\n * Public API Surface of ng2csv\n */\n\nexport * from './lib/ng2csv.service';\nexport * from './lib/ng2csv.module';\nexport * from './lib/auto-csv-row-mapper.class';\nexport * from './lib/csv-configuration.class';\nexport * from './lib/csv-row-mapper.interface';\nexport * from './lib/ordered-projection-csv-row-mapper.class';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;MAEa,6BAA6B,CAAA;AACvB,IAAA,WAAW;AAI5B,IAAA,WAAA,CACE,WAAmE,EAAA;AAEnE,QAAA,IAAI,CAAC,WAAW,GAAG,WAAW;IAChC;IAEO,cAAc,GAAA;AACnB,QAAA,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1C;AAEO,IAAA,GAAG,CAAC,GAAM,EAAA;AACf,QAAA,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IAC/C;AACD;;MCjBY,gBAAgB,CAAA;AACnB,IAAA,mBAAmB;AAE3B,IAAA,WAAA,CAAmB,I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ib/auto-csv-row-mapper.class.ts","../../../projects/ng2csv/src/lib/csv-configuration.class.ts","../../../projects/ng2csv/src/lib/ng2csv.service.ts"],"sourcesContent":["import { ICsvRowMapper } from './csv-row-mapper.interface';\n\nexport class OrderedProjectionCsvRowMapper<T> implements ICsvRowMapper<T> {\n private readonly projections: Array<\n [string, (obj: T) => string | null | undefined]\n >;\n\n public constructor(\n projections: Array<[string, (obj: T) => string | null | undefined]>\n ) {\n this.projections = projections;\n }\n\n public getColumnNames(): string[] {\n return this.projections.map((x) => x[0]);\n }\n\n public map(obj: T): (string | null | undefined)[] {\n return this.projections.map((x) => x[1](obj));\n }\n}\n","import { ICsvRowMapper } from './csv-row-mapper.interface';\nimport { OrderedProjectionCsvRowMapper } from './ordered-projection-csv-row-mapper.class';\n\nexport class AutoCsvRowMapper<T extends object> implements ICsvRowMapper<T> {\n private derivedCsvRowMapper: OrderedProjectionCsvRowMapper<T>;\n\n public constructor(data: T[]) {\n if (!data || data.length === 0) {\n throw new Error(\"Parameter 'data' must be a non-empty array of objects.\");\n }\n\n if (typeof data[0] !== 'object') {\n throw new Error(\"Parameter 'data' must contain objects.\");\n }\n\n const projections: Array<[string, (obj: T) => string]> = [];\n\n const allKeys: string[] = this.getAllKeys(data);\n for (const key of allKeys) {\n projections.push([key, this.createProjection(key)]);\n }\n\n this.derivedCsvRowMapper = new OrderedProjectionCsvRowMapper<T>(\n projections,\n );\n }\n\n public getColumnNames(): string[] {\n return this.derivedCsvRowMapper.getColumnNames();\n }\n\n public map(obj: T): (string | null | undefined)[] {\n return this.derivedCsvRowMapper.map(obj);\n }\n\n private createProjection(property: string): (obj: T) => string {\n return (x: T) => {\n if (x && typeof x === 'object' && Object.hasOwn(x, property)) {\n const propertyValue = x[property as keyof T];\n if (propertyValue === undefined || propertyValue === null) {\n return '';\n }\n return propertyValue.toString();\n } else {\n return '';\n }\n };\n }\n\n private getAllKeys(objs: T[]): string[] {\n const allKeys: { [key: string]: number } = {};\n\n for (const obj of objs) {\n for (const objectKey of Object.keys(obj)) {\n allKeys[objectKey] = 1;\n }\n }\n\n return Object.keys(allKeys);\n }\n}\n","export class CsvConfiguration {\n public delimiter = ',';\n public quote = '\"';\n public newLine = '\\r\\n';\n public includeHeaderLine = true;\n public outputValueForNull = '';\n public outputValueForUndefined = '';\n}\n","import { Service } from '@angular/core';\nimport { saveAs } from 'file-saver';\nimport { AutoCsvRowMapper } from './auto-csv-row-mapper.class';\nimport { CsvConfiguration } from './csv-configuration.class';\nimport { ICsvRowMapper } from './csv-row-mapper.interface';\n\n@Service()\nexport class Ng2CsvService {\n public download<T extends object>(\n data: T[],\n filename: string,\n csvRowMapper?: ICsvRowMapper<T>,\n config: CsvConfiguration = new CsvConfiguration(),\n ): void {\n const csvData: string = this.convertToCsv(data, csvRowMapper, config);\n\n const mimeType: string =\n 'text/csv; header=' + (config.includeHeaderLine ? 'present' : 'absent');\n\n const csvBlob: Blob = new Blob([csvData], { type: mimeType });\n saveAs(csvBlob, filename, { autoBom: false });\n }\n\n public convertToCsv<T extends object>(\n data: T[],\n csvRowMapper?: ICsvRowMapper<T>,\n config: CsvConfiguration = new CsvConfiguration(),\n ): string {\n if (csvRowMapper === undefined) {\n csvRowMapper = new AutoCsvRowMapper(data);\n }\n\n const rows: string[] = [];\n\n if (config.includeHeaderLine) {\n const headerFieldSeparator = `${config.quote}${config.delimiter}${config.quote}`;\n rows.push(\n config.quote +\n csvRowMapper\n .getColumnNames()\n .map((x) => this.escapeQuotes(x, config.quote))\n .join(headerFieldSeparator) +\n config.quote,\n );\n }\n\n for (const row of data) {\n rows.push(\n csvRowMapper\n .map(row)\n .map((x) => this.mapNullOrUndefinedValues(x, config))\n .map((x) => this.escapeRowValue(x, config))\n .join(config.delimiter),\n );\n }\n\n return rows.join(config.newLine);\n }\n\n private mapNullOrUndefinedValues(\n value: string | null | undefined,\n config: CsvConfiguration,\n ): string {\n switch (value) {\n case null: {\n return config.outputValueForNull;\n }\n case undefined: {\n return config.outputValueForUndefined;\n }\n default: {\n return value;\n }\n }\n }\n\n private escapeQuotes(value: string, quoteChar: string): string {\n return value.replace(\n new RegExp(quoteChar.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&'), 'g'),\n quoteChar + quoteChar,\n );\n }\n\n private escapeRowValue(value: string, config: CsvConfiguration): string {\n if (\n value.indexOf(config.delimiter) > -1 ||\n value.indexOf(config.quote) > -1\n ) {\n const escapedValue = this.escapeQuotes(value, config.quote);\n return `${config.quote}${escapedValue}${config.quote}`;\n }\n return value;\n }\n}\n"],"mappings":";;;AAEA,IAAa,gCAAb,MAA0C;CACvB;CAIjB,YACE,aAAmE;EAEnE,KAAK,cAAc;CACrB;CAEO,iBAAc;EACnB,OAAO,KAAK,YAAY,KAAK,MAAM,EAAE,EAAE;CACzC;CAEO,IAAI,KAAM;EACf,OAAO,KAAK,YAAY,KAAK,MAAM,EAAE,EAAE,CAAC,GAAG,CAAC;CAC9C;AACD;ACjBD,IAAa,mBAAb,MAA6B;CACnB;CAER,YAAmB,MAAS;EAC1B,IAAI,CAAC,QAAQ,KAAK,WAAW,GAC3B,MAAM,IAAI,MAAM,wDAAwD;EAG1E,IAAI,OAAO,KAAK,OAAO,UACrB,MAAM,IAAI,MAAM,wCAAwC;EAG1D,MAAM,cAAmD,CAAA;EAEzD,MAAM,UAAoB,KAAK,WAAW,IAAI;EAC9C,KAAK,MAAM,OAAO,SAChB,YAAY,KAAK,CAAC,KAAK,KAAK,iBAAiB,GAAG,CAAC,CAAC;EAGpD,KAAK,sBAAsB,IAAI,8BAC7B,WAAW;CAEf;CAEO,iBAAc;EACnB,OAAO,KAAK,oBAAoB,eAAc;CAChD;CAEO,IAAI,KAAM;EACf,OAAO,KAAK,oBAAoB,IAAI,GAAG;CACzC;CAEQ,iBAAiB,UAAgB;EACvC,QAAQ,MAAQ;GACd,IAAI,KAAK,OAAO,MAAM,YAAY,OAAO,OAAO,GAAG,QAAQ,GAAG;IAC5D,MAAM,gBAAgB,EAAE;IACxB,IAAI,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AC1C,KAAK,OAAO,SAAS,CAAC;EAI7B,OAAO,KAAK,KAAK,OAAO,OAAO;CACjC;CAEQ,yBACN,OACA,QAAwB;EAExB,QAAQ,OAAR;GACE,KAAK,MACH,OAAO,OAAO;GAEhB,KAAK,QACH,OAAO,OAAO;GAEhB,SACE,OAAO;EAEX;CACF;CAEQ,aAAa,OAAe,WAAiB;EACnD,OAAO,MAAM,QACX,IAAI,OAAO,UAAU,QAAQ,uBAAuB,MAAM,GAAG,GAAG,GAChE,YAAY,SAAS;CAEzB;CAEQ,eAAe,OAAe,QAAwB;EAC5D,IACE,MAAM,QAAQ,OAAO,SAAS,IAAI,MAClC,MAAM,QAAQ,OAAO,KAAK,IAAI,IAC9B;GACA,MAAM,eAAe,KAAK,aAAa,OAAO,OAAO,KAAK;GAC1D,OAAO,GAAG,OAAO,QAAQ,eAAe,OAAO;EACjD;EACA,OAAO;CACT;CArFW,OAAA,OAAA,GAAA,mBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;EAAa,MAAA,CAAA;EAAA,QAAA,GAAA,gBAAA;CAAA,CAAA;CAAb,OAAA,QAAA,GAAA,mBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;CAAa,CAAA;;AAAb,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAa,YAAA,CAAA,EADzB,MAAA,QAAA,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ng2csv",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.0",
|
|
4
4
|
"description": "An Angular library for exporting data to CSV.",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"tslib": "^2.0.0"
|
|
7
7
|
},
|
|
8
8
|
"peerDependencies": {
|
|
9
|
-
"@angular/core": "^
|
|
9
|
+
"@angular/core": "^22.0.0",
|
|
10
10
|
"file-saver": "^2.0.0"
|
|
11
11
|
},
|
|
12
12
|
"repository": {
|
|
@@ -35,5 +35,6 @@
|
|
|
35
35
|
"default": "./fesm2022/ng2csv.mjs"
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
|
-
"sideEffects": false
|
|
38
|
+
"sideEffects": false,
|
|
39
|
+
"type": "module"
|
|
39
40
|
}
|
package/types/ng2csv.d.ts
CHANGED
|
@@ -1,50 +1,36 @@
|
|
|
1
|
-
import * as i0 from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
outputValueForUndefined: string;
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
export declare class CsvConfiguration {
|
|
3
|
+
delimiter: string;
|
|
4
|
+
quote: string;
|
|
5
|
+
newLine: string;
|
|
6
|
+
includeHeaderLine: boolean;
|
|
7
|
+
outputValueForNull: string;
|
|
8
|
+
outputValueForUndefined: string;
|
|
10
9
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
map(obj: T): (string | null | undefined)[];
|
|
10
|
+
export interface ICsvRowMapper<T> {
|
|
11
|
+
getColumnNames(): string[];
|
|
12
|
+
map(obj: T): (string | null | undefined)[];
|
|
15
13
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
static ɵprov: i0.ɵɵInjectableDeclaration<Ng2CsvService>;
|
|
14
|
+
export declare class Ng2CsvService {
|
|
15
|
+
download<T extends object>(data: T[], filename: string, csvRowMapper?: ICsvRowMapper<T>, config?: CsvConfiguration): void;
|
|
16
|
+
convertToCsv<T extends object>(data: T[], csvRowMapper?: ICsvRowMapper<T>, config?: CsvConfiguration): string;
|
|
17
|
+
private mapNullOrUndefinedValues;
|
|
18
|
+
private escapeQuotes;
|
|
19
|
+
private escapeRowValue;
|
|
20
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<Ng2CsvService, never>;
|
|
21
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<any>;
|
|
25
22
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
export declare class AutoCsvRowMapper<T extends object> implements ICsvRowMapper<T> {
|
|
24
|
+
private derivedCsvRowMapper;
|
|
25
|
+
constructor(data: T[]);
|
|
26
|
+
getColumnNames(): string[];
|
|
27
|
+
map(obj: T): (string | null | undefined)[];
|
|
28
|
+
private createProjection;
|
|
29
|
+
private getAllKeys;
|
|
31
30
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
private createProjection;
|
|
39
|
-
private getAllKeys;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
declare class OrderedProjectionCsvRowMapper<T> implements ICsvRowMapper<T> {
|
|
43
|
-
private readonly projections;
|
|
44
|
-
constructor(projections: Array<[string, (obj: T) => string | null | undefined]>);
|
|
45
|
-
getColumnNames(): string[];
|
|
46
|
-
map(obj: T): (string | null | undefined)[];
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export { AutoCsvRowMapper, CsvConfiguration, Ng2CsvModule, Ng2CsvService, OrderedProjectionCsvRowMapper };
|
|
50
|
-
export type { ICsvRowMapper };
|
|
31
|
+
export declare class OrderedProjectionCsvRowMapper<T> implements ICsvRowMapper<T> {
|
|
32
|
+
private readonly projections;
|
|
33
|
+
constructor(projections: Array<[string, (obj: T) => string | null | undefined]>);
|
|
34
|
+
getColumnNames(): string[];
|
|
35
|
+
map(obj: T): (string | null | undefined)[];
|
|
36
|
+
}
|