file-to-any
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

file-to-any

NPM npm

The file-to-any is a tiny library that could convert file to arraybuffer, dataUrl and text

Intall

npm i file-to-any -S

or

pnpm add file-to-any -S

Useage

Here is a simple demo.

import { toAny } from "file-to-any";

// You can get file by input tag with type that is file
toAny(file, "arrayBuffer").then((value) => {
  console.log(value); // value is a arrayBuffer
});

API

toAny

The all-purpose api to convert file to others.

  • Params
    • file Blob | File The file to convert.
    • options "arrayBuffer" | "dataUrl" | "objectUrl" | "text" | object
      • options.type "arrayBuffer" | "dataUrl" | "objectUrl" | | "text"
      • options.encoding "string" | undefined Only used for "text"
  • Returns
    • Promise<any> Returns the associated result according to the specified parameter.

toBinaryString

Convert file to binaryString.

  • Params
    • file Blob | File The file to convert.
    • Returns
      • Promise<string> Returns a binaryString.

toArrayBuffer

Convert file to arrayBuffer.

  • Params
    • file Blob | File The file to convert.
    • Returns
      • Promise<ArrayBuffer> Returns a arrayBuffer.

toDataUrl

Convert file to dataUrl.

  • Params
    • file Blob | File The file to convert.
    • Returns
      • Promise<string> Returns a dataUrl.

toObjectUrl

Convert file to objectUrl.

  • Params
    • file Blob | File The file to convert.
    • Returns
      • Promise<string> Returns a objectUrl.

toText

Convert file to string.

  • Params
    • file Blob | File The file to convert.
    • encoding "string" | undefined Encoding type.
    • Returns
      • Promise<string> Returns a string.

Package Sidebar

Install

npm i file-to-any

Weekly Downloads

26

Version

1.2.0

License

MIT

Unpacked Size

17.9 kB

Total Files

20

Last publish

Collaborators

  • yukiniro