@base-web-kits/base-tools-ts 1.4.8 → 1.4.9
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.
- package/dist/base-tools-ts.umd.global.js +14 -0
- package/dist/base-tools-ts.umd.global.js.map +1 -1
- package/dist/index.cjs +15 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +14 -0
- package/dist/index.mjs.map +1 -1
- package/dist/url/index.d.ts +1 -0
- package/dist/url/index.d.ts.map +1 -1
- package/dist/url/path/index.d.ts +17 -0
- package/dist/url/path/index.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/ts/url/index.ts +4 -3
- package/src/ts/url/path/index.ts +29 -0
package/dist/url/index.d.ts
CHANGED
package/dist/url/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ts/url/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC;AACxB,cAAc,MAAM,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ts/url/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,MAAM,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 拼接 URL 路径,并清理各部分交界处多余的斜杠。
|
|
3
|
+
*
|
|
4
|
+
* 空字符串、`null` 和 `undefined` 会被忽略;协议中的 `://` 以及第一个有效参数
|
|
5
|
+
* 开头的 `/` 会被保留。该函数仅用于拼接路径,不负责解析查询参数或哈希片段。
|
|
6
|
+
*
|
|
7
|
+
* @param parts URL 或路径片段
|
|
8
|
+
* @returns 拼接后的 URL 路径;没有有效片段时返回空字符串
|
|
9
|
+
* @example
|
|
10
|
+
* joinUrlPath('https://a.com/', '/images/', '/avatar.png');
|
|
11
|
+
* // 'https://a.com/images/avatar.png'
|
|
12
|
+
*
|
|
13
|
+
* joinUrlPath('', '/images/', null, 'avatar.png');
|
|
14
|
+
* // '/images/avatar.png'
|
|
15
|
+
*/
|
|
16
|
+
export declare function joinUrlPath(...parts: Array<string | null | undefined>): string;
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ts/url/path/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,WAAW,CAAC,GAAG,KAAK,EAAE,KAAK,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,UAarE"}
|
package/package.json
CHANGED
package/src/ts/url/index.ts
CHANGED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 拼接 URL 路径,并清理各部分交界处多余的斜杠。
|
|
3
|
+
*
|
|
4
|
+
* 空字符串、`null` 和 `undefined` 会被忽略;协议中的 `://` 以及第一个有效参数
|
|
5
|
+
* 开头的 `/` 会被保留。该函数仅用于拼接路径,不负责解析查询参数或哈希片段。
|
|
6
|
+
*
|
|
7
|
+
* @param parts URL 或路径片段
|
|
8
|
+
* @returns 拼接后的 URL 路径;没有有效片段时返回空字符串
|
|
9
|
+
* @example
|
|
10
|
+
* joinUrlPath('https://a.com/', '/images/', '/avatar.png');
|
|
11
|
+
* // 'https://a.com/images/avatar.png'
|
|
12
|
+
*
|
|
13
|
+
* joinUrlPath('', '/images/', null, 'avatar.png');
|
|
14
|
+
* // '/images/avatar.png'
|
|
15
|
+
*/
|
|
16
|
+
export function joinUrlPath(...parts: Array<string | null | undefined>) {
|
|
17
|
+
const values = parts.filter((part): part is string => !!part);
|
|
18
|
+
if (!values.length) return '';
|
|
19
|
+
|
|
20
|
+
const [first, ...rest] = values;
|
|
21
|
+
const normalizedFirst = first.replace(/\/+$/, '');
|
|
22
|
+
const normalizedRest = rest.map((part) => part.replace(/^\/+|\/+$/g, '')).filter(Boolean);
|
|
23
|
+
|
|
24
|
+
if (!normalizedRest.length) {
|
|
25
|
+
return normalizedFirst || (first.startsWith('/') ? '/' : '');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return `${normalizedFirst}/${normalizedRest.join('/')}`;
|
|
29
|
+
}
|