🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

solar-core

Package Overview
Dependencies
Maintainers
1
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

solar-core - npm Package Compare versions

Comparing version
4.3.1
to
4.3.2
+1
-1
package.json
{
"name": "solar-core",
"version": "4.3.1",
"version": "4.3.2",
"description": "solar core",

@@ -5,0 +5,0 @@ "main": "src/index",

@@ -5,3 +5,3 @@ /**

*/
import { NetworkExtra, RHttpHeaders } from './types';
import { NetworkExtra, NetworkOptions, RHttpHeaders } from './types';

@@ -14,3 +14,3 @@ type ResponseConvert = 'json' | 'text' | 'arrayBuffer' | 'blob'

*/
public tryNum?= 0;
public tryNum? = 0;

@@ -21,3 +21,3 @@ /**

*/
public tryAssertFunc?= (response: any) => false;
public tryAssertFunc? = (response: any) => false;

@@ -94,2 +94,5 @@ /**

// 请求配置信息
public options: NetworkOptions;
// 获取当前请求返回类型

@@ -104,13 +107,30 @@ get responseType() {

constructor(url: string, method: string, data: any, headers: RHttpHeaders) {
this.url = url;
constructor(url: string, method: string, data: any, headers: RHttpHeaders, options: NetworkOptions) {
this.data = data;
this.method = method;
this.options = options || {};
this.headers = headers || {} as RHttpHeaders;
this.url = this.normalizeUrl(url);
}
normalizeUrl(url: string) {
let base = String(this.options.base).trim();
if (/^\/\//.test(url)) {
// 如果是相对路径
url = location.protocol + url;
}
if (!/(https|http):/.test(url) && base) {
// 去除开头 /
url = url.replace(/^\//, '');
// 保证末尾存在 /
base = base[base.length - 1] == '/' ? base : base + '/';
}
const useBase = new URL(base, location.href).href;
return new URL(url, useBase).href;
}
/**
* 根据返回结果,判断当前请求是否需要重试
*/
shouldRetry?(response:any): boolean {
shouldRetry?(response: any): boolean {
if (this.tryable && this.tryAssertFunc) {

@@ -117,0 +137,0 @@ return this.tryAssertFunc(response);