Enhance the input element so it can declaratively read contents from a local file (or files).
be-literate turns this code snippet into an attribute-based HTML Enhancement / Decorator / Behavior / Directive / Custom Attribute.
Syntax:
<input type=file be-literate>
It causes the input element to emit event "enh-by-be-literate.file-contents-changed", and the contents are provided in the custom event's detail.value property.
The file contents can be read via path: inputEl.beEnhanced.beLiterate.fileContents.
To specify which of the file read options to apply to the file(s), set the attribute:
<input type=file be-literate=readAsDataURL>
If not specified, as above, the default is readAsText.
Any web server than can serve static files will do, but...
- Install git.
- Do a git clone or a git fork of repository https://github.com/bahrus/be-literate
- Install node.js
- Open command window to folder where you cloned this repo.
-
npm install
-
npm run serve
- Open http://localhost:3030/demo/dev in a modern browser.
import 'be-literate/be-literate.js';
<script type=module crossorigin=anonymous>
import 'https://esm.run/be-literate';
</script>