// 处理get的JSON数据

export const normalizeParams = (obj: object, prefix = "?") =>
  Object.entries(obj).reduce(
    (p, [key, value]) =>
      `${p}${key}=${encodeURIComponent(value ? value : "")}&`,
    prefix
  );

// 处理formData的数据

export const normalizeFormDataParams = (params: any) => {
  const myFormData = new FormData();
  Object.keys(params).forEach(key => {
    myFormData.append(key, params[key]);
  });
  return myFormData;
};

// 生成一个get的url

export const normalize = (url: string, params: object = {}, prefix) => {
  return url + normalizeParams(params, prefix);
};
