This repository was archived by the owner on Oct 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfig.js
More file actions
113 lines (70 loc) · 2.84 KB
/
config.js
File metadata and controls
113 lines (70 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/**
* A class to parse user configurations
* **/
class Config {
constructor(config) {
// Store configuration JSON
this.config = config;
// Parse composite fields
this._parseCompositeFields()
}
_parseCompositeFields() {
let configFields = this.config.fields;
Object.keys(configFields).forEach((key) => {
if(configFields[key].composite) {
configFields[key].composite.map(el => {
// Capitalize current subfield
el = el.charAt(0).toUpperCase() + el.slice(1);
let newKey = key + el;
// Copy parent field
this.config.fields[newKey] = JSON.parse(JSON.stringify(configFields[key]));
// Translate subfields as principal fields
if (this.config.fields[newKey].input)
this.config.fields[newKey].input = configFields[key].input + el;
if (this.config.fields[newKey].wikidata)
this.config.fields[newKey].wikidata = configFields[key].wikidata + el;
if (this.config.fields[newKey].viaf)
this.config.fields[newKey].viaf = configFields[key].viaf + el;
if (this.config.fields[newKey].label)
this.config.fields[newKey].label = configFields[key].label + ' ' + el.toUpperCase();
delete this.config.fields[newKey].composite;
});
}
})
}
getConfig() {
return this.config;
}
getInputDictionary() {
let inputDictionary = {};
// Map config fields to get dictionary
Object.keys(this.config.fields).map(el => inputDictionary[el] = this.config.fields[el].input);
return inputDictionary;
}
getOutputDectionary() {
let outputDictionary = {};
// Map config fields to get dictionary
Object.keys(this.config.fields).map(el => outputDictionary[this.config.fields[el].input] = el);
return outputDictionary;
}
getWikidataDictionary() {
let wikidataDictionary = {};
// Map config fields to get dictionary
Object.keys(this.config.fields).map(el => wikidataDictionary[el] = this.config.fields[el].wikidata);
return wikidataDictionary;
}
getViafDictionary() {
let viafDictionary = {};
// Map config fields to get dictionary
Object.keys(this.config.fields).map(el => viafDictionary[el] = this.config.fields[el].viaf);
return viafDictionary;
}
getToFormatFields() {
return Object.keys(this.config.fields).filter(el => this.config.fields[el].format)
}
isFieldComposite(field) {
return this.config.fields[field].composite;
}
}
// Exports
exports.Config = Config;