@lijuhong1981/jsurl 1.1.2 → 1.1.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.
package/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ ISC License
2
+
3
+ Copyright (c) 2022-2026 lijuhong1981
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package/README.md CHANGED
@@ -1,11 +1,17 @@
1
- # `@lijuhong1981/jsurl`
2
-
3
- > TODO: description
4
-
5
- ## Usage
6
-
7
- ```
8
- const jsurl = require('@lijuhong1981/jsurl');
9
-
10
- // TODO: DEMONSTRATE API
11
- ```
1
+ # @lijuhong1981/jsurl
2
+
3
+ > URL 与路径解析工具集,支持 URL 全量解析、查询参数解析、路径拆分与文件名/扩展名提取。
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ npm install @lijuhong1981/jsurl
9
+ ```
10
+
11
+ ## 导出
12
+
13
+ - **解析**:`parseUrl(url, result?)`、`parseQueryParams(urlQuery, result?)`、`parsePath(path, result?)`
14
+ - **拆分**:`splitUrl(url)`、`splitPath(path)`
15
+ - **文件名/路径**:`extractBaseName`、`extractExtName`、`extractFileName`、`extractFolderPath`
16
+ - **协议判断**:`hasProtocolPrefix`、`isHttpProtocol`、`isFileProtocol`、`isBlobProtocol`、`isDataProtocol`
17
+ - **拼接**:`mergeUrl(...)`
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lijuhong1981/jsurl",
3
- "version": "1.1.2",
4
- "description": "> TODO: description",
3
+ "version": "1.1.4",
4
+ "description": "URL and path parsing utilities.",
5
5
  "author": "lijuhong1981 <lijuhong@hotmail.com>",
6
6
  "homepage": "https://github.com/lijuhong1981/jslibs#readme",
7
7
  "license": "ISC",
@@ -18,5 +18,5 @@
18
18
  "bugs": {
19
19
  "url": "https://github.com/lijuhong1981/jslibs/issues"
20
20
  },
21
- "gitHead": "2c858dc3ec250639ecb82d702dff85b72309aad0"
21
+ "gitHead": "e968d936633601ce59f5c9aa99c36143b66a1de2"
22
22
  }
@@ -1,21 +1,16 @@
1
+ import extractFileName from "./extractFileName.js";
2
+
1
3
  /**
2
4
  * 从url中提取不包含扩展名的文件名
3
5
  * @param {String} url 传入的url
4
6
  * @returns {String} 提取的文件名
5
7
  */
6
8
  function extractBaseName(url) {
7
- let index = url.lastIndexOf('?');
8
- if (index !== -1)
9
- url = url.substring(0, index);
10
-
11
- index = url.lastIndexOf('.');
12
- if (index !== -1)
13
- url = url.substring(0, index);
14
-
15
- index = url.lastIndexOf('/');
9
+ const fileName = extractFileName(url);
10
+ const index = fileName.lastIndexOf('.');
16
11
  if (index === -1)
17
- return url;
18
- return url.substring(index + 1);
12
+ return fileName;
13
+ return fileName.substring(0, index);
19
14
  };
20
15
 
21
16
  export default extractBaseName;
@@ -1,3 +1,5 @@
1
+ import extractFileName from "./extractFileName.js";
2
+
1
3
  /**
2
4
  * 从url中提取文件扩展名
3
5
  * @param {String} url 传入的url
@@ -5,14 +7,11 @@
5
7
  * @returns {String} 提取的扩展名
6
8
  */
7
9
  function extractExtName(url, containsPoint = true) {
8
- let index = url.lastIndexOf('?');
9
- if (index !== -1)
10
- url = url.substring(0, index);
11
-
12
- index = url.lastIndexOf('.');
10
+ const fileName = extractFileName(url);
11
+ const index = fileName.lastIndexOf('.');
13
12
  if (index === -1)
14
13
  return '';
15
- return url.substring(containsPoint ? index : index + 1);
14
+ return fileName.substring(containsPoint ? index : index + 1);
16
15
  };
17
16
 
18
17
  export default extractExtName;