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

js-expand-tool

v0.4.6

Published

javascript 工具函数包

Readme

js-expand-tool

js拓展工具库

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

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

安装使用

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

浏览器:

<script src="./node_modules/js-expand-tool/dist/index.js"></script>
<!-- <script src="./dist/index.js"></script> -->
<script>
	let pwd = jst.mask('password:123456789',4);
	console.log('pwd:',pwd) // pwd: **************6789
</script>

npm:

$ npm i js-expand-tool

yarn:

$ yarn add js-expand-tool

cnpm:

$ cnpm i js-expand-tool

React、VueJS,小程序等javascript环境

// 完整引入
import jst from 'js-expand-tool'
let pwd = jst.mask('password:123456789',4);
console.log('pwd:',pwd) // pwd: **************6789

推荐使用方法

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

import { mask } from 'js-expand-tool'
let pwd = mask('password:123456789',4);
console.log('pwd:',pwd) // pwd: **************6789

:package: API文档

Object

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

Array

  • uniqueBy 根据属性去重数组。
  • unique 普通数组去重。
  • flat 数组完全展开
  • range 创建一个长度length,值从start开始递增的数组,每次递增step
  • repeat 重复数组

Date

  • formatTime 格式化时间。
  • formatHMS 将秒数转为 xx小时xx分钟xx秒 例如1h0m10s。

Function

  • throttle 函数节流(首次执行)。

String

  • mask 使用 * 遮蔽字符串。
  • camelCaseToUnderLine 驼峰写法转下划线写法
  • underlineToCamelCase 下划线写法转驼峰写法

Number

  • randomNum 返回指定范围内的随机整数。
  • round 将数字四舍五入到指定的小数位数。
  • sum 返回两个或两个以上数字/数字数组中元素之和。
  • sumBy 根据函数映射每个元素,然后返回数组的和。
  • toDecimalMark 将数字转化为千分位格式。

TypeOf

  • $isNull 判断类型Null
  • $isUndefined 判断类型Undefined
  • $isBoolean 判断类型Boolean
  • $isNumber 判断类型Number
  • $isString 判断类型String
  • $isSymbol 判断类型Symbol
  • $isObject 判断类型Object
  • $isRegExp 判断类型RegExp
  • $isArray 判断类型Array
  • $isFunction 判断类型Function

url

  • Url 根据对象 拼接参数
  • URLSearchParams url 序列化和反序列化

prototype

  • match_all 扩展 String的原型方法 es2019的matchAll(未兼容浏览器)