New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

file-promisify

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

file-promisify

Utilities for file and image handling, in Browsers, with Promise.

latest
Source
npmnpm
Version
3.2.0
Version published
Maintainers
1
Created
Source

file-promisify

Version Downloads License

Utilities for file and image handling, in Browsers, with Promise.

Live demo

Installation

Node.js

$ npm install --save file-promisify

Browser via CDN

<script src="https://cdn.jsdelivr.net/npm/file-promisify/dist/index.umd.js"></script>

Usage

import Files from 'file-promisify'

const instance = new Files()

/** open file dialog */
instance.select()
  .then(([blob]) => {})
  .catch(error => {})

/** open file dialog for selecting multiple files */
instance.select({ multiple: true })
  .then(blobs => {})
  .catch(error => {})

/** open file dialog for selecting an image file */
instance.select({ accept: 'image/*' })
  .then(blob => {
    /** wrap image into maximum 128 × 128 pixels */
    Files.processImage({ blob, width: 128, height: 128, crop: false })
      .then(dataUrl => {})
      .catch(error => {})

    /** crop image into 128 × 128 pixels exactly */
    Files.processImage({ blob, width: 128, height: 128, crop: true })
      .then(dataUrl => {})
      .catch(error => {})
  })
  .catch(error => {})

/** open directory dialog for selecting a directory (only webkit) */
instance.selectDirectory()
  .then(blobs => {})
  .catch(error => {})

API

instance.select({ multiple: [multiple], accept: [accept] })

Open a file dialog.

ParameterTypeDescriptionDefault
multipleBooleanMultiple selection or not.false
acceptStringMIME type accepted.'*/*'
  • Returns: Promise<FileList>

instance.selectDirectory()

Open a directory dialog. (only webkit)

  • Returns: Promise<FileList>

Files.processImage({ blob: <blob>, width: [width], height: [height], crop: [crop] })

Process image.

ParameterTypeDescriptionDefault
blobBlobThe blob of image data.(required)
widthNumberTarget width.null
heightNumberTarget height.null
cropBooleanShould crop or not. true for cropping image into dimension exactly, while false for wrapping image into the maximum dimension.false
  • Returns: Promise<String>

Files.urlToImage(<url>)

Fetch image URL into Image instance.

ParameterTypeDescriptionDefault
urlStringThe URL of image.(required)
  • Returns: Promise<Image>

Files.blobToDataUrl(<blob>)

Transform Blob to data URL.

ParameterTypeDescriptionDefault
blobBlobThe blob.(required)
  • Returns: Promise<String>

Files.dataUrlToBlob(<dataUrl>)

Transform data URL to Blob.

ParameterTypeDescriptionDefault
dataUrlStringThe data url.(required)
  • Returns: Promise<Blob>

Files.dataUrlToBase64(<dataUrl>)

Transform data URL to Base64 encoded string.

ParameterTypeDescriptionDefault
dataUrlStringThe data url.(required)
  • Returns: Promise<String>

Files.blobToBase64(<blob>)

Transform Blob to Base64 encoded string.

ParameterTypeDescriptionDefault
blobBlobThe blob.(required)
  • Returns: Promise<String>

Files.blobToArrayBuffer(<blob>)

Transform Blob to ArrayBuffer.

ParameterTypeDescriptionDefault
blobBlobThe blob.(required)
  • Returns: Promise<ArrayBuffer>

Files.blobToString(<blob>, [encoding])

Transform Blob to string.

ParameterTypeDescriptionDefault
blobBlobThe blob.(required)
encodingStringThe encoding.'UTF-8'
  • Returns: Promise<String>

Files.stringToBlob(<string>, [type])

Transform string to Blob.

ParameterTypeDescriptionDefault
stringStringThe string.(required)
typeStringThe MIME type.'application/octet-stream'
  • Returns: Promise<Blob>

Files.stringToByteArray(<string>)

Transform string to byte array.

ParameterTypeDescriptionDefault
stringStringThe string.(required)
  • Returns: Promise<Uint8Array>

Files.getImageOrientation(<blob>)

Get image orientation value from Blob.

ParameterTypeDescriptionDefault
blobBlobThe blob of image data.(required)
  • Returns: Promise<Number>

Files.getMimeTypeFromDataUrl(<dataUrl>)

Get MIME type from data URL.

ParameterTypeDescriptionDefault
dataUrlStringThe data url.(required)
  • Returns: Promise<String>

License

MIT

Keywords

File

FAQs

Package last updated on 30 Oct 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts