@iebh/reflib 2.6.0 → 2.6.2
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/lib/formats.js +1 -1
- package/modules/bibtex.js +9 -2
- package/package.json +1 -1
package/lib/formats.js
CHANGED
package/modules/bibtex.js
CHANGED
|
@@ -22,6 +22,7 @@ const MODES = {
|
|
|
22
22
|
* @param {Object} [options] Additional options to use when parsing
|
|
23
23
|
* @param {Boolean} [options.recNumberNumeric=true] Only process the BibTeX ID into a recNumber if its a finite numeric, otherwise disguard
|
|
24
24
|
* @param {Boolean} [options.recNumberRNPrefix=true] Accept `RN${NUMBER}` as recNumber if present
|
|
25
|
+
* @param {Boolean} [options.recNumberKey=true] If the reference key cannot be otherwise parsed store it in `key<String>` instead
|
|
25
26
|
* @param {Boolean} [options.omitUnkown=false] If true, only keep known reconised fields
|
|
26
27
|
* @param {String} [options.fallbackType='unkown'] Reflib fallback type if the incoming type is unrecognised or unsupported
|
|
27
28
|
* @param {Set<String>} [options.fieldsOverwrite] Set of field names where the value is clobbered rather than appended if discovered more than once
|
|
@@ -32,6 +33,7 @@ export function readStream(stream, options) {
|
|
|
32
33
|
let settings = {
|
|
33
34
|
recNumberNumeric: true,
|
|
34
35
|
recNumberRNPrefix: true,
|
|
36
|
+
recNumberKey: true,
|
|
35
37
|
omitUnknown: false,
|
|
36
38
|
fallbackType: 'unknown',
|
|
37
39
|
fieldsOverwrite: new Set(['type']),
|
|
@@ -62,6 +64,8 @@ export function readStream(stream, options) {
|
|
|
62
64
|
ref.recNumber = +match.groups.id.slice(2);
|
|
63
65
|
} else if (!settings.recNumberNumeric && match.groups.id) { // Non numeric / finite ID - but we're allowed to accept it anyway
|
|
64
66
|
ref.recNumber = +match.groups.id;
|
|
67
|
+
} else if (settings.recNumberKey) { // Non numeric, custom looking key, stash in 'key' instead
|
|
68
|
+
ref.key = match.groups.id;
|
|
65
69
|
} // Implied else - No ID, ignore
|
|
66
70
|
|
|
67
71
|
ref.type = match.groups.type;
|
|
@@ -193,6 +197,7 @@ export function escape(str) {
|
|
|
193
197
|
* @param {Boolean} [options.omitUnkown=false] If true, only keep known reconised fields
|
|
194
198
|
* @param {Set} [options.omitFields] Set of special fields to always omit, either because we are ignoring or because we have special treatment for them
|
|
195
199
|
* @param {Boolean} [options.recNumberRNPrefix=true] Rewrite recNumber fields as `RN${NUMBER}`
|
|
200
|
+
* @param {Boolean} [options.recNumberKey=true] If the reference `recNumber` is empty use `key<String>` instead
|
|
196
201
|
*
|
|
197
202
|
* @returns {Object} A writable stream analogue defined in `modules/interface.js`
|
|
198
203
|
*/
|
|
@@ -201,8 +206,9 @@ export function writeStream(stream, options) {
|
|
|
201
206
|
defaultType: 'Misc',
|
|
202
207
|
delimeter: '\n',
|
|
203
208
|
omitUnkown: false,
|
|
204
|
-
omitFields: new Set(['recNumber', 'type']),
|
|
209
|
+
omitFields: new Set(['key', 'recNumber', 'type']),
|
|
205
210
|
recNumberRNPrefix: true,
|
|
211
|
+
recNumberKey: true,
|
|
206
212
|
...options,
|
|
207
213
|
};
|
|
208
214
|
|
|
@@ -212,7 +218,7 @@ export function writeStream(stream, options) {
|
|
|
212
218
|
},
|
|
213
219
|
write: ref => {
|
|
214
220
|
// Fetch Reflib type definition
|
|
215
|
-
let rlType = ref.type && translations.types.rlMap.get(ref.type.toLowerCase());
|
|
221
|
+
let rlType = (ref.type || settings.defaultType) && translations.types.rlMap.get(ref.type.toLowerCase());
|
|
216
222
|
let btType = rlType?.bt || settings.defaultType;
|
|
217
223
|
|
|
218
224
|
stream.write(
|
|
@@ -220,6 +226,7 @@ export function writeStream(stream, options) {
|
|
|
220
226
|
+ (
|
|
221
227
|
ref.recNumber && settings.recNumberRNPrefix ? `RN${ref.recNumber},`
|
|
222
228
|
: ref.recNumber ? `${ref.recNumber},`
|
|
229
|
+
: ref.key ? `${ref.key},`
|
|
223
230
|
: ''
|
|
224
231
|
) + '\n'
|
|
225
232
|
+ Object.entries(ref)
|