# @syuminghuang/easyformdata

> 🙂Convert multi-dimensional arrays or objects to formdata format

Latest version **2.5.2** (published 2023-07-15) · ISC license · 0 weekly downloads

## Install

```sh
npm install @syuminghuang/easyformdata
pnpm add @syuminghuang/easyformdata
yarn add @syuminghuang/easyformdata
bun add @syuminghuang/easyformdata
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.5.2 |
| Published | 2023-07-15 |
| First published | 2022-05-02 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 9.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | syuminghuang |
| Keywords | form, formdata, upload, file, javascript, js, object-to-formdata, front-end, web |

## Links

- npm: https://www.npmjs.com/package/@syuminghuang/easyformdata
- Repository: https://github.com/MingHuang4040E095/easyFormData
- Homepage: https://github.com/MingHuang4040E095/easyFormData#readme
- Issues: https://github.com/MingHuang4040E095/easyFormData/issues
- npm.io page: https://npm.io/package/@syuminghuang/easyformdata

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 2.5.2 (latest) — 2023-07-15
- 2.5.1 — 2023-05-03
- 2.5.0 — 2023-04-13
- 2.4.8 — 2023-03-22
- 2.4.7 — 2022-09-03
- 2.4.6 — 2022-05-20
- 2.4.5 — 2022-05-20
- 2.4.4 — 2022-05-11
- 2.4.3 — 2022-05-11
- 2.4.2 — 2022-05-08
- 2.4.1 — 2022-05-08
- 2.4.0 — 2022-05-08
- 2.3.0 — 2022-05-08
- 2.2.0 — 2022-05-08
- 2.0.8 — 2022-05-07
- … 13 more at https://npm.io/package/@syuminghuang/easyformdata/versions

## README

# easyFormData
![npm](https://img.shields.io/npm/dt/@syuminghuang/easyformdata)  
🙂translate from google  
可將多維度陣列或物件轉換成formdata格式  
Convert multi-dimensional arrays or objects to formdata format  


## 😎使用方法 (usage)
```
    npm install --save @syuminghuang/easyformdata
```

## 📌基本用法 (basic)
###### 範例1  (example1)
```javascript
    // step1 import js
    import easyFormData from "@syuminghuang/easyformdata";
    import axios from 'axios';

    // step2 set params
    const params = {
        id:123,
        userInfo:{
            name:'MH',
            tel:['0911-111-111','0922-222-222'],
            account:'email@gmail.com',
            file: file // <--- upload file
        }
    }

    // step3 get formdata
    const formdata = easyFormData(params)
    axios.post("example1", formdata);
```
![image](https://github.com/MingHuang4040E095/easyFormData/blob/%E7%A7%BB%E9%99%A4%E7%AF%84%E4%BE%8B%E5%9C%96%E7%89%87/image/example.jpg)

###### 範例2  (example2)
```javascript
    // step1 import js
    import easyFormData from "@syuminghuang/easyformdata";
    import axios from 'axios'; // 用於請求

    // step2 set params
    const params = {
        sellers: [
          {
            id: "1",
            nickname: "MH",
            account: "user1@gmail.com",
            product: [
              {
                name: "RTX 3060",
                price: 12000,
                quantity: 1
              },
              {
                name: "RTX 3070",
                price: 18790,
                quantity: 2
              }
            ]
          },
          {
            id: "2",
            nickname: "profiteer",
            account: "user2@gmail.com",
            product: [
              {
                name: "RTX 3060",
                price: 15000,
                quantity: 150
              },
              {
                name: "RTX 3070",
                price: 23000,
                quantity: 200
              }
            ]
          }
        ]
    };
    // step3 get formdata
    const payload2 = easyFormData(params);
    axios.post("example2", payload2);
```
![image](https://github.com/MingHuang4040E095/easyFormData/blob/%E7%A7%BB%E9%99%A4%E7%AF%84%E4%BE%8B%E5%9C%96%E7%89%87/image/example2.jpg)


## 📌進階用法 (advanced)
###### 範例1  (example1)
```javascript
    // step1 import js
    import easyFormData from "@syuminghuang/easyformdata";
    import axios from 'axios'; // 用於請求

    // step2 set params
    const params = {
      id:1,
      name:'MH',
      account:'example1@gmail.com',
      education: {
        primarySchool:'primarySchool',
        juniorHighSchool:'juniorHighSchool',
        seniorHighSchool:'seniorHighSchool',
        university:'university'
      }
    }

    // step3 set options
    const options = {
      // 1. "convert" 轉換目標屬性的值
      // 1. "convert"  Convert the value of the target property
      convert:[
        {
          targetProperty:'name', // 目標屬性 target property
          currentValue:'MH', // 當前的值 current value
          convertValue:'Hello World!!' // 轉換後的值 convert value
        },
      ],
      // 2. "ignore" 要忽略的屬性
      // 2. "ignore" properties to ignore
      ignore:['account','primarySchool','juniorHighSchool']
    }

    // step4 get formdata
    const payload1 = easyFormData(params,options);
    axios.post("advancedExample1", payload1);
```
![image](https://github.com/MingHuang4040E095/easyFormData/blob/%E7%A7%BB%E9%99%A4%E7%AF%84%E4%BE%8B%E5%9C%96%E7%89%87/image/advancedExample1.jpg)
![image](https://github.com/MingHuang4040E095/easyFormData/blob/%E7%A7%BB%E9%99%A4%E7%AF%84%E4%BE%8B%E5%9C%96%E7%89%87/image/advancedExample1.gif)

###### 範例2  (example2)
```javascript
    // step1 import js
    import easyFormData from "@syuminghuang/easyformdata";
    import axios from 'axios'; // 用於請求
    
    // step2 set params
    const params = {
      www: false,
      test: {
        a: 111,
        b: 222
      },
      sellers: [
        {
          id: "1",
          nickname: "MH",
          account: "user1@gmail.com",
          product: [
            {
              name: "RTX 3060",
              price: 12000,
              quantity: 1,
              status: true
            },
            {
              name: "RTX 3070",
              price: 18790,
              quantity: 2,
              status: false
            }
          ]
        },
        {
          id: "2",
          nickname: "profiteer",
          account: "user2@gmail.com",
          product: [
            {
              name: "RTX 3060",
              price: 15000,
              quantity: 150,
              status: true
            },
            {
              name: "RTX 3070",
              price: 23000,
              quantity: 200,
              status: false
            }
          ]
        }
      ]
    };

    // step3 set options
    const options = {
      //  convert轉換值
      convert: [
        {
          targetProperty: "status", // 要轉換的屬性
          currentValue: false, // 當前的值
          convertValue: "0" // 轉換後的值
        },
        {
          targetProperty: "status", // 要轉換的屬性
          currentValue: true, // 當前的值
          convertValue: "1" // 轉換後的值
        }
      ],
      // 要跳過的屬性
      ignore: ["www", "name", "nickname"]
    };

    // step4 get formdata
    const payload4 = easyFormData(params,options);
    axios.post("advancedExample2", payload4);
````
![image](https://github.com/MingHuang4040E095/easyFormData/blob/%E7%A7%BB%E9%99%A4%E7%AF%84%E4%BE%8B%E5%9C%96%E7%89%87/image/advancedExample2.jpg)
![image](https://github.com/MingHuang4040E095/easyFormData/blob/%E7%A7%BB%E9%99%A4%E7%AF%84%E4%BE%8B%E5%9C%96%E7%89%87/image/advancedExample2.gif)

---
_Source: https://npm.io/package/@syuminghuang/easyformdata · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
