1.2.0 • Published 3 months ago

file-to-any v1.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

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.
1.2.0

3 months ago

1.1.0

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.0.6

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

2 years ago

1.0.0

2 years ago

0.0.4

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago