gedcom.json 1.0.6 → 1.0.9

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