Comparing version 1.0.1 to 1.0.2
@@ -22,3 +22,7 @@ /** | ||
getIp(): Promise<string>; | ||
testSpeed(): Promise<number>; | ||
/** | ||
* @param {string} resource 资源路径 | ||
* @param {number} size 资源大小 KB | ||
*/ | ||
testSpeed(resource?: string, size?: number): Promise<number>; | ||
[key: string]: any; | ||
@@ -25,0 +29,0 @@ } |
@@ -138,13 +138,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
}); | ||
const testSpeed = () => __awaiter(this, void 0, void 0, function* () { | ||
const testSpeed = (resource = 'https://zhiper-cdn.oss-cn-shanghai.aliyuncs.com/test-network-speed.jpg', size = 194.84) => __awaiter(this, void 0, void 0, function* () { | ||
const testNetwork = () => { | ||
return new Promise((resolve, reject) => { | ||
let img = document.createElement('img'); | ||
img.src = 'https://zhiper-cdn.oss-cn-shanghai.aliyuncs.com/test-network-speed.jpg?_=' + Date.now(); | ||
let size = 194.84; // 图片大小为194KB | ||
img.src = resource + '?_=' + Date.now(); | ||
img.onload = function (evt) { | ||
resolve(size * 1000 / Math.ceil(evt.timeStamp)); | ||
}; | ||
img.onerror = function (evt) { | ||
reject('download fail'); | ||
img.onerror = function () { | ||
reject(`download fail`); | ||
}; | ||
@@ -154,5 +153,5 @@ }); | ||
// 网速测试10次 取平均数 | ||
let size = 10; | ||
let count = 10; | ||
let rs = new Array(); | ||
for (let i = 0; i < size; i++) { | ||
for (let i = 0; i < count; i++) { | ||
try { | ||
@@ -165,3 +164,3 @@ rs.push(yield testNetwork()); | ||
} | ||
return rs.reduce((total, num) => total + num) / size; | ||
return rs.reduce((total, num) => total + num) / count; | ||
}); | ||
@@ -168,0 +167,0 @@ return { |
{ | ||
"name": "detection", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18318
532