GithubHelp home page GithubHelp logo

tobua / device-sizes Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 33 KB

Collection of mobile device properties relevant for development.

Home Page: https://device-sizes.vercel.app/api

TypeScript 94.83% JavaScript 5.17%

device-sizes's Introduction

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

device-sizes's People

Contributors

tobua avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.