iphone-dimensions 1.0.2 → 1.1.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 CHANGED
@@ -13,6 +13,8 @@ function stateRank(state) {
13
13
  function freezePhone(phone) {
14
14
  Object.freeze(phone.resolution_px);
15
15
  Object.freeze(phone.also_known_as);
16
+ Object.freeze(phone.model_identifiers);
17
+ Object.freeze(phone.model_numbers);
16
18
  return Object.freeze(phone);
17
19
  }
18
20
 
@@ -31,22 +33,53 @@ function getPhone(id) {
31
33
  return undefined;
32
34
  }
33
35
 
36
+ function listIncludes(values, needle) {
37
+ for (const value of values) {
38
+ if (value.toLowerCase().includes(needle)) {
39
+ return true;
40
+ }
41
+ }
42
+ return false;
43
+ }
44
+
34
45
  function findPhones(query) {
35
46
  const needle = query.toLowerCase();
36
47
  const matches = [];
37
48
  for (const phone of phones) {
38
- if (phone.name.toLowerCase().includes(needle) || phone.id.toLowerCase().includes(needle)) {
49
+ if (
50
+ phone.name.toLowerCase().includes(needle)
51
+ || phone.id.toLowerCase().includes(needle)
52
+ || listIncludes(phone.also_known_as, needle)
53
+ || listIncludes(phone.model_identifiers, needle)
54
+ || listIncludes(phone.model_numbers, needle)
55
+ ) {
39
56
  matches.push(phone);
40
- continue;
41
57
  }
42
- for (const alias of phone.also_known_as) {
43
- if (alias.toLowerCase().includes(needle)) {
44
- matches.push(phone);
45
- break;
58
+ }
59
+ return matches;
60
+ }
61
+
62
+ function getByIdentifier(modelIdentifier) {
63
+ for (const phone of phones) {
64
+ for (const identifier of phone.model_identifiers) {
65
+ if (identifier === modelIdentifier) {
66
+ return phone;
67
+ }
68
+ }
69
+ }
70
+ return undefined;
71
+ }
72
+
73
+ function getByModelNumber(aNumber) {
74
+ const needle = aNumber.toLowerCase();
75
+ for (const phone of phones) {
76
+ for (const modelNumber of phone.model_numbers) {
77
+ if (modelNumber.toLowerCase() === needle) {
78
+ return phone;
46
79
  }
47
80
  }
48
81
  }
49
- return matches;
82
+ return undefined;
50
83
  }
51
84
 
52
85
  function getProduct(productId) {
@@ -59,4 +92,4 @@ function getProduct(productId) {
59
92
  matches.sort((left, right) => stateRank(left.state) - stateRank(right.state));
60
93
  return matches;
61
94
  }
62
- export { phones, meta, getPhone, findPhones, getProduct };
95
+ export { phones, meta, getPhone, findPhones, getProduct, getByIdentifier, getByModelNumber };
package/index.d.ts CHANGED
@@ -23,9 +23,12 @@ export interface IPhone {
23
23
  display_in: number;
24
24
  resolution_px: ResolutionPx;
25
25
  ppi: number;
26
- url: string;
26
+ url: string | null;
27
27
  source_url: string;
28
28
  dates_source_url: string;
29
+ model_identifiers: readonly string[];
30
+ model_numbers: readonly string[];
31
+ model_identifiers_source: 'apple' | 'secondary';
29
32
  }
30
33
 
31
34
  export interface Units {
@@ -35,16 +38,19 @@ export interface Units {
35
38
  }
36
39
 
37
40
  export interface Meta {
38
- schema_version: 1;
41
+ schema_version: 2;
39
42
  name: string;
40
43
  description: string;
41
44
  license: string;
45
+ license_url: string;
42
46
  homepage: string;
43
47
  source: string;
44
48
  units: Units;
45
49
  verified: string;
46
50
  notes: readonly string[];
47
51
  count: number;
52
+ site_models_count: number;
53
+ historic_count: number;
48
54
  }
49
55
 
50
56
  export const phones: readonly IPhone[];
@@ -52,3 +58,5 @@ export const meta: Meta;
52
58
  export function getPhone(id: string): IPhone | undefined;
53
59
  export function findPhones(query: string): IPhone[];
54
60
  export function getProduct(productId: string): IPhone[];
61
+ export function getByIdentifier(modelIdentifier: string): IPhone | undefined;
62
+ export function getByModelNumber(aNumber: string): IPhone | undefined;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "iphone-dimensions",
3
- "version": "1.0.2",
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.",
3
+ "version": "1.1.0",
4
+ "description": "Apple's published dimensions for every iPhone since 2007, with model identifiers: height, width, depth, weight, display and pixel density, in mm and inches, each row cited to Apple's tech specs.",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "sideEffects": false,