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

wei-util

v1.4.19

Published

This is a particularly handy library of tools

Downloads

60

Readme

wei-util

a good library of tools

Installation

install wei-util:

npm install wei-util --save

Usage

使用方法介绍

1.  findValue(arr,sameValue,key,value) 查找对象,参数
/**
 * 查找符合项的值
 * @param arr 传进来的数组
 * @param sameValue 与之匹配的值
 * @param key 改值得指针,深层对象指针例子'a.b.c'
 * @param value 找的值,深层a.b.c,不传返回匹配的对象
 * @returns 返回值
 */
2.  findIndex(arr,sameValue,key)

 * 查找index,防止指针只想过程报错
 * @param arr 数组
 * @param sameValue 与之匹配的值
 * @param key 改值得指针,深层对象指针例子'a.b.c'
 * @returns 返回下标,找不到返回-1
3.  getValue(data,keyString,defaultValue)
/**
 * 取值(防止指针指向过程中报错问题)
 * @param data 对象
 * @param keyString 指向key值可为['a','b','c']或'a.b.c'
 * @param defaultValue 默认值(可选),不传时返回空字符串
 * @returns 返回值
 */
 4.  toFixed(value,toFixed)
 /**
 * 保留小数位
 * @param value 值
 * @param toFixed 保留几位小数,默认两位
 * @returns
 */
 5. findFilter(arr,sameValue,key)
 /**
 * 查找过滤项
 * @param arr  数组
 * @param sameValue 相同值
 * @param key key:a.b.c
 * @returns 返回相匹配的项 -1找不到
 */
 6. deepClone(data,openRecursion)
 /**
 * 深克隆
 * @param data 深克隆的数据
 * @param openRecursion 是否打开递归克隆,取决于数据的复杂程度,是否有Function,默认为不打开
 */
 7. dfs(arr,node,callBack)
 /**
 * 深度优先遍历
 * @param arr 数组节点
 * @param node 深度遍历节点的key值
 * @param callBack 函数返回值(item)=>{},item深度遍历的item项
 */
 8. bfs(arr,node,callBack)
 /**
 * 广度优先遍历
 * @param arr 数组节点
 * @param node 深度遍历节点的key值
 * @param callBack 函数返回值(item)=>{},item深度遍历的item项
 */
 9. isEmpty(data: any)
 /**
 * 判断是否为空
 * @param data 数据
 * @returns 布尔值
 */
 10. throttle(func: Function, delay: number)
 /**
 * 节流函数
 * @param func 节流的函数
 * @param delay 节流时间
 * @returns 返回一个函数
 */
 11. debounce(func: Function, delay: number)
 /**
 * 防抖函数
 * @param func 防抖函数 
 * @param delay 防抖时间延迟
 * @returns 返回一个函数
 */
 12. carousel(selector: string, direction: string, interval: number = 4000, wholePage: boolean = false, page?: number)
 * 滚动轮播
 * @param selector css选择器
 * @param direction 轮播滚动方向 left , top
 * @param interval 滚动一个单位间隔时间
 * @param wholePage 是否是轮播整页的
 * @param page 每页dom个数,整夜轮播时必传
 */
 13. sfs(arr: any[], node: string, callBack: Function)
 /**
 * 单个下查,查完一项再继续查另一项
 * @param arr 数组节点
 * @param node 深度遍历节点的key值
 * @param callBack 函数返回值(item)=>{},item深度遍历的item项
 */
14. installArrayFunctions 
/** 注意安装数组方法要在工程的最先开始的地方执行,react要在引入App.jsx之前执行该方法,因为react是js文件和vue不一样的是少了一层解析步骤,react可以建一个js文件,在js文件引入该方法执行,然后在main.js中引入该文件,建议在头部引入
 * 执行安装数组方法 sameValue key与上边方法一直,key值新增功能数组下标 例子 'a.b[0].c[0][1]'
 * 安装一些数组方法 例如 Array().deleteItem(sameValue,key) 删除某一项  
 * Array().findValue(sameValue:string,key:string,value?:string) 
 * Array().findFilter(sameValue:string,key:string) 
 * Array().findIndex(sameValue:string,key:string) 
 * Array().sfs(node:string,item=>{}:Function) 
 * Array().dfs(node:string,item=>{}:Function) 
 * Array().bfs(node:string,item=>{}:Function) 
 */
 15. getDate(option,format,data)
 /**
 * 获取日期
 * @param option 默认{
 * year: 0, 当前年份 负值往前,正值往后
 * month: 0, 当前月份 负值往前,正值往后
 * day: 0,当前天号 负值往前,正值往后
 * timeType: '',默认不传则为当前时间 时间类型 可为start 00:00:00开始 end 23:59:59结束
 * monthType: '', 时间类型 可为start 月初开始 end 月末结束
 * setYear: 0, 设置年份  优先级 setYear > year 优先级在前设置的会覆盖优先级在后的
 * setMonth: 0, 设置月份  优先级 monthType > setMonth > month 优先级在前设置的会覆盖优先级在后的
 * setDate: 0 设置日期 优先级 setDate > day 优先级在前设置的会覆盖优先级在后的
 *}
 * @param format 日期格式 默认为 yyyy-MM-dd HH:mm:ss
 * @param data 日期数据 默认为传该值时option中只有timeType生效
 * @returns 返回值日期时间字符串
 */
 16 deleteRepeat(arr: any[], allOrValueSame?: string | true)
 /**
 * 数组去重 
 * @param {any[]}  arr 需要去重的数组 
 * @param {string | true} allOrValueSame string值同之前的key boolean时没项是否全部相同
 * @returns 返回去重之后的数组
 */
 17 replaceObjKey(obj: any, oldKey: string, newKey: string, retainKey: boolean = false)
 /**
 * 替换key值  
 * @param {Object} obj 对象
 * @param {string} oldKey 新key
 * @param {string} newKey 旧key
 * @param {boolean} retainKey 是否保留原来的key默认为false
 */
 18  autoCarousel(selector: string, direction: string, interval: number = 4000, domNum: number = 1)
 /**
 * 改进版轮播方法
 * @param selector css选择器
 * @param direction 轮播滚动方向 left , top
 * @param interval 滚动一次间隔时间
 * @param domNum 每次滚动dom数
 * @returns 返回 {dom,offset,timer} 滚动容器的dom,滚动容器孩子的偏移量,定时器变量
 */

Rules