@iebh/reflib 2.8.0 → 2.8.2
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 -297
- package/app.js +87 -85
- 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/getFormatList.js +12 -0
- 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 -70
- package/shared/camelCase.js +17 -17
- package/shared/emitter.js +23 -23
- package/shared/parseArgs.js +104 -104
- package/shared/streamEmitter.js +61 -61
package/app.js
CHANGED
|
@@ -1,85 +1,87 @@
|
|
|
1
|
-
#!/usr/bin/node
|
|
2
|
-
|
|
3
|
-
import parseArgs from './shared/parseArgs.js';
|
|
4
|
-
import packageInfo from './package.json' with {type: 'json'};
|
|
5
|
-
import reflib from './lib/default.js';
|
|
6
|
-
|
|
7
|
-
let help = `
|
|
8
|
-
|
|
9
|
-
Usage: reflib -i INPUT_FILE [-f FORMAT] [-o -|OUTPUT_FILE]
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
-i, --input <file> Input file to process
|
|
13
|
-
|
|
14
|
-
-o, --output <file> Output file to save. Use '-' for STDOUT
|
|
15
|
-
|
|
16
|
-
-f, --format <reflib-format> Override or set the file output type (if omitted the outfile filename
|
|
17
|
-
is used to determine the format)
|
|
18
|
-
|
|
19
|
-
-v, --verbose Be verbose when processing
|
|
20
|
-
|
|
21
|
-
--version Print CLI version and exit
|
|
22
|
-
|
|
23
|
-
-h, --help This help screen
|
|
24
|
-
`;
|
|
25
|
-
|
|
26
|
-
// Parse args {{{
|
|
27
|
-
let args = parseArgs.parse();
|
|
28
|
-
args = parseArgs.expand(args, {
|
|
29
|
-
'h': 'help',
|
|
30
|
-
'i': 'input',
|
|
31
|
-
'o': 'output',
|
|
32
|
-
'f': 'format',
|
|
33
|
-
'v': 'verbose',
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
//
|
|
44
|
-
if
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
1
|
+
#!/usr/bin/node
|
|
2
|
+
|
|
3
|
+
import parseArgs from './shared/parseArgs.js';
|
|
4
|
+
import packageInfo from './package.json' with {type: 'json'};
|
|
5
|
+
import reflib from './lib/default.js';
|
|
6
|
+
|
|
7
|
+
let help = `
|
|
8
|
+
|
|
9
|
+
Usage: reflib -i INPUT_FILE [-f FORMAT] [-o -|OUTPUT_FILE]
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
-i, --input <file> Input file to process
|
|
13
|
+
|
|
14
|
+
-o, --output <file> Output file to save. Use '-' for STDOUT
|
|
15
|
+
|
|
16
|
+
-f, --format <reflib-format> Override or set the file output type (if omitted the outfile filename
|
|
17
|
+
is used to determine the format)
|
|
18
|
+
|
|
19
|
+
-v, --verbose Be verbose when processing
|
|
20
|
+
|
|
21
|
+
--version Print CLI version and exit
|
|
22
|
+
|
|
23
|
+
-h, --help This help screen
|
|
24
|
+
`;
|
|
25
|
+
|
|
26
|
+
// Parse args {{{
|
|
27
|
+
let args = parseArgs.parse();
|
|
28
|
+
args = parseArgs.expand(args, {
|
|
29
|
+
'h': 'help',
|
|
30
|
+
'i': 'input',
|
|
31
|
+
'o': 'output',
|
|
32
|
+
'f': 'format',
|
|
33
|
+
'v': 'verbose',
|
|
34
|
+
});
|
|
35
|
+
args.format ||= 'json';
|
|
36
|
+
// }}}
|
|
37
|
+
|
|
38
|
+
// Action: Version {{{
|
|
39
|
+
if (args.version) {
|
|
40
|
+
console.log(`Version: ${packageInfo.version}`);
|
|
41
|
+
process.exit(0);
|
|
42
|
+
}
|
|
43
|
+
// }}}
|
|
44
|
+
// Action: Convert (if --input) {{{
|
|
45
|
+
if (args.input) {
|
|
46
|
+
if (args.verbose) console.log('Reading', args.input);
|
|
47
|
+
let refs = await reflib.readFile(args.input);
|
|
48
|
+
if (args.verbose) console.log('Read', refs.length, 'refs');
|
|
49
|
+
|
|
50
|
+
if (
|
|
51
|
+
!args.output // No output file specified
|
|
52
|
+
|| args.output == '-' // OR use STDOUT
|
|
53
|
+
|| args.output === true // OR output is just specified as a flag with no rider
|
|
54
|
+
) {
|
|
55
|
+
if (args.verbose) console.log(`Raw output to STDOUT using "${args.format}" format`);
|
|
56
|
+
|
|
57
|
+
let stream = reflib.writeStream(
|
|
58
|
+
args.format,
|
|
59
|
+
process.stdout,
|
|
60
|
+
args.format == 'json' ? {indent:'\t'} : {},
|
|
61
|
+
);
|
|
62
|
+
await stream.start();
|
|
63
|
+
await Array.fromAsync(refs, (ref, refIndex) => Promise.resolve()
|
|
64
|
+
.then(()=> stream.write(ref))
|
|
65
|
+
.then(()=> refIndex < refs.length && stream.middle && stream.middle(ref))
|
|
66
|
+
);
|
|
67
|
+
await stream.end();
|
|
68
|
+
} else if (args.output) {
|
|
69
|
+
if (args.verbose) console.log('Writing', args.output);
|
|
70
|
+
await reflib.writeFile(args.output, refs);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (args.verbose) console.log('All done');
|
|
74
|
+
process.exit(0);
|
|
75
|
+
}
|
|
76
|
+
// }}}
|
|
77
|
+
// Action: Help {{{
|
|
78
|
+
if (args.help) {
|
|
79
|
+
console.log(help);
|
|
80
|
+
process.exit(0);
|
|
81
|
+
}
|
|
82
|
+
// }}}
|
|
83
|
+
// Action: Unknown {{{
|
|
84
|
+
console.warn('Nothing to do');
|
|
85
|
+
console.log(help);
|
|
86
|
+
process.exit(1);
|
|
87
|
+
// }}}
|
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
|
+
};
|
package/lib/downloadFile.js
CHANGED
|
@@ -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
|
|
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, refIndex, refs) =>
|
|
61
|
+
promiseChain
|
|
62
|
+
.then(()=> streamer.write(ref))
|
|
63
|
+
.then(()=> refIndex < refs.length && streamer.middle && streamer.middle(ref))
|
|
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
|
+
}
|