0.1.1 • Published 6 years ago

tyutil v0.1.1

Weekly downloads
2
License
MIT
Repository
-
Last release
6 years ago

tyutil

一个js工具库

整理了平常项目中常用的一些方法,正则验证,日期处理,金额处理,字符串处理判断,节流防抖等。

安装使用

1. npm完整引入

npm install tyutil --save-dev

支持umd规范

let tyutil = require('tyutil')
let mValue = tyutil.money.toBig(12345)
// mValue : 壹万贰仟叁佰肆拾伍元整

2. 部分引入

你可以只引入你需要的模块

// let date = require('tyutil/module/模块名')
let date = require('tyutil/module/date')
let fTime = date.format(new Date(),'yyyy年MM月dd日')
// fTime : 2017年12月06日

3. 浏览器

直接下载dist目录下的tyutil.min.js使用

<script src="tyutil.min.js"></script>
<script>
var nowTime = tyutil.date.getTime();
</script>

模块

  • common.js 封装了一些常用的函数
  • date.js 日期处理
  • dom.js 常用dom处理
  • drawCircle.js 绘制动态环形进度条
  • money.js 金额处理
  • optimize.js 性能优化
  • store.js 封装了sessionStorage/localStorage/cookie,方便操作
  • regexp.js 一些常用的正则表达式

API文档

Members

Functions

Regexp

正则表达式封装

Kind: global variable

Regexp.isEmail(str) ⇒ boolean

判断是否为邮箱地址

Kind: static method of Regexp

ParamTypeDescription
strstring待验证字符串

Regexp.isMobilePhone(str) ⇒ boolean

判断是否是手机号码

Kind: static method of Regexp

ParamTypeDescription
strstring待验证字符串

Regexp.idCard(str) ⇒ boolean

判断是否是身份证

Kind: static method of Regexp

ParamTypeDescription
strstring待验证字符串

Regexp.isUrl(str) ⇒ boolean

判断是否是url

Kind: static method of Regexp

ParamTypeDescription
strstring待验证字符串

Regexp.isDate(str) ⇒ boolean

判断是否是日期

Kind: static method of Regexp

ParamTypeDescription
strstring待验证字符串

Regexp.isIncludeCn(str) ⇒ boolean

判断是否包含中文

Kind: static method of Regexp

ParamTypeDescription
strstring待验证字符串

Regexp.isUserName(str) ⇒ boolean

判断用户名4-16位(字母,数字,下划线,减号)

Kind: static method of Regexp

ParamTypeDescription
strstring待验证字符串

sstore

sessionStorage封装

Kind: global variable

sstore.set(key, value) ⇒ void

添加

Kind: static method of sstore

ParamTypeDescription
keystringkey
valuestring

sstore.get(key) ⇒ object

获取

Kind: static method of sstore

ParamTypeDescription
keystringkey

sstore.del(key) ⇒ void

删除

Kind: static method of sstore

ParamTypeDescription
keystringkey

sstore.clear() ⇒ void

清除

Kind: static method of sstore

lstore

localStorage封装

Kind: global variable

lstore.set(key, value) ⇒ void

添加

Kind: static method of lstore

ParamTypeDescription
keystringkey
valueobject

lstore.get(key) ⇒ object

获取

Kind: static method of lstore

ParamDescription
keykey

lstore.del(key) ⇒ void

删除

Kind: static method of lstore

ParamDescription
keykey

lstore.clear() ⇒ void

清除

Kind: static method of lstore

cookie

cookie封装

Kind: global variable

cookie.set(key, value, time) ⇒ void

设置cookie key的值

Kind: static method of cookie

ParamTypeDescription
keystringkey
valuestring
timenumber失效时间

cookie.get(key) ⇒ string

获取cookie指定key值

Kind: static method of cookie

ParamTypeDescription
keystringkey

cookie.del(key) ⇒ void

删除cookie

Kind: static method of cookie

ParamTypeDescription
keystringkey

isNotEmpty(str) ⇒ boolean

判断字符串是否不为空

Kind: global function

ParamTypeDescription
strstring字符串

isEmptyObject(obj) ⇒ boolean

判断对象是否为空

Kind: global function

ParamType
objobject

isNumber(n) ⇒ boolean

判断是否是数字

Kind: global function

ParamType
nobject

isArray(obj) ⇒ void

判断是否是数组

Kind: global function

ParamType
objobject

clone(obj) ⇒ object

克隆对象

Kind: global function

ParamType
objobject

getOS() ⇒ string

获取操作系统

Kind: global function

getExplore(versions) ⇒ string

获取浏览器类型和版本

Kind: global function

ParamType
versionsboolean

urlParamsToObj(url) ⇒ object

url参数转对象

Kind: global function

ParamTypeDescription
urlStringurl

objToUrlParams(url, params) ⇒ string

对象参数添加到url上

Kind: global function Returns: string - url

ParamTypeDescription
urlstringurl
paramsobject参数

getParame(name) ⇒ string

获取url参数

Kind: global function

ParamTypeDescription
namestring参数名

randomWord(flag, min, max) ⇒ string

生成任意长度随机字母数字组合

Kind: global function

ParamTypeDescription
flagboolean是否任意长度
minnumber最小长度
maxnumber最大长度

UUID() ⇒ string

生成uuid

Kind: global function

ImgToBase64(url, callback, outputFormat) ⇒ void

img转base64

Kind: global function

ParamType
urlstring
callbackfunction
outputFormatstring

getTime() ⇒ number

获取当前时间戳

Kind: global function

passedTime(startTime) ⇒ string

距现在的已过时间

Kind: global function

ParamTypeDescription
startTimestring开始日期字符串

remainTime(endTime) ⇒ string

距现在的剩余时间

Kind: global function

ParamTypeDescription
endTimestring结束日期字符串

format(dateTime, fmt) ⇒ string

格式化日期

Kind: global function

ParamTypeDescription
dateTimestring日期/日期字符串
fmtobject格式

strToDate(dateStr) ⇒ Date | ''

字符串转日期

Kind: global function

ParamTypeDescription
dateStrstring日期字符串

compareDate(d1, d2) ⇒ number

比较两个日期

Kind: global function Returns: number - 1:大于;0:等于;-1:小于

ParamTypeDescription
d1Date第一个日期
d2Date第二个日期

addDay(date, dayNum) ⇒ Date

日期添加天数

Kind: global function

ParamTypeDescription
dateDate日期
dayNumnumber添加的天数

hasClass(ele, cls) ⇒ boolean

是否有指定样式

Kind: global function

ParamTypeDescription
eleobjectdom节点
clsstringclass名称

addClass(ele, cls) ⇒ void

为指定的dom元素添加样式

Kind: global function

ParamTypeDescription
eleobjectdom节点
clsstringclass名称

removeClass(ele, cls) ⇒ void

删除指定dom元素的样式

Kind: global function

ParamTypeDescription
eleobjectdom节点
clsstringclass名称

toggleClass(ele, cls) ⇒ void

如果存在(不存在),就删除(添加)一个样式

Kind: global function

ParamTypeDescription
eleobjectdom节点
clsstringclass名称

getScrollTop() ⇒ number

获取滚动条距离顶部的距离

Kind: global function

offset(ele) ⇒ number

获取元素的距离文档的位置

Kind: global function

ParamTypeDescription
eleobjectdom节点

setScrollTop(value) ⇒ void

设置滚动条距顶部的距离

Kind: global function

ParamTypeDescription
valuenumber距离

smoothScroll(to, duration) ⇒ void

平滑滚动到指定位置

Kind: global function

ParamTypeDescription
tonumber距离顶部的距离
durationnumber滚动的时间

pin(ele) ⇒ void

当元素滚动到顶部时固定元素

Kind: global function

ParamTypeDescription
eleobjectdom节点

isDOMElement(obj) ⇒ boolean

判断是否是dom对象

Kind: global function

ParamType
objobject

drawCircle(el, percent, style) ⇒ void

绘制圆环进度条

Kind: global function

ParamTypeDescription
elstringcanvas节点
percentnumber进度
styleobject样式配置
style.widthnumber圆环宽度
style.heightnumber圆环高度
style.bgColorstring背景圆环的颜色
style.foreColorstring运动圆环的颜色
style.lineWidthnumber环的宽度
style.fontSizenumber字体大小
style.fontFamilystring字体
style.lineCapboolean运动圆环是否圆角

format(num, precision, separator) ⇒ string

格式化金额

Kind: global function

ParamTypeDescription
numnumber金额
precisionnumber精度
separator*分隔符

toBig(n) ⇒ string

金额转大写

Kind: global function

ParamTypeDescription
nnumber金额

isSupportWebP() ⇒ boolean

判断浏览器是否支持webP格式图片

Kind: global function

loadWebP(attr) ⇒ void

替换webP

Kind: global function

ParamType
attrstring

debounce(func, delay) ⇒ function

防抖动

Kind: global function

ParamTypeDescription
funcfunction要执行的函数
delaynumber间隔时间

throttle(func, delay) ⇒ function

节流

Kind: global function

ParamTypeDescription
funcfunction要执行的函数
delaynumber间隔时间
0.1.1

6 years ago

0.1.0

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago