Skip to content
This repository was archived by the owner on Sep 11, 2025. It is now read-only.

Commit 14cd76b

Browse files
committed
v3.4.9
1 parent 14845e5 commit 14cd76b

File tree

10 files changed

+118
-26
lines changed

10 files changed

+118
-26
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,16 @@ $ npm i @litert/loader@dev --save
4444

4545
### CDN (recommend)
4646

47-
Recommended: https://cdn.jsdelivr.net/npm/@litert/[email protected].8/dist/loader.min.js, you can also find it here https://cdn.jsdelivr.net/npm/@litert/loader/.
47+
Recommended: https://cdn.jsdelivr.net/npm/@litert/[email protected].9/dist/loader.min.js, you can also find it here https://cdn.jsdelivr.net/npm/@litert/loader/.
4848

49-
Also available on [unpkg](https://unpkg.com/@litert/[email protected].8/dist/loader.min.js).
49+
Also available on [unpkg](https://unpkg.com/@litert/[email protected].9/dist/loader.min.js).
5050

5151
## Usage
5252

5353
Here's a general how to use it:
5454

5555
```html
56-
<script src="https://cdn.jsdelivr.net/npm/@litert/[email protected].8/dist/loader.min.js"></script>
56+
<script src="https://cdn.jsdelivr.net/npm/@litert/[email protected].9/dist/loader.min.js"></script>
5757
```
5858

5959
The code hint needs to be added in "tsconfig.json":
@@ -83,25 +83,25 @@ loader.ready(function() {
8383
Alternatively, use ?path= to load the ingress file directly, the js file extension can be omitted.
8484

8585
```html
86-
<script src="https://cdn.jsdelivr.net/npm/@litert/[email protected].8/dist/index.min.js?path=../lib/test"></script>
86+
<script src="https://cdn.jsdelivr.net/npm/@litert/[email protected].9/dist/index.min.js?path=../lib/test"></script>
8787
```
8888

8989
Use the ?cdn= parameter to set the source address of the third library load, default is: https://cdn.jsdelivr.net.
9090

9191
```html
92-
<script src="https://cdn.jsdelivr.net/npm/@litert/[email protected].8/dist/index.min.js?cdn=https://cdn.xxx.xxx"></script>
92+
<script src="https://cdn.jsdelivr.net/npm/@litert/[email protected].9/dist/index.min.js?cdn=https://cdn.xxx.xxx"></script>
9393
```
9494

9595
Use the ?map= parameter to set the path to the third-party library, a JSON string, that is valid only with the path parameter.
9696

9797
```html
98-
<script src="https://cdn.jsdelivr.net/npm/@litert/[email protected].8/dist/index.min.js?&path=xxx&map={'xxx':'https://xx/npm/index'}"></script>
98+
<script src="https://cdn.jsdelivr.net/npm/@litert/[email protected].9/dist/index.min.js?&path=xxx&map={'xxx':'https://xx/npm/index'}"></script>
9999
```
100100

101101
Using the ?npm= parameter loader will automatically go to npm to find the relevant library for sniffing loading, JSON string, module name and version number, only valid with the path parameter.
102102

103103
```html
104-
<script src="https://cdn.jsdelivr.net/npm/@litert/[email protected].8/dist/index.min.js?&path=xxx&npm={'xxx':'1.0.0'}"></script>
104+
<script src="https://cdn.jsdelivr.net/npm/@litert/[email protected].9/dist/index.min.js?&path=xxx&npm={'xxx':'1.0.0'}"></script>
105105
```
106106

107107
You can use the fetchFiles method to load network files into memory.

dist/index.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ interface ILoader {
4040
* @param init 配置项
4141
*/
4242
fetch(url: string, init?: RequestInit): Promise<string | Blob | null>;
43+
/**
44+
* --- 简单 post 数据,提交 json 或 formdata 数据,无需手动设置 content-type ---
45+
* @param url 网址
46+
* @param data 数据对象
47+
* @param opt 选项
48+
*/
49+
post(url: string, data: Record<string, any> | FormData, opt?: {
50+
'credentials'?: 'include' | 'same-origin' | 'omit';
51+
'headers'?: HeadersInit;
52+
}): Promise<Response | null>;
4353
/**
4454
* --- 获取文件序列 ---
4555
* @param urls 网址列表,已加载的文件不会被再次返回

dist/loader.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ return module.exports;`;
416416
if ((_a = res.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.toLowerCase().includes('image/')) {
417417
return res.blob();
418418
}
419-
const typeList = ['text/', 'javascript', 'json', 'plain', 'css', 'xml', 'html'];
419+
const typeList = ['text/', 'javascript', 'json', 'css', 'xml', 'html'];
420420
for (const item of typeList) {
421421
if ((_b = res.headers.get('content-type')) === null || _b === void 0 ? void 0 : _b.toLowerCase().includes(item)) {
422422
return res.text();
@@ -435,6 +435,30 @@ return module.exports;`;
435435
});
436436
});
437437
},
438+
post: function (url, data, opt = {}) {
439+
var _a;
440+
return __awaiter(this, void 0, void 0, function* () {
441+
try {
442+
const headers = {};
443+
if (!(data instanceof FormData)) {
444+
headers['content-type'] = 'application/json';
445+
}
446+
if (opt.headers) {
447+
Object.assign(headers, opt.headers);
448+
}
449+
const res = yield fetch(url, {
450+
'method': 'POST',
451+
'headers': headers,
452+
'body': data instanceof FormData ? data : JSON.stringify(data),
453+
'credentials': (_a = opt.credentials) !== null && _a !== void 0 ? _a : 'include'
454+
});
455+
return res;
456+
}
457+
catch (_b) {
458+
return null;
459+
}
460+
});
461+
},
438462
fetchFiles: function (urls, opt = {}) {
439463
return __awaiter(this, void 0, void 0, function* () {
440464
return new Promise((resolve) => {

dist/loader.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ return module.exports;`;
528528
if (res.headers.get('content-type')?.toLowerCase().includes('image/')) {
529529
return res.blob();
530530
}
531-
const typeList = ['text/', 'javascript', 'json', 'plain', 'css', 'xml', 'html'];
531+
const typeList = ['text/', 'javascript', 'json', 'css', 'xml', 'html'];
532532
for (const item of typeList) {
533533
if (res.headers.get('content-type')?.toLowerCase().includes(item)) {
534534
return res.text();
@@ -548,6 +548,31 @@ return module.exports;`;
548548
});
549549
},
550550

551+
post: async function(url: string, data: Record<string, any> | FormData, opt: {
552+
'credentials'?: 'include' | 'same-origin' | 'omit';
553+
'headers'?: HeadersInit;
554+
} = {}): Promise<Response | null> {
555+
try {
556+
const headers: HeadersInit = {};
557+
if (!(data instanceof FormData)) {
558+
headers['content-type'] = 'application/json';
559+
}
560+
if (opt.headers) {
561+
Object.assign(headers, opt.headers);
562+
}
563+
const res = await fetch(url, {
564+
'method': 'POST',
565+
'headers': headers,
566+
'body': data instanceof FormData ? data : JSON.stringify(data),
567+
'credentials': opt.credentials ?? 'include'
568+
});
569+
return res;
570+
}
571+
catch {
572+
return null;
573+
}
574+
},
575+
551576
fetchFiles: async function(urls: string[], opt: {
552577
'init'?: RequestInit;
553578
'load'?: (url: string) => void;

dist/test-on-browser.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
99
});
1010
};
1111
loader.ready(function () {
12-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
12+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0;
1313
return __awaiter(this, void 0, void 0, function* () {
1414
const keyInput = document.getElementById('key');
1515
const consoleDiv = document.getElementById('console');
@@ -528,5 +528,18 @@ loader.ready(function () {
528528
(_z = document.getElementById('urlResolve')) === null || _z === void 0 ? void 0 : _z.addEventListener('click', function () {
529529
document.getElementById('urlResolve3').innerText = loader.urlResolve(urlResolve1.value, urlResolve2.value);
530530
});
531+
(_0 = document.getElementById('testPost')) === null || _0 === void 0 ? void 0 : _0.addEventListener('click', function () {
532+
(function () {
533+
return __awaiter(this, void 0, void 0, function* () {
534+
console.log('Post start...');
535+
mask.style.display = 'flex';
536+
const r = yield loader.post('./index2.html', {
537+
'param': 'test1'
538+
});
539+
mask.style.display = 'none';
540+
console.log('Post done: ' + typeof r);
541+
});
542+
})();
543+
});
531544
});
532545
});

dist/test-on-browser.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,4 +519,18 @@ loader.ready(async function(): Promise<void> {
519519
document.getElementById('urlResolve')?.addEventListener('click', function() {
520520
document.getElementById('urlResolve3')!.innerText = loader.urlResolve(urlResolve1.value, urlResolve2.value);
521521
});
522+
523+
// --- testPost ---
524+
525+
document.getElementById('testPost')?.addEventListener('click', function() {
526+
(async function() {
527+
console.log('Post start...');
528+
mask.style.display = 'flex';
529+
const r = await loader.post('./index2.html', {
530+
'param': 'test1'
531+
});
532+
mask.style.display = 'none';
533+
console.log('Post done: ' + typeof r);
534+
})() as unknown;
535+
});
522536
});

doc/README.sc.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ $ npm i @litert/loader@dev --save
4343

4444
### CDN(推荐)
4545

46-
推荐引用地址:https://cdn.jsdelivr.net/npm/@litert/[email protected].8/dist/index.min.js,也可以此处查找:https://cdn.jsdelivr.net/npm/@litert/loader/。
46+
推荐引用地址:https://cdn.jsdelivr.net/npm/@litert/[email protected].9/dist/index.min.js,也可以此处查找:https://cdn.jsdelivr.net/npm/@litert/loader/。
4747

48-
同样可使用 [unpkg](https://unpkg.com/@litert/[email protected].8/dist/index.min.js)
48+
同样可使用 [unpkg](https://unpkg.com/@litert/[email protected].9/dist/index.min.js)
4949

5050
## Usage
5151

5252
通常的使用方式:
5353

5454
```html
55-
<script src="https://cdn.jsdelivr.net/npm/@litert/[email protected].8/dist/index.min.js"></script>
55+
<script src="https://cdn.jsdelivr.net/npm/@litert/[email protected].9/dist/index.min.js"></script>
5656
```
5757

5858
代码提示需要在“tsconfig.json”中添加:
@@ -82,25 +82,25 @@ loader.ready(function() {
8282
或者使用 ?path= 直接加载入口 js 文件,js 后缀可省略。
8383

8484
```html
85-
<script src="https://cdn.jsdelivr.net/npm/@litert/[email protected].8/dist/index.min.js?path=../lib/test"></script>
85+
<script src="https://cdn.jsdelivr.net/npm/@litert/[email protected].9/dist/index.min.js?path=../lib/test"></script>
8686
```
8787

8888
使用 ?cdn= 参数设置第三库加载的源地址,默认为:https://cdn.jsdelivr.net。
8989

9090
```html
91-
<script src="https://cdn.jsdelivr.net/npm/@litert/[email protected].8/dist/index.min.js?cdn=https://cdn.xxx.xxx"></script>
91+
<script src="https://cdn.jsdelivr.net/npm/@litert/[email protected].9/dist/index.min.js?cdn=https://cdn.xxx.xxx"></script>
9292
```
9393

9494
使用 ?map= 参数设置第三方库的路径,JSON 字符串,仅在含有 path 参数下有效。
9595

9696
```html
97-
<script src="https://cdn.jsdelivr.net/npm/@litert/[email protected].8/dist/index.min.js?&path=xxx&map={'xxx':'https://xx/npm/index'}"></script>
97+
<script src="https://cdn.jsdelivr.net/npm/@litert/[email protected].9/dist/index.min.js?&path=xxx&map={'xxx':'https://xx/npm/index'}"></script>
9898
```
9999

100100
使用 ?npm= 参数 loader 将自动去 npm 查找相关的库进行嗅探加载,JSON 字符串,模块名跟版本号,仅在含有 path 参数下有效。
101101

102102
```html
103-
<script src="https://cdn.jsdelivr.net/npm/@litert/[email protected].8/dist/index.min.js?&path=xxx&npm={'xxx':'1.0.0'}"></script>
103+
<script src="https://cdn.jsdelivr.net/npm/@litert/[email protected].9/dist/index.min.js?&path=xxx&npm={'xxx':'1.0.0'}"></script>
104104
```
105105

106106
你可以使用 fetchFiles 方法加载网络文件到内存。

doc/README.tc.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ $ npm i @litert/loader@dev --save
4343

4444
### CDN(推薦)
4545

46-
推薦引用位址:https://cdn.jsdelivr.net/npm/@litert/[email protected].8/dist/index.min.js,也可以此處查找:https://cdn.jsdelivr.net/npm/@litert/loader/。
46+
推薦引用位址:https://cdn.jsdelivr.net/npm/@litert/[email protected].9/dist/index.min.js,也可以此處查找:https://cdn.jsdelivr.net/npm/@litert/loader/。
4747

48-
同樣可使用 [unpkg](https://unpkg.com/@litert/[email protected].8/dist/index.min.js)
48+
同樣可使用 [unpkg](https://unpkg.com/@litert/[email protected].9/dist/index.min.js)
4949

5050
## Usage
5151

5252
通常的使用方式:
5353

5454
```html
55-
<script src="https://cdn.jsdelivr.net/npm/@litert/[email protected].8/dist/index.min.js"></script>
55+
<script src="https://cdn.jsdelivr.net/npm/@litert/[email protected].9/dist/index.min.js"></script>
5656
```
5757

5858
代碼提示需要在「tsconfig.json」中添加:
@@ -82,25 +82,25 @@ loader.ready(function() {
8282
或者使用 ?path= 直接載入入口 js 檔,js 後綴可省略。
8383

8484
```html
85-
<script src="https://cdn.jsdelivr.net/npm/@litert/[email protected].8/dist/index.min.js?path=../lib/test"></script>
85+
<script src="https://cdn.jsdelivr.net/npm/@litert/[email protected].9/dist/index.min.js?path=../lib/test"></script>
8686
```
8787

8888
使用 ?cdn= 參數設置三方庫載入的源地址,預設為:https://cdn.jsdelivr.net。
8989

9090
```html
91-
<script src="https://cdn.jsdelivr.net/npm/@litert/[email protected].8/dist/index.min.js?cdn=https://cdn.xxx.xxx"></script>
91+
<script src="https://cdn.jsdelivr.net/npm/@litert/[email protected].9/dist/index.min.js?cdn=https://cdn.xxx.xxx"></script>
9292
```
9393

9494
使用 ?map= 參數設置第三方庫的路徑,JSON 字串,僅在含有 path 參數下有效。
9595

9696
```html
97-
<script src="https://cdn.jsdelivr.net/npm/@litert/[email protected].8/dist/index.min.js?&path=xxx&map={'xxx':'https://xx/npm/index'}"></script>
97+
<script src="https://cdn.jsdelivr.net/npm/@litert/[email protected].9/dist/index.min.js?&path=xxx&map={'xxx':'https://xx/npm/index'}"></script>
9898
```
9999

100100
使用 ?npm= 參數 loader 將自動去 npm 查找相關的庫進行嗅探載入,JSON 字串,模組名跟版本號,僅在含有 path 參數下有效。
101101

102102
```html
103-
<script src="https://cdn.jsdelivr.net/npm/@litert/[email protected].8/dist/index.min.js?&path=xxx&npm={'xxx':'1.0.0'}"></script>
103+
<script src="https://cdn.jsdelivr.net/npm/@litert/[email protected].9/dist/index.min.js?&path=xxx&npm={'xxx':'1.0.0'}"></script>
104104
```
105105

106106
你可以使用 fetchFiles 方法載入網路檔到記憶體。

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@litert/loader",
3-
"version": "3.4.8",
3+
"version": "3.4.9",
44
"description": "Simple browser module loader.",
55
"keywords": [
66
"litert",

test/index.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html>
33
<head>
44
<title>@litert/loader.js test</title>
5-
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
5+
<meta http-equiv="content-type" content="text/html;charset=UTF-8">
66
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no">
77
<script src="../dist/loader.js?path=../dist/tauto"></script>
88
<script src="../dist/test-on-browser.js"></script>
@@ -130,6 +130,12 @@
130130
<input id="urlResolve2" value="../ok/./index.js" style="flex: 1; margin-left: 10px;">
131131
</div>
132132
<div id="urlResolve3" style="display: flex; margin-top: 10px;">Waiting...</div>
133+
<hr>
134+
135+
<div style="display: flex; align-items: center;">
136+
<div>Test post:</div>
137+
<input id="testPost" value="testPost" type="button" style="margin-left: 10px;">
138+
</div>
133139

134140
<div style="height: 360px;"></div>
135141

0 commit comments

Comments
 (0)