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-plus-dc

v1.0.0

Published

js/ts常用工具包

Downloads

1

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',     
  POSTAL = 'postal',
  QQ = 'qq', 
  EMAIL = 'email',
  MONEY = 'money',
  URL = 'URL',
  IP = 'IP',
  DATE = 'date',
  NUMBER ='number',
  ENGLISH = 'english',
  CHINESE = 'chinese',
  LOWER= 'lower',
  UPPER = 'upper',
  HTML = 'HTML'
}

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

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