-
Notifications
You must be signed in to change notification settings - Fork 21
/
schema.js
65 lines (57 loc) · 2.19 KB
/
schema.js
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
/*
***** BEGIN LICENSE BLOCK *****
Copyright © 2021 Corporation for Digital Scholarship
Vienna, Virginia, USA
http://zotero.org
This file is part of Zotero.
Zotero is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Zotero is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Zotero. If not, see <http://www.gnu.org/licenses/>.
***** END LICENSE BLOCK *****
*/
const Schema = {
/**
* This must be called before translation
* @param data - Zotero schema from https://github.com/zotero/zotero-schema or
* https://api.zotero.org/schema
*/
init(data) {
if (typeof data == 'string') {
data = JSON.parse(data);
}
// CSL type/field mappings used by Utilities.Item.itemFromCSLJSON()
Zotero.Schema.CSL_TYPE_MAPPINGS = {};
Zotero.Schema.CSL_TYPE_MAPPINGS_REVERSE = {};
for (let cslType in data.csl.types) {
for (let zoteroType of data.csl.types[cslType]) {
Zotero.Schema.CSL_TYPE_MAPPINGS[zoteroType] = cslType;
}
Zotero.Schema.CSL_TYPE_MAPPINGS_REVERSE[cslType] = [...data.csl.types[cslType]];
}
Zotero.Schema.CSL_TEXT_MAPPINGS = data.csl.fields.text;
Zotero.Schema.CSL_DATE_MAPPINGS = data.csl.fields.date;
Zotero.Schema.CSL_NAME_MAPPINGS = data.csl.names;
Zotero.Schema.CSL_FIELD_MAPPINGS_REVERSE = {};
for (let cslField in data.csl.fields.text) {
for (let zoteroField of data.csl.fields.text[cslField]) {
Zotero.Schema.CSL_FIELD_MAPPINGS_REVERSE[zoteroField] = cslField;
}
}
for (let cslField in data.csl.fields.date) {
let zoteroField = data.csl.fields.date[cslField];
Zotero.Schema.CSL_FIELD_MAPPINGS_REVERSE[zoteroField] = cslField;
}
}
};
if (typeof module != 'undefined') {
module.exports = Schema;
} else if (typeof Zotero != 'undefined') {
Zotero.Schema = Schema;
}