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

@learning-ui/utils

v1.5.11

Published

[TOC]

Readme

[TOC]

安装

npm i @learning-ui/utils --save

详情

  1. ObjectUtils.isEqual() || ArrayUtils.isEqual() 判断数据是否相等
  2. uuid 生成对应位数的uuid
  3. text 用于获取文字的高度和宽度
  4. uploadFileMd5 多个文件上传前获取每个文件的md5 值
  5. scrollHandel 滚动到最下方激活事件
  6. ArrayUtils.arrayMove() 根据数组下标移动到对应的位置
  7. eventManager 事件总线
  8. download 下载
  9. ArrayUtils.unique() 数组去重
  10. formDeepClone 深度拷贝数据
  11. formatTime 将时间戳转换为 年月日时分秒
ObjectUtils.isEqual() || ArrayUtils.isEqual()
import { ObjectUtils } from "@learning-ui/utils";

// a 和 b 可以使任意类型
console.log(ObjectUtils.isEqual(a , b) , ArrayUtils.isEqual(a, b));
uuid(number)
import { uuid } from "@learning-ui/utils";

console.log(uuid(16)); //3faa399e94e27fc1

import { text } from "@learning-ui/utils";

const App = () => {

const divRef = React.useRef(null);

console.log( text({ fontSize: "12px", text: "错误啊啊啊啊啊", ref: divRef.current || undefined, }) ); // {width: 84, height: 17}

return (

</div>

); };


##### uploadFileMd5({	files,  onprogress? , chunkSize?   })

> files 文件集合
>
> onprogress:  加密进度 (current, total, filesLength, currentLength , totalProgress) => {}
>
> ​	current: 当前分割文件的进度
>
> ​     total: 当前分割文件的总数
>
> ​     filesLength: 需要分割文件的个数
>
> ​    currentLength: 正在分割第几个文件
>
> ​    totalProgress: 每个文件的分割进度 
>
> chunkSize?: 分割大小 默认 1024 * 1024

------

```javascript
import { uploadFileMd5 } from "@learning-ui/utils";

const App = () => {
  return (
    <div>
      <input type='file' multiple onChange={(e) => { 
          if(e.target.files && e.target.files.length > 0){
            uploadFileMd5({
              files: e.target.files as unknown as File[],
              onprogress: (current: number, total: number, filesLength: number, currentLength: number , totalProgress: any) => {
                console.log(current , total , filesLength,currentLength , totalProgress);
              },
              chunkSize: 1024 * 1024, // byte
            }).then(res => {
              console.log(res); // MD5
            })
          }
      }} />
    </div>
  );
};
scrollHandel(e: UIEvent , () => void)

import { scrollHandel } from "@learning-ui/utils"

const App = () => {

  return (
    <div style={{ height: "400px", overflow: "auto" }} onScrollCapture={(e) => {
        scrollHandel(e , () => {
            console.log(e , 'e')
        })
    }}>
        <div style={{height: "1200px"}}>
            <div>123</div>
            <div>123</div>
        </div>
    </div>
  );
};
ArrayUtils.arrayMove(array , from , to)

import { ArrayUtils } from "@learning-ui/utils"


let arr = [ 1 , 2 , 3, 4, 5];
ArrayUtils.arrayMove(arr , 2 , 4) //[1, 2, 4, 5, 3]
ArrayUtils.unique(arr , key?:)

import { ArrayUtils } from "@learning-ui/utils"

let arr = [ 1 , 2 , 3, 4, 5 , 4 , 5];
ArrayUtils.unique(arr) //[1, 2, 3, 4, 5]

let arr = [ {name: "a"} , {name: "b"} ,{name: "a"}];
ArrayUtils.unique(arr) //[{name: "a"} , {name: "b"}]
download

import { download } from "@learning-ui/utils"

download({ 
  url,  // 地址
  method='GET', 
  name, // 名称
  progress,  // 下载进度
  onClose  // 通过 xhr.abort() 关闭下载 // (xhr) => {}
})
formatTime(time , keys)

import {formatTime} from "@learning-ui/utils"
formatTime(1635754317815, ["/", ":"]); // "2021/11/01 16:11:57"

事件总线

eventManager

import { eventManager } from "@learning-ui/utils";

eventManager.on("click" , (content) => {
      console.log(content); // Math.random()
}) // 注册 click 事件

eventManager.once("utils" , (content) => {
      console.log(content); // Math.random()
}) // 注册 utils 单次 事件

eventManager.emit("click" , Math.random()); // 激活事件
eventManager.emitOnce("utils" , Math.random()); // 只激活一次 utils 事件


eventManager.off("utils" , () => {}); // 移除 utils 事件
eventManager.off("click" , eventManager.events["click"][0]); // 移除 总事件中click 事件 第一个事件


eventManager.back("click"); // 回退为上一次 click 事件 (废弃)