-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #130 from VWBL/release-0.1.13
Release 0.1.13
- Loading branch information
Showing
33 changed files
with
3,971 additions
and
1,893 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ jobs: | |
|
||
strategy: | ||
matrix: | ||
node-version: [16.x] | ||
node-version: [20.x] | ||
|
||
steps: | ||
- name: Checkout | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
presets: [ | ||
['@babel/preset-env', {targets: {node: 'current'}}], | ||
'@babel/preset-typescript', | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
preset: "ts-jest/presets/js-with-babel-esm", | ||
testEnvironment: "node", | ||
testMatch: ['**/unit/**/*.test.ts'], | ||
transformIgnorePatterns: ['/node_modules'] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,48 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const FileReaderNodeJs = require("filereader"); | ||
import mime from "mime"; | ||
|
||
import { FileOrPath } from "../vwbl/types"; | ||
const isRunningOnBrowser = typeof window !== "undefined"; | ||
|
||
export const toBase64FromBlob = async (blob: Blob): Promise<string> => { | ||
return new Promise((resolve, reject) => { | ||
const reader = switchReader(); | ||
reader.readAsDataURL(blob); | ||
reader.onload = () => { | ||
const result = reader.result; | ||
if (!result || typeof result !== "string") { | ||
reject("cannot convert to base64 string"); | ||
} else { | ||
resolve(result); | ||
} | ||
}; | ||
reader.onerror = (error: any) => reject(error); | ||
}); | ||
if (isRunningOnBrowser) { | ||
return new Promise((resolve, reject) => { | ||
const reader = new window.FileReader(); | ||
reader.readAsDataURL(blob); | ||
reader.onload = () => { | ||
const result = reader.result; | ||
if (!result || typeof result !== "string") { | ||
reject("cannot convert to base64 string"); | ||
} else { | ||
resolve(result); | ||
} | ||
}; | ||
reader.onerror = (error: any) => reject(error); | ||
}); | ||
} | ||
const arrayBuffer = await blob.arrayBuffer(); | ||
const buffer = Buffer.from(arrayBuffer); | ||
return buffer.toString("base64"); | ||
}; | ||
|
||
export const getMimeType = (file: File): string => { | ||
return file.type; | ||
export const getMimeType = (file: FileOrPath): string => { | ||
return file instanceof File ? file.type : mime.getType(file) || ""; | ||
}; | ||
|
||
export const toArrayBuffer = async (blob: Blob): Promise<ArrayBuffer> => { | ||
return new Promise((resolve, reject) => { | ||
const reader = switchReader(); | ||
reader.readAsArrayBuffer(blob); | ||
reader.onload = () => { | ||
const result = reader.result; | ||
if (!result || !(result instanceof Uint8Array)) { | ||
reject("cannot convert to ArrayBuffer"); | ||
} else { | ||
resolve(result); | ||
} | ||
}; | ||
reader.onerror = (error: any) => reject(error); | ||
}); | ||
}; | ||
|
||
const switchReader = (): any => { | ||
if (isRunningOnBrowser) { | ||
return new FileReader(); | ||
} else { | ||
return new FileReaderNodeJs(); | ||
return new Promise((resolve, reject) => { | ||
const reader = new window.FileReader(); | ||
reader.readAsArrayBuffer(blob); | ||
reader.onload = () => { | ||
const result = reader.result; | ||
if (!result || !(result instanceof Uint8Array)) { | ||
reject("cannot convert to ArrayBuffer"); | ||
} else { | ||
resolve(result); | ||
} | ||
}; | ||
reader.onerror = (error: any) => reject(error); | ||
}); | ||
} | ||
return await blob.arrayBuffer(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.