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

montjs-fe

v1.0.1

Published

js/ts常用工具包

Downloads

4

Readme

js-util-plus

一.介绍

用typescript写的常用工具类,由于不同项目中会使用到相关的方法,所以将这些方法统一规整到一个包中,源码已分享(源码中包含部分单元测试),大家可以查看或者提需求。

二.如何使用

yarn add js-util-plus / npm install js-util-plus --dev

import * as util from 'js-util-plus';

三.API

1.string

1.1 strCheck 验证

util.strCheck(str:string, type: StrEnum) => boolean

enum StrEnum {
  PHONE = 'phone', //校验手机号
  TEL = 'tel',     //检验电话
  CARD = 'card',   //检验身份证 
  PWD = 'pwd',      // 密码以字母开头,长度在6~18之间,只能包含字母、数字和下划线 
  POSTAL = 'postal',  // 邮政编码
  QQ = 'qq',   // QQ号
  EMAIL = 'email',  // 邮箱
  MONEY = 'money',  // 金额(小数点2位)
  URL = 'URL',  // 网址
  IP = 'IP',  // IP
  DATE = 'date', // 日期时间
  NUMBER ='number', // 数字
  ENGLISH = 'english', // 英文
  CHINESE = 'chinese',  // 中文
  LOWER= 'lower',   // 小写
  UPPER = 'upper',  // 大写
  HTML = 'HTML' // HTML标记
}

// example
util.strCheck('18268100000', 'phone') => true

1.2去除字符串空格

util.trim(str: string, type: number) => str

type 1-所有空格  2-前后空格  3-前空格 4-后空格(默认type为1)

1.3根据内容超过指定长度显示...

util.sliceContent(cont: string, len: number = 8)

1.4 手机号脱敏

util.phoneDes(phone: string )

1.5 身份证号码脱敏

util.identifynumberDes(phone: string )

1.2 strTransformName 两个字名字中间加空格

util.strTransformName(name: string) => cname
// example
util.strTransformName('王五') => '王 五'

2.object

2.1 objIsNull 对象判空

util.objIsNull(obj: object) => boolean

// example
const obj = {} 
util.objIsNull(obj) => false  // 传参不需要判空,代码里已判空

3.array

3.1 arrIsNull 数组判空

util.arrIsNull(arr: any[]) => boolean

// example
const arr = [] 
util.arrIsNull(arr) => false  // 传参不需要判空,代码里已判空

4.store

4.1 storeCookieSet 设置某个cookie

util.storeCookieSet(str: string, value: string) => void

// example
util.storeCookieSet('token', 'token')

4.2 storeCookieGet 获得coookie中某个值

util.storeCookieGet(str: string) => string

// example
document.cookie="token=token";
util.storeCookieGet('token') => 'token'

4.3 storeCookieDelete 删除单条cookie

util.storeCookieDelete(str: string) => void 

4.4 storeCookieRemove 删除所有cookie

util.storeCookieRemove() => void

4.5 storeLocalStorageSet 设置localStorage 已经JSON.stringify

util.storeLocalStorageSet(name: string, value: any) => void

4.6 storeLocalStorageGet 获取localStorage 已经JSON.parse

util.storeLocalStorageGet(str: string) => any 

5.uri

5.1 uriGetParam 获取uri上的某个参数

util.uriGetParam(str: string) => string

// example
www.xxx.com?a=1&b=2
util.uriGetParam('a') => '1'

6.浏览器

6.1 browserGetType 获取浏览器类型

util.browserGetType() => string

// example
util.browserGetType() => 'Opera' || 'IE' || 'Edge' || 'Firefox' || 'Safari' || 'Chrome' || 'OverIE10'

6.1 browserIsNew 是否是现代浏览器(IE11及以上)

util.browserIsNew() => boolean

// example
// 如果是IE11及以上,返回true
util.browserIsNew() => true 

stringUtils

timeUtils

1.timeAgo返回多久之前,参数要求number

2.getNowTime 获取当前时间并格式化,返回参数格式yyyy-MM-dd HH:mm:ss

3.formatTime自定义时间,参数date,type(返回时间格式类型)可以类型YYYY_MM_DD,YYYY_MM_DD_HAN,YYYY_MM_DD_HH_MM_SSYYYY_MM_DD_HH_MM_SS_HAN,默认返回YYYY_MM_DD_HH_MM_SS