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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@strive_molu/utils

v0.0.5

Published

前端常用工具函数

Downloads

8

Readme

molu-utils

前端常用公共工具函数

安装

npm install @strive_molu/utils --save

方法

debounce

解释


防抖函数:高频触发一个事件只执行最后一次(在immediate为ture执行第一次)。

形参

| 名称 | 说明 | 类型 | 默认值 | | --------- | ---------------------------------------------------------- | -------- | ------ | | fn | 执行目标函数 | Function | 无 | | delay | 目标函数延迟多久执行,单位 ms | number | 200 | | immediate | 是否立即执行目标函数,当为true时,目标函数会优先执行第一次 | boolean | false |

throttle

解释


节流函数:高频执行事件在每delay秒内执行一次。

形参

同上debounce的形参。

deepCopy

解释

深拷贝函数。兼容拷贝属性的描述符;属性值为DateRegExp的对象;处理对象中有循环引用的情况。

形参

| 名称 | 说明 | 类型 | 默认值 | | ------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | -------------------------------- | | target | 需要拷贝的目标对象 | any | 无 | | cacheOptions | 处理循环引用配置;cache:缓存类型为对象的属性值,replace:目标对象中有循环引用的属性值的替代符。 | { cache?: WeakMap<Object, CacheOptions['replace']>; replace?: any } | {cache:new WeakMap,replace:null} |

animationNum

解释

js中数字动画函数。可以获取在规定时间内从初始值到目标值中的每一帧的值。

形参

| 名称 | 说明 | 类型 | 默认值 | | -------- | ----------------------------------- | ------------------ | ------ | | from | 起始值 | number | 无 | | to | 目标值 | number | 无 | | callback | 获取当前帧值的回调函数 | (curValue) => void | 无 | | duration | 从起始值到目标值经历的时间,单位 ms | number | 1000 |

parallelTask

解释

并发执行异步任务。

形参

| 名称 | 说明 | 类型 | 默认值 | | ------------- | ------------------------------------------------------------ | ------------------ | ------ | | tasks | 异步任务集合,每一个任务必须是一个函数,其函数返回一个promise对象。 | Array<()=>Promise> | 无 | | parallelCount | 并发数 | number | 2 |

返回值

返回一个promise对象。该对象的状态为fulfilled时返回的值为一个数组,数组的值的类型如下。

type TaskResData = {
    type: 'success' | "fail"; //异步任务完成状态
    data: any;  //异步任务状态改变的返回值
}

FileChunks

解释

可以对文件进行分块,获取文件的唯一hash值的一个类。

实例属性

| 名称 | 说明 | 类型 | | ------ | ---------------- | ----------- | | chunks | 文件的分块信息, | Array | | hash | 文件的唯一hash值 | string |

静态方法

readChunkFile

读取Blob类型或File类型对象的具体内容

形参

| 名称 | 说明 | 类型 | 默认值 | | ---- | -------------- | --------------------------------------- | ------ | | blob | 需要读取的对象 | Blob | File | 无 | | type | 读取内容的格式 | 'buffer' | 'text' | 'url' | "binary" | buffer |