gedcom.json 1.0.8 → 1.0.10

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 (68) hide show
  1. package/README.md +246 -256
  2. package/dist/ToJSON/console.js +15 -12
  3. package/dist/ToJSON/console.js.map +1 -1
  4. package/dist/ToJSON/models/DefinitionCache.js.map +1 -1
  5. package/dist/ToJSON/models/LineParsingResult.js.map +1 -1
  6. package/dist/ToJSON/models/ParsedLine.js +1 -1
  7. package/dist/ToJSON/models/ParsedLine.js.map +1 -1
  8. package/dist/ToJSON/models/Parsing.js +8 -6
  9. package/dist/ToJSON/models/Parsing.js.map +1 -1
  10. package/dist/ToJSON/models/ParsingObject.js.map +1 -1
  11. package/dist/ToJSON/models/ParsingOptions.js.map +1 -1
  12. package/dist/ToJSON/models/ParsingPath.js.map +1 -1
  13. package/dist/ToJSON/models/ParsingResult.js.map +1 -1
  14. package/dist/ToJSON/models/StatisticLine.js.map +1 -1
  15. package/dist/ToJSON/models/Statistics.js +2 -2
  16. package/dist/ToJSON/models/Statistics.js.map +1 -1
  17. package/dist/ToJSON/models/Store.js +11 -11
  18. package/dist/ToJSON/models/Store.js.map +1 -1
  19. package/dist/ToJSON/models/TagDefinition.js +11 -11
  20. package/dist/ToJSON/models/TagDefinition.js.map +1 -1
  21. package/dist/ToJSON/parsing/lineHelper.js +8 -8
  22. package/dist/ToJSON/parsing/lineHelper.js.map +1 -1
  23. package/dist/ToJSON/parsing/lineValidation.js +6 -6
  24. package/dist/ToJSON/parsing/lineValidation.js.map +1 -1
  25. package/dist/ToJSON/parsing/parseDate.js +84 -84
  26. package/dist/ToJSON/parsing/parseDate.js.map +1 -1
  27. package/dist/ToJSON/parsing/parseLine.js +8 -8
  28. package/dist/ToJSON/parsing/parseLine.js.map +1 -1
  29. package/dist/ToJSON/parsing/parsing.js +17 -17
  30. package/dist/ToJSON/parsing/parsing.js.map +1 -1
  31. package/dist/ToJSON/parsing/processLine.js +18 -18
  32. package/dist/ToJSON/parsing/processLine.js.map +1 -1
  33. package/dist/ToJSON/processing/manipulateValues.js +9 -10
  34. package/dist/ToJSON/processing/manipulateValues.js.map +1 -1
  35. package/dist/ToJSON/processing/result.js +87 -80
  36. package/dist/ToJSON/processing/result.js.map +1 -1
  37. package/dist/common.js +5 -5
  38. package/dist/common.js.map +1 -1
  39. package/dist/console.js +4 -4
  40. package/dist/console.js.map +1 -1
  41. package/dist/index.js.map +1 -1
  42. package/options/version551.yaml +303 -296
  43. package/package.json +13 -8
  44. package/src/ToJSON/console.ts +67 -67
  45. package/src/ToJSON/models/DefinitionCache.ts +7 -7
  46. package/src/ToJSON/models/LineParsingResult.ts +7 -7
  47. package/src/ToJSON/models/ParsedLine.ts +35 -35
  48. package/src/ToJSON/models/Parsing.ts +45 -41
  49. package/src/ToJSON/models/ParsingObject.ts +16 -16
  50. package/src/ToJSON/models/ParsingOptions.ts +41 -41
  51. package/src/ToJSON/models/ParsingPath.ts +7 -7
  52. package/src/ToJSON/models/ParsingResult.ts +10 -10
  53. package/src/ToJSON/models/StatisticLine.ts +16 -16
  54. package/src/ToJSON/models/Statistics.ts +63 -63
  55. package/src/ToJSON/models/Store.ts +106 -108
  56. package/src/ToJSON/models/TagDefinition.ts +123 -122
  57. package/src/ToJSON/parsing/lineHelper.ts +21 -21
  58. package/src/ToJSON/parsing/lineValidation.ts +39 -40
  59. package/src/ToJSON/parsing/parseDate.ts +280 -286
  60. package/src/ToJSON/parsing/parseLine.ts +33 -33
  61. package/src/ToJSON/parsing/parsing.ts +134 -141
  62. package/src/ToJSON/parsing/processLine.ts +112 -109
  63. package/src/ToJSON/processing/manipulateValues.ts +52 -53
  64. package/src/ToJSON/processing/result.ts +247 -241
  65. package/src/common.ts +14 -14
  66. package/src/console.ts +7 -8
  67. package/src/index.ts +3 -6
  68. package/test.json +0 -323
@@ -1,9 +1,9 @@
1
1
  import drop from 'lodash/drop';
2
2
  import join from 'lodash/join';
3
- import trim from "lodash/trim";
4
- import isEmpty from "lodash/isEmpty";
3
+ import trim from 'lodash/trim';
4
+ import isEmpty from 'lodash/isEmpty';
5
5
 
6
- import ParsedLine from "../models/ParsedLine";
6
+ import ParsedLine from '../models/ParsedLine';
7
7
 
8
8
  import { GetLineLevel, GetReferenceId } from './lineHelper';
9
9
 
@@ -14,40 +14,40 @@ import { GetLineLevel, GetReferenceId } from './lineHelper';
14
14
  * @param lineNumber - The line number
15
15
  * @param lastLevel - The level of the last parent
16
16
  * @returns The ParsedLine object if it is a correct gedcom line else undefined
17
- */
18
- export function ParseLine(line: string, lineNumber: number, lastLevel: number) : ParsedLine | undefined {
19
- // level is max + 1 of last level
20
- let level = GetLineLevel(line);
21
- if (level !== 0 && level > lastLevel + 1){
22
- return undefined;
17
+ */
18
+ export function ParseLine(line: string, lineNumber: number, lastLevel: number): ParsedLine | undefined {
19
+ // level is max + 1 of last level
20
+ let level = GetLineLevel(line);
21
+ if (level !== 0 && level > lastLevel + 1) {
22
+ return undefined;
23
+ }
24
+
25
+ let splitWithDelimiter = line.split(' ');
26
+ let tagOrRef = trim(splitWithDelimiter[1]);
27
+ let valueOrTag = trim(splitWithDelimiter[2]);
28
+ let value: string | undefined = join(drop(splitWithDelimiter, 3), ' ');
29
+
30
+ let refId = GetReferenceId(tagOrRef);
31
+
32
+ if (refId !== undefined) {
33
+ if (refId.length > 23) {
34
+ return undefined;
23
35
  }
24
36
 
25
- let splitWithDelimiter = line.split(' ');
26
- let tagOrRef = trim(splitWithDelimiter[1]);
27
- let valueOrTag = trim(splitWithDelimiter[2]);
28
- let value: string | undefined = join(drop(splitWithDelimiter, 3), ' ');
37
+ return new ParsedLine(lineNumber, level, valueOrTag, value, refId);
38
+ }
29
39
 
30
- let refId = GetReferenceId(tagOrRef);
40
+ let tag = tagOrRef;
31
41
 
32
- if (refId !== undefined) {
33
- if (refId.length > 23) {
34
- return undefined;
35
- }
42
+ if (tag.length > 31) {
43
+ return undefined;
44
+ }
36
45
 
37
- return new ParsedLine(lineNumber, level, valueOrTag, value, refId);
38
- }
39
-
40
- let tag = tagOrRef;
41
-
42
- if (tag.length > 31){
43
- return undefined;
44
- }
45
-
46
- value = trim(`${valueOrTag} ${value}`);
46
+ value = trim(`${valueOrTag} ${value}`);
47
47
 
48
- if (trim(value) === 'undefined' || isEmpty(trim(value))) {
49
- value = undefined;
50
- }
48
+ if (trim(value) === 'undefined' || isEmpty(trim(value))) {
49
+ value = undefined;
50
+ }
51
51
 
52
- return new ParsedLine(lineNumber, level, tag, value);
53
- }
52
+ return new ParsedLine(lineNumber, level, tag, value);
53
+ }
@@ -2,7 +2,7 @@ import trimStart from 'lodash/trimStart';
2
2
  import forEach from 'lodash/forEach';
3
3
  import split from 'lodash/split';
4
4
 
5
- import ParsedLine from "../models/ParsedLine";
5
+ import ParsedLine from '../models/ParsedLine';
6
6
  import Statistics from '../models/Statistics';
7
7
  import StatisticLine from '../models/StatisticLine';
8
8
 
@@ -16,58 +16,54 @@ const LineByLineReader = require('line-by-line');
16
16
  let stats = new Statistics();
17
17
 
18
18
  /**
19
- * Parses a text to an object
19
+ * Parses a text to an object
20
20
  *
21
21
  * @param text - The text
22
22
  * @param parsingOptions - The parsing options
23
23
  * @param invokeProgressFunction - Set function that is called before each line, to show progress in some way
24
24
  * @returns An object which includes the parsed object and parsing statistics
25
- */
26
- export function ParseText(
27
- text?: string,
28
- parsingOptions?: string,
29
- invokeProgressFunction?: (linesCount: number, actualLine: number) => void): ParsingResult {
30
- stats = new Statistics();
31
-
32
- if (!text || !parsingOptions){
33
- return new ParsingResult({});
34
- }
25
+ */
26
+ export function ParseText(text?: string, parsingOptions?: string, invokeProgressFunction?: (linesCount: number, actualLine: number) => void): ParsingResult {
27
+ stats = new Statistics();
35
28
 
36
- ResetProcessing();
29
+ if (!text || !parsingOptions) {
30
+ return new ParsingResult({});
31
+ }
37
32
 
38
- let lastLevel = 0;
39
- let lineNumber = 1;
40
- let lines = split(text, "\n");
41
- let yamlOptions: string | object | undefined = {};
33
+ ResetProcessing();
42
34
 
43
- try{
44
- yamlOptions = yaml.safeLoad(parsingOptions);
45
- SetParsingOptions(yamlOptions);
46
- }
47
- catch(e) {
48
- ResetProcessing();
49
- return new ParsingResult({});
35
+ let lastLevel = 0;
36
+ let lineNumber = 1;
37
+ let lines = split(text, '\n');
38
+ let yamlOptions: string | object | undefined = {};
39
+
40
+ try {
41
+ yamlOptions = yaml.safeLoad(parsingOptions);
42
+ SetParsingOptions(yamlOptions);
43
+ } catch (e) {
44
+ ResetProcessing();
45
+ return new ParsingResult({});
46
+ }
47
+
48
+ let nextLine = (lastLine: ParsedLine | undefined = undefined) => {
49
+ if (lastLine) {
50
+ lastLevel = lastLine.Level;
50
51
  }
51
52
 
52
- let nextLine = (lastLine: ParsedLine | undefined = undefined) => {
53
- if (lastLine){
54
- lastLevel = lastLine.Level;
55
- }
53
+ lineNumber++;
54
+ };
56
55
 
57
- lineNumber++;
58
- };
56
+ forEach(lines, (line, index) => {
57
+ if (invokeProgressFunction) {
58
+ invokeProgressFunction(lines.length, index);
59
+ }
59
60
 
60
- forEach(lines, (line, index) => {
61
- if (invokeProgressFunction) {
62
- invokeProgressFunction(lines.length, index);
63
- }
61
+ ProcessNewLine(lastLevel, lineNumber, line, nextLine);
62
+ });
64
63
 
65
- ProcessNewLine(lastLevel, lineNumber, line, nextLine);
66
- });
67
-
68
- let result = GetResult();
69
- ResetProcessing();
70
- return new ParsingResult(result, stats);
64
+ let result = GetResult();
65
+ ResetProcessing();
66
+ return new ParsingResult(result, stats);
71
67
  }
72
68
 
73
69
  /**
@@ -79,93 +75,93 @@ export function ParseText(
79
75
  * @param errorCallback - Returns file reading errors
80
76
  * @param invokeProgressFunction - Set function that is called before each line, to show progress in some way
81
77
  * @returns An object which includes the parsed object and parsing statistics
82
- */
78
+ */
83
79
 
84
80
  /* istanbul ignore next */ // maybe later ;)
85
81
  export function ParseFile(
86
- path: string,
87
- parsingOptions: string,
88
- doneCallback: (result: ParsingResult) => void,
82
+ path: string,
83
+ parsingOptions: string,
84
+ doneCallback: (result: ParsingResult) => void,
89
85
  errorCallback: any,
90
- invokeProgressFunction?: ((linesCount: number, actualLine: number) => void) | undefined) {
91
-
92
- // if no progress should be shown, it is not necessary to get the line count of the file at first
93
- if (!invokeProgressFunction) {
94
- ExecuteParseFile(path, parsingOptions, doneCallback, errorCallback, 0);
95
- return;
96
- }
86
+ invokeProgressFunction?: ((linesCount: number, actualLine: number) => void) | undefined
87
+ ) {
88
+ // if no progress should be shown, it is not necessary to get the line count of the file at first
89
+ if (!invokeProgressFunction) {
90
+ ExecuteParseFile(path, parsingOptions, doneCallback, errorCallback, 0);
91
+ return;
92
+ }
97
93
 
98
- // read first time to get lines count
99
- let linesCountLr = new LineByLineReader(path);
100
- let linesCount = 0;
101
- linesCountLr.on('line', function (line: any) {
102
- linesCountLr.pause();
103
- linesCount++;
104
- linesCountLr.resume();
105
- });
106
-
107
- linesCountLr.on('end', function () {
108
- ExecuteParseFile(path, parsingOptions, doneCallback, errorCallback, linesCount, invokeProgressFunction);
109
- });
94
+ // read first time to get lines count
95
+ let linesCountLr = new LineByLineReader(path);
96
+ let linesCount = 0;
97
+ linesCountLr.on('line', function (line: any) {
98
+ linesCountLr.pause();
99
+ linesCount++;
100
+ linesCountLr.resume();
101
+ });
102
+
103
+ linesCountLr.on('end', function () {
104
+ ExecuteParseFile(path, parsingOptions, doneCallback, errorCallback, linesCount, invokeProgressFunction);
105
+ });
110
106
  }
111
107
 
112
108
  /* istanbul ignore next */ // maybe later ;)
113
109
  function ExecuteParseFile(
114
- path: string,
115
- parsingOptions: string,
116
- doneCallback: (result: ParsingResult) => void,
110
+ path: string,
111
+ parsingOptions: string,
112
+ doneCallback: (result: ParsingResult) => void,
117
113
  errorCallback: any,
118
114
  linesCount: number,
119
- invokeProgressFunction?: ((linesCount: number, actualLine: number) => void) | undefined) {
120
- let lr = new LineByLineReader(path);
121
- let lastLevel = 0;
122
- let lineNumber = 1;
123
- let yamlOptions: string | object | undefined = {};
124
-
125
- try{
126
- yamlOptions = yaml.safeLoad(parsingOptions);
127
- SetParsingOptions(yamlOptions);
115
+ invokeProgressFunction?: ((linesCount: number, actualLine: number) => void) | undefined
116
+ ) {
117
+ let lr = new LineByLineReader(path);
118
+ let lastLevel = 0;
119
+ let lineNumber = 1;
120
+ let yamlOptions: string | object | undefined = {};
121
+
122
+ try {
123
+ yamlOptions = yaml.safeLoad(parsingOptions);
124
+ SetParsingOptions(yamlOptions);
125
+ } catch (e) {
126
+ errorCallback(e);
127
+ doneCallback(new ParsingResult({}));
128
+
129
+ ResetProcessing();
130
+ return;
131
+ }
132
+
133
+ let nextLine = (lastLine: ParsedLine | undefined = undefined) => {
134
+ if (lastLine) {
135
+ lastLevel = lastLine.Level;
128
136
  }
129
- catch(e) {
130
- errorCallback(e);
131
- doneCallback(new ParsingResult({}));
132
137
 
133
- ResetProcessing();
134
- return;
138
+ if (invokeProgressFunction) {
139
+ invokeProgressFunction(linesCount, lineNumber);
135
140
  }
136
-
137
- let nextLine = (lastLine: ParsedLine | undefined = undefined) => {
138
- if (lastLine){
139
- lastLevel = lastLine.Level;
140
- }
141
-
142
- if (invokeProgressFunction) {
143
- invokeProgressFunction(linesCount, lineNumber);
144
- }
145
-
146
- lineNumber++;
147
- lr.resume();
148
- };
149
-
150
- lr.on('error', function (err: any) {
151
- if (errorCallback) {
152
- errorCallback(err);
153
- }
154
- });
155
-
156
- lr.on('line', function (line: any) {
157
- lr.pause();
158
- ProcessNewLine(lastLevel, lineNumber, line, nextLine);
159
- });
160
-
161
- lr.on('end', function () {
162
- let result = GetResult();
163
- ResetProcessing();
164
-
165
- // All lines are read, file is closed now.
166
- doneCallback(new ParsingResult(result, stats));
167
- });
168
- }
141
+
142
+ lineNumber++;
143
+ lr.resume();
144
+ };
145
+
146
+ lr.on('error', function (err: any) {
147
+ if (errorCallback) {
148
+ errorCallback(err);
149
+ }
150
+ });
151
+
152
+ lr.on('line', function (line: any) {
153
+ lr.pause();
154
+ ProcessNewLine(lastLevel, lineNumber, line, nextLine);
155
+ });
156
+
157
+ lr.on('end', function () {
158
+ let result = GetResult();
159
+ ResetProcessing();
160
+
161
+ // All lines are read, file is closed now.
162
+ doneCallback(new ParsingResult(result, stats));
163
+ });
164
+ }
169
165
 
170
166
  /**
171
167
  * Function that processes a text line
@@ -176,36 +172,33 @@ function ExecuteParseFile(
176
172
  * @internal
177
173
  */
178
174
  export function ProcessNewLine(lastLevel: number, lineNumber: number, line: string, nextLine: Function) {
179
- let actualLine = trimStart(line);
175
+ let actualLine = trimStart(line);
180
176
 
181
- if (!IsValidLine(actualLine)) {
182
- stats.IncorrectLines.push(new StatisticLine(lineNumber, actualLine));
183
- nextLine();
184
- return stats;
185
- }
177
+ if (!IsValidLine(actualLine)) {
178
+ stats.IncorrectLines.push(new StatisticLine(lineNumber, actualLine));
179
+ nextLine();
180
+ return stats;
181
+ }
186
182
 
187
- var parsedLine = ParseLine(actualLine, lineNumber, lastLevel);
183
+ var parsedLine = ParseLine(actualLine, lineNumber, lastLevel);
188
184
 
189
- if (parsedLine === undefined) {
190
- stats.IncorrectLines.push(new StatisticLine(lineNumber, actualLine));
191
- nextLine();
192
- return stats;
193
- }
194
-
195
- let processingResult = ProcessLine(parsedLine, lastLevel);
196
- if (processingResult.Parsed) {
197
- stats.ParsedLines.push(new StatisticLine(lineNumber, actualLine));
198
- }
199
- else
200
- {
201
- if (parsedLine.Tag && parsedLine.Tag[0] === '_') {
202
- stats.NotParsedLinesWithoutGEDCOMTag.push(new StatisticLine(lineNumber, actualLine, processingResult.Reason));
203
- }
204
- else{
205
- stats.NotParsedLines.push(new StatisticLine(lineNumber, actualLine, processingResult.Reason));
206
- }
185
+ if (parsedLine === undefined) {
186
+ stats.IncorrectLines.push(new StatisticLine(lineNumber, actualLine));
187
+ nextLine();
188
+ return stats;
189
+ }
190
+
191
+ let processingResult = ProcessLine(parsedLine, lastLevel);
192
+ if (processingResult.Parsed) {
193
+ stats.ParsedLines.push(new StatisticLine(lineNumber, actualLine));
194
+ } else {
195
+ if (parsedLine.Tag && parsedLine.Tag[0] === '_') {
196
+ stats.NotParsedLinesWithoutGEDCOMTag.push(new StatisticLine(lineNumber, actualLine, processingResult.Reason));
197
+ } else {
198
+ stats.NotParsedLines.push(new StatisticLine(lineNumber, actualLine, processingResult.Reason));
207
199
  }
200
+ }
208
201
 
209
- nextLine(parsedLine);
210
- return stats;
211
- }
202
+ nextLine(parsedLine);
203
+ return stats;
204
+ }