npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bound-sensor

v1.1.0

Published

BoundSensor is a JavaScript library to be notified if a DOM boundary changes in browser.

Downloads

190

Readme

Bound Sensor

bound-sensor is a super lightweight JavaScript library to help you to make better applications.
This library is very useful if you want to refresh the content of a container once its boundary's size (width & height) changes.

Breaking Changes

This package on NPM used to be for Angular, now they've been separated. If you want to install this lib for Angular you may find it here as angular-bound-sensor.

Usage

import { BoundSensor, BoundSensorEvent } from 'bound-sensor';

/**
 * Our event name, you may name it anything and we
 * will receive it by the same name
 */
const eventName = 'resize';

// Creates a new copy of bound-sensor
const sensor = new BoundSensor({
  // Name of event, this is a CustomEvent
  eventName,
  /**
   * If you don't want bound-sensor manipulate the host styles
   * you can set this to false and then you must add two propertes
   * to host element:
   * 1. `position` to `relative`
   * 2. `display` to `block`, `table` or `inline-block`
   */
  modifyStyles: true,
  /**
   * This value is amount of time in miliseconds to debounce the event
   * This is quiet useful if you don't wanna receive too many events
   * specially on resize windows or so...
   * Here we'll be notified every seconds after last event
   */
  debounceTime: 1000,
});

// Let's get the element that we want to attache the sensor to
const holder = window.document.getElementById('holder');

/**
 * Let's receive the resize event sent by bound-sensor by adding an
 * event listeneer to our host element
 */
holder.addEventListener(eventName, function (event: BoundSensorEvent) {
  // Here we receive the resize details from event
  // This will log: { width: x, height: x, host: `<div id="holder">` }
  console.log(event.detail);
});

// Now we attach the sensor
sensor.attachSensor(holder);

// Let's detach the sensor after 10 seconds
// We must detach the sensor to avoid memory leaks
window.setTimeout(function () {
  sensor.detachSensor();
}, 10000);

// That's it!

Example

You can checkout a demo here.