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

hu-tool

v1.2.40

Published

good game tools, means final tool

Downloads

57

Readme

Codecov npm bundle size (minified + gzip) GitHub Commitizen friendly

hu-tool is a public code tool library. It will contain some tool modules that are used daily.

Installing

Using NPM

To install the stable version:

$ npm install hu-tool --save

Using unpkg CDN

<script src="https://unpkg.com/[email protected]/lib/hu-tool.js"></script>

Example

TypeCheck

import { TypeCheck } from 'hu-tool'

TypeCheck.isUndef(null) //true
TypeCheck.isUndef(undefined) //true
TypeCheck.isDef(123) //true
TypeCheck.isDef(null) //false
TypeCheck.isObject(null) //false
TypeCheck.isObject({}) //true
TypeCheck.isTrue(1) //false
TypeCheck.isTrue(true) //true
TypeCheck.isFalse(false) //true
TypeCheck.isFalse(0) //false
TypeCheck.isPlainObject({ a: 123 }) //true
TypeCheck.isPlainObject([123, 'ac']) //false
TypeCheck.isRegExp(/abc/gi) //true
TypeCheck.isFuncton(function() {}) //true
TypeCheck.isArray([123, 'ac']) //true
TypeCheck.isNumber(Math.pow(2, 64)) //true
TypeCheck.isNumber(Math.pow(2, 726627262726272626)) //false, overflow
TypeCheck.isPrimitive(123) //true
TypeCheck.isPrimitive('Hello World') //true
TypeCheck.isEmptyObj({}) //true

from is-type-of

API

TypeCheck.array(arr)
TypeCheck.boolean(bool)
TypeCheck.null(null)
TypeCheck.nullOrUndefined(null)
TypeCheck.number(num)
TypeCheck.string(str)
TypeCheck.symbol(sym)
TypeCheck.undefined(undef)
TypeCheck.regExp(reg)
TypeCheck.object(obj)
TypeCheck.date(date)
TypeCheck.error(err)
TypeCheck.function(fn)
TypeCheck.primitive(prim)
TypeCheck.buffer(buf)
TypeCheck.stream(stream)
TypeCheck.readableStream(readable)
TypeCheck.writableStream(writable)
TypeCheck.duplexStream(duplex)
TypeCheck.class(obj)
TypeCheck.finite(num)
TypeCheck.NaN(NaN)
TypeCheck.generator(gen)
TypeCheck.generatorFunction(fn)
TypeCheck.promTypeChecke(fn)
TypeCheck.int(int)
TypeCheck.double(double)
TypeCheck.int32(int)
TypeCheck.long(long)
TypeCheck.Long(Long)

Phone

import { Phone } from 'hu-tool'

Phone.isMobile(13800138000) //true
Phone.isMobile('13800138000') //true
Phone.isMobile('075526069999') //flase
Phone.getPurePhone('13800138000123') //13800138000
Phone.getPurePhone('1380a0138000123c') //13800138000
Phone.beautifyPhone('13800138000') //138 0013 8000
Phone.beautifyPhone('ab1380abc1384') //138 0138 4
Phone.mosaic('13800138000') //138****8000
Phone.mosaic('ab1380abc1384') //138****4
Phone.mosaic('13800138000', '-') //138----8000
Phone.mosaic('13800138000', '-', 4, 7) //1380---8000

URL

import { URL } from 'hu-tool'

const testUrl =
  'http://user:[email protected]:8080/p/a/t/h/2737087.html?mobile=1&mdebug=1&_test=1#haha=init&lh=1'
URL(testUrl).port //'8080'
URL(testUrl).protocol //'http'
URL(testUrl).getQueryParam('mobile') //'1'
URL(testUrl).getUrlParam('_test') //'1'
URL(testUrl).getUrlParam('test') //undefined
URL(testUrl).getHashParam('haha') //'init'
URL(testUrl).format() //Same as testUrl
URL(testUrl, {
  port: '443',
  protocol: 'https'
}).format() //https://user:[email protected]:443/p/a/t/h/2737087.html?mobile=1&mdebug=1&_test=1#haha=init&lh=1

URL(testUrl).format({
  port: '443',
  protocol: 'https'
}) //https://user:[email protected]:443/p/a/t/h/2737087.html?mobile=1&mdebug=1&_test=1#haha=init&lh=1
URL(testUrl).removeProtocal() // //user:[email protected]:8080/p/a/t/h/2737087.html?mobile=1&mdebug=1&_test=1#haha=init&lh=1

UA

import { UA } from 'hu-tool'

const androidUA =
  'Mozilla/5.0 (Linux; Android 8.0.0; G8142 Build/47.1.A.12.270) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Mobile Safari/537.36'
UA(androidUA).isAndroid //true
UA(androidUA).isIOS //false

const wechatUA =
  'Mozilla/5.0 (Linux; Android 8.1.0; PAHM00 Build/OPM1.171019.026; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/62.0.3202.84 Mobile Safari/537.36 MicroMessenger/6.7.3.1360(0x26070336) NetType/WIFI Language/zh_CN Process/appbrand2'
UA(wechatUA).isWeixin //true
UA(wechatUA).isAndroid //true
UA(wechatUA).isIOS //false

const IE6UA = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)'
UA(IE6UA).browser.ie //6
UA(IE6UA).engine.trident //2
UA(IE6UA).system.win //xp

UA().userAgent //Show the userAgent&system of your browser now

UA().isMiniProgram

Testing&Coverage

npm run test

Development

npm run start

Because it is a tool library, it is important to ensure the integrity of the test case. You need to write your test cases while perfecting your code.

Ajax

Using Axios, click here

Time&Date

Using Moment, click here.It's about 200 K, about 50K after gzipped, and the node is used casually. But if feels big in broswer, please use dayjs.

Cookie

Using js-cookie, click here.

localStorage

Using localforage, click here. But the default use of Web SQL in PC, if you need localStorage, modify the driver.

Event

Using events, click here.

License

MIT Copyright (c) 2018-present, ManfredHu