Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

cq_tool

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cq_tool

一些方便实用的函数封装,持续更新

latest
npmnpm
Version
1.0.0
Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source
image-20230625195528765

描述

一些个人简单的函数方法,包含防抖,节流,深拷贝等

使用方法

<script src="./cq_tool.js">
cq.debounce(Fn,time)
</script>

方法

节流

throttle(Fn,time)

用于高频事件,如鼠标移动,页面滚动,高频点击等场景

el.addEventListen('scroll',()=>{
	cq.throttle(Fn,1000)
})

防抖

debounce(Fn,time)

用于输入框请求关键字等场景

el.addEventListen('keyUp',()=>{
	cq.debounce(Fn,1000)
})

对象深拷贝

deepclone(obj)

let obj={
	arr:[1,2,3],
	obj:{
		a:1
	}	
}
let dClone=cq.deepclone(obj)
dClone.arr.push(4)
dCLone.obj.a=2
console.log(obj)//=>{arr:[1,2,3],obj:{a:1}}
console.log(dClone)//=>{arr:[1,2,3,4],obj:{a:2}}

数组剔除某值

deleteObjFalse(obj,types)

用于去除对象中无效值的属性,允许自定义(不支持属性值为复杂数据类型)

types默认为null,false," "

let obj={
	a:false,b:null,c:'',d:0,f:123
	e:{a:null}
}
console.log(cq.deleteObjFalse(obj,false,null,123))
//=>{c:'',d:0,e:{a:null}}

数组剔除重复

arrUni(arr)

用于剔除数组中重复的值

let arr=[1,2,3,1,2]
console.log(cq.arrUni(arr))//=>[3]

字符翻转

stReversal(st)

let str='abc'
console.log(cq.stReversal(sty))//cba

Keywords

deepclone

FAQs

Package last updated on 25 Jun 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts