Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alibasiccoder/easy-formdata
https://github.com/alibasiccoder/easy-formdata
Last synced: 20 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/alibasiccoder/easy-formdata
- Owner: AliBasicCoder
- Created: 2020-03-15T13:12:27.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2022-12-12T05:26:44.000Z (about 2 years ago)
- Last Synced: 2024-11-27T21:16:36.162Z (3 months ago)
- Language: JavaScript
- Size: 16.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# easy-formdata
```easy-formdata``` is a module to parse form data easily
## Usage
```js
const { expressParser, isFile } = require("easy-formdata");
const express = require("express");
const app = express();app.use(expressParser());
app.post("/api", ({ body }, res) => {
for(const key in body){
if(isFile(body[key]))
console.log(`${key} is ${body[key].size} bytes file`);
else
console.log(`${key} is a text field`);
}
res.send(body);
})app.listen(4000, () => console.log("server started"));
```## Types
### expressParser
is the middleware that parsers the formdata for [express](https://github.com/expressjs/express)
### isFile
returns true if the argument passed is a [File](#File) Object
### File
an interface having this properties
```js
interface File {
/** the file name */
filename: string;
/** the encoding of the file */
encoding: string;
/** the mimetype of the file */
mimetype: string;
/** the size of the file */
size: number;
/** the data of the file */
data: Buffer;
}
```