@iebh/reflib 2.5.9 → 2.6.1

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/browser.js CHANGED
@@ -1,30 +1,30 @@
1
- import {downloadFile} from './downloadFile.js';
2
- import {formats} from './formats.js';
3
- import {getModule} from './getModule.js';
4
- import {identifyFormat} from './identifyFormat.js';
5
- import {readStream} from './readStream.js';
6
- import {uploadFile} from './uploadFile.js';
7
- import {writeStream} from './writeStream.js';
8
- import { getRefDoi } from './getRefDoi.js';
9
-
10
- export {
11
- downloadFile,
12
- formats,
13
- getModule,
14
- identifyFormat,
15
- readStream,
16
- uploadFile,
17
- writeStream,
18
- getRefDoi
19
- };
20
-
21
- export default {
22
- downloadFile,
23
- formats,
24
- getModule,
25
- identifyFormat,
26
- readStream,
27
- uploadFile,
28
- writeStream,
29
- getRefDoi
30
- };
1
+ import {downloadFile} from './downloadFile.js';
2
+ import {formats} from './formats.js';
3
+ import {getModule} from './getModule.js';
4
+ import {identifyFormat} from './identifyFormat.js';
5
+ import {readStream} from './readStream.js';
6
+ import {uploadFile} from './uploadFile.js';
7
+ import {writeStream} from './writeStream.js';
8
+ import { getRefDoi } from './getRefDoi.js';
9
+
10
+ export {
11
+ downloadFile,
12
+ formats,
13
+ getModule,
14
+ identifyFormat,
15
+ readStream,
16
+ uploadFile,
17
+ writeStream,
18
+ getRefDoi
19
+ };
20
+
21
+ export default {
22
+ downloadFile,
23
+ formats,
24
+ getModule,
25
+ identifyFormat,
26
+ readStream,
27
+ uploadFile,
28
+ writeStream,
29
+ getRefDoi
30
+ };
package/lib/default.js CHANGED
@@ -1,30 +1,30 @@
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
- import { getRefDoi } from './getRefDoi.js';
9
-
10
- export {
11
- formats,
12
- getModule,
13
- identifyFormat,
14
- readFile,
15
- readStream,
16
- writeFile,
17
- writeStream,
18
- getRefDoi
19
- };
20
-
21
- export default {
22
- formats,
23
- getModule,
24
- identifyFormat,
25
- readFile,
26
- readStream,
27
- writeFile,
28
- writeStream,
29
- getRefDoi
30
- };
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
+ import { getRefDoi } from './getRefDoi.js';
9
+
10
+ export {
11
+ formats,
12
+ getModule,
13
+ identifyFormat,
14
+ readFile,
15
+ readStream,
16
+ writeFile,
17
+ writeStream,
18
+ getRefDoi
19
+ };
20
+
21
+ export default {
22
+ formats,
23
+ getModule,
24
+ identifyFormat,
25
+ readFile,
26
+ readStream,
27
+ writeFile,
28
+ writeStream,
29
+ getRefDoi
30
+ };
@@ -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<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
- }
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
+ };