forked from zoontek/react-native-permissions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetchWindowsCapabilites.js
57 lines (42 loc) · 1.3 KB
/
fetchWindowsCapabilites.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
// Fetch list of Windows UWP App capabilites from the Microsoft docs
// The names of individual capabilites are in <strong> tag and follow camelCase
const https = require('https');
const {EOL} = require('os');
https.get(
'https://docs.microsoft.com/en-us/windows/uwp/packaging/app-capability-declarations',
(res) => {
res.setEncoding('utf8');
let data = '';
res.on('error', ({message}) => {
console.error(message);
process.exit(-1);
});
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => parse(data));
},
);
function parse(data) {
const names = new Set();
for (const match of data.match(/<strong>[a-z]+[a-zA-Z\.]*<\/strong>/gm)) {
names.add(
match.substr('<strong>'.length, match.length - '<strong>'.length - '</strong>'.length),
);
}
const results = [];
for (const name of names) {
let constName = '';
for (let i = 0; i < name.length; ++i) {
const char = name.charAt(i);
if (char === char.toUpperCase()) {
constName += '_';
}
constName += char.toUpperCase();
}
constName = constName.replace('WI_FI', 'WIFI');
constName = constName.replace('VO_I_P', 'VOIP');
results.push(`${constName}: 'windows.permission.${name}',`);
}
console.log(results.sort().join(EOL));
}