From 1fe07931334db0506666607d09a885e4b5301195 Mon Sep 17 00:00:00 2001 From: Epeius of Phocis Date: Wed, 3 Jul 2024 17:44:00 +0200 Subject: [PATCH] Update the readme --- README.md | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/README.md b/README.md index 3327f1b..eb0dfbb 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,68 @@ # formdata-parser Parse the form data + + +## Installation + +`npm install @trojs/formdata-parse` +or +`yarn add @trojs/formdata-parse` + +## Test the package + +`npm run test` +or +`yarn test` + +## How to use + + +```javascript +import parseFormData from '@trojs/formdata-parse'; + + const response = parseFormData('-----------------------------12946965154256166883262710838\r\n' + + 'Content-Disposition: form-data; name="fileName"; filename="test.txt"\r\n' + + 'Content-Type: text/plain\r\n' + + '\r\n' + + '42\n' + + '\r\n' + + '-----------------------------12946965154256166883262710838\r\n' + + 'Content-Disposition: form-data; name="fileName2"; filename="test.xml"\r\n' + + 'Content-Type: text/xml\r\n' + + '\r\n' + + '43\n' + + '\r\n' + + '-----------------------------12946965154256166883262710838--\r\n', 'multipart/form-data; boundary=---------------------------12946965154256166883262710838') +``` + +Result: +```javascript +[ + { + fieldName: 'fileName', + fileName: 'test.txt', + contentType: 'text/plain', + fileData: '42\n', + boundary: '---------------------------12946965154256166883262710838' + }, + { + fieldName: 'fileName2', + fileName: 'test.xml', + contentType: 'text/xml', + fileData: '43\n', + boundary: '---------------------------12946965154256166883262710838' + } +] +``` + +Types: +```typescript +{ + fileName: string; + fileData: string; + field: string; + contentType: string; + boundary: string; +} +``` +See also the form-data.d.ts file