iphone-dimensions 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,62 @@
1
+ // Generated by scripts/build.mjs. Do not edit.
2
+ import dataset from './data.js';
3
+ function stateRank(state) {
4
+ if (state === 'closed') {
5
+ return 0;
6
+ }
7
+ if (state === 'open') {
8
+ return 1;
9
+ }
10
+ return 2;
11
+ }
12
+
13
+ function freezePhone(phone) {
14
+ Object.freeze(phone.resolution_px);
15
+ Object.freeze(phone.also_known_as);
16
+ return Object.freeze(phone);
17
+ }
18
+
19
+ const { phones: phoneList, ...rest } = dataset;
20
+ Object.freeze(rest.notes);
21
+ Object.freeze(rest.units);
22
+ const phones = Object.freeze(phoneList.map(freezePhone));
23
+ const meta = Object.freeze(rest);
24
+
25
+ function getPhone(id) {
26
+ for (const phone of phones) {
27
+ if (phone.id === id) {
28
+ return phone;
29
+ }
30
+ }
31
+ return undefined;
32
+ }
33
+
34
+ function findPhones(query) {
35
+ const needle = query.toLowerCase();
36
+ const matches = [];
37
+ for (const phone of phones) {
38
+ if (phone.name.toLowerCase().includes(needle) || phone.id.toLowerCase().includes(needle)) {
39
+ matches.push(phone);
40
+ continue;
41
+ }
42
+ for (const alias of phone.also_known_as) {
43
+ if (alias.toLowerCase().includes(needle)) {
44
+ matches.push(phone);
45
+ break;
46
+ }
47
+ }
48
+ }
49
+ return matches;
50
+ }
51
+
52
+ function getProduct(productId) {
53
+ const matches = [];
54
+ for (const phone of phones) {
55
+ if (phone.product_id === productId) {
56
+ matches.push(phone);
57
+ }
58
+ }
59
+ matches.sort((left, right) => stateRank(left.state) - stateRank(right.state));
60
+ return matches;
61
+ }
62
+ export { phones, meta, getPhone, findPhones, getProduct };
package/index.d.ts ADDED
@@ -0,0 +1,54 @@
1
+ export interface ResolutionPx {
2
+ readonly width: number;
3
+ readonly height: number;
4
+ }
5
+
6
+ export interface IPhone {
7
+ id: string;
8
+ product_id: string;
9
+ state: 'closed' | 'open' | null;
10
+ name: string;
11
+ also_known_as: readonly string[];
12
+ family: string;
13
+ announced: string;
14
+ released: string;
15
+ height_mm: number;
16
+ width_mm: number;
17
+ depth_mm: number;
18
+ weight_g: number;
19
+ height_in: number;
20
+ width_in: number;
21
+ depth_in: number;
22
+ weight_oz: number;
23
+ display_in: number;
24
+ resolution_px: ResolutionPx;
25
+ ppi: number;
26
+ url: string;
27
+ source_url: string;
28
+ dates_source_url: string;
29
+ }
30
+
31
+ export interface Units {
32
+ readonly length: 'mm';
33
+ readonly mass: 'g';
34
+ readonly display: 'in';
35
+ }
36
+
37
+ export interface Meta {
38
+ schema_version: 1;
39
+ name: string;
40
+ description: string;
41
+ license: string;
42
+ homepage: string;
43
+ source: string;
44
+ units: Units;
45
+ verified: string;
46
+ notes: readonly string[];
47
+ count: number;
48
+ }
49
+
50
+ export const phones: readonly IPhone[];
51
+ export const meta: Meta;
52
+ export function getPhone(id: string): IPhone | undefined;
53
+ export function findPhones(query: string): IPhone[];
54
+ export function getProduct(productId: string): IPhone[];
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "iphone-dimensions",
3
+ "version": "1.0.0",
4
+ "description": "Apple's published dimensions for every iPhone since the iPhone 7: height, width, depth, weight, display and pixel density, in mm and inches, each row cited to Apple's tech specs.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "sideEffects": false,
8
+ "homepage": "https://iphonesize.com/data-sources",
9
+ "repository": "github:iphonesize/iphone-dimensions",
10
+ "bugs": {
11
+ "url": "https://github.com/iphonesize/iphone-dimensions/issues"
12
+ },
13
+ "keywords": [
14
+ "iphone",
15
+ "apple",
16
+ "dimensions",
17
+ "size",
18
+ "specs",
19
+ "dataset",
20
+ "device",
21
+ "screen"
22
+ ],
23
+ "main": "./dist/index.cjs",
24
+ "module": "./dist/index.js",
25
+ "types": "./index.d.ts",
26
+ "exports": {
27
+ ".": {
28
+ "types": "./index.d.ts",
29
+ "import": "./dist/index.js",
30
+ "require": "./dist/index.cjs",
31
+ "default": "./dist/index.js"
32
+ },
33
+ "./data/iphones.json": "./data/iphones.json",
34
+ "./data/iphones.csv": "./data/iphones.csv"
35
+ },
36
+ "files": [
37
+ "dist/",
38
+ "index.d.ts",
39
+ "data/",
40
+ "README.md",
41
+ "LICENSE"
42
+ ],
43
+ "engines": {
44
+ "node": ">=18"
45
+ },
46
+ "scripts": {
47
+ "build": "node scripts/build.mjs",
48
+ "test": "node scripts/build.mjs && node --test --test-timeout=1000",
49
+ "sync": "node scripts/sync.mjs && node scripts/build.mjs",
50
+ "prepublishOnly": "npm test"
51
+ }
52
+ }