
Security News
CVE Volume Surges Past 48,000 in 2025 as WordPress Plugin Ecosystem Drives Growth
CVE disclosures hit a record 48,185 in 2025, driven largely by vulnerabilities in third-party WordPress plugins.
@alekstar79/media-tracker
Advanced tools
A lightweight, high-performance TypeScript library for tracking media queries and responsive breakpoints in modern web applications.
![]()
Check out the live demo: Media Tracker Demo
The demo shows real-time breakpoint tracking with toast notifications and demonstrates all library features in action.
media-tracker/
├── src/
│ ├── lib/ # Library core
│ │ ├── constants.ts # Breakpoint constants
│ │ ├── media-tracker.ts # Main MediaTracker class
│ │ └── index.ts # Library entry point
│ ├── demo/ # Demo application
│ │ ├── emitter.ts # Event emitter (demo only)
│ │ ├── notifications.ts # Toast notifications
│ │ ├── media-handler.ts # Demo media handler
│ │ └── index.ts # Demo entry point
│ ├── styles/
│ │ └── style.css # Demo styles
│ └── index.html # Demo HTML
├── dist/ # Demo build output
├── dist-lib/ # Library build output
└── docs/ # Generated documentation
Library Installation:
yarn install @alekstar79/media-traker
Development Setup:
git clone git@github.com:alekstar79/media-tracker.git
cd media-tracker
yarn install
import { MediaTracker, W768, W1024, W1200 } from 'media-tracker';
const tracker = MediaTracker.create(
[W768, W1024, W1200],
(state) => {
console.log('Current media state:', state);
if (state.width === W768) {
// Mobile layout
} else if (state.width === W1024) {
// Tablet layout
} else if (state.width === W1200) {
// Desktop layout
}
},
150 // Optional debounce time (ms)
)
const { MediaTracker, W768, W1024 } = require('media-tracker')
const tracker = MediaTracker.create([W768, W1024], (state) => {
console.log('Media state changed:', state)
})
<script src="https://unpkg.com/media-tracker/dist-lib/media-tracker.umd.js"></script>
<script>
const tracker = MediaTracker.create(
[MediaTracker.W768, MediaTracker.W1024],
function(state) {
console.log('Breakpoint:', state)
}
)
</script>
import {
W0, // 0px - 📱 Base mobile
W240, // 240px - 📱 Very small mobile
W320, // 320px - 📱 Small mobile
W480, // 480px - 📱 Mobile landscape
W640, // 640px - 📟 Small tablets
W768, // 768px - 📟 Tablets
W991, // 991px - 🖥️ Small desktops
W1024, // 1024px - 🖥️ Desktop screens
W1200, // 1200px - 🖥️ Large desktop
W1280, // 1280px - 🖥️ HD desktop
W1728, // 1728px - 🖥️ Large HD
W1920, // 1920px - 🖥️ Full HD
W1980, // 1980px - 🖥️ Large Full HD
W3840, // 3840px - 📺 4K Ultra HD
W4096 // 4096px - 📺 Maximum
} from 'media-tracker'
🚀 Start development server:
yarn dev
Starts Vite development server at http://localhost:3000
📦 Build for production:
yarn build # 🏗️ Build demo application
yarn build:lib # 📦 Build library for distribution
👀 Preview production build:
yarn preview
📚 Generate documentation:
yarn docs
MediaTracker Options
| Option | Type | Default | Description |
|---|---|---|---|
widths | number[] | Required | Array of breakpoint widths to track |
handler | (state: MediaState) => void | Required | Callback function for media changes |
debounceTime | number | 100 | Debounce time in milliseconds for resize events |
MediaState Object
interface MediaState {
width?: number; // Current viewport width (when exact match)
maxWidth?: number; // Next larger breakpoint
minWidth?: number; // Next smaller breakpoint
}
⚡ Static Methods
MediaTracker.create(widths, handler, debounceTime?)
Creates and initializes a new MediaTracker instance
Parameters:
Returns: MediaTracker instance
🔧 Instance Methods
setWidths(widths)
setHandler(handler)
onTrack()
nearestWidths()
// ✅ Good: Minimal breakpoints
MediaTracker.create([W768, W1024, W1200], handler)
// ✅ Better: Increased debounce for heavy operations
MediaTracker.create(breakpoints, heavyHandler, 250)
Check imports:
// ✅ Correct
import { MediaTracker, W768 } from 'media-tracker'
// ❌ Incorrect
import MediaTracker from 'media-tracker'
Verify breakpoints:
// ✅ Breakpoints must be sorted and unique
MediaTracker.create([768, 1024, 1200], handler) // ✓ Works
MediaTracker.create([1200, 768], handler) // ✓ Auto-sorted
MediaTracker.create([], handler) // ❌ Throws error
Check handler:
// ✅ Handler must be a function
MediaTracker.create(breakpoints, console.log) // ✓ Works
MediaTracker.create(breakpoints, (state) => {/*...*/}) // ✓ Works
MediaTracker.create(breakpoints, 'not a function') // ❌ Throws error
Handler not called on initial load:
Resize events too frequent:
Breakpoints not matching:
<meta name="viewport" content="width=device-width, initial-scale=1.0">| Browser | Version | Support |
|---|---|---|
| 🟢 Chrome | 41+ | ✅ Full |
| 🟢 Firefox | 47+ | ✅ Full |
| 🟢 Safari | 10.1+ | ✅ Full |
| 🟢 Edge | 16+ | ✅ Full |
| 🟢 iOS Safari | 10.3+ | ✅ Full |
| 🟢 Android Browser | 56+ | ✅ Full |
Required APIs:
For older browsers, include these polyfills:
<!-- matchMedia polyfill -->
<script src="https://cdn.polyfill.io/v3/polyfill.min.js?features=MatchMedia"></script>
FAQs
Processing media queries via browser API from JavaScript
The npm package @alekstar79/media-tracker receives a total of 1 weekly downloads. As such, @alekstar79/media-tracker popularity was classified as not popular.
We found that @alekstar79/media-tracker demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Security News
CVE disclosures hit a record 48,185 in 2025, driven largely by vulnerabilities in third-party WordPress plugins.

Security News
Socket CEO Feross Aboukhadijeh joins Insecure Agents to discuss CVE remediation and why supply chain attacks require a different security approach.

Security News
Tailwind Labs laid off 75% of its engineering team after revenue dropped 80%, as LLMs redirect traffic away from documentation where developers discover paid products.