-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Expand file tree
/
Copy pathextract-android-device-names.js
More file actions
30 lines (27 loc) · 888 Bytes
/
extract-android-device-names.js
File metadata and controls
30 lines (27 loc) · 888 Bytes
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
'use strict';
import fs from 'node:fs';
// @ts-expect-error csv-parser has no types
import csv from 'csv-parser';
/**
* Transform CSV results into device mapping object
* @param {Array<{name: string, model: string}>} res - Array of device objects
* @returns {Record<string, string>} Device mapping where key is model and value is name
*/
const transformResults = res => {
/** @type {Record<string, string>} */
const deviceMapping = {};
res.forEach(({name, model}) => {
if (name && model) {
deviceMapping[model] = name;
}
});
return deviceMapping;
};
/** @type {Array<{name: string, model: string}>} */
const results = [];
fs.createReadStream('supported_devices.csv')
.pipe(csv())
.on('data', /** @param {any} data */ data => results.push(data))
.on('end', () => {
fs.writeFileSync('devices.json', JSON.stringify(transformResults(results)));
});