@naverpay/device-info 0.0.2
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/CHANGELOG.md +7 -0
- package/LICENSE +21 -0
- package/aos.json +1 -0
- package/index.d.ts +5 -0
- package/index.js +7 -0
- package/ios.json +1 -0
- package/package.json +19 -0
- package/src/aos.js +106 -0
- package/src/index.js +5 -0
- package/src/ios.js +117 -0
package/index.d.ts
ADDED
package/index.js
ADDED
package/ios.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"Unknown":"iPad Pro (12.9-inch) (6th generation)","iPad4,1":"iPad Air","iPad4,2":"iPad Air","iPad4,3":"iPad Air","iPad5,3":"iPad Air 2","iPad5,4":"iPad Air 2","iPad11,3":"iPad Air (3rd generation)","iPad11,4":"iPad Air (3rd generation)","iPad13,1":"iPad Air (4th generation)","iPad13,2":"iPad Air (4th generation)","iPad13,16":"iPad Air (5th generation)","iPad13,17":"iPad Air (5th generation)","iPad6,7":"iPad Pro (12.9-inch)","iPad6,8":"iPad Pro (12.9-inch)","iPad6,3":"iPad Pro (9.7-inch)","iPad6,4":"iPad Pro (9.7-inch)","iPad7,1":"iPad Pro (12.9-inch) (2nd generation)","iPad7,2":"iPad Pro (12.9-inch) (2nd generation)","iPad7,3":"iPad Pro (10.5-inch)","iPad7,4":"iPad Pro (10.5-inch)","iPad8,1":"iPad Pro (11-inch)","iPad8,2":"iPad Pro (11-inch)","iPad8,3":"iPad Pro (11-inch)","iPad8,4":"iPad Pro (11-inch)","iPad8,5":"iPad Pro (12.9-inch) (3rd generation)","iPad8,6":"iPad Pro (12.9-inch) (3rd generation)","iPad8,7":"iPad Pro (12.9-inch) (3rd generation)","iPad8,8":"iPad Pro (12.9-inch) (3rd generation)","iPad8,9":"iPad Pro (11-inch) (2nd generation)","iPad8,10":"iPad Pro (11-inch) (2nd generation)","iPad8,11":"iPad Pro (12.9-inch) (4th generation)","iPad8,12":"iPad Pro (12.9-inch) (4th generation)","iPad13,4":"iPad Pro (11-inch) (3rd generation)","iPad13,5":"iPad Pro (11-inch) (3rd generation)","iPad13,6":"iPad Pro (11-inch) (3rd generation)","iPad13,7":"iPad Pro (11-inch) (3rd generation)","iPad13,8":"iPad Pro (12.9-inch) (5th generation)","iPad13,9":"iPad Pro (12.9-inch) (5th generation)","iPad13,10":"iPad Pro (12.9-inch) (5th generation)","iPad13,11":"iPad Pro (12.9-inch) (5th generation)","iPad2,5":"iPad mini","iPad2,6":"iPad mini","iPad2,7":"iPad mini","iPad4,4":"iPad mini 2","iPad4,5":"iPad mini 2","iPad4,6":"iPad mini 2","iPad4,7":"iPad mini 3","iPad4,8":"iPad mini 3","iPad4,9":"iPad mini 3","iPad5,1":"iPad mini 4","iPad5,2":"iPad mini 4","iPad11,1":"iPad mini (5th generation)","iPad11,2":"iPad mini (5th generation)","iPad14,1":"iPad mini (6th generation)","iPad14,2":"iPad mini (6th generation)","iPhone1,1":"iPhone","iPhone1,2":"iPhone 3G","iPhone2,1":"iPhone 3GS","iPhone3,1":"iPhone 4","iPhone3,2":"iPhone 4","iPhone3,3":"iPhone 4","iPhone4,1":"iPhone 4S","iPhone5,1":"iPhone 5","iPhone5,2":"iPhone 5","iPhone5,3":"iPhone 5c","iPhone5,4":"iPhone 5c","iPhone6,1":"iPhone 5s","iPhone6,2":"iPhone 5s","iPhone7,2":"iPhone 6","iPhone7,1":"iPhone 6 Plus","iPhone8,1":"iPhone 6s","iPhone8,2":"iPhone 6s Plus","iPhone8,4":"iPhone SE (1st generation)","iPhone9,1":"iPhone 7","iPhone9,3":"iPhone 7","iPhone9,2":"iPhone 7 Plus","iPhone9,4":"iPhone 7 Plus","iPhone10,1":"iPhone 8","iPhone10,4":"iPhone 8","iPhone10,2":"iPhone 8 Plus","iPhone10,5":"iPhone 8 Plus","iPhone10,3":"iPhone X","iPhone10,6":"iPhone X","iPhone11,8":"iPhone XR","iPhone11,2":"iPhone XS","iPhone11,6":"iPhone XS Max","iPhone11,4":"iPhone XS Max","iPhone12,1":"iPhone 11","iPhone12,3":"iPhone 11 Pro","iPhone12,5":"iPhone 11 Pro Max","iPhone12,8":"iPhone SE (2nd generation)","iPhone13,1":"iPhone 12 mini","iPhone13,2":"iPhone 12","iPhone13,3":"iPhone 12 Pro","iPhone13,4":"iPhone 12 Pro Max","iPhone14,4":"iPhone 13 mini","iPhone14,5":"iPhone 13","iPhone14,2":"iPhone 13 Pro","iPhone14,3":"iPhone 13 Pro Max","iPhone14,6":"iPhone SE (3rd generation)","iPhone14,7":"iPhone 14","iPhone14,8":"iPhone 14 Plus","iPhone15,2":"iPhone 14 Pro","iPhone15,3":"iPhone 14 Pro Max","iPhone15,4":"iPhone 15","iPhone15,5":"iPhone 15 Plus","iPhone16,1":"iPhone 15 Pro","iPhone16,2":"iPhone 15 Pro Max"}
|
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@naverpay/device-info",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "Device information",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"author": "geonmo-nine",
|
|
7
|
+
"license": "ISC",
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"node-fetch": "^3.3.2",
|
|
10
|
+
"node-html-parser": "^6.1.12"
|
|
11
|
+
},
|
|
12
|
+
"devDependencies": {
|
|
13
|
+
"@changesets/cli": "^2.27.1"
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"crawling": "node src/index.js",
|
|
17
|
+
"release": "changeset publish"
|
|
18
|
+
}
|
|
19
|
+
}
|
package/src/aos.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { writeFile } from "fs";
|
|
2
|
+
import fetch from "node-fetch";
|
|
3
|
+
import { parse } from "node-html-parser";
|
|
4
|
+
|
|
5
|
+
const trimText = (text) => text?.replace(/\n|"/gi, " ").trim();
|
|
6
|
+
async function fetchDeviceInfoAOS() {
|
|
7
|
+
const res = await fetch(
|
|
8
|
+
"https://storage.googleapis.com/play_public/supported_devices.html"
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
const htmlString = await res.text();
|
|
12
|
+
const document = parse(htmlString);
|
|
13
|
+
|
|
14
|
+
const table = document.querySelector("table.nice-table");
|
|
15
|
+
|
|
16
|
+
const table_data = [];
|
|
17
|
+
|
|
18
|
+
const temp_tds = {};
|
|
19
|
+
let n_column = 0;
|
|
20
|
+
let names_column = [];
|
|
21
|
+
|
|
22
|
+
const trs = table.querySelectorAll("tr");
|
|
23
|
+
|
|
24
|
+
for (let n = 0; n < trs.length; n++) {
|
|
25
|
+
if (n === 0) {
|
|
26
|
+
const ths = trs[n].querySelectorAll("th");
|
|
27
|
+
names_column = ths.map(({ textContent }) => trimText(textContent));
|
|
28
|
+
n_column = names_column.length;
|
|
29
|
+
for (let i = 0; i < n_column; i++) {
|
|
30
|
+
temp_tds[i] = null;
|
|
31
|
+
}
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
const tds = trs[n].querySelectorAll("td");
|
|
35
|
+
const _collected_tds = [];
|
|
36
|
+
|
|
37
|
+
if (n === 1) {
|
|
38
|
+
for (let j = 0; j < tds.length; j++) {
|
|
39
|
+
const td = tds[j];
|
|
40
|
+
const rowspan = Number(td.getAttribute("rowspan"));
|
|
41
|
+
if (rowspan) {
|
|
42
|
+
temp_tds[j] = [td, rowspan];
|
|
43
|
+
} else {
|
|
44
|
+
temp_tds[j] = [td, 1];
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
let keepIndex = 0;
|
|
50
|
+
for (let k = 0; k < n_column; k++) {
|
|
51
|
+
const temp_td = temp_tds[k];
|
|
52
|
+
if (temp_td) {
|
|
53
|
+
temp_td[1] -= 1;
|
|
54
|
+
const [td, cols] = temp_td;
|
|
55
|
+
_collected_tds.push(td);
|
|
56
|
+
|
|
57
|
+
if (cols === 0) {
|
|
58
|
+
temp_tds[k] = null;
|
|
59
|
+
}
|
|
60
|
+
} else {
|
|
61
|
+
for (; keepIndex < tds.length; ) {
|
|
62
|
+
const td = tds[keepIndex];
|
|
63
|
+
const rowspan = Number(td.getAttribute("rowspan"));
|
|
64
|
+
if (rowspan) {
|
|
65
|
+
temp_tds[k] = [td, rowspan - 1];
|
|
66
|
+
_collected_tds.push(td);
|
|
67
|
+
} else {
|
|
68
|
+
_collected_tds.push(td);
|
|
69
|
+
}
|
|
70
|
+
keepIndex++;
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const _row_data = {};
|
|
77
|
+
|
|
78
|
+
for (let i = 0; i < n_column; i++) {
|
|
79
|
+
const td = _collected_tds[i];
|
|
80
|
+
if (td) {
|
|
81
|
+
const value = td.querySelector("a")?.textContent || td.textContent;
|
|
82
|
+
_row_data[names_column[i]] = trimText(value);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
table_data.push(_row_data);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const record = {};
|
|
89
|
+
table_data.forEach((product) => {
|
|
90
|
+
const marketingName = product["Marketing Name"];
|
|
91
|
+
if (marketingName) {
|
|
92
|
+
// 제품명 없는 경우 제외
|
|
93
|
+
record[product.Model] = marketingName;
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
if (record && Object.keys(record).length > 0) {
|
|
98
|
+
writeFile("./aos.json", JSON.stringify(record), (e) => {
|
|
99
|
+
if (e) {
|
|
100
|
+
console.log("[fetch-device-info/aos]", e);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export default fetchDeviceInfoAOS;
|
package/src/index.js
ADDED
package/src/ios.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { writeFile } from "fs";
|
|
2
|
+
import fetch from "node-fetch";
|
|
3
|
+
import { parse } from "node-html-parser";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @see https://github.com/ottocho/ios-devices-table/blob/master/main.py
|
|
7
|
+
* js로 재구현
|
|
8
|
+
*/
|
|
9
|
+
const trimText = (text) => text?.replace(/\n|"/gi, " ").trim();
|
|
10
|
+
async function fetchDeviceInfoIOS() {
|
|
11
|
+
const res = await fetch("https://theapplewiki.com/wiki/Models");
|
|
12
|
+
const htmlString = await res.text();
|
|
13
|
+
const document = parse(htmlString);
|
|
14
|
+
|
|
15
|
+
const all_table_data = {};
|
|
16
|
+
const tables = document.querySelectorAll("table.wikitable");
|
|
17
|
+
|
|
18
|
+
for (const table of tables) {
|
|
19
|
+
const _table_data = [];
|
|
20
|
+
|
|
21
|
+
const heading = table.parentNode.previousElementSibling;
|
|
22
|
+
const brand = heading.childNodes[1]?.id;
|
|
23
|
+
const wantedBrand = brand.includes("iPhone") || brand.includes("iPad");
|
|
24
|
+
if (!wantedBrand) {
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const temp_tds = {};
|
|
29
|
+
let n_column = 0;
|
|
30
|
+
let names_column = [];
|
|
31
|
+
|
|
32
|
+
const trs = table.querySelectorAll("tr");
|
|
33
|
+
for (let n = 0; n < trs.length; n++) {
|
|
34
|
+
if (n === 0) {
|
|
35
|
+
const ths = trs[n].querySelectorAll("th");
|
|
36
|
+
names_column = ths.map(({ textContent }) => trimText(textContent));
|
|
37
|
+
n_column = names_column.length;
|
|
38
|
+
for (let i = 0; i < n_column; i++) {
|
|
39
|
+
temp_tds[i] = null;
|
|
40
|
+
}
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
const tds = trs[n].querySelectorAll("td");
|
|
44
|
+
const _colected_tds = [];
|
|
45
|
+
|
|
46
|
+
if (n === 1) {
|
|
47
|
+
for (let j = 0; j < tds.length; j++) {
|
|
48
|
+
const td = tds[j];
|
|
49
|
+
const rowspan = Number(td.getAttribute("rowspan"));
|
|
50
|
+
if (rowspan) {
|
|
51
|
+
temp_tds[j] = [td, rowspan];
|
|
52
|
+
} else {
|
|
53
|
+
temp_tds[j] = [td, 1];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
let keepIndex = 0;
|
|
59
|
+
for (let k = 0; k < n_column; k++) {
|
|
60
|
+
const temp_td = temp_tds[k];
|
|
61
|
+
if (temp_td) {
|
|
62
|
+
temp_td[1] -= 1;
|
|
63
|
+
const [td, cols] = temp_td;
|
|
64
|
+
_colected_tds.push(td);
|
|
65
|
+
|
|
66
|
+
if (cols === 0) {
|
|
67
|
+
temp_tds[k] = null;
|
|
68
|
+
}
|
|
69
|
+
} else {
|
|
70
|
+
for (; keepIndex < tds.length; ) {
|
|
71
|
+
const td = tds[keepIndex];
|
|
72
|
+
const rowspan = Number(td.getAttribute("rowspan"));
|
|
73
|
+
if (rowspan) {
|
|
74
|
+
temp_tds[k] = [td, rowspan - 1];
|
|
75
|
+
_colected_tds.push(td);
|
|
76
|
+
} else {
|
|
77
|
+
_colected_tds.push(td);
|
|
78
|
+
}
|
|
79
|
+
keepIndex++;
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const _row_data = {};
|
|
86
|
+
|
|
87
|
+
for (let i = 0; i < n_column; i++) {
|
|
88
|
+
const td = _colected_tds[i];
|
|
89
|
+
if (td) {
|
|
90
|
+
const value = td.querySelector("a")?.textContent || td.textContent;
|
|
91
|
+
_row_data[names_column[i]] = trimText(value);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
_table_data.push(_row_data);
|
|
95
|
+
}
|
|
96
|
+
all_table_data[brand] = _table_data;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const brands = Object.keys(all_table_data);
|
|
100
|
+
const record = {};
|
|
101
|
+
brands.forEach((brand) => {
|
|
102
|
+
const products = all_table_data[brand];
|
|
103
|
+
return products.forEach((product) => {
|
|
104
|
+
record[product.Identifier] = product.Generation;
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
if (record && Object.keys(record).length > 0) {
|
|
109
|
+
writeFile("./ios.json", JSON.stringify(record), (e) => {
|
|
110
|
+
if (e) {
|
|
111
|
+
console.log("[fetch-device-info/ios]", e); // eslint-disable-line no-console
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export default fetchDeviceInfoIOS;
|