-
Notifications
You must be signed in to change notification settings - Fork 2
/
parser.js
35 lines (32 loc) · 940 Bytes
/
parser.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
const fnJoin = (expression) => {
const [delimiter, values] = expression;
return values.join(delimiter, resolveExpressions(values))
}
const fnGetAtt = (expression) => {
return expression[1] && expression[1] === 'Arn' ? expression[0] : expression.join('', expression)
}
const resolveExpressions = (expressions) => {
const intrinsicFunctions = [
{
templateName: 'Ref', resolver: () => 'aws'
},
{
templateName: 'Fn::GetAtt', resolver: fnGetAtt
},
{
templateName: 'Fn::Join', resolver: fnJoin
}
]
return expressions.map((item, key) => {
intrinsicFunctions.map((func) => {
if (item.hasOwnProperty(func.templateName)) {
expressions[key] = func.resolver(item[func.templateName]);
}
})
return expressions[key]
})
}
module.exports = {
fnJoin,
resolveExpressions
}