@shotlingo/device-resolutions
v0.1.0
Published
iOS points/scale/pixels/ppi and Android dp/density-bucket/pixels/ppi for every current device class, as a typed lookup table — no network calls, zero dependencies.
Maintainers
Readme
@shotlingo/device-resolutions
iOS points/scale/pixels/ppi and Android dp/density-bucket/pixels/ppi for every current iPhone, iPad, Android phone, and Android tablet class — as a typed lookup table. Zero dependencies, no network calls.
Full interactive reference (searchable table + JSON/CSV export): shotlingo.com/tools/device-resolution-lookup
Install
npm install @shotlingo/device-resolutionsUsage
import { getById, getByPlatform, pxToDp, nearestDensityBucket, DEVICE_RESOLUTIONS } from '@shotlingo/device-resolutions';
getById('iphone-6.9');
// => { id: 'iphone-6.9', platform: 'ios', category: 'iphone', label: 'iPhone 6.9"', logical: { w: 440, h: 956 }, scale: 3, physical: { w: 1320, h: 2868 }, ppi: 460, ... }
getByPlatform('android').map((d) => d.label);
// => ['Pixel 8', 'Pixel 8 Pro', 'Galaxy S23', 'Galaxy S23 Ultra', 'Galaxy Tab S9']
pxToDp(1080, 480);
// => 360
nearestDensityBucket(428).name;
// => 'xxhdpi'
DEVICE_RESOLUTIONS.length;
// => 20API
DEVICE_RESOLUTIONS: DeviceResolution[]— the full device list (iPhone, iPad, Android phone, Android tablet).DENSITY_BUCKETS: DensityBucket[]— the standard Android density buckets (ldpi → xxxhdpi).PLATFORMS: Platform[]—'ios' | 'android'.CATEGORIES: DeviceCategory[]—'iphone' | 'ipad' | 'android-phone' | 'android-tablet'.getById(id: string): DeviceResolution | undefined— lookup by id, e.g.'pixel-8'(case-insensitive).getByPlatform(platform: Platform): DeviceResolution[]getByCategory(category: DeviceCategory): DeviceResolution[]getDensityBucket(id: string): DensityBucket | undefined— lookup by bucket id, e.g.'xxhdpi'(case-insensitive).pxToDp(px: number, ppi: number): number— computed Android dp per the density formula (px ÷ (ppi ÷ 160)). Real hardware rounds to the nearest standard bucket, so treat the result as an estimate.nearestDensityBucket(ppi: number): DensityBucket— the standard bucket whose dpi is closest to a given ppi.
Why this exists
Marketing size names ("6.5-inch", "6.7-inch") don't map 1:1 to pixel grids — several physically-different iPhone classes share a marketing size, and Android manufacturers ship a continuum of real densities instead of the six standard buckets. This package gives you the actual logical/physical/ppi values so screenshot templates and design breakpoints don't drift by a few pixels between "similar" device classes.
License
MIT
