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

zsg-utils

v2.0.1

Published

JavaScript 函数库、工具类

Downloads

41

Readme

zsg-utils

npm version npm downloads gzip size: JS npm license

JavaScript 函数库、工具类

Installing

npm install zsg-utils

Using nodejs

const zsgUtils = require('zsg-utils')

Get on unpkg and cdnjs

<script src="https://unpkg.com/zsg-utils"></script>
<script>
    console.log(ZsgUtils)
</script>  

Import all methods

import zsgUtils from 'zsg-utils'

zsgUtils.getYMDHMS(1646726753253))
// {"year": 2022,"month": "03","date": "08","hours": 16,"minute": "05","second": 53}

'zsg-utils' API

基本方法

getObjType(obj) 检测数据类型-内部使用Object.prototype.toString.call()

import zsgUtils from 'zsg-utils'
zsgUtils.getObjType() // 'undefined'
zsgUtils.getObjType(true) // 'boolean'
zsgUtils.getObjType(1) // 'number'
zsgUtils.getObjType('abc') // 'string'
zsgUtils.getObjType(function () {}) // 'function'
zsgUtils.getObjType([]) // 'array'
zsgUtils.getObjType(new Date()) // 'date'
zsgUtils.getObjType(/^/) // 'regExp'
zsgUtils.getObjType(undefined)) // 'undefined'
zsgUtils.getObjType(null)) //'null'
zsgUtils.getObjType({}) // 'object'
zsgUtils.getObjType(Symbol(1)) // 'symbol'

Date日期方法

getYMDHMS(val) 时间戳转换为年月日时分秒

import zsgUtils from 'zsg-utils'
zsgUtils.getYMDHMS(1646726753253)) // {"year": 2022,"month": "03","date": "08","hours": 16,"minute": "05","second": 53}

Array数组方法

isRepeat(val) 通过哈希判断数组中是否有重复元素

import zsgUtils from 'zsg-utils'
zsgUtils.isRepeat([1,2,3,4,5]) // false
zsgUtils.isRepeat([1,2,1]) // true

url地址栏方法

getQueryVariable(val) 获取url地址栏参数

import zsgUtils from 'zsg-utils'
zsgUtils.getQueryVariable('id') // 地址栏有id就返回具体的值,没有就返回false

正则校验

checkStr(val,type)

  • type目前有以下几种值 phone | card | email | number | english | chinese | lower | upper, 不传、传的不是以上几种参数返回true
import zsgUtils from 'zsg-utils'

zsgUtils.checkStr() // true
zsgUtils.checkStr(1) // true 只穿一个参数返回true
zsgUtils.checkStr(1, 2) // true type类型传的不是以上几种也返回true

// 手机号校验
zsgUtils.checkStr(1311, 'phone') // false
zsgUtils.checkStr(13573218888, 'phone') // true
// 身份证校验15 or 18
zsgUtils.checkStr(1311, 'card') // false
zsgUtils.checkStr(123456789012345, 'card') // true
zsgUtils.checkStr(123456789012345678, 'card') // true
// 英文校验
zsgUtils.checkStr('测试英文', 'english') // false
zsgUtils.checkStr('123', 'english') // false
zsgUtils.checkStr('abcdefg', 'english') // true
// 中文校验
zsgUtils.checkStr('abcdefg', 'chinese') // false
zsgUtils.checkStr(123, 'chinese') // false
zsgUtils.checkStr('测试中文', 'chinese') // true
// 小写字母校验
zsgUtils.checkStr('123', 'lower') // false
zsgUtils.checkStr('abcABC', 'lower') // false
zsgUtils.checkStr('abcdefg', 'lower') // true
// 大写字母校验
zsgUtils.checkStr('123', 'upper') // false
zsgUtils.checkStr('abcABC', 'upper') // false
zsgUtils.checkStr('ABCDEFG', 'upper') // true

本地存储方法

getStore(name) 获取LocalStorage

 let name = zsgUtils.getStore('name')

setStore(name,content) 设置LocalStorage

zsgUtils.setStore('name','zsg')

removeStore(name) 删除LocalStorage

zsgUtils.removeStore('name')

License

MIT © 2022-present, zhaoshiguang, [email protected]