@jsarmyknife/native--file 2.0.0-beta.0 → 2.1.1-beta.0

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/dist/web.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export declare function convertFileToBase64(file: File): Promise<string>;
2
2
  export declare function convertBase64ToFile(base64: string, filename?: string): File;
3
+ export declare function convertBase64ToFileV2(base64: string, filename?: string): Promise<File>;
3
4
  export declare function getFileLink(fileInput: HTMLInputElement, fileIndex?: number): string | null;
4
5
  export declare function resizeAndCropImage({ rawImage, downsizingTo, targetCrop }: {
5
6
  rawImage: File;
package/dist/web.js CHANGED
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.convertFileToBase64 = convertFileToBase64;
4
4
  exports.convertBase64ToFile = convertBase64ToFile;
5
+ exports.convertBase64ToFileV2 = convertBase64ToFileV2;
5
6
  exports.getFileLink = getFileLink;
6
7
  exports.resizeAndCropImage = resizeAndCropImage;
7
8
  function convertFileToBase64(file) {
@@ -37,6 +38,16 @@ function convertBase64ToFile(base64, filename = "untitled") {
37
38
  }
38
39
  return new File([u8arr], filename, { type: mime[1] });
39
40
  }
41
+ async function convertBase64ToFileV2(base64, filename = "untitled") {
42
+ // Fetch the data URL and convert the response to a Blob
43
+ const response = await fetch(base64);
44
+ const blob = await response.blob();
45
+ // Get MIME type from the Blob
46
+ const mimeType = blob.type;
47
+ // Create a File object from the Blob
48
+ const file = new File([blob], filename, { type: mimeType });
49
+ return file;
50
+ }
40
51
  function getFileLink(fileInput, fileIndex = 0) {
41
52
  if (!fileInput.files) {
42
53
  return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsarmyknife/native--file",
3
- "version": "2.0.0-beta.0",
3
+ "version": "2.1.1-beta.0",
4
4
  "public": true,
5
5
  "description": "All Utilities you need for manipulating files.",
6
6
  "main": "dist/index.js",
package/web.ts CHANGED
@@ -34,6 +34,19 @@ export function convertBase64ToFile(base64: string, filename = "untitled"): File
34
34
  return new File([u8arr], filename, { type: mime[1] });
35
35
  }
36
36
 
37
+ export async function convertBase64ToFileV2(base64: string, filename = "untitled"): Promise<File> {
38
+ // Fetch the data URL and convert the response to a Blob
39
+ const response = await fetch(base64);
40
+ const blob = await response.blob();
41
+
42
+ // Get MIME type from the Blob
43
+ const mimeType = blob.type;
44
+
45
+ // Create a File object from the Blob
46
+ const file = new File([blob], filename, { type: mimeType });
47
+ return file;
48
+ }
49
+
37
50
  export function getFileLink(fileInput: HTMLInputElement, fileIndex = 0) {
38
51
  if (!fileInput.files) {
39
52
  return null;