@treeviz/gedcom-parser 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +954 -0
- package/dist/classes/common.d.ts +87 -0
- package/dist/classes/common.d.ts.map +1 -0
- package/dist/classes/common.js +481 -0
- package/dist/classes/date.d.ts +26 -0
- package/dist/classes/date.d.ts.map +1 -0
- package/dist/classes/date.js +176 -0
- package/dist/classes/fam.d.ts +19 -0
- package/dist/classes/fam.d.ts.map +1 -0
- package/dist/classes/fam.js +38 -0
- package/dist/classes/fams.d.ts +16 -0
- package/dist/classes/fams.d.ts.map +1 -0
- package/dist/classes/fams.js +41 -0
- package/dist/classes/gedcom.d.ts +89 -0
- package/dist/classes/gedcom.d.ts.map +1 -0
- package/dist/classes/gedcom.js +421 -0
- package/dist/classes/index.d.ts +19 -0
- package/dist/classes/index.d.ts.map +1 -0
- package/dist/classes/index.js +19 -0
- package/dist/classes/indi.d.ts +298 -0
- package/dist/classes/indi.d.ts.map +1 -0
- package/dist/classes/indi.js +2049 -0
- package/dist/classes/indis.d.ts +54 -0
- package/dist/classes/indis.d.ts.map +1 -0
- package/dist/classes/indis.js +439 -0
- package/dist/classes/list.d.ts +55 -0
- package/dist/classes/list.d.ts.map +1 -0
- package/dist/classes/list.js +440 -0
- package/dist/classes/name.d.ts +20 -0
- package/dist/classes/name.d.ts.map +1 -0
- package/dist/classes/name.js +48 -0
- package/dist/classes/note.d.ts +12 -0
- package/dist/classes/note.d.ts.map +1 -0
- package/dist/classes/note.js +46 -0
- package/dist/classes/obje.d.ts +12 -0
- package/dist/classes/obje.d.ts.map +1 -0
- package/dist/classes/obje.js +81 -0
- package/dist/classes/objes.d.ts +8 -0
- package/dist/classes/objes.d.ts.map +1 -0
- package/dist/classes/objes.js +13 -0
- package/dist/classes/repo.d.ts +11 -0
- package/dist/classes/repo.d.ts.map +1 -0
- package/dist/classes/repo.js +6 -0
- package/dist/classes/repos.d.ts +8 -0
- package/dist/classes/repos.d.ts.map +1 -0
- package/dist/classes/repos.js +13 -0
- package/dist/classes/sour.d.ts +11 -0
- package/dist/classes/sour.d.ts.map +1 -0
- package/dist/classes/sour.js +6 -0
- package/dist/classes/sours.d.ts +8 -0
- package/dist/classes/sours.d.ts.map +1 -0
- package/dist/classes/sours.js +13 -0
- package/dist/classes/subm.d.ts +10 -0
- package/dist/classes/subm.d.ts.map +1 -0
- package/dist/classes/subm.js +6 -0
- package/dist/classes/subms.d.ts +8 -0
- package/dist/classes/subms.d.ts.map +1 -0
- package/dist/classes/subms.js +13 -0
- package/dist/constants/constants.d.ts +14 -0
- package/dist/constants/constants.d.ts.map +1 -0
- package/dist/constants/constants.js +13 -0
- package/dist/constants/filters.d.ts +17 -0
- package/dist/constants/filters.d.ts.map +1 -0
- package/dist/constants/filters.js +44 -0
- package/dist/constants/index.d.ts +4 -0
- package/dist/constants/index.d.ts.map +1 -0
- package/dist/constants/index.js +4 -0
- package/dist/constants/orders.d.ts +17 -0
- package/dist/constants/orders.d.ts.map +1 -0
- package/dist/constants/orders.js +240 -0
- package/dist/factories/cache-factory.d.ts +30 -0
- package/dist/factories/cache-factory.d.ts.map +1 -0
- package/dist/factories/cache-factory.js +43 -0
- package/dist/factories/date-locale-factory.d.ts +30 -0
- package/dist/factories/date-locale-factory.d.ts.map +1 -0
- package/dist/factories/date-locale-factory.js +34 -0
- package/dist/factories/i18n-factory.d.ts +40 -0
- package/dist/factories/i18n-factory.d.ts.map +1 -0
- package/dist/factories/i18n-factory.js +44 -0
- package/dist/factories/index.d.ts +5 -0
- package/dist/factories/index.d.ts.map +1 -0
- package/dist/factories/index.js +5 -0
- package/dist/factories/kinship-factory.d.ts +38 -0
- package/dist/factories/kinship-factory.d.ts.map +1 -0
- package/dist/factories/kinship-factory.js +35 -0
- package/dist/factories/place-parser-provider.d.ts +32 -0
- package/dist/factories/place-parser-provider.d.ts.map +1 -0
- package/dist/factories/place-parser-provider.js +35 -0
- package/dist/factories/place-translator-provider.d.ts +32 -0
- package/dist/factories/place-translator-provider.d.ts.map +1 -0
- package/dist/factories/place-translator-provider.js +35 -0
- package/dist/index.d.ts +78 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +44 -0
- package/dist/interfaces/common.d.ts +43 -0
- package/dist/interfaces/common.d.ts.map +1 -0
- package/dist/interfaces/common.js +1 -0
- package/dist/interfaces/fam.d.ts +11 -0
- package/dist/interfaces/fam.d.ts.map +1 -0
- package/dist/interfaces/fam.js +1 -0
- package/dist/interfaces/fams.d.ts +9 -0
- package/dist/interfaces/fams.d.ts.map +1 -0
- package/dist/interfaces/fams.js +1 -0
- package/dist/interfaces/gedcom.d.ts +30 -0
- package/dist/interfaces/gedcom.d.ts.map +1 -0
- package/dist/interfaces/gedcom.js +1 -0
- package/dist/interfaces/index.d.ts +12 -0
- package/dist/interfaces/index.d.ts.map +1 -0
- package/dist/interfaces/index.js +1 -0
- package/dist/interfaces/indi.d.ts +109 -0
- package/dist/interfaces/indi.d.ts.map +1 -0
- package/dist/interfaces/indi.js +1 -0
- package/dist/interfaces/indis.d.ts +31 -0
- package/dist/interfaces/indis.d.ts.map +1 -0
- package/dist/interfaces/indis.js +1 -0
- package/dist/interfaces/list.d.ts +52 -0
- package/dist/interfaces/list.d.ts.map +1 -0
- package/dist/interfaces/list.js +1 -0
- package/dist/interfaces/obje.d.ts +7 -0
- package/dist/interfaces/obje.d.ts.map +1 -0
- package/dist/interfaces/obje.js +1 -0
- package/dist/interfaces/repo.d.ts +7 -0
- package/dist/interfaces/repo.d.ts.map +1 -0
- package/dist/interfaces/repo.js +1 -0
- package/dist/interfaces/sour.d.ts +7 -0
- package/dist/interfaces/sour.d.ts.map +1 -0
- package/dist/interfaces/sour.js +1 -0
- package/dist/interfaces/subm.d.ts +6 -0
- package/dist/interfaces/subm.d.ts.map +1 -0
- package/dist/interfaces/subm.js +1 -0
- package/dist/kinship-translator/index.d.ts +11 -0
- package/dist/kinship-translator/index.d.ts.map +1 -0
- package/dist/kinship-translator/index.js +10 -0
- package/dist/kinship-translator/kinship-translator.basic.d.ts +30 -0
- package/dist/kinship-translator/kinship-translator.basic.d.ts.map +1 -0
- package/dist/kinship-translator/kinship-translator.basic.js +74 -0
- package/dist/kinship-translator/kinship-translator.d.ts +26 -0
- package/dist/kinship-translator/kinship-translator.d.ts.map +1 -0
- package/dist/kinship-translator/kinship-translator.de.d.ts +18 -0
- package/dist/kinship-translator/kinship-translator.de.d.ts.map +1 -0
- package/dist/kinship-translator/kinship-translator.de.js +180 -0
- package/dist/kinship-translator/kinship-translator.en.d.ts +18 -0
- package/dist/kinship-translator/kinship-translator.en.d.ts.map +1 -0
- package/dist/kinship-translator/kinship-translator.en.js +182 -0
- package/dist/kinship-translator/kinship-translator.es.d.ts +18 -0
- package/dist/kinship-translator/kinship-translator.es.d.ts.map +1 -0
- package/dist/kinship-translator/kinship-translator.es.js +181 -0
- package/dist/kinship-translator/kinship-translator.fr.d.ts +18 -0
- package/dist/kinship-translator/kinship-translator.fr.d.ts.map +1 -0
- package/dist/kinship-translator/kinship-translator.fr.js +181 -0
- package/dist/kinship-translator/kinship-translator.hu.d.ts +19 -0
- package/dist/kinship-translator/kinship-translator.hu.d.ts.map +1 -0
- package/dist/kinship-translator/kinship-translator.hu.js +226 -0
- package/dist/kinship-translator/kinship-translator.interface.d.ts +19 -0
- package/dist/kinship-translator/kinship-translator.interface.d.ts.map +1 -0
- package/dist/kinship-translator/kinship-translator.interface.js +1 -0
- package/dist/kinship-translator/kinship-translator.js +103 -0
- package/dist/kinship-translator/patterns.de.d.ts +2 -0
- package/dist/kinship-translator/patterns.de.d.ts.map +1 -0
- package/dist/kinship-translator/patterns.de.js +14 -0
- package/dist/kinship-translator/patterns.en.d.ts +2 -0
- package/dist/kinship-translator/patterns.en.d.ts.map +1 -0
- package/dist/kinship-translator/patterns.en.js +14 -0
- package/dist/kinship-translator/patterns.es.d.ts +2 -0
- package/dist/kinship-translator/patterns.es.d.ts.map +1 -0
- package/dist/kinship-translator/patterns.es.js +14 -0
- package/dist/kinship-translator/patterns.fr.d.ts +2 -0
- package/dist/kinship-translator/patterns.fr.d.ts.map +1 -0
- package/dist/kinship-translator/patterns.fr.js +14 -0
- package/dist/kinship-translator/patterns.hu.d.ts +6 -0
- package/dist/kinship-translator/patterns.hu.d.ts.map +1 -0
- package/dist/kinship-translator/patterns.hu.js +97 -0
- package/dist/kinship-translator/translators.d.ts +6 -0
- package/dist/kinship-translator/translators.d.ts.map +1 -0
- package/dist/kinship-translator/translators.js +5 -0
- package/dist/kinship-translator/types.d.ts +9 -0
- package/dist/kinship-translator/types.d.ts.map +1 -0
- package/dist/kinship-translator/types.js +1 -0
- package/dist/structures/address.d.ts +14 -0
- package/dist/structures/address.d.ts.map +1 -0
- package/dist/structures/address.js +1 -0
- package/dist/structures/association.d.ts +13 -0
- package/dist/structures/association.d.ts.map +1 -0
- package/dist/structures/association.js +1 -0
- package/dist/structures/change-date.d.ts +8 -0
- package/dist/structures/change-date.d.ts.map +1 -0
- package/dist/structures/change-date.js +1 -0
- package/dist/structures/creation-date.d.ts +7 -0
- package/dist/structures/creation-date.d.ts.map +1 -0
- package/dist/structures/creation-date.js +1 -0
- package/dist/structures/date.d.ts +9 -0
- package/dist/structures/date.d.ts.map +1 -0
- package/dist/structures/date.js +1 -0
- package/dist/structures/event-detail-structure.d.ts +25 -0
- package/dist/structures/event-detail-structure.d.ts.map +1 -0
- package/dist/structures/event-detail-structure.js +1 -0
- package/dist/structures/family.d.ts +34 -0
- package/dist/structures/family.d.ts.map +1 -0
- package/dist/structures/family.js +1 -0
- package/dist/structures/gedcom.d.ts +60 -0
- package/dist/structures/gedcom.d.ts.map +1 -0
- package/dist/structures/gedcom.js +1 -0
- package/dist/structures/index.d.ts +25 -0
- package/dist/structures/index.d.ts.map +1 -0
- package/dist/structures/index.js +1 -0
- package/dist/structures/individual-event-detail-structure.d.ts +9 -0
- package/dist/structures/individual-event-detail-structure.d.ts.map +1 -0
- package/dist/structures/individual-event-detail-structure.js +1 -0
- package/dist/structures/individual-event-structure.d.ts +83 -0
- package/dist/structures/individual-event-structure.d.ts.map +1 -0
- package/dist/structures/individual-event-structure.js +1 -0
- package/dist/structures/individual.d.ts +40 -0
- package/dist/structures/individual.d.ts.map +1 -0
- package/dist/structures/individual.js +1 -0
- package/dist/structures/lds-ordinance-detail.d.ts +17 -0
- package/dist/structures/lds-ordinance-detail.d.ts.map +1 -0
- package/dist/structures/lds-ordinance-detail.js +1 -0
- package/dist/structures/lds-spouse-sealing.d.ts +7 -0
- package/dist/structures/lds-spouse-sealing.d.ts.map +1 -0
- package/dist/structures/lds-spouse-sealing.js +1 -0
- package/dist/structures/marriage-date.d.ts +11 -0
- package/dist/structures/marriage-date.d.ts.map +1 -0
- package/dist/structures/marriage-date.js +1 -0
- package/dist/structures/multimedia-link.d.ts +16 -0
- package/dist/structures/multimedia-link.d.ts.map +1 -0
- package/dist/structures/multimedia-link.js +1 -0
- package/dist/structures/non-event.d.ts +12 -0
- package/dist/structures/non-event.d.ts.map +1 -0
- package/dist/structures/non-event.js +1 -0
- package/dist/structures/note.d.ts +16 -0
- package/dist/structures/note.d.ts.map +1 -0
- package/dist/structures/note.js +1 -0
- package/dist/structures/personal-name-pieces.d.ts +11 -0
- package/dist/structures/personal-name-pieces.d.ts.map +1 -0
- package/dist/structures/personal-name-pieces.js +1 -0
- package/dist/structures/personal-name.d.ts +16 -0
- package/dist/structures/personal-name.d.ts.map +1 -0
- package/dist/structures/personal-name.js +1 -0
- package/dist/structures/place.d.ts +20 -0
- package/dist/structures/place.d.ts.map +1 -0
- package/dist/structures/place.js +1 -0
- package/dist/structures/repository.d.ts +6 -0
- package/dist/structures/repository.d.ts.map +1 -0
- package/dist/structures/repository.js +1 -0
- package/dist/structures/source-citation.d.ts +27 -0
- package/dist/structures/source-citation.d.ts.map +1 -0
- package/dist/structures/source-citation.js +1 -0
- package/dist/structures/source-repository-citation.d.ts +13 -0
- package/dist/structures/source-repository-citation.d.ts.map +1 -0
- package/dist/structures/source-repository-citation.js +1 -0
- package/dist/structures/source.d.ts +28 -0
- package/dist/structures/source.d.ts.map +1 -0
- package/dist/structures/source.js +1 -0
- package/dist/types/ancestry-media.d.ts +65 -0
- package/dist/types/ancestry-media.d.ts.map +1 -0
- package/dist/types/ancestry-media.js +1 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +4 -0
- package/dist/types/settings.d.ts +12 -0
- package/dist/types/settings.d.ts.map +1 -0
- package/dist/types/settings.js +1 -0
- package/dist/types/types.d.ts +220 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/types.js +26 -0
- package/dist/utils/cache.d.ts +22 -0
- package/dist/utils/cache.d.ts.map +1 -0
- package/dist/utils/cache.js +57 -0
- package/dist/utils/common-creator.d.ts +13 -0
- package/dist/utils/common-creator.d.ts.map +1 -0
- package/dist/utils/common-creator.js +72 -0
- package/dist/utils/date-formatter.d.ts +35 -0
- package/dist/utils/date-formatter.d.ts.map +1 -0
- package/dist/utils/date-formatter.js +207 -0
- package/dist/utils/get-all-prop.d.ts +4 -0
- package/dist/utils/get-all-prop.d.ts.map +1 -0
- package/dist/utils/get-all-prop.js +5 -0
- package/dist/utils/get-family-with.d.ts +5 -0
- package/dist/utils/get-family-with.d.ts.map +1 -0
- package/dist/utils/get-family-with.js +11 -0
- package/dist/utils/get-places.d.ts +21 -0
- package/dist/utils/get-places.d.ts.map +1 -0
- package/dist/utils/get-places.js +77 -0
- package/dist/utils/get-product-details.d.ts +4 -0
- package/dist/utils/get-product-details.d.ts.map +1 -0
- package/dist/utils/get-product-details.js +6 -0
- package/dist/utils/get-raw-size.d.ts +2 -0
- package/dist/utils/get-raw-size.d.ts.map +1 -0
- package/dist/utils/get-raw-size.js +3 -0
- package/dist/utils/index.d.ts +17 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +18 -0
- package/dist/utils/logger.d.ts +3 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +11 -0
- package/dist/utils/name-formatter.d.ts +10 -0
- package/dist/utils/name-formatter.d.ts.map +1 -0
- package/dist/utils/name-formatter.js +45 -0
- package/dist/utils/nested-group.d.ts +4 -0
- package/dist/utils/nested-group.d.ts.map +1 -0
- package/dist/utils/nested-group.js +34 -0
- package/dist/utils/ordinalize.d.ts +3 -0
- package/dist/utils/ordinalize.d.ts.map +1 -0
- package/dist/utils/ordinalize.js +104 -0
- package/dist/utils/parser.d.ts +17 -0
- package/dist/utils/parser.d.ts.map +1 -0
- package/dist/utils/parser.js +322 -0
- package/dist/utils/place-parser.d.ts +16 -0
- package/dist/utils/place-parser.d.ts.map +1 -0
- package/dist/utils/place-parser.js +46 -0
- package/dist/utils/place-translator.d.ts +6 -0
- package/dist/utils/place-translator.d.ts.map +1 -0
- package/dist/utils/place-translator.js +8 -0
- package/dist/utils/place-types.d.ts +27 -0
- package/dist/utils/place-types.d.ts.map +1 -0
- package/dist/utils/place-types.js +14 -0
- package/dist/utils/range.d.ts +19 -0
- package/dist/utils/range.d.ts.map +1 -0
- package/dist/utils/range.js +265 -0
- package/package.json +153 -0
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
import { getVersion } from "../utils/get-product-details";
|
|
2
|
+
import { Common, createCommon } from "./common";
|
|
3
|
+
import { CustomTags } from "./indi";
|
|
4
|
+
import { List } from "./list";
|
|
5
|
+
export class GedCom extends Common {
|
|
6
|
+
constructor() {
|
|
7
|
+
super();
|
|
8
|
+
this.tagMembers = {};
|
|
9
|
+
this.reflist = {};
|
|
10
|
+
this.refcount = 0;
|
|
11
|
+
delete this._gedcom;
|
|
12
|
+
delete this.id;
|
|
13
|
+
this.removeValue();
|
|
14
|
+
}
|
|
15
|
+
getMain(type, index) {
|
|
16
|
+
const list = !type || type instanceof List ? type : this.getList(type);
|
|
17
|
+
if (!list) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
if (typeof index === "string") {
|
|
21
|
+
return list.item(index);
|
|
22
|
+
}
|
|
23
|
+
// const keyProbe: IdType[] = [
|
|
24
|
+
// `@I${index}@`,
|
|
25
|
+
// `@P${index}@`,
|
|
26
|
+
// `@XI${index}@`,
|
|
27
|
+
// `@XXI${index}@`,
|
|
28
|
+
// ];
|
|
29
|
+
// let itemProbe: T | undefined;
|
|
30
|
+
// keyProbe.find((key) => {
|
|
31
|
+
// const i = list.item(key);
|
|
32
|
+
// if (i) {
|
|
33
|
+
// itemProbe = i as T;
|
|
34
|
+
// return true;
|
|
35
|
+
// }
|
|
36
|
+
// return false;
|
|
37
|
+
// });
|
|
38
|
+
// if (itemProbe) {
|
|
39
|
+
// return itemProbe as T;
|
|
40
|
+
// }
|
|
41
|
+
const keys = list.keys();
|
|
42
|
+
return list.item(keys[index]);
|
|
43
|
+
}
|
|
44
|
+
getList(type) {
|
|
45
|
+
return this.get(type);
|
|
46
|
+
}
|
|
47
|
+
indis() {
|
|
48
|
+
return this.getList("@@INDI");
|
|
49
|
+
}
|
|
50
|
+
cloneIndis(target, source, avoidKeys = [], removeFromOriginalList = true) {
|
|
51
|
+
const hasFAMS = avoidKeys.includes("FAMS");
|
|
52
|
+
const targetIndi = typeof target === "string" ? this.indi(target) : target;
|
|
53
|
+
const sourceIndi = typeof source === "string" ? this.indi(source) : source;
|
|
54
|
+
if (!targetIndi || !sourceIndi) {
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
57
|
+
const spousesFamily = hasFAMS ? sourceIndi.FAMS?.toList() : undefined;
|
|
58
|
+
const childrenFamily = sourceIndi.FAMC?.toList();
|
|
59
|
+
const cloned = targetIndi.clone(false, avoidKeys);
|
|
60
|
+
const newCloned = sourceIndi.merge(cloned);
|
|
61
|
+
newCloned.cloneOf = targetIndi.id;
|
|
62
|
+
targetIndi.clonedBy = newCloned.id;
|
|
63
|
+
if (newCloned.id) {
|
|
64
|
+
this.getList("@@INDI")?.item(newCloned.id, newCloned);
|
|
65
|
+
if (childrenFamily?.length) {
|
|
66
|
+
childrenFamily.forEach((fam) => {
|
|
67
|
+
if (!fam.ref) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const newChild = createCommon(this, undefined, fam.ref);
|
|
71
|
+
newChild.value = newCloned.id;
|
|
72
|
+
fam.ref.assign("CHIL", newChild, true);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
if (spousesFamily?.length) {
|
|
76
|
+
spousesFamily.forEach((fam) => {
|
|
77
|
+
if (!fam.ref) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const newSpouse = createCommon(this, undefined, fam.ref);
|
|
81
|
+
newSpouse.value = newCloned.id;
|
|
82
|
+
if (newCloned.isMale()) {
|
|
83
|
+
fam.ref.assign("HUSB", newSpouse, true);
|
|
84
|
+
}
|
|
85
|
+
else if (newCloned.isFemale()) {
|
|
86
|
+
fam.ref.assign("WIFE", newSpouse, true);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
if (removeFromOriginalList &&
|
|
91
|
+
newCloned.type &&
|
|
92
|
+
newCloned.type !== targetIndi.type) {
|
|
93
|
+
this.getList(`@@${newCloned.type}`)?.removeItem(newCloned.id);
|
|
94
|
+
}
|
|
95
|
+
newCloned.type = "INDI";
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
mergeIndis(target, source, removeFromOriginalList = true) {
|
|
99
|
+
const targetIndi = typeof target === "string" ? this.indi(target) : target;
|
|
100
|
+
const sourceIndi = typeof source === "string" ? this.indi(source) : source;
|
|
101
|
+
if (!targetIndi || !sourceIndi) {
|
|
102
|
+
return this;
|
|
103
|
+
}
|
|
104
|
+
const sourceIndiId = sourceIndi.id;
|
|
105
|
+
const spousesFamily = sourceIndi.FAMS?.toList();
|
|
106
|
+
const childrenFamily = sourceIndi.FAMC?.toList();
|
|
107
|
+
const newLinked = targetIndi.merge(sourceIndi);
|
|
108
|
+
const mergedId = newLinked.id;
|
|
109
|
+
if (sourceIndiId && (spousesFamily?.length || childrenFamily?.length)) {
|
|
110
|
+
if (childrenFamily?.length && mergedId) {
|
|
111
|
+
childrenFamily.forEach((fam) => {
|
|
112
|
+
if (!fam.ref) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const newChild = createCommon(this, undefined, fam.ref);
|
|
116
|
+
newChild.value = mergedId;
|
|
117
|
+
fam.ref.assign("CHIL", newChild, true);
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
if (spousesFamily?.length && mergedId) {
|
|
121
|
+
spousesFamily.forEach((fam) => {
|
|
122
|
+
if (!fam.ref) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const newSpouse = createCommon(this, undefined, fam.ref);
|
|
126
|
+
newSpouse.value = mergedId;
|
|
127
|
+
if (newLinked?.isMale()) {
|
|
128
|
+
fam.ref.assign("HUSB", newSpouse, true);
|
|
129
|
+
}
|
|
130
|
+
else if (newLinked?.isFemale()) {
|
|
131
|
+
fam.ref.assign("WIFE", newSpouse, true);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (removeFromOriginalList && sourceIndi?.type && sourceIndi.id) {
|
|
137
|
+
this.getList(`@@${sourceIndi.type}`)?.removeItem(sourceIndi.id);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
fams() {
|
|
141
|
+
return this.getList("@@FAM");
|
|
142
|
+
}
|
|
143
|
+
objes() {
|
|
144
|
+
return this.getList("@@OBJE");
|
|
145
|
+
}
|
|
146
|
+
sours() {
|
|
147
|
+
return this.getList("@@SOUR");
|
|
148
|
+
}
|
|
149
|
+
repos() {
|
|
150
|
+
return this.getList("@@REPO");
|
|
151
|
+
}
|
|
152
|
+
subms() {
|
|
153
|
+
return this.getList("@@SUBM");
|
|
154
|
+
}
|
|
155
|
+
tags() {
|
|
156
|
+
return this.getList("@@_MTTAG");
|
|
157
|
+
}
|
|
158
|
+
customTags() {
|
|
159
|
+
return this.getList("@@_MTTAG")?.filter((tag) => {
|
|
160
|
+
return tag?.get("_MTCAT.NAME")?.toValue() === "Custom";
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
indi(index) {
|
|
164
|
+
return this.getMain(this.indis(), index);
|
|
165
|
+
}
|
|
166
|
+
fam(index) {
|
|
167
|
+
return this.getMain(this.fams(), index);
|
|
168
|
+
}
|
|
169
|
+
obje(index) {
|
|
170
|
+
return this.getMain(this.objes(), index);
|
|
171
|
+
}
|
|
172
|
+
sour(index) {
|
|
173
|
+
return this.getMain(this.sours(), index);
|
|
174
|
+
}
|
|
175
|
+
repo(index) {
|
|
176
|
+
return this.getMain(this.repos(), index);
|
|
177
|
+
}
|
|
178
|
+
subm(index) {
|
|
179
|
+
return this.getMain(this.subms(), index);
|
|
180
|
+
}
|
|
181
|
+
tag(index) {
|
|
182
|
+
return this.getMain(this.tags(), index);
|
|
183
|
+
}
|
|
184
|
+
fromList(id) {
|
|
185
|
+
return id ? this.reflist?.[id] : undefined;
|
|
186
|
+
}
|
|
187
|
+
tagByName(name) {
|
|
188
|
+
return this.tags()?.find((tag) => {
|
|
189
|
+
const tagName = tag?.get("NAME")?.toValue();
|
|
190
|
+
return tagName === name;
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
customTag(index) {
|
|
194
|
+
return this.getMain(this.customTags(), index);
|
|
195
|
+
}
|
|
196
|
+
getIndiRelatedLists(indis) {
|
|
197
|
+
const refs = {};
|
|
198
|
+
const individuals = this.indis()?.filter((indi, indiKey) => {
|
|
199
|
+
if (indis.includes(indiKey)) {
|
|
200
|
+
indi.getRefs()
|
|
201
|
+
?.values()
|
|
202
|
+
?.forEach((ref) => {
|
|
203
|
+
const refKey = ref?.value;
|
|
204
|
+
if (ref && refKey && !refs[refKey]) {
|
|
205
|
+
refs[refKey] = ref;
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
return true;
|
|
209
|
+
}
|
|
210
|
+
return false;
|
|
211
|
+
});
|
|
212
|
+
const usedLists = Object.entries(this).filter(([prop, list]) => {
|
|
213
|
+
return (prop !== "@@INDI" &&
|
|
214
|
+
prop.startsWith("@@") &&
|
|
215
|
+
list instanceof List);
|
|
216
|
+
});
|
|
217
|
+
const lists = {};
|
|
218
|
+
if (individuals) {
|
|
219
|
+
lists["@@INDI"] = individuals;
|
|
220
|
+
}
|
|
221
|
+
usedLists.forEach(([key, list]) => {
|
|
222
|
+
const validKey = key;
|
|
223
|
+
if (list) {
|
|
224
|
+
lists[validKey] = list.filter((item) => {
|
|
225
|
+
return Boolean(item.id && refs[item.id]);
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
return lists;
|
|
230
|
+
}
|
|
231
|
+
getDownloadHeader() {
|
|
232
|
+
const newHead = createCommon();
|
|
233
|
+
Object.assign(newHead, this.get("HEAD") ?? {});
|
|
234
|
+
const newSour = createCommon();
|
|
235
|
+
newSour.set("CORP", createCommon());
|
|
236
|
+
newSour.set("CORP.WWW", createCommon());
|
|
237
|
+
newSour.set("NAME", createCommon());
|
|
238
|
+
newSour.set("VERS", createCommon());
|
|
239
|
+
newSour.CORP.value = "TreeViz - The Family Tree Visualiser";
|
|
240
|
+
newSour.CORP.WWW.value = "treeviz.com";
|
|
241
|
+
newSour.NAME.value = "TreeViz - The Family Tree Visualiser";
|
|
242
|
+
newSour.VERS.value = getVersion();
|
|
243
|
+
newHead.set("SOUR", newSour);
|
|
244
|
+
return newHead;
|
|
245
|
+
}
|
|
246
|
+
toFiltered(indis) {
|
|
247
|
+
if (!indis.length) {
|
|
248
|
+
return this;
|
|
249
|
+
}
|
|
250
|
+
const newGedcom = createGedCom();
|
|
251
|
+
const newContent = this.getIndiRelatedLists(indis);
|
|
252
|
+
Object.assign(newGedcom, this, newContent, {
|
|
253
|
+
HEAD: this.getDownloadHeader(),
|
|
254
|
+
});
|
|
255
|
+
return newGedcom;
|
|
256
|
+
}
|
|
257
|
+
toJson(tag, options) {
|
|
258
|
+
if (!options?.indis?.length) {
|
|
259
|
+
return super.toJson(tag, options);
|
|
260
|
+
}
|
|
261
|
+
const newGedcom = createGedCom();
|
|
262
|
+
const newContent = this.getIndiRelatedLists(options.indis);
|
|
263
|
+
Object.assign(newGedcom, this, newContent, {
|
|
264
|
+
HEAD: this.getDownloadHeader(),
|
|
265
|
+
});
|
|
266
|
+
delete options.indis;
|
|
267
|
+
return newGedcom.toJson(tag, options);
|
|
268
|
+
}
|
|
269
|
+
toGedcom(tag, level, options) {
|
|
270
|
+
if (options?.super) {
|
|
271
|
+
return super.toGedcom(tag, level, options);
|
|
272
|
+
}
|
|
273
|
+
const newGedcom = createGedCom();
|
|
274
|
+
if (!options?.original) {
|
|
275
|
+
Object.assign(newGedcom, {
|
|
276
|
+
HEAD: this.getDownloadHeader(),
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
Object.assign(newGedcom, this);
|
|
280
|
+
if (options?.indis?.length) {
|
|
281
|
+
const newContent = this.getIndiRelatedLists(options.indis);
|
|
282
|
+
Object.assign(newGedcom, newContent);
|
|
283
|
+
}
|
|
284
|
+
return newGedcom.toGedcom(tag, level, { ...options, super: true });
|
|
285
|
+
}
|
|
286
|
+
hasTag(tag) {
|
|
287
|
+
const tagName = typeof tag === "string"
|
|
288
|
+
? tag
|
|
289
|
+
: tag?.get("NAME")?.toValue();
|
|
290
|
+
if (!tagName) {
|
|
291
|
+
return false;
|
|
292
|
+
}
|
|
293
|
+
return !!this.tagMembers?.[tagName]?.indis?.length;
|
|
294
|
+
}
|
|
295
|
+
hasUnknownAncestor() {
|
|
296
|
+
return !!this.tagMembers?.[CustomTags.UnknownAncestor]?.indis?.length;
|
|
297
|
+
}
|
|
298
|
+
hasIgnoredMember() {
|
|
299
|
+
return !!this.tagMembers?.[CustomTags.IgnoredMember]?.indis?.length;
|
|
300
|
+
}
|
|
301
|
+
hasUnattachedMember() {
|
|
302
|
+
return !!this.tagMembers?.[CustomTags.UnattachedMember]?.indis?.length;
|
|
303
|
+
}
|
|
304
|
+
hasUnknownGivenname() {
|
|
305
|
+
return !!this.tagMembers?.[CustomTags.UnknownGivenname]?.indis?.length;
|
|
306
|
+
}
|
|
307
|
+
hasUnknownSurname() {
|
|
308
|
+
return !!this.tagMembers?.[CustomTags.UnknownSurname]?.indis?.length;
|
|
309
|
+
}
|
|
310
|
+
hasNonRelevant() {
|
|
311
|
+
return this.hasUnknownAncestor() || this.hasUnattachedMember();
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Get all places from the GEDCOM with occurrence counts
|
|
315
|
+
* @returns Record mapping place names to their occurrence count
|
|
316
|
+
*/
|
|
317
|
+
getAllPlaces() {
|
|
318
|
+
const indis = this.indis();
|
|
319
|
+
const allPlaces = {};
|
|
320
|
+
indis?.forEach((indi) => {
|
|
321
|
+
if (!indi.id)
|
|
322
|
+
return;
|
|
323
|
+
const places = indi.getPlaces();
|
|
324
|
+
places.forEach((placeObj) => {
|
|
325
|
+
const placeName = placeObj?.place;
|
|
326
|
+
if (placeName && typeof placeName === "string") {
|
|
327
|
+
allPlaces[placeName] = (allPlaces[placeName] || 0) + 1;
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
});
|
|
331
|
+
return allPlaces;
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Get all places from the GEDCOM with associated individual IDs
|
|
335
|
+
* @param usedIndis Optional array of individual IDs to filter by
|
|
336
|
+
* @returns Record mapping place names to arrays of individual IDs
|
|
337
|
+
*/
|
|
338
|
+
getAllPlacesWithIndis(usedIndis = []) {
|
|
339
|
+
const indis = this.indis();
|
|
340
|
+
const allPlaces = {};
|
|
341
|
+
indis?.forEach((indi) => {
|
|
342
|
+
if (!indi.id ||
|
|
343
|
+
(usedIndis.length && !usedIndis.includes(indi.id))) {
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
const places = indi.getPlaces();
|
|
347
|
+
places.forEach((placeObj) => {
|
|
348
|
+
const placeName = placeObj?.place;
|
|
349
|
+
if (placeName && typeof placeName === "string" && indi.id) {
|
|
350
|
+
if (!allPlaces[placeName]) {
|
|
351
|
+
allPlaces[placeName] = [];
|
|
352
|
+
}
|
|
353
|
+
allPlaces[placeName].push(indi.id);
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
});
|
|
357
|
+
return allPlaces;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
export const createGedCom = () => {
|
|
361
|
+
return new GedCom();
|
|
362
|
+
};
|
|
363
|
+
export const isGedcomString = (gedcomString) => {
|
|
364
|
+
return (typeof gedcomString === "string" &&
|
|
365
|
+
gedcomString[0] === "0" &&
|
|
366
|
+
gedcomString
|
|
367
|
+
.split("\n")
|
|
368
|
+
.slice(0, 1000)
|
|
369
|
+
.every((l) => !l || /^\d+\s+/.test(l)));
|
|
370
|
+
};
|
|
371
|
+
/**
|
|
372
|
+
* Validates if a string is a valid GEDCOM file content
|
|
373
|
+
* @param content - The file content to validate
|
|
374
|
+
* @returns An object with `valid` boolean and optional `error` message
|
|
375
|
+
*/
|
|
376
|
+
export const validateGedcomContent = (content) => {
|
|
377
|
+
if (!content) {
|
|
378
|
+
return { valid: false, error: "File is empty" };
|
|
379
|
+
}
|
|
380
|
+
const trimmedContent = content.trim();
|
|
381
|
+
if (!trimmedContent) {
|
|
382
|
+
return { valid: false, error: "File is empty" };
|
|
383
|
+
}
|
|
384
|
+
// Check for common binary file signatures
|
|
385
|
+
const firstBytes = trimmedContent.substring(0, 10);
|
|
386
|
+
const isBinary = firstBytes.startsWith("\x89PNG") || // PNG
|
|
387
|
+
firstBytes.startsWith("\xFF\xD8\xFF") || // JPEG
|
|
388
|
+
firstBytes.startsWith("GIF8") || // GIF
|
|
389
|
+
firstBytes.startsWith("BM") || // BMP
|
|
390
|
+
firstBytes.startsWith("PK") || // ZIP
|
|
391
|
+
firstBytes.startsWith("%PDF") || // PDF
|
|
392
|
+
// eslint-disable-next-line no-control-regex
|
|
393
|
+
/[\x00-\x08\x0E-\x1F]/.test(firstBytes); // Other binary content
|
|
394
|
+
if (isBinary) {
|
|
395
|
+
return {
|
|
396
|
+
valid: false,
|
|
397
|
+
error: "File appears to be a binary file (image, PDF, etc.), not a GEDCOM text file",
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
// Check if content starts with GEDCOM header
|
|
401
|
+
// GEDCOM files must start with "0 HEAD" or "0 head" (case-insensitive)
|
|
402
|
+
const startsWithHeader = /^0\s+(HEAD|head)/i.test(trimmedContent);
|
|
403
|
+
if (!startsWithHeader) {
|
|
404
|
+
return {
|
|
405
|
+
valid: false,
|
|
406
|
+
error: "Invalid GEDCOM file format. File must start with '0 HEAD' record",
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Turning this off, because it's invalidating multiline gedcom property
|
|
411
|
+
* (I know these kind of GEDCOMs are not standard, but need to allow any user files)
|
|
412
|
+
**/
|
|
413
|
+
// Additional check using the existing isGedcomString logic
|
|
414
|
+
// if (!isGedcomString(trimmedContent)) {
|
|
415
|
+
// return {
|
|
416
|
+
// valid: false,
|
|
417
|
+
// error: "Invalid GEDCOM file format. File contains invalid line formats",
|
|
418
|
+
// };
|
|
419
|
+
// }
|
|
420
|
+
return { valid: true };
|
|
421
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export * from "./common";
|
|
2
|
+
export * from "./date";
|
|
3
|
+
export * from "./fam";
|
|
4
|
+
export * from "./fams";
|
|
5
|
+
export * from "./gedcom";
|
|
6
|
+
export * from "./indi";
|
|
7
|
+
export * from "./indis";
|
|
8
|
+
export * from "./list";
|
|
9
|
+
export * from "./name";
|
|
10
|
+
export * from "./note";
|
|
11
|
+
export * from "./obje";
|
|
12
|
+
export * from "./objes";
|
|
13
|
+
export * from "./repo";
|
|
14
|
+
export * from "./repos";
|
|
15
|
+
export * from "./sour";
|
|
16
|
+
export * from "./sours";
|
|
17
|
+
export * from "./subm";
|
|
18
|
+
export * from "./subms";
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/classes/index.ts"],"names":[],"mappings":"AACA,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,OAAO,CAAC;AACtB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Classes exports - barrel file for easier imports
|
|
2
|
+
export * from "./common";
|
|
3
|
+
export * from "./date";
|
|
4
|
+
export * from "./fam";
|
|
5
|
+
export * from "./fams";
|
|
6
|
+
export * from "./gedcom";
|
|
7
|
+
export * from "./indi";
|
|
8
|
+
export * from "./indis";
|
|
9
|
+
export * from "./list";
|
|
10
|
+
export * from "./name";
|
|
11
|
+
export * from "./note";
|
|
12
|
+
export * from "./obje";
|
|
13
|
+
export * from "./objes";
|
|
14
|
+
export * from "./repo";
|
|
15
|
+
export * from "./repos";
|
|
16
|
+
export * from "./sour";
|
|
17
|
+
export * from "./sours";
|
|
18
|
+
export * from "./subm";
|
|
19
|
+
export * from "./subms";
|