0.1.3 • Published 4 years ago

ecard-tool v0.1.3

Weekly downloads
11
License
MIT
Repository
github
Last release
4 years ago

ecard-tool library

广州易林电子商务有限公司前端业务常用JavaScript函数封装

Install

npm install ecard-tool --save

Usage

import { Module_name } from 'ecard-tool';

Module_name.method();

Example

import { Regular } from 'ecard-tool';

let result = Regular.isEmail('liang0x4c@gmail.com');
console.log(result); // true

Cookie

操作cookie的方法集合

方法名称说明返回值
setCookie(cname, cvalue, exdays)设置Cookie-
getCookie(cname)读取CookieString
delCookie(cname)删除cookie-
import { Cookie } from 'ecard-tool'
let cname = 'cookie-name'
let cvalue = 'cookie-value'
let exdays = 1
Cookie.setCookie(cname, cvalue, exdays)
let value = Cookie.getCookie(cname)
console.log(value)
  
参数名称说明参数格式默认值必填
cnamecookie名字string-
cvaluecookie值string-
exdays过期天数integer1

FormatDate

格式化时间戳 yyyy-MM-dd hh:mm:ss

方法名称说明返回值
ym(time)年月String
md(time)月日String
ymd(time)年月日String
hm(time)时分String
ms(time)分秒String
hms(time)时分秒String
getDateTime(time)年月日时分秒Sring
import { FormatDate } from 'ecard-tool'
let time = 1543821845
let result = FormateDate.getDateTime(time)
console.log(result) // 2018-12-03 15:24:05
参数名称说明参数格式默认值必填
time时间戳number-

注: 方法内部会将time * 1000

Regular

常用正则及判断

方法名称说明返回值备注
isPhone(str)验证手机号码(中国大陆)boolean
isEmail(str)验证邮箱地址boolean
isIdCard(str)验证身份证boolean特定算法准确判断国内身份证(包含国际友人在华身份证)
isUrl(str)验证url地址boolean
isInteger(str)验证正整数boolean
isMoney(str)验证字符串是否为金额boolean
isChineseName(str)验证字符串是否为中文名字object
isBankCard(str)验证字符串是否为国内储蓄卡/信用卡boolean采用LUHN算法 支持 14, 19 位数字
常量名称说明返回值
phoneReg手机号码(中国大陆)正则String
emailReg邮箱正则String
idCardReg身份证(中国)正则String
integerReg正整数正则String
money货币金额正则String
chinese中文正则String
import { Regular } from 'ecard-tool'
let phone = Regular.isPhone('13800138000') // true
let email = Regular.isEmail('liang0x4c@gmail.com') // true
let phoneReg = Regular.phoneReg // '^1[3,4,5,6,7,8,9]{1}\\d{9}$'

FileType

上传文件类型

常量名称说明返回值
xls_xxls和xlsx文件格式String
image图片格式:jpge、jpg、pngString
video视频格式:mp4String
import { FileType } from 'ecard-tool'
let video = FileType.video // 'audio/mp4,video/mp4'

FormatMoney

格式化金额

方法名称说明返回值
currency格式化货币并保留两位数String -> eg: 1,234.00
limit限制输入框小数点后两位String
import { FormatMoney } from 'ecard-tool'
let money = 4000
console.log( FormatMoney.currency(money) ) // 4,000.00
// for vuejs
<input type="number" v-model="money" @input="money = FormatMoney.limit(money)" />
0.1.3

4 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago