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

cmsl

v1.2.1

Published

collection of common methods

Readme

这是一个常用方法的集合

数据类型

getDataType(target):获取数据类型

  • 返回值{string} Null、Undefined、String、Array、Object、FormData...
  • target{any}(必填)

matchDataType(target,type):精准匹配数据类型

  • 返回值{boolean} true/false
  • target{any}(必填)
  • type{string}(必填) 可选值 Null、Undefined、String、Array、Object、FormData...

filterDataType(params):过滤指定数据类型,如[]、{}、""(包括去空格)、null、undefined

  • 返回值{boolean} true/false
  • params{any}

filterObject(object):过滤对象中的[]、{}、""(包括去空格)、null、undefined

  • 返回值{object}
  • object{object}(必填) 必须是object对象

getTargetVal({target[, key, value]}):返回目标对象或目标对象的key值

  • 返回值{string}
  • target{any}(必填)
  • key{string}(选填) target的key,当target为对象时填写
  • value{string}(选填) 默认值 null,经过filterParams过滤后,如果目标对象(或key)不存在或不符合要求,返回的值为value

getTargetConst(constant, value, key):返回常量集合中的key值

  • 返回值{string} 返回constant中的key值
  • constant{array}(必填) 目标常量集合,成员对象中必须含有value,格式:[{value:"",label:""},...]
  • value{string}(必填) 匹配constant中的value值
  • key{string}(必填) 匹配constant中的key值

digitalFormat(type, number, other):计算2位(包括2位)以内的小数,主要用于金额的准确率(避免出现0.1+0.2,0.8*3误差)

  • 返回值{number}
  • type{string}(必填) 可选值 '+'、'-'、'*'、'/'
  • number{string,number}(必填)
  • other{string,number}(必填) 当type为'/'是,不建议值为0,如果为0,默认返回0

digitalToThousandth(params):数字格式化为千分位,默认保留2位小数

  • 返回值{string} 不传,默认返回""
  • params{string,number}(选填)

日期时间

dateTimeFormat({ts[,type,flag,isTime]}) 日期格式化

  • 默认值 yy-mm-dd hh:mm:ss
  • ts{number} 时间戳(必传)
  • flag{string}(选填) 日期的拼接格式 默认值 '-'
  • isTime{boolean}(选填) 返回值是否包括时间 默认值 true
  • type{string}(选填) 返回的日期格式(yy-mm-dd) 可选值 'YMD'、'YM'、'MD'

dateFormatConversion(dateTime[,isTime]) 日期格式转换(兼容Safari和IE)

  • 返回值{number} 时间戳
  • dateTime{string}(必传) 标准时间,格式为:yy-mm-dd 或 yy.mm.dd 或 yy/mm/dd
  • isTime{boolean}(选填) 返回的时间戳是否包含具体时间,默认值 true

DOM操作

trim(str[,type]) 去除(all:所有,between:两边,left:左边,right:右边)空格

  • 返回值{number} 时间戳
  • str{string}(必传)
  • type{string}(选填) 可选值 'all','between','left','right',默认值 'all'

closeCurrentPage() 关闭当前页面