screencalc
Version:
Calculate data about any display (width, height, ratio, area, density, etc.)
80 lines (79 loc) • 3.35 kB
TypeScript
import { ScreenProperties } from './ScreenProperties';
/**
* Allows screen information to be easily stored and calculated
*/
declare class ScreenCalc {
/** Holds the provided display data */
private d;
constructor(properties: ScreenProperties);
/**
* Attempts to calculate/return the pixel height of the screen.
*/
getPixelHeight(): number;
/**
* Attempts to calculate/return the pixel width of the screen.
*/
getPixelWidth(): number;
/**
* Attempts to calculate/return the screen's physical height.
*/
getPhysicalHeight(): number;
/**
* Attempts to calculate/return the screen's physical width.
*/
getPhysicalWidth(): number;
/**
* Attempts to calculate/return the screen's diagonal size.
*/
getDiagonalSize(): number;
/**
* Returns the number of pixels per unit in the display
* (will be ppi if units are in, or ppcm if units are cm)
*/
getPixelDensity(): number;
/**
* Returns the area of the display in square units.
*/
getArea(): number;
/**
* Returns the total number of pixels in the screen.
*/
getPixelCount(): number;
/**
* Returns the screen's width divided by its height.
* For example, the ratio of a 1920x1080 display would
* be 1.78 when rounded to two decimal places.
*/
getRatio(): number;
/**
* Returns an object with 'width' and 'height' properties containing a simplified ratio for the display.
* Additionally, a 'difference' property is included which contains the difference between the simplified
* and original ratio (0 if the simplified ratio is exact). For example, a 1366x768 display would (by default)
* return { width: 16, height: 9, difference: -0.0008680555555555802 }.
* Returns null if there is not enough data to calculate the ratio.
* @param precision (optional) pass a number between 0 and 1 for precision (defaults to 5.0e-3).
* The closer the number is to zero the greater the precision. For example, if 1.0e-6 is passed,
* the return value for a 1366x768 display would be { width: 683, height: 384, difference: 0 }.
*/
getSimpleRatio(precision?: number): {
width: number;
height: number;
difference: number;
};
/**
* Returns the same simplified ratio as getSimpleRatio(), but as a string in the format width:height.
* For example, a 1920x1080 display would return "16:9". If the ratio is imprecise, a tilde (~) character
* is prepended to the string (i.e. "~16x9").
* Returns null if there is not enough data to calculate the ratio.
* @param precision (optional) pass a number between 0 and 1 for precision (defaults to 5.0e-3).
* The closer the number is to zero the greater the precision. For example, if 1.0e-6 is passed,
* the return value for a 1366x768 display would be the precise ratio "683:384".
*/
getStringRatio(precision?: number): string;
/**
* Tries to calculate width and height in the same units (used for ratio calculation).
* Returns an object with height and width properties, or null if insufficient data.
*/
private calculateWidthAndHeight();
}
export default ScreenCalc;