From bcd24089669a2ed1e9111a1eb3501cd00ded8548 Mon Sep 17 00:00:00 2001 From: pierre-marie broca Date: Fri, 2 Jun 2023 12:18:21 +0200 Subject: [PATCH] fix: lint --- package-lock.json | 1 + package.json | 8 +- src/_styles.scss | 2 +- src/app/app.component.scss | 14 ++-- src/app/app.component.ts | 5 +- .../list-composition.component.html | 2 +- .../list-composition.component.scss | 2 +- .../list-composition.component.ts | 7 +- .../list-fichier/list-fichier.component.html | 2 +- .../list-fichier/list-fichier.component.scss | 2 +- .../list-fichier/list-fichier.component.ts | 6 +- src/app/list/list.component.scss | 14 ++-- src/app/services/data.service.ts | 80 ++++++++++--------- src/app/services/dexie.service.ts | 6 +- src/app/services/dropbox.service.ts | 76 +++++++----------- src/app/services/utils.service.ts | 45 ++++------- src/app/utils/dropbox.ts | 1 + src/app/utils/model.ts | 9 +++ src/app/utils/title.pipe.ts | 5 +- src/app/utils/utils.ts | 28 ++++--- src/main.ts | 2 +- 21 files changed, 151 insertions(+), 166 deletions(-) diff --git a/package-lock.json b/package-lock.json index 01489a19..cf41f0f4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,6 +7,7 @@ "": { "name": "ng-music", "version": "0.0.0", + "hasInstallScript": true, "license": "MIT", "dependencies": { "@angular-devkit/build-angular": "12.2.18", diff --git a/package.json b/package.json index 8d20d686..af37e8ed 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "start": "ng serve --port 7070", "build": "ng build --configuration production --progress false", "cordova": "npm run build --base-href file:///android_asset/www/", - "lint": "run-p lint:**", + "lint": "run-s lint:**", "lint:ts": "gts lint", "lint:format": "prettier --check .", "lint:stylelint": "stylelint \"**/*.scss\" verbose", @@ -17,9 +17,9 @@ "fix:fix": "gts fix", "clean": "gts clean", "compile": "tsc --noEmit", - "prepare": "run-s prepare:*", - "prepare:husky": "husky install", - "prepare:compile": "pnpm compile", + "postinstall": "run-s postinstall:*", + "postinstall:husky": "husky install", + "postinstall:compile": "npm run compile", "pretest": "npm run compile", "posttest": "npm run lint" }, diff --git a/src/_styles.scss b/src/_styles.scss index 7e59ed64..80f903f0 100644 --- a/src/_styles.scss +++ b/src/_styles.scss @@ -5,7 +5,7 @@ } $green: #0ad06f; -$light_green: #d1fff7; +$light-green: #d1fff7; $odd: #cee9f0; $even: #c8ddf0; $blue: #007fff; diff --git a/src/app/app.component.scss b/src/app/app.component.scss index 820523c5..40619b1c 100644 --- a/src/app/app.component.scss +++ b/src/app/app.component.scss @@ -3,9 +3,13 @@ border: 1px solid #ccc; overflow: hidden; - & button { + .active { + background-color: #ccc; + } + + button { background-color: inherit; - border: none; + border: 0; cursor: pointer; float: left; outline: none; @@ -15,15 +19,11 @@ &:hover { background-color: #ddd; } - - &.active { - background-color: #ccc; - } } } .tabcontent { - border-top: none; + border-top: 0; } .tabcontent:not(.active) { diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 27977f9e..1c367fee 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -3,6 +3,7 @@ import {Component, OnInit} from '@angular/core'; import {DataService} from './services/data.service'; import {Dropbox} from './utils/dropbox'; import {DexieService} from './services/dexie.service'; +import {Composition, Fichier} from './utils/model'; @Component({ selector: 'app-root', @@ -19,13 +20,13 @@ export class AppComponent implements OnInit { ) {} ngOnInit(): void { - this.dataService.loadsList( + this.dataService.loadsList( this.dexieService.compositionTable, this.dexieService.fileComposition, Dropbox.DROPBOX_COMPOSITION_FILE, true ); - this.dataService.loadsList( + this.dataService.loadsList( this.dexieService.fichierTable, this.dexieService.fileFichier, Dropbox.DROPBOX_FICHIER_FILE, diff --git a/src/app/list-composition/list-composition.component.html b/src/app/list-composition/list-composition.component.html index 1f99ecd5..f33bd08b 100644 --- a/src/app/list-composition/list-composition.component.html +++ b/src/app/list-composition/list-composition.component.html @@ -267,6 +267,6 @@ > - diff --git a/src/app/list-composition/list-composition.component.scss b/src/app/list-composition/list-composition.component.scss index 96a8d505..8184eb15 100644 --- a/src/app/list-composition/list-composition.component.scss +++ b/src/app/list-composition/list-composition.component.scss @@ -1 +1 @@ -@import '../list/list.component.scss'; +@import '../list/list.component'; diff --git a/src/app/list-composition/list-composition.component.ts b/src/app/list-composition/list-composition.component.ts index 3a09e777..a34462a2 100644 --- a/src/app/list-composition/list-composition.component.ts +++ b/src/app/list-composition/list-composition.component.ts @@ -47,6 +47,7 @@ export class ListCompositionComponent 'size', 'rank', ]; + displayedFichier = new BehaviorSubject([]); sortFichier: Sort; expandedElement: Composition; @@ -100,13 +101,13 @@ export class ListCompositionComponent filterOnComposition(list: Composition[]): Composition[] { let result = list; if (this.artistFilter) { - result = Utils.filterByFields(result, ['sArtist'], this.artistFilter); + result = Utils.filterByFields(result, 'sArtist', this.artistFilter); } if (this.titleFilter) { - result = Utils.filterByFields(result, ['sTitle'], this.titleFilter); + result = Utils.filterByFields(result, 'sTitle', this.titleFilter); } if (this.filteredType) { - result = Utils.filterByFields(result, ['type'], this.filteredType.code); + result = Utils.filterByFields(result, 'type', this.filteredType.code); } if (!this.deleted) { result = result.filter(c => !c.deleted); diff --git a/src/app/list-fichier/list-fichier.component.html b/src/app/list-fichier/list-fichier.component.html index de5f8cf1..030c06e6 100644 --- a/src/app/list-fichier/list-fichier.component.html +++ b/src/app/list-fichier/list-fichier.component.html @@ -279,6 +279,6 @@ > - diff --git a/src/app/list-fichier/list-fichier.component.scss b/src/app/list-fichier/list-fichier.component.scss index 96a8d505..8184eb15 100644 --- a/src/app/list-fichier/list-fichier.component.scss +++ b/src/app/list-fichier/list-fichier.component.scss @@ -1 +1 @@ -@import '../list/list.component.scss'; +@import '../list/list.component'; diff --git a/src/app/list-fichier/list-fichier.component.ts b/src/app/list-fichier/list-fichier.component.ts index 1f1a65ee..cb95f5d3 100644 --- a/src/app/list-fichier/list-fichier.component.ts +++ b/src/app/list-fichier/list-fichier.component.ts @@ -82,13 +82,13 @@ export class ListFichierComponent filter(list: Fichier[]): Fichier[] { let result = list; if (this.nameFilter) { - result = Utils.filterByFields(result, ['name'], this.nameFilter); + result = Utils.filterByFields(result, 'name', this.nameFilter); } if (this.authorFilter) { - result = Utils.filterByFields(result, ['author'], this.authorFilter); + result = Utils.filterByFields(result, 'author', this.authorFilter); } if (this.filteredType) { - result = Utils.filterByFields(result, ['type'], this.filteredType.code); + result = Utils.filterByFields(result, 'type', this.filteredType.code); } if (this.beginFilter) { result = result.filter(f => f.rangeBegin >= this.beginFilter); diff --git a/src/app/list/list.component.scss b/src/app/list/list.component.scss index ac62995e..47545839 100644 --- a/src/app/list/list.component.scss +++ b/src/app/list/list.component.scss @@ -35,7 +35,7 @@ display: flex; flex-direction: row; - & .clear-btn { + .clear-btn { align-items: center; display: flex; margin: auto; @@ -71,7 +71,7 @@ mat-row { min-height: 0 !important; } -.example-detail-row td.mat-cell { +.example-detail-row .mat-cell { border-bottom-style: unset !important; } @@ -83,11 +83,11 @@ mat-row { border-bottom-width: 0; } -#goTop { +.go-top { display: flex; margin: auto; - & ::ng-deep.fa-angle-up { + ::ng-deep.fa-angle-up { color: $blue; } } @@ -97,18 +97,18 @@ mat-row { } .sorted { - background-color: $light_green !important; + background-color: $light-green !important; } @include media('800px') { .filters { flex-direction: column; - & ::ng-deep.mat-form-field-flex { + ::ng-deep.mat-form-field-flex { flex-direction: row; } - & .filter-item .mat-form-field { + .filter-item .mat-form-field { width: 90vw; } } diff --git a/src/app/services/data.service.ts b/src/app/services/data.service.ts index cd179283..c5dca254 100644 --- a/src/app/services/data.service.ts +++ b/src/app/services/data.service.ts @@ -4,13 +4,17 @@ import * as xml2js from 'xml2js'; import * as moment from 'moment-mini-ts'; import Dexie from 'dexie'; import * as JSZip from 'jszip'; +import DropboxTypes from 'dropbox'; import {DropboxService} from './dropbox.service'; import {UtilsService} from './utils.service'; -import {Composition, Fichier} from '../utils/model'; +import {Composition, Fichier, File} from '../utils/model'; import {ToastService} from './toast.service'; import {Dropbox} from '../utils/dropbox'; +type CompositionOrFichier = + T extends Composition ? Composition : Fichier; + @Injectable({ providedIn: 'root', }) @@ -25,11 +29,11 @@ export class DataService { private toast: ToastService ) {} - loadsList( - table: Dexie.Table, - file: Dexie.Table, + loadsList( + table: Dexie.Table, number>, + file: Dexie.Table, dropboxFile: string, - isCompilation: boolean + isComposition: boolean ): void { Promise.all([ file.get(1), @@ -41,18 +45,18 @@ export class DataService { ); if (!fileNameToDownload && !storedName) { this.toast.open('No file to download or loaded'); - this.done(isCompilation); + this.done(isComposition); } else if (fileNameToDownload && !storedName) { this.downloadsList( table, file, fileNameToDownload, - 'Download ' + dropboxFile, - isCompilation + `Download ${dropboxFile}`, + isComposition ); } else if (!fileNameToDownload && storedName) { this.toast.open('Already loaded'); - this.done(isCompilation); + this.done(isComposition); } else { if ( this.extractDateFromFilename(fileNameToDownload).isAfter( @@ -63,12 +67,12 @@ export class DataService { table, file, fileNameToDownload, - 'Update ' + dropboxFile, - isCompilation + `Update ${dropboxFile}`, + isComposition ); } else { this.toast.open('Already loaded'); - this.done(isCompilation); + this.done(isComposition); } } }); @@ -82,14 +86,10 @@ export class DataService { return table.add(data); } - addAll(table: Dexie.Table, data: T[]): Promise { + addAll(table: Dexie.Table, data: T[]): Promise { return table .bulkAdd(data) - .then(lastKey => { - console.log(`Done adding ${data.length} datas`); - console.log('Last data id was: ' + lastKey); - return lastKey; - }) + .then(() => console.warn(`Done adding ${data.length} datas`)) .catch(Dexie.BulkError, e => { // Explicitely catching the bulkAdd() operation makes those successful // additions commit despite that there were errors. @@ -98,7 +98,6 @@ export class DataService { data.length - e.failures.length } items was added successfully` ); - return 0; }); } @@ -114,35 +113,35 @@ export class DataService { return table.delete(id); } - downloadsList( - table: Dexie.Table, - fileTable: Dexie.Table, + downloadsList( + table: Dexie.Table, number>, + fileTable: Dexie.Table, fileName: string, resultMessage: string, - isCompilation: boolean - ): Promise { + isComposition: boolean + ): Promise { // download file const t0 = performance.now(); const zip: JSZip = new JSZip(); return this.dropboxService .downloadFile(fileName) .then((content: string) => { - this.toast.open('File downloaded: ' + fileName); + this.toast.open(`File downloaded: ${fileName}`); return zip.loadAsync(content); }) .then(content => zip.file(Object.keys(content.files)[0]).async('string')) .then((dataFromFile: string) => { if (dataFromFile && dataFromFile.trim().length > 0) { // Parse file - const dataList = this.parseData(dataFromFile, isCompilation); + const dataList = this.parseData(dataFromFile, isComposition); const t1 = performance.now(); - console.log('Call took ' + (t1 - t0) / 1000 + ' seconds'); + console.warn(`Call took ${(t1 - t0) / 1000} seconds`); return dataList; } else { return []; } }) - .then((dataList: T[]) => { + .then((dataList: (Composition | Fichier)[]) => { this.toast.open('Data parsed'); fileTable.get(1).then(item => { if (!item) { @@ -154,13 +153,16 @@ export class DataService { table.clear(); this.addAll(table, dataList); this.toast.open(resultMessage); - this.done(isCompilation); + this.done(isComposition); }) .catch(err => this.serviceUtils.handlePromiseError(err)); } - parseData(dataFromFile: string, isCompilation: boolean): any[] { - if (isCompilation) { + parseData( + dataFromFile: string, + isComposition: boolean + ): (Composition | Fichier)[] { + if (isComposition) { return this.parseCompositions(dataFromFile); } else { return this.parseFichiers(dataFromFile); @@ -172,9 +174,7 @@ export class DataService { new xml2js.Parser().parseString(compoFromFile, result => { result.Compositions.C.forEach(el => { const c = this.parseComposition(el); - c.fileList = el.F.map((elFile: any) => - this.parseFichier(elFile, false) - ); + c.fileList = el.F.map(elFile => this.parseFichier(elFile, false)); compoList.push(c); }); }); @@ -186,15 +186,14 @@ export class DataService { new xml2js.Parser().parseString(fichierFromFile, result => { result.Fichiers.F.forEach(el => { const f = this.parseFichier(el, true); - f.compoList = el.C.map((elCompo: any) => - this.parseComposition(elCompo) - ); + f.compoList = el.C.map(elCompo => this.parseComposition(elCompo)); fichierList.push(f); }); }); return fichierList; } + // eslint-disable-next-line @typescript-eslint/no-explicit-any private parseComposition(compoXml: any): Composition { return new Composition( compoXml.$.A, @@ -210,6 +209,7 @@ export class DataService { ); } + // eslint-disable-next-line @typescript-eslint/no-explicit-any private parseFichier(fichierXml: any, splitName: boolean): Fichier { let name: string = fichierXml.$.name; const f = new Fichier( @@ -237,7 +237,10 @@ export class DataService { return f; } - private findsFileNameToDownload(filesList: any, dropboxFile: string): string { + private findsFileNameToDownload( + filesList: DropboxTypes.files.ListFolderResult, + dropboxFile: string + ): string { if (!filesList) { return undefined; } @@ -262,7 +265,6 @@ export class DataService { const fileToDownload = names.find(name => name.includes(moment(lastDate).format(this.dateFormat)) ); - console.log('fileToDownload', fileToDownload); return fileToDownload; } } diff --git a/src/app/services/dexie.service.ts b/src/app/services/dexie.service.ts index a6b9a5d3..80ef1bc0 100644 --- a/src/app/services/dexie.service.ts +++ b/src/app/services/dexie.service.ts @@ -1,6 +1,6 @@ import {Injectable} from '@angular/core'; import Dexie from 'dexie'; -import {Composition, Fichier} from '../utils/model'; +import {Composition, Fichier, File} from '../utils/model'; @Injectable({ providedIn: 'root', @@ -8,8 +8,8 @@ import {Composition, Fichier} from '../utils/model'; export class DexieService extends Dexie { compositionTable: Dexie.Table; fichierTable: Dexie.Table; - fileComposition: Dexie.Table; - fileFichier: Dexie.Table; + fileComposition: Dexie.Table; + fileFichier: Dexie.Table; constructor() { super('NgMusic'); diff --git a/src/app/services/dropbox.service.ts b/src/app/services/dropbox.service.ts index a07b6f37..cb299002 100644 --- a/src/app/services/dropbox.service.ts +++ b/src/app/services/dropbox.service.ts @@ -1,21 +1,22 @@ import {Injectable} from '@angular/core'; -import * as Dropbox from 'dropbox'; - +import DropboxTypes from 'dropbox'; import {UtilsService} from './utils.service'; -import {Dropbox as DropboxConstante} from '../utils/dropbox'; +import {Dropbox as DropboxConstant} from '../utils/dropbox'; @Injectable({providedIn: 'root'}) export class DropboxService { constructor(private serviceUtils: UtilsService) {} - getDbx(): Dropbox.Dropbox { - return new Dropbox.Dropbox({accessToken: DropboxConstante.DROPBOX_TOKEN}); + getDbx(): DropboxTypes.Dropbox { + return new DropboxTypes.Dropbox({ + accessToken: DropboxConstant.DROPBOX_TOKEN, + }); } - listFiles(folder: string): Promise { + listFiles(folder: string): Promise { return this.getDbx() .filesListFolder({path: folder}) - .then((response: Dropbox.files.ListFolderResult) => response) + .then((response: DropboxTypes.files.ListFolderResult) => response) .catch(err => { this.serviceUtils.handleError(err); return undefined; @@ -23,49 +24,26 @@ export class DropboxService { } getPath(fileName: string): string { - return DropboxConstante.DROPBOX_FOLDER + fileName; - } - - uploadFile( - fichier: Blob, - fileName: string - ): Promise { - const pathFile = this.getPath(fileName); - return this.getDbx() - .filesDeleteV2({path: pathFile}) - .then(() => { - return this.getDbx().filesUpload({path: pathFile, contents: fichier}); - }) - .catch(err => this.serviceUtils.handlePromiseError(err)); + return DropboxConstant.DROPBOX_FOLDER + fileName; } - uploadNewFile( - fichier: string, - fileName: string - ): Promise { - const pathFile = this.getPath(fileName); - return this.getDbx() - .filesUpload({path: pathFile, contents: fichier}) - .then(() => new Promise(resolve => resolve())) - .catch(err => this.serviceUtils.handlePromiseError(err)); - } - - downloadFile(fileName: string): Promise { - return this.getDbx() - .filesDownload({path: this.getPath(fileName)}) - .then((response: any) => { - const fileReader = new FileReader(); - return new Promise((resolve, reject) => { - fileReader.onerror = () => { - fileReader.abort(); - reject(new DOMException('Problem parsing input file.')); - }; - fileReader.onload = () => { - return resolve(fileReader.result.toString()); - }; - fileReader.readAsBinaryString(response.fileBlob); - }); - }) - .catch(err => this.serviceUtils.handleError(err)); + downloadFile(fileName: string): Promise { + return ( + this.getDbx() + .filesDownload({path: this.getPath(fileName)}) + // eslint-disable-next-line @typescript-eslint/no-explicit-any + .then((response: any) => { + const fileReader = new FileReader(); + return new Promise((resolve, reject) => { + fileReader.onerror = () => { + fileReader.abort(); + reject(new DOMException('Problem parsing input file.')); + }; + fileReader.onload = () => resolve(fileReader.result.toString()); + fileReader.readAsBinaryString(response.fileBlob); + }); + }) + .catch(err => this.serviceUtils.handleError(err)) + ); } } diff --git a/src/app/services/utils.service.ts b/src/app/services/utils.service.ts index e5893fa6..7069c4c8 100644 --- a/src/app/services/utils.service.ts +++ b/src/app/services/utils.service.ts @@ -1,21 +1,17 @@ import {Observable} from 'rxjs'; import {Injectable} from '@angular/core'; -import {HttpHeaders, HttpClient} from '@angular/common/http'; - +import {HttpHeaders, HttpClient, HttpErrorResponse} from '@angular/common/http'; import {ToastService} from './toast.service'; +import {GlobalError} from '../utils/model'; @Injectable({providedIn: 'root'}) export class UtilsService { constructor(private http: HttpClient, private toast: ToastService) {} - static getErrorMessage(error: any): string { + static getErrorMessage(error: GlobalError): string { let message; - if (error.response) { - message = error.response.error; - } else if (error.error && error.error.errors) { - message = 'Status ' + error.status + ': ' + error.error.errors.join(', '); - } else if (error.error) { - message = error.error; + if (UtilsService.isHttpError(error)) { + message = `Status ${error.status}: ${error.error.errors.join(', ')}`; } else if (error.message) { message = error.message; } else { @@ -24,31 +20,30 @@ export class UtilsService { return message; } + private static isHttpError(error: GlobalError): error is HttpErrorResponse { + return 'status' in error; + } + static encodeQueryUrl(query: string): string { return encodeURIComponent(query).replace( /[!'()*]/g, - c => '%' + c.charCodeAt(0).toString(16) + c => `%${c.charCodeAt(0).toString(16)}` ); } getHeaders(): HttpHeaders { - const headers = new HttpHeaders({'Content-Type': 'application/json'}); - // headers.append('Accept', 'application/json'); - return headers; + return new HttpHeaders({'Content-Type': 'application/json'}); } - handleError(error: any): void { - console.log('handleError'); - console.error('error', error); + handleError(error: GlobalError): void { + console.error('handleError', error); this.toast.open(UtilsService.getErrorMessage(error)); - this.toast.open(error); } - handlePromiseError(error: any): Promise { - console.log('handlePromiseError'); - console.error('error', error); + handlePromiseError(error: GlobalError): Promise { + console.error('handlePromiseError', error); this.toast.open(UtilsService.getErrorMessage(error)); - return new Promise(resolve => { + return new Promise(resolve => { resolve(undefined); }); } @@ -62,12 +57,4 @@ export class UtilsService { ? this.http.get(url, {headers: headers}) : this.http.get(url); } - - jsonpPromise(url: string, callback: any): Promise { - return this.jsonpObservable(url, callback).toPromise(); - } - - jsonpObservable(url: string, callback: any): Observable { - return this.http.jsonp(url, callback); - } } diff --git a/src/app/utils/dropbox.ts b/src/app/utils/dropbox.ts index 5bd3ba5a..c9a3a3cc 100644 --- a/src/app/utils/dropbox.ts +++ b/src/app/utils/dropbox.ts @@ -1,6 +1,7 @@ export class Dropbox { static readonly DROPBOX_TOKEN = 'G-_ZeiEAvB0AAAAAAAANQd4IMHRr7Y9aTvAiivg-8LImbDKmo9pdu95_SIioW3lR'; + static readonly DROPBOX_FOLDER = '/XML/'; static readonly DROPBOX_COMPOSITION_FILE = 'final'; static readonly DROPBOX_FICHIER_FILE = 'fichier'; diff --git a/src/app/utils/model.ts b/src/app/utils/model.ts index 7894ab0a..1f6a00da 100644 --- a/src/app/utils/model.ts +++ b/src/app/utils/model.ts @@ -1,3 +1,5 @@ +import {HttpErrorResponse} from '@angular/common/http'; + export class Fichier { category: string; creation: string; @@ -87,3 +89,10 @@ export class Dropdown { this.code = code; } } + +export class File { + id?: number; + filename: string; +} + +export type GlobalError = Error | HttpErrorResponse; diff --git a/src/app/utils/title.pipe.ts b/src/app/utils/title.pipe.ts index 8616e995..667c96f4 100644 --- a/src/app/utils/title.pipe.ts +++ b/src/app/utils/title.pipe.ts @@ -8,7 +8,10 @@ const unicodeWordMatch = name: 'title', }) export class TitlePipe implements PipeTransform { - transform(value: any, replaceUnderscore?: boolean): any { + transform( + value: unknown | string, + replaceUnderscore?: boolean + ): unknown | string { if (!value) { return value; } diff --git a/src/app/utils/utils.ts b/src/app/utils/utils.ts index e50a3529..a4b0e3fe 100644 --- a/src/app/utils/utils.ts +++ b/src/app/utils/utils.ts @@ -5,8 +5,6 @@ import {Composition, Fichier} from './model'; export class Utils { static sortComposition(list: Composition[], sort: Sort): Composition[] { - console.log('list', list); - console.log('sort', sort); if (sort && sort.active && sort.direction !== '') { return list.sort((a, b) => { const isAsc: boolean = sort.direction === 'asc'; @@ -92,22 +90,26 @@ export class Utils { return result * (isAsc ? 1 : -1); } - static filterByFields(items: T[], fields: string[], value: any): T[] { + static filterByFields( + items: T[], + field: string & keyof T, + value: string + ): T[] { if (!items || items === undefined) { - return []; + return [] as T[]; } - if (value === undefined || value.length === 0) { + if ( + value === undefined || + value.trim().length === 0 || + value.trim() === '' + ) { return items; } - const val = value.toLowerCase(); return items.filter(item => { - return fields.some(field => { - let it = item[field]; - if (it) { - it = typeof it === 'string' ? it.toLowerCase() : it.toString(); - return it.includes(val); - } - }); + const fieldItem = item[field]; + return typeof fieldItem === 'string' + ? fieldItem.toLowerCase() + : fieldItem.toString().includes(value.toLowerCase()); }); } diff --git a/src/main.ts b/src/main.ts index 8463f57f..947bb036 100644 --- a/src/main.ts +++ b/src/main.ts @@ -10,4 +10,4 @@ if (environment.production) { platformBrowserDynamic() .bootstrapModule(AppModule) - .catch(err => console.log(err)); + .catch(err => console.error(err));