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-util-lib

v1.0.5

Published

javascript 工具类

Downloads

3

Readme

js-util-lib

JavaScript 工具函数库

Install

npm install --save js-util-lib

or

<script src="../../js.utils.lib.js"></script>

1. jsUtilLib.query

  • 获取当前浏览器url上的参数,或者指定链接的参数
  • 可以获取全部参数,或者指定参数
  • jsUtilLib.query.getAllParams -- 获取url全部参数
  • jsUtilLib.query.getQueryString -- 获取url某个参数

2. jsUtilLib.validata

  • 校验
  • jsUtilLib.validata.isNull -- 是否为空||undefined || null
  • jsUtilLib.validata.isString -- 是否是字符串
  • jsUtilLib.validata.isMobile -- 判断是否是手机号
  • jsUtilLib.validata.isTelephone -- 判断是否是座机号
  • jsUtilLib.validata.isIdCardNum -- 判断是否是身份证号
  • jsUtilLib.validata.isBankCardNum -- 判断是否是银行卡号
  • jsUtilLib.validata.isEmail -- 判断是否是邮箱
  • jsUtilLib.validata.isEnString -- 判断是不是都是字母
  • jsUtilLib.validata.isZhString -- 判断是不是都是中文
  • jsUtilLib.validata.isUrl -- 判断是不是url地址

3. jsUtilLib.dataMask

  • 脱敏处理
  • jsUtilLib.dataMask.mobile -- 手机号脱敏
  • jsUtilLib.dataMask.idCardNum -- 身份证号脱敏
  • jsUtilLib.dataMask.bankCardNum -- 银行卡号脱敏
  • jsUtilLib.dataMask.telephone -- 固定电话脱敏
  • jsUtilLib.dataMask.chineseName -- 中文姓名脱敏
  • jsUtilLib.dataMask.email -- 邮箱脱敏

4. jsUtilLib.image

  • 图片处理
  • jsUtilLib.image.base64 -- 图片转base64
  • jsUtilLib.image.size -- 获取图片宽高

5. jsUtilLib.guid

  • 生成GUID || UUID (随机生成,不能保证绝对没有重复)
  • jsUtilLib.guid.get -- 生成GUID

5. jsUtilLib.device

  • 获取设备信息
  • jsUtilLib.device.os -- 获取当前系统信息
  • jsUtilLib.device.type -- 获取当前设备类型(移动端和pc端)

使用方法:

1.jsUtilLib.query


1. getAllParams

jsUtilLib.query.getAllParams(url:String,cover:Boolean);

  • url 选填,默认为当前页面的url
  • cover 默认为true, true 时会覆盖相同的key,false时会保留所有参数
  • 如:
  • url = 'http://js/utils/lib?aaa=1&bbb=3&aaa=4'
  • if cover = true :
  •  {aaa:4,bbb=3}
  • if cover = false :
  •  {aaa:[1,4],bbb=3}
jsUtilLib.query.getAllParams(null,true);
// 或者
jsUtilLib.query.getAllParams();
	

2.getQueryString

jsUtilLib.query.getQueryString(name:String<required>,url:String);

/**
 * Getting parameters from URL or custom string;
 * @param { String } `name` The key corresponding to the value you want;
 * @param { String } `url` 
 * @example :
 *  url = 'http://js/utils/lib?aaa=1&bbb=3&aaa=4'
 *  this.getQueryString('aaa'); // 4
 *  this.getQueryString('aaa','your custom url'); 
 */
jsUtilLib.query.getQueryString('sdf');

2.jsUtilLib.validata


jsUtilLib.validata

  • jsUtilLib.validata.isNull(str:String<required>);
  • jsUtilLib.validata.isString(str:String<required>);
  • jsUtilLib.validata.isMobile(str:String<required>);
  • jsUtilLib.validata.isTelephone(str:String<required>);
  • jsUtilLib.validata.isIdCardNum(str:String<required>);
  • jsUtilLib.validata.isBankCardNum(str:String<required>);
  • jsUtilLib.validata.isEmail(str:String<required>);
  • jsUtilLib.validata.isEnString(str:String<required>);
  • jsUtilLib.validata.isZhString(str:String<required>);
  • jsUtilLib.validata.isUrl(str:String<required>);
    console.log('是否为空',jsUtilLib.validata.isNull('')); // 是否为空 true
    console.log('是否是字符串',jsUtilLib.validata.isString('')); // 是否是字符串 true
    console.log('判断是否是手机号',jsUtilLib.validata.isMobile('')); // 判断是否是手机号 false
    console.log('判断是否是座机号',jsUtilLib.validata.isTelephone('')); // 判断是否是座机号 false
    console.log('判断是否是身份证号',jsUtilLib.validata.isIdCardNum('')); // 判断是否是身份证号 false
    console.log('判断是否是银行卡号',jsUtilLib.validata.isBankCardNum('')); // 判断是否是银行卡号 false
    console.log('判断是否是邮箱',jsUtilLib.validata.isEmail('')); // 判断是否是邮箱 false
    console.log('判断是不是都是字母',jsUtilLib.validata.isEnString('')); // 判断是不是都是字母 false
    console.log('判断是不是都是中文',jsUtilLib.validata.isZhString('')); // 判断是不是都是中文 false
    console.log('判断是不是url地址',jsUtilLib.validata.isUrl('')); // 判断是不是url地址 false

3.jsUtilLib.dataMask


jsUtilLib.dataMask

  • jsUtilLib.dataMask.mobile(str:String<required>);
  • jsUtilLib.dataMask.idCardNum(str:String<required>);
  • jsUtilLib.dataMask.bankCardNum(str:String<required>);
  • jsUtilLib.dataMask.telephone(str:String<required>);
  • jsUtilLib.dataMask.chineseName(str:String<required>);
  • jsUtilLib.dataMask.email(str:String<required>);
    console.log('手机号',jsUtilLib.dataMask.mobile('13019219923')); // 手机号 130****9923
    console.log('座机',jsUtilLib.dataMask.telephone('010-51662227')); // 座机 ****2227
    console.log('身份证号',jsUtilLib.dataMask.idCardNum('130184188202121212'));//身份证号 ************1212
    console.log('银行卡号',jsUtilLib.dataMask.bankCardNum('6217002260009086123'));// 银行卡号 621700**********6123
    console.log('中文名',jsUtilLib.dataMask.chineseName('李啊地方'));// 中文名 李*方
    console.log('邮箱',jsUtilLib.dataMask.email('[email protected]'));// 邮箱 a**@qq.com

4.jsUtilLib.image


jsUtilLib.image.base64

  • jsUtilLib.image.base64(url:String<required>,callback:Function<required>,quality:Float||Number);
// 获取图片base64
jsUtilLib.image.base64('../../img/demo.jpg',function(error,data){
    if (error) {
        console.log(error);
    } else {
        console.log(data);
    }
},1);

jsUtilLib.image.size

  • jsUtilLib.image.size(url:String<required>,callback:Function<required>);
// 获取图片宽高
jsUtilLib.image.size('../../img/demo.jpg',function(error,data){
    if (error) {
        console.log(error);
    } else {
        console.log(data);
    }
},1);

4.jsUtilLib.guid


jsUtilLib.guid.get

console.log('guid:',jsUtilLib.guid.get()); // guid: a91a7228-da1b-4026-af47-232c0dcd9a2a

5. jsUtilLib.device


jsUtilLib.device.os

  • 获取当前系统信息
  • 返回值:ios|android|windowphone|windows|macos|''
console.log('系统信息',jsUtilLib.device.os()); //系统信息 windows

jsUtilLib.device.type

  • 获取当前设备类型(移动端和pc端)
  • 返回值:mobile|pc|''
console.log('pc还是移动端',jsUtilLib.device.type());//pc还是移动端 pc