@iebh/reflib 2.1.3 → 2.2.0
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 +1 -1
- package/lib/browser.js +21 -3
- package/lib/default.js +19 -2
- package/lib/downloadFile.js +90 -0
- package/lib/writeFile.js +3 -0
- package/modules/endnoteXml.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -55,7 +55,7 @@ Each reference has the following standardized fields, these are translated from
|
|
|
55
55
|
| researchNotes | `string` | |
|
|
56
56
|
| keywords | `array<string>` | Optional list of keywords that apply to the reference |
|
|
57
57
|
| accessDate | `string` | |
|
|
58
|
-
| accession | `string` |
|
|
58
|
+
| accession | `string` | [Accession numbers spec](https://support.nlm.nih.gov/knowledgebase/article/KA-03434/en-us), can sometimes be the PubMed ID |
|
|
59
59
|
| doi | `string` | |
|
|
60
60
|
| section | `string` | |
|
|
61
61
|
| language | `string` | |
|
package/lib/browser.js
CHANGED
|
@@ -1,9 +1,27 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {downloadFile} from './downloadFile.js';
|
|
2
2
|
import {formats} from './formats.js';
|
|
3
3
|
import {getModule} from './getModule.js';
|
|
4
|
+
import {identifyFormat} from './identifyFormat.js';
|
|
4
5
|
import {readStream} from './readStream.js';
|
|
5
6
|
import {uploadFile} from './uploadFile.js';
|
|
6
7
|
import {writeStream} from './writeStream.js';
|
|
7
8
|
|
|
8
|
-
export {
|
|
9
|
-
|
|
9
|
+
export {
|
|
10
|
+
downloadFile,
|
|
11
|
+
formats,
|
|
12
|
+
getModule,
|
|
13
|
+
identifyFormat,
|
|
14
|
+
readStream,
|
|
15
|
+
uploadFile,
|
|
16
|
+
writeStream,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default {
|
|
20
|
+
downloadFile,
|
|
21
|
+
formats,
|
|
22
|
+
getModule,
|
|
23
|
+
identifyFormat,
|
|
24
|
+
readStream,
|
|
25
|
+
uploadFile,
|
|
26
|
+
writeStream,
|
|
27
|
+
};
|
package/lib/default.js
CHANGED
|
@@ -6,5 +6,22 @@ import {readFile} from './readFile.js';
|
|
|
6
6
|
import {writeStream} from './writeStream.js';
|
|
7
7
|
import {writeFile} from './writeFile.js';
|
|
8
8
|
|
|
9
|
-
export {
|
|
10
|
-
|
|
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
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
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
|
+
*
|
|
13
|
+
* @returns {Promise} A promise which will resolve when the file download has completed
|
|
14
|
+
*/
|
|
15
|
+
export function downloadFile(refs, options) {
|
|
16
|
+
let settings = {
|
|
17
|
+
filename: 'References.xml',
|
|
18
|
+
writeStreamOptions: {},
|
|
19
|
+
...options,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
return Promise.resolve()
|
|
23
|
+
// Identify module from filename {{{
|
|
24
|
+
.then(()=> {
|
|
25
|
+
let module = identifyFormat(settings.filename);
|
|
26
|
+
if (!module) throw new Error(`Unsupported Reflib filename "${settings.filename}"`);
|
|
27
|
+
return module;
|
|
28
|
+
})
|
|
29
|
+
// }}}
|
|
30
|
+
// Create stream {{{
|
|
31
|
+
.then(async (module) => {
|
|
32
|
+
let blobData = [];
|
|
33
|
+
let writableStream = new WritableStream({
|
|
34
|
+
write(chunk) {
|
|
35
|
+
blobData.push(chunk);
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
let writer = writableStream.getWriter();
|
|
40
|
+
|
|
41
|
+
// Map end->close to keep browser compatibility with Node
|
|
42
|
+
writer.end = async (cb) => {
|
|
43
|
+
await writer.close();
|
|
44
|
+
cb();
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
let streamer = await writeStream(module.id, writer, settings.writeStreamOptions);
|
|
48
|
+
|
|
49
|
+
return {blobData, streamer};
|
|
50
|
+
})
|
|
51
|
+
// }}}
|
|
52
|
+
// Flush all references into the stream {{{
|
|
53
|
+
.then(async ({blobData, streamer}) => {
|
|
54
|
+
// Start stream
|
|
55
|
+
await streamer.start();
|
|
56
|
+
|
|
57
|
+
// Write all references as a promise chain
|
|
58
|
+
await refs.reduce((promiseChain, ref) =>
|
|
59
|
+
promiseChain.then(()=>
|
|
60
|
+
streamer.write(ref)
|
|
61
|
+
)
|
|
62
|
+
, Promise.resolve());
|
|
63
|
+
|
|
64
|
+
// End stream
|
|
65
|
+
await streamer.end();
|
|
66
|
+
|
|
67
|
+
return blobData;
|
|
68
|
+
})
|
|
69
|
+
// }}}
|
|
70
|
+
// Convert blobData array to a Blob {{{
|
|
71
|
+
.then(blobData => {
|
|
72
|
+
return new Blob(blobData);
|
|
73
|
+
})
|
|
74
|
+
// }}}
|
|
75
|
+
// Download Blob
|
|
76
|
+
.then(blob => {
|
|
77
|
+
let url = URL.createObjectURL(blob);
|
|
78
|
+
let aEl = document.createElement('a');
|
|
79
|
+
aEl.href = url;
|
|
80
|
+
aEl.download = settings.filename;
|
|
81
|
+
document.body.appendChild(aEl);
|
|
82
|
+
aEl.click();
|
|
83
|
+
|
|
84
|
+
// Clean up DOM
|
|
85
|
+
document.body.removeChild(aEl);
|
|
86
|
+
URL.revokeObjectURL(url);
|
|
87
|
+
// }}}
|
|
88
|
+
})
|
|
89
|
+
// }}}
|
|
90
|
+
}
|
package/lib/writeFile.js
CHANGED
|
@@ -4,9 +4,12 @@ import {writeStream} from './writeStream.js';
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Write a file to disk via the appropriate module
|
|
7
|
+
*
|
|
7
8
|
* @param {string} path The file path to write, the module to use will be determined from this
|
|
9
|
+
* @param {Array<Ref>} Collection of references to write
|
|
8
10
|
* @param {Object} [options] Additional options to pass to the file writer
|
|
9
11
|
* @param {string} [options.module] The module to use if overriding from the file path
|
|
12
|
+
*
|
|
10
13
|
* @returns {Promise} A promise which resolves when the operation has completed
|
|
11
14
|
*/
|
|
12
15
|
export function writeFile(path, refs, options) {
|
package/modules/endnoteXml.js
CHANGED
|
@@ -136,8 +136,6 @@ export function readStream(stream) {
|
|
|
136
136
|
})
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
-
console.error("This line should not be hit!");
|
|
140
|
-
|
|
141
139
|
})
|
|
142
140
|
|
|
143
141
|
return emitter;
|
|
@@ -215,6 +213,7 @@ export function writeStream(stream, options) {
|
|
|
215
213
|
['database', 'remote-database-name'],
|
|
216
214
|
['doi', 'electronic-resource-num'],
|
|
217
215
|
['isbn', 'isbn'],
|
|
216
|
+
['accessionNum', 'accession-num'],
|
|
218
217
|
['label', 'label'],
|
|
219
218
|
['language', 'language'],
|
|
220
219
|
['notes', 'notes'],
|
|
@@ -357,6 +356,7 @@ export let translations = {
|
|
|
357
356
|
{rl: 'volume', raw: 'volume'},
|
|
358
357
|
{rl: 'number', raw: 'number'},
|
|
359
358
|
{rl: 'isbn', raw: 'isbn'},
|
|
359
|
+
{rl: 'accessionNum', raw: 'accessionNum'},
|
|
360
360
|
{rl: 'abstract', raw: 'abstract'},
|
|
361
361
|
{rl: 'label', raw: 'label'},
|
|
362
362
|
{rl: 'caption', raw: 'caption'},
|