@iebh/reflib 2.6.2 → 2.6.4
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 +274 -274
- 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 +383 -372
- package/modules/default.js +7 -7
- package/modules/endnoteEnl.js +237 -237
- package/modules/endnoteEnlX.js +85 -85
- package/modules/endnoteXml.js +442 -442
- package/modules/interface.js +47 -47
- package/modules/json.js +79 -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 +51 -51
- package/package.json +66 -66
- package/shared/camelCase.js +17 -17
- package/shared/emitter.js +23 -23
- package/shared/streamEmitter.js +61 -61
package/lib/writeFile.js
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import {createWriteStream} from 'node:fs';
|
|
2
|
-
import {finished as streamFinished} from 'node:stream/promises';
|
|
3
|
-
import {identifyFormat} from './identifyFormat.js';
|
|
4
|
-
import {writeStream} from './writeStream.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Write a file to disk via the appropriate module
|
|
8
|
-
*
|
|
9
|
-
* @param {string} path The file path to write, the module to use will be determined from this
|
|
10
|
-
* @param {Array<ReflibRef>} refs Collection of references to write
|
|
11
|
-
* @param {Object} [options] Additional options to pass to the file writer
|
|
12
|
-
* @param {string} [options.module] The module to use if overriding from the file path
|
|
13
|
-
*
|
|
14
|
-
* @returns {Promise} A promise which resolves when the operation has completed
|
|
15
|
-
*/
|
|
16
|
-
export function writeFile(path, refs, options) {
|
|
17
|
-
let format = options?.module || identifyFormat(path)?.id;
|
|
18
|
-
if (!format) throw new Error(`Unable to identify reference library format when saving file "${path}"`);
|
|
19
|
-
|
|
20
|
-
let fileStream = createWriteStream(path);
|
|
21
|
-
let writer = writeStream(format, fileStream, options);
|
|
22
|
-
|
|
23
|
-
return Promise.resolve()
|
|
24
|
-
.then(()=> writer.start())
|
|
25
|
-
.then(()=> refs.reduce((chain, ref, refIndex, refs) => chain // Write all refs as a series of promises
|
|
26
|
-
.then(()=> writer.write(ref))
|
|
27
|
-
.then(()=> refIndex < refs.length && writer.middle && writer.middle(ref))
|
|
28
|
-
, Promise.resolve()))
|
|
29
|
-
.then(()=> writer.end())
|
|
30
|
-
.then(()=> fileStream.close())
|
|
31
|
-
.then(()=> streamFinished(fileStream))
|
|
32
|
-
}
|
|
1
|
+
import {createWriteStream} from 'node:fs';
|
|
2
|
+
import {finished as streamFinished} from 'node:stream/promises';
|
|
3
|
+
import {identifyFormat} from './identifyFormat.js';
|
|
4
|
+
import {writeStream} from './writeStream.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Write a file to disk via the appropriate module
|
|
8
|
+
*
|
|
9
|
+
* @param {string} path The file path to write, the module to use will be determined from this
|
|
10
|
+
* @param {Array<ReflibRef>} refs Collection of references to write
|
|
11
|
+
* @param {Object} [options] Additional options to pass to the file writer
|
|
12
|
+
* @param {string} [options.module] The module to use if overriding from the file path
|
|
13
|
+
*
|
|
14
|
+
* @returns {Promise} A promise which resolves when the operation has completed
|
|
15
|
+
*/
|
|
16
|
+
export function writeFile(path, refs, options) {
|
|
17
|
+
let format = options?.module || identifyFormat(path)?.id;
|
|
18
|
+
if (!format) throw new Error(`Unable to identify reference library format when saving file "${path}"`);
|
|
19
|
+
|
|
20
|
+
let fileStream = createWriteStream(path);
|
|
21
|
+
let writer = writeStream(format, fileStream, options);
|
|
22
|
+
|
|
23
|
+
return Promise.resolve()
|
|
24
|
+
.then(()=> writer.start())
|
|
25
|
+
.then(()=> refs.reduce((chain, ref, refIndex, refs) => chain // Write all refs as a series of promises
|
|
26
|
+
.then(()=> writer.write(ref))
|
|
27
|
+
.then(()=> refIndex < refs.length && writer.middle && writer.middle(ref))
|
|
28
|
+
, Promise.resolve()))
|
|
29
|
+
.then(()=> writer.end())
|
|
30
|
+
.then(()=> fileStream.close())
|
|
31
|
+
.then(()=> streamFinished(fileStream))
|
|
32
|
+
}
|
package/lib/writeStream.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import {getModule} from './getModule.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Write an output stream via a given format ID
|
|
5
|
-
* This function is really just a multiplexor around each modules `writeStream` export
|
|
6
|
-
* @param {string} module The module ID as per `lib/formats.js`
|
|
7
|
-
* @param {Stream.Writable} stream Output stream to write to
|
|
8
|
-
* @param {Object} [options] Additional options to pass to the stream writer
|
|
9
|
-
* @returns {Object} An object composed of `{start, write, end}` functions
|
|
10
|
-
*/
|
|
11
|
-
export function writeStream(module, stream, options) {
|
|
12
|
-
if (!module) throw new Error('No module provided to parse with');
|
|
13
|
-
if (!stream) throw new Error('No stream provided to parse');
|
|
14
|
-
|
|
15
|
-
return getModule(module).writeStream(stream, options);
|
|
16
|
-
}
|
|
1
|
+
import {getModule} from './getModule.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Write an output stream via a given format ID
|
|
5
|
+
* This function is really just a multiplexor around each modules `writeStream` export
|
|
6
|
+
* @param {string} module The module ID as per `lib/formats.js`
|
|
7
|
+
* @param {Stream.Writable} stream Output stream to write to
|
|
8
|
+
* @param {Object} [options] Additional options to pass to the stream writer
|
|
9
|
+
* @returns {Object} An object composed of `{start, write, end}` functions
|
|
10
|
+
*/
|
|
11
|
+
export function writeStream(module, stream, options) {
|
|
12
|
+
if (!module) throw new Error('No module provided to parse with');
|
|
13
|
+
if (!stream) throw new Error('No stream provided to parse');
|
|
14
|
+
|
|
15
|
+
return getModule(module).writeStream(stream, options);
|
|
16
|
+
}
|