Fully working with the rule no explicit any
This commit is contained in:
@ -1,15 +1,19 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
import { ToCsvType } from './to-csv-type';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class ToCsvService {
|
||||
// eslint-disable-next-line class-methods-use-this
|
||||
toCsv(headers: any, data: any[]): string {
|
||||
toCsv(headers: { [display: string]: string }, data: unknown[]): string {
|
||||
const header = Object.keys(headers);
|
||||
const replacer = (key: string, value: string | number | null) => (value === null ? '' : value);
|
||||
const csv = data.map((row) =>
|
||||
header.map((fieldName) => JSON.stringify(row[headers[fieldName]], replacer)).join(','),
|
||||
header
|
||||
.map((fieldName) => JSON.stringify((row as ToCsvType)[headers[fieldName]], replacer))
|
||||
.join(','),
|
||||
);
|
||||
csv.unshift(header.join(','));
|
||||
return csv.join('\r\n');
|
||||
|
||||
Reference in New Issue
Block a user