1.0.1 • Published 7 years ago

rectangle-state v1.0.1

Weekly downloads
6
License
MIT
Repository
github
Last release
7 years ago

rectangle-state

npm version

Generate a state meaning a rectangle as a plane object

Installation

npm install rectangle-state

Usage

const { createRectangleState, toXYWidthHeight } = require('rectangle-state');

console.log(
  createRectangleState({ top: 1, right: 12, bottom: 2, left: 11 })
);  // -> { top: 1, right: 12, bottom: 2, left: 11 }

console.log(
  createRectangleState({ x: 11, y: 1, width: 1, height: 1 })
);  // -> { top: 1, right: 12, bottom: 2, left: 11 }

console.log(
  toXYWidthHeight(
    createRectangleState({ top: 1, right: 12, bottom: 2, left: 11 })
  )
);  // -> { x: 11, y: 1, width: 1, height: 1 }

// Error - The `x` is mixed.
//createRectangleState({ top: 1, right: 12, bottom: 2, left: 11, x: 1 });

// Error - The `top` is greater than the `bottom`.
//createRectangleState({ top: 100, right: 12, bottom: 2, left: 11 });