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
|
@@ -4,11 +4,11 @@ import find from 'lodash/find';
|
|
|
4
4
|
import findLast from 'lodash/findLast';
|
|
5
5
|
import remove from 'lodash/remove';
|
|
6
6
|
import isEqual from 'lodash/isEqual';
|
|
7
|
-
import split from
|
|
7
|
+
import split from 'lodash/split';
|
|
8
8
|
import forEach from 'lodash/forEach';
|
|
9
9
|
import isObject from 'lodash/isObject';
|
|
10
10
|
import isArray from 'lodash/isArray';
|
|
11
|
-
import dropRight from
|
|
11
|
+
import dropRight from 'lodash/dropRight';
|
|
12
12
|
import indexOf from 'lodash/indexOf';
|
|
13
13
|
import take from 'lodash/take';
|
|
14
14
|
import slice from 'lodash/slice';
|
|
@@ -18,7 +18,7 @@ import last from 'lodash/last';
|
|
|
18
18
|
import keys from 'lodash/keys';
|
|
19
19
|
import first from 'lodash/first';
|
|
20
20
|
|
|
21
|
-
import objectPath from
|
|
21
|
+
import objectPath from 'object-path';
|
|
22
22
|
|
|
23
23
|
import ParsingObject from '../models/ParsingObject';
|
|
24
24
|
import TagDefinition from '../models/TagDefinition';
|
|
@@ -30,67 +30,66 @@ import fclone from 'fclone';
|
|
|
30
30
|
import { AddStartWith } from './manipulateValues';
|
|
31
31
|
|
|
32
32
|
export function CreateResult(objects: ParsingObject[]) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
33
|
+
// collect all main objects
|
|
34
|
+
let mainObjectIndexes = GetMainObjectIndexes(objects);
|
|
35
|
+
let mainObjects: MainObject[] = [];
|
|
36
|
+
|
|
37
|
+
// create all main objects
|
|
38
|
+
forEach(mainObjectIndexes, (mainObjectIndex) => {
|
|
39
|
+
let mainObjectSubObjects = take(slice(objects, mainObjectIndex.StartIndex), mainObjectIndex.EndIndex - mainObjectIndex.StartIndex);
|
|
40
|
+
mainObjects.push(CreateMainObject(mainObjectSubObjects));
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// merge all main objects together
|
|
44
|
+
let result = {};
|
|
45
|
+
forEach(mainObjects, (mainObject) => {
|
|
46
|
+
SetObject(result, mainObject.Informations.PropertyPath, mainObject.Result, mainObject.Informations.Definition);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
return result;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
export function CreateMainObject(objects: ParsingObject[]): MainObject {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
/*
|
|
53
|
+
let result = {};
|
|
54
|
+
|
|
55
|
+
// concat objects
|
|
56
|
+
let mergeWithLastValue = filter(objects, (x) => x.Definition.MergeWithLast === 'true') as ParsingObject[];
|
|
57
|
+
let mergeValue = '';
|
|
58
|
+
|
|
59
|
+
forEachRight(mergeWithLastValue, (obj) => {
|
|
60
|
+
let index = indexOf(objects, obj);
|
|
61
|
+
let objectsToSearch = take(objects, index);
|
|
62
|
+
let mergeObject = last(objectsToSearch);
|
|
63
|
+
|
|
64
|
+
let val = obj.Line.Value;
|
|
65
|
+
val = AddStartWith(obj.Definition.StartWith, val);
|
|
66
|
+
if (!mergeObject) {
|
|
67
|
+
mergeValue = val;
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (!isEmpty(obj.Object) && (isArray(obj.Object) || isObject(obj.Object))) {
|
|
72
|
+
SetOrCreateArray(mergeObject.Object, split(obj.Definition.Path, '.'), obj.Definition, obj.Object);
|
|
73
|
+
remove(objects, (x) => isEqual(x, obj));
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (mergeObject.Definition.MergeWithLast === 'true') {
|
|
78
|
+
mergeValue = `${val}${mergeValue}`;
|
|
79
|
+
remove(objects, (x) => isEqual(x, obj));
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
mergeValue = `${val}${mergeValue}`;
|
|
84
|
+
|
|
85
|
+
if (isString(mergeObject.Object)) {
|
|
86
|
+
mergeObject.Object += mergeValue;
|
|
87
|
+
mergeValue = '';
|
|
88
|
+
remove(objects, (x) => isEqual(x, obj));
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/*
|
|
94
93
|
startlevel to has greater than null, because
|
|
95
94
|
|
|
96
95
|
1 EVEN RCKarnes-RootsWeb & John D Newport-Ancestry.com (johndnewport@valornet
|
|
@@ -107,227 +106,234 @@ export function CreateMainObject(objects: ParsingObject[]): MainObject {
|
|
|
107
106
|
NOT!
|
|
108
107
|
|
|
109
108
|
*/
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
objectPath.set(mergeObject.Object, key, `${value}${mergeValue}`);
|
|
124
|
-
mergeValue = "";
|
|
125
|
-
remove(objects, x => isEqual(x, obj));
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
});
|
|
109
|
+
if (mergeObject.StartLevel > 0 && isObject(mergeObject.Object)) {
|
|
110
|
+
let key = last(keys(mergeObject.Object));
|
|
111
|
+
|
|
112
|
+
if (!key) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
let value = objectPath.get(mergeObject.Object, key);
|
|
117
|
+
|
|
118
|
+
if (!isString(value)) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
129
121
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
if (mergeObject) {
|
|
136
|
-
objectPath.set(mergeObject.Object, "Text", mergeValue);
|
|
137
|
-
mergeValue = "";
|
|
138
|
-
}
|
|
122
|
+
objectPath.set(mergeObject.Object, key, `${value}${mergeValue}`);
|
|
123
|
+
mergeValue = '';
|
|
124
|
+
remove(objects, (x) => isEqual(x, obj));
|
|
125
|
+
return;
|
|
139
126
|
}
|
|
127
|
+
});
|
|
140
128
|
|
|
141
|
-
|
|
142
|
-
let
|
|
129
|
+
if (!isEmpty(mergeValue)) {
|
|
130
|
+
let index = indexOf(objects, first(mergeWithLastValue));
|
|
131
|
+
let objectsToSearch = take(objects, index);
|
|
132
|
+
let mergeObject = last(objectsToSearch);
|
|
143
133
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
134
|
+
if (mergeObject) {
|
|
135
|
+
objectPath.set(mergeObject.Object, 'Text', mergeValue);
|
|
136
|
+
mergeValue = '';
|
|
137
|
+
}
|
|
138
|
+
}
|
|
147
139
|
|
|
148
|
-
|
|
140
|
+
// move objects to other objects
|
|
141
|
+
let mergeWithLast = filter(objects, (x) => x.Definition.MergeWithLast) as ParsingObject[];
|
|
149
142
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
154
|
-
});
|
|
143
|
+
forEachRight(mergeWithLast, (obj) => {
|
|
144
|
+
let index = indexOf(objects, obj);
|
|
145
|
+
let objectsToSearch = take(objects, index);
|
|
155
146
|
|
|
156
|
-
let
|
|
147
|
+
let mergeObject = findLast(objectsToSearch, (x) => x.Definition.Tag === obj.Definition.MergeWithLast);
|
|
157
148
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
149
|
+
if (mergeObject) {
|
|
150
|
+
SetOrCreateArray(mergeObject.Object, split(obj.Definition.Path, '.'), obj.Definition, obj.Object);
|
|
151
|
+
remove(objects, (x) => isEqual(x, obj));
|
|
152
|
+
}
|
|
153
|
+
});
|
|
162
154
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
155
|
+
let mergeWithNext = filter(objects, (x) => x.Definition.MergeWithNext) as ParsingObject[];
|
|
156
|
+
|
|
157
|
+
forEachRight(mergeWithNext, (obj) => {
|
|
158
|
+
let index = indexOf(objects, obj);
|
|
159
|
+
let objectsToSearch = slice(objects, index);
|
|
160
|
+
let mergeObject = find(objectsToSearch, (x) => x.Definition.Tag === obj.Definition.MergeWithNext);
|
|
161
|
+
|
|
162
|
+
if (mergeObject) {
|
|
163
|
+
SetOrCreateArray(mergeObject.Object, split(obj.Definition.Path, '.'), obj.Definition, obj.Object);
|
|
164
|
+
remove(objects, (x) => isEqual(x, obj));
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
// set all sub objects in object
|
|
169
|
+
forEach(objects, (o) => {
|
|
170
|
+
let obj = o as ParsingObject;
|
|
171
|
+
let partPath: string[] = [];
|
|
172
|
+
|
|
173
|
+
forEach(dropRight(obj.PropertyPath), (property: any) => {
|
|
174
|
+
if (IsEmpty(property)) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
partPath.push(property);
|
|
168
179
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
let convertedValue = {};
|
|
194
|
-
objectPath.set(convertedValue, "Value", value);
|
|
195
|
-
objectPath.set(result, partPath, convertedValue);
|
|
196
|
-
}
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
remove(obj.PropertyPath, x => isEmpty(x));
|
|
200
|
-
SetOrCreateArray(result, obj.PropertyPath, obj.Definition, obj.Object);
|
|
180
|
+
const parentPath = dropRight(partPath);
|
|
181
|
+
const parentObj = objectPath.get(result, parentPath);
|
|
182
|
+
|
|
183
|
+
if (parentPath.length > 0 && objectPath.has(result, parentPath) && isArray(parentObj)) {
|
|
184
|
+
partPath = parentPath;
|
|
185
|
+
partPath.push(`${parentObj.length - 1}`);
|
|
186
|
+
partPath.push(property);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (!objectPath.has(result, partPath)) {
|
|
190
|
+
objectPath.set(result, partPath, {});
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
let value = objectPath.get(result, partPath);
|
|
195
|
+
|
|
196
|
+
// If path value is an array, add position in array to path
|
|
197
|
+
if (isArray(value)) {
|
|
198
|
+
obj.PropertyPath.splice(indexOf(obj.PropertyPath, property) + 1, 0, `${value.length - 1}`);
|
|
199
|
+
} else if (!isObject(value) && !isArray(value)) {
|
|
200
|
+
let convertedValue = {};
|
|
201
|
+
objectPath.set(convertedValue, 'Value', value);
|
|
202
|
+
objectPath.set(result, partPath, convertedValue);
|
|
203
|
+
}
|
|
201
204
|
});
|
|
202
205
|
|
|
203
|
-
|
|
206
|
+
remove(obj.PropertyPath, (x) => isEmpty(x));
|
|
207
|
+
SetOrCreateArray(result, obj.PropertyPath, obj.Definition, obj.Object);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
return new MainObject(objects[0], result);
|
|
204
211
|
}
|
|
205
212
|
|
|
206
213
|
class MainObject {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
214
|
+
constructor(informations: ParsingObject, obj: Object) {
|
|
215
|
+
this.Informations = informations;
|
|
216
|
+
this.Result = obj;
|
|
217
|
+
}
|
|
211
218
|
|
|
212
|
-
|
|
213
|
-
|
|
219
|
+
Informations: ParsingObject;
|
|
220
|
+
Result: Object;
|
|
214
221
|
}
|
|
215
222
|
|
|
216
223
|
export function GetMainObjectIndexes(objects: ParsingObject[]) {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
224
|
+
// get all objects with level 0
|
|
225
|
+
let mainObjects = filter(objects, (x) => x.StartLevel === 0);
|
|
226
|
+
let mainObjectIndexes: number[] = [];
|
|
220
227
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
228
|
+
forEach(mainObjects, (mainObject) => {
|
|
229
|
+
mainObjectIndexes.push(indexOf(objects, mainObject));
|
|
230
|
+
});
|
|
224
231
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
for(let i = 0; i < mainObjects.length; i++) {
|
|
228
|
-
let startIndex = mainObjectIndexes[i];
|
|
229
|
-
let endIndex = 0;
|
|
230
|
-
|
|
231
|
-
if (i === mainObjects.length - 1) {
|
|
232
|
-
endIndex = objects.length;
|
|
233
|
-
}
|
|
234
|
-
else {
|
|
235
|
-
endIndex = mainObjectIndexes[i + 1];
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
mainObjectIndexObject.push({
|
|
239
|
-
StartIndex: startIndex,
|
|
240
|
-
EndIndex: endIndex
|
|
241
|
-
});
|
|
242
|
-
}
|
|
232
|
+
let mainObjectIndexObject = [];
|
|
243
233
|
|
|
244
|
-
|
|
245
|
-
|
|
234
|
+
for (let i = 0; i < mainObjects.length; i++) {
|
|
235
|
+
let startIndex = mainObjectIndexes[i];
|
|
236
|
+
let endIndex = 0;
|
|
246
237
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
238
|
+
if (i === mainObjects.length - 1) {
|
|
239
|
+
endIndex = objects.length;
|
|
240
|
+
} else {
|
|
241
|
+
endIndex = mainObjectIndexes[i + 1];
|
|
251
242
|
}
|
|
252
243
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
244
|
+
mainObjectIndexObject.push({
|
|
245
|
+
StartIndex: startIndex,
|
|
246
|
+
EndIndex: endIndex,
|
|
247
|
+
});
|
|
248
|
+
}
|
|
256
249
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
if (definition.CollectAsArray) {
|
|
260
|
-
objectPath.set(mainObject, path, [ value ]);
|
|
261
|
-
return;
|
|
262
|
-
}
|
|
250
|
+
return mainObjectIndexObject;
|
|
251
|
+
}
|
|
263
252
|
|
|
264
|
-
|
|
265
|
-
|
|
253
|
+
export function SetObject(mainObject: Object, path: string[], value: Object, definition: TagDefinition) {
|
|
254
|
+
if (path.length === 0) {
|
|
255
|
+
assignIn(mainObject, value);
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
if (objectPath.has(value, path)) {
|
|
260
|
+
value = objectPath.get(value, path);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
if (!objectPath.has(mainObject, path)) {
|
|
264
|
+
// should be array
|
|
265
|
+
if (definition.CollectAsArray) {
|
|
266
|
+
objectPath.set(mainObject, path, [value]);
|
|
267
|
+
return;
|
|
266
268
|
}
|
|
267
269
|
|
|
268
|
-
|
|
270
|
+
objectPath.set(mainObject, path, value);
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
269
273
|
|
|
270
|
-
|
|
271
|
-
objectPath.insert(mainObject, path, value, oldValue.length);
|
|
272
|
-
return;
|
|
273
|
-
}
|
|
274
|
+
let oldValue = objectPath.get(mainObject, path);
|
|
274
275
|
|
|
275
|
-
|
|
276
|
+
if (isArray(oldValue)) {
|
|
277
|
+
objectPath.insert(mainObject, path, value, oldValue.length);
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
objectPath.set(mainObject, path, [oldValue, value]);
|
|
276
282
|
}
|
|
277
283
|
|
|
278
284
|
export function SetOrCreateArray(obj: any, path: string[], definition: TagDefinition, value: any) {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
}
|
|
285
|
+
// should be a single value -> last wins
|
|
286
|
+
if (definition.IsSingleValue) {
|
|
287
|
+
if (objectPath.has(obj, path)) {
|
|
288
|
+
objectPath.del(obj, path);
|
|
284
289
|
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// if empty AND NOT type of string, ignore value
|
|
293
|
+
if (IsEmpty(value) && !(definition.ConvertTo instanceof ConvertToString)) {
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
if (!objectPath.has(obj, path)) {
|
|
298
|
+
// parent object could be a string or array, check this an create object if needed
|
|
299
|
+
let parentPath = dropRight(fclone(path));
|
|
300
|
+
if (objectPath.has(obj, parentPath)) {
|
|
301
|
+
let parentValue = objectPath.get(obj, parentPath);
|
|
302
|
+
|
|
303
|
+
if (!isObject(parentValue)) {
|
|
304
|
+
let convertedValue = {};
|
|
305
|
+
objectPath.set(convertedValue, 'Value', parentValue);
|
|
306
|
+
objectPath.set(obj, parentPath, convertedValue);
|
|
307
|
+
}
|
|
289
308
|
}
|
|
290
309
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
if (objectPath.has(obj, parentPath)) {
|
|
295
|
-
let parentValue = objectPath.get(obj, parentPath);
|
|
310
|
+
objectPath.set(obj, path, value);
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
296
313
|
|
|
297
|
-
|
|
298
|
-
let convertedValue = {};
|
|
299
|
-
objectPath.set(convertedValue, "Value", parentValue);
|
|
300
|
-
objectPath.set(obj, parentPath, convertedValue);
|
|
301
|
-
}
|
|
302
|
-
}
|
|
314
|
+
let oldValue = objectPath.get(obj, path);
|
|
303
315
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
}
|
|
316
|
+
if (definition.ConvertTo instanceof ConvertToString) {
|
|
317
|
+
let newLineCharacter = definition.ConvertTo.NewLineCharacter;
|
|
307
318
|
|
|
308
|
-
|
|
319
|
+
if (definition.ConvertTo.NewLineIfEmpty && IsEmpty(value)) {
|
|
320
|
+
value = newLineCharacter;
|
|
321
|
+
}
|
|
309
322
|
|
|
310
|
-
|
|
311
|
-
|
|
323
|
+
// ignore empty value
|
|
324
|
+
if (IsEmpty(value)) {
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
312
327
|
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
328
|
+
// concat
|
|
329
|
+
objectPath.set(obj, path, `${oldValue}${value}`);
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
316
332
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
// concat
|
|
323
|
-
objectPath.set(obj, path, `${oldValue}${value}`);
|
|
324
|
-
return;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
if (isArray(oldValue)) {
|
|
328
|
-
objectPath.insert(obj, path, value, oldValue.length);
|
|
329
|
-
return;
|
|
330
|
-
}
|
|
333
|
+
if (isArray(oldValue)) {
|
|
334
|
+
objectPath.insert(obj, path, value, oldValue.length);
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
331
337
|
|
|
332
|
-
|
|
333
|
-
}
|
|
338
|
+
objectPath.set(obj, path, [oldValue, value]);
|
|
339
|
+
}
|
package/src/common.ts
CHANGED
|
@@ -7,32 +7,32 @@ import isNaN from 'lodash/isNaN';
|
|
|
7
7
|
* Test if an string can be parsed as an number
|
|
8
8
|
* @param str the string
|
|
9
9
|
*/
|
|
10
|
-
export function IsNumber(str: string)
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
export function IsNumber(str: string): Boolean {
|
|
11
|
+
if (IsEmpty(str) || str === ' ') {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
let number = toNumber(str);
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
if (isNaN(number)) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
return isNumber(number);
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* Converts a string to an number
|
|
26
26
|
* @param str the string
|
|
27
27
|
*/
|
|
28
|
-
export function ToNumber(str: string)
|
|
29
|
-
|
|
28
|
+
export function ToNumber(str: string): number {
|
|
29
|
+
return toNumber(str);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* Tests if an string is empty
|
|
34
34
|
* @param str the string
|
|
35
35
|
*/
|
|
36
|
-
export function IsEmpty(str: string)
|
|
37
|
-
|
|
38
|
-
}
|
|
36
|
+
export function IsEmpty(str: string): Boolean {
|
|
37
|
+
return isEmpty(str);
|
|
38
|
+
}
|
package/src/console.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import yargs from 'yargs';
|
|
3
|
-
import { Convert as ConvertToJSON } from
|
|
3
|
+
import { Convert as ConvertToJSON } from './ToJSON/console';
|
|
4
4
|
|
|
5
|
-
const { hideBin } = require('yargs/helpers')
|
|
6
|
-
let argv = yargs(hideBin(process.argv)).argv
|
|
5
|
+
const { hideBin } = require('yargs/helpers');
|
|
6
|
+
let argv = yargs(hideBin(process.argv)).argv;
|
|
7
7
|
|
|
8
|
-
if (!argv.mode || argv.mode ===
|
|
9
|
-
|
|
8
|
+
if (!argv.mode || argv.mode === 'JSON') {
|
|
9
|
+
ConvertToJSON(argv);
|
|
10
|
+
} else {
|
|
11
|
+
console.log('TODO: Conversion from JS\\JSON to GEDCOM');
|
|
10
12
|
}
|
|
11
|
-
else {
|
|
12
|
-
console.log("TODO: Conversion from JS\\JSON to GEDCOM");
|
|
13
|
-
}
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import JsonParsing from
|
|
2
|
-
import ParsingOptions from
|
|
1
|
+
import JsonParsing from './ToJSON/models/Parsing';
|
|
2
|
+
import ParsingOptions from './ToJSON/models/ParsingOptions';
|
|
3
3
|
|
|
4
|
-
export {
|
|
5
|
-
JsonParsing,
|
|
6
|
-
ParsingOptions
|
|
7
|
-
}
|
|
4
|
+
export { JsonParsing, ParsingOptions };
|