🎯 Lightweight JavaScript utility library crafted for modern developers
📖 Documentation • 中文 • Quick Start • Features
🎯 Say Goodbye to Boilerplate - 200+ curated functions solving 90% of daily development needs ⚡ Ready to Use - Zero config, works in any JavaScript environment 🧩 Import on Demand - Tree-shaking friendly, bundle only what you use 🛡️ Type Safe - Full TypeScript support with intelligent IDE hints 🔄 Auto Cleanup - Smart memory management, no more memory leaks
# Install
npm install lazy-js-utilsimport {
insertElement,
useEventListener,
useMutationObserver,
} from 'lazy-js-utils'
// 🎯 One-liner event listener with auto cleanup
const stopListening = useEventListener('#button', 'click', () => {
console.log('Button clicked!')
})
// 🔍 Monitor DOM changes without refs
useMutationObserver('#container', (mutations) => {
console.log('Container content changed:', mutations)
})
// ➕ Simple element manipulation
insertElement('#container', '<div>New content</div>')// Traditional way 😵
const container = document.querySelector('#container')
const newElement = document.createElement('div')
newElement.innerHTML = 'Hello World'
container?.appendChild(newElement)
// Lazy JS Utils way 😎
insertElement('#container', '<div>Hello World</div>')// Auto-cleanup event listeners
const stop = useEventListener(window, 'resize', () => {
console.log('Window resized')
})
// Automatically calls stop() on page unload, no manual cleanup needed!// High-performance animation frame control
useRaf(
(timestamp) => {
// Animation that runs once per second
updateAnimation(timestamp)
},
{
delta: 1000,
autoStop: true, // Auto-stop after one execution
},
)| Module | Features | Examples |
|---|---|---|
| 🎯 DOM | Element manipulation, selectors | insertElement, removeElement |
| 🎮 Events | Event listeners, auto cleanup | useEventListener, useMutationObserver |
| 🎬 Animation | Animation frames, easing functions | useRaf, useInterval |
| 🔧 Utils | Utility functions, type checking | deepCompare, throttle, debounce |
| 📝 String | String processing | camelCase, kebabCase |
| 🔢 Math | Mathematical calculations | clamp, random |
| 🎤 Speech | Voice analysis, TTS | analyzeUserVoice, VoiceAnalyzer |
// 📱 Responsive design
useEventListener(
window,
'resize',
throttle(() => {
// Throttled window resize handling
updateLayout()
}, 300),
)
// 🖼️ Image lazy loading
useMutationObserver('.image-container', (mutations) => {
mutations.forEach((mutation) => {
// Auto-handle newly added image elements
lazyLoadImages(mutation.addedNodes)
})
})
// 🎪 Dynamic forms
insertElement(
'.form-container',
createFormField({
type: 'input',
placeholder: 'Enter content',
}),
)
// 🎤 Voice analysis
const { result, controller } = await analyzeUserVoice({
duration: 5000,
onProgress: progress => console.log(`Progress: ${progress * 100}%`),
})| Scenario | Vanilla JS | Lazy JS Utils | Performance Gain |
|---|---|---|---|
| Event cleanup | Manual management | Auto cleanup | ⚡ 100% |
| DOM operations | 10+ lines of code | 1 line of code | 🚀 90% |
| Memory usage | Prone to leaks | Smart management | 💾 80% |
![]() |
![]() |
![]() |
![]() |
|---|---|---|---|
| Chrome ✅ | Firefox ✅ | Safari ✅ | Edge ✅ |
One of the unique features of Lazy JS Utils is the built-in voice analysis capabilities:
import { VoiceAnalyzer, analyzeUserVoice } from 'lazy-js-utils'
// Quick voice analysis
const { result, controller } = await analyzeUserVoice({
duration: 5000,
onProgress: progress => console.log(`Recording: ${progress * 100}%`),
onVolumeChange: volume => updateVolumeIndicator(volume),
})
// Get analysis results
const analysis = await result
if (analysis) {
console.log('Voice characteristics:', analysis.characteristics)
console.log('TTS suggestions:', analysis.suggestions)
}
// Advanced usage with custom analyzer
const analyzer = new VoiceAnalyzer()
analyzer.setAnalysisConfig({
minFundamentalFreq: 70,
maxFundamentalFreq: 900,
enableVoiceClassification: true,
})We welcome contributions of all kinds!
- 🐛 Report Bug
- 💡 Request Feature
- 📖 Improve Documentation
- ⭐ Star the project
MIT © 2024 Simon He
Built with ❤️ by Simon He



