Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

device-sizes

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

device-sizes

Collection of properties of popular mobile devices.

  • 1.2.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Device Sizes

Device Sizes

Collection of various properties relevant for development of various popular mobile devices.

Installation and Usage

npm install device-sizes
import { deviceSizes } from 'device-sizes'

console.log(deviceSizes.iphone15.name === 'iPhone 15') // true

const widths = Object.keys(deviceSizes).map((key) => deviceSizes[key].width)
const sumOfWidths = widths.reduce((previous, current) => previous + current, 0)
const averageWidth = sumOfWidths / Object.keys(deviceSizes).length

console.log(averageWidth)

Available Properties

interface Device {
  id: string
  name: string
  width: number
  height: number
  // Screen diagonal in inches
  size: number
  // In Pixels per Inch (ppi)
  density: number
  // Responsive scaling factor
  scale: number
  brand: Brand
  camera: Camera
  type: Type
}

enum Brand {
  Apple,
  Samsung,
  Google,
  Xiaomi,
  Oppo,
  Huawei,
}

enum Camera {
  Notch,
  DynamicIsland,
  Center,
  Left,
  Right,
  Outside,
  Unknown,
}

enum Type {
  Phone,
  Tablet,
}

The types can be imported from the plugin when needed.

import { Device, Brand, Camera, Type } from 'device-sizes'

GraphQL API

To avoid bundling all devices or download unnecessary properties the data can be queried through GraphQL. The API is reachable at https://device-sizes.vercel.app/api.

import { ApolloClient, InMemoryCache, gql, HttpLink } from '@apollo/client'

const client = new ApolloClient({
  uri: 'https://device-sizes.vercel.app/api'
  cache: new InMemoryCache(),
})

const response = await client.query({
  query: gql`
    query GetDevices {
      devices {
        id
        name
        width
        height
      }
    }
  `,
})

const { devices } = response.data

Keywords

FAQs

Package last updated on 12 Jun 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc