@iebh/reflib 2.0.0 → 2.0.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/README.md CHANGED
@@ -18,7 +18,7 @@ Compatibility
18
18
  | EndNote ENLX | `.enlx` | :x: | :x: |
19
19
  | EndNote XML | `.xml` | :heavy_check_mark: | :heavy_check_mark: |
20
20
  | JSON | `.json` | :heavy_check_mark: | :heavy_check_mark: |
21
- | Medline | `.nbib` | :x: | :x: |
21
+ | Medline | `.nbib` | :heavy_check_mark: | :heavy_check_mark: |
22
22
  | RIS | `.ris` / `.txt` | :heavy_check_mark: | :heavy_check_mark: |
23
23
  | Tab Separated Values | `.tsv` | :x: | :x: |
24
24
 
package/lib/default.js CHANGED
@@ -1,7 +1,10 @@
1
- export * from './identifyFormat.js';
2
- export * from './formats.js';
3
- export * from './getModule.js';
4
- export * from './readFile.js';
5
- export * from './readStream.js';
6
- export * from './writeFile.js';
7
- export * from './writeStream.js';
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
+
9
+ export {identifyFormat, formats, getModule, readStream, readFile, writeStream, writeFile};
10
+ export default {identifyFormat, formats, getModule, readStream, readFile, writeStream, writeFile};
package/lib/fields.js CHANGED
@@ -125,9 +125,6 @@ export let fields = {
125
125
  language: {
126
126
  type: 'string',
127
127
  },
128
- researchNotes: {
129
- type: 'string',
130
- },
131
128
  databaseProvider: {
132
129
  type: 'string',
133
130
  },
package/lib/formats.js CHANGED
@@ -39,8 +39,8 @@ export let formats = {
39
39
  title: 'MEDLINE / PubMed',
40
40
  titleShort: 'MEDLINE',
41
41
  ext: ['.nbib'],
42
- canRead: false,
43
- canWrite: false,
42
+ canRead: true,
43
+ canWrite: true,
44
44
  },
45
45
  ris: {
46
46
  id: 'ris',
@@ -1,6 +1,6 @@
1
1
  import camelCase from '../shared/camelCase.js';
2
2
  import Emitter from '../shared/emitter.js';
3
- import {WritableStream as XMLParser} from 'htmlparser2/lib/WritableStream.js';
3
+ import {WritableStream as XMLParser} from 'htmlparser2/lib/WritableStream';
4
4
 
5
5
 
6
6
  /**
@@ -287,12 +287,12 @@ export function xmlEscape(str) {
287
287
  */
288
288
  export function xmlUnescape(str) {
289
289
  return ('' + str)
290
- .replace(/\&/g, '&')
291
- .replace(/\
/g, '\r')
292
- .replace(/\&lt;/g, '<')
293
- .replace(/\&gt;/g, '>')
294
- .replace(/\&quot;/g, '"')
295
- .replace(/\&apos;/g, "'");
290
+ .replace(/&amp;/g, '&')
291
+ .replace(/&#xD;/g, '\r')
292
+ .replace(/&lt;/g, '<')
293
+ .replace(/&gt;/g, '>')
294
+ .replace(/&quot;/g, '"')
295
+ .replace(/&apos;/g, "'");
296
296
  }
297
297
 
298
298
 
@@ -47,14 +47,14 @@ export function readStream(stream, options) {
47
47
  from: 'type',
48
48
  to: 'type',
49
49
  delete: false,
50
- reformat: (v, ref) => translations.types.rawMap[v] || settings.defaultType,
50
+ reformat: v => translations.types.rawMap[v] || settings.defaultType,
51
51
  });
52
52
 
53
53
  // Reformat authors
54
54
  settings.fieldsReplace.push({
55
55
  to: 'authors',
56
56
  reformat: (authors, ref) => (ref.medlineAuthorsShort || ref.medlineAuthorsFull || []).map(author =>
57
- author.replace(/^(?<last>[\w\-]+?) (?<initials>\w+)$/, (match, last, initials) => {
57
+ author.replace(/^(?<last>[\w-]+?) (?<initials>\w+)$/, (match, last, initials) => {
58
58
  return (
59
59
  last && initials ? last + ', ' + initials.split('').map(i => `${i}.`).join(' ')
60
60
  : last ? last
@@ -90,7 +90,7 @@ export function readStream(stream, options) {
90
90
  from: 'medlineArticleID',
91
91
  to: 'doi',
92
92
  delete: false,
93
- reformat: v => /(?<doi>[\w\.\/\_]+) \[doi\]/.exec(v)?.groups.doi || false,
93
+ reformat: v => /(?<doi>[\w\.\/_]+) \[doi\]/.exec(v)?.groups.doi || false, // eslint-disable-line no-useless-escape
94
94
  });
95
95
 
96
96
  // Allow parsing of years
@@ -128,7 +128,8 @@ export function readStream(stream, options) {
128
128
  let bufferSplitter = /(\r\n|\n){2,}/g; // RegExp to use per segment (multiple calls to .exec() stores state because JS is a hellscape)
129
129
 
130
130
  let bufferSegment;
131
- while (bufferSegment = bufferSplitter.exec(buffer)) {
131
+
132
+ while (bufferSegment = bufferSplitter.exec(buffer)) { // eslint-disable-line no-cond-assign
132
133
  let parsedRef = parseRef(buffer.substring(bufferCrop, bufferSegment.index), settings); // Parse the ref from the start+end points
133
134
  emitter.emit('ref', parsedRef);
134
135
 
@@ -187,7 +188,7 @@ export function writeStream(stream, options) {
187
188
  ? [
188
189
  'TI - ' + ref.title,
189
190
  ...(ref.authors || []).flatMap((a, i) => [
190
- ref.medlineAuthorsFull?.[i] ? `FAU - ${ref.medlineAuthorsFull[i]}` : `FAU - ${authors[i]}`,
191
+ ref.medlineAuthorsFull?.[i] ? `FAU - ${ref.medlineAuthorsFull[i]}` : `FAU - ${ref.authors[i]}`,
191
192
  ref.medlineAuthorsShort?.[i] && `AU - ${ref.medlineAuthorsShort[i]}`,
192
193
  ref.medlineAuthorsAffiliation?.[i] && `AD - ${ref.medlineAuthorsAffiliation[i]}`,
193
194
  ref.medlineAuthorsId?.[i] && `AUID- ${ref.medlineAuthorsId[i]}`,
@@ -224,7 +225,6 @@ export function writeStream(stream, options) {
224
225
  export function parseRef(refString, settings) {
225
226
  let ref = {}; // Reference under construction
226
227
  let lastField; // Last field object we saw, used to append values if they don't match the default RIS key=val one-liner
227
- let didWrap = false; // Whether the input was taken over multiple lines - if so obey `trimDotSuffix` before accepting
228
228
 
229
229
  refString
230
230
  .split(/[\r\n|\n]/) // Split into lines
@@ -237,7 +237,6 @@ export function parseRef(refString, settings) {
237
237
  if (lastField.inputArray) { // Treat each line feed like an array entry
238
238
  ref[lastField.rl].push(line);
239
239
  } else { // Assume we append each line entry as a single-line string
240
- didWrap = true;
241
240
  ref[lastField.rl] += ' ' + line;
242
241
  }
243
242
  }
@@ -246,10 +245,8 @@ export function parseRef(refString, settings) {
246
245
 
247
246
  let fieldLookup = translations.fields.rawMap.get(parsedLine.key);
248
247
 
249
- if (lastField?.trimDotSuffix) {
248
+ if (lastField?.trimDotSuffix)
250
249
  ref[lastField.rl] = ref[lastField.rl].replace(/\.$/, '');
251
- didWrap = false;
252
- }
253
250
 
254
251
  if (!fieldLookup) { // Skip unknown field translations
255
252
  lastField = null;
@@ -286,6 +283,7 @@ export function parseRef(refString, settings) {
286
283
  if (replacement.from && (replacement.delete ?? true))
287
284
  delete ref[replacement.from];
288
285
  })
286
+ // }}}
289
287
 
290
288
  return ref;
291
289
  }
package/modules/ris.js CHANGED
@@ -27,7 +27,7 @@ export function readStream(stream, options) {
27
27
  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)
28
28
 
29
29
  let bufferSegment;
30
- while (bufferSegment = bufferSplitter.exec(buffer)) {
30
+ while (bufferSegment = bufferSplitter.exec(buffer)) { // eslint-disable-line no-cond-assign
31
31
  let parsedRef = parseRef(buffer.substring(bufferCrop, bufferSegment.index), settings); // Parse the ref from the start+end points
32
32
 
33
33
  emitter.emit('ref', parsedRef);
@@ -85,9 +85,8 @@ export function writeStream(stream, options) {
85
85
  delete ref.pages;
86
86
  }
87
87
 
88
- let a ;
89
88
  stream.write(
90
- a = translations.fields.collectionOutput
89
+ translations.fields.collectionOutput
91
90
  .filter(f => ref[f.rl]) // Has field?
92
91
  .flatMap(f =>
93
92
  f.rl == 'type' // Translate type field
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iebh/reflib",
3
- "version": "2.0.0",
3
+ "version": "2.0.3",
4
4
  "description": "Reference / Citation reference library utilities",
5
5
  "scripts": {
6
6
  "lint": "eslint lib modules shared test",
@@ -36,16 +36,28 @@
36
36
  "./*": "./lib/*.js"
37
37
  },
38
38
  "devDependencies": {
39
- "chai": "^4.3.4",
40
- "eslint": "^8.7.0",
41
- "mocha": "^9.1.3",
42
- "mocha-logger": "^1.0.7",
39
+ "chai": "^4.3.6",
40
+ "eslint": "^8.15.0",
41
+ "mocha": "^10.0.0",
42
+ "mocha-logger": "^1.0.8",
43
43
  "temp": "^0.9.4"
44
44
  },
45
45
  "dependencies": {
46
- "htmlparser2": "^7.2.0",
46
+ "htmlparser2": "^8.0.1",
47
47
  "JSONStream": "^1.3.5",
48
48
  "mitt": "^3.0.0",
49
49
  "vite-plugin-replace": "^0.1.1"
50
+ },
51
+ "eslintConfig": {
52
+ "extends": "eslint:recommended",
53
+ "env": {
54
+ "browser": true,
55
+ "es2021": true,
56
+ "mocha": true
57
+ },
58
+ "parserOptions": {
59
+ "ecmaVersion": 13,
60
+ "sourceType": "module"
61
+ }
50
62
  }
51
63
  }
package/.eslintrc.cjs DELETED
@@ -1,14 +0,0 @@
1
- module.exports = {
2
- "env": {
3
- "browser": true,
4
- "es2021": true,
5
- "mocha": true
6
- },
7
- "extends": "eslint:recommended",
8
- "parserOptions": {
9
- "ecmaVersion": 13,
10
- "sourceType": "module"
11
- },
12
- "rules": {
13
- }
14
- };