You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.2 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("./utils");
const utils_lang_1 = require("./utils.lang");
const isStream = require('is-stream');
/**
* 是否能够使用 FormData 发送数据
* @param {any} data - 待发送的数据
*/
function canUseFormdata(data) {
let enable = true;
for (const key in data) {
const value = data[key];
if (!isStream(value) && (utils_1.isNodeEnv() && !Buffer.isBuffer(value)) && !utils_lang_1.isString(value) && !utils_lang_1.isNumber(value)) {
enable = false;
break;
}
}
return enable;
}
exports.canUseFormdata = canUseFormdata;
/**
* 是否一定要通过 FormData 发送数据
* 如果有 Buffer 和 Stream 必须用 multipart/form-data如果同时还含有
* @param {any} data - 待发送的数据
*/
function mustUseFormdata(data) {
let must = false;
for (const key in data) {
const value = data[key];
if ((utils_1.isNodeEnv() && Buffer.isBuffer(value)) || isStream(value)) {
must = true;
break;
}
}
return must;
}
exports.mustUseFormdata = mustUseFormdata;