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.
- package/README.md +246 -256
- package/dist/ToJSON/console.js +15 -12
- package/dist/ToJSON/console.js.map +1 -1
- package/dist/ToJSON/models/DefinitionCache.js.map +1 -1
- package/dist/ToJSON/models/LineParsingResult.js.map +1 -1
- package/dist/ToJSON/models/ParsedLine.js +1 -1
- package/dist/ToJSON/models/ParsedLine.js.map +1 -1
- package/dist/ToJSON/models/Parsing.js +8 -6
- package/dist/ToJSON/models/Parsing.js.map +1 -1
- package/dist/ToJSON/models/ParsingObject.js.map +1 -1
- package/dist/ToJSON/models/ParsingOptions.js.map +1 -1
- package/dist/ToJSON/models/ParsingPath.js.map +1 -1
- package/dist/ToJSON/models/ParsingResult.js.map +1 -1
- package/dist/ToJSON/models/StatisticLine.js.map +1 -1
- package/dist/ToJSON/models/Statistics.js +2 -2
- package/dist/ToJSON/models/Statistics.js.map +1 -1
- package/dist/ToJSON/models/Store.js +11 -11
- package/dist/ToJSON/models/Store.js.map +1 -1
- package/dist/ToJSON/models/TagDefinition.js +11 -11
- package/dist/ToJSON/models/TagDefinition.js.map +1 -1
- package/dist/ToJSON/parsing/lineHelper.js +8 -8
- package/dist/ToJSON/parsing/lineHelper.js.map +1 -1
- package/dist/ToJSON/parsing/lineValidation.js +6 -6
- package/dist/ToJSON/parsing/lineValidation.js.map +1 -1
- package/dist/ToJSON/parsing/parseDate.js +84 -84
- package/dist/ToJSON/parsing/parseDate.js.map +1 -1
- package/dist/ToJSON/parsing/parseLine.js +8 -8
- package/dist/ToJSON/parsing/parseLine.js.map +1 -1
- package/dist/ToJSON/parsing/parsing.js +17 -17
- package/dist/ToJSON/parsing/parsing.js.map +1 -1
- package/dist/ToJSON/parsing/processLine.js +18 -18
- package/dist/ToJSON/parsing/processLine.js.map +1 -1
- package/dist/ToJSON/processing/manipulateValues.js +9 -10
- package/dist/ToJSON/processing/manipulateValues.js.map +1 -1
- package/dist/ToJSON/processing/result.js +87 -80
- package/dist/ToJSON/processing/result.js.map +1 -1
- package/dist/common.js +5 -5
- package/dist/common.js.map +1 -1
- package/dist/console.js +4 -4
- package/dist/console.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/options/version551.yaml +303 -296
- package/package.json +13 -8
- package/src/ToJSON/console.ts +67 -67
- package/src/ToJSON/models/DefinitionCache.ts +7 -7
- package/src/ToJSON/models/LineParsingResult.ts +7 -7
- package/src/ToJSON/models/ParsedLine.ts +35 -35
- package/src/ToJSON/models/Parsing.ts +45 -41
- package/src/ToJSON/models/ParsingObject.ts +16 -16
- package/src/ToJSON/models/ParsingOptions.ts +41 -41
- package/src/ToJSON/models/ParsingPath.ts +7 -7
- package/src/ToJSON/models/ParsingResult.ts +10 -10
- package/src/ToJSON/models/StatisticLine.ts +16 -16
- package/src/ToJSON/models/Statistics.ts +63 -63
- package/src/ToJSON/models/Store.ts +106 -108
- package/src/ToJSON/models/TagDefinition.ts +123 -122
- package/src/ToJSON/parsing/lineHelper.ts +21 -21
- package/src/ToJSON/parsing/lineValidation.ts +39 -40
- package/src/ToJSON/parsing/parseDate.ts +280 -286
- package/src/ToJSON/parsing/parseLine.ts +33 -33
- package/src/ToJSON/parsing/parsing.ts +134 -141
- package/src/ToJSON/parsing/processLine.ts +112 -109
- package/src/ToJSON/processing/manipulateValues.ts +52 -53
- package/src/ToJSON/processing/result.ts +247 -241
- package/src/common.ts +14 -14
- package/src/console.ts +7 -8
- package/src/index.ts +3 -6
- 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
|
|
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
|
-
|
|
31
|
-
|
|
30
|
+
store.Reset();
|
|
31
|
+
parsingOptions = {};
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
export function SetParsingOptions(options: any) {
|
|
35
|
-
|
|
35
|
+
parsingOptions = options;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
export function GetResult() {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
let result = store.CreateResultObject();
|
|
40
|
+
store.FullReset();
|
|
41
|
+
return result;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
export function EndProcessing() {
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
store.Reset();
|
|
46
|
+
ClearDateTimeMergingInfos();
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
export function ProcessLine(line: ParsedLine, lastLevel: number)
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
if (!store.IsParsing()) {
|
|
60
|
+
return new LineParsingResult(false, 'Parent has no parsing definition');
|
|
61
|
+
}
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
|
|
67
|
+
AdjustPath(line, lastLevel);
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
let definition = GetLocalDefinition(line.Tag);
|
|
70
70
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
if (!definition) {
|
|
72
|
+
definition = GetTagDefinition(line.Tag);
|
|
73
|
+
}
|
|
74
74
|
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
if (!definition) {
|
|
76
|
+
store.StopParsingUntilLevel(line.Level);
|
|
77
77
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
-
|
|
84
|
-
|
|
85
|
-
return new LineParsingResult(true);
|
|
85
|
+
return new LineParsingResult(true);
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
function GetLocalDefinition(tag: string): TagDefinition | undefined {
|
|
89
|
-
|
|
89
|
+
let path = fclone(store.GetPath());
|
|
90
90
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
91
|
+
/* istanbul ignore next */ // should never happen
|
|
92
|
+
if (path.length === 0) {
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
95
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
96
|
+
let definition = SearchDefinitionDeep(parsingOptions.Definition, path, tag);
|
|
97
|
+
|
|
98
|
+
if (!definition) {
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
101
|
|
|
102
|
-
|
|
102
|
+
return new TagDefinition(definition);
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
export function SearchDefinitionDeep(properties: any[], searchpath: ParsingPath[], searchedTag: string): any {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
106
|
+
// search path
|
|
107
|
+
let specificPath = map(searchpath, (x) => x.Tag);
|
|
108
|
+
specificPath.push(searchedTag);
|
|
109
109
|
|
|
110
|
-
|
|
110
|
+
let cachedValue = store.GetDefinitionFromCache(specificPath);
|
|
111
111
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
112
|
+
if (cachedValue) {
|
|
113
|
+
return cachedValue.Definition;
|
|
114
|
+
}
|
|
115
115
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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
|
-
|
|
148
|
+
return pathStartWithsTag?.Definition;
|
|
146
149
|
}
|
|
147
150
|
|
|
148
151
|
function AdjustPath(line: ParsedLine, lastLevel: number) {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
+
if (line.Level > lastLevel) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
152
155
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
156
|
+
if (line.Level === lastLevel) {
|
|
157
|
+
store.DropRightPath();
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
157
160
|
|
|
158
|
-
|
|
159
|
-
|
|
161
|
+
store.DropRightPath(line.Level);
|
|
162
|
+
ClearDateTimeMergingInfos();
|
|
160
163
|
}
|
|
161
164
|
|
|
162
165
|
function GetTagDefinition(tag: string): TagDefinition | undefined {
|
|
163
|
-
|
|
166
|
+
let definition = find(parsingOptions.Definition, (x) => x.Tag === tag);
|
|
164
167
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
+
if (!definition) {
|
|
169
|
+
return undefined;
|
|
170
|
+
}
|
|
168
171
|
|
|
169
|
-
|
|
172
|
+
return new TagDefinition(definition);
|
|
170
173
|
}
|
|
171
174
|
|
|
172
|
-
export function ProcessStartLevel(line: ParsedLine)
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
175
|
+
export function ProcessStartLevel(line: ParsedLine): Boolean {
|
|
176
|
+
if (line.Tag === 'TRLR') {
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
176
179
|
|
|
177
|
-
|
|
178
|
-
|
|
180
|
+
EndProcessing();
|
|
181
|
+
let definition = GetTagDefinition(line.Tag);
|
|
179
182
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
+
if (!definition) {
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
183
186
|
|
|
184
|
-
|
|
185
|
-
|
|
187
|
+
store.StartParsing(definition, line);
|
|
188
|
+
ClearDateTimeMergingInfos();
|
|
186
189
|
|
|
187
|
-
|
|
188
|
-
}
|
|
190
|
+
return true;
|
|
191
|
+
}
|
|
@@ -1,83 +1,82 @@
|
|
|
1
|
-
import isEmpty from
|
|
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
|
|
8
|
-
import TagDefinition from
|
|
9
|
-
import ConvertToDate from
|
|
10
|
-
import ConvertToArray from
|
|
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
|
|
13
|
-
import ConvertToTime from
|
|
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
|
-
|
|
17
|
-
|
|
16
|
+
let value: string = trim(isEmpty(line.ReferenceId) ? line.Value : line.ReferenceId);
|
|
17
|
+
let convertTo = definition.PropertyType ?? definition.ConvertTo;
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
if (value.match(/^(@.*@)/)) {
|
|
20
|
+
if (definition.ConvertTo instanceof ConvertToArray) {
|
|
21
|
+
return ConvertStringToArray(definition.ConvertTo, value);
|
|
22
|
+
}
|
|
20
23
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return value;
|
|
26
|
-
};
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
27
26
|
|
|
28
|
-
|
|
27
|
+
value = AddStartWith(definition.StartWith, value);
|
|
29
28
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
if (definition.Replace) {
|
|
30
|
+
let pattern = definition.Replace.Value;
|
|
31
|
+
let replacement = definition.Replace.With;
|
|
33
32
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
33
|
+
if (pattern && replacement) {
|
|
34
|
+
value = replace(value, pattern, replacement);
|
|
37
35
|
}
|
|
36
|
+
}
|
|
38
37
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
if (definition.StripHtml) {
|
|
39
|
+
value = value.replace(/(<([^>]+)>)/gi, '');
|
|
40
|
+
}
|
|
42
41
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
if (!convertTo) {
|
|
43
|
+
return value;
|
|
44
|
+
}
|
|
46
45
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
if (convertTo instanceof ConvertToDate) {
|
|
47
|
+
return ConvertDateStringToObject(convertTo, value);
|
|
48
|
+
}
|
|
50
49
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
if (convertTo instanceof ConvertToTime) {
|
|
51
|
+
return ConvertTimeStringToObject(value, definition.Property);
|
|
52
|
+
}
|
|
54
53
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
if (convertTo instanceof ConvertToArray) {
|
|
55
|
+
return ConvertStringToArray(convertTo, value);
|
|
56
|
+
}
|
|
58
57
|
|
|
59
|
-
|
|
58
|
+
return value;
|
|
60
59
|
}
|
|
61
60
|
|
|
62
61
|
export function AddStartWith(startWith: string | undefined, value: string | undefined): string {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
62
|
+
if (!startWith) {
|
|
63
|
+
return value ?? '';
|
|
64
|
+
}
|
|
66
65
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
66
|
+
if (startWith === '\\n') {
|
|
67
|
+
startWith = '\n';
|
|
68
|
+
}
|
|
70
69
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
70
|
+
if (!value) {
|
|
71
|
+
return startWith;
|
|
72
|
+
}
|
|
74
73
|
|
|
75
|
-
|
|
74
|
+
return `${startWith}${value}`;
|
|
76
75
|
}
|
|
77
76
|
|
|
78
77
|
function ConvertStringToArray(convertOptions: ConvertToArray, value: string) {
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
let arr = split(value, convertOptions.Delimiter);
|
|
79
|
+
arr = map(arr, (x) => trim(x));
|
|
81
80
|
|
|
82
|
-
|
|
83
|
-
}
|
|
81
|
+
return arr;
|
|
82
|
+
}
|