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

@endgame/eva

v1.0.8-alpha.0

Published

Ease Viewport Access

Downloads

99

Readme

EVA

EVA: Easy Viewport Access

Installation

yarn add @endgame/eva
# or
npm i -S @endgame/eva

The initialization

Vanilla js users

// Import the constructor
import { Eva } from '@endgame/eva';

// Ask EVA to help you 👌
const eva = new Eva();

/**
 * EVA will be at your disposal everywhere at:
 * 👉 window.$endgame.eva
 */
window.$endgame = {
  eva,
};

Framework usage (example: Nuxt)

// Import the constructor
import { Eva } from '@endgame/eva';

/**
 * If you're using Nuxt I recommend you
 * to do that in a plugin 🚀
 */
... global-plugin.client.js
const initializeEndgame = (_context, inject) => {
  inject('endgame', {
    eva: new Eva(),
  });
};
...

... YourComponent.vue
mounted() {
  /**
   * EVA will be at your disposal at:
   * 👉 this.$endgame.eva
   */
}
...

The methods

The initialize method

With this method you'll:

👉 Initialize the window's resize event listener.

👉 Prepare EVA to be able to give you info on the viewport.

🥚 Vanilla

window.$endgame.eva.initialize();

🍳 Nuxt

... YourComponent.vue

beforeMount() {
  // 🚀 For Nuxt: preferably in layout/default.vue
  this.$endgame.eva.initialize();
},

...

The destroy method

The destroy method will remove all watchers and the resize event listener. Everything will be ready for garbage collection 👌

🥚 Vanilla

window.$endgame.eva.destroy();

🍳 Vue.js

... YourComponent.vue

beforeDestroy(){
  this.$endgame.eva.destroy();
},

...

Access and watch viewport data

For purposes of listening to window's width, height changes, breakpoints updates, etc. you only need one method: watch.

/**
 * width, height, outerWidth and outerHeight are built-in watchers.
 * With them you'll be able to listen to the window's resized values.
 */

// 🥚 Vanilla EVA access
const { eva } = window.$endgame;

// 🍳 Vue EVA access
// const { eva } = this.$endgame;

// Access the declared window reactive data
// SEE: @endgame/calvin
console.log(eva.viewport.data.width);
console.log(eva.viewport.data.height);
console.log(eva.viewport.data.outerWidth);
console.log(eva.viewport.data.outerHeight);

// Get notified any time the window's data are updated
eva.viewport.watch({
  width: (val) => {
    console.log(`window inner width: ${val}`);
  },
  height: (val) => {
    console.log(`window inner height: ${val}`);
  },
  outerWidth: (val) => {
    console.log(`window outer width: ${val}`);
  },
  outerHeight: (val) => {
    console.log(`window outer height: ${val}`);
  },
});