1.0.1 • Published 1 year ago

aspratio v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

aspratio

To get aspect-ratio of 'screen size or image'

Install

npm install aspratio

Usage:

get ratio with CJS

const ratio = require("aspratio");
const [Width, Height] = [1920, 1080];
console.log(ratio.toRatio(Width, Height)); // => 16:9
console.log(ratio.toRatio(Width, Height, '/')); // => 16/9
const { toRatio } = require("aspratio");
const [Width, Height] = [1920, 1080];
console.log(toRatio(Width, Height)); // => 16:9
console.log(toRatio(Width, Height, '/')); // => 16/9

get ratio with ESM

import ratio from "aspratio";
const [Width, Height] = [1920, 1080];
console.log(ratio.toRatio(Width, Height)); // => 16:9
console.log(ratio.toRatio(Width, Height, '/')); // => 16/9
import { toRatio } from "aspratio";
const [Width, Height] = [1920, 1080];
console.log(toRatio(Width, Height)); // => 16:9
console.log(toRatio(Width, Height, '/')); // => 16/9

To get width

CJS :

const ratio = require("aspratio");
const Height = 1080;
console.log(ratio.toWidth("16:9", Height)); // 1920
const { toWidth } = require("aspratio");
const Height = 1080;
console.log(toWidth("16:9", Height)); // 1920

ESM :

import ratio from "aspratio";
const Height = 1080;
console.log(ratio.toWidth("16:9", Height)); // 1920
import { toWidth } from "aspratio";
const Height = 1080;
console.log(toWidth("16:9", Height)); // 1920

To get height

CJS :

const ratio = require("aspratio");
const Width = 1920;
console.log(ratio.toHeight("16:9", Width)); // 1080
const { toHeight } = require("aspratio");
const Width = 1920;
console.log(toHeight("16:9", Width)); // 1080

ESM :

import ratio from "aspratio";
const Width = 1920;
console.log(ratio.toHeight("16:9", Width)); // 1080
import { toHeight } from "aspratio";
const Width = 1920;
console.log(toHeight("16:9", Width)); // 1080