Fully working with the rule no explicit any

This commit is contained in:
2020-11-25 09:27:42 +05:30
parent 84535ca9bb
commit b583b90756
27 changed files with 223 additions and 155 deletions

View File

@ -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');