rectangle-state

1.0.1 • Public • Published

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 });

Readme

Keywords

Package Sidebar

Install

npm i rectangle-state

Weekly Downloads

0

Version

1.0.1

License

MIT

Last publish

Collaborators

  • kjirou