npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

js-tools-zk

v1.0.8

Published

js 常用工具类汇总

Downloads

36

Readme

js-tools-zk

js-tools-zk 常用工具类汇总

Install via NPM/Yarn

npm install js-tools-zk
yarn add js-tools-zk

Example - basic

import {
  isPhone,
  isEmail,
  isPostcode,
  isFixedphone,
  isURL,
  isIdCard,
  isMobile,
  isWX,
  isPatrn,
  isEmojo,
  isIp,
  isIMEI,
  isLicense,
  isLeapYear,
  checkPwd,
  getRandomNumber,
  dateFormat,
  joinUrlQuery,
  getParams,
  fileDownload,
  debounce,
  throttle,
  hideMobile,
  typeOf
} from 'js-tools-zk'

// 是否是手机号
isPhone('13600000000') // true

// 是否是邮箱
isEmail('[email protected]') // true

// 是否是邮编
isPostcode('518173') // true

// 是否是座机
isFixedphone('0713-7669133') // true

// 是否是url
isURL('http://www.baidu.com') // true

// 是否是身份证号码
isIdCard('42112619901001519X') // true

// 是否是移动端
isMobile() // 不用传参 手机端返回true、电脑端返回false

// 是否微信环境
isWX() // 不用传参 微信环境内为true、否则返回false

// 是否包含特殊字符
isPatrn('?$~!123456') // true  // 目前中括号内的字符都标记为特殊字符, 主要校验非文字输入 [`~!@#$%^&*_|+<>?"{}.\/;'[\]]

// 是否包含表情符号
isEmojo('hello') // false ,如果输入包含表情符号则返回 true

// 是否是IP地址
isIp('192.168.1.100') // true

// 是否是手机机身码(IMEI)
isIMEI('1234567') // false  可上网查看手机IMEI规则

// 是否统一社会信用代码 (营业执照)
isLicense('12345678') // false 可上网查看营业执照规则

// 是否是闰年
isLeapYear('2020') // true

// 验证密码强度
checkPwd('123456') // 默认为0、包含字母返回1、数字+字母返回2、数字+字母+特殊符号返回3

// 获取指定范围内随机数
getRandomNumber(10, 30) // 22 随机返回10~30之间的数字

// 转换日期为 YYYY-MM-DD HH:mm:ss 字符串
dateFormat(date, 'YYYY-MM-DD HH:mm:ss') // date为传入的时间  2023-05-11 13:08:16

// 拼接url参数
joinUrlQuery({name: 'wangxinyan', age: 33}) // ?name=wangxinyan&age=30

// 获取url中参数  例如 url = https://www.baidu.com?age=33
getParams('age') // 33

// 文件下载
fileDownload(url, fileName) //传入2个参数 [要下载的文件路径和下载后展示的文件名]

// 防抖 vue为例
methods: {
  btnClick() {
    debounce(() => {
      console.log('测试防抖')
    }, 600)
  }
}

// 节流
methods: {
  btnClick() {
    throttle(() => {
      console.log('测试节流')
    }, 600)
  }
}

// 手机号脱敏
hideMobile('13612345678') // 136****5678

// 数据类型判断
typeOf('王新焱')  // string
typeOf(33)  // Number
typeOf([])  // array
typeOf({})  // object
typeOf(new Date())  // date
typeOf(null) // null
typeOf(true) // boolean
typeOf(() => { }) // function