gedcom-ts 1.1.0 → 1.1.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.
@@ -1,6 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class Act {
1
+ export class Act {
2
+ dateAct;
3
+ place;
4
+ act;
5
+ files;
4
6
  constructor(dateAct, place, act, files) {
5
7
  if (dateAct) {
6
8
  this.dateAct = dateAct;
@@ -16,4 +18,3 @@ class Act {
16
18
  }
17
19
  }
18
20
  }
19
- exports.Act = Act;
@@ -1,12 +1,15 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var TypeDateAct;
1
+ export var TypeDateAct;
4
2
  (function (TypeDateAct) {
5
3
  TypeDateAct["BEF"] = "BEF";
6
4
  TypeDateAct["ABT"] = "ABT";
7
5
  TypeDateAct["NULL"] = "NULL";
8
- })(TypeDateAct = exports.TypeDateAct || (exports.TypeDateAct = {}));
9
- class DateAct {
6
+ })(TypeDateAct || (TypeDateAct = {}));
7
+ export class DateAct {
8
+ typeDateAct;
9
+ day;
10
+ month;
11
+ year;
12
+ date;
10
13
  constructor(dateLine) {
11
14
  if (dateLine && dateLine !== 'inconnue') {
12
15
  const dateParts = dateLine.split(' ');
@@ -125,4 +128,3 @@ class DateAct {
125
128
  return new Date(year, month, day);
126
129
  }
127
130
  }
128
- exports.DateAct = DateAct;
@@ -1,6 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var Identificator;
1
+ export var Identificator;
4
2
  (function (Identificator) {
5
3
  Identificator["ABBR"] = "ABBR";
6
4
  Identificator["ADDR"] = "ADDR";
@@ -131,4 +129,4 @@ var Identificator;
131
129
  Identificator["VERS"] = "VERS";
132
130
  Identificator["WIFE"] = "WIFE";
133
131
  Identificator["WILL"] = "WILL";
134
- })(Identificator = exports.Identificator || (exports.Identificator = {}));
132
+ })(Identificator || (Identificator = {}));
@@ -1,15 +1,23 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const Act_1 = require("./Act");
4
- const Identificator_enum_1 = require("./Identificator.enum");
5
- const Utils_People_1 = require("./Utils-People");
6
- const DateAct_1 = require("./DateAct");
7
- var Sex;
1
+ import { Act } from './Act';
2
+ import { Identificator } from "./Identificator.enum";
3
+ import { findLinesConcernedByKeyword, findValueInLine } from "./Utils-People";
4
+ import { DateAct } from "./DateAct";
5
+ export var Sex;
8
6
  (function (Sex) {
9
7
  Sex["M"] = "M";
10
8
  Sex["F"] = "F";
11
- })(Sex = exports.Sex || (exports.Sex = {}));
12
- class People {
9
+ })(Sex || (Sex = {}));
10
+ export class People {
11
+ sosa;
12
+ sex;
13
+ firstnames;
14
+ lastname;
15
+ birth;
16
+ marriage;
17
+ death;
18
+ FAMC;
19
+ FAMS;
20
+ photo;
13
21
  constructor(sosa, sex, firstnames, lastname, birth, marriage, death, FAMC, FAMS, photo) {
14
22
  this.sosa = sosa;
15
23
  this.sex = sex;
@@ -28,8 +36,8 @@ class People {
28
36
  this.createSex(peoplesLinesWithoutCarriage);
29
37
  this.createFAM(peoplesLinesWithoutCarriage);
30
38
  this.createPhoto(peoplesLinesWithoutCarriage);
31
- this.birth = this.createBirthDeathAct(peoplesLinesWithoutCarriage, Identificator_enum_1.Identificator.BIRT);
32
- this.death = this.createBirthDeathAct(peoplesLinesWithoutCarriage, Identificator_enum_1.Identificator.DEAT);
39
+ this.birth = this.createBirthDeathAct(peoplesLinesWithoutCarriage, Identificator.BIRT);
40
+ this.death = this.createBirthDeathAct(peoplesLinesWithoutCarriage, Identificator.DEAT);
33
41
  }
34
42
  createFirstnamesAndLastnameJson(peopleLines) {
35
43
  let lineName = peopleLines.find((information) => information ? information.startsWith('1 NAME') : false);
@@ -41,22 +49,22 @@ class People {
41
49
  this.firstnames = lineName ? lineName.replace(new RegExp('"', 'g'), '').trim().split(' ') : null;
42
50
  }
43
51
  createSex(peopleLines) {
44
- this.sex = Utils_People_1.findValueInLine(peopleLines, '1 SEX ') === Sex.M ? Sex.M : Sex.F;
52
+ this.sex = findValueInLine(peopleLines, '1 SEX ') === Sex.M ? Sex.M : Sex.F;
45
53
  }
46
54
  // Enfant issu de la Famille (union de 2 parents)
47
55
  createFAM(peopleLines) {
48
56
  const numberPattern = /\d+/g;
49
- const famc = Utils_People_1.findValueInLine(peopleLines, '1 FAMC ');
57
+ const famc = findValueInLine(peopleLines, '1 FAMC ');
50
58
  if (famc) {
51
59
  this.FAMC = Number(famc.match(numberPattern));
52
60
  }
53
- const fams = Utils_People_1.findLinesConcernedByKeyword(peopleLines, '1 FAMS ').map(line => Number(line.match(numberPattern)));
54
- if ((fams === null || fams === void 0 ? void 0 : fams.length) > 0) {
55
- this.FAMS = (fams === null || fams === void 0 ? void 0 : fams.length) > 0 ? fams : [];
61
+ const fams = findLinesConcernedByKeyword(peopleLines, '1 FAMS ').map(line => Number(line.match(numberPattern)));
62
+ if (fams?.length > 0) {
63
+ this.FAMS = fams?.length > 0 ? fams : [];
56
64
  }
57
65
  }
58
66
  createPhoto(peopleLines) {
59
- const photoUrl = Utils_People_1.findValueInLine(peopleLines, '2 FILE ');
67
+ const photoUrl = findValueInLine(peopleLines, '2 FILE ');
60
68
  if (photoUrl) {
61
69
  this.photo = photoUrl;
62
70
  }
@@ -66,15 +74,15 @@ class People {
66
74
  const startArray = peopleLines.slice(idxBegin + 1);
67
75
  const idxEnd = startArray.findIndex((lineInformation) => lineInformation.startsWith('1 '));
68
76
  const finalArray = idxEnd >= 0 ? startArray.slice(0, idxEnd) : startArray;
69
- return new Act_1.Act(new DateAct_1.DateAct(Utils_People_1.findValueInLine(finalArray, '2 DATE ')), Utils_People_1.findValueInLine(finalArray, '2 PLAC '));
77
+ return new Act(new DateAct(findValueInLine(finalArray, '2 DATE ')), findValueInLine(finalArray, '2 PLAC '));
70
78
  }
71
79
  }
72
- exports.People = People;
73
- class TreePeople extends People {
80
+ export class TreePeople extends People {
81
+ parents;
82
+ childrens;
74
83
  constructor(people, parents, childrens, currentSosa) {
75
84
  super(currentSosa, people.sex, people.firstnames, people.lastname, people.birth, people.marriage, people.death, people.FAMC, people.FAMS);
76
85
  this.parents = parents;
77
86
  this.childrens = childrens;
78
87
  }
79
88
  }
80
- exports.TreePeople = TreePeople;
@@ -1,6 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class Place {
1
+ export class Place {
2
+ city;
3
+ zip;
4
+ county;
5
+ region;
6
+ country;
7
+ coordinate;
4
8
  constructor(city, zip, county, region, country, coordinate) {
5
9
  this.city = city;
6
10
  this.zip = zip;
@@ -10,11 +14,11 @@ class Place {
10
14
  this.coordinate = coordinate;
11
15
  }
12
16
  }
13
- exports.Place = Place;
14
- class CoordinateGPS {
17
+ export class CoordinateGPS {
18
+ latitude;
19
+ longitude;
15
20
  constructor(latitude, longitude) {
16
21
  this.latitude = latitude;
17
22
  this.longitude = longitude;
18
23
  }
19
24
  }
20
- exports.CoordinateGPS = CoordinateGPS;
@@ -1,6 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var Separators;
1
+ export var Separators;
4
2
  (function (Separators) {
5
3
  Separators["CARRIAGE_RETURN"] = "\n";
6
- })(Separators = exports.Separators || (exports.Separators = {}));
4
+ })(Separators || (Separators = {}));
@@ -1,10 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.findValueInLine = (lines, keyword) => {
1
+ export const findValueInLine = (lines, keyword) => {
4
2
  const line = lines.find((lineInformation) => lineInformation.startsWith(keyword));
5
3
  return line ? line.replace(keyword, '') : null;
6
4
  };
7
- exports.findLinesConcernedByKeyword = (lines, keyword) => {
5
+ export const findLinesConcernedByKeyword = (lines, keyword) => {
8
6
  return [...lines]
9
7
  .filter(line => line.startsWith(keyword))
10
8
  .map(line => line.replace(keyword, ''));
@@ -1,9 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const Separators_1 = require("../commons/Separators");
4
- const People_1 = require("../commons/People");
5
- const Identificator_enum_1 = require("../commons/Identificator.enum");
6
- class ExportFormatFile {
1
+ import { Separators } from '../commons/Separators';
2
+ import { Sex } from '../commons/People';
3
+ import { Identificator } from '../commons/Identificator.enum';
4
+ export class ExportFormatFile {
5
+ title;
6
+ extension;
7
7
  constructor(title) {
8
8
  this.title = title;
9
9
  }
@@ -14,15 +14,15 @@ class ExportFormatFile {
14
14
  link.click();
15
15
  }
16
16
  }
17
- exports.ExportFormatFile = ExportFormatFile;
18
- class GEDCOM extends ExportFormatFile {
17
+ export class GEDCOM extends ExportFormatFile {
18
+ peoples;
19
19
  constructor(title, peoples) {
20
20
  super(title);
21
21
  this.extension = '.ged';
22
22
  this.peoples = peoples;
23
23
  }
24
24
  get beginGedcom() {
25
- const cr = Separators_1.Separators.CARRIAGE_RETURN;
25
+ const cr = Separators.CARRIAGE_RETURN;
26
26
  const date = new Date();
27
27
  const options = { day: '2-digit', month: '2-digit', year: 'numeric' };
28
28
  const formattedTime = date.toLocaleTimeString('fr-FR');
@@ -47,11 +47,10 @@ class GEDCOM extends ExportFormatFile {
47
47
  }
48
48
  get contentGedcom() {
49
49
  let content = '';
50
- const cr = Separators_1.Separators.CARRIAGE_RETURN;
50
+ const cr = Separators.CARRIAGE_RETURN;
51
51
  if (this.peoples && this.peoples.length > 0) {
52
52
  this.peoples.forEach((people) => {
53
- var _a, _b, _c, _d, _e;
54
- const firstnames = (_a = people.firstnames) !== null && _a !== void 0 ? _a : [];
53
+ const firstnames = people.firstnames ?? [];
55
54
  const peopleLine = new PeopleLine(people.sosa, [...firstnames], people.lastname, people.FAMS, people.FAMC);
56
55
  // sosa
57
56
  content += peopleLine.indi;
@@ -66,20 +65,20 @@ class GEDCOM extends ExportFormatFile {
66
65
  // sex
67
66
  content += peopleLine.sex;
68
67
  // birth
69
- if (people.birth && (((_b = people.birth.dateAct) === null || _b === void 0 ? void 0 : _b.date) || people.birth.place)) {
70
- const actLine = new ActLine(Identificator_enum_1.Identificator.BIRT, people.birth);
68
+ if (people.birth && (people.birth.dateAct?.date || people.birth.place)) {
69
+ const actLine = new ActLine(Identificator.BIRT, people.birth);
71
70
  content += actLine.typeLine;
72
- if ((_c = people.birth.dateAct) === null || _c === void 0 ? void 0 : _c.date) {
71
+ if (people.birth.dateAct?.date) {
73
72
  content += actLine.dateLine;
74
73
  }
75
74
  if (people.birth.place) {
76
75
  content += actLine.placeLine;
77
76
  }
78
77
  }
79
- if (people.death && (((_d = people.death.dateAct) === null || _d === void 0 ? void 0 : _d.date) || people.death.place)) {
80
- const actLine = new ActLine(Identificator_enum_1.Identificator.DEAT, people.death);
78
+ if (people.death && (people.death.dateAct?.date || people.death.place)) {
79
+ const actLine = new ActLine(Identificator.DEAT, people.death);
81
80
  content += actLine.typeLine;
82
- if ((_e = people.death.dateAct) === null || _e === void 0 ? void 0 : _e.date) {
81
+ if (people.death.dateAct?.date) {
83
82
  content += actLine.dateLine;
84
83
  }
85
84
  if (people.death.place) {
@@ -92,25 +91,26 @@ class GEDCOM extends ExportFormatFile {
92
91
  return content;
93
92
  }
94
93
  download() {
95
- const ged = `data:text/ged;charset=utf-8,${this.beginGedcom}${this.contentGedcom}${Identificator_enum_1.Identificator.TRLR}`;
94
+ const ged = `data:text/ged;charset=utf-8,${this.beginGedcom}${this.contentGedcom}${Identificator.TRLR}`;
96
95
  const data = encodeURI(ged);
97
96
  this.export(data);
98
97
  }
99
98
  }
100
- exports.GEDCOM = GEDCOM;
101
- class LineGedcom {
102
- constructor() {
103
- this.cr = Separators_1.Separators.CARRIAGE_RETURN;
104
- }
99
+ export class LineGedcom {
100
+ cr = Separators.CARRIAGE_RETURN;
105
101
  }
106
- exports.LineGedcom = LineGedcom;
107
- class PeopleLine extends LineGedcom {
102
+ export class PeopleLine extends LineGedcom {
103
+ sosa;
104
+ fams;
105
+ famc;
106
+ firstnames;
107
+ lastnames;
108
108
  constructor(sosa, firstnames, lastnames, fams, famc) {
109
109
  super();
110
110
  this.sosa = sosa;
111
111
  this.firstnames = firstnames;
112
- this.lastnames = lastnames !== null && lastnames !== void 0 ? lastnames : '';
113
- this.fams = (fams === null || fams === void 0 ? void 0 : fams.length) > 0 ? fams : [];
112
+ this.lastnames = lastnames ?? '';
113
+ this.fams = fams?.length > 0 ? fams : [];
114
114
  if (famc) {
115
115
  this.famc = famc;
116
116
  }
@@ -151,13 +151,14 @@ class PeopleLine extends LineGedcom {
151
151
  }
152
152
  get sex() {
153
153
  if (this.sosa) {
154
- return `1 SEX ${this.sosa === 1 || this.sosa % 2 ? People_1.Sex.F : People_1.Sex.M}${this.cr}`;
154
+ return `1 SEX ${this.sosa === 1 || this.sosa % 2 ? Sex.F : Sex.M}${this.cr}`;
155
155
  }
156
156
  return '';
157
157
  }
158
158
  }
159
- exports.PeopleLine = PeopleLine;
160
- class ActLine extends LineGedcom {
159
+ export class ActLine extends LineGedcom {
160
+ type;
161
+ act;
161
162
  constructor(type, act) {
162
163
  super();
163
164
  this.type = type;
@@ -167,17 +168,15 @@ class ActLine extends LineGedcom {
167
168
  return `1 ${this.type}${this.cr}`;
168
169
  }
169
170
  get dateLine() {
170
- var _a, _b;
171
- if ((_b = (_a = this.act) === null || _a === void 0 ? void 0 : _a.dateAct) === null || _b === void 0 ? void 0 : _b.date) {
171
+ if (this.act?.dateAct?.date) {
172
172
  const options = { day: '2-digit', month: 'short', year: 'numeric' };
173
- return `2 ${Identificator_enum_1.Identificator.DATE} ${this.formatDate(this.act.dateAct)}${this.cr}`;
173
+ return `2 ${Identificator.DATE} ${this.formatDate(this.act.dateAct)}${this.cr}`;
174
174
  }
175
175
  return '';
176
176
  }
177
177
  get placeLine() {
178
- var _a, _b;
179
- if (((_b = (_a = this.act) === null || _a === void 0 ? void 0 : _a.place) === null || _b === void 0 ? void 0 : _b.length) > 0) {
180
- return `2 ${Identificator_enum_1.Identificator.PLAC} ${this.act.place}${this.cr}`;
178
+ if (this.act?.place?.length > 0) {
179
+ return `2 ${Identificator.PLAC} ${this.act.place}${this.cr}`;
181
180
  }
182
181
  return '';
183
182
  }
@@ -188,4 +187,3 @@ class ActLine extends LineGedcom {
188
187
  return '';
189
188
  }
190
189
  }
191
- exports.ActLine = ActLine;
@@ -1,7 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const People_1 = require("../commons/People");
4
- class ReadGed {
1
+ import { People, Sex } from '../commons/People';
2
+ export class ReadGed {
3
+ gedcom;
4
+ peoples;
5
+ partnersMap;
6
+ childsMap;
5
7
  constructor(gedcom) {
6
8
  this.gedcom = gedcom;
7
9
  this.peoples = this.import();
@@ -36,8 +38,7 @@ class ReadGed {
36
38
  }
37
39
  groupPartners() {
38
40
  [...this.peoples].forEach(people => {
39
- var _a;
40
- if (((_a = people.FAMS) === null || _a === void 0 ? void 0 : _a.length) > 0) {
41
+ if (people.FAMS?.length > 0) {
41
42
  people.FAMS.forEach(oneFams => {
42
43
  let partners = [people];
43
44
  if (this.partnersMap.has(oneFams)) {
@@ -61,7 +62,7 @@ class ReadGed {
61
62
  }
62
63
  haveParentsOfPeople(people, directAncestries, sosaChild) {
63
64
  const copyPeople = Object.assign({}, people);
64
- copyPeople.sosa = !sosaChild ? 1 : (sosaChild * 2) + (people.sex === People_1.Sex.F ? 1 : 0);
65
+ copyPeople.sosa = !sosaChild ? 1 : (sosaChild * 2) + (people.sex === Sex.F ? 1 : 0);
65
66
  if (this.partnersMap.has(copyPeople.FAMC)) {
66
67
  const parents = [...this.partnersMap.get(copyPeople.FAMC)];
67
68
  if (parents && parents.length > 0) {
@@ -74,14 +75,13 @@ class ReadGed {
74
75
  return directAncestries;
75
76
  }
76
77
  }
77
- exports.ReadGed = ReadGed;
78
- class Create {
78
+ export class Create {
79
79
  static json(peoplesFile, marriagesFile) {
80
80
  if (peoplesFile && peoplesFile.length > 0) {
81
81
  return peoplesFile
82
82
  .map((peopleFile) => {
83
83
  const peopleLines = peopleFile.split('\n');
84
- const newPeopleJson = new People_1.People();
84
+ const newPeopleJson = new People();
85
85
  newPeopleJson.createPeopleJson(peopleLines);
86
86
  return newPeopleJson;
87
87
  })
@@ -90,4 +90,3 @@ class Create {
90
90
  return null;
91
91
  }
92
92
  }
93
- exports.Create = Create;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { People } from "./commons/People";
1
+ export { People, Sex } from "./commons/People";
2
2
  export { Act } from "./commons/Act";
3
3
  export { Place } from "./commons/Place";
4
4
  export { Identificator } from "./commons/Identificator.enum";
package/dist/index.js CHANGED
@@ -1,14 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var People_1 = require("./commons/People");
4
- exports.People = People_1.People;
5
- var Act_1 = require("./commons/Act");
6
- exports.Act = Act_1.Act;
7
- var Place_1 = require("./commons/Place");
8
- exports.Place = Place_1.Place;
9
- var Identificator_enum_1 = require("./commons/Identificator.enum");
10
- exports.Identificator = Identificator_enum_1.Identificator;
11
- var GEDCOM_1 = require("./export/GEDCOM");
12
- exports.GEDCOM = GEDCOM_1.GEDCOM;
13
- var ReadGed_1 = require("./import/ReadGed");
14
- exports.ReadGed = ReadGed_1.ReadGed;
1
+ export { People, Sex } from "./commons/People";
2
+ export { Act } from "./commons/Act";
3
+ export { Place } from "./commons/Place";
4
+ export { Identificator } from "./commons/Identificator.enum";
5
+ export { GEDCOM } from "./export/GEDCOM";
6
+ export { ReadGed } from "./import/ReadGed";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gedcom-ts",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "A TypeScript library to create genealogy tree data model and to import/export data in a GEDCOM file (.ged).",
5
5
  "author": "Bertrand Jaunet <bertrand.jaunet@gmail.com>",
6
6
  "license": "proprietary",
@@ -11,11 +11,11 @@
11
11
  "test": "jest"
12
12
  },
13
13
  "devDependencies": {
14
- "@types/jest": "^25.1.3",
15
- "@types/node": "^13.9.0",
16
- "jest": "^25.1.0",
17
- "ts-jest": "^25.2.1",
18
- "typescript": "^3.8.3"
14
+ "@types/jest": "^29.5.2",
15
+ "@types/node": "^20.3.1",
16
+ "jest": "^29.5.0",
17
+ "ts-jest": "^29.1.0",
18
+ "typescript": "^5.1.3"
19
19
  },
20
20
  "keywords": [
21
21
  "genealogy",
@@ -1,6 +0,0 @@
1
- export declare class ConvertStringToDate {
2
- private monthMapping;
3
- private dateString;
4
- constructor(dateString: string);
5
- get toDate(): Date | undefined;
6
- }
@@ -1,43 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class ConvertStringToDate {
4
- constructor(dateString) {
5
- this.monthMapping = {
6
- JAN: 0,
7
- FEB: 1,
8
- MAR: 2,
9
- APR: 3,
10
- MAY: 4,
11
- JUN: 5,
12
- JUL: 6,
13
- AUG: 7,
14
- SEP: 8,
15
- OCT: 9,
16
- NOV: 10,
17
- DEC: 11
18
- };
19
- this.dateString = dateString;
20
- }
21
- get toDate() {
22
- const regex = /^(\w+\s)?(\d{1,2})?\s?([A-Za-z]+)?\s?(\d{4})?$/;
23
- const match = this.dateString.match(regex);
24
- if (match) {
25
- const prefix = match[1];
26
- const day = match[1];
27
- const monthStr = match[3];
28
- const year = match[4];
29
- console.log(match);
30
- if (year) {
31
- if (monthStr) {
32
- if (day) {
33
- return new Date(parseInt(year), this.monthMapping[monthStr], parseInt(day));
34
- }
35
- return new Date(parseInt(year), this.monthMapping[monthStr], 1);
36
- }
37
- return new Date(parseInt(year), 0, 1);
38
- }
39
- }
40
- return undefined;
41
- }
42
- }
43
- exports.ConvertStringToDate = ConvertStringToDate;
@@ -1,2 +0,0 @@
1
- export declare class Utils {
2
- }
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class Utils {
4
- }
5
- exports.Utils = Utils;