-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathget-mdi-svgs.js
47 lines (42 loc) · 1.12 KB
/
get-mdi-svgs.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
'use strict';
var https = require('https');
var fs = require('fs');
var join = require('path').join;
function getMdiApi(path, cb) {
return https.get({
host: 'materialdesignicons.com',
path: '/api' + path
}, function(response) {
var body = '';
response.on('data', function(d) {
body += d;
});
response.on('end', function() {
var parsed = null;
try {
parsed = JSON.parse(body);
} catch (e) {
console.error('Did not receive JSON:', body);
}
cb(parsed);
});
});
}
function buildSvg(pathData) {
return '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="' + pathData + '" /></svg>';
}
function writeSvg(svg, name) {
fs.writeFile(join(__dirname, 'svg', name + '.svg'), svg, function(err) {
if (err) {
console.error('Error while writing svg:', err);
}
});
}
getMdiApi('/init', function (init) {
var mainPackageId = init.packages[0].id;
getMdiApi('/package/' + mainPackageId, function(data) {
data.icons.forEach(function (icon) {
writeSvg(buildSvg(icon.data), icon.name);
});
});
});