Socket
Book a DemoInstallSign in
Socket

ldfile

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ldfile

File Loader

Source
npmnpm
Version
0.0.1
Version published
Weekly downloads
1
-50%
Maintainers
1
Weekly downloads
 
Created
Source

ldFile

file loader helper in vanilla JS.

Usage

var ldf = new ldFile(config);
ldf.on("load", function(ret) {
  for(i=0;i<ret.length;i++) {
    console.log(
      ret[i].result,    # file content
      ret[i].file       # file object
    );
  }
});

Configuration

  • root - HTMLElement or CSS Selector for the input element.
  • type - one of <[dataurl text binary arraybuffer blob bloburl]>. default binary.
  • ldcv - ldCover for choosing encoding for text type. fallback to browser prompt if omitted.

Method

  • on - add event listener. Currently only one event fired:
    • load - fired when input value changed. provide a list of file information as param, with following format for each object:
      • file: the file object provided by browser.
      • result: file content parsed by ldFile.

API

  • ldFile.fromURL(url, type, encoding) - load file by URL.
    • type is the same as the type in ldFile object configuration.
    • encoding is default utf-8 and only applicable when type is text.
    • return a promise
    • resolve a {result, file} object.
  • ldFile.fromFile(file, type, encoding) - load File object
    • same with ldFile.fromURL except that the first param (file) is a File object.

Compatibility

ldFile uses following HTML5 features, which may not be supported by all browsers:

  • File Reader ( IE <= 9; read as binary needs polyfill for IE <= 11 )
  • Promise ( IE <= 11, some mobile browsers )

Please use Polyfills to support legacy browsers if necessary.

License

MIT

FAQs

Package last updated on 30 Jul 2021

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