fit-box

Fits a box within a boundary while keeping its original aspect ratio

Usage no npm install needed!

<script type="module">
  import fitBox from 'https://cdn.skypack.dev/fit-box';
</script>

README

Fit Box

Fits a box within a boundary while keeping its original aspect ratio.

npm module Coverage Status Build Status Dependencies devDependencies Status

The box will either be scaled up or scaled down within the boundary:

fitBox({
  boundary: { width: 400, height: 300 },
  box: { width: 20, height: 60 },
});
// => { width: 100, height: 300 }

fitBox({
  boundary: { width: 400, height: 300 },
  box: { width: 1280, height: 760 },
});
// => { width: 400, height: 237.5 }