Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/sbstjn/sqs-object

Convert JavaScript objects to SQS Meta Attributes
https://github.com/sbstjn/sqs-object

aws mapping object sqs

Last synced: 28 days ago
JSON representation

Convert JavaScript objects to SQS Meta Attributes

Awesome Lists containing this project

README

        

# sqs-object

[![npm](https://img.shields.io/npm/v/sqs-object.svg)](https://www.npmjs.com/package/sqs-object)
[![license](https://img.shields.io/github/license/sbstjn/sqs-object.svg)](https://github.com/sbstjn/sqs-object/blob/master/LICENSE.md)
[![CircleCI](https://img.shields.io/circleci/project/github/sbstjn/sqs-object/master.svg)](https://circleci.com/gh/sbstjn/sqs-object)

Convert **JavaScript** objects to **SQS Meta** attributes as *vice verse*.

## Installation

```bash
$ > npm install sqs-object --save
```

## Usage

```js
const sqsObject = require('sqs-object');
```

## Mapping

First define a mapping between the JavaScript object and the SQS Meta Attributes like this:

```js
const mapping = [
{
objectKey: 'id',
sqsKey: 'ID',
sqsType: 'Number'
},
{
objectKey: 'name',
sqsKey: 'Name',
sqsType: 'String'
},
{
objectKey: 'age',
sqsKey: 'Age',
sqsType: 'Number'
}
];
```

## Object to Meta Attributes

```js
const meta = sqsObject.Meta({
id: 12,
name: 'Paul',
age: 45
}, mapping);
```

```json
{
"ID": {
"DataType": "Number",
"StringValue": "12"
},
"Name": {
"DataType": "String",
"StringValue": "Paul"
},
"Age": {
"DataType": "Number",
"StringValue": "45"
}
}
```

## Meta Attributes to Object

```js
const object = sqsObject.Object({
ID: {
DataType: 'Number',
StringValue: '12'
},
Name: {
DataType: 'String',
StringValue: 'Paul'
},
Age: {
DataType: 'Number',
StringValue: '45'
}
}, mapping);
```

```json
{
"id": 12,
"name": "Paul",
"age": 45
}
```

## License

Feel free to use the code, it's released using the [MIT license](https://github.com/sbstjn/sqs-object/blob/master/LICENSE.md).

## Contributors

- [Sebastian Müller](https://sbstjn.com)