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 🙏

© 2026 – Pkg Stats / Ryan Hefner

toolcore

v1.0.1

Published

js 常用前端代码工具库

Readme

toolcore

常用前端代码工具库(不定时更新)

目的:高效率完成前端业务代码

业务开发过程中,会经常用到String,Number,Array,Object,Function,Date扩展方法浏览器类型判断base64表单验证url常用方法等常用函数,为避免不同项目多次复制粘贴的麻烦,这里统一封装,并发布到npm,以提高开发效率。如果你也有常用的代码,欢迎为本项目提交pr.

安装使用

  1. 直接下载dist目录下的toolcore.min.js使用,支持UMD,CommonJS,ES6各模块化规范。
  2. 使用npm/yarn/cnpm安装,支持CommonJS,ES6各模块化规范。

浏览器:

<script src="https://unpkg.com/toolcore"></script>
<!-- <script src="./dist/toolcore.min.js"></script> -->
<script>
	let max = toolcore.maxNum([12,3,31,5,3]) 
	console.log(max) // => "31"
</script>

npm

$ npm i toolcore

yarn

$ yarn add toolcore

cnpm

$ cnpm i toolcore

React、VueJS,小程序等javascript环境

// 完整引入
import toolcore from 'toolcore'
let txt = toolcore.mask('12398765432',3,7) 
console.log(txt) // => "123****5432"

推荐使用方法

你真的不需要完整引入所有函数,所以只引入需要使用的方法即可。

import { mask } from 'toolcore'
let txt = mask('12398765432',3,7) 
console.log(txt) // => "123****5432"

:package: API文档

TypeOf

  • isNull 判断类型Null。
  • isUndefined 判断类型Undefined。
  • isBoolean 判断类型Boolean。
  • isNumber 判断类型Number。
  • isString 判断类型String。
  • isSymbol 判断类型Symbol。
  • isObject 判断类型Object。
  • isRegExp 判断类型RegExp。
  • isArray 判断类型Array。
  • isFunction 判断类型Function。
  • getType 获取类型,全能型的typeOf。
  • inBrowser 判断是否为浏览器。

base64

  • encode base64加密。
  • decode base64解密。

Date

  • timejs 格式化时间。
  • formatHMS 将秒数转为 xx小时xx分钟xx秒 例如1h0m10s。
  • unix 获取时间戳 (秒)

EventEmitter

  • on 为指定事件注册一个监听器。
  • once 为指定事件注册一个单次监听器。
  • emit 触发指定事件的监听器。
  • off 移除指定事件的监听器。
  • allOff 移除所有事件的所有监听器,如果指定事件,则移除指定事件的所有监听器。

Array

  • uniqueBy 根据属性去重数组。
  • unique 普通数组去重。
  • maxNumBy 找出数组中该属性最大值的一列。
  • minNumBy 找出数组中该属性最小值的一列。
  • maxNum 数组中的最大值。
  • mixNum 数组中的最小值。
  • shuffle 将数组打乱
  • equal 判断两个数组是否相等

Function

  • debounceStart 函数防抖 (立即执行版)。
  • debounceEnd 函数防抖 (非立即执行版)。
  • debounce 函数防抖 (完全版)。
  • throttle 函数节流。

Number

  • randomNum 返回指定范围内的随机整数。
  • round 将数字四舍五入到指定的小数位数。
  • sum 返回两个或两个以上数字/数字数组中元素之和。
  • sumBy 根据函数映射每个元素,然后返回数组的和。
  • toDecimalMark 将数字转化为千分位格式,可以在数字前面加上符号。
  • accAdd 加法运算,可浮点安全运算。
  • accSub 减法运算,可浮点安全运算。
  • accMul 乘法运算,可浮点安全运算。
  • accDiv 除法运算,可浮点安全运算。
  • getrandom 产生n个随机数,并且随机数之和是固定值

Object

  • deepClone 深度克隆。
  • orderBy 返回按属性(props)和顺序(orders)排序的对象数组,用于数据排序。
  • findPathByLeafId 根据 key 递归查找链带关系。
  • merge 对象合并。

String

  • mask 根据位置,使用 * 遮蔽字符串。
  • maskLeft 从位置左边开始,使用 * 遮蔽字符串。
  • maskRight 从位置右边开始,使用 * 遮蔽字符串。
  • randomHexColorCode 生成一个随机的十六进制颜色代码。
  • getCounts 返回元素出现的次数。
  • uuid 全局唯一标识符 UUID
  • guid GUID:128位的数字标识符

url

  • insertUrl 根据对象中的参数匹配插入到url中。
  • URLSearchParams url 序列化和反序列化。
  • Url 返回网址的相关信息,模拟了 浏览器的 new URL(urlString) 部分功能