file-to-text
v1.0.3
Published
A utility to extract the text out of a file.
Downloads
56
Maintainers
Readme
file-to-text
A utility to extract text out of a file. Currently supports the following file types as input and plain text as output.
- TXT
- CSV
- HTML
- CSS
- JS
- DOCX
- JSON
Installation
Go to the root of your project directory and run the following command.
pnpm add file-to-text
Usage
'use client'
import { fileToText } from 'file-to-text'
export default function Page() {
const [text, setText] = useState('')
async function handleFileChange(event: ChangeEvent<HTMLInputElement>) {
if (!event.target.files || event.target.files.length === 0) return
const file = event.target.files[0]
const fileText = await fileToText(file)
if (fileText) setText(fileText)
}
return (
<div>
<input type='file' accept='text/*, application/pdf' onChange={handleFileChange} />
{text}
</div>
)
}
Contributing
If you're interested in contributing, please read the contributing docs before submitting a pull request.
License
This package is licensed under the MIT License. See LICENSE for more information.