Skip to content

Latest commit

 

History

History
44 lines (35 loc) · 1.49 KB

README.md

File metadata and controls

44 lines (35 loc) · 1.49 KB

calc-aspect-ratio

NPM version NPM downloads install size

Small package for calculating aspect ratio of display resolution.

Demo

Install

npm i --save-dev calc-aspect-ratio

Using

import { calcAspectRatio } from 'calc-aspect-ratio';

const aspectRatio = calcAspectRatio(1920, 1080);
console.log(aspectRatio);
/* console output:
    {
        x: 16,
        y: 9,
        value: '16:9',
        approximately: false,
        nonStandard: false
    }
 */

// or calc for current screen
console.log(calcAspectRatio(screen.width, screen.height).value);

Examples

  • Standard aspect ratio: 4:3
  • Approximate aspect ratio: ≈16:9
  • Nonstandard aspect ratio: 11.99:1

Links