preview-utils
v1.0.3
Published
a preview utils for web
Downloads
9
Maintainers
Readme
preview-utils
web client preview utils
install
npm i preview-utils
base64 utils
parseBase64
const {content,contentType} = parseBase64(base64)
return base64 contentType and content
fileToBase64
const base64 =await fileToBase64(file)
convert a file object to base64,this is a promise
imageToBase64
const base64 = imageToBase64(image)
// args (image, type = 'image/png', quality = .8)
convert a html image object to base64 ,use canvas,this is a sync function
imageToBlob
const file = imageToFile(image)
convert a html image object to blob
imageToFile
const blob = imageToBlob(image,"file.png")
//args (image, fileName, { lastModified = Date.now() } = {})
convert a html image object to File
imageUrlToBase64
const base64 = await imageUrlToBase64(url)
use a image url (the url allow cross domain ) from remote ,convert to base64
blobToFile
const file = blobToFile(blob)
//args (blob, fileName, { contentType, lastModified = Date.now() } = {})
convert a blob to File
base64ToBlob
const blob = base64ToBlob(base64)
convert a base64 to Blob
base64ToFile
const file = base64ToFile(base64,"file.txt")
//args (base64, fileName, { contentType, lastModified = Date.now() } = {})
convert a base64 to File
urlToBlob
const blob = await urlToBlob(url)
fetch a remote url as Blob
urlToFile
const file = await urlToFile(url,"image.png")
//args (url, fileName, { contentType, lastModified = Date.now() } = {})
fetch a remote url as File
createThumb
const thumbBase64 = await createThumb(url,100,100)
//args (file, width, height, { timeout = 2048, currentTime = 1, type = "image/png", quality = .8,toBlog=false } = {})
//file type:File,Image,HTMLVideoElement
create File | Image | Video 's thumb base64,
creatPreviewUrl
const url = await creatPreviewUrl(file)
//args (file, timeout = 2048)
use URL.createObjectURL(file) to create url,and use settimeout to revokeObjectURL