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

dime

v3.0.0

Published

cross-browser module to measure dimensions

Downloads

10

Readme

dime is an ultra-fast open-source cross-browser micro-library for calculating dimensions, using pure native JavaScript methods.

API

Methods

dime.deviceW()   // get device width
dime.deviceH()   // get device height
dime.deviceMax() // get Math.max(dime.deviceW, dime.deviceH)
dime.deviceMin() // get Math.min(dime.deviceW, dime.deviceH)
dime.viewportW() // get viewport width
dime.viewportH() // get viewport height
dime.documentW() // get document width
dime.documentH() // get document height
dime.overflowX() // get # of horizontal pixels that doc overflows viewport (or 0 if no overflow)
dime.overflowY() // get # of vertical pixels that doc overflows viewport (or 0 if no overflow)
dime.scrollX()   // cross-broswer equiv to native window.scrollX
dime.scrollY()   // cross-broswer equiv to native window.scrollY

dime.is(method, min [, max]) // boolean for testing ranges
dime.is('viewportW', 800) // equiv to (dime.viewportW() >= 800)
dime.is('deviceH', 480, 960) // equiv to (dime.deviceH() >= 480 && dime.deviceH() <= 960)
// ... works for any of the methods listed above

dime(elem) // wrapper for element-based methods (accepts native DOM elements, document, or window)
dime(elem).rectangle() // cross-browser getBoundingClientRect: .top/.bottom/.left/.right/.width/.height
dime(elem).offset() // coordinates relative to the document: .top/.bottom/.left/.right/.width/.height
dime(elem).get(index) // applicable when dime is paired w/ a query engine (index -1 gets the last elem)
dime(elem).element() // if elem (index 0) is a DOM element, get it. Otherwise get the documentElement.

Extending

Devs can add a query engine such as qwery to provide the ability to query selector strings like dime('#example')


dime.setQueryEngine()       // set query engine to $
dime.setQueryEngine(qwery)  // set query engine to qwery
dime.setQueryEngine(jQuery) // set query engine to jQuery

Instances

If you need to check whether an unknown object is an instance of dime() you can use either of these techniques:


ukn instanceof dime // true if ukn is an instance of dime()
ukn && ukn.dime     // true if ukn is an instance of dime()

The result of calling the dime() function is an array-like object. It has a length property representing the number of elems. If you haven't added a query engine, then the length will be 1 and that element will be stored in index 0, unless you pass it something invalid then the length property will be 0 and index 0 will be false. If you've added an engine, the length will be the number of selected elements.

var elem, dimeElem;
elem = document.getElementById("example");
dimeElem = dime(elem);
!!dimeElem.length;      // true if #example exists
1 === dimeElem.length;  // true if #example exists
elem === dimeElem[0];   // true if #example exists (otherwise false)
true === dimeElem.dime; // true if it exists *or* if it doesn't

Projects

Much of dime is also built into Response 0.3+

License

dime is available under the MIT license

Copyright (C) 2012 by Ryan Van Etten

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.