-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
244 lines (228 loc) · 9.75 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
// apple-device-names
// Version 1.1.7
// https://github.com/twitter-fabric/apple-model-names
// (c) 2017 Google, Inc.
// apple-device-names may be freely distributed under the MIT license.
;(function () {
function _convertMacbookPro(code, opts) {
if (!code) return '';
if (/^13[_,]3$/.test(code)) return 'Retina, 15", Late 2016';
if (/^13[_,]2$/.test(code)) return 'Retina, 13", Late 2016, Four Thunderbolt 3 ports';
if (/^13[_,]1$/.test(code)) return 'Retina, 13", Late 2016, Two Thunderbolt 3 ports';
if (/^11[_,][4,5]$/.test(code)) return 'Retina, 15", Mid 2015';
if (/^11[_,][2,3]$/.test(code)) return 'Retina, 15", Mid 2014';
if (/^12[_,]1$/.test(code)) return 'Retina, 13", Early 2015';
if (/^11[_,]1$/.test(code)) return 'Retina, 13", Mid 2014';
if (/^10[_,]2$/.test(code)) return 'Retina, 13", Early 2013';
if (/^10[_,]1$/.test(code)) return 'Retina, 15", Early 2013';
if (/^9[_,]2$/.test(code)) return '13", Mid 2012';
if (/^9[_,]1$/.test(code)) return '15", Mid 2012';
if (/^8[_,]3$/.test(code)) return '17", Late 2011';
if (/^8[_,]2$/.test(code)) return '15", Late 2011';
if (/^8[_,]1$/.test(code)) return '13", Late 2011';
if (/^7[_,]1$/.test(code)) return '13", Mid 2010';
if (/^6[_,]2$/.test(code)) return '15", Mid 2010';
if (/^6[_,]1$/.test(code)) return '17", Mid 2010';
if (/^5[_,]5$/.test(code)) return '13", Mid 2009';
if (/^5[_,]3$/.test(code)) return '15", Mid 2009';
if (/^5[_,]2$/.test(code)) return '17", Mid 2009';
if (/^5[_,]1$/.test(code)) return 'Late 2008';
if (/^4[_,]1$/.test(code)) return 'Early 2008';
if (/^3[_,]1$/.test(code)) return 'Late 2007';
if (/^2[_,]2$/.test(code)) return '15", Core 2 Duo';
if (/^2[_,]1$/.test(code)) return '17", Core 2 Duo';
if (/^1[_,]2$/.test(code)) return '17"';
if (/^1[_,]1$/.test(code)) return '15", Glossy';
return code;
}
function _convertMacbookAir(code, opts) {
if (!code) return '';
if (/^7[_,]2$/.test(code)) return '13", Early 2015';
if (/^7[_,]1$/.test(code)) return '11", Early 2015';
if (/^6[_,]2$/.test(code)) return '13", Mid 2013/Early 2014';
if (/^6[_,]1$/.test(code)) return '11", Mid 2013/Early 2014';
if (/^5[_,]2$/.test(code)) return '13", Mid 2012';
if (/^5[_,]1$/.test(code)) return '11", Mid 2012';
if (/^4[_,]2$/.test(code)) return '13", Mid 2011';
if (/^4[_,]1$/.test(code)) return '11", Mid 2011';
if (/^3[_,]2$/.test(code)) return '13", Late 2010';
if (/^3[_,]1$/.test(code)) return '11", Late 2010';
if (/^2[_,]1$/.test(code)) return 'Late 2008/Mid 2009';
if (/^1[_,]1$/.test(code)) return 'Original Model';
return code;
}
function _convertMacbook(code, opts) {
if (!code) return '';
if (/^8[_,]1$/.test(code)) return 'Retina, 12", Early 2015';
if (/^7[_,]1$/.test(code)) return '13", Mid 2010';
if (/^6[_,]1$/.test(code)) return '13", Late 2009';
if (/^5[_,]2$/.test(code)) return '13", Mid 2009';
if (/^5[_,]1$/.test(code)) return '13", Aluminum, Late 2008';
if (/^4[_,]1$/.test(code)) return '13", Late 2007';
if (/^3[_,]1$/.test(code)) return '13", Late 2007';
if (/^2[_,]1$/.test(code)) return '13", Mid 2007';
if (/^1[_,]1$/.test(code)) return 'Original Model';
return code;
}
function _convertImac(code, opts) {
if (!code) return '';
if (/^17[_,]2$/.test(code)) return 'Retina 5K, 27", Late 2015';
if (/^16[_,]2$/.test(code)) return 'Retina 4K, 21.5", Late 2015';
if (/^16[_,]1$/.test(code)) return '21.5", Late 2015';
if (/^15[_,]1$/.test(code)) return 'Retina 5K, 27", Mid 2015';
if (/^15[_,]1$/.test(code)) return 'Retina 5K, 27", Mid 2015';
if (/^14[_,]4$/.test(code)) return '21.5", Mid 2014';
if (/^14[_,]2$/.test(code)) return '27", Late 2013';
if (/^14[_,]1$/.test(code)) return '21.5", Late 2013';
if (/^13[_,]2$/.test(code)) return '27", Late 2012';
if (/^13[_,]1$/.test(code)) return '21.5", Late 2012';
if (/^12[_,]2$/.test(code)) return '27", Mid 2011';
if (/^12[_,]1$/.test(code)) return '21.5", Mid 2011';
if (/^11[_,]3$/.test(code)) return '27", Mid 2010';
if (/^11[_,]2$/.test(code)) return '21.5", Mid 2010';
if (/^10[_,]1$/.test(code)) return 'Late 2009';
if (/^9[_,]1$/.test(code)) return 'Early 2009';
if (/^8[_,]1$/.test(code)) return 'Early 2008';
if (/^7[_,]1$/.test(code)) return 'Mid 2007';
return code;
}
function _convertMacMini(code, opts) {
if (!code) return '';
if (/^7[_,][1-3]$/.test(code)) return 'Late 2014';
if (/^6[_,][1-2]$/.test(code)) return 'Late 2012';
if (/^5[_,][1-3]$/.test(code)) return 'Mid 2011';
if (/^5[_,][1-3]$/.test(code)) return 'Mid 2011';
if (/^4[_,]1$/.test(code)) return 'Mid 2010';
if (/^3[_,]1$/.test(code)) return 'Early/Late 2009';
if (/^2[_,]1$/.test(code)) return 'Mid 2007';
if (/^1[_,]1$/.test(code)) return 'Early/Late 2006';
return code;
}
function _convertMacPro(code, opts) {
if (!code) return '';
if (/^6[_,]1$/.test(code)) return 'Late 2013';
if (/^5[_,]1$/.test(code)) return 'Mid 2012';
return code;
}
function _convertIphone(code, opts) {
if (!code) return '';
if (/^10[_,][36]$/.test(code)) return 'X';
if (/^10[_,][25]$/.test(code)) return '8 Plus';
if (/^10[_,][14]$/.test(code)) return '8';
if (/^9[_,][24]$/.test(code)) return '7 Plus';
if (/^9[_,][13]$/.test(code)) return '7';
if (/^8[_,]4$/.test(code)) return 'SE';
if (/^8[_,]2$/.test(code)) return '6s Plus';
if (/^8[_,]1$/.test(code)) return '6s';
if (/^7[_,]2$/.test(code)) return '6';
if (/^7[_,]1$/.test(code)) return '6 Plus';
if (/^6[_,]\d$/.test(code)) return '5s';
if (/^5[_,][34]$/.test(code)) return '5c';
if (/^5[_,]\d$/.test(code)) return '5';
if (/^4[_,]\d$/.test(code)) return '4s';
if (/^3[_,]\d$/.test(code)) return '4';
if (/^2[_,]\d$/.test(code)) return '3GS';
if (/^1[_,]2$/.test(code)) return '3G';
if (/^1[_,]1$/.test(code)) return '1';
return code;
}
function _convertIpod(code, opts) {
if (!code) return '';
if (/^7[_,]\d$/.test(code)) return '6G';
if (/^5[_,]\d$/.test(code)) return '5G';
if (/^4[_,]\d$/.test(code)) return '4G';
if (/^3[_,]\d$/.test(code)) return '3G';
if (/^2[_,]\d$/.test(code)) return '2G';
if (/^1[_,]\d$/.test(code)) return '1G';
return code;
}
function _convertIpad(code, opts) {
if (!code) return '';
if (/^7[_,][3-4]$/.test(code)) return 'Pro (10.5 inch)';
if (/^7[_,][1-2]$/.test(code)) return 'Pro (12.9 inch, 2nd Gen)';
if (/^6[_,]1[1-2]$/.test(code)) return '5';
if (/^6[_,][7-8]$/.test(code)) return 'Pro (12.9 inch)';
if (/^6[_,][3-4]$/.test(code)) return 'Pro (9.7 inch)';
if (/^5[_,][3-4]$/.test(code)) return 'Air 2';
if (/^5[_,][1-2]$/.test(code)) return 'mini 4';
if (/^4[_,][7-9]$/.test(code)) return 'mini 3';
if (/^4[_,][4-6]$/.test(code)) return 'mini 2';
if (/^4[_,][1-3]$/.test(code)) return 'Air';
if (/^3[_,][4-6]$/.test(code)) return '4';
if (/^3[_,][1-3]$/.test(code)) return '3';
if (/^2[_,][5-7]$/.test(code)) return 'mini';
if (/^2[_,][1-4]$/.test(code)) return '2';
if (/^1[_,]\d$/.test(code)) return '1';
return code;
}
function _convertTv(code, opts) {
if (!code) return '';
if (/^6[_,]\d$/.test(code)) return '4K';
if (/^5[_,]\d$/.test(code)) return '4th G';
if (/^3[_,]\d$/.test(code)) return '3rd G';
if (/^2[_,]\d$/.test(code)) return '2nd G';
return code;
}
function _convertWatch(code, opts) {
if (!code) return '';
if (/^2[_,][3-4]$/.test(code)) return 'Series 2';
if (/^1[_,][6-7]$/.test(code)) return 'Series 1';
if (/^1[_,][1-2]$/.test(code)) return '1st G';
return code;
}
function _parseOptions(opts) {
opts = typeof opts === 'undefined' ? {} : opts;
opts.noMatchString = opts.noMatchString || 'Other';
return opts;
}
function getAppleModelName(str, opts) {
if (!str || typeof str !== 'string') return;
opts = _parseOptions(opts);
var result = [str];
if (str.match(/simulator/i)) {
result = ['Simulator'];
} else if (str.match(/ios/i)) {
result = ['iOS (Simulator)'];
} else if (m = str.match(/iphone\s?(.*)/i)) {
result = ['iPhone', _convertIphone(m[1], opts)];
} else if (m = str.match(/ipad\s?(.*)/i)) {
result = ['iPad', _convertIpad(m[1], opts)];
} else if (m = str.match(/ipod\s?(.*)/i)) {
result = ['iPod touch', _convertIpod(m[1], opts)];
} else if (m = str.match(/macbookpro\s?(.*)/i)) {
result = ['MacBook Pro', _convertMacbookPro(m[1], opts)];
} else if (m = str.match(/macbookair\s?(.*)/i)) {
result = ['MacBook Air', _convertMacbookAir(m[1], opts)];
} else if (m = str.match(/macbook\s?(.*)/i)) {
result = ['MacBook', _convertMacbook(m[1], opts)];
} else if (m = str.match(/imac\s?(.*)/i)) {
result = ['iMac', _convertImac(m[1], opts)];
} else if (m = str.match(/macmini\s?(.*)/i)) {
result = ['Mac mini', _convertMacMini(m[1], opts)];
} else if (m = str.match(/macpro\s?(.*)/i)) {
result = ['Mac Pro', _convertMacPro(m[1], opts)];
} else if (m = str.match(/appletv\s?(.*)/i)) {
result = ['Apple TV', _convertTv(m[1], opts)];
} else if (m = str.match(/watch\s?(.*)/i)) {
result = ['Apple Watch', _convertWatch(m[1], opts)];
} else {
result = [opts.noMatchString];
}
if (!opts.split) {
result = result.join(' ').trim();
}
return result;
};
if (typeof define === 'function' && define.amd) {
// RequireJS / AMD
define(function () {
return getAppleModelName;
});
} else if (typeof module !== 'undefined' && module.exports) {
// CommonJS
module.exports = getAppleModelName;
} else {
// Global
this.getAppleModelName = getAppleModelName;
}
}.call(this));