npm.io
4.2.1 • Published 3 years ago

simon-js-tool

Licence
MIT
Version
4.2.1
Deps
5
Size
179 kB
Vulns
0
Weekly
0
Stars
81
DeprecatedThis package is deprecated

simon-js-tool

NPM version NPM version NPM version

文档

English | 简体中文

目前整理了100+的常用函数,还在持续更新中...,你的认可是对我最大的鼓励

亮点

  • 纯js的工具函数,可使用在任何可执行js的环境
  • 大量减少ref<HTMLElment>onMounted的使用,可以script标签直接调用
  • 所有的副作用函数都能返回一个stop函数,可以在任意地方停止事件的执行,并且在页面销毁时自动销毁事件
  • api设计简单、实用、类型友好

例子

import { animationFrameWrapper, insertElement, useEventListener, useMutationObserver } from 'simon-js-tool'
// 监听container的变化, 你不在需要const container = ref<HTMLElement>
useMutationObserver('#container', (mutationsList, observer) => {
  console.log(mutationsList)
})
// requestAnimationFrame
animationFrameWrapper((timestamp) => {
  // 每针相隔1s执行
  console.log('animationFrame', timestamp)
}, 1000, true /* 只执行一次后被销毁 */)
// 注册事件
useEventListener('#container', 'click', () => {
  console.log('click')
})
// 插入元素
insertElement('#container', '.content')
// 删除元素
removeElement('.content')
<div id="container"></div>
<div class="content">hello world</div>

更多

使用说明

npm i simon-js-tool # 安装

import { 
  deepCompare
 } from 'simon-js-tool' # 按需引入

文档

请我喝一杯咖啡

License

MIT

GitHub地址

欢迎PR

Keywords