0.1.5 • Published 4 years ago
@luohuidong/url v0.1.5
url
The url module provides utilities for URL resolution and parsing.
The structure of url
yarn add @luohuidong/url
Use npm:
npm i @luohuidong/url
Use yarn:
yarn add @luohuidong/url
How to use
import url from "url";
const parsedUrlObject = url.parse("https://user:pass@sub.example.com:8080/p/a/t/h?query=string#hash");
const formattedUrl = url.formatUrl({
protocol: 'https',
hostname: 'www.test.com',
pathname: '/',
query: {
a: 1,
b: 2
},
search: '?a=44&c=22'
})
API
parse
interface ParsedUrlObject {
protocal: string;
search: string;
query: {
[index: string]: string;
};
};
let parse: (url: string) => ParsedUrlObject
format
interface UrlObject {
protocol: string;
hostname: string;
port?: string;
pathname: string;
search?: string;
query?: {
[index: string]: string | number
};
hash?: string;
}
let format: (urlObj: UrlObject) => string;
example:
const formattedurl = url.format({
protocol: 'https',
hostname: 'luohuidong.cn',
pathname: '/',
query: {
a: 'b',
c: 'd'
}
}))
// 'https://luohuidong.cn/?a=b&c=d'