@iebh/reflib 2.7.2 → 2.8.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/.ignore +1 -1
- package/LICENSE +20 -20
- package/README.md +297 -274
- package/app.js +87 -0
- package/lib/browser.js +30 -30
- package/lib/default.js +30 -30
- package/lib/downloadFile.js +94 -94
- package/lib/fields.js +158 -158
- package/lib/formats.js +85 -85
- package/lib/getModule.js +39 -39
- package/lib/getRefDoi.js +16 -16
- package/lib/identifyFormat.js +13 -13
- package/lib/readFile.js +63 -63
- package/lib/readStream.js +21 -21
- package/lib/uploadFile.js +71 -71
- package/lib/writeFile.js +32 -32
- package/lib/writeStream.js +16 -16
- package/modules/bibtex.js +401 -401
- package/modules/default.js +7 -7
- package/modules/endnoteEnl.js +237 -237
- package/modules/endnoteEnlX.js +85 -85
- package/modules/endnoteXml.js +410 -474
- package/modules/interface.js +47 -47
- package/modules/json.js +109 -79
- package/modules/medline.js +638 -638
- package/modules/ris.js +383 -383
- package/modules/shims/JSONStream-browser.js +43 -43
- package/modules/shims/WritableStream-browser.js +52 -52
- package/package.json +68 -66
- package/shared/camelCase.js +17 -17
- package/shared/emitter.js +23 -23
- package/shared/parseArgs.js +104 -0
- package/shared/streamEmitter.js +61 -61
package/modules/interface.js
CHANGED
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generic module interface
|
|
3
|
-
* This file serves no purpose other than to document the methods that each module can itself expose
|
|
4
|
-
*/
|
|
5
|
-
/* eslint-disable jsdoc/require-returns-check, no-unused-vars */
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Provide the low-level function for a module to read a stream and emit refs
|
|
10
|
-
* @param {stream.Readable} stream Input stream to read from
|
|
11
|
-
* @param {Object} [options] Additional options to use when parsing
|
|
12
|
-
* @returns {EventEmitter} EventEmitter(-like) that should emit the below events
|
|
13
|
-
*
|
|
14
|
-
* @emits ref Emitted with a single ref object when found
|
|
15
|
-
* @emits end Emitted when parsing has completed
|
|
16
|
-
* @emits error Emitted when an error has been raised
|
|
17
|
-
* @emits progress Emitted as (bytesRead) when reading a stream
|
|
18
|
-
*/
|
|
19
|
-
export function readStream(stream, options) {
|
|
20
|
-
// Stub
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Provide the low-level function for a module to write a stream
|
|
26
|
-
* @param {stream.Writable} stream Output stream to write to
|
|
27
|
-
* @param {array<Object>} refs Collection of refs to write
|
|
28
|
-
* @param {Object} [options] Additional options to use when writing
|
|
29
|
-
*
|
|
30
|
-
* @returns {Object} An object which exposes methods to call to start, write and end the writing process. All methods MUST return a Promise
|
|
31
|
-
* @property {function<Promise>} start Function to call when beginning to write
|
|
32
|
-
* @property {function<Promise>} write Function called as `(ref)` when writing a single ref
|
|
33
|
-
* @property {function<promise>} [middle] Function to call after `write()` for each reference if the reference is NOT last, this works similar to `Array.prototype.join()`
|
|
34
|
-
* @property {function<Promise>} end Function to call when finishing writing, must resolve its Promise when the stream has closed successfully
|
|
35
|
-
*/
|
|
36
|
-
export function writeStream(stream, refs, options) {
|
|
37
|
-
// Stub
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Function to run to set up any additional data before the module is needed
|
|
43
|
-
* This is generally used by worker functions which construct maps from collections for efficiency purposes
|
|
44
|
-
*/
|
|
45
|
-
export function setup() {
|
|
46
|
-
// Stub
|
|
47
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Generic module interface
|
|
3
|
+
* This file serves no purpose other than to document the methods that each module can itself expose
|
|
4
|
+
*/
|
|
5
|
+
/* eslint-disable jsdoc/require-returns-check, no-unused-vars */
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Provide the low-level function for a module to read a stream and emit refs
|
|
10
|
+
* @param {stream.Readable} stream Input stream to read from
|
|
11
|
+
* @param {Object} [options] Additional options to use when parsing
|
|
12
|
+
* @returns {EventEmitter} EventEmitter(-like) that should emit the below events
|
|
13
|
+
*
|
|
14
|
+
* @emits ref Emitted with a single ref object when found
|
|
15
|
+
* @emits end Emitted when parsing has completed
|
|
16
|
+
* @emits error Emitted when an error has been raised
|
|
17
|
+
* @emits progress Emitted as (bytesRead) when reading a stream
|
|
18
|
+
*/
|
|
19
|
+
export function readStream(stream, options) {
|
|
20
|
+
// Stub
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Provide the low-level function for a module to write a stream
|
|
26
|
+
* @param {stream.Writable} stream Output stream to write to
|
|
27
|
+
* @param {array<Object>} refs Collection of refs to write
|
|
28
|
+
* @param {Object} [options] Additional options to use when writing
|
|
29
|
+
*
|
|
30
|
+
* @returns {Object} An object which exposes methods to call to start, write and end the writing process. All methods MUST return a Promise
|
|
31
|
+
* @property {function<Promise>} start Function to call when beginning to write
|
|
32
|
+
* @property {function<Promise>} write Function called as `(ref)` when writing a single ref
|
|
33
|
+
* @property {function<promise>} [middle] Function to call after `write()` for each reference if the reference is NOT last, this works similar to `Array.prototype.join()`
|
|
34
|
+
* @property {function<Promise>} end Function to call when finishing writing, must resolve its Promise when the stream has closed successfully
|
|
35
|
+
*/
|
|
36
|
+
export function writeStream(stream, refs, options) {
|
|
37
|
+
// Stub
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Function to run to set up any additional data before the module is needed
|
|
43
|
+
* This is generally used by worker functions which construct maps from collections for efficiency purposes
|
|
44
|
+
*/
|
|
45
|
+
export function setup() {
|
|
46
|
+
// Stub
|
|
47
|
+
}
|
package/modules/json.js
CHANGED
|
@@ -1,79 +1,109 @@
|
|
|
1
|
-
import Emitter from '../shared/emitter.js';
|
|
2
|
-
// This import is overwritten by the 'browser' field in package.json with the shimmed version
|
|
3
|
-
import JSONStream from 'JSONStream';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
let
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
nodeJSONStream
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
nodeJSONStream.on('
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* @param {
|
|
49
|
-
* @param {
|
|
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
|
-
|
|
1
|
+
import Emitter from '../shared/emitter.js';
|
|
2
|
+
// This import is overwritten by the 'browser' field in package.json with the shimmed version
|
|
3
|
+
import JSONStream from 'JSONStream';
|
|
4
|
+
import sortKeys from '@momsfriendlydevco/sort-keys';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Read a JSON stream and emit references
|
|
8
|
+
* @see modules/interface.js
|
|
9
|
+
*
|
|
10
|
+
* @param {Stream} stream Stream primative to encapsulate
|
|
11
|
+
*
|
|
12
|
+
* @returns {Object} A readable stream analogue defined in `modules/interface.js`
|
|
13
|
+
*/
|
|
14
|
+
export function readStream(stream) {
|
|
15
|
+
let recNumber = 1;
|
|
16
|
+
let emitter = Emitter();
|
|
17
|
+
|
|
18
|
+
// Queue up the parser in the next tick (so we can return the emitter first)
|
|
19
|
+
setTimeout(()=> {
|
|
20
|
+
stream.on('data', ()=> emitter.emit('progress', stream.bytesRead));
|
|
21
|
+
|
|
22
|
+
if (typeof stream.pipe === 'function') {
|
|
23
|
+
// On node.js
|
|
24
|
+
const nodeJSONStream = JSONStream.parse('*')
|
|
25
|
+
nodeJSONStream.on('data', ref => emitter.emit('ref', {
|
|
26
|
+
recNumber: recNumber++,
|
|
27
|
+
...ref,
|
|
28
|
+
}))
|
|
29
|
+
nodeJSONStream.on('end', ()=> emitter.emit('end'))
|
|
30
|
+
nodeJSONStream.on('error', emitter.emit.bind('error'));
|
|
31
|
+
stream.pipe(nodeJSONStream)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
else {
|
|
35
|
+
console.error('Error with stream, check "streamEmitter.js" if on browser')
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
return emitter;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Write to a stream object
|
|
45
|
+
*
|
|
46
|
+
* @see modules/interface.js
|
|
47
|
+
*
|
|
48
|
+
* @param {Steam} [stream] The stream to write to
|
|
49
|
+
* @param {Object} [options] Additional options to use when parsing
|
|
50
|
+
* @param {String} [options.indent=2] The Indentation option, specify number of space indents or the literal string to indent by (i.e. `\t`)
|
|
51
|
+
* @param {String} [options.lineSuffix='\n'] Optional line suffix for each output line of JSON
|
|
52
|
+
* @param {Object} [options.sortKeys] Optional options object passed to `sort-keys` to tidy up the output. If omitted the reference is used as is
|
|
53
|
+
*
|
|
54
|
+
* @returns {Object} A writable stream analogue defined in `modules/interface.js`
|
|
55
|
+
*/
|
|
56
|
+
export function writeStream(stream, options) {
|
|
57
|
+
let settings = {
|
|
58
|
+
lineSuffix: '\n',
|
|
59
|
+
indent: 2,
|
|
60
|
+
sortKeys: {
|
|
61
|
+
keys: {
|
|
62
|
+
'recNumber': 1,
|
|
63
|
+
'type': 5,
|
|
64
|
+
'title': 13,
|
|
65
|
+
'journal': 14,
|
|
66
|
+
'authors': 15,
|
|
67
|
+
'isbn': 16,
|
|
68
|
+
'doi': 17,
|
|
69
|
+
'edition': 21,
|
|
70
|
+
'number': 22,
|
|
71
|
+
'pages': 23,
|
|
72
|
+
'language': 70,
|
|
73
|
+
'custom1': 81,
|
|
74
|
+
'custom2': 82,
|
|
75
|
+
'custom3': 83,
|
|
76
|
+
'custom4': 84,
|
|
77
|
+
'custom5': 85,
|
|
78
|
+
'custom6': 86,
|
|
79
|
+
'custom7': 87,
|
|
80
|
+
'researchNotes': 91,
|
|
81
|
+
'notes': 92,
|
|
82
|
+
'abstract': 93,
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
...options,
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
let lastRef; // Hold last refrence string in memory so we know when we've reached the end (last item shoulnd't have a closing comma)
|
|
89
|
+
|
|
90
|
+
return {
|
|
91
|
+
start: ()=> {
|
|
92
|
+
stream.write('[\n');
|
|
93
|
+
return Promise.resolve();
|
|
94
|
+
},
|
|
95
|
+
write: rawRef => {
|
|
96
|
+
let ref = settings.sortKeys ? sortKeys(rawRef, settings.sortKeys) : rawRef;
|
|
97
|
+
if (lastRef) stream.write(lastRef + ',' + settings.lineSuffix); // Flush last reference to disk with comma
|
|
98
|
+
lastRef = JSON.stringify(ref, null, settings.indent);
|
|
99
|
+
return Promise.resolve();
|
|
100
|
+
},
|
|
101
|
+
end: ()=> {
|
|
102
|
+
if (lastRef) stream.write(lastRef + settings.lineSuffix); // Flush final reference to disk without final comma
|
|
103
|
+
stream.write(']');
|
|
104
|
+
return new Promise((resolve, reject) =>
|
|
105
|
+
stream.end(err => err ? reject(err) : resolve())
|
|
106
|
+
);
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
}
|