@iebh/reflib 2.6.2 → 2.6.3
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 +388 -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/.ignore
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
test/data/
|
|
1
|
+
test/data/
|
package/LICENSE
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2022 Bond University Institute for Evidence-Based Healthcare
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
-
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
-
the Software without restriction, including without limitation the rights to
|
|
8
|
-
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
-
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
-
subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
17
|
-
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
-
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
-
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
-
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Bond University Institute for Evidence-Based Healthcare
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,274 +1,274 @@
|
|
|
1
|
-
@IEBH/Reflib
|
|
2
|
-
============
|
|
3
|
-
Reference library processing for Node.
|
|
4
|
-
|
|
5
|
-
This library provides various read/write functionality to process citation libraries and handle individual references (henceforth "Refs").
|
|
6
|
-
|
|
7
|
-
This module forms part of the [Systematic Review Accelerator](https://sr-accelerator.com)
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
Compatibility
|
|
11
|
-
=============
|
|
12
|
-
|
|
13
|
-
| Library | Extension(s) | Read | Write |
|
|
14
|
-
|------------------------|-----------------|--------------------|--------------------|
|
|
15
|
-
| BibTeX | `.bib` | :heavy_check_mark: | :heavy_check_mark: |
|
|
16
|
-
| Comma Separated Values | `.csv` | :x: | :x: |
|
|
17
|
-
| EndNote ENL | `.enl` | :heavy_check_mark: | (untested) |
|
|
18
|
-
| EndNote ENLX | `.enlx` | :heavy_check_mark: | :x: |
|
|
19
|
-
| EndNote XML | `.xml` | :heavy_check_mark: | :heavy_check_mark: |
|
|
20
|
-
| JSON | `.json` | :heavy_check_mark: | :heavy_check_mark: |
|
|
21
|
-
| Medline | `.nbib` | :heavy_check_mark: | :heavy_check_mark: |
|
|
22
|
-
| RIS | `.ris` | :heavy_check_mark: | :heavy_check_mark: |
|
|
23
|
-
| Tab Separated Values | `.tsv` | :x: | :x: |
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
**Notes on different formats**:
|
|
27
|
-
|
|
28
|
-
* Not all formats are one-to-one translations, some have differing field definitions or type definitions
|
|
29
|
-
* BibTeX support is only provided for "well-formatted" files - i.e. correct use of newlines rather than one-single-line-per-ref, this is to avoid having to implement a full AST parser
|
|
30
|
-
* Medline seems to implement a totally different [publication type system](https://www.nlm.nih.gov/mesh/pubtypes.html) than others. Reflib will attempt to guess the best match, storing the original type in the `medlineType` key. Should the citation library be exported _back_ to Medline / `.nbib` files this key will take precedence to avoid data loss
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
Reference Structure
|
|
34
|
-
===================
|
|
35
|
-
Reflib creates a simple Plain-Old-JavaScript-Object (POJO) for each reference it parses, or writes to a file format when given a collection of the same.
|
|
36
|
-
|
|
37
|
-
Each reference has the following standardized fields, these are translated from whatever internal format each module uses - e.g. the `TY` RIS field is automatically translated to `title`.
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
| Field | Type | Description |
|
|
41
|
-
|------------------|-----------------|----------------------------------------------------------------------------------------|
|
|
42
|
-
| recNumber | `Number` | The sorting number of the reference. Not present in RIS files |
|
|
43
|
-
| type | `String` | A supported [reference type](#reference-types) (e.g. journalArticle) |
|
|
44
|
-
| title | `String` | The reference's main title |
|
|
45
|
-
| journal | `String` | The reference's secondary title, this is usually the journal for most published papers |
|
|
46
|
-
| authors | `Array<String>` | An array of each Author in the originally specified format |
|
|
47
|
-
| date | `String` | The raw, internal date of the reference |
|
|
48
|
-
| urls | `Array<String>` | An array of each URL for the reference |
|
|
49
|
-
| pages | `String` | The page reference, usually in the format `123-4` |
|
|
50
|
-
| volume | `String` | |
|
|
51
|
-
| number | `String` | |
|
|
52
|
-
| isbn | `String` | |
|
|
53
|
-
| abstract | `String` | |
|
|
54
|
-
| label | `String` | |
|
|
55
|
-
| caption | `String` | |
|
|
56
|
-
| notes | `String` | |
|
|
57
|
-
| address | `String` | |
|
|
58
|
-
| researchNotes | `String` | |
|
|
59
|
-
| keywords | `Array<String>` | Optional list of keywords that apply to the reference |
|
|
60
|
-
| accessDate | `String` | |
|
|
61
|
-
| accession | `String` | [Accession numbers spec](https://support.nlm.nih.gov/knowledgebase/article/KA-03434/en-us), can sometimes be the PubMed ID |
|
|
62
|
-
| doi | `String` | |
|
|
63
|
-
| section | `String` | |
|
|
64
|
-
| language | `String` | |
|
|
65
|
-
| researchNotes | `String` | |
|
|
66
|
-
| databaseProvider | `String` | |
|
|
67
|
-
| database | `String` | |
|
|
68
|
-
| workType | `String` | |
|
|
69
|
-
| custom1 | `String` | |
|
|
70
|
-
| custom2 | `String` | |
|
|
71
|
-
| custom3 | `String` | |
|
|
72
|
-
| custom4 | `String` | |
|
|
73
|
-
| custom5 | `String` | |
|
|
74
|
-
| custom6 | `String` | |
|
|
75
|
-
| custom7 | `String` | |
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
Reference Types
|
|
79
|
-
---------------
|
|
80
|
-
As with refs the following ref types are supported and translated from the module internal formats.
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
```
|
|
84
|
-
aggregatedDatabase
|
|
85
|
-
ancientText
|
|
86
|
-
artwork
|
|
87
|
-
audioVisualMaterial
|
|
88
|
-
bill
|
|
89
|
-
blog
|
|
90
|
-
book
|
|
91
|
-
bookSection
|
|
92
|
-
case
|
|
93
|
-
catalog
|
|
94
|
-
chartOrTable
|
|
95
|
-
classicalWork
|
|
96
|
-
computerProgram
|
|
97
|
-
conferencePaper
|
|
98
|
-
conferenceProceedings
|
|
99
|
-
dataset
|
|
100
|
-
dictionary
|
|
101
|
-
editedBook
|
|
102
|
-
electronicArticle
|
|
103
|
-
electronicBook
|
|
104
|
-
electronicBookSection
|
|
105
|
-
encyclopedia
|
|
106
|
-
equation
|
|
107
|
-
figure
|
|
108
|
-
filmOrBroadcast
|
|
109
|
-
generic
|
|
110
|
-
governmentDocument
|
|
111
|
-
grant
|
|
112
|
-
hearing
|
|
113
|
-
journalArticle
|
|
114
|
-
legalRuleOrRegulation
|
|
115
|
-
magazineArticle
|
|
116
|
-
manuscript
|
|
117
|
-
map
|
|
118
|
-
music
|
|
119
|
-
newspaperArticle
|
|
120
|
-
onlineDatabase
|
|
121
|
-
onlineMultimedia
|
|
122
|
-
pamphlet
|
|
123
|
-
patent
|
|
124
|
-
personalCommunication
|
|
125
|
-
report
|
|
126
|
-
serial
|
|
127
|
-
standard
|
|
128
|
-
statute
|
|
129
|
-
thesis
|
|
130
|
-
unknown
|
|
131
|
-
unpublished
|
|
132
|
-
web
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
API
|
|
138
|
-
===
|
|
139
|
-
Each API is available either from the default `reflib` object or as a separate import.
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
```javascript
|
|
143
|
-
import reflib from 'reflib'; // Import everything as `reflib`
|
|
144
|
-
reflib.readFile(path);
|
|
145
|
-
reflib.writeFile(path, refs);
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
import {readFile, writeFile} from 'reflib'; // Import specific functions
|
|
149
|
-
readFile(path);
|
|
150
|
-
writeFile(path, refs);
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
formats
|
|
155
|
-
=======
|
|
156
|
-
Available: Node + Browser
|
|
157
|
-
A lookup object of all supported citation library formats.
|
|
158
|
-
Each key is the unique ID of that module.
|
|
159
|
-
|
|
160
|
-
Properties are:
|
|
161
|
-
|
|
162
|
-
| Key | Type | Description |
|
|
163
|
-
|--------------|-----------------|------------------------------------------------------------------------|
|
|
164
|
-
| `id` | `String` | The unique ID of that module (same as object key) |
|
|
165
|
-
| `title` | `String` | Longer, human readable title of the module |
|
|
166
|
-
| `titleShort` | `String` | Shorter, human readable title of the module |
|
|
167
|
-
| `ext` | `Array<String>` | Array of output file extensions, first extension should be the default |
|
|
168
|
-
| `canRead` | `boolean` | Whether the format is supported when reading a citation library |
|
|
169
|
-
| `canWrite` | `boolean` | Whether the format is supported when writing a citation library |
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
identifyFormat(path)
|
|
173
|
-
====================
|
|
174
|
-
Available: Node + Browser
|
|
175
|
-
Attempt to determine the format of a file on disk from its path. The file does not need to actually exist.
|
|
176
|
-
|
|
177
|
-
```javascript
|
|
178
|
-
identifyFormat('My Refs.csv') //= csv
|
|
179
|
-
identifyFormat('My Refs.json') //= json
|
|
180
|
-
identifyFormat('My Refs.nbib') //= nbib
|
|
181
|
-
identifyFormat('My Refs.txt.ris') //= ris
|
|
182
|
-
identifyFormat('MY REFS.TXT.RIS') //= ris
|
|
183
|
-
identifyFormat('My Refs.data.tsv') //= tsv
|
|
184
|
-
identifyFormat('My Refs.xml') //= endnoteXml
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
readFile(path, options)
|
|
189
|
-
=======================
|
|
190
|
-
Available: Node
|
|
191
|
-
Read a file on disk, returning a Promise which will resolve with an array of all Refs extracted.
|
|
192
|
-
|
|
193
|
-
```javascript
|
|
194
|
-
reflib.readFile('./data/json/json1.json')
|
|
195
|
-
.then(refs => /* Do something with Ref collection */)
|
|
196
|
-
```
|
|
197
|
-
|
|
198
|
-
An emitter is available to track progress while reading. Note that due to the chainable nature of promises the first return contains the `emitter` key only:
|
|
199
|
-
|
|
200
|
-
```javascript
|
|
201
|
-
let reader = reflib.readFile('./data/json/json1.json');
|
|
202
|
-
|
|
203
|
-
reader.emitter
|
|
204
|
-
.on('progress', ({readBytes, totalSize, refsFound}) => /* Report progress somehow */);
|
|
205
|
-
.on('end', ({refsFound}) => /* Report progress somehow */);
|
|
206
|
-
|
|
207
|
-
reader
|
|
208
|
-
.then(refs => /* Do something with Ref collection */)
|
|
209
|
-
```
|
|
210
|
-
|
|
211
|
-
uploadFile(options)
|
|
212
|
-
===================
|
|
213
|
-
Available: Browser
|
|
214
|
-
Prompt the user for a file and process it into an array of citations.
|
|
215
|
-
|
|
216
|
-
```javascript
|
|
217
|
-
reflib.uploadFile({ // Additional options
|
|
218
|
-
file, // Optional File object if known, if omitted this function will prompt the user to select a file
|
|
219
|
-
onStart, // Async function called as `(File)` when starting the read stage
|
|
220
|
-
onProgress, // Function called as `(position, totalSize)` when processing the file
|
|
221
|
-
onEnd, // Async function called as `()` when the read stage has completed
|
|
222
|
-
})
|
|
223
|
-
.then(refs => /* Do something with Ref collection */)
|
|
224
|
-
```
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
writeFile(path, refs, options)
|
|
228
|
-
==============================
|
|
229
|
-
Available: Node
|
|
230
|
-
Write a file back to disk, returning a Promise which will resolve when done.
|
|
231
|
-
|
|
232
|
-
```javascript
|
|
233
|
-
reflib.writeFile('MyRefs.xml', refs);
|
|
234
|
-
```
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
readStream(moduleId, inputStream, options)
|
|
239
|
-
==========================================
|
|
240
|
-
Available: Node + Browser
|
|
241
|
-
Low level worker of `readFile()`.
|
|
242
|
-
Accept an input Stream.Readable and return a emitter which will emit each Ref found.
|
|
243
|
-
|
|
244
|
-
```javascript
|
|
245
|
-
reflib.readStream('json', createReadStream('./data/json/json1.json'))
|
|
246
|
-
.on('end', ()=> /* Finished reading */)
|
|
247
|
-
.on('error', err => /* Deal with errors */)
|
|
248
|
-
.on('ref', ref => /* Do something with extracted Ref */)
|
|
249
|
-
```
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
writeStream(moduleId, outputStream, options)
|
|
253
|
-
============================================
|
|
254
|
-
Available: Node + Browser
|
|
255
|
-
Low level worker of `writeFile()`.
|
|
256
|
-
Return an object with methods to call to write to a given stream.
|
|
257
|
-
The returned object will have a `start()`, `end()` and `write(ref)` (optional `middle(ref)`) function which can be called to write to the original input stream.
|
|
258
|
-
|
|
259
|
-
```javascript
|
|
260
|
-
// Convert a JSON file to EndNoteXML via a stream
|
|
261
|
-
let output = reflib.writeStream('json', createWriteStream('./MyRefs.xml'));
|
|
262
|
-
|
|
263
|
-
output.start(); // Begin stream writing
|
|
264
|
-
|
|
265
|
-
reflib.readStream('json', createReadStream('./data/json/json1.json'))
|
|
266
|
-
.on('ref', ref => output.write(ref))
|
|
267
|
-
.on('end', ()=> output.end())
|
|
268
|
-
```
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
Credits
|
|
272
|
-
=======
|
|
273
|
-
Developed for the [Bond University Institute for Evidence-Based Healthcare](https://iebh.bond.edu.au).
|
|
274
|
-
Please contact [the author](mailto:matt_carter@bond.edu.au) with any issues.
|
|
1
|
+
@IEBH/Reflib
|
|
2
|
+
============
|
|
3
|
+
Reference library processing for Node.
|
|
4
|
+
|
|
5
|
+
This library provides various read/write functionality to process citation libraries and handle individual references (henceforth "Refs").
|
|
6
|
+
|
|
7
|
+
This module forms part of the [Systematic Review Accelerator](https://sr-accelerator.com)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
Compatibility
|
|
11
|
+
=============
|
|
12
|
+
|
|
13
|
+
| Library | Extension(s) | Read | Write |
|
|
14
|
+
|------------------------|-----------------|--------------------|--------------------|
|
|
15
|
+
| BibTeX | `.bib` | :heavy_check_mark: | :heavy_check_mark: |
|
|
16
|
+
| Comma Separated Values | `.csv` | :x: | :x: |
|
|
17
|
+
| EndNote ENL | `.enl` | :heavy_check_mark: | (untested) |
|
|
18
|
+
| EndNote ENLX | `.enlx` | :heavy_check_mark: | :x: |
|
|
19
|
+
| EndNote XML | `.xml` | :heavy_check_mark: | :heavy_check_mark: |
|
|
20
|
+
| JSON | `.json` | :heavy_check_mark: | :heavy_check_mark: |
|
|
21
|
+
| Medline | `.nbib` | :heavy_check_mark: | :heavy_check_mark: |
|
|
22
|
+
| RIS | `.ris` | :heavy_check_mark: | :heavy_check_mark: |
|
|
23
|
+
| Tab Separated Values | `.tsv` | :x: | :x: |
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
**Notes on different formats**:
|
|
27
|
+
|
|
28
|
+
* Not all formats are one-to-one translations, some have differing field definitions or type definitions
|
|
29
|
+
* BibTeX support is only provided for "well-formatted" files - i.e. correct use of newlines rather than one-single-line-per-ref, this is to avoid having to implement a full AST parser
|
|
30
|
+
* Medline seems to implement a totally different [publication type system](https://www.nlm.nih.gov/mesh/pubtypes.html) than others. Reflib will attempt to guess the best match, storing the original type in the `medlineType` key. Should the citation library be exported _back_ to Medline / `.nbib` files this key will take precedence to avoid data loss
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
Reference Structure
|
|
34
|
+
===================
|
|
35
|
+
Reflib creates a simple Plain-Old-JavaScript-Object (POJO) for each reference it parses, or writes to a file format when given a collection of the same.
|
|
36
|
+
|
|
37
|
+
Each reference has the following standardized fields, these are translated from whatever internal format each module uses - e.g. the `TY` RIS field is automatically translated to `title`.
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
| Field | Type | Description |
|
|
41
|
+
|------------------|-----------------|----------------------------------------------------------------------------------------|
|
|
42
|
+
| recNumber | `Number` | The sorting number of the reference. Not present in RIS files |
|
|
43
|
+
| type | `String` | A supported [reference type](#reference-types) (e.g. journalArticle) |
|
|
44
|
+
| title | `String` | The reference's main title |
|
|
45
|
+
| journal | `String` | The reference's secondary title, this is usually the journal for most published papers |
|
|
46
|
+
| authors | `Array<String>` | An array of each Author in the originally specified format |
|
|
47
|
+
| date | `String` | The raw, internal date of the reference |
|
|
48
|
+
| urls | `Array<String>` | An array of each URL for the reference |
|
|
49
|
+
| pages | `String` | The page reference, usually in the format `123-4` |
|
|
50
|
+
| volume | `String` | |
|
|
51
|
+
| number | `String` | |
|
|
52
|
+
| isbn | `String` | |
|
|
53
|
+
| abstract | `String` | |
|
|
54
|
+
| label | `String` | |
|
|
55
|
+
| caption | `String` | |
|
|
56
|
+
| notes | `String` | |
|
|
57
|
+
| address | `String` | |
|
|
58
|
+
| researchNotes | `String` | |
|
|
59
|
+
| keywords | `Array<String>` | Optional list of keywords that apply to the reference |
|
|
60
|
+
| accessDate | `String` | |
|
|
61
|
+
| accession | `String` | [Accession numbers spec](https://support.nlm.nih.gov/knowledgebase/article/KA-03434/en-us), can sometimes be the PubMed ID |
|
|
62
|
+
| doi | `String` | |
|
|
63
|
+
| section | `String` | |
|
|
64
|
+
| language | `String` | |
|
|
65
|
+
| researchNotes | `String` | |
|
|
66
|
+
| databaseProvider | `String` | |
|
|
67
|
+
| database | `String` | |
|
|
68
|
+
| workType | `String` | |
|
|
69
|
+
| custom1 | `String` | |
|
|
70
|
+
| custom2 | `String` | |
|
|
71
|
+
| custom3 | `String` | |
|
|
72
|
+
| custom4 | `String` | |
|
|
73
|
+
| custom5 | `String` | |
|
|
74
|
+
| custom6 | `String` | |
|
|
75
|
+
| custom7 | `String` | |
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
Reference Types
|
|
79
|
+
---------------
|
|
80
|
+
As with refs the following ref types are supported and translated from the module internal formats.
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
```
|
|
84
|
+
aggregatedDatabase
|
|
85
|
+
ancientText
|
|
86
|
+
artwork
|
|
87
|
+
audioVisualMaterial
|
|
88
|
+
bill
|
|
89
|
+
blog
|
|
90
|
+
book
|
|
91
|
+
bookSection
|
|
92
|
+
case
|
|
93
|
+
catalog
|
|
94
|
+
chartOrTable
|
|
95
|
+
classicalWork
|
|
96
|
+
computerProgram
|
|
97
|
+
conferencePaper
|
|
98
|
+
conferenceProceedings
|
|
99
|
+
dataset
|
|
100
|
+
dictionary
|
|
101
|
+
editedBook
|
|
102
|
+
electronicArticle
|
|
103
|
+
electronicBook
|
|
104
|
+
electronicBookSection
|
|
105
|
+
encyclopedia
|
|
106
|
+
equation
|
|
107
|
+
figure
|
|
108
|
+
filmOrBroadcast
|
|
109
|
+
generic
|
|
110
|
+
governmentDocument
|
|
111
|
+
grant
|
|
112
|
+
hearing
|
|
113
|
+
journalArticle
|
|
114
|
+
legalRuleOrRegulation
|
|
115
|
+
magazineArticle
|
|
116
|
+
manuscript
|
|
117
|
+
map
|
|
118
|
+
music
|
|
119
|
+
newspaperArticle
|
|
120
|
+
onlineDatabase
|
|
121
|
+
onlineMultimedia
|
|
122
|
+
pamphlet
|
|
123
|
+
patent
|
|
124
|
+
personalCommunication
|
|
125
|
+
report
|
|
126
|
+
serial
|
|
127
|
+
standard
|
|
128
|
+
statute
|
|
129
|
+
thesis
|
|
130
|
+
unknown
|
|
131
|
+
unpublished
|
|
132
|
+
web
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
API
|
|
138
|
+
===
|
|
139
|
+
Each API is available either from the default `reflib` object or as a separate import.
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
```javascript
|
|
143
|
+
import reflib from 'reflib'; // Import everything as `reflib`
|
|
144
|
+
reflib.readFile(path);
|
|
145
|
+
reflib.writeFile(path, refs);
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
import {readFile, writeFile} from 'reflib'; // Import specific functions
|
|
149
|
+
readFile(path);
|
|
150
|
+
writeFile(path, refs);
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
formats
|
|
155
|
+
=======
|
|
156
|
+
Available: Node + Browser
|
|
157
|
+
A lookup object of all supported citation library formats.
|
|
158
|
+
Each key is the unique ID of that module.
|
|
159
|
+
|
|
160
|
+
Properties are:
|
|
161
|
+
|
|
162
|
+
| Key | Type | Description |
|
|
163
|
+
|--------------|-----------------|------------------------------------------------------------------------|
|
|
164
|
+
| `id` | `String` | The unique ID of that module (same as object key) |
|
|
165
|
+
| `title` | `String` | Longer, human readable title of the module |
|
|
166
|
+
| `titleShort` | `String` | Shorter, human readable title of the module |
|
|
167
|
+
| `ext` | `Array<String>` | Array of output file extensions, first extension should be the default |
|
|
168
|
+
| `canRead` | `boolean` | Whether the format is supported when reading a citation library |
|
|
169
|
+
| `canWrite` | `boolean` | Whether the format is supported when writing a citation library |
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
identifyFormat(path)
|
|
173
|
+
====================
|
|
174
|
+
Available: Node + Browser
|
|
175
|
+
Attempt to determine the format of a file on disk from its path. The file does not need to actually exist.
|
|
176
|
+
|
|
177
|
+
```javascript
|
|
178
|
+
identifyFormat('My Refs.csv') //= csv
|
|
179
|
+
identifyFormat('My Refs.json') //= json
|
|
180
|
+
identifyFormat('My Refs.nbib') //= nbib
|
|
181
|
+
identifyFormat('My Refs.txt.ris') //= ris
|
|
182
|
+
identifyFormat('MY REFS.TXT.RIS') //= ris
|
|
183
|
+
identifyFormat('My Refs.data.tsv') //= tsv
|
|
184
|
+
identifyFormat('My Refs.xml') //= endnoteXml
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
readFile(path, options)
|
|
189
|
+
=======================
|
|
190
|
+
Available: Node
|
|
191
|
+
Read a file on disk, returning a Promise which will resolve with an array of all Refs extracted.
|
|
192
|
+
|
|
193
|
+
```javascript
|
|
194
|
+
reflib.readFile('./data/json/json1.json')
|
|
195
|
+
.then(refs => /* Do something with Ref collection */)
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
An emitter is available to track progress while reading. Note that due to the chainable nature of promises the first return contains the `emitter` key only:
|
|
199
|
+
|
|
200
|
+
```javascript
|
|
201
|
+
let reader = reflib.readFile('./data/json/json1.json');
|
|
202
|
+
|
|
203
|
+
reader.emitter
|
|
204
|
+
.on('progress', ({readBytes, totalSize, refsFound}) => /* Report progress somehow */);
|
|
205
|
+
.on('end', ({refsFound}) => /* Report progress somehow */);
|
|
206
|
+
|
|
207
|
+
reader
|
|
208
|
+
.then(refs => /* Do something with Ref collection */)
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
uploadFile(options)
|
|
212
|
+
===================
|
|
213
|
+
Available: Browser
|
|
214
|
+
Prompt the user for a file and process it into an array of citations.
|
|
215
|
+
|
|
216
|
+
```javascript
|
|
217
|
+
reflib.uploadFile({ // Additional options
|
|
218
|
+
file, // Optional File object if known, if omitted this function will prompt the user to select a file
|
|
219
|
+
onStart, // Async function called as `(File)` when starting the read stage
|
|
220
|
+
onProgress, // Function called as `(position, totalSize)` when processing the file
|
|
221
|
+
onEnd, // Async function called as `()` when the read stage has completed
|
|
222
|
+
})
|
|
223
|
+
.then(refs => /* Do something with Ref collection */)
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
writeFile(path, refs, options)
|
|
228
|
+
==============================
|
|
229
|
+
Available: Node
|
|
230
|
+
Write a file back to disk, returning a Promise which will resolve when done.
|
|
231
|
+
|
|
232
|
+
```javascript
|
|
233
|
+
reflib.writeFile('MyRefs.xml', refs);
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
readStream(moduleId, inputStream, options)
|
|
239
|
+
==========================================
|
|
240
|
+
Available: Node + Browser
|
|
241
|
+
Low level worker of `readFile()`.
|
|
242
|
+
Accept an input Stream.Readable and return a emitter which will emit each Ref found.
|
|
243
|
+
|
|
244
|
+
```javascript
|
|
245
|
+
reflib.readStream('json', createReadStream('./data/json/json1.json'))
|
|
246
|
+
.on('end', ()=> /* Finished reading */)
|
|
247
|
+
.on('error', err => /* Deal with errors */)
|
|
248
|
+
.on('ref', ref => /* Do something with extracted Ref */)
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
writeStream(moduleId, outputStream, options)
|
|
253
|
+
============================================
|
|
254
|
+
Available: Node + Browser
|
|
255
|
+
Low level worker of `writeFile()`.
|
|
256
|
+
Return an object with methods to call to write to a given stream.
|
|
257
|
+
The returned object will have a `start()`, `end()` and `write(ref)` (optional `middle(ref)`) function which can be called to write to the original input stream.
|
|
258
|
+
|
|
259
|
+
```javascript
|
|
260
|
+
// Convert a JSON file to EndNoteXML via a stream
|
|
261
|
+
let output = reflib.writeStream('json', createWriteStream('./MyRefs.xml'));
|
|
262
|
+
|
|
263
|
+
output.start(); // Begin stream writing
|
|
264
|
+
|
|
265
|
+
reflib.readStream('json', createReadStream('./data/json/json1.json'))
|
|
266
|
+
.on('ref', ref => output.write(ref))
|
|
267
|
+
.on('end', ()=> output.end())
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
Credits
|
|
272
|
+
=======
|
|
273
|
+
Developed for the [Bond University Institute for Evidence-Based Healthcare](https://iebh.bond.edu.au).
|
|
274
|
+
Please contact [the author](mailto:matt_carter@bond.edu.au) with any issues.
|
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
|
+
};
|