multermate 1.0.3 → 1.0.4

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 (3) hide show
  1. package/index.js +27 -36
  2. package/package.json +9 -2
  3. package/readme.md +5 -1
package/index.js CHANGED
@@ -1,7 +1,17 @@
1
- const path = require("path");
2
- const multer = require("multer");
3
- const { v4: uuidv4 } = require("uuid");
4
- const fs = require("fs/promises");
1
+ const path =
2
+ typeof require !== "undefined"
3
+ ? require("path")
4
+ : (await import("path")).default;
5
+ const multer =
6
+ typeof require !== "undefined"
7
+ ? require("multer")
8
+ : (await import("multer")).default;
9
+ const { v4: uuidv4 } =
10
+ typeof require !== "undefined" ? require("uuid") : await import("uuid");
11
+ const fs =
12
+ typeof require !== "undefined"
13
+ ? require("fs/promises")
14
+ : await import("fs/promises");
5
15
 
6
16
  // Constants for allowed MIME types
7
17
  const ALLOWED_MIME_TYPES = {
@@ -170,48 +180,29 @@ const deleteFile = async (filePath) => {
170
180
  }
171
181
  };
172
182
 
173
- // Export functions to configure multer and available file types
174
- module.exports = {
175
- /**
176
- * Function to handle a single file upload.
177
- *
178
- * @param {object} options - Configuration options for the single file upload.
179
- * @param {string} [options.destination] - Destination folder for the uploaded file.
180
- * @param {string} [options.filename] - Custom filename template for the uploaded file.
181
- * @param {Array<string>} [options.fileTypes] - Array of file types to allow (e.g., ['images']).
182
- * @param {Array<string>} [options.customMimeTypes] - Array of custom MIME types to allow.
183
- * @param {number} [options.fileSizeLimit] - Maximum file size allowed (in bytes). Default is 50MB.
184
- * @param {boolean} [options.preservePath] - Preserve the full path of the uploaded file. Default is false.
185
- * @returns {function} - Multer instance configured for single file upload.
186
- */
183
+ const exportObject = {
187
184
  uploadSingle: (options = {}) => {
188
185
  const multerInstance = configureMulter(options);
189
186
  return multerInstance.single(options.filename || "file");
190
187
  },
191
188
 
192
- /**
193
- * Function to handle multiple file uploads across multiple fields.
194
- *
195
- * @param {object} options - Configuration options for multiple file uploads.
196
- * @param {Array<object>} options.fields - Array of field configurations for multiple file uploads.
197
- * @param {string} [options.destination] - Destination folder for the uploaded files.
198
- * @param {Array<string>} [options.customMimeTypes] - Array of custom MIME types to allow.
199
- * @param {number} [options.fileSizeLimit] - Maximum file size allowed (in bytes). Default is 50MB.
200
- * @param {boolean} [options.preservePath] - Preserve the full path of the uploaded files. Default is false.
201
- * @returns {function} - Multer instance configured for multiple file uploads.
202
- */
203
189
  uploadMultiple: (options = {}) => {
204
190
  const multerInstance = configureMulter(options);
205
191
  return multerInstance.fields(options.fields || []);
206
192
  },
207
193
 
208
- /**
209
- * Export the allowed file types for reference.
210
- *
211
- * @type {Array<string>}
212
- */
213
194
  ALLOWED_FILE_TYPES: Object.keys(ALLOWED_MIME_TYPES),
214
-
215
- // Add the delete file utility
216
195
  deleteFile,
217
196
  };
197
+
198
+ // Dual export support
199
+ if (typeof module !== "undefined" && module.exports) {
200
+ module.exports = exportObject;
201
+ } else {
202
+ Object.assign(globalThis, {
203
+ uploadSingle: exportObject.uploadSingle,
204
+ uploadMultiple: exportObject.uploadMultiple,
205
+ ALLOWED_FILE_TYPES: exportObject.ALLOWED_FILE_TYPES,
206
+ deleteFile: exportObject.deleteFile,
207
+ });
208
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "multermate",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "A flexible and customizable npm package for configuring Multer",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -26,5 +26,12 @@
26
26
  "bugs": {
27
27
  "url": "https://github.com/Wasim-Zaman/multermate/issues"
28
28
  },
29
- "homepage": "https://github.com/Wasim-Zaman/multermate#readme"
29
+ "homepage": "https://github.com/Wasim-Zaman/multermate#readme",
30
+ "type": "commonjs",
31
+ "exports": {
32
+ ".": {
33
+ "require": "./index.js",
34
+ "import": "./index.js"
35
+ }
36
+ }
30
37
  }
package/readme.md CHANGED
@@ -24,7 +24,11 @@ npm install multermate
24
24
  ## Basic Usage
25
25
 
26
26
  ```javascript
27
+ // CommonJS
27
28
  const { uploadSingle, uploadMultiple, deleteFile } = require("multermate");
29
+
30
+ // ES Modules
31
+ import { uploadSingle, uploadMultiple, deleteFile } from "multermate";
28
32
  ```
29
33
 
30
34
  ## Upload Configurations
@@ -248,7 +252,7 @@ Contributions are welcome! Please feel free to submit issues and pull requests.
248
252
 
249
253
  ## Author
250
254
 
251
- Your Name
255
+ Wasim Zaman
252
256
 
253
257
  ## Support
254
258