@iebh/reflib 2.6.4 → 2.6.6

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 +17 -8
  2. package/package.json +1 -1
package/modules/bibtex.js CHANGED
@@ -4,10 +4,17 @@ 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 author = 'Anon';
8
+ if (ref.authors && ref.authors.length > 0) {
9
+ author = ref.authors[0].split(',')[0];
10
+ }
11
+
12
+ let year = 'n.d.';
13
+ if (ref.year) {
14
+ year = ref.year;
15
+ }
16
+
17
+ return `${author}${year}`;
11
18
  }
12
19
  /**
13
20
  * Lookup enum for the current parser mode we are in
@@ -74,9 +81,7 @@ export function readStream(stream, options) {
74
81
  } else if (!settings.recNumberNumeric && match.groups.id) { // Non numeric / finite ID - but we're allowed to accept it anyway
75
82
  ref.recNumber = +match.groups.id;
76
83
  } else if (settings.recNumberKey) { // Non numeric, custom looking key, stash in 'key' instead
77
- ref.key = generateCitationKey(ref);
78
- // ref.key = match.groups.id;
79
- console.log("Here is the id",ref.key)
84
+ ref.key = match.groups.id;
80
85
  } // Implied else - No ID, ignore
81
86
 
82
87
  ref.type = match.groups.type;
@@ -217,7 +222,7 @@ export function writeStream(stream, options) {
217
222
  defaultType: 'Misc',
218
223
  delimeter: '\n',
219
224
  omitUnkown: false,
220
- omitFields: new Set(['key', 'recNumber', 'type']),
225
+ omitFields: new Set(['recNumber', 'type']),
221
226
  recNumberRNPrefix: true,
222
227
  recNumberKey: true,
223
228
  ...options,
@@ -228,6 +233,10 @@ export function writeStream(stream, options) {
228
233
  return Promise.resolve();
229
234
  },
230
235
  write: ref => {
236
+ if (!ref.key) {
237
+ ref.key = generateCitationKey(ref);
238
+ }
239
+ console.log("Here is the id",ref.key)
231
240
  // Fetch Reflib type definition
232
241
  let rlType = (ref.type || settings.defaultType) && translations.types.rlMap.get(ref.type.toLowerCase());
233
242
  let btType = rlType?.bt || settings.defaultType;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iebh/reflib",
3
- "version": "2.6.4",
3
+ "version": "2.6.6",
4
4
  "description": "Reference / Citation reference library utilities",
5
5
  "scripts": {
6
6
  "lint": "eslint",