@treeviz/gedcom-parser 2.0.10 → 2.0.12

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.
Files changed (40) hide show
  1. package/dist/classes/common.d.ts +6 -1
  2. package/dist/classes/common.d.ts.map +1 -1
  3. package/dist/classes/fam.d.ts +9 -1
  4. package/dist/classes/fam.d.ts.map +1 -1
  5. package/dist/classes/gedcom.d.ts +6 -2
  6. package/dist/classes/gedcom.d.ts.map +1 -1
  7. package/dist/classes/index.js +495 -50
  8. package/dist/classes/indi.d.ts +6 -0
  9. package/dist/classes/indi.d.ts.map +1 -1
  10. package/dist/cli/index.js +3383 -2932
  11. package/dist/constants/constants.d.ts +7 -0
  12. package/dist/constants/constants.d.ts.map +1 -1
  13. package/dist/constants/index.js +1287 -916
  14. package/dist/factories/index.js +409 -39
  15. package/dist/index.d.ts +2 -0
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +5327 -4777
  18. package/dist/interfaces/fam.d.ts +7 -1
  19. package/dist/interfaces/fam.d.ts.map +1 -1
  20. package/dist/interfaces/gedcom.d.ts +4 -0
  21. package/dist/interfaces/gedcom.d.ts.map +1 -1
  22. package/dist/interfaces/indi.d.ts +5 -1
  23. package/dist/interfaces/indi.d.ts.map +1 -1
  24. package/dist/kinship-translator/index.js +409 -39
  25. package/dist/structures/gedcom.d.ts +1 -0
  26. package/dist/structures/gedcom.d.ts.map +1 -1
  27. package/dist/types/types.d.ts +10 -0
  28. package/dist/types/types.d.ts.map +1 -1
  29. package/dist/utils/fact-edit.d.ts +22 -0
  30. package/dist/utils/fact-edit.d.ts.map +1 -0
  31. package/dist/utils/family-edit.d.ts +23 -0
  32. package/dist/utils/family-edit.d.ts.map +1 -0
  33. package/dist/utils/gedcom-trailer.d.ts +6 -0
  34. package/dist/utils/gedcom-trailer.d.ts.map +1 -0
  35. package/dist/utils/index.d.ts +4 -1
  36. package/dist/utils/index.d.ts.map +1 -1
  37. package/dist/utils/index.js +605 -55
  38. package/dist/utils/parser.d.ts +3 -0
  39. package/dist/utils/parser.d.ts.map +1 -1
  40. package/package.json +1 -1
@@ -343,6 +343,11 @@ var inRange = (year, range, trueIfNoYear = false) => {
343
343
  // src/constants/constants.ts
344
344
  var ID_REG = /^@[_a-zA-Z0-9]+@/;
345
345
  var ID_GETTER_REG = /^(?<at>@)?(?<letter>[A-Z])?/i;
346
+ var ORIG_HEAD_TAG = "_ORIGHEAD";
347
+
348
+ // src/utils/gedcom-trailer.ts
349
+ var GEDCOM_TRAILER_TAG = "TRLR";
350
+ var isGedcomTrailerTag = (tag) => tag === GEDCOM_TRAILER_TAG;
346
351
  var List = class _List {
347
352
  // length = 0;
348
353
  constructor(items) {
@@ -853,6 +858,9 @@ var Common = class _Common {
853
858
  delete this._value;
854
859
  }
855
860
  set(name, value) {
861
+ if (isGedcomTrailerTag(name)) {
862
+ return void 0;
863
+ }
856
864
  if (typeof value === "string") {
857
865
  const usedValue = createCommon(this._gedcom, void 0, this.main);
858
866
  usedValue.value = value;
@@ -863,6 +871,9 @@ var Common = class _Common {
863
871
  return get(this, name);
864
872
  }
865
873
  assign(name, value, unique = false) {
874
+ if (isGedcomTrailerTag(name)) {
875
+ return void 0;
876
+ }
866
877
  let curValue = this.get(name);
867
878
  if (curValue?.isListable) {
868
879
  if (curValue instanceof _Common) {
@@ -1085,30 +1096,47 @@ var Common = class _Common {
1085
1096
  });
1086
1097
  return gedcom;
1087
1098
  }
1099
+ getHeadRecord() {
1100
+ return get(this, "HEAD") || get(this.getGedcom(), "HEAD");
1101
+ }
1102
+ getOriginalHeadRecord() {
1103
+ return get(this, ORIG_HEAD_TAG) || get(this.getGedcom(), ORIG_HEAD_TAG) || get(this.getHeadRecord(), ORIG_HEAD_TAG);
1104
+ }
1105
+ getSourceHeads() {
1106
+ const heads = [this.getOriginalHeadRecord(), this.getHeadRecord()];
1107
+ return heads.filter((head, index) => {
1108
+ return Boolean(head && heads.indexOf(head) === index);
1109
+ });
1110
+ }
1111
+ getFromSourceHeads(path) {
1112
+ for (const head of this.getSourceHeads()) {
1113
+ const value = get(head, path);
1114
+ if (value !== void 0 && value !== null && value !== "") {
1115
+ return value;
1116
+ }
1117
+ }
1118
+ return void 0;
1119
+ }
1120
+ sourStartsWith(prefix) {
1121
+ return this.getSourceHeads().some((head) => {
1122
+ const sour = get(head, "SOUR.value");
1123
+ return !!sour?.toLowerCase()?.startsWith(prefix);
1124
+ });
1125
+ }
1088
1126
  isGenoPro() {
1089
- const head = get(this, "HEAD") || get(this.getGedcom(), "HEAD");
1090
- const sour = get(head, "SOUR.value");
1091
- return !!sour?.toLowerCase()?.startsWith("genopro");
1127
+ return this.sourStartsWith("genopro");
1092
1128
  }
1093
1129
  isAhnenblatt() {
1094
- const head = get(this, "HEAD") || get(this.getGedcom(), "HEAD");
1095
- const sour = get(head, "SOUR.value");
1096
- return !!sour?.toLowerCase()?.startsWith("ahnenblatt");
1130
+ return this.sourStartsWith("ahnenblatt");
1097
1131
  }
1098
1132
  isGeni() {
1099
- const head = get(this, "HEAD") || get(this.getGedcom(), "HEAD");
1100
- const sour = get(head, "SOUR.value");
1101
- return !!sour?.toLowerCase()?.startsWith("geni");
1133
+ return this.sourStartsWith("geni");
1102
1134
  }
1103
1135
  isAncestry() {
1104
- const head = get(this, "HEAD") || get(this.getGedcom(), "HEAD");
1105
- const sour = get(head, "SOUR.value");
1106
- return !!sour?.toLowerCase()?.startsWith("ancestry");
1136
+ return this.sourStartsWith("ancestry");
1107
1137
  }
1108
1138
  isMyHeritage() {
1109
- const head = get(this, "HEAD") || get(this.getGedcom(), "HEAD");
1110
- const sour = get(head, "SOUR.value");
1111
- return !!sour?.toLowerCase()?.startsWith("myheritage");
1139
+ return this.sourStartsWith("myheritage");
1112
1140
  }
1113
1141
  /**
1114
1142
  * Get the source type as a string (for prefixing tree IDs and names)
@@ -1125,22 +1153,22 @@ var Common = class _Common {
1125
1153
  return void 0;
1126
1154
  }
1127
1155
  isFamilySearch() {
1128
- const head = get(this, "HEAD") || get(this.getGedcom(), "HEAD");
1129
- const sourName = get(head, "SOUR.NAME.value");
1130
- return sourName === "FamilySearch API";
1156
+ return this.getSourceHeads().some((head) => {
1157
+ const sourName = get(head, "SOUR.NAME.value");
1158
+ return sourName === "FamilySearch API";
1159
+ });
1131
1160
  }
1132
1161
  isGNO2GED() {
1133
- const head = get(this, "HEAD") || get(this.getGedcom(), "HEAD");
1134
- const sour = get(head, "SOUR.value");
1135
- return sour === "GNO2GED";
1162
+ return this.getSourceHeads().some((head) => {
1163
+ const sour = get(head, "SOUR.value");
1164
+ return sour === "GNO2GED";
1165
+ });
1136
1166
  }
1137
1167
  getAncestryTreeId() {
1138
- const path = "HEAD.SOUR._TREE.RIN.value";
1139
- return get(this, path) || get(this.getGedcom(), path);
1168
+ return this.getFromSourceHeads("SOUR._TREE.RIN.value") || (get(this, "HEAD.SOUR._TREE.RIN.value") || get(this.getGedcom(), "HEAD.SOUR._TREE.RIN.value"));
1140
1169
  }
1141
1170
  getMyHeritageTreeId() {
1142
- const path = "HEAD._EXPORTED_FROM_SITE_ID.value";
1143
- return get(this, path) || get(this.getGedcom(), path);
1171
+ return this.getFromSourceHeads("_EXPORTED_FROM_SITE_ID.value") || (get(this, "HEAD._EXPORTED_FROM_SITE_ID.value") || get(this.getGedcom(), "HEAD._EXPORTED_FROM_SITE_ID.value"));
1144
1172
  }
1145
1173
  getTreeId() {
1146
1174
  if (this?.isAncestry()) {
@@ -1174,8 +1202,7 @@ var Common = class _Common {
1174
1202
  return this.getUniversalTreeId();
1175
1203
  }
1176
1204
  getAncestryTreeName() {
1177
- const path = "HEAD.SOUR._TREE.value";
1178
- return get(this, path) || get(this.getGedcom(), path);
1205
+ return this.getFromSourceHeads("SOUR._TREE.value") || (get(this, "HEAD.SOUR._TREE.value") || get(this.getGedcom(), "HEAD.SOUR._TREE.value"));
1179
1206
  }
1180
1207
  getMyHeritageTreeName() {
1181
1208
  const path = "HEAD.FILE.value";
@@ -1185,14 +1212,14 @@ var Common = class _Common {
1185
1212
  )?.groups?.tree;
1186
1213
  }
1187
1214
  getFamilySearchTreeId() {
1188
- const rin = get(this, "HEAD.SOUR._TREE.RIN.value") || get(this.getGedcom(), "HEAD.SOUR._TREE.RIN.value");
1215
+ const rin = this.getFromSourceHeads("SOUR._TREE.RIN.value") || get(this, "HEAD.SOUR._TREE.RIN.value") || get(this.getGedcom(), "HEAD.SOUR._TREE.RIN.value");
1189
1216
  if (rin) {
1190
1217
  return rin;
1191
1218
  }
1192
1219
  return "familysearch";
1193
1220
  }
1194
1221
  getFamilySearchTreeName() {
1195
- const treeName = get(this, "HEAD.SOUR._TREE.value") || get(this.getGedcom(), "HEAD.SOUR._TREE.value");
1222
+ const treeName = this.getFromSourceHeads("SOUR._TREE.value") || get(this, "HEAD.SOUR._TREE.value") || get(this.getGedcom(), "HEAD.SOUR._TREE.value");
1196
1223
  if (treeName) {
1197
1224
  return treeName;
1198
1225
  }
@@ -1284,11 +1311,11 @@ var Common = class _Common {
1284
1311
  const cleanName = fileName.replace(/\.ged$/i, "").replace(/_/g, " ");
1285
1312
  return `${prefix}${cleanName}`;
1286
1313
  }
1287
- const sourName = get(this, "HEAD.SOUR.NAME.value") || get(this.getGedcom(), "HEAD.SOUR.NAME.value");
1314
+ const sourName = this.getFromSourceHeads("SOUR.NAME.value") || get(this, "HEAD.SOUR.NAME.value") || get(this.getGedcom(), "HEAD.SOUR.NAME.value");
1288
1315
  if (sourName) {
1289
1316
  return `${prefix}${sourName}`;
1290
1317
  }
1291
- const sourValue = get(this, "HEAD.SOUR.value") || get(this.getGedcom(), "HEAD.SOUR.value");
1318
+ const sourValue = this.getFromSourceHeads("SOUR.value") || get(this, "HEAD.SOUR.value") || get(this.getGedcom(), "HEAD.SOUR.value");
1292
1319
  if (sourValue) {
1293
1320
  return `${prefix}${sourValue}`;
1294
1321
  }
@@ -1354,7 +1381,7 @@ var isOnlyMainProp = (key) => {
1354
1381
  };
1355
1382
  var isValidKey = (common, key) => {
1356
1383
  const prop = get(common, key);
1357
- return key !== "_gedcom" && key !== "_main" && key !== "_parent" && key !== "_uniqueId" && key !== "_refs" && key !== "_type" && (key === "id" || key === "_id" || key === "value" || key === "_value" || prop instanceof Common || prop instanceof List);
1384
+ return key !== "_gedcom" && key !== "_main" && key !== "_parent" && key !== "_uniqueId" && key !== "_refs" && key !== "_type" && !(typeof key === "string" && isGedcomTrailerTag(key)) && (key === "id" || key === "_id" || key === "value" || key === "_value" || prop instanceof Common || prop instanceof List);
1358
1385
  };
1359
1386
  var getValidKeys = (common) => {
1360
1387
  return Object.keys(common).filter((key) => {
@@ -2029,6 +2056,239 @@ var cacheDiscoveredPath = (gedcom, path) => {
2029
2056
  }
2030
2057
  };
2031
2058
 
2059
+ // src/utils/fact-edit.ts
2060
+ var SINGLETON_TAGS = /* @__PURE__ */ new Set(["BIRT", "DEAT", "SSN", "SEX", "DSCR"]);
2061
+ var firstRecord = (node) => {
2062
+ if (!node) {
2063
+ return void 0;
2064
+ }
2065
+ if (node instanceof List) {
2066
+ return node.index(0);
2067
+ }
2068
+ return node.index(0) ?? node;
2069
+ };
2070
+ var setDateOn = (gedcom, owner, parent, date) => {
2071
+ const trimmed = date.trim();
2072
+ if (!trimmed) {
2073
+ return;
2074
+ }
2075
+ let dateNode = parent.get("DATE");
2076
+ if (!dateNode || dateNode instanceof List) {
2077
+ dateNode = createCommonDate(gedcom, void 0, owner, parent);
2078
+ dateNode.type = "DATE";
2079
+ parent.set("DATE", dateNode);
2080
+ }
2081
+ dateNode.value = trimmed;
2082
+ };
2083
+ var fillFact = (gedcom, owner, event, input) => {
2084
+ if (input.value?.trim()) {
2085
+ event.value = input.value.trim();
2086
+ }
2087
+ if (input.type?.trim()) {
2088
+ event.set("TYPE", input.type.trim());
2089
+ }
2090
+ if (input.date) {
2091
+ setDateOn(gedcom, owner, event, input.date);
2092
+ }
2093
+ if (input.place?.trim()) {
2094
+ event.set("PLAC", input.place.trim());
2095
+ }
2096
+ if (input.note?.trim()) {
2097
+ event.set("NOTE", input.note.trim());
2098
+ }
2099
+ };
2100
+ var addIndividualFact = (indi, input) => {
2101
+ const gedcom = indi.getGedcom();
2102
+ if (!gedcom) {
2103
+ return void 0;
2104
+ }
2105
+ const tag = input.tag;
2106
+ let event = SINGLETON_TAGS.has(tag) ? firstRecord(indi.get(tag)) : void 0;
2107
+ if (!event) {
2108
+ event = createCommon(gedcom, void 0, indi);
2109
+ event.type = tag;
2110
+ if (SINGLETON_TAGS.has(tag)) {
2111
+ indi.set(tag, event);
2112
+ } else {
2113
+ indi.assign(tag, event);
2114
+ }
2115
+ }
2116
+ fillFact(gedcom, indi, event, input);
2117
+ return event;
2118
+ };
2119
+ var addFamilyFact = (fam, input) => {
2120
+ const gedcom = fam.getGedcom();
2121
+ if (!gedcom) {
2122
+ return void 0;
2123
+ }
2124
+ const event = createCommon(gedcom, void 0, fam);
2125
+ event.type = input.tag;
2126
+ fam.assign(input.tag, event);
2127
+ fillFact(gedcom, fam, event, input);
2128
+ return event;
2129
+ };
2130
+
2131
+ // src/utils/family-edit.ts
2132
+ var PEDIGREE_VALUES = [
2133
+ "birth" /* BIRTH */,
2134
+ "adopted" /* ADOPTED */,
2135
+ "foster" /* FOSTER */,
2136
+ "step" /* STEP */,
2137
+ "sealing" /* SEALING */
2138
+ ];
2139
+ var toGedcomPedigree = (value) => {
2140
+ const normalized = String(value || "birth" /* BIRTH */).toLowerCase();
2141
+ if (normalized === "biological" /* BIOLOGICAL */ || normalized === "birth" /* BIRTH */) {
2142
+ return "birth" /* BIRTH */;
2143
+ }
2144
+ const match = PEDIGREE_VALUES.find((item) => item === normalized);
2145
+ return match ?? "birth" /* BIRTH */;
2146
+ };
2147
+ var pointerIds = (tag) => {
2148
+ if (!tag) {
2149
+ return [];
2150
+ }
2151
+ if (tag instanceof List) {
2152
+ return tag.values().map((item) => item?.toValue?.()).filter((value2) => !!value2);
2153
+ }
2154
+ const value = tag.toValue?.();
2155
+ return value ? [String(value)] : [];
2156
+ };
2157
+ var firstPointerId = (tag) => pointerIds(tag)[0];
2158
+ var makePointer = (gedcom, parent, value, refType) => {
2159
+ const pointer = createCommon(gedcom, void 0, parent);
2160
+ pointer.value = value;
2161
+ pointer.refType = refType;
2162
+ return pointer;
2163
+ };
2164
+ var familyHasParent = (fam, indiId) => pointerIds(fam.get("HUSB")).includes(indiId) || pointerIds(fam.get("WIFE")).includes(indiId);
2165
+ var familyHasChild = (fam, indiId) => pointerIds(fam.get("CHIL")).includes(indiId);
2166
+ var spouseTagFor = (indi, fam) => {
2167
+ const husbId = firstPointerId(fam.get("HUSB"));
2168
+ const wifeId = firstPointerId(fam.get("WIFE"));
2169
+ if (husbId === indi.id) {
2170
+ return "HUSB";
2171
+ }
2172
+ if (wifeId === indi.id) {
2173
+ return "WIFE";
2174
+ }
2175
+ if (indi.isFemale()) {
2176
+ return wifeId && wifeId !== indi.id ? "HUSB" : "WIFE";
2177
+ }
2178
+ if (indi.isMale()) {
2179
+ return husbId && husbId !== indi.id ? "WIFE" : "HUSB";
2180
+ }
2181
+ return husbId ? "WIFE" : "HUSB";
2182
+ };
2183
+ var canAttachAsSpouse = (fam, indi) => {
2184
+ if (!indi.id) {
2185
+ return false;
2186
+ }
2187
+ if (familyHasParent(fam, indi.id)) {
2188
+ return true;
2189
+ }
2190
+ const tag = spouseTagFor(indi, fam);
2191
+ const occupied = firstPointerId(fam.get(tag));
2192
+ return !occupied || occupied === indi.id;
2193
+ };
2194
+ var pointerByValue = (tag, id) => {
2195
+ if (!tag) {
2196
+ return void 0;
2197
+ }
2198
+ const fromValues = tag.toValueList?.().item(id);
2199
+ if (fromValues) {
2200
+ return fromValues;
2201
+ }
2202
+ return tag.toList()?.values().find((item) => item?.toValue?.() === id);
2203
+ };
2204
+ var setChildPedigree = (fam, child, pedigree, parent) => {
2205
+ if (!fam.id || !child.id) {
2206
+ return;
2207
+ }
2208
+ const pedi = toGedcomPedigree(pedigree);
2209
+ const famc = pointerByValue(child.get("FAMC"), fam.id);
2210
+ if (famc) {
2211
+ famc.set("PEDI", pedi);
2212
+ }
2213
+ const chil = pointerByValue(fam.get("CHIL"), child.id);
2214
+ if (!chil) {
2215
+ return;
2216
+ }
2217
+ const setFather = !parent || parent.isMale() || parent.isUnknownSex();
2218
+ const setMother = !parent || parent.isFemale() || parent.isUnknownSex();
2219
+ if (setFather) {
2220
+ chil.set("_FREL", pedi);
2221
+ }
2222
+ if (setMother) {
2223
+ chil.set("_MREL", pedi);
2224
+ }
2225
+ };
2226
+ var attachSpouseToFamily = (fam, indi) => {
2227
+ const gedcom = fam.getGedcom() ?? indi.getGedcom();
2228
+ if (!indi.id || !fam.id || !gedcom) {
2229
+ return false;
2230
+ }
2231
+ if (!canAttachAsSpouse(fam, indi)) {
2232
+ return false;
2233
+ }
2234
+ const tag = spouseTagFor(indi, fam);
2235
+ if (firstPointerId(fam.get(tag)) !== indi.id) {
2236
+ fam.set(tag, makePointer(gedcom, fam, indi.id, "INDI"));
2237
+ }
2238
+ indi.assign("FAMS", makePointer(gedcom, indi, fam.id, "FAM"), true);
2239
+ return true;
2240
+ };
2241
+ var attachChildToFamily = (fam, child, pedigree, parent) => {
2242
+ const gedcom = fam.getGedcom() ?? child.getGedcom();
2243
+ if (!child.id || !fam.id || !gedcom) {
2244
+ return false;
2245
+ }
2246
+ if (!familyHasChild(fam, child.id)) {
2247
+ fam.assign("CHIL", makePointer(gedcom, fam, child.id, "INDI"), true);
2248
+ }
2249
+ const existingFamc = pointerByValue(child.get("FAMC"), fam.id);
2250
+ if (!existingFamc) {
2251
+ child.assign("FAMC", makePointer(gedcom, child, fam.id, "FAM"), true);
2252
+ }
2253
+ setChildPedigree(fam, child, pedigree, parent);
2254
+ return true;
2255
+ };
2256
+ var findReusableParentChildFamily = (parent, child) => {
2257
+ if (!parent.id || !child.id) {
2258
+ return void 0;
2259
+ }
2260
+ let reusableFamc;
2261
+ let already = false;
2262
+ child.getFamilies("FAMC")?.forEach((fam) => {
2263
+ if (!fam) {
2264
+ return;
2265
+ }
2266
+ if (familyHasParent(fam, parent.id) && familyHasChild(fam, child.id)) {
2267
+ already = true;
2268
+ return;
2269
+ }
2270
+ if (!reusableFamc && canAttachAsSpouse(fam, parent)) {
2271
+ reusableFamc = fam;
2272
+ }
2273
+ });
2274
+ if (already) {
2275
+ return "already";
2276
+ }
2277
+ if (reusableFamc) {
2278
+ return reusableFamc;
2279
+ }
2280
+ const parentFams = [];
2281
+ parent.getFamilies("FAMS")?.forEach((fam) => {
2282
+ if (fam) {
2283
+ parentFams.push(fam);
2284
+ }
2285
+ });
2286
+ if (parentFams.length === 1) {
2287
+ return parentFams[0];
2288
+ }
2289
+ return void 0;
2290
+ };
2291
+
2032
2292
  // src/utils/get-places.ts
2033
2293
  var getPlaces = (common, type = ["ALL" /* All */], maxLevel = 1, level = 0, mainKey) => {
2034
2294
  const types = Array.isArray(type) ? type : [type];
@@ -2687,6 +2947,31 @@ var Fam = class extends Common {
2687
2947
  getParents() {
2688
2948
  return this.getHusband().copy().merge(this.getWife());
2689
2949
  }
2950
+ hasParent(indi) {
2951
+ const indiId = typeof indi === "string" ? indi : indi?.id;
2952
+ return !!indiId && familyHasParent(this, indiId);
2953
+ }
2954
+ hasChild(indi) {
2955
+ const indiId = typeof indi === "string" ? indi : indi?.id;
2956
+ return !!indiId && familyHasChild(this, indiId);
2957
+ }
2958
+ canAddSpouse(indi) {
2959
+ return canAttachAsSpouse(this, indi);
2960
+ }
2961
+ addSpouse(indi) {
2962
+ return attachSpouseToFamily(this, indi);
2963
+ }
2964
+ addChild(child, pedigree, parent) {
2965
+ return attachChildToFamily(
2966
+ this,
2967
+ child,
2968
+ pedigree,
2969
+ parent
2970
+ );
2971
+ }
2972
+ addFact(input) {
2973
+ return addFamilyFact(this, input);
2974
+ }
2690
2975
  toList() {
2691
2976
  return new Families().concat(
2692
2977
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -2787,19 +3072,51 @@ var ALLOWED_FACTS = [
2787
3072
  "OCCU",
2788
3073
  "OCCUPATIONS",
2789
3074
  "RESI",
3075
+ "BIRT",
3076
+ "DEAT",
2790
3077
  "BAPT",
3078
+ "BAPM",
2791
3079
  "CHRI",
2792
3080
  "CHR",
3081
+ "CHRA",
2793
3082
  "BURI",
2794
- "EDUC",
3083
+ "CREM",
3084
+ "ADOP",
3085
+ "BARM",
3086
+ "BASM",
3087
+ "BLES",
3088
+ "CONF",
3089
+ "FCOM",
3090
+ "ORDN",
3091
+ "NATU",
3092
+ "EMIG",
3093
+ "IMMI",
3094
+ "CENS",
3095
+ "PROB",
3096
+ "WILL",
2795
3097
  "GRAD",
3098
+ "RETI",
3099
+ "EDUC",
2796
3100
  "DIV",
2797
- "IMMI",
2798
3101
  "RELI",
3102
+ "CAST",
3103
+ "DSCR",
3104
+ "NATI",
3105
+ "PROP",
3106
+ "SSN",
3107
+ "TITL",
3108
+ "ADDR",
3109
+ "BAPL",
3110
+ "CONL",
3111
+ "ENDL",
3112
+ "SLGC",
2799
3113
  "_MILT",
2800
3114
  "_MILTID",
2801
3115
  "FACT",
2802
- "_ORIG"
3116
+ "_ORIG",
3117
+ "_WLNK",
3118
+ "WWW",
3119
+ "URL"
2803
3120
  ];
2804
3121
  var DISALLOWED_CUSTOM_FACTS = ["DNA Test", "Newspaper"];
2805
3122
  var CustomFactRenderers = {
@@ -3343,7 +3660,7 @@ var Indi = class extends Common {
3343
3660
  return result;
3344
3661
  }
3345
3662
  ancestryLink() {
3346
- const www = this._gedcom?.HEAD?.SOUR?.CORP?.WWW?.value;
3663
+ const www = this.getFromSourceHeads("SOUR.CORP.WWW.value") || this._gedcom?.HEAD?.SOUR?.CORP?.WWW?.value;
3347
3664
  const tree = this.getAncestryTreeId();
3348
3665
  if (this.id) {
3349
3666
  return `https://${www}/family-tree/person/tree/${tree}/person/${this.id.replace(
@@ -3355,7 +3672,7 @@ var Indi = class extends Common {
3355
3672
  async ancestryMedia(namespace) {
3356
3673
  const list = {};
3357
3674
  const objeList = this.get("OBJE")?.toList().copy();
3358
- const www = this._gedcom?.HEAD?.SOUR?.CORP?.WWW?.value;
3675
+ const www = this.getFromSourceHeads("SOUR.CORP.WWW.value") || this._gedcom?.HEAD?.SOUR?.CORP?.WWW?.value;
3359
3676
  const tree = this.getAncestryTreeId();
3360
3677
  if (objeList) {
3361
3678
  await Promise.all(
@@ -3415,7 +3732,7 @@ var Indi = class extends Common {
3415
3732
  return list;
3416
3733
  }
3417
3734
  myheritageLink(poolId = 0) {
3418
- const www = this._gedcom?.HEAD?.SOUR?.CORP?.value?.toLowerCase().replace(/^www\./gi, "");
3735
+ const www = (this.getFromSourceHeads("SOUR.CORP.value") || this._gedcom?.HEAD?.SOUR?.CORP?.value)?.toLowerCase().replace(/^www\./gi, "");
3419
3736
  const site = this.getMyHeritageTreeId();
3420
3737
  const file = this._gedcom?.HEAD?.get("FILE")?.toValue()?.match(/Exported by MyHeritage.com from .+ in (?<site>.+) on .+$/)?.groups?.site;
3421
3738
  const normalizedFile = file?.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase().replace(/[^a-z0-9]+/g, "-");
@@ -3936,6 +4253,57 @@ var Indi = class extends Common {
3936
4253
  isUnknownSex() {
3937
4254
  return !this.isMale() && !this.isFemale();
3938
4255
  }
4256
+ addSpouse(other) {
4257
+ if (!this.id || !other?.id || this.id === other.id || !this._gedcom) {
4258
+ return void 0;
4259
+ }
4260
+ const existing = getFamilyWith(this, other.id);
4261
+ if (existing) {
4262
+ return existing;
4263
+ }
4264
+ const fam = this._gedcom.createFamily();
4265
+ if (!fam.addSpouse(this) || !fam.addSpouse(other)) {
4266
+ return void 0;
4267
+ }
4268
+ return fam;
4269
+ }
4270
+ addChild(child, pedigree) {
4271
+ if (!this.id || !child?.id || this.id === child.id || !this._gedcom) {
4272
+ return void 0;
4273
+ }
4274
+ const existing = findReusableParentChildFamily(
4275
+ this,
4276
+ child
4277
+ );
4278
+ if (existing === "already") {
4279
+ const fam2 = child.getFamilies("FAMC")?.find(
4280
+ (item) => !!item && item.hasParent(this.id) && item.hasChild(child.id)
4281
+ );
4282
+ if (fam2) {
4283
+ setChildPedigree(
4284
+ fam2,
4285
+ child,
4286
+ pedigree,
4287
+ this
4288
+ );
4289
+ }
4290
+ return fam2;
4291
+ }
4292
+ const fam = existing ?? this._gedcom.createFamily();
4293
+ if (!fam.addSpouse(this)) {
4294
+ return void 0;
4295
+ }
4296
+ if (!fam.addChild(child, pedigree, this)) {
4297
+ return void 0;
4298
+ }
4299
+ return fam;
4300
+ }
4301
+ addParent(parent, pedigree) {
4302
+ return parent.addChild(this, pedigree);
4303
+ }
4304
+ addFact(input) {
4305
+ return addIndividualFact(this, input);
4306
+ }
3939
4307
  getParentType(id) {
3940
4308
  let indi;
3941
4309
  if (typeof id === "string" || typeof id === "number") {
@@ -4136,7 +4504,9 @@ var Indi = class extends Common {
4136
4504
  }
4137
4505
  }
4138
4506
  if (kinship !== "child" || !breakAfterSpouse) {
4139
- indi.getBiologicalFathers().copy().merge(indi.getBiologicalMothers()).merge(indi.getFathers().copy().merge(indi.getMothers())).forEach((relative) => {
4507
+ indi.getBiologicalFathers().copy().merge(indi.getBiologicalMothers()).merge(
4508
+ indi.getFathers().copy().merge(indi.getMothers())
4509
+ ).forEach((relative) => {
4140
4510
  if (!visited.has(relative)) {
4141
4511
  const currentRelation = indi.getParentType(relative);
4142
4512
  const isNonBiological = !!currentRelation && currentRelation !== "biological" /* BIOLOGICAL */;
package/dist/index.d.ts CHANGED
@@ -14,6 +14,8 @@ export { fromTuple, inRange, isIntersectedRange, splitRange, parseRangeBounds, i
14
14
  export * from "./utils/cache";
15
15
  export * from "./utils/common-creator";
16
16
  export * from "./utils/date-formatter";
17
+ export * from "./utils/family-edit";
18
+ export * from "./utils/fact-edit";
17
19
  export * from "./utils/get-all-prop";
18
20
  export * from "./utils/get-family-with";
19
21
  export * from "./utils/get-places";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAA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