@iebh/reflib 2.4.2 → 2.4.3

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/lib/default.js CHANGED
@@ -1,27 +1,27 @@
1
- import {identifyFormat} from './identifyFormat.js';
2
- import {formats} from './formats.js';
3
- import {getModule} from './getModule.js';
4
- import {readStream} from './readStream.js';
5
- import {readFile} from './readFile.js';
6
- import {writeStream} from './writeStream.js';
7
- import {writeFile} from './writeFile.js';
8
-
9
- export {
10
- formats,
11
- getModule,
12
- identifyFormat,
13
- readFile,
14
- readStream,
15
- writeFile,
16
- writeStream,
17
- };
18
-
19
- export default {
20
- formats,
21
- getModule,
22
- identifyFormat,
23
- readFile,
24
- readStream,
25
- writeFile,
26
- writeStream,
27
- };
1
+ import {identifyFormat} from './identifyFormat.js';
2
+ import {formats} from './formats.js';
3
+ import {getModule} from './getModule.js';
4
+ import {readStream} from './readStream.js';
5
+ import {readFile} from './readFile.js';
6
+ import {writeStream} from './writeStream.js';
7
+ import {writeFile} from './writeFile.js';
8
+
9
+ export {
10
+ formats,
11
+ getModule,
12
+ identifyFormat,
13
+ readFile,
14
+ readStream,
15
+ writeFile,
16
+ writeStream,
17
+ };
18
+
19
+ export default {
20
+ formats,
21
+ getModule,
22
+ identifyFormat,
23
+ readFile,
24
+ readStream,
25
+ writeFile,
26
+ writeStream,
27
+ };
@@ -1,94 +1,94 @@
1
- import {identifyFormat} from './identifyFormat.js';
2
- import {writeStream} from './writeStream.js';
3
-
4
- /**
5
- * Prompt the user for a file to save as and Write a given array of citations
6
- *
7
- * @param {Array<Ref>} Collection of references to write
8
- *
9
- * @param {Object} [options] Additional options when prompting the user
10
- * @param {String} [options.filename='References.xml'] The filename to download
11
- * @param {Object} [options.writeStreamOptions] Additional options for the subsequent `writeStream` internal call
12
- * @param {Object} [options.promptDownload=true] Prompt the user to save the file, if falsy this returns the Blob file content instead of asking the user where to save it
13
- *
14
- * @returns {Promise|Promise<Blob>} A promise which will resolve when the file download has completed or (if `!promptDownload`) with the blob contents
15
- */
16
- export function downloadFile(refs, options) {
17
- let settings = {
18
- filename: 'References.xml',
19
- writeStreamOptions: {},
20
- promptDownload: true,
21
- ...options,
22
- };
23
-
24
- return Promise.resolve()
25
- // Identify module from filename {{{
26
- .then(()=> {
27
- let module = identifyFormat(settings.filename);
28
- if (!module) throw new Error(`Unsupported Reflib filename "${settings.filename}"`);
29
- return module;
30
- })
31
- // }}}
32
- // Create stream {{{
33
- .then(async (module) => {
34
- let blobData = [];
35
- let writableStream = new WritableStream({
36
- write(chunk) {
37
- blobData.push(chunk);
38
- },
39
- });
40
-
41
- let writer = writableStream.getWriter();
42
-
43
- // Map end->close to keep browser compatibility with Node
44
- writer.end = async (cb) => {
45
- await writer.close();
46
- cb();
47
- };
48
-
49
- let streamer = await writeStream(module.id, writer, settings.writeStreamOptions);
50
-
51
- return {blobData, streamer};
52
- })
53
- // }}}
54
- // Flush all references into the stream {{{
55
- .then(async ({blobData, streamer}) => {
56
- // Start stream
57
- await streamer.start();
58
-
59
- // Write all references as a promise chain
60
- await refs.reduce((promiseChain, ref) =>
61
- promiseChain.then(()=>
62
- streamer.write(ref)
63
- )
64
- , Promise.resolve());
65
-
66
- // End stream
67
- await streamer.end();
68
-
69
- return blobData;
70
- })
71
- // }}}
72
- // Convert blobData array to a Blob {{{
73
- .then(blobData => {
74
- return new Blob(blobData);
75
- })
76
- // }}}
77
- // Download Blob
78
- .then(blob => {
79
- if (!settings.promptDownload) return blob;
80
-
81
- let url = URL.createObjectURL(blob);
82
- let aEl = document.createElement('a');
83
- aEl.href = url;
84
- aEl.download = settings.filename;
85
- document.body.appendChild(aEl);
86
- aEl.click();
87
-
88
- // Clean up DOM
89
- document.body.removeChild(aEl);
90
- URL.revokeObjectURL(url);
91
- // }}}
92
- })
93
- // }}}
94
- }
1
+ import {identifyFormat} from './identifyFormat.js';
2
+ import {writeStream} from './writeStream.js';
3
+
4
+ /**
5
+ * Prompt the user for a file to save as and Write a given array of citations
6
+ *
7
+ * @param {Array<ReflibRef>} refs Collection of references to write
8
+ *
9
+ * @param {Object} [options] Additional options when prompting the user
10
+ * @param {String} [options.filename='References.xml'] The filename to download
11
+ * @param {Object} [options.writeStreamOptions] Additional options for the subsequent `writeStream` internal call
12
+ * @param {Object} [options.promptDownload=true] Prompt the user to save the file, if falsy this returns the Blob file content instead of asking the user where to save it
13
+ *
14
+ * @returns {Promise|Promise<Blob>} A promise which will resolve when the file download has completed or (if `!promptDownload`) with the blob contents
15
+ */
16
+ export function downloadFile(refs, options) {
17
+ let settings = {
18
+ filename: 'References.xml',
19
+ writeStreamOptions: {},
20
+ promptDownload: true,
21
+ ...options,
22
+ };
23
+
24
+ return Promise.resolve()
25
+ // Identify module from filename {{{
26
+ .then(()=> {
27
+ let module = identifyFormat(settings.filename);
28
+ if (!module) throw new Error(`Unsupported Reflib filename "${settings.filename}"`);
29
+ return module;
30
+ })
31
+ // }}}
32
+ // Create stream {{{
33
+ .then(async (module) => {
34
+ let blobData = [];
35
+ let writableStream = new WritableStream({
36
+ write(chunk) {
37
+ blobData.push(chunk);
38
+ },
39
+ });
40
+
41
+ let writer = writableStream.getWriter();
42
+
43
+ // Map end->close to keep browser compatibility with Node
44
+ writer.end = async (cb) => {
45
+ await writer.close();
46
+ cb();
47
+ };
48
+
49
+ let streamer = await writeStream(module.id, writer, settings.writeStreamOptions);
50
+
51
+ return {blobData, streamer};
52
+ })
53
+ // }}}
54
+ // Flush all references into the stream {{{
55
+ .then(async ({blobData, streamer}) => {
56
+ // Start stream
57
+ await streamer.start();
58
+
59
+ // Write all references as a promise chain
60
+ await refs.reduce((promiseChain, ref) =>
61
+ promiseChain.then(()=>
62
+ streamer.write(ref)
63
+ )
64
+ , Promise.resolve());
65
+
66
+ // End stream
67
+ await streamer.end();
68
+
69
+ return blobData;
70
+ })
71
+ // }}}
72
+ // Convert blobData array to a Blob {{{
73
+ .then(blobData => {
74
+ return new Blob(blobData);
75
+ })
76
+ // }}}
77
+ // Download Blob
78
+ .then(blob => {
79
+ if (!settings.promptDownload) return blob;
80
+
81
+ let url = URL.createObjectURL(blob);
82
+ let aEl = document.createElement('a');
83
+ aEl.href = url;
84
+ aEl.download = settings.filename;
85
+ document.body.appendChild(aEl);
86
+ aEl.click();
87
+
88
+ // Clean up DOM
89
+ document.body.removeChild(aEl);
90
+ URL.revokeObjectURL(url);
91
+ // }}}
92
+ })
93
+ // }}}
94
+ }
package/lib/fields.js CHANGED
@@ -1,158 +1,158 @@
1
- /**
2
- * Field definitions for Reflib citations
3
- * @type {Object} An object lookup where each key represents a field within a citation
4
- * @property {string} type A TypeScript compatible type for that field
5
- * @property {array<string>} [value] Possible values if the type is restricted
6
- */
7
- export let fields = {
8
- recNumber: {
9
- type: 'string',
10
- },
11
- type: {
12
- type: 'string',
13
- values: [
14
- 'aggregatedDatabase',
15
- 'ancientText',
16
- 'artwork',
17
- 'audioVisualMaterial',
18
- 'bill',
19
- 'blog',
20
- 'book',
21
- 'bookSection',
22
- 'case',
23
- 'catalog',
24
- 'chartOrTable',
25
- 'classicalWork',
26
- 'computerProgram',
27
- 'conferencePaper',
28
- 'conferenceProceedings',
29
- 'dataset',
30
- 'dictionary',
31
- 'editedBook',
32
- 'electronicArticle',
33
- 'electronicBook',
34
- 'electronicBookSection',
35
- 'encyclopedia',
36
- 'equation',
37
- 'figure',
38
- 'filmOrBroadcast',
39
- 'generic',
40
- 'governmentDocument',
41
- 'grant',
42
- 'hearing',
43
- 'journalArticle',
44
- 'legalRuleOrRegulation',
45
- 'agazineArticle',
46
- 'manuscript',
47
- 'map',
48
- 'music',
49
- 'newspaperArticle',
50
- 'onlineDatabase',
51
- 'onlineMultimedia',
52
- 'pamphlet',
53
- 'patent',
54
- 'personalCommunication',
55
- 'report',
56
- 'serial',
57
- 'standard',
58
- 'statute',
59
- 'thesis',
60
- 'unknown',
61
- 'unpublished',
62
- 'web',
63
- ],
64
- },
65
- title: {
66
- type: 'string',
67
- },
68
- journal: {
69
- type: 'string',
70
- },
71
- authors: {
72
- type: 'array<string>',
73
- },
74
- date: {
75
- type: 'string',
76
- },
77
- urls: {
78
- type: 'array<string>',
79
- },
80
- pages: {
81
- type: 'string',
82
- },
83
- volume: {
84
- type: 'string',
85
- },
86
- number: {
87
- type: 'string',
88
- },
89
- isbn: {
90
- type: 'string',
91
- },
92
- abstract: {
93
- type: 'string',
94
- },
95
- label: {
96
- type: 'string',
97
- },
98
- caption: {
99
- type: 'string',
100
- },
101
- notes: {
102
- type: 'string',
103
- },
104
- address: {
105
- type: 'string',
106
- },
107
- researchNotes: {
108
- type: 'string',
109
- },
110
- keywords: {
111
- type: 'array<string>',
112
- },
113
- accessDate: {
114
- type: 'string',
115
- },
116
- accession: {
117
- type: 'string',
118
- },
119
- doi: {
120
- type: 'string',
121
- },
122
- section: {
123
- type: 'string',
124
- },
125
- language: {
126
- type: 'string',
127
- },
128
- databaseProvider: {
129
- type: 'string',
130
- },
131
- database: {
132
- type: 'string',
133
- },
134
- workType: {
135
- type: 'string',
136
- },
137
- custom1: {
138
- type: 'string',
139
- },
140
- custom2: {
141
- type: 'string',
142
- },
143
- custom3: {
144
- type: 'string',
145
- },
146
- custom4: {
147
- type: 'string',
148
- },
149
- custom5: {
150
- type: 'string',
151
- },
152
- custom6: {
153
- type: 'string',
154
- },
155
- custom7: {
156
- type: 'string',
157
- },
158
- };
1
+ /**
2
+ * Field definitions for Reflib citations
3
+ * @type {Object} An object lookup where each key represents a field within a citation
4
+ * @property {string} type A TypeScript compatible type for that field
5
+ * @property {array<string>} [value] Possible values if the type is restricted
6
+ */
7
+ export let fields = {
8
+ recNumber: {
9
+ type: 'string',
10
+ },
11
+ type: {
12
+ type: 'string',
13
+ values: [
14
+ 'aggregatedDatabase',
15
+ 'ancientText',
16
+ 'artwork',
17
+ 'audioVisualMaterial',
18
+ 'bill',
19
+ 'blog',
20
+ 'book',
21
+ 'bookSection',
22
+ 'case',
23
+ 'catalog',
24
+ 'chartOrTable',
25
+ 'classicalWork',
26
+ 'computerProgram',
27
+ 'conferencePaper',
28
+ 'conferenceProceedings',
29
+ 'dataset',
30
+ 'dictionary',
31
+ 'editedBook',
32
+ 'electronicArticle',
33
+ 'electronicBook',
34
+ 'electronicBookSection',
35
+ 'encyclopedia',
36
+ 'equation',
37
+ 'figure',
38
+ 'filmOrBroadcast',
39
+ 'generic',
40
+ 'governmentDocument',
41
+ 'grant',
42
+ 'hearing',
43
+ 'journalArticle',
44
+ 'legalRuleOrRegulation',
45
+ 'agazineArticle',
46
+ 'manuscript',
47
+ 'map',
48
+ 'music',
49
+ 'newspaperArticle',
50
+ 'onlineDatabase',
51
+ 'onlineMultimedia',
52
+ 'pamphlet',
53
+ 'patent',
54
+ 'personalCommunication',
55
+ 'report',
56
+ 'serial',
57
+ 'standard',
58
+ 'statute',
59
+ 'thesis',
60
+ 'unknown',
61
+ 'unpublished',
62
+ 'web',
63
+ ],
64
+ },
65
+ title: {
66
+ type: 'string',
67
+ },
68
+ journal: {
69
+ type: 'string',
70
+ },
71
+ authors: {
72
+ type: 'array<string>',
73
+ },
74
+ date: {
75
+ type: 'string',
76
+ },
77
+ urls: {
78
+ type: 'array<string>',
79
+ },
80
+ pages: {
81
+ type: 'string',
82
+ },
83
+ volume: {
84
+ type: 'string',
85
+ },
86
+ number: {
87
+ type: 'string',
88
+ },
89
+ isbn: {
90
+ type: 'string',
91
+ },
92
+ abstract: {
93
+ type: 'string',
94
+ },
95
+ label: {
96
+ type: 'string',
97
+ },
98
+ caption: {
99
+ type: 'string',
100
+ },
101
+ notes: {
102
+ type: 'string',
103
+ },
104
+ address: {
105
+ type: 'string',
106
+ },
107
+ researchNotes: {
108
+ type: 'string',
109
+ },
110
+ keywords: {
111
+ type: 'array<string>',
112
+ },
113
+ accessDate: {
114
+ type: 'string',
115
+ },
116
+ accession: {
117
+ type: 'string',
118
+ },
119
+ doi: {
120
+ type: 'string',
121
+ },
122
+ section: {
123
+ type: 'string',
124
+ },
125
+ language: {
126
+ type: 'string',
127
+ },
128
+ databaseProvider: {
129
+ type: 'string',
130
+ },
131
+ database: {
132
+ type: 'string',
133
+ },
134
+ workType: {
135
+ type: 'string',
136
+ },
137
+ custom1: {
138
+ type: 'string',
139
+ },
140
+ custom2: {
141
+ type: 'string',
142
+ },
143
+ custom3: {
144
+ type: 'string',
145
+ },
146
+ custom4: {
147
+ type: 'string',
148
+ },
149
+ custom5: {
150
+ type: 'string',
151
+ },
152
+ custom6: {
153
+ type: 'string',
154
+ },
155
+ custom7: {
156
+ type: 'string',
157
+ },
158
+ };
package/lib/formats.js CHANGED
@@ -1,61 +1,61 @@
1
- /**
2
- * Lookup table of various citation file formats
3
- * @type {array<Object>} A collection of Reflib supported file formats
4
- * @property {string} title The long form title of the format
5
- * @property {string} titleShort Shorter title of the format
6
- * @property {string} input Input format required by parser
7
- * @property {string} output Output format required by formatter
8
- * @property {array>string>} ext File extensions of this format, the first entry is generally used as the output default
9
- * @property {boolean} canRead Whether the format is supported when reading a citation library
10
- * @property {boolean} canWrite Whether the format is supported when writing a citation library
11
- */
12
- export let formats = {
13
- csv: {
14
- id: 'csv',
15
- title: 'Comma Seperated Values',
16
- titleShort: 'CSV',
17
- ext: ['.csv'],
18
- canRead: false,
19
- canWrite: false,
20
- },
21
- endnoteXml: {
22
- id: 'endnoteXml',
23
- title: 'EndNoteXML',
24
- titleShort: 'EndNoteXML',
25
- ext: ['.xml'],
26
- canRead: true,
27
- canWrite: true,
28
- },
29
- json: {
30
- id: 'json',
31
- title: 'JSON',
32
- titleShort: 'JSON',
33
- ext: ['.json'],
34
- canRead: true,
35
- canWrite: true,
36
- },
37
- medline: {
38
- id: 'medline',
39
- title: 'MEDLINE / PubMed',
40
- titleShort: 'MEDLINE',
41
- ext: ['.nbib'],
42
- canRead: true,
43
- canWrite: true,
44
- },
45
- ris: {
46
- id: 'ris',
47
- title: 'RIS',
48
- titleShort: 'RIS',
49
- ext: ['.ris','.txt'],
50
- canRead: true,
51
- canWrite: true,
52
- },
53
- tsv: {
54
- id: 'tsv',
55
- title: 'Tab Seperated Values',
56
- titleShort: 'TSV',
57
- ext: ['.tsv'],
58
- canRead: false,
59
- canWrite: false,
60
- },
61
- }
1
+ /**
2
+ * Lookup table of various citation file formats
3
+ * @type {array<Object>} A collection of Reflib supported file formats
4
+ * @property {string} title The long form title of the format
5
+ * @property {string} titleShort Shorter title of the format
6
+ * @property {string} input Input format required by parser
7
+ * @property {string} output Output format required by formatter
8
+ * @property {Array<String>} ext File extensions of this format, the first entry is generally used as the output default
9
+ * @property {boolean} canRead Whether the format is supported when reading a citation library
10
+ * @property {boolean} canWrite Whether the format is supported when writing a citation library
11
+ */
12
+ export let formats = {
13
+ csv: {
14
+ id: 'csv',
15
+ title: 'Comma Seperated Values',
16
+ titleShort: 'CSV',
17
+ ext: ['.csv'],
18
+ canRead: false,
19
+ canWrite: false,
20
+ },
21
+ endnoteXml: {
22
+ id: 'endnoteXml',
23
+ title: 'EndNoteXML',
24
+ titleShort: 'EndNoteXML',
25
+ ext: ['.xml'],
26
+ canRead: true,
27
+ canWrite: true,
28
+ },
29
+ json: {
30
+ id: 'json',
31
+ title: 'JSON',
32
+ titleShort: 'JSON',
33
+ ext: ['.json'],
34
+ canRead: true,
35
+ canWrite: true,
36
+ },
37
+ medline: {
38
+ id: 'medline',
39
+ title: 'MEDLINE / PubMed',
40
+ titleShort: 'MEDLINE',
41
+ ext: ['.nbib'],
42
+ canRead: true,
43
+ canWrite: true,
44
+ },
45
+ ris: {
46
+ id: 'ris',
47
+ title: 'RIS',
48
+ titleShort: 'RIS',
49
+ ext: ['.ris','.txt'],
50
+ canRead: true,
51
+ canWrite: true,
52
+ },
53
+ tsv: {
54
+ id: 'tsv',
55
+ title: 'Tab Seperated Values',
56
+ titleShort: 'TSV',
57
+ ext: ['.tsv'],
58
+ canRead: false,
59
+ canWrite: false,
60
+ },
61
+ }