@tknf-labs/read-files
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

Read File Promise

Utility for async use of FileReader API on browser.

Created by TKNF LLC License npm npm



Installation

From npm

npm install --save @tknf-labs/read-files # npm
yarn add @tknf-labs/read-files           # yarn
pnpm add @tknf-labs/read-files           # pnpm

in browser

<script src="https://unpkg.com/@tknf-labs/read-files@0.1.0/dist/index.min.js"></script>

Basic usage

import { readAsDataUrl, safeReadAsDataUrl } from "@tknf-labs/read-files";

document.querySelector("input#file-upload").addEventListener("change", async (e) => {
  const files = e.target.files;
  if (!files.length) return;
  for (const file of files) {
    // reading file
    await readAsDataUrl(file); // => "data:image/jpeg;base64,..."

    // "safe" reading
    await safeReadAsDataUrl(file); // => { result: "data:image/jpeg;base64,...", error: null }
    await safeReadAsDataUrl("not file"); // => { result: null, error: DOMException }
  }
});

Changelog

View the changelog at CHANGELOG.md

Dependencies (0)

    Dev Dependencies (13)

    Package Sidebar

    Install

    npm i @tknf-labs/read-files

    Weekly Downloads

    0

    Version

    1.1.1

    License

    MIT

    Unpacked Size

    65.8 kB

    Total Files

    16

    Last publish

    Collaborators

    • mast1ff