Global

Methods

addQuote(target) → {String}

[addQuote description] 在字符串两端添加双引号,然后内部需要转义的地方都要转义,用于接装 JSON的键名或模析系统中,感谢:http://code.google.com/p/jquery-json/
Parameters:
Name Type Description
target String 目标字符串
Source:
Returns:
返回转义之后的字符串
Type
String

addStyle(css) → {Null}

[addStyle description] 动态添加样式
Parameters:
Name Type Description
css String css代码
Source:
Returns:
无返回
Type
Null

appendQuery(url, query) → {String}

[appendQuery description] 给url添加query参数
Parameters:
Name Type Description
url String 需要添加的url
query String 添加的query,一般为'name=value'
Source:
Returns:
返回新url
Type
String

bs2(v) → {Array}

[bs2 description] 通过字节操作将数字转换成有2个字节的数组
Parameters:
Name Type Description
v Number 原数字
Source:
Returns:
转换后的数组
Type
Array

bs4(v) → {Array}

[bs4 description] 通过字节操作将数字转换成有4个字节的数组
Parameters:
Name Type Description
v Number 原数字
Source:
Returns:
转换后的数组
Type
Array

bs8(v) → {Array}

[bs8 description] 通过字节操作将数字转换成有8个字节的数组
Parameters:
Name Type Description
v Number 原数字
Source:
Returns:
转换后的数组
Type
Array

byteCount(str) → {Number}

[byteCount description] 返回UTF-8字符串的字节大小
Parameters:
Name Type Description
str String 字符串
Source:
Returns:
返回字节大小,即转换成Ascii码之后的字节大小
Type
Number

CanvasTest() → {Boolean}

[CanvasTest description] Canvas支持度检测
Source:
Returns:
返回检测结果
Type
Boolean

cloneDeep(obj) → {Object}

[cloneDeep description] 深度克隆object
Parameters:
Name Type Description
obj Object 需要克隆的object
Source:
Returns:
克隆之后的新Object
Type
Object

copyTextToClipboard(text) → {Null}

[copyTextToClipboard description] 将文本复制到剪贴板,来自:https://stackoverflow.com/questions/400212/how-do-i-copy-to-the-clipboard-in-javascript
Parameters:
Name Type Description
text String 需要复制的文本
Source:
Returns:
无返回
Type
Null

countItemNum(arr) → {Object}

[countItemNum description] 统计数组中各成员个数
Parameters:
Name Type Description
arr Array 待统计数组
Source:
Returns:
统计结果
Type
Object

cssTest(property, value) → {Boolean}

[cssTest description] 用于简单的 CSS 特性检测,来自:https://github.com/chokcoco/iCSS/issues/9
Parameters:
Name Type Description
property String 需要检测的 CSS 属性名
value String 样式的具体属性值
Source:
Returns:
返回检查结果
Type
Boolean

dateToString(date) → {String}

[dateToString description] 获取字符串形式的年月日,使用数组的join方法返回连接起来的字符串
Parameters:
Name Type Description
date Date 需要转换成字符串格式的日期
Source:
Returns:
字符串格式的日期
Type
String

debounce(func, delay, immediate) → {function}

[debounce description] 函数防抖动
Parameters:
Name Type Description
func function 实际要执行的函数
delay Number 执行间隔,单位是毫秒(ms)
immediate String 是否第一次立即执行
Source:
Returns:
返回一个“防抖动”函数
Type
function

digitUppercase(n) → {String}

[digitUppercase description] 金额的大写转换,来自:https://segmentfault.com/g/1570000011077131/d/1560000011078444
Parameters:
Name Type Description
n Number 原金额数字
Source:
Returns:
大写的金额
Type
String

escapeHTML(target) → {String}

[escapeHTML description] 将字符串经过html转义得到适合在页面中显示的内容,如将 < 替换为 <
Parameters:
Name Type Description
target String 目标字符串
Source:
Returns:
转义之后的字符串
Type
String

escapeRegExp(str) → {String}

[stripScripts description] 把字符串转为安全的正则源码,文档:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
Parameters:
Name Type Description
str String 字符串
Source:
Returns:
返回安全的正则源码
Type
String

formatDate(date, fmt) → {String}

[formatDate description] 时间戳转换
Parameters:
Name Type Description
date Date Date对象
fmt String 转换格式
Source:
Returns:
返回一个转换后的字符串
Type
String

formatDuration(t) → {String}

[formatDuration description] 时间转换,多用于视频播放时的剩余时间显示
Parameters:
Name Type Description
t Number/String 视频的秒数
Source:
Returns:
转换后的时间,例如:'389:03','00:05'
Type
String

genDateArray() → {Array}

[genDateArray description] 创建过去七天的数组
Source:
Returns:
过去七天的数组(Date类型)
Type
Array

generateDaysArray(start, end) → {Array}

[generateDaysArray description] 根据开始时间和结束时间,返回其间所有天组成的数组
Parameters:
Name Type Description
start String 字符串格式的开始日期
end String 字符串格式的结束日期
Source:
Returns:
其间所有天组成的数组
Type
Array

genRandomColor() → {String}

[genRandomColor description] 产生随机颜色
Source:
Returns:
随机rgb格式的颜色像素值
Type
String

genRandomHEX() → {String}

[genRandomHEX description] 生成随机HEX色值
Source:
Returns:
随机HEX色值
Type
String

genRandomId(len) → {String}

[genRandomId description] 生成随机ID
Parameters:
Name Type Description
len Number 需要生成的ID的长度
Source:
Returns:
生成的随机字符串ID
Type
String

genRandomNum(min, max) → {Number}

[getRoundNum description] 生成范围随机数
Parameters:
Name Type Description
min Number 最小值
max Number 最大值
Source:
Returns:
生成的随机数字
Type
Number

genRandomString(length) → {String}

[genRandomString description] 生成固定长度的随机字符串
Parameters:
Name Type Description
length Number 字符串长度
Source:
Returns:
返回随机字符串
Type
String

genStarScore(rate) → {String}

[genStarScore description] 生成星级评分
Parameters:
Name Type Description
rate Number 评分数据,0.5为单位
Source:
Returns:
星级评分字符串
Type
String

genTimeStamp() → {String}

[genTimeStamp description] 生成一个随机数时间戳,来自:Coco
Source:
Returns:
随机数时间戳
Type
String

getBrowserName() → {String}

[getBrowserName description] 获取当前浏览器的名称
Source:
Returns:
浏览器名称
Type
String

getCookie(name) → {String}

[getCookie description] 获取 Cookie 值
Parameters:
Name Type Description
name String Cookie的name属性
Source:
Returns:
Cookie的value值
Type
String

getCurrentPath() → {String}

[getType description] 获取当前路径
Source:
Returns:
当前路径
Type
String

getDateDiff(start, end) → {Number}

[getDateDiff description] 根据开始时间和结束时间,计算相差的天数
Parameters:
Name Type Description
start String 字符串格式的开始日期->"YYYY-MM-DD"
end String 字符串格式的结束日期->"YYYY-MM-DD"
Source:
Returns:
相差天数
Type
Number

getDevice() → {String}

[getDevice description] 获取当前设备类型
Source:
Returns:
设备类型
Type
String

getInputIndex(obj) → {Number}

[getJsDir description] 获取文本框光标位置
Parameters:
Name Type Description
obj Object 需要获取光标位置的 input | textarea dom对象
Source:
Returns:
返回光标所在索引
Type
Number

getJsDir(src) → {String}

[getJsDir description] 获取js所在路径
Parameters:
Name Type Description
src String html中的script代码
Source:
Returns:
js所在路径
Type
String

getLocation(callback) → {Null}

[getLocation description] 获取地理位置
Parameters:
Name Type Description
callback function 回调函数
Source:
Returns:
无返回
Type
Null

getNetType() → {String}

[getNetType description] 获取当前网络类型
Source:
Returns:
网络类型
Type
String

getPageHeight() → {Number}

[getPageHeight description] 获取页面高度
Source:
Returns:
页面高度
Type
Number

getPageViewWidth() → {Number}

[getPageViewWidth description] 获取页面可视宽度
Source:
Returns:
页面可视宽度
Type
Number

getPageWidth() → {Number}

[getPageWidth description] 获取页面宽度
Source:
Returns:
页面宽度
Type
Number

getRandomItem(arr) → {Any}

[getRandomItem description] 获取随机数组成员
Parameters:
Name Type Description
arr Array 数组
Source:
Returns:
随机数组成员
Type
Any

getRequestParams(paras) → {Object/String}

[getRequestParams description] url中query解析
Parameters:
Name Type Description
paras Null 参数可以为空,此时返回请求参数Map本身 {String} 参数可以为请求key,以便返回querystring中key对应的value
Source:
Returns:
根据参数不同,要返回不同的结果,object或者字符串
Type
Object/String

getRoundNum(num, decimal) → {Number}

[getRoundNum description] 精确到小数点后几位
Parameters:
Name Type Description
num Number 原数值
decimal Number 精确到小数点后的位数
Source:
Returns:
精确后的数字
Type
Number

getSearchParams() → {Object}

[getSearchParams description] 获取URL的查询参数
Source:
Returns:
查询参数对象
Type
Object

getStringLength(str, fix) → {Number}

[getStringLength description] 求得计算机学上的字符串长度
Parameters:
Name Type Description
str String 字符串
fix Number 修正,一个汉字占几个字节
Source:
Returns:
返回计算机学上的字符串长度
Type
Number

getSystem() → {String}

[getSystem description] 获取当前操作系统
Source:
Returns:
操作系统名称+版本
Type
String

getType(any) → {String}

[getType description] 判断具体类型
Parameters:
Name Type Description
any Object 需要判断的值
Source:
Returns:
类型
Type
String

getUrlState(URL) → {Boolean}

[getUrlState description] 检查URL链接是否有效
Parameters:
Name Type Description
URL String 需要检查的URL链接
Source:
Returns:
检查结果
Type
Boolean

hexMd5(sMessage, bit) → {String}

[hexMd5 description] md5加密函数
Parameters:
Name Type Description
sMessage String 需要加密的字符串
bit Number 加密返回的位数,默认为16
Source:
Returns:
返回md5加密后的字符串
Type
String

hexToRgba(color, opacity) → {String}

[hexToRgba description] 将hex格式像素值转换成rgba格式
Parameters:
Name Type Description
color String hex格式像素值
opacity Number 透明度
Source:
Returns:
返回rgba格式像素值
Type
String

initRequestAnimationFrame() → {Null}

[addStyle description] requestAnimationFrame初始化
Source:
Returns:
无返回
Type
Null

isContains(target, str, separator) → {Boolean}

[isContains description] 判断一个字符串是否包含另外一个字符串
Parameters:
Name Type Description
target String 目标字符串
str String 父字符串
separator String 分隔符
Source:
Returns:
返回判断结果
Type
Boolean

isDigit(value) → {String}

[isDigit description] 判断是否为数字类型
Parameters:
Name Type Description
value String/Number 需要判断的值
Source:
Returns:
判断
Type
String

isEndsWith(str, suffix) → {Boolean}

[isEndsWith description] 判断是否以给定字符串结尾
Parameters:
Name Type Description
str String 字符串
suffix String 后缀
Source:
Returns:
返回判断结果
Type
Boolean

isStartsWith(str, prefix) → {Boolean}

[isStartsWith description] 判断是否以给定字符串开始
Parameters:
Name Type Description
str String 字符串
prefix String 前缀
Source:
Returns:
返回判断结果
Type
Boolean

loadScript(src) → {Null}

[loadStyle description] 加载 JS 文件
Parameters:
Name Type Description
src String js文件所在地址
Source:
Returns:
无返回
Type
Null

loadStyle(url) → {Null}

[loadStyle description] 加载 CSS 文件
Parameters:
Name Type Description
url String css文件所在url
Source:
Returns:
无返回
Type
Null

localStorageTest() → {Boolean}

[localStorageTest description] localStorage支持度检测
Source:
Returns:
返回检测结果
Type
Boolean

move(v, bits, bytes) → {Number}

[move description] 将数字右移
Parameters:
Name Type Description
v String 原数字
bits Number 移动位数
bytes Number 控制右移之后的结果范围
Source:
Returns:
返回右移结果
Type
Number

numberUpperFormat(input) → {String}

[numberUpperFormat description] 数字转换,简单理解后面要有三个0,则是千,4个零,则是万。当然不一定是零,位数到了就行,反正都会省略掉(未做四舍五入),来自:http://xjinjin.net/2016/08/12/unit-conversion/
Parameters:
Name Type Description
input Number 原数字
Source:
Returns:
转换后的"数字"
Type
String

numOfComma(num) → {String}

[numOfComma description] 将数字转换为每3位添加一个逗号的格式,123456->123,456
Parameters:
Name Type Description
num Number 原数字
Source:
Returns:
转换后的"数字"
Type
String

numOfComma2(num) → {String}

[numOfComma2 description] 利用正则将数字转换为每3位添加一个逗号的格式(第2种实现方式)
Parameters:
Name Type Description
num Number 原数字
Source:
Returns:
转换后的"数字"
Type
String

objToQuery(obj) → {String}

[objToQuery description] 将object转换成query形式
Parameters:
Name Type Description
obj Object 需要转换的object
Source:
Returns:
返回query形式的字符串
Type
String

pad(target, n) → {String}

[pad description] 与 trim 相反, pad 可以为字符串的某一端添加字符串。如pad("Merrier",9) -> 00Merrier
Parameters:
Name Type Description
target String 目标字符串
n Number 目标长度
Source:
Returns:
返回截取之后的字符串
Type
String

pseudoHack(dom) → {Null}

[pseudoHack description] IE6,7兼容伪类设置
Parameters:
Name Type Description
dom Object dom元素
Source:
Returns:
无返回
Type
Null

regularExpressionTest(type, val) → {Boolean}

[regularExpressionTest description] 函数防抖动
Parameters:
Name Type Description
type String 验证类型
val String/Number 进行验证的值
Source:
Returns:
返回验证结果
Type
Boolean

remInit() → {Null}

[remInit description] rem初始化,用于适配
Source:
Returns:
无返回,直接执行该函数即可
Type
Null

repeat(target, n) → {String}

[repeat description] 将一个字符串重复自身N次,如 repeat("Ha")得到HaHa。
Parameters:
Name Type Description
target String 目标字符串
n String 重复次数
Source:
Returns:
重复之后的字符串
Type
String

replaceAll(str, s1, s2) → {String}

[replaceAll description] 替换全部给定字符串
Parameters:
Name Type Description
str String 原字符串
s1 String 需要替换掉的字符串
s2 String 用于替换的字符串
Source:
Returns:
替换之后的字符串
Type
String

reverse(str) → {String}

[reverse description] 字符串反序输出
Parameters:
Name Type Description
str String 原字符串
Source:
Returns:
反序之后的字符串
Type
String

sessionStorageTest() → {Boolean}

[sessionStorageTest description] sessionStorage支持度检测
Source:
Returns:
返回检测结果
Type
Boolean

setCookie(name, value, hours) → {Null}

[setCookie description] 设置 Cookie 值
Parameters:
Name Type Description
name String Cookie的name属性
value String Cookie的value属性
hours Number 过期时间,单位为小时
Source:
Returns:
无返回
Type
Null

showDomOutline() → {null}

[showDomOutline description] 显示全部DOM边框
Source:
Returns:
Type
null

stringToDate(str) → {Date}

[stringToDate description] 使字符串形式的日期返回为Date型的日期
Parameters:
Name Type Description
str String 需要转换成日期格式的字符串
Source:
Returns:
日期
Type
Date

stripHTMLTags(str) → {String}

[stripHTMLTags description] 去除字符串中的html标签
Parameters:
Name Type Description
str String 字符串
Source:
Returns:
返回去除html标签之后的字符串
Type
String

stripScripts(str) → {String}

[stripScripts description] 去除字符串中的script代码
Parameters:
Name Type Description
str String 字符串
Source:
Returns:
返回去除script代码之后的字符串
Type
String

SVGTest() → {Boolean}

[SVGTest description] SVG支持度检测
Source:
Returns:
返回检测结果
Type
Boolean

throttle(func, threshhold, immediate) → {function}

[throttle description] 函数节流
Parameters:
Name Type Description
func function 实际要执行的函数
threshhold Number 执行间隔,单位是毫秒(ms)
immediate String 是否第一次立即执行
Source:
Returns:
返回一个“节流”函数
Type
function

timeAgo(agoTimeStamp, nowTimeStamp) → {String}

[timeAgo description] 时间转换,转换为'几分钟前'、'几个月前'、'几天前'这种,来自:http://caibaojian.com/timestamp.html
Parameters:
Name Type Description
agoTimeStamp Number 之前的时间戳
nowTimeStamp Number 当前时间戳,默认为new Date().getTime()
Source:
Returns:
返回一个转换后的字符串
Type
String

toAscii(str) → {Number}

[toAscii description] 将字符串转换成Ascii码形式,主要是对中文的转换
Parameters:
Name Type Description
str String 字符串
Source:
Returns:
返回Ascii码形式的字符串
Type
Number

toHump() → {String}

[toHump description] 字符串转成驼峰格式
Source:
Returns:
驼峰格式的字符串
Type
String

trim(str) → {String}

[trim description] 清除字符串两端的空白字符
Parameters:
Name Type Description
str String 目标字符串
Source:
Returns:
处理之后的字符串
Type
String

truncate(str, length, truncation) → {String}

[truncate description] 字符串截断,超出部分用省略号代替
Parameters:
Name Type Description
str String 字符串
length Number 最大长度
truncation String 代替部分
Source:
Returns:
返回替换之后的字符串
Type
String

ucfirst(str) → {String}

[ucfirst description] 首字母大写
Parameters:
Name Type Description
str String 原字符串
Source:
Returns:
返回新字符串
Type
String

webpAnimataionSupportDetect(feature, callback) → {Object}

[webpAnimataionSupportDetect description] 检测对webp的支持,来自:https://developers.google.com/speed/webp/faq 原理: 预先生成好webp格式的图片, 保存经过base64编码后的结果 生成相应的img标签, 将src设置为相应的base64地址 如果img标签能够成功加载(加载后的图片有宽和高), 则说明支持相应的webp格式 参数中的feature需要设置为'animation'
Parameters:
Name Type Description
feature String [lossy|lossless|alpha|animation]
callback function
Source:
Returns:
返回callback结果
Type
Object