npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

file-promisify

v3.1.0

Published

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

Downloads

8

Readme

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.

| Parameter | Type | Description | Default | | --- | --- | --- | --- | | multiple | Boolean | Multiple selection or not. | false | | accept | String | MIME 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.

| Parameter | Type | Description | Default | | --- | --- | --- | --- | | blob | Blob | The blob of image data. | (required) | | width | Number | Target width. | null | | height | Number | Target height. | null | | crop | Boolean | Should 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.

| Parameter | Type | Description | Default | | --- | --- | --- | --- | | url | String | The URL of image. | (required) |

  • Returns: Promise<Image>

Files.blobToDataUrl(<blob>)

Transform Blob to data URL.

| Parameter | Type | Description | Default | | --- | --- | --- | --- | | blob | Blob | The blob. | (required) |

  • Returns: Promise<String>

Files.dataUrlToBlob(<dataUrl>)

Transform data URL to Blob.

| Parameter | Type | Description | Default | | --- | --- | --- | --- | | dataUrl | String | The data url. | (required) |

  • Returns: Promise<Blob>

Files.dataUrlToBase64(<dataUrl>)

Transform data URL to Base64 encoded string.

| Parameter | Type | Description | Default | | --- | --- | --- | --- | | dataUrl | String | The data url. | (required) |

  • Returns: Promise<String>

Files.blobToBase64(<blob>)

Transform Blob to Base64 encoded string.

| Parameter | Type | Description | Default | | --- | --- | --- | --- | | blob | Blob | The blob. | (required) |

  • Returns: Promise<String>

Files.blobToArrayBuffer(<blob>)

Transform Blob to ArrayBuffer.

| Parameter | Type | Description | Default | | --- | --- | --- | --- | | blob | Blob | The blob. | (required) |

  • Returns: Promise<ArrayBuffer>

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

Transform Blob to string.

| Parameter | Type | Description | Default | | --- | --- | --- | --- | | blob | Blob | The blob. | (required) | | encoding | String | The encoding. | 'UTF-8' |

  • Returns: Promise<String>

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

Transform string to Blob.

| Parameter | Type | Description | Default | | --- | --- | --- | --- | | string | String | The string. | (required) | | type | String | The MIME type. | 'application/octet-stream' |

  • Returns: Promise<Blob>

Files.stringToByteArray(<string>)

Transform string to byte array.

| Parameter | Type | Description | Default | | --- | --- | --- | --- | | string | String | The string. | (required) |

  • Returns: Promise<Uint8Array>

Files.getImageOrientation(<blob>)

Get image orientation value from Blob.

| Parameter | Type | Description | Default | | --- | --- | --- | --- | | blob | Blob | The blob of image data. | (required) |

  • Returns: Promise<Number>

Files.getMimeTypeFromDataUrl(<dataUrl>)

Get MIME type from data URL.

| Parameter | Type | Description | Default | | --- | --- | --- | --- | | dataUrl | String | The data url. | (required) |

  • Returns: Promise<String>

License

MIT