@lijuhong1981/jsurl 1.0.0 → 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.
- package/package.json +1 -1
- package/src/extractExtName.js +3 -2
package/package.json
CHANGED
package/src/extractExtName.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 从url中提取文件扩展名
|
|
3
3
|
* @param {String} url 传入的url
|
|
4
|
+
* @param {Boolean} containsPoint 是否包含'.'符号,默认true
|
|
4
5
|
* @returns {String} 提取的扩展名
|
|
5
6
|
*/
|
|
6
|
-
function extractExtName(url) {
|
|
7
|
+
function extractExtName(url, containsPoint = true) {
|
|
7
8
|
let index = url.lastIndexOf('?');
|
|
8
9
|
if (index !== -1)
|
|
9
10
|
url = url.substring(0, index - 1);
|
|
@@ -11,7 +12,7 @@ function extractExtName(url) {
|
|
|
11
12
|
index = url.lastIndexOf('.');
|
|
12
13
|
if (index === -1)
|
|
13
14
|
return '';
|
|
14
|
-
return url.substring(index);
|
|
15
|
+
return url.substring(containsPoint ? index : index + 1);
|
|
15
16
|
};
|
|
16
17
|
|
|
17
18
|
export default extractExtName;
|