codestar-url-util
v1.2.2
Published
```typescript import urlUtil from "codestar-url-util"; ```
Readme
常用URL处理工具类
import urlUtil from "codestar-url-util";获取URL中的域名
expect(urlUtil.getDomain('http://www.google.com/index.html')).toEqual('www.google.com')获取URL中的path部分
expect(urlUtil.getPath('http://127.0.0.1:9655/index.php?a=2#kk')).toEqual('/index.php')
expect(urlUtil.getPath('http://127.0.0.1:9655/a#')).toEqual('/a')获取URL中的文件名称
expect(urlUtil.getFilename('https://x.com/x/234s.jpg?234234')).toEqual('234s.jpg')获取URL中的query部分字符串
expect(urlUtil.getQueryStr('http://www.x.com/index.html?x1=s&dd=655#aa=1')).toEqual('x1=s&dd=655')获取URL中的query参数对象
expect(urlUtil.getQueryMap('http://www.x.com/index.html?x1=s&dd=655#aa=1')).toEqual({x1:'s',dd:'655'})query参数字符串转成对象格式
expect(urlUtil.queryStrToMap('x1=s&dd=655')).toEqual({x1:'s',dd:'655'})query对象转成query字符串
expect(urlUtil.mapToQueryStr({x1:'s',dd:'655'})).toEqual('x1=s&dd=655')从URL的query中获取指定key的值
dateUtil.getPara(key: string, defaultValue: string | number = '', url?: string): string | number对URL进行替换,将query指定key的value替换成新值
expect(urlUtil.replace('x', '56465456','http://x.com/index.html?x=1d545')).toEqual('http://x.com/index.html?x=56465456')生成URL
dateUtil.createUrl(url: string, query?: { [key: string]: string | number | string[] }): string
expect(urlUtil.createUrl('https://x.com',{x:1,y:2})).toEqual('https://x.com?x=1&y=2')
