
Research
/Security News
Toptal’s GitHub Organization Hijacked: 10 Malicious Packages Published
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
screencalc
Advanced tools
Calculate data about any display (width, height, ratio, area, density, etc.)
ScreenCalc is a powerful JavaScript module which makes it easy to answer almost any kind of question about the properties of a display. For example:
What is the resolution of a 16:9 screen with 1,440,000 pixels?
var screen = new ScreenCalc({
ratio: 16/9,
pixelCount: 1440000
});
var w = screen.getPixelWidth(); // 1600
var h = screen.getPixelHeight(); // 900
What are the physical dimensions and ppi of a 50-inch 1080p television screen?
var screen = new ScreenCalc({
pixelWidth: 1920,
pixelHeight: 1080,
diagonalSize: 50
});
var w = screen.getPhysicalWidth(); // 43.579
var h = screen.getPhysicalHeight(); // 24.513
var d = screen.getPixelDensity(); // 44.058
What resolution is needed for a 27-inch 16:9 display with 300ppi?
var screen = new ScreenCalc({
diagonalSize: 27,
pixelDensity: 300,
ratio: 16/9
});
var w = screen.getPixelWidth(); // 7059.762
var h = screen.getPixelHeight(); // 3971.116
What is the aspect ratio and diagonal size of a screen with an area of 8437.5 square centimeters and a width of 112.5 centimeters?
var screen = new ScreenCalc({
area: 8437.5,
physicalWidth: 112.5
});
var r = screen.getStringRatio(); // 3:2
var d = screen.getDiagonalSize(); // 135.2
Install using npm:
npm install screencalc
Require the module and instantiate with any combination of properties:
var ScreenCalc = require('screencalc');
var screen = new ScreenCalc({
ratio: 16/10,
pixelDensity: 225,
physicalHeight: 4.5
});
Each of these properties has a corresponding getPropertyName() method (e.g. getPixelHeight()
). Methods will throw an error if there is not enough data to perform the calculation:
var noPixels = new ScreenCalc({
physicalWidth: 30,
physicalHeight: 18
});
noPixels.getPixelCount(); // Error: Insufficient data to calculate pixel count
Note: ScreenCalc intentionally avoids rounding any values calculated by these methods (including pixel width, pixel height, and pixel count). When working with imprecise data, be sure to round results as necessary.
In addition to the getter methods corresponding to each settable property, ScreenCalc comes with two additional methods for calculating simplified ratios: getSimpleRatio()
and getStringRatio()
.
getSimpleRatio()
returns an object with width
and height
properties containing the simplified ratio. Additionally, a difference
property stores the difference between the simplified ratio and the exact ratio of the screen. The difference will be zero if the simplified ratio is precise.
var laptop = new ScreenCalc({
pixelWidth: 1366,
pixelHeight: 768
});
var ratio = laptop.getSimpleRatio(); // { width: 16, height: 9, difference: -0.0008680555555555802 }
getStringRatio()
returns the same simplified ratio as getSimpleRatio()
, but as a string in the format width:height. If the simplified ratio is not exact, a tilde will be prepended to the string:
var strRatio = laptop.getStringRatio(); // "~16:9"
Both getSimpleRatio()
and getStringRatio()
accept an optional parameter to override the default precision. This parameter should be a number between 0 and 1, where values closer to zero increase the precision. If not specified, the precision will default to 5.0e-3
.
var exactRatio = laptop.getSimpleRatio(1.0e-5); // { width: 683, height: 384, difference: 0 }
var exactStrRatio = laptop.getStringRatio(1.0e-5); // "683:384"
ScreenCalc is written in TypeScript. After editing files, run npm install
to compile everything and create a browser test bundle. Run npm test
to ensure all the tests pass, or use test/browser/index.html
to run the tests in a browser. Bug reports and pull requests are welcome!
Theodore Brown
http://theodorejb.me
MIT
FAQs
Calculate data about any display (width, height, ratio, area, density, etc.)
The npm package screencalc receives a total of 3 weekly downloads. As such, screencalc popularity was classified as not popular.
We found that screencalc demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
Research
/Security News
Socket researchers investigate 4 malicious npm and PyPI packages with 56,000+ downloads that install surveillance malware.
Security News
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.