Skip to content

Latest commit

 

History

History
83 lines (66 loc) · 2.78 KB

README_en.md

File metadata and controls

83 lines (66 loc) · 2.78 KB

lazy-js-utils

NPM version NPM version NPM version

🖥 Docs

English | 简体中文

At present, I have sorted out about 200 commonly used functions, and I am still updating..., and your recognition is the biggest encouragement to me ♥️

💯 Highlights

  • Pure JS utility functions, Can be used in any environment where JS can be executed
  • Greatly reduced the use of ref<HTMLElment> and onMounted, which can be called directly from the script tag
  • All side effect functions can return a stop function, which can stop the execution of the event anywhere, and automatically destroy the event when the page is destroyed
  • API design is simple, practical and type-friendly

✋ Example

import {
  animationFrameWrapper,
  insertElement,
  useEventListener,
  useMutationObserver,
} from 'lazy-js-utils'

// To listen for container changes, you don't need const container <HTMLElement>= ref
useMutationObserver('#container', (mutationsList, observer) => {
  console.log(mutationsList)
})
// requestAnimationFrame
animationFrameWrapper(
  (timestamp) => {
    // Each needle is executed 1s apart
    console.log('animationFrame', timestamp)
  },
  1000,
  true /* It is destroyed after only one execution */,
)
// Register for events
useEventListener('#container', 'click', () => {
  console.log('click')
})
// Insert an element
insertElement('#container', '.content')
// Delete an element
removeElement('.content')
<div id="container"></div>
<div class="content">hello world</div>

📖 Instructions for use

npm i lazy-js-utils // Installation

import {
  deepCompare
 } from 'lazy-js-utils' // Ingestion on demand

Buy me a cup of coffee

GitHub 地址

Welcome to PR