Security News
The Push to Ban Ransom Payments Is Gaining Momentum
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
@festardoctor/utils-util
Advanced tools
Readme
Base64操作模块
数字操作工具模块
数据操作工具模块
URL操作工具模块
Base64操作模块
String
⏏Base64解码
Kind: Exported function
Param | Type |
---|---|
str | String |
Example
Base64Utils.base64Decode("Uy5ILkkuRS5MLkQ=") === 'S.H.I.E.L.D'
动态加载外部JS脚本
Kind: Exported function
Param | Type |
---|---|
opts | Object |
callback | function |
数字操作工具模块
String
⏏数字转成字符串
Kind: Exported function
Param | Type |
---|---|
num | Number |
Example
NumUtil.num2str(654.560) === '654.56'
字符串首部占位填充
Kind: Exported function
Param | Type | Default | Description |
---|---|---|---|
number | Number | 要填充的字符串 | |
len | Number | 2 | 填充后的长度 |
char | String | 0 | 占位的字符,默认为'0' |
Example
NumUtil.fillNumber(34,3)==='034'
NumUtil.fillNumber(34,3,'@')==='@34'
数据操作工具模块
Boolean
⏏对象合并,建议用Object.assign来替代
Kind: Exported function
Param | Type |
---|---|
destination | Object |
Boolean
⏏判断给定的对象是否为空对象
Kind: Exported function
Param | Type | Description |
---|---|---|
obj | Object | 给定的对象 |
URL操作工具模块
Object
⏏Object
⏏*
⏏Object
⏏解析URL
Kind: Exported function
Returns: Object
- 解析后返回的对象, {"loc": loc,"params": params, "append": append}
Param | Type | Description |
---|---|---|
url | String | 需要解析的url |
Example
const url = 'https://m.meitun.com/pdetails.html?mtoapp=0&mtomeitun=302&sid=18405&pid=08010200640101&promotionId=18405&promotionType=1&topicType=1&url=//m.meitun.com/h5/group/group.html&index=1&referer_url=joingroup&referer_code=joingroupHot'
UrlUtils.parseUrl(url)
//return {'loc':'https://m.meitun.com/pdetails.html',params:{mtoapp:'0',mtomeitun:'302',sid:'18405',pid:'08010200640101',promotionId:'18405','promotionType':'1','topicType':'1',url:'//m.meitun.com/h5/group/group.html',index:'1',referer_url:'joingroup',referer_code:'joingroupHot'},append:{}}
Object
⏏获取URL的qs
Kind: Exported function
Returns: Object
- 返回qs
Param | Type |
---|---|
url | String |
Example
const url = 'https://m.meitun.com/pdetails.html?mtoapp=0&mtomeitun=302&sid=18405&pid=08010200640101&promotionId=18405&promotionType=1&topicType=1&url=//m.meitun.com/h5/group/group.html&index=1&referer_url=joingroup&referer_code=joingroupHot'
UrlUtils.getParams(url)
//return {mtoapp:'0',mtomeitun:'302',sid:'18405',pid:'08010200640101',promotionId:'18405','promotionType':'1','topicType':'1',url:'//m.meitun.com/h5/group/group.html',index:'1',referer_url:'joingroup',referer_code:'joingroupHot'}
组装URL
Kind: Exported function
Param | Type | Description |
---|---|---|
obj | Object | 类型{"loc": loc,"params": params, "append": append} |
Example
let obj = {loc: "https://m.meitun.com/pdetails.html",params: {a: 1, b: 2},append: "#aaa"}
let url = UrlUtils.toCusString(obj);
//return 'https://m.meitun.com/pdetails.html?a=1&b=2#aaa'
往给定url上追加参数
Kind: Exported function
Param | Type | Description |
---|---|---|
url | String | 给定的url |
obj | Object | 需要追加的参数键值对 |
Example
let url = 'https://m.meitun.com/pdetails.html?a=1&b=2#aaa';
UrlUtils.appendParams(url, {a: 1})
//return 'https://m.meitun.com/pdetails.html?a=1&b=2#aaa'
判断给定的URL是否带有query string
Kind: Exported function
Param | Type | Description |
---|---|---|
url | String | 给定的url |
*
⏏查询location.href的queryString
Kind: Exported function
Returns: *
- 返回url 查询参数值 没有则返回null
Param | Description |
---|---|
name | url 查询参数名 |
给指定的href增加参数
Kind: Exported function
Param | Type | Description |
---|---|---|
href | String | 指定的href |
key | String | 需要增加的参数名称 |
value | Number | String | Array | 需要增加的参数值 |
Example
let url = 'https://m.meitun.com/pdetails.html?a=1&b=2#aaa';
UrlUtils.appendHref(url, a,1)
//return 'https://m.meitun.com/pdetails.html?a=1&b=2#aaa'
FAQs
基础工具组件.;
We found that @festardoctor/utils-util demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
Application Security
New SEC disclosure rules aim to enforce timely cyber incident reporting, but fear of job loss and inadequate resources lead to significant underreporting.
Security News
The Python Software Foundation has secured a 5-year sponsorship from Fastly that supports PSF's activities and events, most notably the security and reliability of the Python Package Index (PyPI).