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 🙏

© 2025 – Pkg Stats / Ryan Hefner

cutil

v1.1.22

Published

the most useful utils for javascript

Readme

cutil

cutil是一款无任何依赖,非常实用的工具包,涵盖完美多继承,时间格式化,类型判断,表单验证,本地存储等常用的web开发工具方法 使用es6编写,支持浏览器打包调用,包含完整的单元测试

目前共13个工具,包括

  • is 准确的类型判断方法
  • multiExtend 完美多继承,完美支持Function Class,ES6 Class
  • formCheck 表单验证方法,简单实用
  • date 时间格式化方法,支持时间戳,字符串等多种形式调用
  • wxAsync 微信小程序API的Promise封装
  • storage 基于现代浏览器的storage工具类
  • commonCss 基于现代浏览器的实用css工具类,包含scss
  • easing 共30种不同的缓动方法
  • emitter 一个实用的订阅者类
  • parseUrl url格式化工具
  • session 基于axios的js爬虫工具
  • unit 价格单位转换工具
  • hooks 基于vue-composition-api的hooks

快速启动

  • 安装 npm install cutil
  • 引入 import {is,multiExtend,formCheck} from "cutil"
  • 使用 is([]) === Array

使用说明

  • is(target any) 返回目标对象的类型(js内置对象) 返回值为[undefined,null,NaN,Function,Object,Array,String,Number,Boolean,Date,JSON]中的一种

      is({}) === Object
  • multiExtend([baseClassArr] Array) 返回多个基础类型的组合类 完美支持Function Class,ES6 Class,constructor,super,instanceOf

      let Target = class extends multiExtend([Base1, Base2]) {
      	constructor(para) {
      		super(para)
      	}
      }
  • formCheck(target Object,option Object) 传入目标对象和检查配置,通过则返回true,不通过则返回错误提示 目前内置了["empty","phone","email"]三种规则 !!option和target键值对顺序必须一一对应

      let target = {
      	userName: "用户名",
      	password: "123456",
      	tel: 111111,
      	email: "[email protected]"
      }
      let result = formCheck(target, {
      	"用户名":"empty",
      	"密码":"empty",
      	"手机号码":["empty","phone"],
      	"电子邮箱":["empty","email"]
      })
      //检查通过
      result === true
      //检查不通过
      result === "手机号码不合法"
  • date(Class)

    • now(format String) 返回当前时间,format不传则默认为"YYYY-MM-DD hh:mm:ss",传入则自动格式化

        date.now("YYYY-MM") === "2019-08"
      		
    • format(option Object) option必传,根据option配置返回格式化后的时间 option = { value: 1565416462326 || "2019-08-10 12:05:01" 需格式化的时间(只能为时间戳或YYYY-MM-DD hh:mm:ss字符串) input: "timeStamp" || "dateTime" 传入的时间格式 output: "timeStamp" || "dateTime" || "YYYY-MM-DD hh" 需要输出的时间格式 }

        date.format({
        	value:1565416595,
        	input:"timeStamp",
        	output:"YYYY-MM-DD hh时"
        }) === "2019-08-10 13时"
      		
  • wxAsync(Class) 返回微信小程序wx对象的Promise封装(cutil会检查全局对象中的wx对象,仅在微信小程序环境下可用)

      //选择图片
      async function(){
      	await $wxAsync.chooseImage({
      		count: 1
      	}).then(res => {
      		if (res.errMsg === "chooseImage:ok") {
      			console.log(res.tempFilePaths[0])
      		}
      	})
      }
  • storage(Class)

    • set type("localStorage" || "sessionStorage") 设置使用的本地存储类型 默认为"localStorage"

    • set timeOut(Number) 设置本地存储类型的过期时间,单位为分钟 默认为20

    • set baseKey(String) 设置本地存储键值的前缀 默认为""

    • getStorage(key String) 获取本地数据存储,过期或不存在则为null

        storage.getStorage("test_key") === "test_value" || null
      		
    • setStorage(key String,value any,minute Number) 设置本地存储键,值及过期时间

        storage.setStorage("test_key","test_value",5)
    • removeStorage(key String) 移除本地存储

        storage.removeStorage("test_key")
  • emitter(Class)

    • on(eventName, callback) 订阅事件

        let fun = data=>{
        	console.log("test emit")
        }
        emitter.on("test",fun)
      	
    • off(eventName, callback) 取消订阅事件

        emitter.off("test", fun)
    • emit(eventName, data) 发布订阅事件

        emitter.emit("test", "我是参数")
    • once(eventName,callback) 只订阅一次

        emitter.once("test",data=>{
        	console.log("test emit")
        })
        emitter.emit("test", "我是参数")
        //执行一次后就取消订阅
        emitter.emit("test", "我是参数")
    • isSubed(eventName,callback) 该事件是否被订阅

        emitter.isSubed("test", fun)
  • parseUrl(url)

    格式化url

      	let query = parseUrl(url)
  • session(Class)

    • setSession(option:AxiosOptions) 发送axios请求并记录cookies

    • request(option:AxiosOptions) 使用setSession记录的cookie发送axios请求

  • unit(Object)

    • toCent(yuan, fixed=0) 输入元,返回分,默认保留0位小数

    • toYuan(cent, fixed=2) 输入分,返回元,默认保留2位小数