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

viewport-funcs

v0.3.1

Published

A very limited subset of viewport functions I use every day

Downloads

30

Readme

viewport-funcs

A very limited subset of viewport functions I use every day

Install

npm i viewport-funcs

Package on npm

API

contains(el, [offset], [check])

Check if el is in the viewport, return a boolean

| Argument | Action | | :------ | :------- | | el | the tested Html Element el | | offset | optional offset, default to 0 | | check | optional check, default to false. If true performs multiple tests explained below |

If check is true, safer but slower tests are performed

  • check if el is a Html Element, with nodeType 1 and landed in the document.body
  • check if el has no size. An empty or a display:none div or an img with no src will always return false
const contains = require('viewport-funcs/contains')

var el = document.querySelector('.rect')

// true if the element is fully or partially in the viewport
contains(el)

margins()

Get the viewport size and margins

left, top, right and bottom are relative to each side of the document

The object returned contains:

| Key | Value | | :------ | :------- | | width | the viewport width | | height | the viewport height | | left | the margin-left, distance between the left of the document and the left of the viewport | | top | the margin-top, distance between the top of the document and the top of the viewport | | right | the margin-right, distance between the right of the document and the right of the viewport | | bottom | the margin-bottom, distance between the bottom of the document and the bottom of the viewport |

The example below shows:

  • how to get the viewport bottom-right corner location
  • how to get the document width and height
const margins = require('viewport-funcs/margins')

// {width: 591, height: 328, left: 0, top: 56, right: 0, bottom: 316}
var data = margins()

/*
the viewport bottom-right corner location
{x: 591, y: 384}
*/
var br = {x: data.left + data.width, y: data.top + data.height}

/*
the document width and height
{width: 591, height: 700}
*/
var doc = {
   width: data.left + data.width  + data.right,
  height: data.top  + data.height + data.bottom
}

The returned object is internally cached to boost performance


rect()

Get the viewport size and position

left, top, right and bottom are relative to the top-left of the document

The object returned contains:

| Key | Value | | :------ | :------- | | width | the viewport width | | height | the viewport height | | left | the distance between the left of the document and the left of the viewport | | top | the distance between the top of the document and the top of the viewport | | right | the distance between the left of the document and the right of the viewport | | bottom | the distance between the top of the document and the bottom of the viewport |

This means:

  • right = left + width
  • bottom = top + height

The returned object is internally cached to boost performance

const rect = require('viewport-funcs/rect')

// {width: 800, height: 600, left: 10, top: 10, right: 810, bottom: 610}
rect()

Thanks

Mainly forked / inspired on

Performance and tips from

License

MIT