UNPKG

1.07 kBtext/coffeescriptView Raw
1exports.getAllAttributes = (message) ->
2 attributes = {}
3 if message.MessageAttributes
4 MessageAttrs = message.MessageAttributes
5 for attributeKey in Object.keys(MessageAttrs)
6 DataType = MessageAttrs[attributeKey].DataType
7 subKey = DataType
8 if DataType is 'Number'
9 subKey = 'String'
10 subKey = subKey + 'Value'
11 if MessageAttrs[attributeKey][subKey] is 'true'
12 MessageAttrs[attributeKey][subKey] = true
13 attributes[attributeKey] = MessageAttrs[attributeKey][subKey]
14 if DataType is 'Number'
15 attributes[attributeKey] = Number(attributes[attributeKey])
16 return attributes
17
18exports.setAllAttributes = (attributes) ->
19 returnValue = {}
20 for attributeKey, attributeValue of attributes
21
22 # fetch datatype from value
23 DataType = getDataType(attributeValue)
24
25 # begin setting the attribute
26 returnValue[attributeKey] =
27 DataType: DataType
28 StringValue: String(attributeValue)
29
30 return returnValue
31
32# private
33getDataType = (data) ->
34 if !isNaN(data)
35 return 'Number'
36 return 'String'
\No newline at end of file