@treeviz/gedcom-parser 1.0.5 → 1.0.7

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.
@@ -1,3 +1,4 @@
1
+ import type { Locale } from "date-fns";
1
2
  import type { IdType, MultiTag } from "../types/types";
2
3
  import type { Range } from "../utils/range";
3
4
  import { Common } from "./common";
@@ -17,7 +18,7 @@ export declare class CommonDate extends Common<string> {
17
18
  assign<T extends Common | List = Common | List>(name: MultiTag, value: T, unique?: boolean): T;
18
19
  private isValidDateFormat;
19
20
  toNote(short?: boolean): string | undefined;
20
- toValue(dateFormat?: string): string | undefined;
21
+ toValue(dateFormat?: string, locale?: Locale): string | undefined;
21
22
  exportValue(): string;
22
23
  inRange(range: Range, trueIfNoYear?: boolean): boolean;
23
24
  }
@@ -1 +1 @@
1
- {"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../../src/classes/date.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAGvD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAE5C,OAAO,EAAE,MAAM,EAA6B,MAAM,UAAU,CAAC;AAC7D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,UAAU,CAAC;AACzC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAiDnC,qBAAa,UAAW,SAAQ,MAAM,CAAC,MAAM,CAAC;IAC7C,OAAO,CAAC,KAAK,CAAC,CAAO;IAErB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;gBAGb,MAAM,CAAC,EAAE,UAAU,EACnB,EAAE,CAAC,EAAE,MAAM,EACX,I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C,qBAAa,UAAW,SAAQ,MAAM,CAAC,MAAM,CAAC;IAC7C,OAAO,CAAC,KAAK,CAAC,CAAO;IAErB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;gBAGb,MAAM,CAAC,EAAE,UAAU,EACnB,EAAE,CAAC,EAAE,MAAM,EACX,IAAI,CAAC,EAAE,MAAM,EACb,MAAM,CAAC,EAAE,MAAM;IAOhB,IAAI,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,EA0ElC;IAED,IAAI,KAAK,IA5EQ,MAAM,GAAG,SAAS,CA+FlC;IAED,IAAI,QAAQ,SAEX;IAED,MAAM,CAAC,CAAC,SAAS,MAAM,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,EAC7C,IAAI,EAAE,QAAQ,EACd,KAAK,EAAE,CAAC,EACR,MAAM,UAAQ;IAUf,OAAO,CAAC,iBAAiB;IAgBzB,MAAM,CAAC,KAAK,UAAO,GAAG,MAAM,GAAG,SAAS;IAUxC,OAAO,CAAC,UAAU,SAAgB,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAuBxE,WAAW;IAIX,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,YAAY,UAAQ;CAG1C;AAED,eAAO,MAAM,gBAAgB,GAC5B,SAAS,UAAU,EACnB,KAAK,MAAM,EACX,OAAO,MAAM,EACb,SAAS,MAAM,KACb,aAAa,CAAC,UAAU,CAI1B,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,QAAQ,OAAO,KAAG,KAAK,IAAI,UAOvD,CAAC"}
@@ -1,4 +1,5 @@
1
1
  import { format, isValid, parse } from "date-fns";
2
+ import { enUS } from "date-fns/locale";
2
3
  import { getDateLocale } from "../factories/index.js";
3
4
  import { ACCEPTED_DATE_FORMATS } from "../utils/date-formatter.js";
4
5
  import { inRange } from "../utils/range.js";
@@ -12,7 +13,7 @@ const NOTE_MARKER = "####";
12
13
  /**
13
14
  * Format a date based on available components (DAY, MONTH, YEAR, NOTE)
14
15
  */
15
- const formatDateWithComponents = (date, hasDay, hasMonth, hasYear, noteValue, baseFormat = "dd MMM yyyy") => {
16
+ const formatDateWithComponents = (date, hasDay, hasMonth, hasYear, noteValue, baseFormat = "dd MMM yyyy", locale) => {
16
17
  const hasNote = baseFormat.includes("NOTE");
17
18
  let validDateFormat = baseFormat.replace("NOTE", NOTE_MARKER);
18
19
  if (!hasDay) {
@@ -28,7 +29,7 @@ const formatDateWithComponents = (date, hasDay, hasMonth, hasYear, noteValue, ba
28
29
  .replace(/([.\-\s/])\1+/g, "$1")
29
30
  .replace(/^[.\-\s/]+|[.\-\s/]+$/g, "");
30
31
  const formattedDate = format(date, validDateFormat, {
31
- locale: getDateLocale(),
32
+ locale: locale ? locale : getDateLocale(),
32
33
  });
33
34
  // Add NOTE prefix if it exists
34
35
  return noteValue && hasNote
@@ -147,7 +148,7 @@ export class CommonDate extends Common {
147
148
  }
148
149
  return note;
149
150
  }
150
- toValue(dateFormat = "dd MMM yyyy") {
151
+ toValue(dateFormat = "dd MMM yyyy", locale) {
151
152
  const hasDay = !!this.DAY?.value;
152
153
  const hasMonth = !!this.MONTH?.value;
153
154
  const hasYear = !!this.YEAR?.value;
@@ -156,10 +157,10 @@ export class CommonDate extends Common {
156
157
  (!hasDay && !hasMonth && !hasYear)) {
157
158
  return this._value;
158
159
  }
159
- return formatDateWithComponents(this._date, hasDay, hasMonth, hasYear, this.NOTE?.value, dateFormat);
160
+ return formatDateWithComponents(this._date, hasDay, hasMonth, hasYear, this.NOTE?.value, dateFormat, locale);
160
161
  }
161
162
  exportValue() {
162
- return this.toValue("NOTE dd MMM yyyy");
163
+ return this.toValue("NOTE dd MMM yyyy", enUS);
163
164
  }
164
165
  inRange(range, trueIfNoYear = false) {
165
166
  return inRange(this.YEAR?.value, range, trueIfNoYear);
@@ -729,17 +729,16 @@ export const mergeGedcoms = (targetGedcom, sourceGedcom, strategy = "id") => {
729
729
  ...targetChildIds,
730
730
  ]).size;
731
731
  // Match if:
732
- // 1. Both have no children, OR
732
+ // 1. At least one spouse is present (to avoid matching empty families), OR
733
733
  // 2. At least 50% of children overlap
734
- if (totalUniqueChildren === 0 ||
735
- childOverlap / totalUniqueChildren >= 0.5) {
736
- // Additionally require at least one spouse to be present (not both empty)
737
- if (finalHusbId ||
738
- finalWifeId ||
739
- targetHusbId ||
740
- targetWifeId) {
741
- matchedTargetFam = targetFam;
742
- }
734
+ const hasSpouses = finalHusbId ||
735
+ finalWifeId ||
736
+ targetHusbId ||
737
+ targetWifeId;
738
+ const hasMatchingChildren = totalUniqueChildren > 0 &&
739
+ childOverlap / totalUniqueChildren >= 0.5;
740
+ if (hasSpouses || hasMatchingChildren) {
741
+ matchedTargetFam = targetFam;
743
742
  }
744
743
  }
745
744
  });
@@ -799,7 +798,7 @@ export const mergeGedcoms = (targetGedcom, sourceGedcom, strategy = "id") => {
799
798
  if (!sourceIndi)
800
799
  return;
801
800
  // Clear and rebuild FAMS references with remapped IDs
802
- // clonedIndi.delete("FAMS");
801
+ clonedIndi.remove("FAMS");
803
802
  const sourceFAMS = sourceIndi.FAMS?.toList();
804
803
  sourceFAMS?.forEach((famRef) => {
805
804
  const oldFamId = famRef.value;
@@ -813,7 +812,7 @@ export const mergeGedcoms = (targetGedcom, sourceGedcom, strategy = "id") => {
813
812
  }
814
813
  });
815
814
  // Clear and rebuild FAMC references with remapped IDs
816
- // clonedIndi.delete("FAMC");
815
+ clonedIndi.remove("FAMC");
817
816
  const sourceFAMC = sourceIndi.FAMC?.toList();
818
817
  sourceFAMC?.forEach((famRef) => {
819
818
  const oldFamId = famRef.value;
@@ -853,7 +852,7 @@ export const mergeGedcoms = (targetGedcom, sourceGedcom, strategy = "id") => {
853
852
  }
854
853
  }
855
854
  // Update CHIL references
856
- // clonedFam.delete("CHIL");
855
+ clonedFam.remove("CHIL");
857
856
  const sourceChildren = sourceFam.CHIL?.toList();
858
857
  sourceChildren?.forEach((childRef) => {
859
858
  const oldChildId = childRef.value;
@@ -875,7 +874,9 @@ export const mergeGedcoms = (targetGedcom, sourceGedcom, strategy = "id") => {
875
874
  const targetIndi = mergedGedcom.indis()?.item(matchedTargetId);
876
875
  if (targetIndi) {
877
876
  // Merge without overriding existing data
878
- targetIndi.merge(clonedIndi, false);
877
+ // If using a strategy field (not "id"), avoid merging that field since it's already the same
878
+ const avoidKeys = strategy !== "id" ? [strategy] : [];
879
+ targetIndi.merge(clonedIndi, false, avoidKeys);
879
880
  }
880
881
  }
881
882
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@treeviz/gedcom-parser",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "Lightweight, pluggable GEDCOM parser for JavaScript/TypeScript with optional caching and place matching. Zero browser dependencies.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",