ddan-js 2.9.3 → 2.9.4

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.
@@ -34,20 +34,58 @@ const parsePath = (url) => {
34
34
  const route = _url.substring(0, idx) || '';
35
35
  return { route, page, name, withoutExtension, extname };
36
36
  };
37
+ // const join = (...args: string[]) => {
38
+ // let arr: string[] = []
39
+ // args.forEach((e) => {
40
+ // const _s = e.trim().replace(/^\/*(.*?)\/*$/, '$1')
41
+ // if (_s.length <= 0) return
42
+ // if (/^(\w+):\/\//.test(_s)) {
43
+ // arr = [_s]
44
+ // } else {
45
+ // arr.push(_s)
46
+ // }
47
+ // })
48
+ // return arr.join('/')
49
+ // }
37
50
  const join = (...args) => {
38
- let arr = [];
39
- args.forEach((e) => {
40
- const _s = e.trim().replace(/^\/*(.*?)\/*$/, '$1');
41
- if (_s.length <= 0)
51
+ const result = [];
52
+ let hasProtocol = false;
53
+ args.forEach((part) => {
54
+ const trimmed = part.trim();
55
+ if (trimmed === '') {
56
+ // 忽略空段
42
57
  return;
43
- if (/^(\w+):\/\//.test(_s)) {
44
- arr = [_s];
45
58
  }
46
- else {
47
- arr.push(_s);
59
+ if (/^(\w+):\/\//.test(trimmed)) {
60
+ // 处理带协议的路径,重置所有内容
61
+ result.length = 0;
62
+ result.push(trimmed);
63
+ hasProtocol = true;
64
+ return;
48
65
  }
66
+ const segments = trimmed.split('/');
67
+ segments.forEach((segment) => {
68
+ if (segment === '.' || segment === '') {
69
+ // 忽略当前目录标志或多余的斜杠
70
+ return;
71
+ }
72
+ if (segment === '..') {
73
+ // 返回上一级目录
74
+ if (result.length > 0 && result[result.length - 1] !== '..') {
75
+ result.pop();
76
+ }
77
+ else if (!hasProtocol) {
78
+ // 非协议情况下,保留多余的 ".."
79
+ result.push('..');
80
+ }
81
+ }
82
+ else {
83
+ // 普通路径段,直接加入
84
+ result.push(segment);
85
+ }
86
+ });
49
87
  });
50
- return arr.join('/');
88
+ return result.join('/');
51
89
  };
52
90
  const parseHost = (url) => {
53
91
  const result = {
@@ -562,7 +562,7 @@ declare const dWeb: {
562
562
  fail?: ((error: Error) => void) | undefined;
563
563
  }) => Promise<Uint8Array | undefined>;
564
564
  getText: (url: string, cache?: RequestCache | undefined) => Promise<[any, undefined] | [null, string]>;
565
- cache: (url: string, cache?: RequestCache | undefined) => Promise<[any, undefined] | [null, boolean]>;
565
+ cache: (url: string, cache?: RequestCache) => Promise<[any, undefined] | [null, boolean]>;
566
566
  };
567
567
  Http: typeof Http;
568
568
  css: {
@@ -1077,7 +1077,7 @@ declare const _default: {
1077
1077
  fail?: ((error: Error) => void) | undefined;
1078
1078
  }) => Promise<Uint8Array | undefined>;
1079
1079
  getText: (url: string, cache?: RequestCache | undefined) => Promise<[any, undefined] | [null, string]>;
1080
- cache: (url: string, cache?: RequestCache | undefined) => Promise<[any, undefined] | [null, boolean]>;
1080
+ cache: (url: string, cache?: RequestCache) => Promise<[any, undefined] | [null, boolean]>;
1081
1081
  };
1082
1082
  rsa: {
1083
1083
  generateKeys: () => Promise<{
@@ -562,7 +562,7 @@ declare const dWeb: {
562
562
  fail?: ((error: Error) => void) | undefined;
563
563
  }) => Promise<Uint8Array | undefined>;
564
564
  getText: (url: string, cache?: RequestCache | undefined) => Promise<[any, undefined] | [null, string]>;
565
- cache: (url: string, cache?: RequestCache | undefined) => Promise<[any, undefined] | [null, boolean]>;
565
+ cache: (url: string, cache?: RequestCache) => Promise<[any, undefined] | [null, boolean]>;
566
566
  };
567
567
  Http: typeof Http;
568
568
  css: {
@@ -1113,7 +1113,7 @@ declare const _default: {
1113
1113
  fail?: ((error: Error) => void) | undefined;
1114
1114
  }) => Promise<Uint8Array | undefined>;
1115
1115
  getText: (url: string, cache?: RequestCache | undefined) => Promise<[any, undefined] | [null, string]>;
1116
- cache: (url: string, cache?: RequestCache | undefined) => Promise<[any, undefined] | [null, boolean]>;
1116
+ cache: (url: string, cache?: RequestCache) => Promise<[any, undefined] | [null, boolean]>;
1117
1117
  };
1118
1118
  rsa: {
1119
1119
  generateKeys: () => Promise<{
@@ -11,6 +11,6 @@ declare const _default: {
11
11
  fail?: ((error: Error) => void) | undefined;
12
12
  }) => Promise<Uint8Array | undefined>;
13
13
  getText: (url: string, cache?: RequestCache | undefined) => Promise<[any, undefined] | [null, string]>;
14
- cache: (url: string, cache?: RequestCache | undefined) => Promise<[any, undefined] | [null, boolean]>;
14
+ cache: (url: string, cache?: RequestCache) => Promise<[any, undefined] | [null, boolean]>;
15
15
  };
16
16
  export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ddan-js",
3
- "version": "2.9.3",
3
+ "version": "2.9.4",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "ddan-js",