# center-it

> `CenterIt` calculates width, height, ratio and offset when you want to center one rectangle into another, with designated center type (cover or contain)

Latest version **1.1.3** (published 2017-07-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install center-it
pnpm add center-it
yarn add center-it
bun add center-it
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.3 |
| Published | 2017-07-11 |
| First published | 2016-11-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | ygjack414@hotmail.com |
| Maintainers | ygjack |
| Keywords | center-it, centerIt, center |

## Links

- npm: https://www.npmjs.com/package/center-it
- Repository: https://github.com/jackgit/center-it
- Homepage: https://github.com/jackgit/center-it#readme
- Issues: https://github.com/jackgit/center-it/issues
- npm.io page: https://npm.io/package/center-it

## Recent versions

- 1.1.3 (latest) — 2017-07-11
- 1.1.2 — 2017-07-11
- 1.1.1 — 2017-06-04
- 1.1.0 — 2017-06-04
- 1.0.1 — 2017-06-04
- 1.0.0 — 2017-06-04
- 0.1.0 — 2016-11-13
- 0.0.1 — 2016-11-11

## README

## description

`CenterIt` calculates width, height, ratio and offset when you want to center one rectangle into another, with designated center type (cover or contain)

## demo

[demo](https://jackgit.github.io/center-it/index.html)

## include

by script

```html
<script src="center-it.js"></script>
```

by npm

```bash
npm install center-it --save
```

```js
var CenterIt = require('center-it')
```

## usage

```js
var centerIt = new CenterIt({
  containerWidth: 100,
  containerHeight: 100,
  originWidth: 600,
  originHeight: 400,
  centerType: 'cover' // "cover" or "contain"
})

centerIt.width() // return resized width in px
centerIt.height() // return resized height in px
centerIt.ratio() // return resized ratio of origin
centerIt.offset() // return offset {top, left} of origin in px
```

it provides two helper functions

```js
// this is a helper function to set top left width height
centerIt.setPosition(el)

// this is a helper function to draw image into a canvas
centerIt.drawImage(context, image)
```

---
_Source: https://npm.io/package/center-it · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
