@festardoctor/utils-util

0.0.2 • Public • Published

Modules

@festardoctor/utils-util/Base64Utils

Base64操作模块

@festardoctor/utils-util/LoadScript
@festardoctor/utils-util/NumUtils

数字操作工具模块

@festardoctor/utils-util/ObjUtils

数据操作工具模块

@festardoctor/utils-util/UrlUtils

URL操作工具模块

@festardoctor/utils-util/Base64Utils

Base64操作模块

base64Decode(str) ⇒ String

Base64解码

Kind: Exported function

Param Type
str String

Example

Base64Utils.base64Decode("Uy5ILkkuRS5MLkQ=") === 'S.H.I.E.L.D'

@festardoctor/utils-util/LoadScript

loadScript(opts, callback)

动态加载外部JS脚本

Kind: Exported function

Param Type
opts Object
callback function

@festardoctor/utils-util/NumUtils

数字操作工具模块

num2str(num) ⇒ String

数字转成字符串

Kind: Exported function

Param Type
num Number

Example

NumUtil.num2str(654.560) === '654.56'

fillNumber(number, len, char)

字符串首部占位填充

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'

@festardoctor/utils-util/ObjUtils

数据操作工具模块

ObjUtils.extend(destination)

对象合并,建议用Object.assign来替代

Kind: Exported function

Param Type
destination Object

ObjUtils.isEmptyObject(obj) ⇒ Boolean

判断给定的对象是否为空对象

Kind: Exported function

Param Type Description
obj Object 给定的对象

@festardoctor/utils-util/UrlUtils

URL操作工具模块

parseUrl(url) ⇒ 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:{}}

getParams(url) ⇒ 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'}

toCusString(obj)

组装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'

appendParams(url, obj)

往给定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'

hasParam(url)

判断给定的URL是否带有query string

Kind: Exported function

Param Type Description
url String 给定的url

getUrlParamByName(name) ⇒ *

查询location.href的queryString

Kind: Exported function Returns: * - 返回url 查询参数值 没有则返回null

Param Description
name url 查询参数名

appendHref(href, key, value)

给指定的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'

Readme

Keywords

none

Package Sidebar

Install

npm i @festardoctor/utils-util

Weekly Downloads

1

Version

0.0.2

License

ISC

Unpacked Size

52.3 kB

Total Files

18

Last publish

Collaborators

  • tiffanyyan879
  • liyanfang
  • fe-stardoctor