Skip to content

Latest commit

 

History

History
85 lines (68 loc) · 2.81 KB

README_en.md

File metadata and controls

85 lines (68 loc) · 2.81 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<HTMLElement> 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 {
  insertElement,
  useEventListener,
  useMutationObserver,
  useRaf,
} from 'lazy-js-utils'

// To listen for container changes, you don't need const container = ref<HTMLElement>
useMutationObserver('#container', (mutationsList, observer) => {
  console.log(mutationsList)
})
// requestAnimationFrame
useRaf(
  (timestamp) => {
    // Executed only when at least 1s has passed between frames
    console.log('animationFrame', timestamp)
  },
  {
    delta: 1000,
    autoStop: 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 Repository

Welcome to PR