npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

video-resolutions

v1.3.0

Published

Search into a local database of 184 video resolutions and aspect-ratio

Downloads

654

Readme

video-resolutions Build Status Coverage Status

The data come from this Wikipedia page: en.wikipedia.org/wiki/List_of_common_resolutions

Example

import resolutions from 'video-resolutions';

/* some script playing with a video object */

const compatibleAspects = resolutions.getMatchingAspect(
  resolutions.getOne({
    width: video.width,
    height: video.height
  })
);
/* for 4096×2160, it returns: */
[
  Format {
    code: 'DCI_2K',
    name: 'DCI 2K',
    fullName: 'DCI 2K (DCI 2K)',
    alternativeNames: [],
    width: 2048,
    height: 1080,
    aspects: {
      storage: Aspect { string: '256:135', float: 1.8962962962962964 },
      display: Aspect { string: '1.90:1', float: 1.9 },
      pixel: Aspect { string: '1.002', float: 1.002 }
    }
  }
]

Installation

$ npm install -D video-resolutions

Usage

This package export this list of classes and functions:

  • Aspect - A class representing an aspect-ratio
  • Format - A class representing an image format
  • getList - Get the list of the 184 formats
  • getAll - Get a list of formats matching a query object (eg. a width)
  • getOne - Returns the best result of getAll or create it
  • getMatchingAspect - Get a list of formats matching another format aspect ratio
  • search - Search a list of formats matching a query string
  • searchOne - Returns the best result of search or null

Notice: All the getters and searchers results are always a copy of database items so you can edit them without damaging database data.

Format

Each format code is either an unique string or null.

Each format resolution unique.

The Format class has a getter resolution returning a string of the width and height merged around a "×" symbol, and a getter pixelCount returning the multiplication of the number of pixels of width and height.

aspect is always a shorthand for aspects.storage, either as a getter of the Format class or in a query object.

You can use the methods setWidth(width) and setHeight(height) to edit a format width or height. The respectives height or width will be adapted to this change to match the aspect-ratio. By changing width or height, the format will lose its code, name, fullName, and alternativeNames.

getList()

import resolutions from 'video-resolutions';

resolutions.getList();
/* returns: */
[
  {
    format: Format {
      code: null,
      name: null,
      fullName: null,
      alternativeNames: [ 'Microvision' ],
      width: 16,
      height: 16,
      aspects: {
        storage: Aspect { string: '1:1', float: 1 },
        display: Aspect { string: '1:1', float: 1 },
        pixel: Aspect { string: '1:1', float: 1 }
      }
    },
    score: 20.509185851025467
  },
  /* 183 other items */
]

getAll(query)

resolutions.getAll({
  height: 1080
});
/* returns: */
[
  Format {
    code: null,
    name: null,
    fullName: null,
    alternativeNames: [ 'HDV 1080i' ],
    width: 1440,
    height: 1080,
    /* etc */
  }
  /* etc */
]

getOne(query, opts)

resolutions.getOne({
  width: 4096,
  height: 2160
});
/* returns: */
Format {
  code: 'DCI_4K',
  name: 'DCI 4K',
  fullName: 'DCI 4K (DCI 4K)',
  alternativeNames: [],
  width: 4096,
  height: 2160,
  aspects: {
    storage: Aspect { string: '256:135', float: 1.8962962962962964 },
    display: Aspect { string: '1.90:1', float: 1.9 },
    pixel: Aspect { string: '1.002', float: 1.002 }
  }
}

If no format matches the query, getOne will by default return a new Format created from query's data. By settings the opts to { create: false }, the function will instead return a null Object.

getMatchingAspect(format, aspect = 'storage')

resolutions.getMatchingAspect(
  resolutions.getOne({
    width: 4096,
    height: 2160
  })
);
/* returns: */
[
  Format {
    code: 'DCI_2K',
    name: 'DCI 2K',
    fullName: 'DCI 2K (DCI 2K)',
    alternativeNames: [],
    width: 2048,
    height: 1080,
    aspects: {
      storage: Aspect { string: '256:135', float: 1.8962962962962964 },
      display: Aspect { string: '1.90:1', float: 1.9 },
      pixel: Aspect { string: '1.002', float: 1.002 }
    }
  }
]

If no format matches the query, getOne will by default return a new Format created from query's data. By settings the opts to { create: false }, the function will instead return a null Object.

search(query)

resolutions.search('4k');
/* returns: */
[
  {
    format: Format {
      code: 'DCI_4K',
      name: 'DCI 4K',
      fullName: 'DCI 4K (DCI 4K)',
      alternativeNames: [],
      width: 4096,
      height: 2160,
      aspects: {
        storage: Aspect { string: '256:135', float: 1.8962962962962964 },
        display: Aspect { string: '1.90:1', float: 1.9 },
        pixel: Aspect { string: '1.002', float: 1.002 }
      }
    },
    score: 20.509185851025467
  },
  {
    format: Format {
      code: '4K_UHD_1',
      name: '4K Ultra HD 1',
      fullName: '4K Ultra HD 1 (4K UHD-1)',
      alternativeNames: [ '2160p', '4000-lines UHDTV (4K UHD)' ],
      width: 3840,
      height: 2160,
      aspects: {
        storage: Aspect { string: '16:9', float: 1.7777777777777777 },
        display: Aspect { string: '16:9', float: 1.7777777777777777 },
        pixel: Aspect { string: '1:1', float: 1 }
      }
    },
    score: 17.092425489432678
  },
  {
    format: Format {
      code: 'UW4K',
      name: 'Ultra-Wide 4K',
      fullName: 'Ultra-Wide 4K (UW4K)',
      alternativeNames: [],
      width: 3840,
      height: 1600,
      aspects: {
        storage: Aspect { string: '2.35:1', float: 2.35 },
        display: Aspect { string: '2.35:1', float: 2.35 },
        pixel: Aspect { string: '0.996', float: 0.996 }
      }
    },
    score: 15.99784821394083
  }
]

searchOne(query)

This function will return the best result from searchAll or null.

Related

elasticlunr - Package powering the format search engine

License

This project is licensed under the MIT license.