Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mp-network

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mp-network - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

15

dist/index.d.ts

@@ -22,2 +22,7 @@ declare type HeaderValue = string | string[] | number | boolean | null;

/**
* 请求地址前缀
* @default ''
*/
baseUrl?: string;
/**
* 超时时间。 单位: `ms`

@@ -121,2 +126,7 @@ * @default 60000

/**
* 请求地址前缀
* @default ''
*/
baseUrl?: string;
/**
* HTTP 请求的 Header

@@ -154,2 +164,7 @@ */

/**
* 请求地址前缀
* @default ''
*/
baseUrl?: string;
/**
* 要上传文件资源的路径 (本地路径)

@@ -156,0 +171,0 @@ */

18

dist/index.js

@@ -26,2 +26,11 @@ // src/utils/is.ts

// src/utils/combUrl.ts
var httpPattern = /^([a-z][a-z\d+\-.]*:)?\/\//i;
var isHttp = (url) => httpPattern.test(url);
var combUrl = (baseUrl, url) => {
if (isHttp(url))
return url;
return url ? `${baseUrl.replace(/\/+$/, "")}/${url.replace(/^\/+/, "")}` : baseUrl;
};
// src/core/support.ts

@@ -203,3 +212,6 @@ var platformList = [

transformOptions(options) {
return deepMerge({}, this.options, options);
const _options = deepMerge({}, this.options, options);
_options.url = combUrl(this.options.baseUrl || "", options.url);
delete _options.baseUrl;
return _options;
}

@@ -238,4 +250,6 @@ get(url, data, options) {

_option.filePath = data.filePath;
_option.url = combUrl(_option.baseUrl || "", _option.url);
delete data.filePath;
delete data.name;
delete _option.baseUrl;
_option.formData = deepMerge(

@@ -282,2 +296,4 @@ _option.formData,

);
_option.url = combUrl(_option.baseUrl || "", _option.url);
delete _option.baseUrl;
const adapter = downloadAdapter(_option);

@@ -284,0 +300,0 @@ const promise = adapter.promise;

2

package.json
{
"name": "mp-network",
"version": "0.1.1",
"version": "0.1.2",
"description": "小程序 网络请求接口二次封装, request/upload/download,适配多个平台",

@@ -5,0 +5,0 @@ "keywords": [

@@ -274,2 +274,3 @@ # mp-network

const customRequest = createRequest({
baseUrl: 'http://example.com/',
timeout: 60000,

@@ -283,3 +284,3 @@ dataType: 'json',

// 发起 post 请求
customRequest.post('https://example.com/b', { b: 1 })
customRequest.post('/b', { b: 1 })
.then((response) => {

@@ -298,2 +299,3 @@ console.log(response)

const customUpload = createUpload({
baseUrl: 'http://example.com/',
timeout: 60000

@@ -303,3 +305,3 @@ })

// 上传文件
customUpload('https://example.com/upload', { filePath: '/local/1.txt', name: '1.txt' })
customUpload('/upload', { filePath: '/local/1.txt', name: '1.txt' })
.then((response) => {

@@ -318,6 +320,7 @@ console.log(response)

const customDownload = createDownload({
baseUrl: 'http://example.com/',
timeout: 60000
})
// 下载文件
customDownload('https://example.com/download', 'local/1.txt')
customDownload('/download', 'local/1.txt')
.then((response) => {

@@ -334,2 +337,3 @@ console.log(response)

| -- | -- | -- |
| baseUrl | string | 请求路径公共前缀 |
| timeout |number | 超时时间,单位为毫秒。默认值为 60000 |

@@ -352,2 +356,3 @@ | header | object | 设置请求的 header |

| -- | -- | -- |
| baseUrl | string | 请求路径公共前缀 |
| timeout |number | 超时时间,单位为毫秒。|

@@ -360,2 +365,3 @@ | header | object | 设置请求的 header |

| -- | -- | -- |
| baseUrl | string | 请求路径公共前缀 |
| timeout |number | 超时时间,单位为毫秒。|

@@ -362,0 +368,0 @@ | header | object | 设置请求的 header |

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc