Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

region

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

region

A helper to work with rectangular regions in the DOM

  • 2.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6.6K
decreased by-10.41%
Maintainers
1
Weekly downloads
 
Created
Source

region

A helper to work with rectangular regions in the DOM

Install

$ npm install region --save

Usage

var Region = require('region')

var region = Region({
    top: 10,
    left: 10,
    width: 50,
    height: 60
})

region.getRight() == 60
region.getBottom() == 70

API

Instantiation

You can create a new Region by calling the function returned by require('region'). You can call it as a constructor if you want.

var Region = require('region')

new Region({
    top: 10,
    left: 10
    //either width,height
    //or right, bottom
    width: 10,
    height: 10
})

or

var Region = require('region')
var r = Region({
    top: 10,
    left: 10,
    right: 20,
    bottom: 20
})

You can instantiate a Region from a DOM node, using Region.fromDOM (NOTE: uses dom.offsetWidth/Height/Left/Top for getting coordinates)

var r = Region.fromDOM(document.body)

Getters

  • get - returns an object with {top, left, bottom, right}
  • getWidth
  • getHeight
  • getLeft
  • getTop
  • getRight
  • getBottom
  • getPosition - returns an object with {left, top}
  • getSize - returns an object with {width, height}

containsPoint(x,y) or containsPoint({x,y}) : Boolean

var r = Region({
    top: 10,
    left: 10,
    width: 10,
    height: 10
})

r.containsPoint(15, 10) == true
r.containsPoint({x: 10, y: 10}) == true

equals(r): Boolean

Returns true if this region equals the region (or the object) given as the first param var r = Region({top: 10, left: 10, bottom: 20, right: 20 })

r.equals({top: 10, left: 10, bottom: 20, right: 20 }) == true

equalsPosition({top, left}): Boolean

Returns true if this region has top, left equal to the given coordinates

equalsSize({width, height}): Boolean

Returns true if this region has the same size as the given region or object

var coords = { top: 10, left: 10, width: 100, height: 100 }
var r = Region(coords)
r.equalsSize(coords) == true
r.equalsSize(r.clone()) == true

getIntersection(Region): Region/false

Returns the region resulted by intersecting this region with the given region. If no intersection, returns false

clone: Region

Returns a new region instance with the same coordinates

var r = new Region({left: 10, right: 10, width: 10, height: 20})
r.clone().equals(r)

Tests

$ make

Watch mode

$ make test-w

License

MIT

Keywords

FAQs

Package last updated on 06 Feb 2015

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc