JSPM

aspratio

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q16711F
  • License MIT

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

Package Exports

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (aspratio) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    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