Use instanceof instead of duck typing for TAbstractFile
This commit is contained in:
parent
075225298f
commit
0da5b3ebe7
|
@ -51,15 +51,16 @@ export class FileHelper {
|
||||||
abstractFile: TAbstractFile,
|
abstractFile: TAbstractFile,
|
||||||
counts: CountsByFile
|
counts: CountsByFile
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
if ((abstractFile as TFolder).children) {
|
if (abstractFile instanceof TFolder) {
|
||||||
Object.assign(counts, this.getAllFileCounts());
|
Object.assign(counts, this.getAllFileCounts());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const file = abstractFile as TFile;
|
if (abstractFile instanceof TFile) {
|
||||||
const contents = await this.vault.cachedRead(file);
|
const contents = await this.vault.cachedRead(abstractFile);
|
||||||
const wordCount = this.countWords(contents);
|
const wordCount = this.countWords(contents);
|
||||||
this.setCounts(counts, file.path, wordCount);
|
this.setCounts(counts, abstractFile.path, wordCount);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private countWords(content: string): number {
|
private countWords(content: string): number {
|
||||||
|
|
Loading…
Reference in New Issue