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
@@ -6,7 +6,7 @@ import drop from 'lodash/drop';
6
6
 
7
7
  import fclone from 'fclone';
8
8
 
9
- import ParsedLine from "../models/ParsedLine";
9
+ import ParsedLine from '../models/ParsedLine';
10
10
  import Store from '../models/Store';
11
11
  import TagDefinition from '../models/TagDefinition';
12
12
  import LineParsingResult from '../models/LineParsingResult';
@@ -25,164 +25,167 @@ let store = new Store();
25
25
 
26
26
  /**
27
27
  * Resets all variables, which are used for parsing
28
- */
28
+ */
29
29
  export function ResetProcessing() {
30
- store.Reset();
31
- parsingOptions = {};
30
+ store.Reset();
31
+ parsingOptions = {};
32
32
  }
33
33
 
34
34
  export function SetParsingOptions(options: any) {
35
- parsingOptions = options;
35
+ parsingOptions = options;
36
36
  }
37
37
 
38
38
  export function GetResult() {
39
- let result = store.CreateResultObject();
40
- store.FullReset();
41
- return result;
39
+ let result = store.CreateResultObject();
40
+ store.FullReset();
41
+ return result;
42
42
  }
43
43
 
44
44
  export function EndProcessing() {
45
- store.Reset();
46
- ClearDateTimeMergingInfos();
45
+ store.Reset();
46
+ ClearDateTimeMergingInfos();
47
47
  }
48
48
 
49
- export function ProcessLine(line: ParsedLine, lastLevel: number) : LineParsingResult {
50
- if (!line || !line.Tag) {
51
- return new LineParsingResult(false, "No line or no line tag found");
52
- }
49
+ export function ProcessLine(line: ParsedLine, lastLevel: number): LineParsingResult {
50
+ if (!line || !line.Tag) {
51
+ return new LineParsingResult(false, 'No line or no line tag found');
52
+ }
53
53
 
54
- if (line.Level === 0) {
55
- let process = ProcessStartLevel(line);
56
- return new LineParsingResult(process, process ? undefined : "No tag definition found");
57
- }
54
+ if (line.Level === 0) {
55
+ let process = ProcessStartLevel(line);
56
+ return new LineParsingResult(process, process ? undefined : 'No tag definition found');
57
+ }
58
58
 
59
- if (!store.IsParsing()) {
60
- return new LineParsingResult(false, "Parent has no parsing definition");
61
- }
59
+ if (!store.IsParsing()) {
60
+ return new LineParsingResult(false, 'Parent has no parsing definition');
61
+ }
62
62
 
63
- if (!store.ShouldParseLine(line.Level)) {
64
- return new LineParsingResult(false, "Parent has no parsing definition, so all children will be ignored");
65
- }
63
+ if (!store.ShouldParseLine(line.Level)) {
64
+ return new LineParsingResult(false, 'Parent has no parsing definition, so all children will be ignored');
65
+ }
66
66
 
67
- AdjustPath(line, lastLevel);
67
+ AdjustPath(line, lastLevel);
68
68
 
69
- let definition = GetLocalDefinition(line.Tag)
69
+ let definition = GetLocalDefinition(line.Tag);
70
70
 
71
- if (!definition) {
72
- definition = GetTagDefinition(line.Tag);
73
- }
71
+ if (!definition) {
72
+ definition = GetTagDefinition(line.Tag);
73
+ }
74
74
 
75
- if (!definition) {
76
- store.StopParsingUntilLevel(line.Level);
75
+ if (!definition) {
76
+ store.StopParsingUntilLevel(line.Level);
77
77
 
78
- // add temporaray path, that will be removed later
79
- store.AddTempPath();
80
- return new LineParsingResult(false, "No tag definition found");
81
- }
78
+ // add temporaray path, that will be removed later
79
+ store.AddTempPath();
80
+ return new LineParsingResult(false, 'No tag definition found');
81
+ }
82
+
83
+ store.StartParsing(definition, line);
82
84
 
83
- store.StartParsing(definition, line);
84
-
85
- return new LineParsingResult(true);
85
+ return new LineParsingResult(true);
86
86
  }
87
87
 
88
88
  function GetLocalDefinition(tag: string): TagDefinition | undefined {
89
- let path = fclone(store.GetPath());
89
+ let path = fclone(store.GetPath());
90
90
 
91
- /* istanbul ignore next */ // should never happen
92
- if (path.length === 0) {
93
- return undefined;
94
- }
91
+ /* istanbul ignore next */ // should never happen
92
+ if (path.length === 0) {
93
+ return undefined;
94
+ }
95
95
 
96
- let definition = SearchDefinitionDeep(parsingOptions.Definition, path, tag);
97
-
98
- if (!definition) {
99
- return undefined;
100
- }
96
+ let definition = SearchDefinitionDeep(parsingOptions.Definition, path, tag);
97
+
98
+ if (!definition) {
99
+ return undefined;
100
+ }
101
101
 
102
- return new TagDefinition(definition);
102
+ return new TagDefinition(definition);
103
103
  }
104
104
 
105
105
  export function SearchDefinitionDeep(properties: any[], searchpath: ParsingPath[], searchedTag: string): any {
106
- // search path
107
- let specificPath = map(searchpath, x => x.Tag);
108
- specificPath.push(searchedTag);
106
+ // search path
107
+ let specificPath = map(searchpath, (x) => x.Tag);
108
+ specificPath.push(searchedTag);
109
109
 
110
- let cachedValue = store.GetDefinitionFromCache(specificPath);
110
+ let cachedValue = store.GetDefinitionFromCache(specificPath);
111
111
 
112
- if (cachedValue) {
113
- return cachedValue.Definition;
114
- }
112
+ if (cachedValue) {
113
+ return cachedValue.Definition;
114
+ }
115
115
 
116
- // search all tag definitions
117
- let tagDefinitions: any[] = [];
118
- eachDeep(properties, (val:any, key:string, parent:any, context:any) => {
119
- if (key === "Tag" && val === searchedTag) {
120
- tagDefinitions.push({
121
- Definition: parent,
122
- Path: filter(map(context.parents, x => x.value.Tag), x => x !== undefined)
123
- });
124
- }
125
- });
126
-
127
- // explicit local path
128
- let pathStartWithsTag;
129
-
130
- // drop first tag until found -> last is global definition
131
- while(!pathStartWithsTag && specificPath.length > 0) {
132
- pathStartWithsTag = find(tagDefinitions, y => isEqual(y.Path, specificPath));
133
-
134
- if (!pathStartWithsTag) {
135
- specificPath = drop(specificPath);
136
- }
116
+ // search all tag definitions
117
+ let tagDefinitions: any[] = [];
118
+ eachDeep(properties, (val: any, key: string, parent: any, context: any) => {
119
+ if (key === 'Tag' && val === searchedTag) {
120
+ tagDefinitions.push({
121
+ Definition: parent,
122
+ Path: filter(
123
+ map(context.parents, (x) => x.value.Tag),
124
+ (x) => x !== undefined
125
+ ),
126
+ });
137
127
  }
128
+ });
138
129
 
139
- if (pathStartWithsTag?.Definition) {
140
- let foundPath = map(searchpath, x => x.Tag);
141
- foundPath.push(searchedTag);
142
- store.AddDefinitionToCache(foundPath, pathStartWithsTag.Definition);
130
+ // explicit local path
131
+ let pathStartWithsTag;
132
+
133
+ // drop first tag until found -> last is global definition
134
+ while (!pathStartWithsTag && specificPath.length > 0) {
135
+ pathStartWithsTag = find(tagDefinitions, (y) => isEqual(y.Path, specificPath));
136
+
137
+ if (!pathStartWithsTag) {
138
+ specificPath = drop(specificPath);
143
139
  }
140
+ }
141
+
142
+ if (pathStartWithsTag?.Definition) {
143
+ let foundPath = map(searchpath, (x) => x.Tag);
144
+ foundPath.push(searchedTag);
145
+ store.AddDefinitionToCache(foundPath, pathStartWithsTag.Definition);
146
+ }
144
147
 
145
- return pathStartWithsTag?.Definition;
148
+ return pathStartWithsTag?.Definition;
146
149
  }
147
150
 
148
151
  function AdjustPath(line: ParsedLine, lastLevel: number) {
149
- if (line.Level > lastLevel) {
150
- return;
151
- }
152
+ if (line.Level > lastLevel) {
153
+ return;
154
+ }
152
155
 
153
- if (line.Level === lastLevel) {
154
- store.DropRightPath();
155
- return;
156
- }
156
+ if (line.Level === lastLevel) {
157
+ store.DropRightPath();
158
+ return;
159
+ }
157
160
 
158
- store.DropRightPath(line.Level);
159
- ClearDateTimeMergingInfos();
161
+ store.DropRightPath(line.Level);
162
+ ClearDateTimeMergingInfos();
160
163
  }
161
164
 
162
165
  function GetTagDefinition(tag: string): TagDefinition | undefined {
163
- let definition = find(parsingOptions.Definition, x => x.Tag === tag);
166
+ let definition = find(parsingOptions.Definition, (x) => x.Tag === tag);
164
167
 
165
- if (!definition) {
166
- return undefined;
167
- }
168
+ if (!definition) {
169
+ return undefined;
170
+ }
168
171
 
169
- return new TagDefinition(definition);
172
+ return new TagDefinition(definition);
170
173
  }
171
174
 
172
- export function ProcessStartLevel(line: ParsedLine) : Boolean {
173
- if (line.Tag === "TRLR") {
174
- return true;
175
- }
175
+ export function ProcessStartLevel(line: ParsedLine): Boolean {
176
+ if (line.Tag === 'TRLR') {
177
+ return true;
178
+ }
176
179
 
177
- EndProcessing();
178
- let definition = GetTagDefinition(line.Tag);
180
+ EndProcessing();
181
+ let definition = GetTagDefinition(line.Tag);
179
182
 
180
- if (!definition) {
181
- return false;
182
- }
183
+ if (!definition) {
184
+ return false;
185
+ }
183
186
 
184
- store.StartParsing(definition, line);
185
- ClearDateTimeMergingInfos();
187
+ store.StartParsing(definition, line);
188
+ ClearDateTimeMergingInfos();
186
189
 
187
- return true;
188
- }
190
+ return true;
191
+ }
@@ -1,83 +1,82 @@
1
- import isEmpty from "lodash/isEmpty";
1
+ import isEmpty from 'lodash/isEmpty';
2
2
  import trim from 'lodash/trim';
3
3
  import replace from 'lodash/replace';
4
4
  import split from 'lodash/split';
5
5
  import map from 'lodash/map';
6
6
 
7
- import ParsedLine from "../models/ParsedLine";
8
- import TagDefinition from "../models/TagDefinition";
9
- import ConvertToDate from "../models/converter/ConvertToDate";
10
- import ConvertToArray from "../models/converter/ConvertToArray";
7
+ import ParsedLine from '../models/ParsedLine';
8
+ import TagDefinition from '../models/TagDefinition';
9
+ import ConvertToDate from '../models/converter/ConvertToDate';
10
+ import ConvertToArray from '../models/converter/ConvertToArray';
11
11
 
12
- import { ConvertDateStringToObject, ConvertTimeStringToObject } from "../parsing/parseDate";
13
- import ConvertToTime from "../models/converter/ConvertToTime";
12
+ import { ConvertDateStringToObject, ConvertTimeStringToObject } from '../parsing/parseDate';
13
+ import ConvertToTime from '../models/converter/ConvertToTime';
14
14
 
15
15
  export function ManipulateValue(definition: TagDefinition, line: ParsedLine) {
16
- let value:string = trim(isEmpty(line.ReferenceId) ? line.Value : line.ReferenceId);
17
- let convertTo = definition.PropertyType ?? definition.ConvertTo;
16
+ let value: string = trim(isEmpty(line.ReferenceId) ? line.Value : line.ReferenceId);
17
+ let convertTo = definition.PropertyType ?? definition.ConvertTo;
18
18
 
19
- if (value.match(/^(@.*@)/)) {
19
+ if (value.match(/^(@.*@)/)) {
20
+ if (definition.ConvertTo instanceof ConvertToArray) {
21
+ return ConvertStringToArray(definition.ConvertTo, value);
22
+ }
20
23
 
21
- if (definition.ConvertTo instanceof ConvertToArray) {
22
- return ConvertStringToArray(definition.ConvertTo, value);
23
- }
24
-
25
- return value;
26
- };
24
+ return value;
25
+ }
27
26
 
28
- value = AddStartWith(definition.StartWith, value);
27
+ value = AddStartWith(definition.StartWith, value);
29
28
 
30
- if (definition.Replace) {
31
- let pattern = definition.Replace.Value;
32
- let replacement = definition.Replace.With;
29
+ if (definition.Replace) {
30
+ let pattern = definition.Replace.Value;
31
+ let replacement = definition.Replace.With;
33
32
 
34
- if (pattern && replacement){
35
- value = replace(value, pattern, replacement);
36
- }
33
+ if (pattern && replacement) {
34
+ value = replace(value, pattern, replacement);
37
35
  }
36
+ }
38
37
 
39
- if (definition.StripHtml){
40
- value = value.replace(/(<([^>]+)>)/gi, "");
41
- }
38
+ if (definition.StripHtml) {
39
+ value = value.replace(/(<([^>]+)>)/gi, '');
40
+ }
42
41
 
43
- if (!convertTo) {
44
- return value;
45
- }
42
+ if (!convertTo) {
43
+ return value;
44
+ }
46
45
 
47
- if (convertTo instanceof ConvertToDate) {
48
- return ConvertDateStringToObject(convertTo, value);
49
- }
46
+ if (convertTo instanceof ConvertToDate) {
47
+ return ConvertDateStringToObject(convertTo, value);
48
+ }
50
49
 
51
- if (convertTo instanceof ConvertToTime) {
52
- return ConvertTimeStringToObject(value, definition.Property);
53
- }
50
+ if (convertTo instanceof ConvertToTime) {
51
+ return ConvertTimeStringToObject(value, definition.Property);
52
+ }
54
53
 
55
- if (convertTo instanceof ConvertToArray) {
56
- return ConvertStringToArray(convertTo, value);
57
- }
54
+ if (convertTo instanceof ConvertToArray) {
55
+ return ConvertStringToArray(convertTo, value);
56
+ }
58
57
 
59
- return value;
58
+ return value;
60
59
  }
61
60
 
62
61
  export function AddStartWith(startWith: string | undefined, value: string | undefined): string {
63
- if (!startWith) {
64
- return value ?? '';
65
- }
62
+ if (!startWith) {
63
+ return value ?? '';
64
+ }
66
65
 
67
- if (startWith === "\\n") {
68
- startWith = "\n";
69
- }
66
+ if (startWith === '\\n') {
67
+ startWith = '\n';
68
+ }
70
69
 
71
- if (!value) {
72
- return startWith;
73
- }
70
+ if (!value) {
71
+ return startWith;
72
+ }
74
73
 
75
- return `${startWith}${value}`;
74
+ return `${startWith}${value}`;
76
75
  }
77
76
 
78
77
  function ConvertStringToArray(convertOptions: ConvertToArray, value: string) {
79
- let arr = split(value, convertOptions.Delimiter);
80
- arr = map(arr, x => trim(x));
78
+ let arr = split(value, convertOptions.Delimiter);
79
+ arr = map(arr, (x) => trim(x));
81
80
 
82
- return arr;
83
- }
81
+ return arr;
82
+ }