Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@uppy/utils: improve return type of dataURItoFile #5112

Merged
merged 2 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions packages/@uppy/utils/src/dataURItoBlob.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
const DATA_URL_PATTERN = /^data:([^/]+\/[^,;]+(?:[^,]*?))(;base64)?,([\s\S]*)$/

export default function dataURItoBlob(
type dataURItoBlobOptions = { mimeType?: string; name?: string }

function dataURItoBlob(dataURI: string, opts: dataURItoBlobOptions): Blob
function dataURItoBlob(
dataURI: string,
opts: dataURItoBlobOptions,
toFile: true,
): File

function dataURItoBlob(
dataURI: string,
opts: { mimeType?: string; name?: string },
opts: dataURItoBlobOptions,
toFile?: boolean,
): Blob | File {
// get the base64 data
Expand Down Expand Up @@ -30,3 +39,5 @@ export default function dataURItoBlob(

return new Blob(data, { type: mimeType })
}

export default dataURItoBlob
2 changes: 1 addition & 1 deletion packages/@uppy/utils/src/dataURItoFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import dataURItoBlob from './dataURItoBlob.ts'
export default function dataURItoFile(
dataURI: string,
opts: { mimeType?: string; name?: string },
): File | Blob {
): File {
return dataURItoBlob(dataURI, opts, true)
}
Loading