@iebh/reflib 2.6.3 → 2.6.5

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.
Files changed (2) hide show
  1. package/modules/bibtex.js +10 -13
  2. package/package.json +1 -1
package/modules/bibtex.js CHANGED
@@ -4,10 +4,12 @@ import Emitter from '../shared/emitter.js';
4
4
  * Example: "Roomruangwong2020"
5
5
  */
6
6
  function generateCitationKey(ref) {
7
- let author = ref.authors?.[0] || ref.author?.split(/,|\sand\s/)[0] || 'Anon';
8
- author = author.replace(/\s+/g, '').replace(/[^a-zA-Z]/g, ''); // remove spaces & non-letters
9
- let year = ref.year || new Date().getFullYear();
10
- return `${author}${year}`;
7
+ let authorLastName = 'Anon';
8
+ if (Array.isArray(ref.authors) && ref.authors.length > 0) {
9
+ authorLastName = ref.authors[0].split(',')[0].trim();
10
+ }
11
+ let year = ref.year || 'n.d.'; // fallback if no year
12
+ return `${authorLastName}${year}`;
11
13
  }
12
14
  /**
13
15
  * Lookup enum for the current parser mode we are in
@@ -66,9 +68,7 @@ export function readStream(stream, options) {
66
68
 
67
69
  while (true) {
68
70
  let match; // Regex storage for match groups
69
- console.log("Here 0")
70
71
  if ((mode == MODES.REF) && (match = /^\s*@(?<type>\w+?)\s*\{(?<id>.*?),/s.exec(buffer))) {
71
- console.log("Here 1")
72
72
  if (settings.recNumberNumeric && isFinite(match.groups.id)) { // Accept numeric recNumber
73
73
  ref.recNumber = +match.groups.id;
74
74
  } else if (settings.recNumberRNPrefix && /^RN\d+$/.test(match.groups.id)) {
@@ -76,13 +76,10 @@ export function readStream(stream, options) {
76
76
  } else if (!settings.recNumberNumeric && match.groups.id) { // Non numeric / finite ID - but we're allowed to accept it anyway
77
77
  ref.recNumber = +match.groups.id;
78
78
  } else if (settings.recNumberKey) { // Non numeric, custom looking key, stash in 'key' instead
79
- ref.key = match.groups.id;
80
- console.log("Here 2")
81
- } // Implied else - No ID, ignore
82
- else {
83
- console.log("Here 3")
84
79
  ref.key = generateCitationKey(ref);
85
- }
80
+ // ref.key = match.groups.id;
81
+ console.log("Here is the id",ref.key)
82
+ } // Implied else - No ID, ignore
86
83
 
87
84
  ref.type = match.groups.type;
88
85
  mode = MODES.FIELDS;
@@ -222,7 +219,7 @@ export function writeStream(stream, options) {
222
219
  defaultType: 'Misc',
223
220
  delimeter: '\n',
224
221
  omitUnkown: false,
225
- omitFields: new Set(['key', 'recNumber', 'type']),
222
+ omitFields: new Set(['recNumber', 'type']),
226
223
  recNumberRNPrefix: true,
227
224
  recNumberKey: true,
228
225
  ...options,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iebh/reflib",
3
- "version": "2.6.3",
3
+ "version": "2.6.5",
4
4
  "description": "Reference / Citation reference library utilities",
5
5
  "scripts": {
6
6
  "lint": "eslint",