-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (43 loc) · 1.05 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
const fs = require("fs");
const path = require("path");
const mapping = require("./mapping.json");
function getSVG(cfnType, type = "svg", size = "64") {
try {
return fs
.readFileSync(
path.join(
__dirname,
mapping[cfnType.toLowerCase()].icon
.replace(/\{size\}/g, size)
.replace("{type}", type)
)
)
.toString();
} catch (err) {
if (process.env.AWS_ICON_DIR_DEBUG === 1) console.log(err);
return;
}
}
function guessSVG(service, type = "svg", size = "64") {
try {
const bestGuessKey = Object.keys(mapping).filter(p => p.toLowerCase().contains(service.toLowerCase()));
const bestGuess = mapping[bestGuessKey];
return fs
.readFileSync(
path.join(
__dirname,
bestGuess.icon
.replace(/\{size\}/g, size)
.replace("{type}", type)
)
)
.toString();
} catch (err) {
if (process.env.AWS_ICON_DIR_DEBUG === 1) console.log(err);
return;
}
}
module.exports = {
getSVG,
guessSVG
};