@iebh/reflib 2.2.0 → 2.2.1

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.
@@ -9,13 +9,15 @@ import {writeStream} from './writeStream.js';
9
9
  * @param {Object} [options] Additional options when prompting the user
10
10
  * @param {String} [options.filename='References.xml'] The filename to download
11
11
  * @param {Object} [options.writeStreamOptions] Additional options for the subsequent `writeStream` internal call
12
+ * @param {Object} [options.promptDownload=true] Prompt the user to save the file, if falsy this returns the Blob file content instead of asking the user where to save it
12
13
  *
13
- * @returns {Promise} A promise which will resolve when the file download has completed
14
+ * @returns {Promise|Promise<Blob>} A promise which will resolve when the file download has completed or (if `!promptDownload`) with the blob contents
14
15
  */
15
16
  export function downloadFile(refs, options) {
16
17
  let settings = {
17
18
  filename: 'References.xml',
18
19
  writeStreamOptions: {},
20
+ promptDownload: true,
19
21
  ...options,
20
22
  };
21
23
 
@@ -74,6 +76,8 @@ export function downloadFile(refs, options) {
74
76
  // }}}
75
77
  // Download Blob
76
78
  .then(blob => {
79
+ if (!settings.promptDownload) return blob;
80
+
77
81
  let url = URL.createObjectURL(blob);
78
82
  let aEl = document.createElement('a');
79
83
  aEl.href = url;
package/lib/uploadFile.js CHANGED
@@ -8,7 +8,7 @@ import StreamEmitter from '../shared/streamEmitter.js';
8
8
  * @param {Object} [options] Additional options when prompting the user
9
9
  * @param {File} [options.file] The File object to process, omitting this will prompt the user to select a file
10
10
  * @param {function} [options.onStart] Async function called as `(File)` when starting the read stage
11
- * @param {function} [options.onProgress] Function called as `(position, totalSize)` when processing the file
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
13
  * @param {*} [options.*] Additional settings to pass to `readStream()`
14
14
  * @returns {Promise} A promise which will resolve with an array of extracted citations
@@ -17,6 +17,7 @@ export function uploadFile(options) {
17
17
  let settings = {...options};
18
18
 
19
19
  if (!settings.file) { // No file provided - prompt the user via the DOM
20
+ // Horrible kludge to create an upload element in the DOM + interact with it {{{
20
21
  return new Promise(resolve => {
21
22
  // Create hidden layer we will use to wrap the actual file upload input box
22
23
  let fileWrapper = document.createElement('div');
@@ -40,6 +41,7 @@ export function uploadFile(options) {
40
41
  fileWrapper.appendChild(uploader);
41
42
  uploader.dispatchEvent(new MouseEvent('click'));
42
43
  });
44
+ // }}}
43
45
  } else { // Read the File object and return an emitter
44
46
  if (!(settings.file instanceof File)) throw new Error('Expected "file" setting to uploadFile() to be a File type');
45
47
  let identifiedType = identifyFormat(settings.file.name);
@@ -49,7 +51,6 @@ export function uploadFile(options) {
49
51
  return Promise.resolve()
50
52
  .then(()=> settings.onStart && settings.onStart(settings.file))
51
53
  .then(()=> new Promise((resolve, reject) => {
52
-
53
54
  let streamer = readStream(
54
55
  identifiedType.id,
55
56
  StreamEmitter(settings.file.stream()),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iebh/reflib",
3
- "version": "2.2.0",
3
+ "version": "2.2.1",
4
4
  "description": "Reference / Citation reference library utilities",
5
5
  "scripts": {
6
6
  "lint": "eslint lib modules shared test",