npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@syuminghuang/easyformdata

v2.5.2

Published

🙂Convert multi-dimensional arrays or objects to formdata format

Downloads

9

Readme

easyFormData

npm
🙂translate from google
可將多維度陣列或物件轉換成formdata格式
Convert multi-dimensional arrays or objects to formdata format

😎使用方法 (usage)

    npm install --save @syuminghuang/easyformdata

📌基本用法 (basic)

範例1 (example1)
    // 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 protected]',
            file: file // <--- upload file
        }
    }

    // step3 get formdata
    const formdata = easyFormData(params)
    axios.post("example1", formdata);

image

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

    // step2 set params
    const params = {
        sellers: [
          {
            id: "1",
            nickname: "MH",
            account: "[email protected]",
            product: [
              {
                name: "RTX 3060",
                price: 12000,
                quantity: 1
              },
              {
                name: "RTX 3070",
                price: 18790,
                quantity: 2
              }
            ]
          },
          {
            id: "2",
            nickname: "profiteer",
            account: "[email protected]",
            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

📌進階用法 (advanced)

範例1 (example1)
    // step1 import js
    import easyFormData from "@syuminghuang/easyformdata";
    import axios from 'axios'; // 用於請求

    // step2 set params
    const params = {
      id:1,
      name:'MH',
      account:'[email protected]',
      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 image

範例2 (example2)
    // 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: "[email protected]",
          product: [
            {
              name: "RTX 3060",
              price: 12000,
              quantity: 1,
              status: true
            },
            {
              name: "RTX 3070",
              price: 18790,
              quantity: 2,
              status: false
            }
          ]
        },
        {
          id: "2",
          nickname: "profiteer",
          account: "[email protected]",
          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 image