mirror of
https://github.com/PeWu/topola-viewer.git
synced 2026-07-29 23:21:50 +00:00
Improve code quality
Fix lint warnings
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
/** Sends an event to Google Analytics. */
|
||||
export function analyticsEvent(action: string, data?: any) {
|
||||
export function analyticsEvent(action: string, data?: unknown) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
(window as any).gtag('event', action, data);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/** No-op function for analytics. */
|
||||
export function analyticsEvent(action: string, data?: any) {
|
||||
export function analyticsEvent(_action: string, _data?: unknown) {
|
||||
// no-op
|
||||
}
|
||||
|
||||
@@ -180,9 +180,5 @@ export function isDateRangeClosed(range: DateRange | undefined): boolean {
|
||||
}
|
||||
|
||||
export function toDateObject(date: TopolaDate): Date {
|
||||
return new Date(
|
||||
date.year !== undefined ? date.year! : 0,
|
||||
date.month !== undefined ? date.month! - 1 : 0,
|
||||
date.day !== undefined ? date.day! : 1,
|
||||
);
|
||||
return new Date(date.year ?? 0, (date.month ?? 1) - 1, date.day ?? 1);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
import {describe, expect, it} from '@jest/globals';
|
||||
import {getName, normalizeGedcom} from './gedcom_util';
|
||||
import {JsonGedcomData} from 'topola';
|
||||
import {
|
||||
findRelationshipPath,
|
||||
getAncestors,
|
||||
getDescendants,
|
||||
getName,
|
||||
idToFamMap,
|
||||
idToIndiMap,
|
||||
normalizeGedcom,
|
||||
} from './gedcom_util';
|
||||
|
||||
describe('normalizeGedcom()', () => {
|
||||
it('sorts children', () => {
|
||||
@@ -62,7 +71,7 @@ describe('normalizeGedcom()', () => {
|
||||
],
|
||||
};
|
||||
const normalized = normalizeGedcom(data);
|
||||
expect(normalized.indis.find((i) => i.id === 'I4')!.fams).toEqual([
|
||||
expect(normalized.indis.find((i) => i.id === 'I4')?.fams).toEqual([
|
||||
'F3',
|
||||
'F2',
|
||||
'F1',
|
||||
@@ -140,16 +149,8 @@ describe('getName()', () => {
|
||||
});
|
||||
});
|
||||
|
||||
import {
|
||||
findRelationshipPath,
|
||||
getAncestors,
|
||||
getDescendants,
|
||||
idToFamMap,
|
||||
idToIndiMap,
|
||||
} from './gedcom_util';
|
||||
|
||||
describe('Relationship algorithms', () => {
|
||||
const sampleData = {
|
||||
const sampleData: JsonGedcomData = {
|
||||
indis: [
|
||||
{id: 'I1', fams: ['F1']},
|
||||
{id: 'I2', fams: ['F1'], famc: 'F2'},
|
||||
@@ -160,7 +161,7 @@ describe('Relationship algorithms', () => {
|
||||
{id: 'F1', husb: 'I1', wife: 'I2', children: ['I3']},
|
||||
{id: 'F2', children: ['I2', 'I4']},
|
||||
],
|
||||
} as any;
|
||||
};
|
||||
|
||||
const indiMap = idToIndiMap(sampleData);
|
||||
const famMap = idToFamMap(sampleData);
|
||||
|
||||
@@ -13,7 +13,7 @@ import {TopolaError} from './error';
|
||||
|
||||
export interface GedcomData {
|
||||
/** The HEAD entry. */
|
||||
head: GedcomEntry;
|
||||
head?: GedcomEntry;
|
||||
/** INDI entries mapped by id. */
|
||||
indis: {[key: string]: GedcomEntry};
|
||||
/** FAM entries mapped by id. */
|
||||
@@ -62,7 +62,7 @@ export function idToFamMap(data: JsonGedcomData): Map<string, JsonFam> {
|
||||
}
|
||||
|
||||
function prepareGedcom(entries: GedcomEntry[]): GedcomData {
|
||||
const head = entries.find((entry) => entry.tag === 'HEAD')!;
|
||||
const head = entries.find((entry) => entry.tag === 'HEAD');
|
||||
const indis: {[key: string]: GedcomEntry} = {};
|
||||
const fams: {[key: string]: GedcomEntry} = {};
|
||||
const other: {[key: string]: GedcomEntry} = {};
|
||||
@@ -223,12 +223,13 @@ function filterImage(indi: JsonIndi, images: Map<string, string>): JsonIndi {
|
||||
const newImages: JsonImage[] = [];
|
||||
indi.images.forEach((image) => {
|
||||
const filePath = image.url.replaceAll('\\', '/');
|
||||
const fileName = filePath.match(/[^/]*$/)![0];
|
||||
// If the image file has been loaded into memory, use it.
|
||||
if (images.has(filePath)) {
|
||||
newImages.push({url: images.get(filePath)!, title: image.title});
|
||||
} else if (images.has(fileName)) {
|
||||
newImages.push({url: images.get(fileName)!, title: image.title});
|
||||
const fileName = filePath.split('/').pop() || '';
|
||||
const fileUrl = images.get(filePath);
|
||||
const nameUrl = images.get(fileName);
|
||||
if (fileUrl) {
|
||||
newImages.push({url: fileUrl, title: image.title});
|
||||
} else if (nameUrl) {
|
||||
newImages.push({url: nameUrl, title: image.title});
|
||||
} else if (image.url.startsWith('http') && isImageFile(image.url)) {
|
||||
newImages.push(image);
|
||||
}
|
||||
@@ -279,7 +280,7 @@ export function convertGedcom(
|
||||
}
|
||||
|
||||
/** Returns the name of the software used to generate the GEDCOM file, if available. */
|
||||
export function getSoftware(head: GedcomEntry): string | null {
|
||||
export function getSoftware(head?: GedcomEntry): string | null {
|
||||
const sour =
|
||||
head && head.tree && head.tree.find((entry) => entry.tag === 'SOUR');
|
||||
const name =
|
||||
@@ -443,6 +444,7 @@ export function findRelationshipPath(
|
||||
visited.set(indiId1, null);
|
||||
|
||||
while (queue.length > 0) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
const current = queue.shift()!;
|
||||
if (current === indiId2) {
|
||||
const path: string[] = [];
|
||||
@@ -479,6 +481,7 @@ export function getAncestors(
|
||||
visited.add(indiId);
|
||||
|
||||
while (queue.length > 0) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
const {id, gen} = queue.shift()!;
|
||||
if (id !== indiId && !id.startsWith('private_')) {
|
||||
result.push(id);
|
||||
@@ -518,6 +521,7 @@ export function getDescendants(
|
||||
visited.add(indiId);
|
||||
|
||||
while (queue.length > 0) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
const {id, gen} = queue.shift()!;
|
||||
if (id !== indiId && !id.startsWith('private_')) {
|
||||
result.push(id);
|
||||
|
||||
Reference in New Issue
Block a user