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

hansen-tool

v0.4.8

Published

web的一些工具集函数,包括(树形菜单转换、本地存储、文件下载、文件大小单位转换、金额格式化、浏览器判断)等

Readme

hansen-tool

实用的工具集-tool,web的一些工具集函数,包括(树形菜单转换、本地存储、文件下载、文件大小单位转换、金额格式化、浏览器判断)等,一款来在工具库的爱!

简介

特色,我们开发中一些实用的工具函数,分为二种打包模式esModule,global模式

安装下载

  • 下载地址 https://github.com/Hansen520/hansen-tool/releases
  • npm地址 npm i hansen-tool
  • CDN https://unpkg.com/hansen-tool

使用方法

esModule

import {randomRgbColor, Storage} from 'hansen-tool';
randomRgbColor();
Storage.setStorage(key: string, value: string)

global ,可以直接调用cdn方式进行调用

<script src="http://unpkg.com/hansen-tool"></script>
hansenTool.randomRgbColor();
hansenTool.Storage.setStorage(key: string, value: string)

相关函数的介绍

具体参数请参考每个函数的typescript文件

| getBetweenYearsArr | 根据开始年和结束年获取之间的所有日期(包含开始和结束) | | -------------------------- | :----------------------------------------------------------- | | detectDeviceType | 设备的判断,判断是移动端还是PC端的用户,利用header头部的userAgent | | checkBrowser | 判断浏览器内核 | | convertFileSize | 精准将文件大小从一个单位转换为另一个单位 | | formatFileSize | 模糊匹配格式化文件大小,将字节转换为 KB、MB、GB 或 TB | | colorRgbaToHex | rgba的颜色值转为Hex颜色值 | | colorHexToRgb | rgba的颜色值转为Hex颜色值 | | colorHexToRgba | rgba的颜色值转为Hex颜色值 | | fileDownload | 通过文件地址下载文件 | | fileDownloadByType | 强制修改稿响应头下载文件 | | fileDownloadByRes | 通过后端流文件形式接口下载文件 | | formatPrice | 金额逗号分隔 | | convertCurrency | 将金额转为为繁体字 | | getExt | 获取文件的后缀名 | | hasDuplicates | 判断数组内是否有元素重复,如果有返回true,没有返回false | | phoneEncryption | 手机号码*加密函数 | | randomRgbColor | 获取rgb随机颜色值 | | randomString | 获取随机字符串 | | scrollToTop | 滑滚动页面到顶部 | | scrollToBottom | 滚动到页面底部 | | sleepFn | 对某一个函数延迟执行, 异步 | | sleep | 直接延迟睡眠,异步 | | findParentNodeArray | 根据递归树形菜单和目标值,获取从根节点到目标节点的路径 | | treeToList | 树形菜单转为铺平为数组,并为每个节点添加层级和父节点信息 | | listToTree | 数组转为树形菜单 | | findNodeInTree | 精准查找想要的某节点字段的信息,并返回该节点 | | findNodeInTreeByCondition | 根据条件,精准找到想要的某节点字段的信息,并返回该节点,这个功能和findNodeInTree差不多 | | findNodesInTreeByCondition | 根据条件,查找所有满足条件的节点,并返回一个集合 | | Storage.setStorage | 设置本地存储,设置为string类型或者为转换后的的JSON | | Storage.getStorage | 获取本地存储 | | Storage.updateStorage | 更新本地存储,如果是字符串直接更新,如果是对象,则合并 | | Storage.removeStorage | 移除某个本地存储 | | Storage.clearStorage | 清空本地存储 |

快速使用

简单的接入文档

交流 & 提问

  • 提问: https://github.com/Hansen520/hansen-tool/issues

关于作者

  • 个人主页
  • 编码不易,还望支持哦! 感觉还可以的话在github点个赞噢