zsg-utils
v2.0.1
Published
JavaScript 函数库、工具类
Downloads
41
Readme
zsg-utils
JavaScript 函数库、工具类
Installing
npm install zsg-utils
Using nodejs
const zsgUtils = require('zsg-utils')
<script src="https://unpkg.com/zsg-utils"></script>
<script>
console.log(ZsgUtils)
</script>
Import all methods
import zsgUtils from 'zsg-utils'
zsgUtils.getYMDHMS(1646726753253))
// {"year": 2022,"month": "03","date": "08","hours": 16,"minute": "05","second": 53}
'zsg-utils' API
基本方法
getObjType(obj) 检测数据类型-内部使用Object.prototype.toString.call()
import zsgUtils from 'zsg-utils'
zsgUtils.getObjType() // 'undefined'
zsgUtils.getObjType(true) // 'boolean'
zsgUtils.getObjType(1) // 'number'
zsgUtils.getObjType('abc') // 'string'
zsgUtils.getObjType(function () {}) // 'function'
zsgUtils.getObjType([]) // 'array'
zsgUtils.getObjType(new Date()) // 'date'
zsgUtils.getObjType(/^/) // 'regExp'
zsgUtils.getObjType(undefined)) // 'undefined'
zsgUtils.getObjType(null)) //'null'
zsgUtils.getObjType({}) // 'object'
zsgUtils.getObjType(Symbol(1)) // 'symbol'
Date日期方法
getYMDHMS(val) 时间戳转换为年月日时分秒
import zsgUtils from 'zsg-utils'
zsgUtils.getYMDHMS(1646726753253)) // {"year": 2022,"month": "03","date": "08","hours": 16,"minute": "05","second": 53}
Array数组方法
isRepeat(val) 通过哈希判断数组中是否有重复元素
import zsgUtils from 'zsg-utils'
zsgUtils.isRepeat([1,2,3,4,5]) // false
zsgUtils.isRepeat([1,2,1]) // true
url地址栏方法
getQueryVariable(val) 获取url地址栏参数
import zsgUtils from 'zsg-utils'
zsgUtils.getQueryVariable('id') // 地址栏有id就返回具体的值,没有就返回false
正则校验
checkStr(val,type)
type
目前有以下几种值 phone | card | email | number | english | chinese | lower | upper, 不传、传的不是以上几种参数返回true
import zsgUtils from 'zsg-utils'
zsgUtils.checkStr() // true
zsgUtils.checkStr(1) // true 只穿一个参数返回true
zsgUtils.checkStr(1, 2) // true type类型传的不是以上几种也返回true
// 手机号校验
zsgUtils.checkStr(1311, 'phone') // false
zsgUtils.checkStr(13573218888, 'phone') // true
// 身份证校验15 or 18
zsgUtils.checkStr(1311, 'card') // false
zsgUtils.checkStr(123456789012345, 'card') // true
zsgUtils.checkStr(123456789012345678, 'card') // true
// 英文校验
zsgUtils.checkStr('测试英文', 'english') // false
zsgUtils.checkStr('123', 'english') // false
zsgUtils.checkStr('abcdefg', 'english') // true
// 中文校验
zsgUtils.checkStr('abcdefg', 'chinese') // false
zsgUtils.checkStr(123, 'chinese') // false
zsgUtils.checkStr('测试中文', 'chinese') // true
// 小写字母校验
zsgUtils.checkStr('123', 'lower') // false
zsgUtils.checkStr('abcABC', 'lower') // false
zsgUtils.checkStr('abcdefg', 'lower') // true
// 大写字母校验
zsgUtils.checkStr('123', 'upper') // false
zsgUtils.checkStr('abcABC', 'upper') // false
zsgUtils.checkStr('ABCDEFG', 'upper') // true
本地存储方法
getStore(name) 获取LocalStorage
let name = zsgUtils.getStore('name')
setStore(name,content) 设置LocalStorage
zsgUtils.setStore('name','zsg')
removeStore(name) 删除LocalStorage
zsgUtils.removeStore('name')
License
MIT © 2022-present, zhaoshiguang, [email protected]