Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@
"configurations": {
"production": {
"tsConfig": "projects/ng2csv/tsconfig.lib.prod.json"
},
"development": {
"tsConfig": "projects/ng2csv/tsconfig.lib.json"
}
}
},
"test": {
"builder": "@angular/build:karma",
"builder": "@angular/build:unit-test",
"options": {
"main": "projects/ng2csv/src/test.ts",
"tsConfig": "projects/ng2csv/tsconfig.spec.json",
"karmaConfig": "projects/ng2csv/karma.conf.js"
"tsConfig": "projects/ng2csv/tsconfig.spec.json"
}
},
"lint": {
Expand Down
8,267 changes: 4,887 additions & 3,380 deletions package-lock.json

Large diffs are not rendered by default.

58 changes: 26 additions & 32 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,62 +1,56 @@
{
"name": "ng2csv",
"version": "7.0.0",
"version": "8.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build ng2csv --configuration production",
"test": "ng test ng2csv --watch false",
"test": "ng test ng2csv --no-watch",
"lint": "ng lint",
"e2e": "ng e2e",
"release": "standard-version"
},
"private": true,
"dependencies": {
"@angular/animations": "^20.3.9",
"@angular/common": "^20.3.9",
"@angular/compiler": "^20.3.9",
"@angular/core": "^20.3.9",
"@angular/forms": "^20.3.9",
"@angular/platform-browser": "^20.3.9",
"@angular/platform-browser-dynamic": "^20.3.9",
"@angular/router": "^20.3.9",
"@angular/animations": "^21.0.6",
"@angular/common": "^21.0.6",
"@angular/compiler": "^21.0.6",
"@angular/core": "^21.0.6",
"@angular/forms": "^21.0.6",
"@angular/platform-browser": "^21.0.6",
"@angular/platform-browser-dynamic": "^21.0.6",
"@angular/router": "^21.0.6",
"file-saver": "^2.0.5",
"rxjs": "~7.8.0",
"tslib": "^2.0.0",
"zone.js": "~0.15.0"
},
"devDependencies": {
"@angular-devkit/architect": "^0.2003.8",
"@angular-eslint/builder": "^20.1.1",
"@angular-eslint/eslint-plugin": "^20.1.1",
"@angular-eslint/eslint-plugin-template": "^20.1.1",
"@angular-eslint/schematics": "^20.1.1",
"@angular-eslint/template-parser": "^20.1.1",
"@angular/build": "^20.3.8",
"@angular/cli": "^20.3.8",
"@angular/compiler-cli": "^20.3.9",
"@angular/language-service": "^20.3.9",
"@angular-devkit/architect": "^0.2100.4",
"@angular-eslint/builder": "^21.1.0",
"@angular-eslint/eslint-plugin": "^21.1.0",
"@angular-eslint/eslint-plugin-template": "^21.1.0",
"@angular-eslint/schematics": "^21.1.0",
"@angular-eslint/template-parser": "^21.1.0",
"@angular/build": "^21.0.4",
"@angular/cli": "^21.0.4",
"@angular/compiler-cli": "^21.0.6",
"@angular/language-service": "^21.0.6",
"@commitlint/cli": "^20.1.0",
"@commitlint/config-conventional": "^20.0.0",
"@types/jasmine": "~5.1.4",
"@types/jasminewd2": "~2.0.3",
"@types/file-saver": "^2.0.7",
"@typescript-eslint/eslint-plugin": "^8.35.1",
"@typescript-eslint/parser": "^8.35.1",
"angular-eslint": "^20.1.1",
"angular-eslint": "^21.1.0",
"eslint": "^9.16.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jsdoc": "^61.1.2",
"eslint-plugin-prefer-arrow": "^1.2.3",
"jasmine-core": "~5.1.1",
"jasmine-spec-reporter": "~7.0.0",
"karma": "~6.4.2",
"karma-chrome-launcher": "~3.2.0",
"karma-coverage-istanbul-reporter": "~3.0.2",
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "^2.0.0",
"ng-packagr": "^20.0.1",
"jsdom": "^27.4.0",
"ng-packagr": "^21.0.1",
"standard-version": "^9.1.1",
"typescript": "~5.9.3"
"typescript": "~5.9.3",
"vitest": "^4.0.16"
},
"config": {
"commitizen": {
Expand Down
32 changes: 0 additions & 32 deletions projects/ng2csv/karma.conf.js

This file was deleted.

5 changes: 3 additions & 2 deletions projects/ng2csv/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"name": "ng2csv",
"version": "7.0.0",
"version": "8.0.0",
"description": "An Angular library for exporting data to CSV.",
"dependencies": {
"tslib": "^2.0.0"
},
"peerDependencies": {
"@angular/core": "^19.0.0",
"@angular/core": "^21.0.0",
"file-saver": "^2.0.0"
},
"repository": {
Expand Down
21 changes: 7 additions & 14 deletions projects/ng2csv/src/lib/auto-csv-row-mapper.class.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,23 @@
import { ICsvRowMapper } from './csv-row-mapper.interface';
import { OrderedProjectionCsvRowMapper } from './ordered-projection-csv-row-mapper.class';

export class AutoCsvRowMapper<T> implements ICsvRowMapper<T> {

export class AutoCsvRowMapper<T extends object> implements ICsvRowMapper<T> {
private derivedCsvRowMapper: OrderedProjectionCsvRowMapper<T>;

public constructor(data: T[]) {
if (!data || data.length === 0) {
throw new Error(
'Parameter \'data\' must be a non-empty array of objects.');
throw new Error("Parameter 'data' must be a non-empty array of objects.");
}

if (typeof data[0] !== 'object') {
throw new Error(
'Parameter \'data\' must contain objects.'
);
throw new Error("Parameter 'data' must contain objects.");
}

const projections: Array<[string, (obj: T) => string]> = [];

const allKeys: string[] = this.getAllKeys(data);
for (const key of allKeys) {
projections.push([
key,
this.createProjection(key)
]);
projections.push([key, this.createProjection(key)]);
}

this.derivedCsvRowMapper = new OrderedProjectionCsvRowMapper<T>(
Expand All @@ -36,14 +29,14 @@ export class AutoCsvRowMapper<T> implements ICsvRowMapper<T> {
return this.derivedCsvRowMapper.getColumnNames();
}

public map(obj: T): string[] {
public map(obj: T): (string | null | undefined)[] {
return this.derivedCsvRowMapper.map(obj);
}

private createProjection(property: string): (obj: T) => string {
return (x: T) => {
if (x.hasOwnProperty(property)) {
const propertyValue = (x as any)[property];
if (x && typeof x === 'object' && Object.hasOwn(x, property)) {
const propertyValue = x[property as keyof T];
if (propertyValue === undefined || propertyValue === null) {
return '';
}
Expand Down
8 changes: 4 additions & 4 deletions projects/ng2csv/src/lib/auto-csv-row-mapper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('AutoCsvRowMapper', () => {
describe('map()', () => {
it('should return row mapping for object', () => {
const columnNames: string[] = rowMapper.getColumnNames();
const row: string[] = rowMapper.map({
const row: (string | null | undefined)[] = rowMapper.map({
address: 'My Address',
email: 'myemail@mail.com',
id: 1,
Expand All @@ -53,12 +53,12 @@ describe('AutoCsvRowMapper', () => {

it('should map missing properties to the empty string', () => {
const columnNames: string[] = rowMapper.getColumnNames();
const row: string[] = rowMapper.map({
id: undefined,
const row: (string | null | undefined)[] = rowMapper.map({
id: 0,
name: 'Bob',
});
expect(row.length).toBe(4);
expect(row[columnNames.indexOf('id')]).toBe('');
expect(row[columnNames.indexOf('id')]).toBe('0');
expect(row[columnNames.indexOf('name')]).toBe('Bob');
expect(row[columnNames.indexOf('address')]).toBe('');
expect(row[columnNames.indexOf('email')]).toBe('');
Expand Down
2 changes: 1 addition & 1 deletion projects/ng2csv/src/lib/csv-row-mapper.interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface ICsvRowMapper<T> {
getColumnNames(): string[];
map(obj: T): string[];
map(obj: T): (string | null | undefined)[];
}
Loading