@iebh/reflib 2.4.2 → 2.4.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.
@@ -4,7 +4,7 @@ import {writeStream} from './writeStream.js';
4
4
  /**
5
5
  * Prompt the user for a file to save as and Write a given array of citations
6
6
  *
7
- * @param {Array<Ref>} Collection of references to write
7
+ * @param {Array<ReflibRef>} refs Collection of references to write
8
8
  *
9
9
  * @param {Object} [options] Additional options when prompting the user
10
10
  * @param {String} [options.filename='References.xml'] The filename to download
package/lib/formats.js CHANGED
@@ -5,7 +5,7 @@
5
5
  * @property {string} titleShort Shorter title of the format
6
6
  * @property {string} input Input format required by parser
7
7
  * @property {string} output Output format required by formatter
8
- * @property {array>string>} ext File extensions of this format, the first entry is generally used as the output default
8
+ * @property {Array<String>} ext File extensions of this format, the first entry is generally used as the output default
9
9
  * @property {boolean} canRead Whether the format is supported when reading a citation library
10
10
  * @property {boolean} canWrite Whether the format is supported when writing a citation library
11
11
  */
@@ -46,7 +46,7 @@ export let formats = {
46
46
  id: 'ris',
47
47
  title: 'RIS',
48
48
  titleShort: 'RIS',
49
- ext: ['.ris','.txt'],
49
+ ext: ['.ris','.txt', '.cgi'],
50
50
  canRead: true,
51
51
  canWrite: true,
52
52
  },
package/lib/getModule.js CHANGED
@@ -4,10 +4,12 @@ let hasSetup = new Set(); // Modules we have already setup
4
4
 
5
5
  /**
6
6
  * Simple wrapper which loads the named module as a keyed lirary of functions
7
+ *
7
8
  * @param {string} module The module ID as per `lib/formats.js`
8
9
  * @param {Object} [options] Additional options to use when fetching the module
9
10
  * @param {boolean} [options.setup=true] Call the `setup()` function on any module requested before use
10
- * @return {Object} The loaded module as an object of standardised functionality
11
+ *
12
+ * @returns {Object} The loaded module as an object of standardised functionality
11
13
  */
12
14
  export function getModule(module, options) {
13
15
  // Sanity checking
package/lib/readFile.js CHANGED
@@ -14,8 +14,8 @@ import {readStream} from './readStream.js';
14
14
  * @returns {Promise<Array>} An eventual array of all references parsed from the file
15
15
  * @property {EventEmitter} emitter An event emitter which will fire the below events
16
16
  *
17
- * @fires progress Emitted as `({readBytes: Number, totalSize: Number, refsFound: Number})`
18
- * @fires end Emitted as `({refsFound: Number})` when the reading operation has completed
17
+ * @emits progress Emitted as `({readBytes: Number, totalSize: Number, refsFound: Number})`
18
+ * @emits end Emitted as `({refsFound: Number})` when the reading operation has completed
19
19
  */
20
20
  export function readFile(path, options) {
21
21
  let settings = {
@@ -28,7 +28,7 @@ export function readFile(path, options) {
28
28
  let promiseEmitter = Promise.resolve()
29
29
  .then(()=> stat(path))
30
30
  .then(stats => new Promise((resolve, reject) => {
31
- let refs = []; // eslint-disable-line no-unused-vars
31
+ let refs = [];
32
32
 
33
33
  readStream(
34
34
  module,
package/lib/uploadFile.js CHANGED
@@ -10,7 +10,7 @@ import StreamEmitter from '../shared/streamEmitter.js';
10
10
  * @param {function} [options.onStart] Async function called as `(File)` when starting the read stage
11
11
  * @param {function} [options.onProgress] Function called as `(position, totalSize, refCount)` when processing the file
12
12
  * @param {function} [options.onEnd] Async function called as `()` when the read stage has completed
13
- * @param {*} [options.*] Additional settings to pass to `readStream()`
13
+ * @param {...*} [options...] Additional settings to pass to `readStream()`
14
14
  * @returns {Promise} A promise which will resolve with an array of extracted citations
15
15
  */
16
16
  export function uploadFile(options) {
package/lib/writeFile.js CHANGED
@@ -6,7 +6,7 @@ import {writeStream} from './writeStream.js';
6
6
  * Write a file to disk via the appropriate module
7
7
  *
8
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
9
+ * @param {Array<ReflibRef>} refs Collection of references to write
10
10
  * @param {Object} [options] Additional options to pass to the file writer
11
11
  * @param {string} [options.module] The module to use if overriding from the file path
12
12
  *
@@ -5,7 +5,10 @@ import Emitter from '../shared/emitter.js';
5
5
  import { WritableStream as XMLParser } from 'htmlparser2/lib/WritableStream';
6
6
 
7
7
  /**
8
+ * Read an EndnoteXML file, returning a stream analogue
8
9
  * @see modules/inhterface.js
10
+ * @param {Stream} stream Stream primative to encapsulate
11
+ * @returns {Object} A readable stream analogue defined in `modules/interface.js`
9
12
  */
10
13
  export function readStream(stream) {
11
14
  let emitter = Emitter();
@@ -103,18 +106,14 @@ export function readStream(stream) {
103
106
 
104
107
  // Queue up the parser in the next tick (so we can return the emitter first)
105
108
  setTimeout(() => {
106
-
107
109
  if (typeof stream.pipe === 'function') {
108
110
  let parser = new XMLParser(parserOptions);
109
111
  stream.on('data', ()=> emitter.emit('progress', stream.bytesRead))
110
112
  stream.pipe(parser)
111
113
  return;
112
- }
113
-
114
- else {
114
+ } else {
115
115
  console.error('Error with stream, check "streamEmitter.js" if on browser')
116
116
  }
117
-
118
117
  })
119
118
 
120
119
  return emitter;
@@ -123,11 +122,15 @@ export function readStream(stream) {
123
122
 
124
123
  /**
125
124
  * @see modules/interface.js
125
+ *
126
+ * @param {Stream} stream Writable stream to output to
126
127
  * @param {Object} [options] Additional options to use when parsing
127
128
  * @param {string} [options.defaultType='journalArticle'] Default citation type to assume when no other type is specified
128
129
  * @param {string} [options.filePath="c:\\"] "Fake" internal source file path the citation library was exported from, must end with backslashes
129
130
  * @param {string} [options.fileName="EndNote.enl"] "Fake" internal source file name the citation library was exported from
130
131
  * @param {function} [options.formatDate] Date formatter to translate between a JS Date object and the EndNote YYYY-MM-DD format
132
+ *
133
+ * @returns {Object} A writable stream analogue defined in `modules/interface.js`
131
134
  */
132
135
  export function writeStream(stream, options) {
133
136
  let settings = {
@@ -2,7 +2,7 @@
2
2
  * Generic module interface
3
3
  * This file serves no purpose other than to document the methods that each module can itself expose
4
4
  */
5
- /* eslint-disable no-unused-vars */
5
+ /* eslint-disable jsdoc/require-returns-check, no-unused-vars */
6
6
 
7
7
 
8
8
  /**
package/modules/json.js CHANGED
@@ -3,7 +3,12 @@ import Emitter from '../shared/emitter.js';
3
3
  import JSONStream from 'JSONStream';
4
4
 
5
5
  /**
6
+ * Read a JSON stream and emit references
6
7
  * @see modules/interface.js
8
+ *
9
+ * @param {Stream} stream Stream primative to encapsulate
10
+ *
11
+ * @returns {Object} A readable stream analogue defined in `modules/interface.js`
7
12
  */
8
13
  export function readStream(stream) {
9
14
  let recNumber = 1;
@@ -35,9 +40,15 @@ export function readStream(stream) {
35
40
 
36
41
 
37
42
  /**
43
+ * Write to a stream object
44
+ *
38
45
  * @see modules/interface.js
46
+ *
47
+ * @param {Steam} [stream] The stream to write to
39
48
  * @param {Object} [options] Additional options to use when parsing
40
49
  * @param {string} [options.lineSuffix='\n'] Optional line suffix for each output line of JSON
50
+ *
51
+ * @returns {Object} A writable stream analogue defined in `modules/interface.js`
41
52
  */
42
53
  export function writeStream(stream, options) {
43
54
  let settings = {
@@ -1,7 +1,10 @@
1
1
  import Emitter from '../shared/emitter.js';
2
2
 
3
3
  /**
4
+ * Read a Medline file as a stream
5
+ *
4
6
  * @see modules/interface.js
7
+ * @param {Stream} stream A readable stream analogue
5
8
  * @param {Object} [options] Additional options to use when parsing
6
9
  * @param {string} [options.defaultType='journalArticle'] Default citation type to assume when no other type is specified
7
10
  * @param {string} [options.delimeter='\r'] How to split multi-line items
@@ -16,6 +19,8 @@ import Emitter from '../shared/emitter.js';
16
19
  * @param {string} options.fieldsReplace.to Field to copy/move the value to
17
20
  * @param {string} [options.fieldsReplace.delete=true] Whether to remove the orignal 'from' field if successful (i.e. reformat doesn't return false)
18
21
  * @param {function} [options.fieldsReplace.reformat] Optional function called as `(value, ref)` to provide the new field value. If return value is boolean `false` no action is taken
22
+ *
23
+ * @returns {Object} A readable stream analogue defined in `modules/interface.js`
19
24
  */
20
25
  export function readStream(stream, options) {
21
26
  let settings = {
@@ -90,7 +95,7 @@ export function readStream(stream, options) {
90
95
  from: 'medlineArticleID',
91
96
  to: 'doi',
92
97
  delete: false,
93
- reformat: v => /(?<doi>[\w\.\/_]+) \[doi\]/.exec(v)?.groups.doi || false, // eslint-disable-line no-useless-escape
98
+ reformat: v => /(?<doi>[\w\.\/_]+) \[doi\]/.exec(v)?.groups.doi || false,
94
99
  });
95
100
 
96
101
  // Allow parsing of years
@@ -130,7 +135,7 @@ export function readStream(stream, options) {
130
135
 
131
136
  let bufferSegment;
132
137
 
133
- while (bufferSegment = bufferSplitter.exec(buffer)) { // eslint-disable-line no-cond-assign
138
+ while (bufferSegment = bufferSplitter.exec(buffer)) {
134
139
  let parsedRef = parseRef(buffer.substring(bufferCrop, bufferSegment.index), settings); // Parse the ref from the start+end points
135
140
  emitter.emit('ref', parsedRef);
136
141
 
@@ -156,10 +161,15 @@ export function readStream(stream, options) {
156
161
 
157
162
 
158
163
  /**
164
+ * Write a Medline citation file to a stream
159
165
  * @see modules/interface.js
166
+ *
167
+ * @param {Stream} stream The stream to write to
160
168
  * @param {Object} [options] Additional options to use when parsing
161
169
  * @param {string} [options.defaultType='journalArticle'] Default citation type to assume when no other type is specified
162
170
  * @param {string} [options.delimeter='\r'] How to split multi-line items
171
+ *
172
+ * @returns {Object} A writable stream analogue defined in `modules/interface.js`
163
173
  */
164
174
  export function writeStream(stream, options) {
165
175
  let settings = {
@@ -220,8 +230,11 @@ export function writeStream(stream, options) {
220
230
  /**
221
231
  * Parse a single RIS format reference from a block of text
222
232
  * This function is used internally by parseStream() for each individual reference
233
+ *
223
234
  * @param {string} refString Raw RIS string composing the start -> end of the ref
224
235
  * @param {Object} settings Additional settings to pass, this should be initialized + parsed by the calling function for efficiency, see readStream() for full spec
236
+ *
237
+ * @returns {ReflibRef} A single reference, parsed form the incoming string
225
238
  */
226
239
  export function parseRef(refString, settings) {
227
240
  let ref = {}; // Reference under construction
package/modules/ris.js CHANGED
@@ -1,10 +1,16 @@
1
1
  import Emitter from '../shared/emitter.js';
2
2
 
3
3
  /**
4
+ * Parse a RIS file from a readable stream
5
+ *
4
6
  * @see modules/interface.js
7
+ *
8
+ * @param {Stream} stream The readable stream to accept data from
5
9
  * @param {Object} [options] Additional options to use when parsing
6
10
  * @param {string} [options.defaultType='report'] Default citation type to assume when no other type is specified
7
11
  * @param {string} [options.delimeter='\r'] How to split multi-line items
12
+ *
13
+ * @returns {Object} A readable stream analogue defined in `modules/interface.js`
8
14
  */
9
15
  export function readStream(stream, options) {
10
16
  let settings = {
@@ -28,7 +34,7 @@ export function readStream(stream, options) {
28
34
  let bufferSplitter = /(\r\n|\n)ER\s+-\s*(\r\n|\n)/g; // RegExp to use per segment (multiple calls to .exec() stores state because JS is a hellscape)
29
35
 
30
36
  let bufferSegment;
31
- while (bufferSegment = bufferSplitter.exec(buffer)) { // eslint-disable-line no-cond-assign
37
+ while (bufferSegment = bufferSplitter.exec(buffer)) {
32
38
  let parsedRef = parseRef(buffer.substring(bufferCrop, bufferSegment.index), settings); // Parse the ref from the start+end points
33
39
 
34
40
  emitter.emit('ref', parsedRef);
@@ -55,10 +61,17 @@ export function readStream(stream, options) {
55
61
 
56
62
 
57
63
  /**
64
+ * Write a RIS file to a writable stream
65
+ *
58
66
  * @see modules/interface.js
67
+ *
68
+ * @param {Stream} stream The writable stream to write to
69
+ *
59
70
  * @param {Object} [options] Additional options to use when parsing
60
71
  * @param {string} [options.defaultType='journalArticle'] Default citation type to assume when no other type is specified
61
72
  * @param {string} [options.delimeter='\r'] How to split multi-line items
73
+ *
74
+ * @returns {Object} A writable stream analogue defined in `modules/interface.js`
62
75
  */
63
76
  export function writeStream(stream, options) {
64
77
  let settings = {
@@ -116,8 +129,10 @@ export function writeStream(stream, options) {
116
129
  /**
117
130
  * Parse a single RIS format reference from a block of text
118
131
  * This function is used internally by parseStream() for each individual reference
132
+ *
119
133
  * @param {string} refString Raw RIS string composing the start -> end of the ref
120
134
  * @param {Object} settings Additional settings to pass, this should be initialized + parsed by the calling function for efficiency, see readStream() for full spec
135
+ * @returns {ReflibRef} The parsed reference
121
136
  */
122
137
  export function parseRef(refString, settings) {
123
138
  let ref = {}; // Reference under construction
@@ -16,13 +16,15 @@ export default class BrowserJSONStream {
16
16
  try {
17
17
  // Parse this.text as JSON
18
18
  const jsonArray = JSON.parse(this.text);
19
+
19
20
  // Free memory
20
21
  this.text = '';
21
22
 
22
23
  // For each entry in the json array (as ref):
23
- jsonArray.forEach(ref => {
24
- this.emitter.emit('data', ref);
25
- });
24
+ if (Array.isArray(jsonArray))
25
+ jsonArray.forEach(ref => {
26
+ this.emitter.emit('data', ref);
27
+ });
26
28
 
27
29
  // Finished
28
30
  this.emitter.emit('end');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iebh/reflib",
3
- "version": "2.4.2",
3
+ "version": "2.4.4",
4
4
  "description": "Reference / Citation reference library utilities",
5
5
  "scripts": {
6
6
  "lint": "eslint .",
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "repository": {
11
11
  "type": "git",
12
- "url": "https://github.com/IEBH/Reflib"
12
+ "url": "git+https://github.com/IEBH/Reflib.git"
13
13
  },
14
14
  "keywords": [
15
15
  "reflib",
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * Camel case any input string
3
3
  * This is functionally the same as Lodash's camelCase() function
4
+ *
4
5
  * @param {string} input The input string to camelize
5
- * @return {string} The input string in camelCase format
6
+ * @returns {string} The input string in camelCase format
6
7
  * @url https://github.com/MomsFriendlyDevCo/Nodash
7
8
  */
8
9
  export default function(input) {
package/shared/emitter.js CHANGED
@@ -3,6 +3,8 @@ import Mitt from 'mitt';
3
3
  /**
4
4
  * Generic wrapper for an event emitter
5
5
  * This module returns a wrapped version of `mitt` stand-alone event emitter (+ support for method chaining)
6
+ *
7
+ * @returns {Object} A wrapped version of the NPM Mitt event emitter with chainable functionality
6
8
  */
7
9
  export default function emitter() {
8
10
  let emitter = Mitt();