@cclr/utils 0.0.5
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/README.md +11 -0
- package/lib/cjs/index.js +32 -0
- package/lib/esm/index.js +29 -0
- package/lib/type/index.d.ts +27 -0
- package/package.json +26 -0
package/README.md
ADDED
package/lib/cjs/index.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const urlREG = new RegExp([
|
|
4
|
+
"^(https?:)//", // protocol
|
|
5
|
+
"(([^:/?#]*)(?::([0-9]+))?)", // host (hostname and port)
|
|
6
|
+
"(/{0,1}[^?#]*)", // pathname
|
|
7
|
+
"(\\?[^#]*|)", // search
|
|
8
|
+
"(#.*|)$", // hash
|
|
9
|
+
].join(""));
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 解析url
|
|
13
|
+
* @param url
|
|
14
|
+
*/
|
|
15
|
+
function urlParse(url) {
|
|
16
|
+
const match = url.match(urlREG);
|
|
17
|
+
return match
|
|
18
|
+
? {
|
|
19
|
+
href: url,
|
|
20
|
+
protocol: match[1],
|
|
21
|
+
host: match[2],
|
|
22
|
+
hostname: match[3],
|
|
23
|
+
port: match[4],
|
|
24
|
+
pathname: match[5],
|
|
25
|
+
search: match[6],
|
|
26
|
+
hash: match[7],
|
|
27
|
+
}
|
|
28
|
+
: {};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
exports.urlParse = urlParse;
|
|
32
|
+
exports.urlREG = urlREG;
|
package/lib/esm/index.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const urlREG = new RegExp([
|
|
2
|
+
"^(https?:)//", // protocol
|
|
3
|
+
"(([^:/?#]*)(?::([0-9]+))?)", // host (hostname and port)
|
|
4
|
+
"(/{0,1}[^?#]*)", // pathname
|
|
5
|
+
"(\\?[^#]*|)", // search
|
|
6
|
+
"(#.*|)$", // hash
|
|
7
|
+
].join(""));
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 解析url
|
|
11
|
+
* @param url
|
|
12
|
+
*/
|
|
13
|
+
function urlParse(url) {
|
|
14
|
+
const match = url.match(urlREG);
|
|
15
|
+
return match
|
|
16
|
+
? {
|
|
17
|
+
href: url,
|
|
18
|
+
protocol: match[1],
|
|
19
|
+
host: match[2],
|
|
20
|
+
hostname: match[3],
|
|
21
|
+
port: match[4],
|
|
22
|
+
pathname: match[5],
|
|
23
|
+
search: match[6],
|
|
24
|
+
hash: match[7],
|
|
25
|
+
}
|
|
26
|
+
: {};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { urlParse, urlREG };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 解析url
|
|
3
|
+
* @param url
|
|
4
|
+
*/
|
|
5
|
+
declare function urlParse(url: string): {
|
|
6
|
+
href: string;
|
|
7
|
+
protocol: string;
|
|
8
|
+
host: string;
|
|
9
|
+
hostname: string;
|
|
10
|
+
port: string;
|
|
11
|
+
pathname: string;
|
|
12
|
+
search: string;
|
|
13
|
+
hash: string;
|
|
14
|
+
} | {
|
|
15
|
+
href?: undefined;
|
|
16
|
+
protocol?: undefined;
|
|
17
|
+
host?: undefined;
|
|
18
|
+
hostname?: undefined;
|
|
19
|
+
port?: undefined;
|
|
20
|
+
pathname?: undefined;
|
|
21
|
+
search?: undefined;
|
|
22
|
+
hash?: undefined;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
declare const urlREG: RegExp;
|
|
26
|
+
|
|
27
|
+
export { urlParse, urlREG };
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cclr/utils",
|
|
3
|
+
"version": "0.0.5",
|
|
4
|
+
"description": "> TODO: description",
|
|
5
|
+
"author": "cclr <18843152354@163.com>",
|
|
6
|
+
"homepage": "",
|
|
7
|
+
"license": "ISC",
|
|
8
|
+
"main": "lib/cjs/index.js",
|
|
9
|
+
"module": "lib/esm/index.js",
|
|
10
|
+
"types": "lib/type/index.d.ts",
|
|
11
|
+
"directories": {
|
|
12
|
+
"lib": "lib",
|
|
13
|
+
"test": "__tests__"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"lib"
|
|
17
|
+
],
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git@gitee.com:cclr/toolkit.git"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"test": "node ./__tests__/utils.test.js"
|
|
24
|
+
},
|
|
25
|
+
"gitHead": "ff52fad0705ca94354c4596e238a793ae342bab4"
|
|
26
|
+
}
|