为大部分命令添加输出结构结构化数据

This commit is contained in:
fofolee
2025-01-26 22:55:47 +08:00
parent 73684865ae
commit deade3e1de
33 changed files with 1519 additions and 248 deletions

View File

@@ -54,17 +54,6 @@ function formatQuery(queryParams) {
}
}
// 解析路径名
function parsePath(path) {
return url.parse(path);
}
// 解析主机名
function parseHost(host) {
const { hostname, port } = url.parse(`http://${host}`);
return { hostname, port };
}
// 解析 URL 参数
function getQueryParam(urlString, param) {
const { query } = url.parse(urlString, true);
@@ -92,32 +81,13 @@ function isAbsolute(urlString) {
return url.parse(urlString).protocol !== null;
}
// 解析 URL 的各个部分
function parseComponents(urlString) {
const { protocol, auth, hostname, port, pathname, search, hash } =
url.parse(urlString);
return {
protocol: protocol?.replace(":", ""),
auth,
hostname,
port,
pathname,
search: search?.replace("?", ""),
hash: hash?.replace("#", ""),
};
}
module.exports = {
parse,
format,
parseQuery,
formatQuery,
parsePath,
parseHost,
getQueryParam,
addQueryParam,
removeQueryParam,
isAbsolute,
parseComponents,
};