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 🙏

© 2026 – Pkg Stats / Ryan Hefner

js-utils-zhql

v1.1.5

Published

"js工具包"

Readme

js-utils-zhql

介绍了整个工具包的使用及包含的功能

Alt text (完善后将上传到 github)

安装说明

npm install js-utils-zhql
1.npm install XXX -s
  
  npm install XXX -s 相当于 npm install -S 相当于 npm install --save

  这样安装是局部安装的,会写进package.json文件中的dependencie里。

  dependencies: 表示生产环境下的依赖管理;

  说白了你安装一个库如果是用来构建你的项目的,比如echarts、element-ui,是实际在项目中起作用,就可以使用 -s 来安装。

2.npm install XXX -d
  
  npm install XXX -d 相当于 npm install -D 相当于 npm install --save-dev

  这样安装是局部安装的,会写进package.json文件中的devDependencies 里。

  devDependencies :表示开发环境下的依赖管理;

  如果你安装的库是用来打包的、解析代码的,比如webpack、babel,就可以用 -d 来安装,项目上线了,这些库就没用了,不然留这些库给用户自己来打包和解析代码嘛。

3.npm install XXX -g
        
  npm install XXX -g 表示全局安装,安装一次过后,你就可以在其他直接用啦。

4.npm install XXX
        
  npm install XXX   什么都不加的时候

  npm5开始通过npm install 什么都不加 和 npm install --save一样,都是局部安装并会把模块自动写入package.json中的dependencies里。

使用说明

//方式一:
 import jsUtils from 'js-utils-zhql';

// 方式二
import { httpAxios, dataStorage, baseTools, sm4 } from 'js-utils-zhql';

// 挂载的方式
Vue.prototype.$axios = jsUtils.httpAxios;
Vue.prototype.$dataStorage= jsUtils.dataStorage;
Vue.prototype.$baseTools = jsUtils.baseTools;

🚀 API 文档

1.dataStorage

  • getSessionStorage: 获取 session

  • setSessionStorage: 设置 session

  • deleteSessionStorage: 删除 session

import { dataStorage } from 'js-utils-zhql';

dataStorage.getSessionStorage('token');

dataStorage.setSessionStorage('token','32sfdff232');

dataStorage.deleteSessionStorage('token');
  • getLocalStorage: 获取 localStorage

  • setLocalStorage: 设置 localStorage

  • deleteLocalStorage: 删除 localStorage

import { dataStorage } from 'js-utils-zhql';

dataStorage.getLocalStorage('token');

dataStorage.setLocalStorage('token','32sfdff232');

dataStorage.deleteLocalStorage('token');

2.dateFormat

  • formatPassTime:格式化现在的已过时间
  dateFormat.formatPassTime (1586840260500)  // 2年前
  • formatTime:格式化时间戳
import { dateFormat } from 'js-utils-zhql';
dateFormat.formatTime (new Date())  // 默认格式 'yyyy-MM-dd hh:mm:ss'
dateFormat.formatTime (new Date(),'yyyy:MM:dd')  // 自定义格式 'yyyy.MM.dd'

3.httpAxios

基于 axios 做二次封装

  • init: axios 初始化配置 option

  • get:get 请求方式

  • post:post 请求方式

import { httpAxios } from 'js-utils-zhql';
const option = {
    url: process.env.VUE_APP_URL ,  // 根据不同环节配置初始化baseUrl
}
httpAxios.init(option);

export const getList = async (params = {}) => httpAxios.get(`/user/list`, { params });

4.baseTools

常用函数工具库(防抖、节流、数据类型检测、深浅拷贝,数据脱敏等等,详见js库)

  • getDateType :数据类型检测
import { baseTools } from 'js-utils-zhql';
baseTools.getDateType({}) //Object
baseTools.getDateType([]) //Array
  • firstUpperCase :头字母大写
import { baseTools } from 'js-utils-zhql';
baseTools.firstUpperCase('string') //String
  • getRandomNumber :获取两个数字之间的随机数
import { baseTools } from 'js-utils-zhql';
baseTools.getRandomNumber(10,20) //10到20之间的随机数
  • descCompare :排序函数升序
import { baseTools } from 'js-utils-zhql';
arr.sort(baseTools.compare(prop))
  • debounce :防抖
import { baseTools } from 'js-utils-zhql';
methods:{
    sumbit: baseTools.debounce(function(){
          // todo
     },500),
}
  • throttle : 节流
import { baseTools } from 'js-utils-zhql';
methods:{
    sumbit: baseTools.throttle(function(){
          // todo
     },500),
}

5.inputValidate

表单输入数据验证 (返回Boolean)

  • checkType :类型检测

    支持类型有 ip、phone(手机号码)、email(邮箱)、IDCard(身份证)、url(网址)、number(数字)等

  import { inputValidate } from 'js-utils-zhql';
  inputValidate.checkType('15919542299','phone') //检测手机
  inputValidate.checkType('[email protected]','email') //检测邮箱
  • checkIDCard :身份证验证
  import { inputValidate } from 'js-utils-zhql';
  inputValidate.checkIDCard('15919542299') //检测身份证
  • CheckSocialCreditCode :统一信用代码校验
  import { inputValidate } from 'js-utils-zhql';
  inputValidate.CheckSocialCreditCode('15919542299') //检测统一信用代码
  • filterSpecialStr : 过滤特殊字符后的字符串
  import { inputValidate } from 'js-utils-zhql';
  inputValidate.filterSpecialStr('1591%|+{}9542299') //返回去掉特殊字符的字符串

6.sm4

sm4加密

 import {sm4} from 'js-utils-zhql';
 sm4(key).encrypt(this.idCard) //key密钥,加密
 sm4(key).decrypt(res) //key密钥,解密
 Vue.prototype.$sm4 = sm4;
 this.$sm4.encrypt(this.idCard)
 this.$sm4.decrypt(res)

7.sentry

捕获异常信息

  • 初始化
 import { sentry } from 'js-utils-zhql';
 const option = {dsn:http://753ce3bf82e94ab0aa7b5e62fae16d3c@sentry.***.com:9000/2}
 const Sentry = sentry.getInstance(Vue, option);
 Vue.prototype.$sentry = sentry;
  • 主动上报
 this.$sentry.log('test');