network-speed-js 0.0.2 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/README.md +817 -6
  2. package/dist/core/performance-utils.d.ts +21 -0
  3. package/dist/core/performance-utils.d.ts.map +1 -0
  4. package/dist/core/sdk.d.ts +34 -0
  5. package/dist/core/sdk.d.ts.map +1 -0
  6. package/dist/core/speed-tester.d.ts +34 -0
  7. package/dist/core/speed-tester.d.ts.map +1 -0
  8. package/dist/core/types.d.ts +59 -0
  9. package/dist/core/types.d.ts.map +1 -0
  10. package/dist/index.d.ts +4 -0
  11. package/dist/index.d.ts.map +1 -0
  12. package/dist/network-speed-js.js +175 -0
  13. package/dist/network-speed-js.umd.js +1 -0
  14. package/package.json +50 -7
  15. package/.eslintrc.js +0 -3
  16. package/.vscode/extensions.json +0 -3
  17. package/index.html +0 -13
  18. package/playground/.vscode/extensions.json +0 -3
  19. package/playground/README.md +0 -18
  20. package/playground/index.html +0 -13
  21. package/playground/package.json +0 -21
  22. package/playground/pnpm-global/5/pnpm-lock.yaml +0 -7
  23. package/playground/pnpm-lock.yaml +0 -701
  24. package/playground/public/vite.svg +0 -1
  25. package/playground/src/App.vue +0 -11
  26. package/playground/src/assets/vue.svg +0 -1
  27. package/playground/src/components/HelloWorld.vue +0 -38
  28. package/playground/src/main.ts +0 -7
  29. package/playground/src/style.css +0 -79
  30. package/playground/src/vite-env.d.ts +0 -1
  31. package/playground/tsconfig.json +0 -25
  32. package/playground/tsconfig.node.json +0 -10
  33. package/playground/vite.config.ts +0 -7
  34. package/pnpm-lock.yaml +0 -928
  35. package/src/App.vue +0 -118
  36. package/src/api.ts +0 -23
  37. package/src/index.ts +0 -1
  38. package/src/main.ts +0 -5
  39. package/src/vite-env.d.ts +0 -1
  40. package/tsconfig.json +0 -25
  41. package/tsconfig.node.json +0 -10
  42. package/vite.config.ts +0 -13
@@ -0,0 +1,21 @@
1
+ import type { ResourceSpeedInfo } from './types';
2
+ /**
3
+ * 计算单个资源的下载速度
4
+ */
5
+ export declare function calcSpeedByResource(entry: PerformanceResourceTiming): ResourceSpeedInfo | null;
6
+ /**
7
+ * 获取所有资源的测速信息
8
+ */
9
+ export declare function getAllResourcesSpeeds(): ResourceSpeedInfo[];
10
+ /**
11
+ * 清除指定URL的性能记录
12
+ */
13
+ export declare function clearPerformanceEntry(url: string): void;
14
+ /**
15
+ * 评估网络类型
16
+ */
17
+ export declare function evaluateNetworkType(speedMbps: number, thresholds?: {
18
+ fast: number;
19
+ medium: number;
20
+ }): 'fast' | 'medium' | 'slow' | 'unknown';
21
+ //# sourceMappingURL=performance-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"performance-utils.d.ts","sourceRoot":"","sources":["../../src/core/performance-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEjD;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,yBAAyB,GAC/B,iBAAiB,GAAG,IAAI,CAoB1B;AAED;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,iBAAiB,EAAE,CAU3D;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAKvD;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,MAAM,EACjB,UAAU;;;CAA0B,GACnC,MAAM,GAAG,QAAQ,GAAG,MAAM,GAAG,SAAS,CASxC"}
@@ -0,0 +1,34 @@
1
+ import type { SpeedTestOptions, SpeedTestResult, ResourceSpeedInfo } from './types';
2
+ /**
3
+ * 网速测试 SDK
4
+ */
5
+ export declare class NetworkSpeedSDK {
6
+ private tester;
7
+ constructor(options?: SpeedTestOptions);
8
+ /**
9
+ * 执行网速测试
10
+ */
11
+ test(): Promise<SpeedTestResult>;
12
+ /**
13
+ * 获取所有已加载资源的速度信息
14
+ */
15
+ getAllResourcesSpeeds(): ResourceSpeedInfo[];
16
+ /**
17
+ * 监听特定资源的性能数据
18
+ */
19
+ observeResource(urlPattern: string, callback: (entry: PerformanceResourceTiming) => void): () => void;
20
+ /**
21
+ * 更新配置
22
+ */
23
+ updateOptions(options: Partial<SpeedTestOptions>): void;
24
+ /**
25
+ * 销毁SDK实例
26
+ */
27
+ destroy(): void;
28
+ }
29
+ /**
30
+ * 创建SDK实例的工厂函数
31
+ */
32
+ export declare function createNetworkSpeedSDK(options?: SpeedTestOptions): NetworkSpeedSDK;
33
+ export default NetworkSpeedSDK;
34
+ //# sourceMappingURL=sdk.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../../src/core/sdk.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEpF;;GAEG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,MAAM,CAAc;gBAEhB,OAAO,GAAE,gBAAqB;IAI1C;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,eAAe,CAAC;IAItC;;OAEG;IACH,qBAAqB,IAAI,iBAAiB,EAAE;IAI5C;;OAEG;IACH,eAAe,CACb,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,CAAC,KAAK,EAAE,yBAAyB,KAAK,IAAI,GACnD,MAAM,IAAI;IAIb;;OAEG;IACH,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,gBAAgB,CAAC,GAAG,IAAI;IAIvD;;OAEG;IACH,OAAO,IAAI,IAAI;CAGhB;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,CAAC,EAAE,gBAAgB,GAAG,eAAe,CAEjF;AAGD,eAAe,eAAe,CAAC"}
@@ -0,0 +1,34 @@
1
+ import type { SpeedTestResult, SpeedTestOptions, PerformanceEntryCallback } from './types';
2
+ /**
3
+ * 网速测试核心类
4
+ */
5
+ export declare class SpeedTester {
6
+ private options;
7
+ private observer;
8
+ constructor(options?: SpeedTestOptions);
9
+ /**
10
+ * 执行测速
11
+ */
12
+ test(): Promise<SpeedTestResult>;
13
+ /**
14
+ * 自动检测内外网并测速
15
+ */
16
+ private testWithAutoDetect;
17
+ /**
18
+ * 测试单个URL
19
+ */
20
+ private testSingleUrl;
21
+ /**
22
+ * 监听特定资源的性能数据
23
+ */
24
+ observeResource(urlPattern: string, callback: PerformanceEntryCallback): () => void;
25
+ /**
26
+ * 更新配置
27
+ */
28
+ updateOptions(options: Partial<SpeedTestOptions>): void;
29
+ /**
30
+ * 销毁实例
31
+ */
32
+ destroy(): void;
33
+ }
34
+ //# sourceMappingURL=speed-tester.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"speed-tester.d.ts","sourceRoot":"","sources":["../../src/core/speed-tester.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,gBAAgB,EAChB,wBAAwB,EACzB,MAAM,SAAS,CAAC;AAGjB;;GAEG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,OAAO,CAA6B;IAC5C,OAAO,CAAC,QAAQ,CAAoC;gBAExC,OAAO,GAAE,gBAAqB;IAU1C;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,eAAe,CAAC;IAQtC;;OAEG;YACW,kBAAkB;IAehC;;OAEG;IACH,OAAO,CAAC,aAAa;IAuErB;;OAEG;IACH,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,wBAAwB,GAAG,MAAM,IAAI;IAkBnF;;OAEG;IACH,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,gBAAgB,CAAC,GAAG,IAAI;IAIvD;;OAEG;IACH,OAAO,IAAI,IAAI;CAMhB"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * 网速测试结果
3
+ */
4
+ export interface SpeedTestResult {
5
+ /** 下载速度 (Mbps) */
6
+ speedMbps: number;
7
+ /** 下载速度 (KB/s) */
8
+ speedKBps: number;
9
+ /** 网络类型评估 */
10
+ networkType: 'fast' | 'medium' | 'slow' | 'unknown';
11
+ /** 是否为内网 */
12
+ isIntranet: boolean;
13
+ /** 测试耗时 (ms) */
14
+ duration: number;
15
+ /** 传输大小 (bytes) */
16
+ transferSize: number;
17
+ /** 测试资源URL */
18
+ resourceUrl: string;
19
+ }
20
+ /**
21
+ * 资源测速信息
22
+ */
23
+ export interface ResourceSpeedInfo {
24
+ /** 资源名称 */
25
+ name: string;
26
+ /** 下载速度 (Mbps) */
27
+ speedMbps: number;
28
+ /** 下载速度 (KB/s) */
29
+ speedKBps: number;
30
+ /** 下载时间 (ms) */
31
+ downloadTime: number;
32
+ /** 传输大小 (bytes) */
33
+ transferSize: number;
34
+ }
35
+ /**
36
+ * SDK配置选项
37
+ */
38
+ export interface SpeedTestOptions {
39
+ /** 内网测速资源URL */
40
+ intranetUrl?: string;
41
+ /** 外网测速资源URL */
42
+ internetUrl?: string;
43
+ /** 超时时间 (ms) */
44
+ timeout?: number;
45
+ /** 是否自动检测内外网 */
46
+ autoDetect?: boolean;
47
+ /** 网速评估阈值 (Mbps) */
48
+ thresholds?: {
49
+ fast: number;
50
+ medium: number;
51
+ };
52
+ }
53
+ /**
54
+ * Performance Observer 回调参数
55
+ */
56
+ export interface PerformanceEntryCallback {
57
+ (entry: PerformanceResourceTiming): void;
58
+ }
59
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,kBAAkB;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,kBAAkB;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa;IACb,WAAW,EAAE,MAAM,GAAG,QAAQ,GAAG,MAAM,GAAG,SAAS,CAAC;IACpD,YAAY;IACZ,UAAU,EAAE,OAAO,CAAC;IACpB,gBAAgB;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,mBAAmB;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc;IACd,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,WAAW;IACX,IAAI,EAAE,MAAM,CAAC;IACb,kBAAkB;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,kBAAkB;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,mBAAmB;IACnB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,gBAAgB;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gBAAgB;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gBAAgB;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gBAAgB;IAChB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,oBAAoB;IACpB,UAAU,CAAC,EAAE;QACX,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,CAAC,KAAK,EAAE,yBAAyB,GAAG,IAAI,CAAC;CAC1C"}
@@ -0,0 +1,4 @@
1
+ export * from './core/sdk';
2
+ export type { SpeedTestResult, SpeedTestOptions, ResourceSpeedInfo, PerformanceEntryCallback, } from './core/types';
3
+ export { calcSpeedByResource, getAllResourcesSpeeds, evaluateNetworkType, } from './core/performance-utils';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,YAAY,CAAC;AAG3B,YAAY,EACV,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,wBAAwB,GACzB,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,mBAAmB,EACnB,qBAAqB,EACrB,mBAAmB,GACpB,MAAM,0BAA0B,CAAC"}
@@ -0,0 +1,175 @@
1
+ var m = Object.defineProperty;
2
+ var h = (t, e, r) => e in t ? m(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
3
+ var a = (t, e, r) => h(t, typeof e != "symbol" ? e + "" : e, r);
4
+ function d(t) {
5
+ const e = t.responseEnd - t.responseStart;
6
+ if (e <= 0 || t.transferSize === 0)
7
+ return null;
8
+ const r = t.transferSize * 8 / e / 1e3, n = t.transferSize / e;
9
+ return {
10
+ name: t.name,
11
+ speedMbps: Number(r.toFixed(2)),
12
+ speedKBps: Number(n.toFixed(2)),
13
+ downloadTime: Number(e.toFixed(2)),
14
+ transferSize: t.transferSize
15
+ };
16
+ }
17
+ function b() {
18
+ return performance.getEntriesByType("resource").filter(
19
+ (e) => e instanceof PerformanceResourceTiming && e.transferSize > 0
20
+ ).map(d).filter((e) => e !== null);
21
+ }
22
+ function S(t) {
23
+ performance.getEntriesByName(t).forEach(() => {
24
+ performance.clearResourceTimings();
25
+ });
26
+ }
27
+ function w(t, e = { fast: 10, medium: 2 }) {
28
+ return t >= e.fast ? "fast" : t >= e.medium ? "medium" : t > 0 ? "slow" : "unknown";
29
+ }
30
+ class y {
31
+ constructor(e = {}) {
32
+ a(this, "options");
33
+ a(this, "observer", null);
34
+ this.options = {
35
+ intranetUrl: e.intranetUrl || "",
36
+ internetUrl: e.internetUrl || "",
37
+ timeout: e.timeout || 1e4,
38
+ autoDetect: e.autoDetect ?? !0,
39
+ thresholds: e.thresholds || { fast: 10, medium: 2 }
40
+ };
41
+ }
42
+ /**
43
+ * 执行测速
44
+ */
45
+ async test() {
46
+ return this.options.autoDetect ? this.testWithAutoDetect() : this.testSingleUrl(this.options.internetUrl, !1);
47
+ }
48
+ /**
49
+ * 自动检测内外网并测速
50
+ */
51
+ async testWithAutoDetect() {
52
+ if (this.options.intranetUrl)
53
+ try {
54
+ return await this.testSingleUrl(this.options.intranetUrl, !0);
55
+ } catch {
56
+ console.log("内网测速失败,切换到外网测速");
57
+ }
58
+ return this.testSingleUrl(this.options.internetUrl, !1);
59
+ }
60
+ /**
61
+ * 测试单个URL
62
+ */
63
+ testSingleUrl(e, r) {
64
+ return new Promise((n, c) => {
65
+ const o = `${e}?t=${Date.now()}`;
66
+ S(o);
67
+ const u = new PerformanceObserver((s) => {
68
+ for (const l of s.getEntries())
69
+ if (l.entryType === "resource" && l.name.includes(e)) {
70
+ const i = d(l);
71
+ if (i) {
72
+ const p = {
73
+ speedMbps: i.speedMbps,
74
+ speedKBps: i.speedKBps,
75
+ networkType: w(
76
+ i.speedMbps,
77
+ this.options.thresholds
78
+ ),
79
+ isIntranet: r,
80
+ duration: i.downloadTime,
81
+ transferSize: i.transferSize,
82
+ resourceUrl: e
83
+ };
84
+ u.disconnect(), n(p);
85
+ }
86
+ }
87
+ });
88
+ u.observe({ entryTypes: ["resource"] });
89
+ const f = setTimeout(() => {
90
+ u.disconnect(), c(new Error(`测速超时: ${e}`));
91
+ }, this.options.timeout);
92
+ fetch(o, {
93
+ method: "GET",
94
+ cache: "no-store"
95
+ // 禁用缓存
96
+ }).then((s) => {
97
+ if (!s.ok)
98
+ throw new Error(`HTTP error! status: ${s.status}`);
99
+ return s.blob();
100
+ }).then(() => {
101
+ clearTimeout(f);
102
+ }).catch((s) => {
103
+ clearTimeout(f), u.disconnect(), c(new Error(`资源加载失败: ${s.message}`));
104
+ });
105
+ });
106
+ }
107
+ /**
108
+ * 监听特定资源的性能数据
109
+ */
110
+ observeResource(e, r) {
111
+ const n = new PerformanceObserver((c) => {
112
+ for (const o of c.getEntries())
113
+ o.entryType === "resource" && o.name.includes(e) && r(o);
114
+ });
115
+ return n.observe({ entryTypes: ["resource"] }), () => n.disconnect();
116
+ }
117
+ /**
118
+ * 更新配置
119
+ */
120
+ updateOptions(e) {
121
+ this.options = { ...this.options, ...e };
122
+ }
123
+ /**
124
+ * 销毁实例
125
+ */
126
+ destroy() {
127
+ this.observer && (this.observer.disconnect(), this.observer = null);
128
+ }
129
+ }
130
+ class T {
131
+ constructor(e = {}) {
132
+ a(this, "tester");
133
+ this.tester = new y(e);
134
+ }
135
+ /**
136
+ * 执行网速测试
137
+ */
138
+ async test() {
139
+ return this.tester.test();
140
+ }
141
+ /**
142
+ * 获取所有已加载资源的速度信息
143
+ */
144
+ getAllResourcesSpeeds() {
145
+ return b();
146
+ }
147
+ /**
148
+ * 监听特定资源的性能数据
149
+ */
150
+ observeResource(e, r) {
151
+ return this.tester.observeResource(e, r);
152
+ }
153
+ /**
154
+ * 更新配置
155
+ */
156
+ updateOptions(e) {
157
+ this.tester.updateOptions(e);
158
+ }
159
+ /**
160
+ * 销毁SDK实例
161
+ */
162
+ destroy() {
163
+ this.tester.destroy();
164
+ }
165
+ }
166
+ function U(t) {
167
+ return new T(t);
168
+ }
169
+ export {
170
+ T as NetworkSpeedSDK,
171
+ d as calcSpeedByResource,
172
+ U as createNetworkSpeedSDK,
173
+ w as evaluateNetworkType,
174
+ b as getAllResourcesSpeeds
175
+ };
@@ -0,0 +1 @@
1
+ (function(r,s){typeof exports=="object"&&typeof module<"u"?s(exports):typeof define=="function"&&define.amd?define(["exports"],s):(r=typeof globalThis<"u"?globalThis:r||self,s(r.NetworkSpeedJS={}))})(this,function(r){"use strict";var g=Object.defineProperty;var v=(r,s,n)=>s in r?g(r,s,{enumerable:!0,configurable:!0,writable:!0,value:n}):r[s]=n;var f=(r,s,n)=>v(r,typeof s!="symbol"?s+"":s,n);function s(t){const e=t.responseEnd-t.responseStart;if(e<=0||t.transferSize===0)return null;const o=t.transferSize*8/e/1e3,c=t.transferSize/e;return{name:t.name,speedMbps:Number(o.toFixed(2)),speedKBps:Number(c.toFixed(2)),downloadTime:Number(e.toFixed(2)),transferSize:t.transferSize}}function n(){return performance.getEntriesByType("resource").filter(e=>e instanceof PerformanceResourceTiming&&e.transferSize>0).map(s).filter(e=>e!==null)}function y(t){performance.getEntriesByName(t).forEach(()=>{performance.clearResourceTimings()})}function m(t,e={fast:10,medium:2}){return t>=e.fast?"fast":t>=e.medium?"medium":t>0?"slow":"unknown"}class b{constructor(e={}){f(this,"options");f(this,"observer",null);this.options={intranetUrl:e.intranetUrl||"",internetUrl:e.internetUrl||"",timeout:e.timeout||1e4,autoDetect:e.autoDetect??!0,thresholds:e.thresholds||{fast:10,medium:2}}}async test(){return this.options.autoDetect?this.testWithAutoDetect():this.testSingleUrl(this.options.internetUrl,!1)}async testWithAutoDetect(){if(this.options.intranetUrl)try{return await this.testSingleUrl(this.options.intranetUrl,!0)}catch{console.log("内网测速失败,切换到外网测速")}return this.testSingleUrl(this.options.internetUrl,!1)}testSingleUrl(e,o){return new Promise((c,l)=>{const u=`${e}?t=${Date.now()}`;y(u);const d=new PerformanceObserver(i=>{for(const p of i.getEntries())if(p.entryType==="resource"&&p.name.includes(e)){const a=s(p);if(a){const T={speedMbps:a.speedMbps,speedKBps:a.speedKBps,networkType:m(a.speedMbps,this.options.thresholds),isIntranet:o,duration:a.downloadTime,transferSize:a.transferSize,resourceUrl:e};d.disconnect(),c(T)}}});d.observe({entryTypes:["resource"]});const S=setTimeout(()=>{d.disconnect(),l(new Error(`测速超时: ${e}`))},this.options.timeout);fetch(u,{method:"GET",cache:"no-store"}).then(i=>{if(!i.ok)throw new Error(`HTTP error! status: ${i.status}`);return i.blob()}).then(()=>{clearTimeout(S)}).catch(i=>{clearTimeout(S),d.disconnect(),l(new Error(`资源加载失败: ${i.message}`))})})}observeResource(e,o){const c=new PerformanceObserver(l=>{for(const u of l.getEntries())u.entryType==="resource"&&u.name.includes(e)&&o(u)});return c.observe({entryTypes:["resource"]}),()=>c.disconnect()}updateOptions(e){this.options={...this.options,...e}}destroy(){this.observer&&(this.observer.disconnect(),this.observer=null)}}class h{constructor(e={}){f(this,"tester");this.tester=new b(e)}async test(){return this.tester.test()}getAllResourcesSpeeds(){return n()}observeResource(e,o){return this.tester.observeResource(e,o)}updateOptions(e){this.tester.updateOptions(e)}destroy(){this.tester.destroy()}}function w(t){return new h(t)}r.NetworkSpeedSDK=h,r.calcSpeedByResource=s,r.createNetworkSpeedSDK=w,r.evaluateNetworkType=m,r.getAllResourcesSpeeds=n,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,24 +1,67 @@
1
1
  {
2
2
  "name": "network-speed-js",
3
3
  "private": false,
4
- "description": "A small tool for testing network speed. It also has the ability to test internal and external networks.",
5
- "version": "0.0.2",
4
+ "description": "A framework-agnostic network speed testing SDK based on Performance API with intranet/internet auto-detection support",
5
+ "version": "1.0.1",
6
+ "author": "Sunny-117",
7
+ "license": "MIT",
8
+ "keywords": [
9
+ "network",
10
+ "speed",
11
+ "test",
12
+ "performance",
13
+ "bandwidth",
14
+ "sdk",
15
+ "typescript",
16
+ "framework-agnostic",
17
+ "vue",
18
+ "react",
19
+ "angular"
20
+ ],
21
+ "main": "dist/network-speed-js.umd.js",
6
22
  "module": "dist/network-speed-js.js",
23
+ "types": "dist/index.d.ts",
7
24
  "type": "module",
25
+ "files": [
26
+ "dist",
27
+ "README.md"
28
+ ],
29
+ "exports": {
30
+ ".": {
31
+ "import": "./dist/network-speed-js.js",
32
+ "require": "./dist/network-speed-js.umd.js",
33
+ "types": "./dist/index.d.ts"
34
+ }
35
+ },
8
36
  "scripts": {
9
37
  "dev": "vite",
10
- "build": "vue-tsc && vite build",
11
- "preview": "vite preview"
38
+ "build": "npm run build:lib && npm run build:types",
39
+ "build:lib": "vite build --mode lib",
40
+ "build:types": "tsc --project tsconfig.build.json",
41
+ "build:demo": "vite build",
42
+ "preview": "vite preview",
43
+ "deploy": "sh deploy.sh",
44
+ "prepublishOnly": "npm run build"
45
+ },
46
+ "peerDependencies": {
47
+ "vue": "^3.3.11"
12
48
  },
13
49
  "dependencies": {
14
- "axios": "^1.6.2",
15
- "element-plus": "^2.4.4",
16
50
  "vue": "^3.3.11"
17
51
  },
18
52
  "devDependencies": {
53
+ "@types/node": "^25.0.10",
19
54
  "@vitejs/plugin-vue": "^4.5.2",
20
55
  "typescript": "^5.2.2",
21
56
  "vite": "^5.0.8",
22
57
  "vue-tsc": "^1.8.25"
23
- }
58
+ },
59
+ "repository": {
60
+ "type": "git",
61
+ "url": "https://github.com/Sunny-117/network-speed-js.git"
62
+ },
63
+ "bugs": {
64
+ "url": "https://github.com/Sunny-117/network-speed-js/issues"
65
+ },
66
+ "homepage": "https://github.com/Sunny-117/network-speed-js#readme"
24
67
  }
package/.eslintrc.js DELETED
@@ -1,3 +0,0 @@
1
- module.exports = {
2
- "no-unused-vars": ["error", { varsIgnorePattern: ".*", args: "none" }],
3
- };
@@ -1,3 +0,0 @@
1
- {
2
- "recommendations": ["Vue.volar", "Vue.vscode-typescript-vue-plugin"]
3
- }
package/index.html DELETED
@@ -1,13 +0,0 @@
1
- <!doctype html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8" />
5
- <link rel="icon" type="image/svg+xml" href="/vite.svg" />
6
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
- <title>Vite + Vue + TS</title>
8
- </head>
9
- <body>
10
- <div id="app"></div>
11
- <script type="module" src="/src/main.ts"></script>
12
- </body>
13
- </html>
@@ -1,3 +0,0 @@
1
- {
2
- "recommendations": ["Vue.volar", "Vue.vscode-typescript-vue-plugin"]
3
- }
@@ -1,18 +0,0 @@
1
- # Vue 3 + TypeScript + Vite
2
-
3
- This template should help get you started developing with Vue 3 and TypeScript in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
4
-
5
- ## Recommended IDE Setup
6
-
7
- - [VS Code](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur) + [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin).
8
-
9
- ## Type Support For `.vue` Imports in TS
10
-
11
- TypeScript cannot handle type information for `.vue` imports by default, so we replace the `tsc` CLI with `vue-tsc` for type checking. In editors, we need [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin) to make the TypeScript language service aware of `.vue` types.
12
-
13
- If the standalone TypeScript plugin doesn't feel fast enough to you, Volar has also implemented a [Take Over Mode](https://github.com/johnsoncodehk/volar/discussions/471#discussioncomment-1361669) that is more performant. You can enable it by the following steps:
14
-
15
- 1. Disable the built-in TypeScript Extension
16
- 1. Run `Extensions: Show Built-in Extensions` from VSCode's command palette
17
- 2. Find `TypeScript and JavaScript Language Features`, right click and select `Disable (Workspace)`
18
- 2. Reload the VSCode window by running `Developer: Reload Window` from the command palette.
@@ -1,13 +0,0 @@
1
- <!doctype html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8" />
5
- <link rel="icon" type="image/svg+xml" href="/vite.svg" />
6
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
- <title>Vite + Vue + TS</title>
8
- </head>
9
- <body>
10
- <div id="app"></div>
11
- <script type="module" src="/src/main.ts"></script>
12
- </body>
13
- </html>
@@ -1,21 +0,0 @@
1
- {
2
- "name": "playground",
3
- "private": true,
4
- "version": "0.0.0",
5
- "type": "module",
6
- "scripts": {
7
- "dev": "vite",
8
- "build": "vue-tsc && vite build",
9
- "preview": "vite preview"
10
- },
11
- "dependencies": {
12
- "network-speed-js": "^0.0.1",
13
- "vue": "^3.3.11"
14
- },
15
- "devDependencies": {
16
- "@vitejs/plugin-vue": "^4.5.2",
17
- "typescript": "^5.2.2",
18
- "vite": "^5.0.8",
19
- "vue-tsc": "^1.8.25"
20
- }
21
- }
@@ -1,7 +0,0 @@
1
- lockfileVersion: 5.3
2
-
3
- specifiers:
4
- network-speed-js: ^0.0.1
5
-
6
- dependencies:
7
- network-speed-js: link:../../../../../.nvm/versions/node/v16.14.2/pnpm-global/5/node_modules/network-speed-js